{# LIBRARIES #}
{{ attach_library('ui_patterns/menu_il.menu_il_lib') }}

{# VARIABLES #}
{% set icon = icon|default("chevron-down") %}
{% set mid = mid|default(random()) %}

{% set wrapper_attributes = wrapper_attributes|default(create_attribute())%}
{% set wrapper_classes = [
  wrapper_class ? wrapper_class : "",
  "nav-inline",
  "ulc", "ulin"
]%}

{# TEMPLATE #}
{% if links %}
  <nav aria-label="Inline menu {{ mid }}" class="nav-inline-wrapper">
    <ul {{ wrapper_attributes.addClass(wrapper_classes) }} >
      {% if pre_link %}
        <li class="lic liin">{{ pre_link }}</li>
      {% endif %}
      {% for link in links %}
        {% if link['title'] != '<none>' %}
          <li class="lic liin {{ link['li_class'] }}">
            {# Attributes are the wrong format for this template, let's make a filter to catch them #}
            {% set link_attr = create_attribute() %}
            {% set link_class = '' %}
            {% if link['attributes'] and link['attributes'] is iterable %}
              {% for key, value in link['attributes'] %}
                {% set link_attr = link_attr.setAttribute(key,value ) %}
              {% endfor %}
            {% endif %}
            {% include "@atoms/tm-links/icon-bookended/icon-bookended.twig" with {
              "text": link['title'],
              "url": link['url'],
              "icon_left": link['icon'],
              "attr": link_attr,
              "class": link['class'],
            } only %}
          </li>
        {% endif %}
      {% endfor %}
      {% if post_link %}
        <li class="lic liin">{{ post_link }}</li>
      {% endif %}
    </ul>
  </nav>
{% endif %}
