<?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/notation_form.html.twig */
class __TwigTemplate_a4fe0bd2e6f13ad19c73fd18f6a93014 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'],
            'stylesheets' => [$this, 'block_stylesheets'],
        ];
    }

    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("notation.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 "    ";
        yield         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock(($context["form"] ?? null), 'form_start');
        yield "
  
        ";
        // line 9
        yield from $this->load("plan/notation_form.html.twig", 9, 839638903)->unwrap()->yield($context);
        // line 27
        yield "     
        ";
        // line 28
        if (((($context["actionId"] ?? null) > 0) && (Twig\Extension\CoreExtension::length($this->env->getCharset(), CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "notationModels", [], "any", false, false, false, 28)) > 0))) {
            // line 29
            yield "        ";
            yield from $this->load("plan/notation_form.html.twig", 29, 1529533935)->unwrap()->yield($context);
            // line 58
            yield "         ";
        } else {
            // line 59
            yield "        <div class=\"alert alert-info\" role=\"alert\">
            ";
            // line 60
            yield $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans("Veuillez sélectionner une action  pour afficher ces activités", [], "messages");
            // line 61
            yield "        </div>
        ";
        }
        // line 63
        yield "                
    ";
        // line 64
        yield         $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->renderBlock(($context["form"] ?? null), 'form_end');
        yield "
  
";
        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_collection_model_maxRate').val()
        let minRate = \$('#notation_collection_model_minRate').val()
        let weighting = \$('#notation_collection_model_weighting').val()
        let grouping = '";
        // line 73
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["grouping"] ?? null), "html", null, true);
        yield "'

        window.onload = function(){
            \$(\"#notationTable tr.notation\").each(function() {
                let row = this.id
                if(grouping == 'arrondissement'){
                    \$('#'+row+'_locationType').val('arrondissement');
                }else{
                    \$('#'+row+'_locationType').val('department');
                }
                locationTypeChange(row)
                calculTargetRate(row)
                calculLocationRate(row)
            });
        };

        \$(document).on('change', '#notation_collection_model_type, #notation_collection_model_entite, #notation_collection_model_programm', function () {
            let \$type = \$('#notation_collection_model_type')
            let \$entite = \$('#notation_collection_model_entite')
            let \$form = \$(this).closest('form')

            let data = {}
            data[\$type.attr('name')] = \$type.val()
            data[\$entite.attr('name')] = \$entite.val()
            data[\$(this).attr('name')] = \$(this).val()
            
            let \$field = \$(this).attr('id')
            \$.ajax({
                url: \$form.attr('action'),
                type: \$form.attr('method'),
                data: data,
                success: function(html) {
                    if (\$field == 'notation_collection_model_type') {
                        \$('#notation_collection_model_entite').replaceWith(
                            \$(html).find('#notation_collection_model_entite')
                        )
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_entite') {
                        \$('#notation_collection_model_programm').replaceWith(
                            \$(html).find('#notation_collection_model_programm')
                        )
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                    if (\$field == 'notation_collection_model_programm') {
                        \$('#notation_collection_model_action').replaceWith(
                            \$(html).find('#notation_collection_model_action')
                        )
                    }
                }
            });
        });


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

                        \$('#'+row+'_target').attr('required', false)
                        if (\$('#'+row+'_treated').is(':checked')) {
                            \$('#'+row+'_target').attr('required', true)
                        }                        
                    }
                    if (field == row+'_target') {
                        \$('#'+row+'_indicators').replaceWith(
                            \$(html).find('#'+row+'_indicators')
                        )
                    }
                }
            });
        }

        function locationTypeChange(row) {
            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                document.getElementById(row+'_arrondissements').disabled = true;
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                \$('#'+row+'_communes_div').hide();
                \$('#'+row+'_postes_div').show();
                document.getElementById(row+'_communes').disabled = true;
                document.getElementById(row+'_postes').disabled = false;
            } else {
                \$('#'+row+'_communes_div').show();
                \$('#'+row+'_postes_div').hide();
                document.getElementById(row+'_communes').disabled = false;
                document.getElementById(row+'_postes').disabled = true;
            }
        }

        function treatedChange(row) {
            let \$treated = \$('#'+row+'_treated')
            let \$nature = \$('#'+row+'_nature')
            let \$goal = \$('#'+row+'_goal')
            let \$target = \$('#'+row+'_target')
            let \$communes = \$('#'+row+'_communes')
            let \$postes = \$('#'+row+'_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 ? sel.options.length : 0; 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_collection_model_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(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())
            
            let targetRate = natureRate
            //let nbTotal = 0
            let nbSelec = 0
            if (natureRate && (natureRate - minRate) != 0) {
                document.getElementById(row+'_goal').disabled = false;
                document.getElementById(row+'_target').disabled = false;
                document.getElementById(row+'_indicators').disabled = false;
                document.getElementById(row+'_locationType').disabled = false;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = false;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = false;
                } else {
                    document.getElementById(row+'_communes').disabled = false;
                }

                nbSelec = getSelectedOptions(document.getElementById(row+'_indicators')).length
                //nbTotal = document.getElementById(row+'_indicators').options.length
                //if (nbTotal!=0) {
                //    targetRate = ((maxRate * nbSelec) + natureRate * (nbTotal - nbSelec)) / nbTotal
                //}
                if (nbSelec>0) {
                    targetRate = maxRate
                }
            } else {
                document.getElementById(row+'_goal').disabled = true;
                document.getElementById(row+'_target').disabled = true;
                document.getElementById(row+'_indicators').disabled = true;
                document.getElementById(row+'_locationType').disabled = true;
                if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                    document.getElementById(row+'_arrondissements').disabled = true;
                }else if (\$('#'+row+'_locationType').val() == 'poste') {
                    document.getElementById(row+'_postes').disabled = true;
                } else {
                    document.getElementById(row+'_communes').disabled = true;
                }
            }
            \$('#'+row+'_targetRate').val(targetRate)

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

            if (\$('#'+row+'_locationType').val() == 'arrondissement') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_arrondissements')).length
                nbTotal = document.getElementById(row+'_arrondissements') ? document.getElementById(row+'_arrondissements').options.length : 0
            }else if (\$('#'+row+'_locationType').val() == 'poste') {
                nbSelec = getSelectedOptions(document.getElementById(row+'_postes')).length
                nbTotal = document.getElementById(row+'_postes').options.length
            } else {
                nbSelec = getSelectedOptions(document.getElementById(row+'_communes')).length
                nbTotal = document.getElementById(row+'_communes') ? document.getElementById(row+'_communes').options.length : 0
            }
            if (nbTotal!=0) {
                locationRate = (nbSelec / nbTotal) * 100
            }
            \$('#'+row+'_locationRate').val(locationRate)

            calculSensitivity(row)
        }

        function calculSensitivity(row) {
            let natureRate = getSelectedRate(\$('#'+row+'_nature').val())

            let locationRate = \$('#'+row+'_locationRate').val()
            let sensitivity = \$('#'+row+'_targetRate').val()
            if (natureRate && (natureRate - minRate) != 0) {
                sensitivity = (sensitivity - ((100 - locationRate) / 10)) * weighting / 100
            }
            \$('#'+row+'_sensitivity').val(sensitivity)
            \$('#'+row+'_sensHtml').val(sensitivity)
        }
    </script>

    <script>
        \$(function () {
            \$(\"#notationTable\").DataTable({
                \"pageLength\": 25
            });
        });
    </script>

    <script src=\"";
        // line 323
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("plugins/datatables/jquery.dataTables.js"), "html", null, true);
        yield "\"></script>
    <script src=\"";
        // line 324
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("plugins/datatables-bs4/js/dataTables.bootstrap4.js"), "html", null, true);
        yield "\"></script>
