{#
/**
 * @file
 * Default theme implementation to display wizard tree.
 *
 * Available variables:
 * - step: The current step name.
 * - tree: A nested list of menu items. Each menu item contains:
 *   - title: The menu link title.
 *   - url: The menu link url, instance of \Drupal\Core\Url
 *   - children: The menu item child items.
 *   - step: The name of the step.
 *
 * @ingroup themeable
 */
#}

{{ attach_library('page_manager_ui/page_variants') }}

{% import _self as page_manager %}

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

{% macro wizard_tree(items, step, menu_level) %}
  {% import _self as page_manager %}
  {% if items %}
    <ul class="page__section__{{ menu_level }}">

    {% for item in items %}
      {% if step is same as(item.step) %}
        {% set active_class = " current_variant" %}
      {% else %}
        {% set active_class = "" %}
      {% endif %}
      <li class="page__section_item__{{ menu_level }}{{ active_class }}">
        <label class="page__section__label">
          {% if item.url %}
            {% if step is same as(item.step) %}
              <strong>{{ link(item.title, item.url) }}</strong>
            {% else %}
              {{ link(item.title, item.url) }}
            {% endif %}
          {% else %}
            {{ item.title }}
          {% endif %}
        </label>
        {% if item.children %}
          {{ page_manager.wizard_tree(item.children, step, menu_level + 1) }}
        {% endif %}
      </li>
    {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}
