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

{% block main %}

    {% trans_default_domain 'admin' %}

    {% if notAllowed|default(false) %}
        <div data-modal-hide-close>
            <div>
                <div class="mx-auto flex size-12 items-center justify-center rounded-full bg-red-100 dark:bg-red-600/70">
                    <span class="block h-6 w-6 text-red-600 dark:text-red-100/90"><twig:ux:icon name="ph:warning" /></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">Aktion nicht möglich</h3>
                    <div class="mt-2">
                        <p class="text-sm text-gray-500 dark:text-gray-400">
                            Dieses Angebot kann derzeit nicht wiederhergestellt werden. Ist das Angebot gar nicht abgesagt worden oder liegt es in der Vergangenheit?
                        </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">Schließen</twig:Admin:Button>
            </div>
        </div>
    {% else %}

    {{ form_start(relaunch, {
        attr: { 'data-turbo-frame': '_top' }
    }) }}

    <div class="sm:flex sm:items-start">
        <div class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 dark:bg-red-600/70 sm:mx-0 sm:h-10 sm:w-10">
            <span class="block h-6 w-6 text-red-600 dark:text-red-100/90"><twig:ux:icon name="ph:warning" /></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">{{ 'offers.relaunchModal.headline'|trans }}</h3>
            <div class="mt-2"
             data-controller="ferienpass--admin-reveal">
                <p class="text-sm leading-5 text-gray-500 dark:text-gray-300">
                    {{ 'offers.relaunchModal.confirm'|trans }}
                </p>


                <div class="mt-6">
                    {% include '@FerienpassAdmin/fragment/_modal_dl.html.twig' with { metadata: {
                        name: '{{ offer.name }}',
                        date: '
{% if offer.dates is not empty %}
    {% set startDate = offer.dates|first.begin %}
    {% if startDate %}
        <time datetime="{{ startDate|date(\'c\') }}">{{ startDate|format_datetime(pattern="E, dd.MM.yyyy HH:mm") }}</time>
    {% else %}
        <span class="inline-flex items-center text-orange-600">
            {{ ux_icon(\'ph:warning\', {class: \'mr-1 size-4\'}) }}
            <span>Termin fehlt</span>
        </span>
    {% endif %}
{% else %}
    <span>Dauerangebot</span>
{% endif %}
',
                        attendances: '
                <p class="flex items-center space-x-1" title="aktuelle Anmeldungen">
                    <span class="{{ (offer.maxParticipants and offer.attendancesConfirmed|length >= offer.maxParticipants) ? \'text-red-700\' : \'text-green-700\' }}">
                        <svg viewBox="0 0 2 2" class="h-2 w-2 fill-current">
                            <circle cx="1" cy="1" r="1"/>
                        </svg>
                    </span>

                    <span>
                        {{ offer.attendancesNotHidden|length ~ \' / \' ~ (offer.maxParticipants ?: \'∞\') ~ \'\' }}
                    </span>
                </p>
',
                    }} %}
                </div>

                <p class="text-sm font-bold leading-5 text-gray-600 dark:text-gray-300 mt-2">
                    {% if offer.onlineApplication %}
                        <span>{{ 'offers.relaunchModal.notificationsConfirmed'|trans({count: offer.attendancesConfirmed|length}) }}</span>
                        {% set otherAttendances = offer.attendancesWithStatuses(['waitlisted', 'withdrawn', 'unfulfilled', 'waiting']) %}
                        {% if otherAttendances is not empty %}
                            <span class="font-normal">{{ 'offers.relaunchModal.notificationsUnconfirmed'|trans({count: otherAttendances|length}) }}</span>
                        {% endif %}
                        <span class="font-normal">{{ 'offers.relaunchModal.notificationsDispatch'|trans }}</span>
                         <a href="#"
                           data-action="ferienpass--admin-reveal#toggle:prevent"
                           class="font-normal underline hover:no-underline">E-Mail-Text vor Versand
                            anpassen.</a>
                    {% endif %}
                </p>

                   <div
                        data-ferienpass--admin-reveal-target="item"
                        data-transition-enter="transition ease-out duration-100"
                        data-transition-enter-start="transform opacity-0"
                        data-transition-enter-end="transform opacity-100"
                        data-transition-leave="transition ease-in duration-75"
                        data-transition-leave-start="transform opacity-100"
                        data-transition-leave-end="transform opacity-0"
                        class="hidden mt-6 pt-6 border-t border-gray-100 dark:border-gray-700">
                    {{ form_row(relaunch.notifyText) }}
                </div>

            </div>
        </div>
    </div>
    <div class="mt-5 sm:mt-4 sm:ml-10 sm:flex sm:pl-4 sm:gap-3">

        <twig:Admin:Button variant="destructive" type="submit" class="inline-flex w-full justify-center sm:w-auto">{{ 'offers.relaunchModal.submit'|trans }}</twig:Admin:Button>
        <twig:Admin:Button command="close" commandfor="admin-modal-dialog" class="mt-3 sm:mt-0 inline-flex w-full justify-center sm:w-auto">Abbrechen</twig:Admin:Button>
    </div>

    {{ form_end(relaunch) }}

    {% endif %}

{% endblock %}

{% block success_stream %}
    <twig:Turbo:Stream:Update target="#modal"/>
    <twig:Turbo:Stream:Prepend target="#notifications">
        <twig:Admin:Notification type="success" title="{{ 'offers.status.relaunched'|trans({}, 'admin') }}" message="{{ 'offers.status.relaunched_help'|trans({}, 'admin') }}"/>
        {% if offer.onlineApplication %}
            <twig:Admin:Notification type="mail_sent" title="Rundmail versendet" dismissAfter="0" primaryActionTitle="Versandnachweis öffnen" primaryActionLink="{{ path('admin_tools_dispatch', {uuid: transitionUuid}) }}"/>
        {% endif %}
    </twig:Turbo:Stream:Prepend>
{% endblock %}
