{#
    /**
     * This file is part of FacturaScripts
     * Copyright (C) 2017-2019 Carlos Garcia Gomez <carlos@facturascripts.com>
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     * GNU Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public License
     * along with this program. If not, see <http://www.gnu.org/licenses/>.
     */
#}

{% macro showMenu(menuItem, parent) %}
    {% import _self as macros %}
    {% set active = menuItem.active ? ' active' : '' %}
    {% set menuId = parent is empty ? 'menu-' ~ menuItem.title : parent ~ menuItem.name %}

    {% if parent is empty %}
        {# Main level menu/submenu #}
        <li class="nav-item dropdown{{ active }}">
            <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                {% set title = menuItem.title %}
                <span class="d-md-none">{{ title | slice(0, 2) }}</span>
                <span class="d-none d-md-inline-block">{{ title }}</span>
            </a>
            <ul class="dropdown-menu" aria-labelledby="{{ menuId }}">
    {% else %}
        {# Child level submenu #}
        <li class="dropdown-submenu">
            <a class="dropdown-item{{ active }}" href="#">
                <i class="fas fa-folder-open fa-fw" aria-hidden="true"></i>
                &nbsp;{{ menuItem.title }}
            </a>
            <ul class="dropdown-menu" aria-labelledby="{{ menuId }}">
    {% endif %}

    {% for item in menuItem.menu %}
        {% set extraClass = item.active ? ' active' : '' %}

        {% if item.menu is empty %}
            <li>
                <a class="dropdown-item{{ extraClass }}" href="{{ item.url }}">
                    <i class="{{ item.icon }} fa-fw" aria-hidden="true"></i> &nbsp;{{ item.title }}
                </a>
            </li>
        {% else %}
            {{ macros.showMenu(item, menuId) }}
        {% endif %}
    {% endfor %}
    </ul>
{% endmacro %}