{% trans_default_domain 'EasyAdminBundle' %}

{% set _paginator_request_parameters = _request_parameters|merge({'referer': null}) %}

{% if paginator.haveToPaginate %}
    <div class="list-pagination">
        <div class="row">
            <div class="col-sm-3 hidden-xs list-pagination-counter">
                {{ 'paginator.counter'|trans({ '%start%': paginator.currentPageOffsetStart, '%end%': paginator.currentPageOffsetEnd, '%results%': paginator.nbResults})|raw }}
            </div>
            <div class="col-xs-12 col-sm-9">
                <ul class="pagination list-pagination-paginator {{ 1 == paginator.currentPage ? 'first-page' : '' }} {{ paginator.hasNextPage ? '' : 'last-page' }}">
                    {% if 1 == paginator.currentPage %}
                        <li class="disabled">
                            <span class="page-link ">
                                <i class="fa fa-angle-double-left"></i>
                            </span>
                        </li>
                    {% else %}
                        <li>
                            <a class="page-link"
                               href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: 1 }) ) }}">
                                <i class="fa fa-angle-double-left"></i>
                            </a>
                        </li>
                    {% endif %}

                    {% if paginator.hasPreviousPage %}
                        <li>
                            <a class="page-link"
                               href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: paginator.previousPage }) ) }}">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        </li>
                    {% else %}
                        <li class="disabled">
                            <span class="page-link">
                                <i class="fa fa-angle-left"></i>
                            </span>
                        </li>
                    {% endif %}

                    {# BEGIN DISPLAYING PAGE NUMBERS #}

                    {# the number of pages that are displayed around the active page #}
                    {% set nearbyPagesLimit = 8 %}

                    {% if paginator.currentPage > 1 %}
                        {% for i in range(paginator.currentPage-nearbyPagesLimit, paginator.currentPage-1) if ( i > 0 ) %}
                            <li >
                                <a class="page-link"
                                   href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}">{{ i }}</a>
                            </li>
                        {% endfor %}
                    {% endif %}
                    <li>
                        <a class="current page-link">{{ paginator.currentPage }}</a>
                    </li>
                    {% if paginator.currentPage < paginator.nbPages %}
                        {% for i in range(paginator.currentPage+1, paginator.currentPage + nearbyPagesLimit) if ( i <= paginator.nbPages ) %}
                            <li>
                                <a class="page-link"
                                   href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}">{{ i }}</a>
                            </li>
                        {% endfor %}
                    {% endif %}

                    {# END DISPLAYING PAGE NUMBERS #}

                    {% if paginator.hasNextPage %}
                        <li>
                            <a class="page-link"
                               href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nextPage }) ) }}">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        </li>
                    {% else %}
                        <li class="disabled">
                            <span class="page-link">
                               <i class="fa fa-angle-right"></i>
                            </span>
                        </li>
                    {% endif %}

                    {% if paginator.currentPage < paginator.nbPages %}
                        <li>
                            <a class="page-link"
                               href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nbPages }) ) }}">
                               <i class="fa fa-angle-double-right"></i>
                            </a>
                        </li>
                    {% else %}
                        <li class="disabled">
                            <span class="page-link">
                               <i class="fa fa-angle-double-right"></i>
                            </span>
                        </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </div>
{% endif %}
