<!DOCTYPE html>
<html lang="{{ app.request.locale|default('fr') }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#383838">
    <title>{% block title %}Admin - VitiCore{% endblock %}</title>
    {{ encore_entry_link_tags('admin', null, 'admin') }}
    {{ encore_entry_script_tags('admin', null, 'admin') }}
    {% block stylesheets %}{% endblock %}
</head>
<body class="admin-shell" x-data="{ sidebarOpen: false }">
{% set current_route = app.request.attributes.get('_route')|default('') %}
{% set settings_active = current_route starts with 'admin_settings'
    or current_route starts with 'admin_shop_config'
    or current_route starts with 'admin_payment'
    or current_route starts with 'admin_product_tax'
    or current_route starts with 'admin_shipping'
    or current_route starts with 'admin_tracking'
    or current_route starts with 'admin_contact'
    or current_route starts with 'admin_user'
    or current_route starts with 'admin_locale'
    or current_route starts with 'admin_shop_information_block'
%}
<div class="admin-layout">
    <aside class="admin-sidebar" :class="{ 'is-open': sidebarOpen }" aria-label="Navigation admin">
        <div class="admin-sidebar-header">
            <a class="admin-brand" href="{{ path('admin_homepage') }}" aria-label="Retour a l'accueil admin">
                <span class="admin-brand-mark">V</span>
                <span>
                    <strong>VitiCore</strong>
                    <small>Administration</small>
                </span>
            </a>
            <button class="admin-sidebar-close" type="button" aria-label="Fermer le menu" @click="sidebarOpen = false">
                <span aria-hidden="true"></span>
            </button>
        </div>

        {% if app.user %}
            <nav class="admin-nav">
                <div class="admin-nav-section">
                    <p class="admin-nav-label">Pilotage</p>
                    <a class="admin-nav-link {{ current_route == 'admin_homepage' ? 'is-active' : '' }}" href="{{ path('admin_homepage') }}">
                        <span class="admin-nav-dot"></span>
                        Accueil
                    </a>

                    {% if is_granted('ROLE_ORDER') or is_granted('ROLE_ADMIN') %}
                        {% set order_group_active = current_route starts with 'admin_order' %}
                        <details class="admin-nav-group {{ order_group_active ? 'is-active' : '' }}" {% if order_group_active %}open{% endif %}>
                            <summary>Commandes</summary>
                            <div>
                                <a class="{{ order_group_active and not (current_route starts with 'admin_order_invoices') and not (current_route starts with 'admin_order_stats') ? 'is-active' : '' }}" href="{{ path('admin_order') }}">Historique</a>
                                {% if invoiceFeatureEnabled() %}
                                    <a class="{{ current_route starts with 'admin_order_invoices' ? 'is-active' : '' }}" href="{{ path('admin_order_invoices') }}">Factures</a>
                                {% endif %}
                                <a class="{{ current_route starts with 'admin_order_stats' ? 'is-active' : '' }}" href="{{ path('admin_order_stats') }}">Statistiques</a>
                            </div>
                        </details>
                    {% endif %}

                    {% if is_granted('ROLE_ADMIN') %}
                        <a class="admin-nav-link {{ current_route starts with 'admin_client' ? 'is-active' : '' }}" href="{{ path('admin_client') }}">
                            <span class="admin-nav-dot"></span>
                            Clients
                        </a>
                    {% endif %}
                </div>

                {% if is_granted('ROLE_ADMIN') or is_granted('ROLE_PRODUCT') %}
                    <div class="admin-nav-section">
                        <p class="admin-nav-label">Catalogue</p>
                        <a class="admin-nav-link {{ (current_route starts with 'admin_product') and not (current_route starts with 'admin_product_category') ? 'is-active' : '' }}" href="{{ path('admin_product') }}">
                            <span class="admin-nav-dot"></span>
                            Produits
                        </a>
                        {% if is_granted('ROLE_ADMIN') %}
                            <a class="admin-nav-link {{ current_route starts with 'admin_product_category' ? 'is-active' : '' }}" href="{{ path('admin_product_category') }}">
                                <span class="admin-nav-dot"></span>
                                Categories
                            </a>
                            <a class="admin-nav-link {{ current_route starts with 'admin_label' ? 'is-active' : '' }}" href="{{ path('admin_label') }}">
                                <span class="admin-nav-dot"></span>
                                Labels
                            </a>
                        {% endif %}
                    </div>
                {% endif %}

                {% if is_granted('ROLE_NEWS') or is_granted('ROLE_ADMIN') or is_granted('ROLE_SOCIAL') %}
                    <div class="admin-nav-section">
                        <p class="admin-nav-label">Contenu</p>
                        {% if is_granted('ROLE_NEWS') or is_granted('ROLE_ADMIN') %}
                            <a class="admin-nav-link {{ current_route starts with 'admin_news' ? 'is-active' : '' }}" href="{{ path('admin_news') }}">
                                <span class="admin-nav-dot"></span>
                                Actualites
                            </a>
                        {% endif %}
                        {% if is_granted('ROLE_SOCIAL') or is_granted('ROLE_ADMIN') %}
                            <a class="admin-nav-link {{ current_route starts with 'admin_social' ? 'is-active' : '' }}" href="{{ path('admin_social') }}">
                                <span class="admin-nav-dot"></span>
                                Reseaux sociaux
                            </a>
                        {% endif %}
                        {% if is_granted('ROLE_ADMIN') %}
                            <a class="admin-nav-link {{ current_route starts with 'admin_library' ? 'is-active' : '' }}" href="{{ path('admin_library') }}">
                                <span class="admin-nav-dot"></span>
                                Mediatheque
                            </a>
                        {% endif %}
                    </div>
                {% endif %}

                {% block menus %}{% endblock %}

                {% if is_granted('ROLE_ADMIN') or is_granted('ROLE_TRACKING') or is_granted('ROLE_SHIPPING') %}
                    <div class="admin-nav-section admin-nav-section-bottom">
                        <a class="admin-nav-link admin-nav-link-settings {{ settings_active ? 'is-active' : '' }}" href="{{ path('admin_settings') }}">
                            <span class="admin-nav-dot"></span>
                            Parametres
                        </a>
                    </div>
                {% endif %}
            </nav>
        {% endif %}
    </aside>

    <div class="admin-mobile-scrim" :class="{ 'is-visible': sidebarOpen }" @click="sidebarOpen = false"></div>

    <div class="admin-main">
        <header class="admin-topbar">
            <button class="admin-icon-button admin-menu-button" type="button" aria-label="Ouvrir le menu" @click="sidebarOpen = true">
                <span class="admin-menu-icon" aria-hidden="true"></span>
            </button>

            <div class="admin-heading">
                <p>{% block section_label %}Administration{% endblock %}</p>
                <h1>{% block page_title %}VitiCore{% endblock %}</h1>
            </div>

            <div class="admin-topbar-actions">
                {% block topbar_actions %}{% endblock %}

                <button class="admin-icon-button admin-alert-button" type="button" aria-label="Alertes">
                    <svg viewBox="0 0 24 24" aria-hidden="true">
                        <path d="M18 8a6 6 0 0 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"></path>
                        <path d="M13.73 21a2 2 0 0 1-3.46 0"></path>
                    </svg>
                </button>

                {% if app.user %}
                    <details class="admin-account">
                        <summary>
                            <span class="admin-account-avatar">{{ app.user.username|default(app.user.email|default('A'))|slice(0, 1)|upper }}</span>
                            <span class="admin-account-copy">
                                <strong>{{ app.user.username|default(app.user.email|default('Admin')) }}</strong>
                                <small>Connecte</small>
                            </span>
                        </summary>
                        <div class="admin-account-menu">
                            <a href="{{ path('admin_logout') }}">Deconnexion</a>
                        </div>
                    </details>
                {% else %}
                    <a class="admin-button admin-button-primary" href="{{ path('login') }}">Connexion</a>
                {% endif %}
            </div>
        </header>

        <div class="admin-workspace {{ settings_active ? 'has-settings-sidebar' : '' }}">
            {% if settings_active %}
                {{ include('@CpCreationVitiCore/admin/settings/_sidebar.html.twig', { current_route: current_route }, with_context=true) }}
            {% endif %}

            <main class="admin-page">
                {% set flashMessages = app.session.flashbag.all() %}
                {% if flashMessages is not empty %}
                    <div class="admin-flashes" role="status" aria-live="polite">
                        {% for type, messages in flashMessages %}
                            {% for message in messages %}
                                <div class="admin-flash admin-flash-{{ type|e('html_attr') }}">
                                    {{ message|raw }}
                                </div>
                            {% endfor %}
                        {% endfor %}
                    </div>
                {% endif %}

                {% block content %}{% endblock %}
            </main>
        </div>
    </div>
</div>

{% block javascripts %}{% endblock %}
</body>
</html>
