{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% extends "pages/admin/form/condition_configuration.html.twig" %}

{# Compute strategy, with a fallback to "Always visible" #}
{% if item is null %}
    {% set submit_button_strategy = enum('Glpi\\Form\\Condition\\VisibilityStrategy').ALWAYS_VISIBLE %}
{% else %}
    {% set submit_button_strategy = item.getConfiguredVisibilityStrategy() %}
{% endif %}

{% block conditions_editor %}
    <div
        data-glpi-form-editor-visibility-dropdown-container
        class="btn-group pe-0"
    >
        <button
            title="{{ __('Configure visibility') }}"
            data-bs-toggle="dropdown"
            data-bs-auto-close="outside"
            class="dropdown-toggle btn btn-outline-secondary px-2"
            data-bs-placement="top"
            type="button"
            data-glpi-form-editor-visibility-dropdown
        >
            {% for strategy in enum_cases('Glpi\\Form\\Condition\\VisibilityStrategy') %}
                {% set is_visible = submit_button_strategy == strategy %}
                {% set display_class = is_visible ? 'd-flex' : 'd-none' %}
                <div
                    class="{{ display_class }} align-items-center"
                    data-glpi-editor-visibility-badge="{{ strategy.value }}"
                >
                    <i class="{{ strategy.getIcon() }} me-1"></i>
                    <span>{{ strategy.getLabel() }}</span>
                </div>
            {% endfor %}
        </button>
        <div
            class="dropdown-menu dropdown-menu-end dropdown-menu-card animate__animated animate__zoomIn"
        >
            <div class="card visibility-dropdown-card" data-glpi-form-editor-on-click="stop-propagation">
                <div class="card-body">
                    <h3 class="card-title d-flex align-items-center">
                        <i class="ti ti-circuit-changeover me-2"></i>
                        {{ __('Conditional visibility') }}
                    </h3>

                    {# Parent properties #}
                    {% set strategies = 'Glpi\\Form\\Condition\\VisibilityStrategy' %}
                    {% set selected_strategy = submit_button_strategy %}
                    {% set strategy_input_name = "submit_button_visibility_strategy" %}
                    {% set conditions = item is not null ? item.getConfiguredConditionsData() : [] %}
                    {{ parent() }}
                </div>
            </div>
        </div>
    </div>
{% endblock %}
