{% extends "@FerienpassAdmin/layout/modalBase.html.twig" %}

{% trans_default_domain 'admin' %}
{% set translationPrefix = app.request.get('_route')|split('_')[1] %}

{% block main %}

    {% set can_duplicate_in_current = is_granted('offer.create', item.edition) %}
    {% set other_editions = not is_granted('ROLE_ADMIN') ? editions|filter(e => e.id != item.edition.id and is_granted('offer.create', e)) : [] %}
    {% set has_options = can_duplicate_in_current or other_editions|length > 0 %}

    {% if not has_options %}
        <div data-modal-hide-close>
            <div>
                <div class="mx-auto flex size-12 items-center justify-center rounded-full bg-green-100 dark:bg-green-600/70">
                    <span class="block h-6 w-6 text-green-600 dark:text-green-100/90">{{ ux_icon('ph:copy') }}</span>
                </div>
                <div class="mt-3 text-center sm:mt-5">
                    <h3 class="text-base font-semibold text-gray-900 dark:text-white"
                        id="modal-headline">Angebot kopieren</h3>
                    <div class="mt-2">
                        <p class="text-sm text-gray-500 dark:text-gray-400">
                            Leider steht die Kopieren-Funktion nicht zur Verfügung, weil sie von einem Administrator deaktiviert wurde.
                        </p>
                    </div>
                </div>
            </div>
            <div class="mt-5 sm:mt-6">
                <twig:Admin:Button variant="destructive" command="close" commandfor="admin-modal-dialog" class="inline-flex w-full justify-center">Abbrechen</twig:Admin:Button>
            </div>
        </div>
    {% else %}
        <div class="sm:flex sm:items-center">
            <div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 dark:bg-green-600/70 sm:mx-0 sm:h-10 sm:w-10">
                <span class="block h-6 w-6 text-green-600 dark:text-green-100/90">{{ ux_icon('ph:copy') }}</span>
            </div>
            <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
                <h3 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100"
                    id="modal-headline">Angebot kopieren</h3>
                <p class="text-sm text-gray-700 dark:text-gray-200">
                    Bitte wählen Sie eine der nachfolgenden Optionen.
                </p>
            </div>
        </div>

        <div class="mt-4 space-y-2">
            {% if can_duplicate_in_current %}
                <a href="{{ path('admin_offers_new_variant', { uuid: (item.variant ? item.variantBase.uuid : item.uuid).toBase58 }) }}"
                   data-turbo-frame="_top"
                   class="rounded-md bg-white group cursor-pointer border border-gray-200 hover:border-primary-700 p-4 focus:outline-none hover:bg-primary-50 flex flex-col">
                    <span class="block text-sm font-medium text-gray-900 group-hover:text-primary-900">Neuen Termin für
                        gleiches Angebot erstellen</span>
                    <span class="block text-sm text-gray-500 group-hover:text-primary-800">Sie bieten das Angebot
                        mehrmals für eine andere Gruppe von Teilnehmenden an. Alle Angebot-Infos bleiben dann gleich.</span>
                </a>

                <a href="{{ path('admin_offers_copy', { uuid: item.uuid.toBase58 }) }}"
                   data-turbo-frame="_top"
                   class="rounded-md bg-white group cursor-pointer border border-gray-200 hover:border-primary-700 p-4 focus:outline-none hover:bg-primary-50 flex flex-col">
                    <span class="block text-sm font-medium text-gray-900 group-hover:text-primary-900">Angebot
                        kopieren</span>
                    <span class="block text-sm text-gray-500 group-hover:text-primary-800">
                        {% if item.edition %}
                            Eine unabhängige Kopie wird in »{{ item.edition.name }}« erstellt.
                        {% else %}
                            Eine unabhängige Kopie wird erstellt.
                        {% endif %}
                    </span>
                </a>
            {% endif %}

            {% for edition in other_editions %}
                <a href="{{ path('admin_offers_copy_to_edition', { uuid: item.uuid.toBase58, edition: edition.alias }) }}"
                   data-turbo-frame="_top"
                   class="rounded-md bg-white group cursor-pointer border border-gray-200 hover:border-primary-700 p-4 focus:outline-none hover:bg-primary-50 flex flex-col">
                    <span class="block text-sm font-medium text-gray-900 group-hover:text-primary-900">Angebot nach
                        »{{ edition.name }}« kopieren</span>
                    <span class="block text-sm text-gray-500 group-hover:text-primary-800">Eine unabhängige Kopie wird
                        in »{{ edition.name }}« erstellt.</span>
                </a>
            {% endfor %}
        </div>
    {% endif %}
{% endblock %}
