{% load display_tags %}
{% load i18n %}
{% load oxyan %}
{% load ocyanjson %}

{% if paginator.num_pages > 1 %}
    <nav class="{% if search_form.has_items_per_page_choices %}d-flex{% endif %} mb-5">    
        <ul class="pagination justify-content-center mb-0 flex-wrap">
            {% if page_obj.has_previous %}
                <li class="page-item">
                    <a class="page-link" href="?{% get_parameters 'page' %}page={{ page_obj.previous_page_number }}" tabindex="-1">
                        {% trans "previous" %}
                    </a>
                </li>
            {% endif %}

            {% ocyanjson "themes" "extra_page_choices" 0 as extra_page_choices %}

            {% if extra_page_choices %}
                {% get_pages paginator extra_page_choices %}
            {% else %}
                <li class="page-item disabled">
                    <span class="page-link">
                        {% blocktrans with page_num=page_obj.number total_pages=paginator.num_pages %}Page {{ page_num }} of {{ total_pages }}{% endblocktrans %}
                    </span>
                </li>
            {% endif %}

            {% if page_obj.has_next %}
                <li class="page-item">
                    <a class="page-link" href="?{% get_parameters 'page' %}page={{ page_obj.next_page_number }}">
                        {% trans "next" %}
                    </a>
                </li>
            {% endif %}
        </ul>

        {% if search_form.has_items_per_page_choices %}
        <div class="d-flex flex-column ms-auto">
            <div class="btn-group float-right" role="group" aria-label="{{ search_form.items_per_page.label }}" title="{% trans search_form.items_per_page.label %}">
                {% for choice, label in search_form.get_items_per_page_choices %}<a
                   rel="nofollow" tabindex="-1"
                   title="{{ search_form.items_per_page.label }}" {% if search_form.items_per_page.value %}
                   class="btn btn-primary{% if choice|lower == search_form.items_per_page.value %} active{% endif %}"{% else %}
                   class="btn btn-primary{% if forloop.first %} active{% endif %}"{% endif %}
                   href="?{% get_parameters 'items_per_page' %}items_per_page={{ choice }}">{{ label }}</a>{% endfor %}
            </div>
        </div>
        {% endif %}
    </nav>
{% endif %}
