<?php

use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\CoreExtension;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
use Twig\TemplateWrapper;

/* plan/evaluation_form.html.twig */
class __TwigTemplate_3856781a32962bcb65597aac2d054efb extends Template
{
    private Source $source;
    /**
     * @var array<string, Template>
     */
    private array $macros = [];

    public function __construct(Environment $env)
    {
        parent::__construct($env);

        $this->source = $this->getSourceContext();

        $this->blocks = [
            'page_title' => [$this, 'block_page_title'],
            'page_content' => [$this, 'block_page_content'],
            'javascripts' => [$this, 'block_javascripts'],
        ];
    }

    protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
    {
        // line 1
        return "@AdminLTE/layout/mesodd-layout.html.twig";
    }

    protected function doDisplay(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        $this->parent = $this->load("@AdminLTE/layout/mesodd-layout.html.twig", 1);
        yield from $this->parent->unwrap()->yield($context, array_merge($this->blocks, $blocks));
    }

    // line 3
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_page_title(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        yield $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans("evaluation.title", [], "messages");
        yield from [];
    }

    // line 6
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_page_content(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        // line 7
        yield "    <div class=\"card card-primary\">
        ";
        // line 8
        yield         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock(($context["form"] ?? null), 'form_start');
        yield "
            <div class=\"card-body\">    
              
                <table class=\"table table-striped notation-collection\">
                    <thead>
                        <th class=\"row\">
                            <div class=\"col-2 text-center\">Nature</div>
                            <div class=\"col-6 text-center\">ODD / Cible / Indicateur</div>
                            <div class=\"col-3 text-center\">Localisation</div>
                            <div class=\"col-1 text-center\">Mesure</div>
                        </th>
                    </thead>
                    <tbody>

                    <tr class=\"notation\">
                        <td>
                            <div class=\"row mt-2\">
                                ";
        // line 25
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "targetRate", [], "any", false, false, false, 25), 'widget');
        yield "
                                ";
        // line 26
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "locationRate", [], "any", false, false, false, 26), 'widget');
        yield "
                                <div class=\"col-2\">";
        // line 27
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "nature", [], "any", false, false, false, 27), 'widget', ["attr" => ["onchange" => "calculTargetRate()"]]);
        yield "</div>
                                <div class=\"col-6 p-0\">
                                    <div class=\"col-6 float-left\">";
        // line 29
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "goal", [], "any", false, false, false, 29), 'widget', ["attr" => ["onchange" => "goalChange(this.id)"]]);
        yield "</div>
                                    <div class=\"col-6 float-right\">";
        // line 30
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "target", [], "any", false, false, false, 30), 'widget', ["attr" => ["onchange" => "goalChange(this.id)"]]);
        yield "</div>
                                </div>
                                <div class=\"col-3\">";
        // line 32
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "locationType", [], "any", false, false, false, 32), 'widget', ["attr" => ["onchange" => "locationTypeChange()"]]);
        yield "</div>
                                <div class=\"col-1\">
                                    ";
        // line 34
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "sensHtml", [], "any", false, false, false, 34), 'widget');
        yield "
                                    ";
        // line 35
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "sensitivity", [], "any", false, false, false, 35), 'widget');
        yield "
                                </div>
                            </div>
                
                            <div class=\"row mt-2 mb-2\">
                                <div class=\"col-2\">";
        // line 40
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(CoreExtension::getAttribute($this->env, $this->source, CoreExtension::getAttribute($this->env, $this->source, ($context["notation"] ?? null), "activity", [], "any", false, false, false, 40), "code", [], "any", false, false, false, 40), "html", null, true);
        yield " - ";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(CoreExtension::getAttribute($this->env, $this->source, CoreExtension::getAttribute($this->env, $this->source, ($context["notation"] ?? null), "activity", [], "any", false, false, false, 40), "name", [], "any", false, false, false, 40), "html", null, true);
        yield "</div>
                                <div class=\"col-6\">";
        // line 41
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "indicators", [], "any", false, false, false, 41), 'widget', ["attr" => ["onchange" => "calculTargetRate(this.id)"]]);
        yield "</div>
                                ";
        // line 42
        if ((($context["grouping"] ?? null) == "arrondissement")) {
            // line 43
            yield "                                    <div class=\"col-3\">
                                        <div id=\"notation_arrondissements_div\">";
            // line 44
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "arrondissements", [], "any", false, false, false, 44), 'widget', ["attr" => ["onchange" => "calculLocationRate()"]]);
            yield "</div>
                                    </div>
                                ";
        } else {
            // line 47
            yield "                                    <div class=\"col-3\">
                                    <div id=\"notation_communes_div\">";
            // line 48
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "communes", [], "any", false, false, false, 48), 'widget', ["attr" => ["onchange" => "calculLocationRate()"]]);
            yield "</div>
                                    <div id=\"notation_postes_div\">";
            // line 49
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "postes", [], "any", false, false, false, 49), 'widget', ["attr" => ["onchange" => "calculLocationRate()"]]);
            yield "</div>
                                </div>
                                ";
        }
        // line 52
        yield "                                <div class=\"col-1 text-center\">
                                    ";
        // line 53
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "treated", [], "any", false, false, false, 53), 'widget', ["attr" => ["onchange" => "treatedChange()"]]);
        yield "
                                    <br/>
                                    <button type=\"submit\" class=\"btn btn-block btn-primary\"><i class=\"fas fa-share-square\"></i></button>
                                </div>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>

            </div>
        ";
        // line 64
        yield         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock(($context["form"] ?? null), 'form_end');
        yield "
    </div>
