{% extends '@Contao/fragment/_container.html.twig' %}

{% block container %}

    <div class="pb-12">

        {% if edition is not defined %}

            <div class="flex items-center justify-center py-12">
                <twig:ux:icon name="lucide:frown" class="h-16 w-16 text-gray-400 mr-4" />
                <p class="text-2xl text-gray-600">{{ 'offerList.noEdition'|trans({}, 'cms') }}</p>
            </div>

        {% else %}

            <div class="space-y-6">
                {% block filter_decoration %}{% endblock %}

                {#
                  Turbo Frame: chip clicks, search submits, pagination links and
                  the reset link stay inside this frame, which means:
                    - URL still updates (data-turbo-action="advance") so links
                      remain bookmarkable / cache-friendly,
                    - scroll position is preserved — no page jumps,
                    - it's still GET-only, no live-component POST roundtrips.

                  External navigations (offer detail link, "Infos →" button) are
                  marked data-turbo-frame="_top" on the card itself.
                #}
                <turbo-frame id="cms-offer-list"
                             data-turbo-action="advance"
                             data-controller="ferienpass--cms-wishlists"
                             class="block space-y-6">

                    {% block filter %}
                        <twig:Cms:Filter :form="filterForm"
                                         :applicationSystem="applicationSystem|default(null)"
                                         :categories="categories|default([])"
                                         :totalCount="pagination.numResults" />
                    {% endblock %}

                    {% block active_filters %}
                        {% include '@Contao/components/filter_active_pills.html.twig' %}
                    {% endblock %}

                    {% if pagination.results is empty %}
                        {% embed '@FerienpassCore/Alert/warning.html.twig' %}
                            {% block headline %}
                                {{ 'offerList.noResults.title'|trans({}, 'cms') }}
                            {% endblock %}
                            {% block content %}
                                {{ 'offerList.noResults.text'|trans({}, 'cms') }}
                            {% endblock %}
                        {% endembed %}
                    {% else %}
                        {% block list %}
                            <section data-controller="ferienpass--cms-masonry"
                                     aria-label="{{ 'offerList.ariaLabel'|trans({}, 'cms') }}"
                                     class="mt-2">

                                {% for item in pagination.results %}
                                    <div class="w-full sm:w-[calc(100%/2-26px)] md:w-[calc(100%/3-26px)]">
                                        <twig:Cms:OfferListItem item="{{ item }}" key="{{ item.id }}"/>
                                    </div>
                                {% endfor %}

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

                    {% if pagination.hasToPaginate %}
                        <div class="py-10">
                            {% include '@Contao/fragment/_pagination.html.twig' %}
                        </div>
                    {% endif %}
                </turbo-frame>
            </div>

        {% endif %}
    </div>

{% endblock %}
