{#
Parameters:
  - title: (string) (default: '')
  - title_tag: (string) (default: 'h2')
  - title_link: (link object) (default: {})
  - title_attributes (drupal attrs)
  - links: (link[]) (default: [])
  - id (string) (default: bcl-inpage-navigation-random(10000))
  - dropdown_id (string) (default: bcl-inpage-navigation-dropdown-random(10000))
  - dynamic_active: (boolean) (default: false)
  - icon_path (string) (default: '')
  - attributes (drupal attrs)
#}

{%- set _title = title|default('') %}
{% set _title_tag = title_tag|default('h2') %}
{% set _title_link = title_link|default({}) %}
{% set _title_attributes = title_attributes ?: create_attribute() %}
{% set _links = links|default([]) %}
{% set _id = id|default('bcl-inpage-navigation-' ~ random(10000)) %}
{% set _icon_path = icon_path|default('') %}
{% set _dropdown_id = dropdown_id|default('bcl-inpage-navigation-dropdown' ~ random(10000)) %}
{% set _dyanmic_active = dynamic_active|default(false) %}

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

{%- set attributes = attributes.addClass(['bcl-inpage-navigation', 'position-sticky']).setAttribute('id', _id) %}

{%- if not attributes.hasAttribute('aria-label') and not attributes.hasAttribute('aria-labelledby') %}
  {%- set attributes = attributes.setAttribute('aria-labelledby', _dropdown_id) %}
{% endif %}

{%- set title_attributes = _title_attributes.addClass(['mb-0', 'd-none', 'd-md-block']) %}
{% set _button_content %}
  {{- _title }}
  {%- include '@oe-bcl/bcl-icon/icon.html.twig' with {
    name: 'chevron-down',
    size: 's',
    path: _icon_path,
  } only -%}
{% endset %}

{%- set _classes = [] %}

{%- if _dyanmic_active %}
  {%- set _classes = _classes|merge(['dynamic-active']) %}
{% endif -%}

<nav{{ attributes.addClass(_classes) }}>
  {%- set trigger_attributes = create_attribute()
                              .setAttribute('aria-expanded', 'false')
                              .setAttribute('type', 'button')
                              .setAttribute('id', _dropdown_id)
                              .setAttribute('data-bs-toggle', 'dropdown')
                              .addClass(['dropdown-toggle', 'h2', 'd-md-none']) %}
  {%- include '@oe-bcl/bcl-button/button.html.twig' with {
    label: _button_content,
    clean_class: true,
    attributes: trigger_attributes,
  } only %}
  {%- include '@oe-bcl/bcl-heading/heading.html.twig' with {
    title: _title,
    title_tag: _title_tag,
    title_link: _title_link,
    attributes: _title_attributes,
  } only -%}
  <div class="dropdown-menu">
    {%- include '@oe-bcl/bcl-navigation/navigation.html.twig' with {
      'pills': true,
      'vertical': true,
      'items': _links,
    } only -%}
  </div>{# -#}
</nav>
{#--#}
