{% load i18n %}
{% load pagination %}

{% if page.paginator.num_pages > 1 %}
<nav class="text-center">
    {% if page.paginator.num_pages > 10 %}
    <ul class="pager">
        {% if page.has_previous %}
            <li class="col-md-4 text-right">
                <a href="?{% add_to_query_string page=page.previous_page_number count=page.paginator.per_page %}">&larr; {% trans 'Previous' %}</a>
            </li>
        {% else %}
            <li class="disabled col-md-4 text-right"><span>&larr; {% trans 'Previous' %}</span></li>
        {% endif %}
        <li class="pager-select col-md-4">
            <a href="">{% blocktrans with num=page.number total=page.paginator.num_pages %}Page {{ num }} of {{ total }}{% endblocktrans %}</a>
            <form class="form-inline hidden" action="" method="GET">
            <label>
                {% trans 'Jump to page:' %}
                <select class="form-control input-sm" name="page">
                {% for pagenum in page.paginator.page_range %}
                    <option value="{{ pagenum }}"
                        {% if page.number == pagenum %}selected{% endif %}>
                        {{ pagenum }}
                    </option>
                {% endfor %}
                </select>
            </label>
            {% for key, value in request.GET.items %}
                {% if key != 'page' %}
                    <input type="hidden" name="{{ key }}" value="{{ value }}" />
                {% endif %}
            {% endfor %}
            </form>
        </li>
        {% if page.has_next %}
            <li class="col-md-4 text-left">
                <a href="?{% add_to_query_string page=page.next_page_number count=page.paginator.per_page %}">{% trans 'Next' %} &rarr;</a>
            </li>
        {% else %}
            <li class="disabled col-md-4 text-left"><span>{% trans 'Next' %} &rarr;</span></li>
        {% endif %}
    </ul>
    {% else %}
        <ul class="pagination">
        {% if page.has_previous %}
            <li>
                <a href="?{% add_to_query_string page=page.previous_page_number count=page.paginator.per_page %}">&laquo;</a>
            </li>
        {% else %}
            <li class="disabled"><span>&laquo;</span></li>
        {% endif %}
            {% for pagenum in page.paginator.page_range %}
                {% if page.number == pagenum %}
                <li class="active"><span>{{ pagenum }}</span></li>
                {% else %}
                <li><a href="?{% add_to_query_string page=pagenum count=page.paginator.per_page %}">{{ pagenum }}</a></li>
                {% endif %}
            {% endfor %}
        {% if page.has_next %}
            <li><a href="?{% add_to_query_string page=page.next_page_number count=page.paginator.per_page %}">&raquo;</a></li>
        {% else %}
            <li class="disabled"><span>&raquo;</span></li>
        {% endif %}
        </ul>
    {% endif %}
    <form action="{{ request.path }}" method="get" class="form-inline">
        <p class="text-center">
            {% for key, value in request.GET.items %}
                {% if key != 'count' %}
                    <input type="hidden" name="{{ key }}" value="{{ value }}" />
                {% endif %}
            {% endfor %}
            {% trans 'Results per page:' %}
            <select name="count" class="form-control input-sm">
                {% for count in count_options %}
                    <option value="{{ count }}"
                        {% if page.paginator.per_page == count %}
                        selected="selected"
                        {% endif %}
                        >{{ count }}
                    </option>
                {% endfor %}
            </select>
            <input type="submit" class="btn btn-default btn-sm" value="Update" />
        </p>
    </form>
</nav>
{% endif %}