";
        yield from [];
    }

    // line 327
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_stylesheets(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        // line 328
        yield "    <link rel=\"stylesheet\" href=\"";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("plugins/datatables-bs4/css/dataTables.bootstrap4.css"), "html", null, true);
        yield "\">
";
        yield from [];
    }

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

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

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  395 => 328,  388 => 327,  381 => 324,  377 => 323,  124 => 73,  118 => 69,  111 => 68,  103 => 64,  100 => 63,  96 => 61,  94 => 60,  91 => 59,  88 => 58,  85 => 29,  83 => 28,  80 => 27,  78 => 9,  72 => 7,  65 => 6,  54 => 3,  43 => 1,);
    }

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


/* plan/notation_form.html.twig */
class __TwigTemplate_a4fe0bd2e6f13ad19c73fd18f6a93014___839638903 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 = [
            'box_body' => [$this, 'block_box_body'],
        ];
    }

    protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
    {
        // line 9
        return "@AdminLTE/Widgets/box-widget.html.twig";
    }

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

    // line 10
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_box_body(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        // line 11
        yield "                <div class=\"text-right\">
                    <a href=\"";
        // line 12
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("app_evaluation", ["id" => ($context["actionId"] ?? null)]), "html", null, true);
        yield "\" class=\"btn btn-primary\">
                        ";
        // line 13
        yield $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->trans("basics.appreciation", [], "messages");
        yield "  <i class=\"fas fa-angle-double-right\"></i>
                    </a>
                </div><br>
                ";
        // line 16
        if ((($tmp = $this->extensions['Symfony\Bridge\Twig\Extension\SecurityExtension']->isGranted("ROLE_MANAGER")) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 17
            yield "                    ";
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "type", [], "any", false, false, false, 17), 'row');
            yield "
                    ";
            // line 18
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "entite", [], "any", false, false, false, 18), 'row');
            yield "
                ";
        }
        // line 20
        yield "                ";
        if ((($tmp = $this->extensions['Symfony\Bridge\Twig\Extension\SecurityExtension']->isGranted("ROLE_DDD")) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 21
            yield "                    ";
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "entite", [], "any", false, false, false, 21), 'row');
            yield "
                ";
        }
        // line 23
        yield "                ";
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "programm", [], "any", false, false, false, 23), 'row');
        yield "
                ";
        // line 24
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "action", [], "any", false, false, false, 24), 'row');
        yield "
            ";
        yield from [];
    }

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

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

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  513 => 24,  508 => 23,  502 => 21,  499 => 20,  494 => 18,  489 => 17,  487 => 16,  481 => 13,  477 => 12,  474 => 11,  467 => 10,  456 => 9,  395 => 328,  388 => 327,  381 => 324,  377 => 323,  124 => 73,  118 => 69,  111 => 68,  103 => 64,  100 => 63,  96 => 61,  94 => 60,  91 => 59,  88 => 58,  85 => 29,  83 => 28,  80 => 27,  78 => 9,  72 => 7,  65 => 6,  54 => 3,  43 => 1,);
    }

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


