{#
    /**
     * This file is part of FacturaScripts
     * Copyright (C) 2017-2025 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 ? parent ~ menuItem.name : 'menu_' ~ menuItem.name %}

    {% if not parent %}
        {# Main level menu/submenu #}
        <li id="{{ menuId | lower }}" class="fs-menu-item nav-item dropdown">
            <a class="nav-link dropdown-toggle{{ active }}" href="#" data-bs-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 id="{{ menuId | lower }}" class="fs-menu-item dropdown-submenu">
            <a class="dropdown-item{{ active }}" href="#">
                <i class="fa-solid fa-folder-open fa-fw me-1" aria-hidden="true"></i> {{ menuItem.title }}
            </a>
            <ul class="dropdown-menu" aria-labelledby="{{ menuId }}">
    {% endif %}

    {% for item in menuItem.menu %}
        {% set extraClass = item.active ? ' active' : '' %}
        {% set childId = menuId ~ '_' ~ item.name %}

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