{#
/**
 * @file
 * Template for a Pagination components.
 *
 * Available config:
 * - utility_classes: An array of utility classes.
 * - size: sm, md, lg
 * - alignment: left | right | center | vertical.
 */
 */
#}

{% if alignment == 'right' %}
  {% set alignment = 'justify-content-end' %}
{% elseif alignment == 'center' %}
  {% set alignment = 'justify-content-center' %}
{% else %}
  {% set alignment = '' %}
{% endif %}

{% set attributes = create_attribute() %}

{% if items %}
  <nav {{ attributes.addClass(utility_classes|join(' '))}} role="navigation" aria-label="{{ 'Pagination'|t }}">
    <div class="pager pager__items js-pager__items {{ size ? 'pagination-' ~ size }} {{ alignment }}">
      <div class="pager__jump-group flex">
      {# Print first item if we are not on the first page. #}
      {% if items.first %}
        <div class="page-item pager__item pager__item--first">
          <a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title') }} class="page-link">
            <span class="visually-hidden">{{ 'First page'|t }}</span>
            <span aria-hidden="true">{{ items.first.text|default('« First'|t) }}</span>
          </a>
        </div>
      {% endif %}
      {# Print previous item if we are not on the first page. #}
      {% if items.previous %}
        <div class="page-item pager__item pager__item--previous">
          <a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel') }} class="page-link">
            <span class="visually-hidden">{{ 'Previous page'|t }}</span>
            <span aria-hidden="true">{{ items.previous.text|default('‹ Previous'|t) }}</span>
          </a>
        </div>
      {% endif %}
      </div>

      {# Now generate the actual pager piece. #}
      <ol class="pager__pages list-none flex flex-wrap">
      {% for key, item in items.pages %}
        <li class="page-item pager__item{{ current == key ? ' is-active active' : '' }}">
          {% if current == key %}
            {% set title = 'Current page'|t %}
          {% else %}
            {% set title = 'Go to page @key'|t({'@key': key}) %}
          {% endif %}
          <a href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title') }} class="page-link">
            <span class="visually-hidden">
              {{ current == key ? 'Current page'|t : 'Page'|t }}
            </span>
            {{- key -}}
          </a>
        </li>
      {% endfor %}
      </ol>


      {% if items.current and (items.previous or items.next) %}
        <div class="page-item disabled">
          <span class="page-link">
            {% trans %}Page {{ items.current }}{% endtrans %}
          </span>
        </div>
      {% endif %}

      {# Print next item if we are not on the last page. #}
      <div class="pager__jump-group flex">
      {% if items.next %}
        <div class="page-item pager__item pager__item--next">
          <a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel') }} class="page-link">
            <span class="visually-hidden">{{ 'Next page'|t }}</span>
            <span aria-hidden="true">{{ items.next.text|default('Next ›'|t) }}</span>
          </a>
        </div>
      {% endif %}
      {# Print last item if we are not on the last page. #}
      {% if items.last %}
        <div class="page-item pager__item pager__item--last">
          <a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title') }} class="page-link">
            <span class="visually-hidden">{{ 'Last page'|t }}</span>
            <span aria-hidden="true">{{ items.last.text|default('Last »'|t) }}</span>
          </a>
        </div>
      {% endif %}
      </div>
    </div>
  </nav>
  {% if libraries %}
    {% for library in libraries %}
      {{ attach_library(library) }}
    {% endfor %}
  {% endif %}
{% endif %}
