{% load i18n %}
{% load milea_menu %}
{% if app_list %}
    {% for app in app_list %}
        {% app_additional_config app as app_infos %}
        <li class="nav-item dropdown {% if app.app_url in request.path|urlencode %} active{% endif %}">
            <a class="nav-link dropdown-toggle"
                href="#navbar-help"
                data-bs-toggle="dropdown"
                data-bs-auto-close="outside"
                role="button"
                aria-expanded="false">
                <span class="nav-link-icon d-md-none d-lg-inline-block">
                    <i class="{{ app_infos.menu_icon }} fs-2"></i>
                </span>
                <span class="nav-link-title">{{ app.name }}</span>
            </a>
            <div class="dropdown-menu">

                <!-- Firstlevel Menu -->
                {% for model in app_infos.menu_firstlevel %}
                    {% if model.admin_url %}
                        <a class="dropdown-item {% if model.admin_url in request.path|urlencode %}active{% endif %}"
                            href="{{ model.admin_url }}">{{ model.name }}</a>
                    {% else %}
                        <a class="dropdown-item disabled" href="#">{{ model.name }}</a>
                    {% endif %}
                {% endfor %}

                <!-- Secondlevel Menu = menu_dropend -->
                {% for secondlevel in app_infos.menu_secondlevel %}
                    <div class="dropend">
                        <a class="dropdown-item dropdown-toggle" href="#secondlevel-{{ secondlevel.key }}" data-bs-toggle="dropdown" data-bs-auto-close="outside" role="button" aria-expanded="false">
                            {{ secondlevel.name }}
                        </a>
                        <div class="dropdown-menu">
                            {% for model in secondlevel.models %}
                                {% if model.admin_url %}
                                    <a class="dropdown-item {% if model.admin_url in request.path|urlencode %}active{% endif %}"
                                        href="{{ model.admin_url }}">{{ model.name }}</a>
                                {% else %}
                                    <a class="dropdown-item disabled" href="#">{{ model.name }}</a>
                                {% endif %}
                            {% endfor %}
                        </div>
                    </div>
                {% endfor %}

            </div>
        </li>
    {% endfor %}
{% else %}
    <p>{% translate "You don’t have permission to view or edit anything." %}</p>
{% endif %}
