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

/* components/form/viewsubitem.html.twig */
class __TwigTemplate_5132306326d5c1d89345cd7b418e1c60 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 "
";
        // line 33
        $context["rand"] = Html::sanitizeDomId(((array_key_exists("rand", $context)) ? (Twig\Extension\CoreExtension::default(($context["rand"] ?? null), Twig\Extension\CoreExtension::random($this->env->getCharset()))) : (Twig\Extension\CoreExtension::random($this->env->getCharset()))));
        // line 34
        $context["subitem_container_id"] = ((array_key_exists("subitem_container_id", $context)) ? (Twig\Extension\CoreExtension::default(($context["subitem_container_id"] ?? null), ("viewsubitem" . ($context["rand"] ?? null)))) : (("viewsubitem" . ($context["rand"] ?? null))));
        // line 35
        $context["ajax_form_submit"] = ((array_key_exists("ajax_form_submit", $context)) ? (Twig\Extension\CoreExtension::default(($context["ajax_form_submit"] ?? null), false)) : (false));
        // line 36
        $context["reload_tab"] = ((array_key_exists("reload_tab", $context)) ? (Twig\Extension\CoreExtension::default(($context["reload_tab"] ?? null), false)) : (false));
        // line 37
        $context["as_modal"] = ((array_key_exists("as_modal", $context)) ? (Twig\Extension\CoreExtension::default(($context["as_modal"] ?? null), false)) : (false));
        // line 38
        $context["add_new_label"] = ((array_key_exists("add_new_label", $context)) ? (Twig\Extension\CoreExtension::default(($context["add_new_label"] ?? null), __("Add"))) : (__("Add")));
        // line 39
        $context["add_new_inline"] = ((array_key_exists("add_new_inline", $context)) ? (Twig\Extension\CoreExtension::default(($context["add_new_inline"] ?? null), false)) : (false));
        // line 40
        yield "
";
        // line 41
        if ((($tmp = ($context["as_modal"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 42
            yield "<div class=\"modal fade\" id=\"";
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($context["subitem_container_id"] ?? null) . "_modal"), "html", null, true);
            yield "\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">
    <div class=\"modal-dialog modal-xl\" role=\"document\">
        <div class=\"modal-content\">
            <div class=\"modal-header\">
                <h1 class=\"modal-title fs-4\">";
            // line 46
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(((array_key_exists("modal_title", $context)) ? (Twig\Extension\CoreExtension::default(($context["modal_title"] ?? null), ($context["add_new_label"] ?? null))) : (($context["add_new_label"] ?? null))), "html", null, true);
            yield "</h1>
                <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"";
            // line 47
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(_x("button", "Close"), "html", null, true);
            yield "\"></button>
            </div>
            <div class=\"modal-body overflow-auto mb-n5\">
";
        }
        // line 51
        yield "<div id='";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["subitem_container_id"] ?? null), "html", null, true);
        yield "'></div>
