{# VARIABLES #}
{% set depth = depth|default(0) %}
{% set depth = depth + 1 %}
{% set in_active_trail = in_active_trail|default(false) %}
{% set active = active|default(false) %}
{% set expanded = expanded|default(false) %}

{# TEMPLATE #}
{% if sub_links is not empty %}
  <li class="parent depth-{{ depth }} lic">

    {% if title != '<none>'%}
      {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
        "text": title,
        "url": url,
        "class": active ? 'active',
      } only %}
    {% endif %}

    {% if not expanded %}

      {% set attr = create_attribute()
        .setAttribute('data-bs-toggle', 'collapse')
        .setAttribute('role', 'button')
        .setAttribute('tabindex', '0')
        .setAttribute('aria-expanded', (in_active_trail or active) ? 'true' : 'false')
        .setAttribute('aria-controls', "mc-#{ lid }")
      %}
      {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
        "text": "<span class='sr-only'>Open</span>",
        "url": "#mc-#{ lid }",
        "attr": attr,
        "toggle": 'sign',
        "class": 'beliag menu-collapse',
        "toggle_open": (in_active_trail or active) ? true : false,
      } only %}

    {% endif %}

    <ul class="{{ not expanded ? 'collapse' }} ulc {{ in_active_trail ? 'show active-trail' }}  {{ active ? 'show active-parent' }}" id="mc-{{ lid }}">
      {% for s_link in sub_links %}
        {% include "@organisms/tm-menu/menu-ac/menu-ac-item.twig" with {
          "lid": s_link['lid'],
          "title": s_link['title'],
          "url": s_link['url'],
          "sub_links": s_link['sub_links'],
          "in_active_trail": s_link['in_active_trail'],
          "active": s_link['active'],
          "depth": depth,
        } only %}
      {% endfor %}
    </ul>
  </li>
{% else %}
  {% if title != '<none>'%}
    <li class="depth-{{ depth }} lic">
      {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
        "text": title,
        "url": url,
        "class": active ? 'active'
      } only %}
    </li>
  {% endif %}
{% endif %}
