{# Parameters:
  - size (string) (default: '')
    - options ['sm', 'lg']
  - alignment (string) (default: '')
    - options ['end', 'center']
  - variant: (string) (default: '')
    - options: ['glossary']
  - aria_label (string) (default: '') - deprecated, use attributes
  - enable_prev_next_icon (boolean) (default: false)
  - enable_first_last_icon (boolean) (default: true)
  - ellipsis_before (boolean) (default: false)
  - ellipsis_after (boolean) (default: false)
  - first (pagination Item object) (default: {})
  - prev (pagination Item object) (default: {})
  - next (pagination Item object) (default: {})
  - last (pagination Item object) (default: {})
  - items (pagination item[]) (default: [])
    format: [
    {
      - path (string) (default: '')
      - label (string) (default: '')
      - disabled (boolean) (default: false)
      - active (boolean) (default: false)
      - aria_label (string) (default: '') - deprecated, use attributes
      - icon (Icon component) (default: {})
      - attributes (drupal attrs)
    }
  - icon_path (string) (default: '')
  - attributes (drupal attrs)
  - list_attributes (drupal attrs)
#}

{%- set _size = size|default('') %}
{% set _alignment = alignment|default('') %}
{% set _variant = variant|default('') %}
{% set _aria_label = aria_label|default('') %}
{% set _enable_prev_next_icon = enable_prev_next_icon ?? false %}
{% set _enable_first_last_icon = enable_first_last_icon ?? true %}
{% set _ellipsis_before = ellipsis_before ?? false %}
{% set _ellipsis_after = ellipsis_after ?? false %}
{% set _first = first|default({}) %}
{% set _prev = prev|default({}) %}
{% set _next = next|default({}) %}
{% set _last = last|default({}) %}
{% set _items = items|default([]) %}
{% set _icon_path = icon_path|default('') %}
{% set _internal_items = [] %}

{%- if _enable_first_last_icon %}
  {%- if _first is not empty %}
    {%- set _first = _first|merge({
      icon_html: "&laquo;",
      icon_name: "chevron-double-left",
    }) %}
  {%- endif %}
  {%- if _last is not empty %}
    {%- set _last = _last|merge({
      icon_html: '&raquo;',
      icon_name: "chevron-double-right",
    }) %}
  {%- endif %}
{% endif %}

{%- if _enable_prev_next_icon %}
  {%- if _prev is not empty %}
    {%- set _prev = _prev|merge({
      icon_html: "&lsaquo;",
      icon_name: "chevron-left",
    }) %}
  {%- endif %}
  {%- if _next is not empty %}
    {%- set _next = _next|merge({
      icon_html: "&rsaquo;",
      icon_name: "chevron-right",
    }) %}
  {%- endif %}
{% endif %}


{%- set _internal_items = _internal_items|merge([_first, _prev]) %}

{%- set _ellipsis_markup %} &hellip; {% endset %}

{%- if _ellipsis_before %}
  {%- set _ellipsis_before_item = {
    icon_html: _ellipsis_markup,
    icon_path: "",
  } %}
  {%- set _internal_items = _internal_items|merge([_ellipsis_before_item]) %}
{% endif %}

{%- set _internal_items = _internal_items|merge(_items) %}

{%- if _ellipsis_after %}
  {%- set _ellipsis_after_item = {
    icon_html: _ellipsis_markup,
    icon_path: "",
  } %}
  {%- set _internal_items = _internal_items|merge([_ellipsis_after_item]) %}
{% endif %}

{%- set _internal_items = _internal_items|merge([_next, _last]) %}

{%- if list_attributes is empty %}
  {%- set list_attributes = create_attribute() %}
{% endif %}

{%- set list_attributes = list_attributes.addClass('pagination') %}
{% if _size is not empty %}
  {%- set list_attributes = list_attributes.addClass('pagination-' ~ _size) %}
{% endif %}
{% if _variant is not empty %}
  {%- set list_attributes = list_attributes.addClass('pagination--' ~ _variant) %}
{% endif %}
{% if _alignment is not empty %}
  {%- set list_attributes = list_attributes.addClass('justify-content-' ~ _alignment) %}
{% endif %}

{%- if attributes is empty %}
  {%- set attributes = create_attribute() %}
{% endif %}

{%- set attributes = attributes.setAttribute('role', 'navigation') %}

{%- if _variant == 'glossary' %}
  {%- set attributes = attributes.addClass(['bcl-glossary']) %}
{% endif %}

{%- if _aria_label is not empty %}
  {%- set attributes = attributes.setAttribute('aria-label', aria_label) %}
{% endif -%}

<nav{{ attributes }}>{# -#}
  <ul{{ list_attributes }}>
{%- if _internal_items is not empty and _internal_items is iterable %}
  {%- for _item in _internal_items %}
    {%- if _item is not empty %}
      {%- set _item_class = ['page-item'] %}
      {%- if _item.disabled %}
        {%- set _item_class = _item_class|merge(['disabled']) %}
      {%- endif %}
      {%- if _item.active %}
        {%- set _item_class = _item_class|merge(['active']) %}
      {%- endif -%}
      <li class="{{ _item_class|join(' ') }}">
        {%- if _item.icon_path is not defined %}
          {%- set _item = _item|merge({
            icon_path: _icon_path,
          }) %}
        {%- endif %}
        {%- include '@oe-bcl/bcl-pagination/pagination-item.html.twig' with _item only -%}
      </li>
    {%- endif %}
  {%- endfor %}
{% endif -%}
  </ul>{# -#}
</nav>
{#--#}
