{% init page = 1 %}
{% init page_max = 0 %}
{% init page_size = 20 %}
{% init page_url = "?page=" %}
{% init page_total = 0 %}

{% if "page_totalsize" in globals() %}
    {% set-global page_total = page_totalsize %}
{% end %}
{% if "page_current" not in globals() %}
    {% set-global page_current = page %}
{% end %}

{% if page_max == 0 %}
    {% if page_total == 0 %}
        {% set-global page_max = 1 %}
    {% else %}
        {% set-global page_max = int(math.ceil(page_total/page_size)) %}
    {% end %}
{% end %}

{% if page_max >= 0 %}
    <div class="pagenation">        
        <a class="x-page-link" href="{{page_url}}1">首页</a>

        {% if page <= 1 %}
            <a class="x-page-link disabled">上一页</a>
        {% else %}
            <a class="x-page-link" href="{{page_url}}{{page-1}}">上一页</a>
        {% end %}

        {% for j in range(max(1, page-2), page) %}
            <a class="x-page-link desktop-only-inline" href="{{page_url}}{{j}}">{{j}}</a>
        {% end %}

        <!-- 当前页 -->
        <a class="x-page-link active" href="#">{{page}}</a>
        
        {% for j in range(page+1, int(min(page+3, page_max+1))) %}
            <a class="x-page-link desktop-only-inline" href="{{page_url}}{{j}}">{{j}}</a>
        {% end %}

        {% if page >= page_max %}
            <a class="x-page-link disabled">下一页</a>
        {% else %}
            <a class="x-page-link" href="{{page_url}}{{page+1}}">下一页</a>
        {% end %}

        <a class="x-page-link" href="{{page_url}}{{page_max}}">尾页</a>
        {% if page_total > 0 and not _is_mobile %}
            <span class="x-page-span">{{page_total}}条记录</span>
        {% end %}
    </div>
{% end %}
