<?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;

/* pages/admin/customobjects/translations.html.twig */
class __TwigTemplate_e2d47ff02d9d4e1b567e255657909f7e 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->parent = false;

        $this->blocks = [
        ];
    }

    protected function doDisplay(array $context, array $blocks = []): iterable
    {
        $macros = $this->macros;
        // line 32
        yield "
<div class=\"modal fade\" id=\"TranslationModal";
        // line 33
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\" tabindex=\"-1\" role=\"dialog\">
    <div class=\"modal-dialog\" role=\"document\">
        <div class=\"modal-content\">
            <form method=\"POST\" action=\"";
        // line 36
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Glpi\Application\View\Extension\ItemtypeExtension']->getItemtypeFormPath(get_class(($context["item"] ?? null))), "html", null, true);
        yield "\">
                <input type=\"hidden\" name=\"id\" value=\"";
        // line 37
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v0 = CoreExtension::getAttribute($this->env, $this->source, ($context["item"] ?? null), "fields", [], "any", false, false, false, 37)) && is_array($_v0) || $_v0 instanceof ArrayAccess ? ($_v0["id"] ?? null) : null), "html", null, true);
        yield "\">
                <input type=\"hidden\" name=\"_glpi_csrf_token\" value=\"";
        // line 38
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(Session::getNewCSRFToken(), "html", null, true);
        yield "\" />
                <input type=\"hidden\" name=\"_save_translation\" value=\"1\" />

                <div class=\"modal-header\">
                    <h4 class=\"modal-title\">";
        // line 42
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Add translation"), "html", null, true);
        yield "</h4>
                    <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"";
        // line 43
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Close"), "html", null, true);
        yield "\"></button>
                </div>
                <div class=\"modal-body\">
                    <div id=\"field_dropdown_container\" class=\"mb-3\">
                        <label class=\"form-label\" for=\"dropdown_field";
        // line 47
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\">";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Asset name / Field"), "html", null, true);
        yield "</label>
                        ";
        // line 48
        yield ($context["fields_dropdown"] ?? null);
        yield "
                    </div>
                    <div class=\"mb-3\">
                        <label class=\"form-label\" for=\"dropdown_language";
        // line 51
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\">";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Language"), "html", null, true);
        yield "</label>
                        ";
        // line 52
        yield ($context["languages_dropdown"] ?? null);
        yield "
                    </div>

                    <div class=\"mb-3\" id=\"translations_panel";
        // line 55
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\">
                    </div>

                </div>
                <div class=\"modal-footer\">
                    <button type=\"submit\" class=\"btn btn-primary\" name=\"update\">
                        <i id=\"translation-modal-button-icon";
        // line 61
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\"></i>
                        <span id=\"translation-modal-button-text";
        // line 62
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\"></span>
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class=\"d-flex\">
    <button type=\"button\" class=\"btn btn-primary add-translation\" data-bs-toggle=\"modal\" data-bs-target=\"#TranslationModal";
        // line 71
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\">
        <i class=\"ti ti-plus\"></i>
        <span>";
        // line 73
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("New translation"), "html", null, true);
        yield "</span>
    </button>
</div>

