{% load i18n %}
{% load bootstrap_pagination %}
<ul class="pagination{% if size == "small" %} pagination-sm{% endif %}{% if size == "large" %} pagination-lg{% endif %} {{ extra_pagination_classes }}">
    {% if show_first_last %}
        {% if not page.has_previous %}
            <li class="page-item disabled">
                <span class="page-link" aria-hidden="true" title="{% trans 'First Page' %}">{{ first_label }}</span>
            </li>
        {% else %}
            <li class="page-item">
                <a class="page-link"
                   aria-label="{% trans 'First Page' %}"
                   title="{% trans  'First Page' %}"
                   {% if htmx %} hx-target="{{ hx_target }}" hx-swap="outerHTML" hx-get="{{ first_page_url|default:"#"|escape }}" {% else %} href="{{ first_page_url|default:"#"|escape }}" {% endif %}>
                    <span aria-hidden="true">{{ first_label }}</span></a>
            </li>
        {% endif %}
    {% endif %}
    {% if show_prev_next %}
        {% if not page.has_previous %}
            <li class="page-item disabled">
                <span class="page-link"
                      aria-hidden="true"
                      title="{% trans 'Previous Page' %}">{{ previous_label }}</span>
            </li>
        {% else %}
            <li class="page-item">
                <a class="page-link"
                   aria-label="{% trans 'Previous Page' %}"
                   title="{% trans 'Previous Page' %}"
                   {% if htmx %} hx-target="{{ hx_target }}" hx-swap="outerHTML" hx-get="{{ previous_page_url|default:"#"|escape }}" {% else %} href="{{ previous_page_url|default:"#"|escape }}" {% endif %}>
                    <span aria-hidden="true">{{ previous_label }}</span></a>
            </li>
        {% endif %}
    {% endif %}
    {% for pagenum, index_range, url in page_urls %}
        {% if page.number == pagenum %}
            <li class="page-item active">
                <span class="page-link"
                      aria-label="{% trans 'Current Page' %}"
                      title="{% trans 'Current Page' %}">
                    {% if show_index_range %}
                        {{ index_range }}
                    {% else %}
                        {{ pagenum }}
                    {% endif %}
                </span>
            </li>
        {% elif pagenum == page.paginator.ELLIPSIS %}
            <li class="page-item disabled">
                <a class="page-link">{{ ellipsis_label }}</a>
            </li>
        {% else %}
            <li class="page-item">
                <a class="page-link"
                   aria-label="{% trans 'Page' %} {{ pagenum }} {% trans 'of' %} {{ page.paginator.num_pages }}"
                   title="{% trans 'Page' %} {{ pagenum }} {% trans 'of' %} {{ page.paginator.num_pages }}"
                   {% if htmx %} hx-target="{{ hx_target }}" hx-swap="outerHTML" hx-get="{{ url|escape }}" {% else %} href="{{ url|escape }}" {% endif %}>
                    {% if show_index_range %}
                        {{ index_range }}
                    {% else %}
                        {{ pagenum }}
                    {% endif %}
                </a>
            </li>
        {% endif %}
    {% endfor %}
    {% if show_prev_next %}
        {% if not page.has_next %}
            <li class="page-item  disabled">
                <span class="page-link" aria-hidden="true" title="{% trans 'Next Page' %}">{{ next_label }}</span>
            </li>
        {% else %}
            <li class="page-item">
                <a class="page-link"
                   aria-label="{% trans 'Next Page' %}"
                   title="{% trans 'Next Page' %}"
                   {% if htmx %} hx-target="{{ hx_target }}" hx-swap="outerHTML" hx-get="{{ next_page_url|default:"#"|escape }}" {% else %} href="{{ next_page_url|default:"#"|escape }}" {% endif %}>
                    <span aria-hidden="true">{{ next_label }}</span></a>
            </li>
        {% endif %}
    {% endif %}
    {% if show_first_last %}
        {% if not page.has_next %}
            <li class="page-item disabled">
                <span class="page-link" aria-hidden="true" title="{% trans 'Last Page' %}">{{ last_label }}</span>
            </li>
        {% else %}
            <li class="page-item">
                <a class="page-link"
                   aria-label="{% trans 'Last Page' %}"
                   title="{% trans 'Last Page' %}"
                   {% if htmx %} hx-target="{{ hx_target }}" hx-swap="outerHTML" hx-get="{{ last_page_url|default:"#"|escape }}" {% else %} href="{{ last_page_url|default:"#"|escape }}" {% endif %}>
                    <span aria-hidden="true">{{ last_label }}</span></a>
            </li>
        {% endif %}
    {% endif %}
</ul>
