{# Not sure how to handle "this" assignment, leaving this here for now. #}

{# {% if pagination is not defined %}
	{% set pagination = this %}
{% endif %} #}

{% if pagination.pageCount is defined %}
	{% set pagination = pagination(pagination) %}

	{% set paginationListBoundaryLength = 1 %}
	{% set paginationListStart = max([1, pagination.current - paginationListBoundaryLength]) %}
	{% set paginationListEnd = min([pagination.last, paginationListStart + paginationListBoundaryLength * 2]) %}
	{% set paginationListStart = max([1, paginationListEnd - paginationListBoundaryLength * 2]) %}

	{% if pagination.pageCount > 1 %}
		<div class="pager{% if pagination.isAjax %} {{ ' ajax-pagination' }} {% endif %}">
			{% if pagination.current > 1 %}
				<a class="btn pager-prev" href="{{ pagination.urlPrevious }}" title="{{ 'label_previous_page'|trans }}" target="_self" data-page="{{ max([pagination.previous, 1]) }}">
					<svg class="icon icon-chevron-left"><use xlink:href="static/svg/svg-sprite.svg#icon-chevron-left"/></svg>
					{{ 'label_previous_page'|trans }}
				</a>
			{% endif %}
			<ul>
				{% if(paginationListStart != pagination.first) %}
				<li class="pager-first">
					{% set url = pagination.isAjax ? 'javascript:void(0)' : pagination.urlprefix ~ pagination.first %}
					<a href="{{ url }}" data-page="{{ pagination.first }}" title="{{ pagination.first }}" target="_self">{{ pagination.first }}</a>
				</li>
				{% endif %}

				{% for i in paginationListStart..paginationListEnd %}
					{% set url = pagination.isAjax ? 'javascript:void(0)' : pagination.urlprefix ~ i %}
					<li><a href="{{ url }}" title="{{ i }}" target="_self" data-page="{{ i }}"{% if pagination.current == i %} {{ ' class="pager-active"' }} {% endif %}>{{ i }}</a></li>
				{% endfor %}

				{% if(paginationListEnd != pagination.last) %}
					{% set url = pagination.isAjax ? 'javascript:void(0)' : pagination.urlprefix ~ pagination.last %}
					<li class="pager-last">
						<a href="{{ url }}" data-page="{{ pagination.last }}" title="{{ pagination.last }}" target="_self">{{ pagination.last }}</a>
					</li>
				{% endif %}
			</ul>

			{% if pagination.current < pagination.last %}
				<a class="btn pager-next" href="{{ pagination.urlNext }}" title="{{ 'label_next_page'|trans }}" target="_self" data-page="{{ max([pagination.next, 1]) }}">
					{{ 'label_next_page'|trans }}
					<svg class="icon icon-chevron-right"><use xlink:href="static/svg/svg-sprite.svg#icon-chevron-right"/></svg>
				</a>
			{% endif %}
		</div>
	{% endif %}
{% else %}
	<div class="alert alert-info">
		{{ 'msg_no_items_found'|trans }}
	</div>
{% endif %}
