{% extends "@FerienpassAdmin/layout/list.html.twig" %}
{% trans_default_domain 'admin' %}

{% block main %}
    {% set isSlideOver = app.request.headers.get('turbo-frame') == 'slideover' %}
    {% if isSlideOver %}
        <h2 class="sr-only">{{ 'offers.participants_label'|trans({}, 'admin') }} {{ offer.name }}</h2>
    {% endif %}
    <div class="mb-4 @lg:mb-8">
        <twig:Admin:Offer:Header offer="{{ offer }}" detailed="{{ true }}"/>
    </div>

    {% set action = 'offer_participant_list' %}

    <div class="p-4 sm:p-6 @lg:p-0">
    {% if missingPrivacyStatement|default %}

        <twig:Admin:Alert type="error" class="mt-6">
            <twig:block name="content">
                <span>{{ 'missingPrivacyStatement'|trans({}, 'admin') }}</span>
                <a class="block mt-2 font-semibold hover:underline" href="{{ path('admin_privacy_consent') }}">{{ 'participantList.privacyStatementLink'|trans({}, 'admin') }}</a>
            </twig:block>
        </twig:Admin:Alert>

    {% elseif notReleased|default %}

        <twig:Admin:Alert type="error" message="participantListNotReleased" class="mt-6"/>

    {% else %}

