{# LIBRARIES #}
{{ attach_library('ui_patterns/libraries.bs_collapse') }}
{{ attach_library('ui_patterns/menu_ac.menu_ac_lib') }}

{# VARIABLES #}
{% set attributes = attributes|default(create_attribute()) %}
{% set class = class|default('') %}
{% set icon_down = icon_down|default(global_icon_down_alt|default('fas fa-angle-down')) %}
{% set toggle = toggle|default('sign') %}
{% set highlight = highlight|default(false) %}

{# STORYBOOK ONLY #}
{% if location %}
<div id="{{ location }}">
  {% endif %}

  {# TEMPLATE #}
  {% if links %}
    <div class="nav-sidebar">

      {% if title and location != 'offcanvas-content' %}
        <h2>
          {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
            "text": title,
            "url": url,
            "icon_right": icon_down,
            "class": "nav-title-link",
          } only %}
        </h2>
      {% endif %}

      <nav aria-label="Sidebar menu">
        <ul {{ attributes.addClass('ulc').addClass(class) }} >
          {% for link in links %}
            {% include "@organisms/tm-menu/menu-ac/menu-ac-item.twig" with {
              "lid": link['lid'],
              "title": link['title'],
              "url": link['url'],
              "sub_links": link['sub_links'],
              "class": link['class'],
              "in_active_trail": link['in_active_trail'],
              "active": link['active'],
              "expanded": link['expanded'],
              "toggle": toggle,
              "highlight": highlight,
            } only %}
          {% endfor %}
        </ul>
      </nav>

    </div>
  {% endif %}

  {# STORYBOOK ONLY #}
  {% if location %}
</div>
{% endif %}
