{% set _currentPage = paginator.currentPage ?: 1 %}
{% set _lastPage = paginator.lastPage %}
{% set _showingPerPage = (_currentPage == _lastPage) ? paginator.total - (this.perPage * (_lastPage - 1))  : ("query" in paginator.items) ? paginator.items.query.maxResults %}

<p class="text-white mt-1">Showing {{ _showingPerPage }} of {{ paginator.total }} total results</p>

{% if paginator.lastPage > 1 %}
    <nav>
        <ul class="mt-2 flex flex-row justify-content-center gap-1 py-1 text-white text-sm">
            <li class="page-item{{ _currentPage <= 1 ? ' disabled' : '' }}">
                <button {% if _currentPage > 1 %}
                   data-action="click->live#action"
                   data-live-action-param="paginate"
                   data-live-page-param="{{ _currentPage - 1 }}"
                   {% endif %}
                   class="page-link px-2.5 py-1 rounded-lg bg-orange-500 align-middle"
                   aria-label="Previous"
                   
                >
                    &laquo;
                </button>
            </li>
            {% set startPage = max(1, _currentPage - 2) %}
            {% set endPage = min(_lastPage, startPage + 4) %}
            {% if startPage > 1 %}
                <li class="page-item">
                    <button data-action="click->live#action"
                       data-live-action-param="paginate"
                       data-live-page-param="{{ "1"|number_format }}"
                       class="page-link px-2.5 py-1 rounded-lg bg-orange-500 align-middle"
                       aria-label="Next"
                       
                    >1</button>
                </li>
                {% if startPage > 2 %}
                    <li class="page-item disabled">
                        <span class="page-link px-2.5 py-1 rounded-lg bg-orange-500 align-middle inline-flex items-stretch">...</span>
                    </li>
                {% endif %}
            {% endif %}
            {% for i in startPage..endPage %}
                <li class="page-item">
                    <button data-action="click->live#action"
                        data-live-action-param="paginate"
                        data-live-page-param="{{ i|number_format }}"
                        class="page-link px-2.5 py-1 rounded-lg bg-orange-500 text-white align-middle"
                        {% if i == _currentPage %}style="background-color: #fff; color: darkorange; font-weight: bold;"{% endif %}
                    >{{ i }}</button>
                </li>
            {% endfor %}
            {% if endPage < _lastPage %}
                {% if endPage < _lastPage - 1 %}
                    <li class="page-item disabled">
                        <span class="page-link px-2.5 py-1 rounded-lg bg-orange-500 align-middle inline-flex items-stretch">...</span>
                    </li>
                {% endif %}
                <li class="page-item">
                    <button data-action="click->live#action"
                       data-live-action-param="paginate"
                       data-live-page-param="{{ _lastPage }}"
                       class="page-link px-2.5 py-1 rounded-lg bg-orange-500 align-middle"
                       aria-label="Next"
                       
                    >{{ _lastPage }}</button>
                </li>
            {% endif %}
            <li class="page-item {{ _currentPage >= paginator.lastPage ? ' disabled' : '' }}">
                <button {% if _currentPage < _lastPage %}
                   data-action="click->live#action"
                   data-live-action-param="paginate"
                   data-live-page-param="{{ _currentPage + 1 }}"
                   {% endif %}
                   class="page-link px-2.5 py-1 rounded-lg bg-orange-500 align-middle"
                   aria-label="Next"
                   
                >
                    &raquo;
                </button>
            </li>
        </ul>
    </nav>
{% endif %}