<div class=\"table-responsive mt-3\">
    ";
        // line 78
        if ((Twig\Extension\CoreExtension::length($this->env->getCharset(), ($context["translations"] ?? null)) == 0)) {
            // line 79
            yield "        <span class=\"text-muted\">";
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("No translation has been added yet"), "html", null, true);
            yield "</span>
    ";
        } else {
            // line 81
            yield "        <table class=\"table\">
            <thead>
            <tr>
                <th><i class=\"ti ti-forms me-1\"></i>";
            // line 84
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Asset name / Field"), "html", null, true);
            yield "</th>
                <th><i class=\"ti ti-language me-1\"></i>";
            // line 85
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Language"), "html", null, true);
            yield "</th>
                <th># ";
            // line 86
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Translations"), "html", null, true);
            yield "</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
                ";
            // line 91
            $context['_parent'] = $context;
            $context['_seq'] = CoreExtension::ensureTraversable(($context["translations"] ?? null));
            foreach ($context['_seq'] as $context["_key"] => $context["trans_data"]) {
                // line 92
                yield "                    <tr data-field=\"";
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v1 = $context["trans_data"]) && is_array($_v1) || $_v1 instanceof ArrayAccess ? ($_v1["id"] ?? null) : null), "html", null, true);
                yield "\" data-language=\"";
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v2 = $context["trans_data"]) && is_array($_v2) || $_v2 instanceof ArrayAccess ? ($_v2["language"] ?? null) : null), "html", null, true);
                yield "\" data-translation=\"";
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(json_encode((($_v3 = $context["trans_data"]) && is_array($_v3) || $_v3 instanceof ArrayAccess ? ($_v3["translation"] ?? null) : null)), "html", null, true);
                yield "\">
                        <td>";
                // line 93
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v4 = $context["trans_data"]) && is_array($_v4) || $_v4 instanceof ArrayAccess ? ($_v4["name"] ?? null) : null), "html", null, true);
                yield "</td>
                        <td lang=\"";
                // line 94
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v5 = $context["trans_data"]) && is_array($_v5) || $_v5 instanceof ArrayAccess ? ($_v5["language"] ?? null) : null), "html", null, true);
                yield "\">";
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v6 = (($_v7 = $this->extensions['Glpi\Application\View\Extension\ConfigExtension']->config("languages")) && is_array($_v7) || $_v7 instanceof ArrayAccess ? ($_v7[(($_v8 = $context["trans_data"]) && is_array($_v8) || $_v8 instanceof ArrayAccess ? ($_v8["language"] ?? null) : null)] ?? null) : null)) && is_array($_v6) || $_v6 instanceof ArrayAccess ? ($_v6[0] ?? null) : null), "html", null, true);
                yield "</td>
                        <td lang=\"";
                // line 95
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v9 = $context["trans_data"]) && is_array($_v9) || $_v9 instanceof ArrayAccess ? ($_v9["language"] ?? null) : null), "html", null, true);
                yield "\">
                            ";
                // line 96
                yield from $this->load("pages/admin/customobjects/plurals.html.twig", 96)->unwrap()->yield(CoreExtension::toArray(["plurals" => (($_v10 =                 // line 97
$context["trans_data"]) && is_array($_v10) || $_v10 instanceof ArrayAccess ? ($_v10["translation"] ?? null) : null)]));
                // line 99
                yield "                        </td>
                        <td>
                            <div title=\"";
                // line 101
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Edit translation"), "html", null, true);
                yield "\" class=\"d-inline\" data-bs-toggle=\"tooltip\" data-bs-placement=\"top\">
                                <button type=\"button\" class=\"btn btn-sm btn-icon btn-ghost-secondary edit-translation\" data-bs-toggle=\"modal\">
                                    <i class=\"ti ti-pencil\"></i>
                                </button>
                            </div>
                            <div title=\"";
                // line 106
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Delete translation"), "html", null, true);
                yield "\" class=\"d-inline\" data-bs-toggle=\"tooltip\" data-bs-placement=\"top\">
                                <form method=\"POST\" action=\"";
                // line 107
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Glpi\Application\View\Extension\ItemtypeExtension']->getItemtypeFormPath(get_class(($context["item"] ?? null))), "html", null, true);
                yield "\" class=\"d-inline\">
                                    <input type=\"hidden\" name=\"id\" value=\"";
                // line 108
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v11 = CoreExtension::getAttribute($this->env, $this->source, ($context["item"] ?? null), "fields", [], "any", false, false, false, 108)) && is_array($_v11) || $_v11 instanceof ArrayAccess ? ($_v11["id"] ?? null) : null), "html", null, true);
                yield "\">
                                    <input type=\"hidden\" name=\"_glpi_csrf_token\" value=\"";
                // line 109
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(Session::getNewCSRFToken(), "html", null, true);
                yield "\" />
                                    <input type=\"hidden\" name=\"_delete_translation\" value=\"1\" />
                                    <input type=\"hidden\" name=\"field\" value=\"";
                // line 111
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v12 = $context["trans_data"]) && is_array($_v12) || $_v12 instanceof ArrayAccess ? ($_v12["id"] ?? null) : null), "html", null, true);
                yield "\" />
                                    <input type=\"hidden\" name=\"language\" value=\"";
                // line 112
                yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($_v13 = $context["trans_data"]) && is_array($_v13) || $_v13 instanceof ArrayAccess ? ($_v13["language"] ?? null) : null), "html", null, true);
                yield "\" />
                                    <button type=\"submit\" name=\"update\" class=\"btn btn-sm btn-icon btn-ghost-danger\">
                                        <i class=\"ti ti-trash-x\"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                ";
            }
            $_parent = $context['_parent'];
            unset($context['_seq'], $context['_key'], $context['trans_data'], $context['_parent']);
            $context = array_intersect_key($context, $_parent) + $_parent;
            // line 121
            yield "            </tbody>
        </table>
    ";
        }
        // line 124
        yield "</div>

