{% trans_default_domain 'contao_default' %}
{% set goToLabel = 'MSC.goToPage'|trans %}

{# Rebuild the current URL with a changed `page`. The fallback must include the
   current route's *route* parameters (e.g. the mandatory `{alias}` on
   cms_edition_landing) alongside the query string — query.all alone omits route
   attributes and breaks URL generation for routes with mandatory params. #}
{% set _routeName = routeName ?? app.request.attributes.get('_route') %}
{% set _routeParameters = routeParameters ?? (app.request.attributes.get('_route_params')|default({})|merge(app.request.query.all)) %}

    <nav class="border-t border-gray-200 px-4 flex items-center justify-between sm:px-0">
        <div class="w-0 flex-1 flex">
            {% if pagination.hasPreviousPage %}
                <a href="{{ path(_routeName, _routeParameters|merge({page: pagination.previousPage})) }}"
                   title="{{ goToLabel|replace({'%s': pagination.previousPage})|e }}"
                   class="-mt-px border-t-2 border-transparent pt-4 pr-1 inline-flex items-center text-sm leading-5 font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-400 transition ease-in-out duration-150">
                    <twig:ux:icon name="lucide:arrow-left" class="mr-3 h-5 w-5 text-gray-400" />
                    {{ 'MSC.previous'|trans }}
                </a>
            {% endif %}
        </div>

        <div class="hidden md:flex">
            {% for i in 1..pagination.lastPage %}
                {% if i == pagination.currentPage %}
                    <strong class="-mt-px border-t-2 border-primary-500 pt-4 px-4 inline-flex items-center text-sm leading-5 font-medium text-primary-600 focus:outline-none focus:text-primary-800 focus:border-primary-700 transition ease-in-out duration-150">{{ i }}</strong>
                {% else %}
                    <a href="{{ path(_routeName, _routeParameters|merge({page: i})) }}"
                       class="-mt-px border-t-2 border-transparent pt-4 px-4 inline-flex items-center text-sm leading-5 font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-400 transition ease-in-out duration-150"
                       title="{{ goToLabel|replace({'%s': i})|e }}">{{ i }}</a>
                {% endif %}
            {% endfor %}
        </div>

        <div class="w-0 flex-1 flex justify-end">
            {% if pagination.hasNextPage %}
                <a href="{{ path(_routeName, _routeParameters|merge({page: pagination.nextPage})) }}"
                   class="-mt-px border-t-2 border-transparent pt-4 pl-1 inline-flex items-center text-sm leading-5 font-medium text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-400 transition ease-in-out duration-150"
                   title="{{ goToLabel|replace({'%s': pagination.nextPage})|e }}">
                    {{ 'MSC.next'|trans }}
                    <twig:ux:icon name="lucide:arrow-right" class="ml-3 h-5 w-5 text-gray-400" />
                </a>
            {% endif %}
        </div>
    </nav>
