{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_collapse') }}
{{ attach_library('ui_patterns/menu_ft.menu_ft_lib') }}

{# VARIABLES #}
{% set icon = icon|default(global_icon_down|default('fas fa-chevron-down')) %}
{% set mid = mid|default(random()) %}
{% set url = url|default(null) %}
{% set collapse = collapse|default(false) %}
{% set title_attributes = create_attribute() %}
{% set nav_attributes = create_attribute() %}
{% set wrapper_attributes = wrapper_attributes|default(create_attribute())%}
{% set wrapper_classes = [
  wrapper_class ? wrapper_class : "",
  "nav-footer"
]%}
{% set toggle = null %}
{% set title_class = "ft-title-link" %}

{% if collapse %}
  {% set title_attributes = title_attributes
    .setAttribute('data-bs-toggle', 'collapse')
    .setAttribute('tabindex', '0')
    .setAttribute('data-bs-target', "#ftml-#{ mid }")
    .setAttribute('aria-expanded', 'false')
  %}
  {% set nav_attributes = nav_attributes
    .setAttribute('id', "ftml-#{ mid }")
    .setAttribute('aria-expanded', 'false')
    .setAttribute('aria-label', "Footer menu #{ mid }")
    .addClass('collapse')
  %}
  {% set toggle = "sign" %}
  {% set title_class = "ft-title-link collapsed belirf beliag" %}
{% endif %}

{# TEMPLATE #}
{% if links %}
  <div {{ wrapper_attributes.addClass(wrapper_classes) }}>
    {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
      "attr": title_attributes,
      "text": title,
      "tag_name": 'h2',
      "icon_left": icon,
      "class": title_class,
      "toggle": toggle,
    } only %}
    <nav {{ nav_attributes }}>
      <ul class="ulc">
        {% for link in links %}
          {% if link['title'] != '<none>' %}
            <li class="lic">
              {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
                "text": link['title'],
                "url": link['url'],
                "icon_left": global_icon_right|default('fas fa-chevron-right'),
                "class": "ft-list-link",
              } only %}
            </li>
          {% endif %}
        {% endfor %}
      </ul>
    </nav>
  </div>
{% endif %}
