{#
/**
 * @file
 * Default theme implementation to display a menu.
 *
 * Overrides bootstrap theme implementation.
 *
 * Remove BS dropdown
 * Add .is-expanded and .is-collapsed classes
 * Add BEM style classes to menu markup
 *
 * @ingroup templates
 */
#}
{% import _self as menus %}

{#
  We call a macro which calls itself to render the full tree.
  @see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}

{% macro menu_links(items, attributes, menu_level) %}
  {% import _self as menus %}
  {% if items %}
    <ul{{ attributes.addClass('menu', 'nav') }}>
    {% for item in items %}
      {%
        set item_classes = [
          'menu__item',
          item.is_expanded ? 'is-expanded',
          item.is_collapsed ? 'is-collapsed',
          item.in_active_trail ? 'active-trail',
        ]
      %}
      {% if menu_level == 0 and item.is_expanded %}
        <li{{ item.attributes.addClass(item_classes) }}>
        {{ link(item.title, item.url, { 'class':['menu__link']}) }}
      {% else %}
        <li{{ item.attributes.addClass(item_classes) }}>
        {{ link(item.title, item.url, { 'class':['menu__link']}) }}
      {% endif %}
      {% if item.below %}
        {{ menus.menu_links(item.below, attributes.removeClass('nav'), menu_level + 1) }}
      {% endif %}

      </li>
    {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}
