{% from "@components/usa-pagination/src/includes/_pagination-button.twig" import paginationButton %}

{% set pager_ranges = {
    'default': range(pagination.current - 1, pagination.current + 2),
    'first_set': range(1, 6)
  }
%}

{% set pager_button_opts = {
  'current': pagination.current,
  'total': pagination.items,
  'aria_labels': {
    'page_label': pagination.page_label | default('Page'),
    'previous': pagination.previous.label | default('Previous'),
    'next': pagination.next.label | default('Next'),
    'last': pagination.last_item.label  | default('Last page,')
    }
} %}

{# Page numbers #}
{# List all items if less than 7 #}
{% if pagination.items <= 7 or pagination.current <= 5  %}
  {% for item in pager_ranges.first_set %}
    {{ paginationButton(item, pager_button_opts) }}
  {% endfor %}
{% else %}
  {# First item #}
  {# Example: 1 … 9 *10* 11 … 24 #}
  {{ paginationButton(1, pager_button_opts) }}

  {{ overflow | trim }}

  {% for item in pager_ranges.default %}
    {{ paginationButton(item, pager_button_opts) }}
  {% endfor %}
{% endif %}

{{ overflow | trim }}
