<commit_before><?php

class ModUI{

    private $container;
    private $name;
    private $selector;
    private $auto_reload_time = 0;
    private $auto_reload_script = null;

    const SEPARATOR = '_';

    public function __construct($name, $container){
        $this->name = $name;
        $this->container = $container;
    }

    public function display(){
        $templates = $this->container->get_templates($this->name);
        $values = $this->container->get_values($this->name);
        $values['name'] = $this->name;
        $values['template_name'] = $this->name;
        $scripts = $this->container->get_scripts($this->name);
        $script = self::get_script($this->name, $scripts);
        if($this->auto_reload_time !== 0 && $this->auto_reload_script !== null){
            $old_values = json_encode($values);
            $script .= <<<JS
old_values = $old_values;
setInterval({$this->auto_reload_script}, {$this->auto_reload_time});
function update_auto(name, new_data, lwte){
    update_auto_body(name, new_data.template_name, old_values, new_data, null, lwte);
    old_values = new_data;
}
function update_auto_body(name, template_name, old_data, new_data, new_data2, lwte){
    if(new_data.name == name && old_data.name == name && new_data.template_name != undefined && new_data.template_name == old_data.template_name){
        for(var key in old_data){
            update_auto_body(key, new_data.template_name, old_data[key], new_data[key], new_data, lwte);
        }
    }else{
        if(old_data != new_data){
            document.getElementById(new_data2.name + "--span").innerHTML = lwte.useTemplate(template_name, new_data2);
        }
    }
}
JS;
        }
        return ['templates' => $templates, 'values' => $values, 'script' => $script];
    }

    public function input($params){
        header('Content-Type: application/json');
        if(isset($params['name'], $params['value'])){
            $name = $params['name'];
            $value = json_decode($params['value'], true);
            $name = self::get_name($name);
            $this->container->input($name[1], $value);
        }
        $values = $this->container->get_values($this->name);
        $values['name'] = $this->name;
        $values['template_name'] = $this->name;
        echo json_encode($values);
        exit();
    }

    public function add($component, $hook_function=null){
        $this->container->add($component, $hook_function);
    }

    public function enable_auto_reload($time, $script){
        $this->auto_reload_time = $time;
        $this->auto_reload_script = $script;
    }

    public static function get_lwte_use($template_name, $name){
        return "<span id=\"$name--span\">{use $template_name $name}</span>";
    }

    public static function get_child_name($base, $name){
        return $base . self::SEPARATOR . $name;
    }

    public static function set_update_script($update_script){
        self::$update_script = $update_script;<commit_msg>Add ModUI->get_values<commit_after><?php

class ModUI{

    private $container;
    private $name;
    private $selector;
    private $auto_reload_time = 0;
    private $auto_reload_script = null;

    const SEPARATOR = '_';

    public function __construct($name, $container){
        $this->name = $name;
        $this->container = $container;
    }

    public function display(){
        $templates = $this->container->get_templates($this->name);
        $scripts = $this->container->get_scripts($this->name);
        $script = self::get_script($this->name, $scripts);
        $values = $this->get_values();
        if($this->auto_reload_time !== 0 && $this->auto_reload_script !== null){
            $old_values = json_encode($values);
            $script .= <<<JS
old_values = $old_values;
setInterval({$this->auto_reload_script}, {$this->auto_reload_time});
function update_auto(name, new_data, lwte){
    update_auto_body(name, new_data.template_name, old_values, new_data, null, lwte);
    old_values = new_data;
}
function update_auto_body(name, template_name, old_data, new_data, new_data2, lwte){
    if(new_data.name == name && old_data.name == name && new_data.template_name != undefined && new_data.template_name == old_data.template_name){
        for(var key in old_data){
            update_auto_body(key, new_data.template_name, old_data[key], new_data[key], new_data, lwte);
        }
    }else{
        if(old_data != new_data){
            document.getElementById(new_data2.name + "--span").innerHTML = lwte.useTemplate(template_name, new_data2);
        }
    }
}
JS;
        }
        return ['templates' => $templates, 'values' => $values, 'script' => $script];
    }

    public function get_values(){
        $values = $this->container->get_values($this->name);
        $values['name'] = $this->name;
        $values['template_name'] = $this->name;
        return $values;
    }

    public function input($params){
        header('Content-Type: application/json');
        if(isset($params['name'], $params['value'])){
            $name = $params['name'];
            $value = json_decode($params['value'], true);
            $name = self::get_name($name);
            $this->container->input($name[1], $value);
        }
        $values = $this->get_values();
        echo json_encode($values);
        exit();
    }

    public function add($component, $hook_function=null){
        $this->container->add($component, $hook_function);
    }

    public function enable_auto_reload($time, $script){
        $this->auto_reload_time = $time;
        $this->auto_reload_script = $script;
    }

    public static function get_lwte_use($template_name, $name){
        return "<span id=\"$name--span\">{use $template_name $name}</span>";
    }

    public static function get_child_name($base, $name){
        return $base . self::SEPARATOR . $name;
    }

    public static function set_update_script($update_script){
        self::$update_script = $update_script;
{'fraction_non_alphanumeric': 0.15687259333668174, 'fraction_numerical': 0.0020090406830738324, 'mean_word_length': 3.1143250688705235, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6041039', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1824, 'n_words': 341}