<div class="@container">
        {% component 'Admin:SearchableQueryableList' with {
            qb,
            ms,
            searchable: searchable|default([]),
            layout: isSlideOver ? 'list' : null,
            routeName: app.current_route,
            routeParameters: app.current_route_parameters|merge(app.request.query.all),
            headline: null,
            createUrl: createUrl|default(null),
            exports: exports|default([]),
            config: {
                showUrl: '{{ path("admin_attendance_show", { uuid: item.uuid.toBase58 }) }}',
                title: '{{ item.participant.name|default("") }}',
                info: [
                    '{{ item.participant.dateOfBirth|default ? item.participant.dateOfBirth|date("d.m.Y") : "" }}',
                    '{{ (item.offer and item.offer.dates|first and item.offer.dates|first.begin) ? item.participant.age(item.offer.dates|first.begin) ~ " " ~ "participantList.years"|trans({}, "admin") : item.participant.age ~ " " ~ "participantList.years"|trans({}, "admin") }}',
                    '{{ ("status."~item.status)|trans({}, "admin") }}',
                    '{% if item.consentOutstanding %}<span class="text-orange-600 font-medium">{{ "consents.consentOutstanding"|trans({}, "admin") }}</span>{% endif %}'
                ],
                columns: columns
            }
        } %}
            {% block head_actions %}
                <div data-live-ignore class="flex items-center gap-x-3 mr-2">
                    <twig:Admin:Dropdown position="left">
                        <twig:block name="toggle">
                            <button class="inline-flex w-full justify-center gap-x-1.5 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-xs inset-ring-1 inset-ring-gray-300 hover:bg-gray-50 dark:bg-gray-800 dark:text-gray-100 dark:inset-ring-gray-700 dark:hover:bg-gray-700">
                                {{ 'offers.attendances.export'|trans({}, 'admin')|default('Export') }}
                                <twig:ux:icon name="ph:caret-down" aria-hidden="true" class="-mr-1 size-5 text-gray-400" />
                            </button>
                        </twig:block>
                        <twig:block name="dropdown">
                            <div class="py-1">
                                <twig:Admin:DropdownItem href="{{ path('admin_offer_participants_pdf', { uuid: offer.uuid.toBase58 }) }}">
                                    <span class="mr-1.5 size-4 flex-shrink-0 ">{{ ux_icon('ph:file-pdf') }}</span>
                                    <span class="text-left leading-tight">{{ 'participantList.attendanceList'|trans({}, 'admin') }}</span>
                                </twig:Admin:DropdownItem>
                                <twig:Admin:DropdownItem href="{{ path('admin_offer_participants_pdf', { uuid: offer.uuid.toBase58, simple: 1 }) }}">
                                    <span class="mr-1.5 size-4 flex-shrink-0 ">{{ ux_icon('ph:file-pdf') }}</span>
                                    <span class="text-left leading-tight">{{ 'participantList.presenceList'|trans({}, 'admin') }}</span>
                                    <span class="ml-1 size-4 flex-shrink-0 ">{{ ux_icon('ph:scribble-loop') }}</span>
                                </twig:Admin:DropdownItem>
                                <twig:Admin:DropdownItem href="{{ path('admin_offer_participants_xlsx', { uuid: offer.uuid.toBase58 }) }}">
                                    <span class="mr-1.5 size-4 flex-shrink-0 ">{{ ux_icon('ph:microsoft-excel-logo') }}</span>
                                    <span class="text-left leading-tight">{{ 'participantList.attendanceList'|trans({}, 'admin') }}</span>
                                </twig:Admin:DropdownItem>
                                {% if hasWordExport %}
                                <twig:Admin:DropdownItem href="{{ path('admin_offer_participants_docx', { uuid: offer.uuid.toBase58 }) }}">
                                    <span class="mr-1.5 size-4 flex-shrink-0 ">{{ ux_icon('ph:microsoft-word-logo') }}</span>
                                    <span class="text-left leading-tight">{{ 'participantList.attendanceList'|trans({}, 'admin') }}</span>
                                </twig:Admin:DropdownItem>
                                    {% endif %}
                            </div>
                            {% if hasConsents %}
                            <div class="py-1 border-t border-gray-100 dark:border-gray-700">
                                <twig:Admin:DropdownItem href="{{ path('admin_offer_consents_pdf', { uuid: offer.uuid.toBase58 }) }}">
                                    <span class="mr-1.5 size-4 flex-shrink-0 ">{{ ux_icon('ph:file-pdf') }}</span>
                                    <span class="text-left leading-tight">{{ 'participantList.consents'|trans({}, 'admin') }}</span>
                                </twig:Admin:DropdownItem>
                                <twig:Admin:DropdownItem href="{{ path('admin_offer_consents_pdf', { detailed: 1, uuid: offer.uuid.toBase58 }) }}">
                                    <span class="mr-1.5 size-4 flex-shrink-0 ">{{ ux_icon('ph:file-pdf') }}</span>
                                    <span class="text-left leading-tight">{{ 'participantList.consents'|trans({}, 'admin') }}</span>
                                    <span class="ml-1 size-4 flex-shrink-0 ">{{ ux_icon('ph:signature') }}</span>
                                </twig:Admin:DropdownItem>
                            </div>
                            {% endif %}
                        </twig:block>
                    </twig:Admin:Dropdown>
                    {% if is_granted('participants.add', offer) %}
                        <twig:Admin:Button variant="secondary" class="hidden @md:inline-flex" href="{{ path('admin_offers_transfer_participants', { uuid: offer.uuid.toBase58 }) }}" data-turbo-frame="slideover">{{ 'offers.action.transfer_participants'|trans({}, 'admin') }}</twig:Admin:Button>
                        <twig:Admin:Button href="{{ path('admin_attendances_create', { offer: offer.uuid }) }}" data-turbo-frame="slideover">{{ 'attendances.new'|trans({}, 'admin') }}</twig:Admin:Button>
                    {% endif %}
                </div>
            {% endblock %}
        {% endcomponent %}
</div>

    {% endif %}
    </div>
{% endblock %}

{% block notification_stream %}
    <twig:Turbo:Stream:Prepend target="#notifications">
        <twig:Admin:Notification type="success" title="{{ 'notifications.savedTitle'|trans({}, 'admin') }}" message="{{ message }}"/>
    </twig:Turbo:Stream:Prepend>
{% endblock %}
