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


{% block list %}

{% component 'Admin:SearchableQueryableList' with {
        qb: qb,
        filterType: filterType,
        routeName: app.current_route,
        routeParameters: app.current_route_parameters|merge(app.request.query.all),
        searchable: searchable|default([]),
        exports: exports|default([]),
        createUrl: null,
        viewKey: 'admin_offers',
        viewPathPrefix: '/admin/angebote',
        config: config
    } %}
        {% block page_header %}
            <div class="flex items-center justify-between gap-4 flex-wrap py-5 border-b border-gray-200 dark:border-gray-800 mb-2">
                <div class="flex items-center gap-4 flex-wrap min-w-0">
                    <twig:Admin:EditionSwitcher :editions="editions|default([])" :selected="selectedEditions|default([])" baseLabel="Angebote" />

                    <div class="h-6 w-px bg-gray-300 dark:bg-gray-700"></div>
                    <nav class="flex items-center space-x-4 overflow-x-auto py-1">
                        <a href="{{ path('admin_offers_index') }}"
                           class="text-sm font-medium whitespace-nowrap {{ (not edition|default and (app.request.get('_route')|split('.')|first) == 'admin_offers_index') ? 'text-primary-600 dark:text-primary-400' : 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300' }}">
                            Liste
                        </a>
                        <a href="{{ edition|default ? path('admin_offers_calendar_in_edition', { edition: edition.alias }) : path('admin_offers_calendar') }}"
                           class="text-sm font-medium whitespace-nowrap {{ (app.request.get('_route')|split('.')|first) in ['admin_offers_calendar', 'admin_offers_calendar_in_edition'] ? 'text-primary-600 dark:text-primary-400' : 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300' }}">
                            Kalender
                        </a>
                    </nav>
                </div>

{# Wrapped in data-live-ignore so morphdom doesn't replace the dropdown
                   on every Live re-render — `creatableEditions` is supplied by
                   the controller, not the LiveComponent, and would be missing
                   during re-renders (making the entire button disappear). #}
                {% if creatableEditions|default([])|length > 0 %}
                    <div data-live-ignore>
                    <el-dropdown {{ stimulus_controller('ferienpass/admin-dropdown') }} class="inline-block">
                        <button type="button"
                                class="inline-flex shadow-sm rounded-md bg-primary-600 text-white dark:bg-primary-500 hover:bg-primary-700 dark:hover:bg-primary-400 focus-visible:outline-2 focus-visible:outline-primary-400 cursor-pointer">
                            <span class="inline-flex items-center gap-x-1.5 px-3 py-2 text-sm font-semibold">
                                <twig:ux:icon name="ph:plus" aria-hidden="true" class="-ml-0.5 size-5"/>
                                <span>{{ 'offers.create.cta'|trans({}, 'admin') }}</span>
                            </span>
                            <span class="inline-flex items-center pr-2 pl-1 py-2">
                                <twig:ux:icon name="ph:caret-down" aria-hidden="true" class="size-5 text-white"/>
                            </span>
                        </button>

                        <el-menu anchor="bottom end" popover
                                 class="w-80 origin-top-right divide-y divide-gray-200 overflow-hidden rounded-md bg-white shadow-lg outline-1 outline-black/5 [--anchor-gap:--spacing(2)] dark:divide-white/10 dark:bg-gray-900 dark:shadow-none dark:-outline-offset-1 dark:outline-white/10">
                            {% for e in creatableEditions %}
                                {% set active = edition|default(null) and edition.id == e.id %}
                                {% set holiday = e.holiday %}
                                <a href="{{ path('admin_offers_new_in_edition', { edition: e.alias }) }}"
                                   data-turbo-frame="slideover"
                                   class="group/option block p-4 text-sm text-gray-900 select-none hover:bg-primary-600 hover:text-white focus:bg-primary-600 focus:text-white focus:outline-hidden dark:text-white dark:hover:bg-primary-500 dark:focus:bg-primary-500 {{ active ? 'bg-yellow-50 dark:bg-yellow-950' : '' }}">
                                    <p class="font-medium">{{ e.name }}</p>
                                    {% set hasPeriod = holiday and holiday.periodBegin and holiday.periodEnd %}
                                    {% if hasPeriod or e.archived %}
                                        <p class="mt-2 text-gray-500 group-hover/option:text-primary-200 group-focus/option:text-primary-200 dark:text-gray-400 dark:group-hover/option:text-primary-100 dark:group-focus/option:text-primary-100">
                                            {% if hasPeriod %}{{ holiday.periodBegin|date('d.m.Y') }} – {{ holiday.periodEnd|date('d.m.Y') }}{% endif %}
                                            {% if e.archived %}{% if hasPeriod %} · {% endif %}{{ 'offers.create.archivedHint'|trans({}, 'admin') }}{% endif %}
                                        </p>
                                    {% endif %}
                                </a>
{% endfor %}
                        </el-menu>
                    </el-dropdown>
                    </div>
                {% endif %}
            </div>
        {% endblock %}
    {% endcomponent %}

{% endblock %}

{% block row_stream %}
    {% set row_config = config|merge({ item: item, selected: [], showActions: true }) %}
    <turbo-stream action="replace" target="tr-{{ item.id }}">
        <template>
            {% include '@FerienpassAdmin/components/_list_row.html.twig' with row_config %}
        </template>
    </turbo-stream>
    <turbo-stream action="replace" target="li-{{ item.id }}">
        <template>
            {% include '@FerienpassAdmin/components/_list_item.html.twig' with row_config %}
        </template>
    </turbo-stream>
{% endblock %}