{#
/**
 * @file
 * Theme override to display a menu.
 *
 * Available variables:
 * - menu_name: The machine name of the menu.
 * - items: A nested list of menu items. Each menu item contains:
 *   - attributes: HTML attributes for the menu item.
 *   - below: The menu item child items.
 *   - title: The menu link title.
 *   - url: The menu link url, instance of \Drupal\Core\Url
 *   - localized_options: Menu link localized options.
 *   - is_expanded: TRUE if the link has visible children within the current
 *     menu tree.
 *   - is_collapsed: TRUE if the link has children within the current menu tree
 *     that are not currently visible.
 *   - in_active_trail: TRUE if the link is in the active trail.
 */
#}

{% macro menu_links(
  items,
  attributes,
  has_link_title,
  menu_level,
  bem_menu_block,
  bem_menu_element,
  bem_menu_modifiers,
  bem_item_block,
  bem_item_element,
  bem_item_modifiers,
  parent
) %}
  {% import _self as menus %}

  {% if items %}
    {% set has_link_title = has_link_title|default(false) %}

    {# Set classes #}
    {% set bem_menu_block = bem_menu_block|default('menu') %}
    {% set bem_menu_element = bem_menu_element|default(false) %}
    {% set bem_menu_modifiers = bem_menu_modifiers|default([])|merge([
      menu_level > 0 ? 'sub',
      menu_level > 0 ? 'sub' ~ menu_level,
    ]) %}

    {% set list_attributes = list_attributes|default(create_attribute()) %}

    {% if not attributes.hasAttribute('aria-label') and parent is not empty %}
      {% set list_attributes = list_attributes.setAttribute('aria-label', parent.title) %}
    {% endif %}

    {# List #}
    <ul{{ list_attributes.addClass(bem(bem_menu_block, bem_menu_element, bem_menu_modifiers)) }}>
      {% block list_content %}
        {% for item in items %}
          {% set bem_item_block = bem_item_block|default(false) %}
          {% set bem_item_element = bem_item_element|default(false) %}
          {% set bem_item_modifiers = bem_item_modifiers|default([]) %}
          {% set bem_item_extra = bem_item_extra|default([]) %}

          {% include "@rocketship-theme-starter-atoms/09-menu/menu-item/_menu-item.twig" with {
            "bem_item_block": bem_menu_block,
            "bem_item_modifiers": bem_menu_modifiers,
            bem_item_extra,
            has_link_title,
            link_attribute_class: item.bem_link_extra,
          } %}
        {% endfor %}
      {% endblock list_content %}
    </ul>
  {% endif %}
{% endmacro %}
