{% load i18n %}

{% load smart_settings_tags %}
{% load templating_math_tags %}
{% load templating_tags %}
{% load views_tags %}

{% smart_setting "APPEARANCE_PAGINATION_DROPDOWN_ENABLE" as setting_page_dropdown_enable %}
{% smart_setting "APPEARANCE_PAGINATION_DROPDOWN_RANGE" as setting_page_dropdown_range %}
{% smart_setting "APPEARANCE_PAGINATION_INPUT_ENABLE" as setting_page_input_enable %}
{% smart_setting "APPEARANCE_ELIDED_PAGER_ON_EACH_SIDE" as setting_elided_pager_on_each_side %}
{% smart_setting "APPEARANCE_ELIDED_PAGER_ON_ENDS" as setting_elided_pager_on_ends %}

{% views_get_proper_elided_page_range paginator page_obj.number on_each_side=setting_elided_pager_on_each_side on_ends=setting_elided_pager_on_ends as page_range %}

{% if page_obj %}
    <div class="pull-left">
        <div class="btn-toolbar" role="toolbar">
            <div class="btn-group">
                {% if page_obj.has_previous %}
                    <a alt="{% trans 'Previous page' %}" class="btn btn-default btn-sm" href="{% views_get_paging_query_string page_number=page_obj.previous_page_number %}">&lsaquo;&lsaquo;</a>
                {% else %}
                    <a alt="{% trans 'Previous page' %}" class="btn btn-default btn-sm disabled" href="#">&lsaquo;&lsaquo;</a>
                {% endif %}

                {% for page_number in page_range %}
                    {% if page_number == paginator.ELLIPSIS %}
                        <a class="btn btn-default btn-sm disabled" href="#">{{ paginator.ELLIPSIS }}</a>
                    {% else %}
                        {% if page_number == page_obj.number %}
                            <a class="active btn btn-default btn-sm pagination-disabled" href="#">{{ page_number }}</a>
                        {% else %}
                            <a class="btn btn-default btn-sm" href="{% views_get_paging_query_string page_number=page_number %}">{{ page_number }}</a>
                        {% endif %}
                    {% endif %}
                {% endfor %}

                {% if page_obj.has_next %}
                    <a alt="{% trans 'Next page' %}" class="btn btn-default btn-sm" href="{% views_get_paging_query_string page_number=page_obj.next_page_number %}">&rsaquo;&rsaquo;</a>
                {% else %}
                    <a alt="{% trans 'Next page' %}" class="btn btn-default btn-sm disabled" href="#">&rsaquo;&rsaquo;</a>
                {% endif %}

                {% if setting_page_input_enable %}
                    <div class="form-inline input-group">
                        <input class="form-control input-sm appearance-pagination-page-select" name="page" placeholder="{% trans 'Page' %}" size="3" title="{% trans 'Jump to page' %}" type="text">
                    </div>
                {% endif %}

                {% if setting_page_dropdown_enable %}
                    {% set setting_page_dropdown_range|math_floor_divide:2 as setting_page_dropdown_range_half %}
                    {% range page_obj.number|math_substract:setting_page_dropdown_range_half page_obj.number|add:setting_page_dropdown_range_half as page_select_range %}
                    <div class="input-group">
                        <select class="form-control input-sm appearance-pagination-page-select" name="page-jump">
                            {% for page_number in page_select_range %}
                                {% if page_number > 0 and page_number <= paginator.num_pages %}
                                    {% if page_number == page_obj.number %}
                                        <option disabled="" selected="" value="{{ page_number }}">{{ page_number }}</option>
                                    {% else %}
                                        <option value="{{ page_number }}">{{ page_number }}</option>
                                    {% endif %}
                                {% endif %}
                            {% endfor %}
                        </select>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
{% endif %}
