{% if pagination and pagination.total > 0 and pagination.total_pages > 1 %}
<div class="pagination">
    <span class="pagination-info">{{ pagination.total }} items &middot; Page {{ pagination.page }} of {{ pagination.total_pages }}</span>
    <div class="pagination-controls">
        {% if pagination.has_prev %}
        <a href="?page={{ pagination.prev_page }}" class="pagination-btn"><span class="icon">&#x2190;</span>Previous</a>
        {% else %}
        <span class="pagination-btn pagination-btn-disabled"><span class="icon">&#x2190;</span>Previous</span>
        {% endif %}

        <div class="pagination-pages">
            {% for p in range(1, pagination.total_pages + 1) %}
                {% if p == 1 or p == pagination.total_pages or (p >= pagination.page - 2 and p <= pagination.page + 2) %}
                <a href="?page={{ p }}" class="pagination-page {% if p == pagination.page %}pagination-page-active{% endif %}">{{ p }}</a>
                {% elif p == pagination.page - 3 or p == pagination.page + 3 %}
                <span class="pagination-ellipsis">&hellip;</span>
                {% endif %}
            {% endfor %}
        </div>

        {% if pagination.has_next %}
        <a href="?page={{ pagination.next_page }}" class="pagination-btn">Next <span class="icon">&#x2192;</span></a>
        {% else %}
        <span class="pagination-btn pagination-btn-disabled">Next <span class="icon">&#x2192;</span></span>
        {% endif %}
    </div>
</div>
{% endif %}