<script>
    \$(() => {
        \$('#TranslationModal";
        // line 128
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=\"language\"]').on('change', function() {
            const field_selection = \$('#TranslationModal";
        // line 129
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=\"field\"]').val();
            setModalLanguagePlural(field_selection, \$(this).val());
        });
        \$('#TranslationModal";
        // line 132
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=\"field\"]').on('change', function() {
            const lang_selection = \$('#TranslationModal";
        // line 133
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=\"language\"]').val();
            setModalLanguagePlural(\$(this).val(), lang_selection);
        });
        \$('.add-translation').on('click', () => {
            // empty the old plural inputs
            \$('#translations_panel";
        // line 138
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').html(\"\");

            // reset the language dropdown
            \$('#TranslationModal";
        // line 141
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=language]').val('').trigger('change');

            \$('#translation-modal-button-icon";
        // line 143
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').attr('class', '').addClass('ti ti-plus');
            \$('#translation-modal-button-text";
        // line 144
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').text(\"";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Add"), "html", null, true);
        yield "\");
        });

        \$('.edit-translation').on('click', (e) => {
            const target_row = \$(e.target).closest('tr');
            const language = target_row.data('language');
            const plurals = target_row.data('translation');
            const field = target_row.data('field') ?? 0;

            \$('#dropdown_language";
        // line 153
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').val(language);
            setModalLanguagePlural(field, language, plurals);

            \$('#translation-modal-button-icon";
        // line 156
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').attr('class', '').addClass('ti ti-device-floppy');
            \$('#translation-modal-button-text";
        // line 157
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').text(\"";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(__("Save"), "html", null, true);
        yield "\");

            \$('#TranslationModal";
        // line 159
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').modal('show');
        });

        let avoid_language_recursion = false;
        const setModalLanguagePlural = (field, language, plurals_values) => {
            if (avoid_language_recursion) {
                return;
            }

            plurals_values = plurals_values || {};

            // empty the old plural inputs
            \$('#translations_panel";
        // line 171
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').html(\"\");

            // Set the language dropdown value (we redo it for edit case)
            avoid_language_recursion = true;
            \$('#TranslationModal";
        // line 175
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=\"field\"]').val(field).trigger('change');
            \$('#TranslationModal";
        // line 176
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield " select[name=\"language\"]').val(language).trigger('change');
            avoid_language_recursion = false;

            const plurals_promise = (field === null || parseInt(field) === 0) ?
                \$.ajax({url: \"";
        // line 180
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Glpi\Application\View\Extension\RoutingExtension']->path("ajax/getPlurals.php"), "html", null, true);
        yield "\", data: {language: language}})
                : Promise.resolve([
                    {id: 'one', formula: 'n = 1', examples: '1'},
                ]);

            plurals_promise.then((data) => {
                // Append new input for each plural in data
                data.forEach((pluralForm) => {
                    let helper = pluralForm.examples;
                    if (pluralForm.formula) {
                        helper = pluralForm.formula + ' (' + pluralForm.examples + ')';
                    }

                    const plural_value = plurals_values[pluralForm.id] || '';
                    const plural_html = `
                    <div class=\"mb-2\">
                        <label class=\"form-label\" for=\"plural_\${pluralForm.id}";
        // line 196
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\">
                            \${pluralForm.id}
                            <span class=\"form-help\" data-bs-toggle=\"popover\" data-bs-placement=\"top\" data-bs-html=\"true\"
                                  data-bs-content=\"\${helper}\">
                                <i class=\"ti ti-help\"></i>
                            </span>
                        </label>
                        <input type=\"text\" class=\"form-control\" id=\"plural_\${pluralForm.id}";
        // line 203
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "\" name=\"plurals[\${pluralForm.id}]\" value=\"\${plural_value}\">
                    </div>
                `;
                    \$('#translations_panel";
        // line 206
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').append(plural_html);
                });
                window.initTooltips(\$('#translations_panel";
        // line 208
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').get(0));
            });
        };
    });
</script>
";
        yield from [];
    }

    /**
     * @codeCoverageIgnore
     */
    public function getTemplateName(): string
    {
        return "pages/admin/customobjects/translations.html.twig";
    }

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

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  398 => 208,  393 => 206,  387 => 203,  377 => 196,  358 => 180,  351 => 176,  347 => 175,  340 => 171,  325 => 159,  318 => 157,  314 => 156,  308 => 153,  294 => 144,  290 => 143,  285 => 141,  279 => 138,  271 => 133,  267 => 132,  261 => 129,  257 => 128,  251 => 124,  246 => 121,  231 => 112,  227 => 111,  222 => 109,  218 => 108,  214 => 107,  210 => 106,  202 => 101,  198 => 99,  196 => 97,  195 => 96,  191 => 95,  185 => 94,  181 => 93,  172 => 92,  168 => 91,  160 => 86,  156 => 85,  152 => 84,  147 => 81,  141 => 79,  139 => 78,  131 => 73,  126 => 71,  114 => 62,  110 => 61,  101 => 55,  95 => 52,  89 => 51,  83 => 48,  77 => 47,  70 => 43,  66 => 42,  59 => 38,  55 => 37,  51 => 36,  45 => 33,  42 => 32,);
    }

    public function getSourceContext(): Source
    {
        return new Source("", "pages/admin/customobjects/translations.html.twig", "/home/tisoluci/public_html/crpamplona/templates/pages/admin/customobjects/translations.html.twig");
    }
}
