{# Markup mirrors your legacy PHP snippet: UL.pagination.clear + li.first/prev/dots/active/next/last #}
<ul class="pagination clear" role="navigation" aria-label="Patients pages">
    {# First / Prev (only when not on first page) #}
    {% if not patients.onFirstPage() %}
        <li class="first">
            <a href="{{ patients.url(1) }}" data-pager>First Page</a>
        </li>
        <li class="prev">
            <a href="{{ patients.previousPageUrl() }}" data-pager rel="prev">Prev</a>
        </li>
    {% endif %}

    {# Number window (from UrlWindow::make) #}
    {% for element in paginationElements %}
        {% if element is iterable %}
            {% for page, url in element %}
                {% if page == patients.currentPage() %}
                    <li class="active"><a aria-current="page">{{ page }}</a></li>
                {% else %}
                    <li><a href="{{ url }}" data-pager>{{ page }}</a></li>
                {% endif %}
            {% endfor %}
        {% else %}
            <li class="dots" aria-hidden="true">&hellip;</li>
        {% endif %}
    {% endfor %}

    {# Next / Last (only when there are more pages) #}
    {% if patients.hasMorePages() %}
        <li class="next">
            <a href="{{ patients.nextPageUrl() }}" data-pager rel="next">Next</a>
        </li>
        <li class="last">
            <a href="{{ patients.url(patients.lastPage()) }}" data-pager>Last Page</a>
        </li>
    {% endif %}
</ul>

{# Keep the hidden info list like the legacy snippet #}
<ul class="paginationInfo" style="display:none; visibility:hidden;">
    <li class="pageNum">{{ patients.currentPage() }}</li>
    <li class="rowsPerPage">{{ patients.perPage() }}</li>
</ul>
