{% if pages > 1 %}
<nav class="mt-3">
    <ul class="pagination justify-content-center flex-wrap">
        <li class="page-item {{ 'disabled' if page == 1 }}">
            <a class="page-link" href="{{ url_for(request.endpoint, **dict(request.args, page=[page-1, 1]|max)) }}">
                <i class="bi bi-chevron-left"></i>
            </a>
        </li>
        {% for p in range([1, page-3]|max, [pages+1, page+4]|min) %}
        <li class="page-item {{ 'active' if p == page }}">
            <a class="page-link" href="{{ url_for(request.endpoint, **dict(request.args, page=p)) }}">{{ p }}</a>
        </li>
        {% endfor %}
        <li class="page-item {{ 'disabled' if page == pages }}">
            <a class="page-link" href="{{ url_for(request.endpoint, **dict(request.args, page=[page+1, pages]|min)) }}">
                <i class="bi bi-chevron-right"></i>
            </a>
        </li>
    </ul>
    <p class="text-center text-muted small">Page {{ page }} of {{ pages }} · {{ total }} entries</p>
</nav>
{% endif %}
