{% import "helpers/components.nunj" as comp %}

{% macro components(items, current, currentDepth, maxDepth, navSort) %}

    {% for item in items %}
        {% if item.type == 'collection' %}
        <li class="MainNav-item MainNav-item--group MainNav-toggled">
            <h4 class="MainNav-itemLabel MainNav-heading MainNav-subSectionToggle">{{ item.labelPathFrom(currentDepth-1) if currentDepth >= maxDepth else item.label }}</h4>
            <ul class="MainNav-children">
            {% set nextItems = item.squash() if (currentDepth + 1) >= maxDepth else item %}
            {{ components(nextItems.orderBy(navSort).items(), current, (currentDepth + 1), maxDepth) }}
            </ul>
        </li>
        {% else %}
        <li class="MainNav-item MainNav-item--sub MainNav-item--component{% if current and (current.handle == item.handle) %} is-current{% endif %}" data-status="{{ status.name }}">
            <a class="MainNav-itemLabel MainNav-link" href="{{ frctl.web.theme.urlFromRoute('component', {handle: item.handle }) }}" data-pjax>
                <span>{{ item.label }}</span> {{ comp.status(item.status) }}
            </a>
        </li>
        {% endif %}
    {% endfor %}
{% endmacro %}

{% macro pages(items, current) %}
    {% for item in items %}
        {% if item.type == 'collection' %}
        <li class="MainNav-item MainNav-item--group">
            <h4 class="MainNav-itemLabel MainNav-heading MainNav-subSectionHeading">{{ item.labelPath }}</h4>
            <ul class="MainNav-children">
            {{ pages(item.items(), current) }}
            </ul>
        </li>
        {% else %}
        {% if item.path != '' %}
        <li class="MainNav-item MainNav-item--sub MainNav-item--page{% if current and (current.handle == item.handle) %} is-current{% endif %}" data-status="{{ item.status.name }}">
            <a class="MainNav-itemLabel MainNav-link" href="{{ frctl.web.theme.urlFromRoute('page', {path: item.path }) }}" data-pjax>
                <span>{{ item.label }}</span>
            </a>
        </li>
        {% endif %}
        {% endif %}
    {% endfor %}
{% endmacro %}