";
        yield from [];
    }

    // line 68
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_javascripts(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        // line 69
        yield "    <script>
        let maxRate = \$('#notation_maxRate').val()
        let minRate = \$('#notation_minRate').val()
        let grouping = '";
        // line 72
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["grouping"] ?? null), "html", null, true);
        yield "'

        window.onload = function(){
            if(grouping == 'arrondissement'){
                \$('#notation_locationType').val('arrondissement');
            } else {
                \$('#notation_locationType').val('department');
            }
            locationTypeChange()
            calculTargetRate()
            calculLocationRate()
        };

        function goalChange(field) {
            let \$field = \$('#'+field)
            let \$goal = \$('#notation_goal')
            let \$form = \$(\$field).closest('form')
            let data = {}
            data[\$goal.attr('name')] = \$goal.val()
            data[\$(\$field).attr('name')] = \$(\$field).val()
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (field == 'notation_goal') {
                        \$('#notation_target').replaceWith(
                            \$(html).find('#notation_target')
                        )
                        \$('#notation_indicators').replaceWith(
                            \$(html).find('#notation_indicators')
                        )

                        /*\$('#notation_target').attr('required', false)
                        if (\$('#notation_treated').is(':checked')) {
                            \$('#notation_target').attr('required', true)
                        } */                       
                    }
                    if (field == 'notation_target') {
                        \$('#notation_indicators').replaceWith(
                            \$(html).find('#notation_indicators')
                        )
                    }
                }
            });
        }

        function locationTypeChange() {
            if (\$('#notation_locationType').val() == 'arrondissement') {
                document.getElementById('notation_arrondissements').disabled = true;
            } else if (\$('#notation_locationType').val() == 'poste') {
                \$('#notation_communes_div').hide();
                \$('#notation_postes_div').show();
                document.getElementById('notation_communes').disabled = true;
                document.getElementById('notation_postes').disabled = false;
            } else {
                \$('#notation_communes_div').show();
                \$('#notation_postes_div').hide();
                document.getElementById('notation_communes').disabled = false;
                document.getElementById('notation_postes').disabled = true;
            }
        }

        function treatedChange() {
            let \$treated = \$('#notation_treated')
            let \$nature = \$('#notation_nature')
            let \$goal = \$('#notation_goal')
            let \$target = \$('#notation_target')
            let \$communes = \$('#notation_communes')
            let \$postes = \$('#notation_postes')

            \$nature.attr('required', false)
            \$goal.attr('required', false)
            \$target.attr('required', false)
            \$communes.attr('required', false)
            \$postes.attr('required', false)
            if (\$treated.is(':checked')) {
                \$nature.attr('required', true)
                \$goal.attr('required', true)
                \$target.attr('required', true)
                \$communes.attr('required', true)
                \$postes.attr('required', true)
            }
        }
        
        function getSelectedOptions(sel, fn) {
            var opts = [], opt;

            for (var i=0, len=sel.options.length; i<len; i++) {
                opt = sel.options[i];

                if ( opt.selected ) {
                    opts.push(opt);
                    if (fn) {
                        fn(opt);
                    }
                }
            }
            return opts;
        }

        function getSelectedRate(nature) {
            let allRate = \$('#notation_allRate').val()
            allRate = JSON.parse(allRate);
            for (var i = 0; i < allRate.length; i++) {
                if (allRate[i].id == nature){
                    return allRate[i].rate
                }
            }
        }
        
        function calculTargetRate() {
            let natureRate = getSelectedRate(\$('#notation_nature').val())

            let targetRate = natureRate
            //let nbTotal = 0
            let nbSelec = 0
            
            if (natureRate && (natureRate - minRate) != 0) {
                document.getElementById('notation_goal').disabled = false;
                document.getElementById('notation_target').disabled = false;
                document.getElementById('notation_indicators').disabled = false;
                document.getElementById('notation_locationType').disabled = false;
                if (\$('#notation_locationType').val() == 'arrondissement') {
                    document.getElementById('notation_arrondissements').disabled = false;
                } else if (\$('#notation_locationType').val() == 'poste') {
                    document.getElementById('notation_postes').disabled = false;
                } else {
                    document.getElementById('notation_communes').disabled = false;
                }
                
                nbSelec = getSelectedOptions(document.getElementById('notation_indicators')).length
                //nbTotal = document.getElementById('notation_indicators').options.length
                //if (nbTotal!=0) {
                //    targetRate = (maxRate * nbSelec + natureRate * (nbTotal - nbSelec)) / nbTotal
                //}
                if (nbSelec>0) {
                    targetRate = maxRate
                }
            } else {
                document.getElementById('notation_goal').disabled = true;
                document.getElementById('notation_target').disabled = true;
                document.getElementById('notation_indicators').disabled = true;
                document.getElementById('notation_locationType').disabled = true;
                if (\$('#notation_locationType').val() == 'arrondissement') {
                    document.getElementById('notation_arrondissements').disabled = true;
                }else if (\$('#notation_locationType').val() == 'poste') {
                    document.getElementById('notation_postes').disabled = true;
                } else {
                    document.getElementById('notation_communes').disabled = true;
                }
            }
            \$('#notation_targetRate').val(targetRate)

            calculSensitivity()
        }
        
        function calculLocationRate() {
            let locationRate = 0
            let nbTotal = 0
            let nbSelec = 0

            if (\$('#notation_locationType').val() == 'arrondissement') {
                nbSelec = getSelectedOptions(document.getElementById('notation_arrondissements')).length
                nbTotal = document.getElementById('notation_arrondissements').options.length
            } else if (\$('#notation_locationType').val() == 'poste') {
                nbSelec = getSelectedOptions(document.getElementById('notation_postes')).length
                nbTotal = document.getElementById('notation_postes').options.length
            } else {
                nbSelec = getSelectedOptions(document.getElementById('notation_communes')).length
                nbTotal = document.getElementById('notation_communes').options.length
            }
            if (nbTotal!=0) {
                locationRate = (nbSelec / nbTotal) * 100
            }
            \$('#notation_locationRate').val(locationRate)

            calculSensitivity()
        }

        function calculSensitivity() {
            let natureRate = getSelectedRate(\$('#notation_nature').val())

            let locationRate = \$('#notation_locationRate').val()
            let sensitivity = \$('#notation_targetRate').val()
            if (natureRate && (natureRate - minRate) != 0) {
                sensitivity = sensitivity - ((100 - locationRate) / 10)
            }
            \$('#notation_sensitivity').val(sensitivity)
            \$('#notation_sensHtml').val(sensitivity)
            //console.log(natureRate, minRate, locationRate, sensitivity)
        }
    </script>

";
        yield from [];
    }

    /**
     * @codeCoverageIgnore
     */
    public function getTemplateName(): string
    {
        return "plan/evaluation_form.html.twig";
    }

    /**
     * @codeCoverageIgnore
     */
    public function isTraitable(): bool
    {
        return false;
    }

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  204 => 72,  199 => 69,  192 => 68,  184 => 64,  170 => 53,  167 => 52,  161 => 49,  157 => 48,  154 => 47,  148 => 44,  145 => 43,  143 => 42,  139 => 41,  133 => 40,  125 => 35,  121 => 34,  116 => 32,  111 => 30,  107 => 29,  102 => 27,  98 => 26,  94 => 25,  74 => 8,  71 => 7,  64 => 6,  53 => 3,  42 => 1,);
    }

    public function getSourceContext(): Source
    {
        return new Source("", "plan/evaluation_form.html.twig", "/var/www/html/templates/plan/evaluation_form.html.twig");
    }
}
