{% load i18n %}
{% comment %}
Shared pagination controls. Context: `page_obj` (a Django Page), `elided_range`
(paginator.get_elided_page_range output) and `querystring` (the current GET
params minus `page`, so filters survive page navigation).
{% endcomment %}
{% if page_obj.paginator.num_pages > 1 %}
    <nav class="d-flex flex-wrap align-items-center gap-3 mt-3"
         aria-label="{% translate 'Pagination' %}">
        <ul class="pagination pagination-sm mb-0">
            {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link"
                       href="?{% if querystring %}{{ querystring }}&amp;{% endif %}page={{ page_obj.previous_page_number }}">&laquo;</a>
                </li>
            {% else %}
                <li class="page-item disabled"><span class="page-link">&laquo;</span></li>
            {% endif %}
            {% for n in elided_range %}
                {% if n == page_obj.paginator.ELLIPSIS %}
                    <li class="page-item disabled"><span class="page-link">{{ n }}</span></li>
                {% elif n == page_obj.number %}
                    <li class="page-item active" aria-current="page"><span class="page-link">{{ n }}</span></li>
                {% else %}
                    <li class="page-item">
                        <a class="page-link"
                           href="?{% if querystring %}{{ querystring }}&amp;{% endif %}page={{ n }}">{{ n }}</a>
                    </li>
                {% endif %}
            {% endfor %}
            {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link"
                       href="?{% if querystring %}{{ querystring }}&amp;{% endif %}page={{ page_obj.next_page_number }}">&raquo;</a>
                </li>
            {% else %}
                <li class="page-item disabled"><span class="page-link">&raquo;</span></li>
            {% endif %}
        </ul>
        <span class="text-muted small">
            {% blocktranslate with start=page_obj.start_index end=page_obj.end_index total=page_obj.paginator.count %}Showing {{ start }}&ndash;{{ end }} of {{ total }}{% endblocktranslate %}
        </span>
    </nav>
{% endif %}