/* plan/notation_form.html.twig */
class __TwigTemplate_a4fe0bd2e6f13ad19c73fd18f6a93014___1529533935 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 = [
            'box_body' => [$this, 'block_box_body'],
        ];
    }

    protected function doGetParent(array $context): bool|string|Template|TemplateWrapper
    {
        // line 29
        return "@AdminLTE/Widgets/box-widget.html.twig";
    }

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

    // line 30
    /**
     * @return iterable<null|scalar|\Stringable>
     */
    public function block_box_body(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        // line 31
        yield "                ";
        // line 32
        $this->env->getRuntime("Symfony\\Component\\Form\\FormRenderer")->setTheme(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "notationModels", [], "any", false, false, false, 32), ["form/notation.html.twig"], true);
        // line 35
        yield "
                ";
        // line 36
        yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock(($context["form"] ?? null), 'errors');
        yield "

                <table id=\"notationTable\" 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>
                    ";
        // line 48
        $context["index"] = 0;
        // line 49
        yield "                    ";
        $context['_parent'] = $context;
        $context['_seq'] = CoreExtension::ensureTraversable(CoreExtension::getAttribute($this->env, $this->source, ($context["form"] ?? null), "notationModels", [], "any", false, false, false, 49));
        foreach ($context['_seq'] as $context["_key"] => $context["notation"]) {
            // line 50
            yield "                        ";
            yield $this->env->getRuntime('Symfony\Component\Form\FormRenderer')->searchAndRenderBlock($context["notation"], 'row', ["activity" => (($_v0 = ($context["activities"] ?? null)) && is_array($_v0) || $_v0 instanceof ArrayAccess ? ($_v0[($context["index"] ?? null)] ?? null) : null)]);
            yield "
                        ";
            // line 51
            $context["index"] = (($context["index"] ?? null) + 1);
            // line 52
            yield "                    ";
        }
        $_parent = $context['_parent'];
        unset($context['_seq'], $context['_key'], $context['notation'], $context['_parent']);
        $context = array_intersect_key($context, $_parent) + $_parent;
        // line 53
        yield "                </tbody>
                </table>

            ";
        yield from [];
    }

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

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

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  633 => 53,  627 => 52,  625 => 51,  620 => 50,  615 => 49,  613 => 48,  598 => 36,  595 => 35,  593 => 32,  591 => 31,  584 => 30,  573 => 29,  513 => 24,  508 => 23,  502 => 21,  499 => 20,  494 => 18,  489 => 17,  487 => 16,  481 => 13,  477 => 12,  474 => 11,  467 => 10,  456 => 9,  395 => 328,  388 => 327,  381 => 324,  377 => 323,  124 => 73,  118 => 69,  111 => 68,  103 => 64,  100 => 63,  96 => 61,  94 => 60,  91 => 59,  88 => 58,  85 => 29,  83 => 28,  80 => 27,  78 => 9,  72 => 7,  65 => 6,  54 => 3,  43 => 1,);
    }

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