{% macro render_pagination(pagination) %}

    {% set args = dict(request.args) %}
    {% set page = args.pop("page", 1) %}

    <nav aria-label="Page navigation">
        <ul class="pagination pagination-sm justify-content-end">

            {% if pagination.has_prev %}
                <li class="page-item">
                    <a class="page-link"
                       href="{{ url_for(".index", page=pagination.prev_num, **args) }}">
                        Previous
                    </a>
                </li>
            {% else %}
                <li class="page-item disabled">
                    <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
                </li>
            {% endif %}

            {% for page in pagination.iter_pages(
                  left_edge=1,
                  right_current=3,
                  right_edge=1
                ) %}
                {% if page %}
                    {% if page != pagination.page %}
                        <li class="page-item">
                            <a class="page-link"
                               href="{{ url_for(".index", page=page, **args) }}">{{ page }}</a>
                        </li>
                    {% else %}
                        <li class="page-item active">
                            <strong>
                                <span class="page-link">{{ page }}</span>
                            </strong>
                        </li>
                    {% endif %}
                {% else %}
                    <li class="page-item disabled">
                        <span class="page-link">...</span>
                    </li>
                {% endif %}
            {% endfor %}

            {% if pagination.has_next %}
                <li class="page-item">
                    <a class="page-link"
                       href="{{ url_for(".index", page=pagination.next_num, **args) }}">
                        Next
                    </a>
                </li>
            {% else %}
                <li class="page-item disabled">
                    <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Next</a>
                </li>
            {% endif %}
        </ul>
    </nav>

{% endmacro %}


{% macro results_pagination(pagination) %}

    {% if pagination.total == 0 %}
        {% set low = 0 %}
    {%  else %}
        {% set low = (pagination.page - 1) * pagination.per_page + 1 %}
    {% endif %}

    {% if pagination.has_next %}
        {% set upp = pagination.page * pagination.per_page %}
    {% else %}
        {% set upp = pagination.total %}
    {% endif %}

    <i class="fa-solid fa-table"></i> {{ low }} to {{ upp }} of {{ pagination.total }}

{% endmacro %}