";
        // line 52
        if ((($tmp = ($context["as_modal"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 53
            yield "            </div>
        </div>
    </div>
</div>
";
        }
        // line 58
        yield "
<script>
    function viewAddEditSubItem";
        // line 60
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "(id) {
        const modal_el = \$('#";
        // line 61
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($context["subitem_container_id"] ?? null) . "_modal"), "css"), "js"), "html", null, true);
        yield "');
        if (modal_el.length) {
            modal_el[0].addEventListener('shown.bs.modal', (event) => {
                event.target.setAttribute('data-cy-ready', 'true');
            });
            modal_el[0].addEventListener('hidden.bs.modal', (event) => {
                event.target.removeAttribute('data-cy-ready');
            });
        }
        \$('#";
        // line 70
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["subitem_container_id"] ?? null), "html", null, true);
        yield "').load('";
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Glpi\Application\View\Extension\RoutingExtension']->path("/ajax/viewsubitem.php"), "js"), "html", null, true);
        yield "',{
            type: \"";
        // line 71
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["type"] ?? null), "js"), "html", null, true);
        yield "\",
            parenttype: \"";
        // line 72
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["parenttype"] ?? null), "js"), "html", null, true);
        yield "\",
            '";
        // line 73
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["items_id"] ?? null), "js"), "html", null, true);
        yield "': ";
        yield json_encode(($context["id"] ?? null));
        yield ",
            id: id
        }, () => {
            if (modal_el.length) {
                modal_el.modal('show');
            }
        });
    }
    \$(() => {
        const modal_el = \$('#";
        // line 82
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape((($context["subitem_container_id"] ?? null) . "_modal"), "css"), "js"), "html", null, true);
        yield "');

        ";
        // line 84
        if (array_key_exists("datatable_id", $context)) {
            // line 85
            yield "            \$('#";
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["datatable_id"] ?? null), "css"), "js"), "html", null, true);
            yield "').on('click', 'tbody tr', (e) => {
                if (\$(e.target).closest('td').find('.massive_action_checkbox').length > 0) {
                    return;
                }
                const subitem_id = \$(e.currentTarget).data('id');
                if (subitem_id) {
                    viewAddEditSubItem";
            // line 91
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
            yield "(subitem_id);
                }
            });
        ";
        }
        // line 95
        yield "
        \$('#addsubitem";
        // line 96
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "').on('click', (e) => {
            viewAddEditSubItem";
        // line 97
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
        yield "(-1);
        });
        const subitem_container = \$('#";
        // line 99
        yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["subitem_container_id"] ?? null), "css"), "js"), "html", null, true);
        yield "');
        subitem_container.on('submit', 'form', (e) => {
            ";
        // line 101
        if ((($tmp = ($context["ajax_form_submit"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 102
            yield "                e.preventDefault();
                let form_data = \$(e.target).serialize();
                // Add submitter button name/value to form data
                const submit_btn = \$(e.originalEvent.submitter);
                form_data += '&' + submit_btn.attr('name') + '=' + submit_btn.val();

                const on_finish = () => {
                    displayAjaxMessageAfterRedirect();
                    if (modal_el.length) {
                        modal_el.modal('hide');
                    }
                };
                const on_success = () => {
                    \$(e.target).trigger('glpi:submit:success', {
                        submitter: submit_btn,
                    });
                    on_finish();
                    ";
            // line 119
            if ((($tmp = ($context["reload_tab"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
                // line 120
                yield "                        window.reloadTab();
                    ";
            }
            // line 122
            yield "                };
                const on_error = () => {
                    \$(e.target).trigger('glpi:submit:error', {
                        submitter: submit_btn,
                    });
                    on_finish();
                };
                \$.post(\$(e.target).attr('action'), form_data).then(on_success, on_error);
            ";
        }
        // line 131
        yield "        });
    });
</script>
";
        // line 134
        if ((($tmp = ($context["cancreate"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
            // line 135
            yield "    ";
            if ((($tmp =  !($context["add_new_inline"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
                // line 136
                yield "        <div class=\"firstbloc\">
    ";
            }
            // line 138
            yield "        <button id=\"addsubitem";
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["rand"] ?? null), "html", null, true);
            yield "\" type=\"button\" class=\"btn ";
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(((array_key_exists("add_new_btn_class", $context)) ? (Twig\Extension\CoreExtension::default(($context["add_new_btn_class"] ?? null), "btn-primary")) : ("btn-primary")), "html", null, true);
            yield " ms-1\" name=\"add\">
            <i class=\"ti ti-link\"></i>
            ";
            // line 140
            yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["add_new_label"] ?? null), "html", null, true);
            yield "
        </button>
    ";
            // line 142
            if ((($tmp =  !($context["add_new_inline"] ?? null)) && $tmp instanceof Markup ? (string) $tmp : $tmp)) {
                // line 143
                yield "        </div>
    ";
            }
        }
        yield from [];
    }

    /**
     * @codeCoverageIgnore
     */
    public function getTemplateName(): string
    {
        return "components/form/viewsubitem.html.twig";
    }

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

    /**
     * @codeCoverageIgnore
     */
    public function getDebugInfo(): array
    {
        return array (  253 => 143,  251 => 142,  246 => 140,  238 => 138,  234 => 136,  231 => 135,  229 => 134,  224 => 131,  213 => 122,  209 => 120,  207 => 119,  188 => 102,  186 => 101,  181 => 99,  176 => 97,  172 => 96,  169 => 95,  162 => 91,  152 => 85,  150 => 84,  145 => 82,  131 => 73,  127 => 72,  123 => 71,  117 => 70,  105 => 61,  101 => 60,  97 => 58,  90 => 53,  88 => 52,  83 => 51,  76 => 47,  72 => 46,  64 => 42,  62 => 41,  59 => 40,  57 => 39,  55 => 38,  53 => 37,  51 => 36,  49 => 35,  47 => 34,  45 => 33,  42 => 32,);
    }

    public function getSourceContext(): Source
    {
        return new Source("", "components/form/viewsubitem.html.twig", "/home/tisoluci/public_html/crpamplona/templates/components/form/viewsubitem.html.twig");
    }
}
