{% extends 'base.html.twig' %}

{% block body_class %}{% endblock %}
{% block header %}{% endblock %}
{% block main_class %}flex{% endblock %}

{% set current_route = app.request.attributes.get('_route') %}

{% block body %}
<div class="admin-wrapper">
    <aside class="admin-sidebar glass-dark-heavy flex flex-col" id="admin-sidebar" >
        <div class="p-5 border-b border-white/10">
            <a href="{{ path('app_admin_dashboard') }}" class="flex items-center gap-3">
                <img class="h-8 w-auto" src="{{ 'logo.jpg' | imagine_filter('navbar_logo') }}" alt="CRM E-Cosplay" loading="eager">
                <span class="text-white/80 font-bold uppercase text-xs tracking-widest">Admin</span>
            </a>
        </div>

        <nav class="flex-1 py-4 px-3 space-y-1 overflow-y-auto">
            <a href="{{ path('app_admin_dashboard') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_dashboard' ? 'active' : '' }}">
                <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
                Tableau de bord
            </a>
            <div class="sidebar-dropdown">
                <button class="sidebar-dropdown-btn sidebar-nav-item w-full justify-between {{ current_route starts with 'app_admin_services' ? 'active' : '' }}">
                    <span class="flex items-center gap-3">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2"/></svg>
                        Services
                    </span>
                    <svg class="w-3 h-3 sidebar-dropdown-arrow transition-transform {{ current_route starts with 'app_admin_services' ? 'rotate-180' : '' }}" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M19 9l-7 7-7-7"/></svg>
                </button>
                <div class="sidebar-dropdown-menu ml-7 pl-3 border-l border-white/10 space-y-0.5 py-1 {{ current_route starts with 'app_admin_services' ? '' : 'hidden' }}">
                    <a href="{{ path('app_admin_services_esyweb') }}" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_esyweb' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Site</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_mail' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Mail</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_mailer' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Mailer</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_analytics' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Track</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_monitor' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Monitor</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_defender' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Protect</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_translate' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Translate</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_signature' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Sign</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_creator' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Creator</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_aide' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Aide</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_meet' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Calendar</a>
                    <a href="#" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_tchat' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">E-Chat</a>
                    <a href="{{ path('app_admin_services_ndd') }}" class="block px-3 py-1.5 text-[10px] font-bold uppercase tracking-widest transition-all {{ current_route == 'app_admin_services_ndd' ? 'text-[#fabf04]' : 'text-white/40 hover:text-white/70' }}">Nom de domaine</a>
                </div>
            </div>
            <a href="{{ path('app_admin_clients_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_clients' ? 'active' : '' }}">
                <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
                Clients
            </a>
            <a href="{{ path('app_admin_contrats_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_contrats' ? 'active' : '' }}">
                <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
                Contrats
            </a>
            <a href="{{ path('app_admin_facturation_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_facturation' ? 'active' : '' }}">
                <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 14l6-6m-5.5.5h.01m4.99 5h.01M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16l3.5-2 3.5 2 3.5-2 3.5 2z"/></svg>
                Facturation
            </a>
            <a href="{{ path('app_admin_revendeurs_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_revendeurs' ? 'active' : '' }}">
                <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
                Revendeurs
            </a>

            {% if is_granted('ROLE_ROOT') %}
                <div class="pt-4 mt-4 border-t border-white/10">
                    <p class="px-3 mb-2 text-[9px] font-bold uppercase tracking-widest text-red-400/70">Super Admin</p>
                    <a href="{{ path('app_admin_membres') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_membres' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_membres' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/></svg>
                        Administration
                    </a>
                    <a href="{{ path('app_admin_stats_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_stats' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_stats' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/></svg>
                        Statistiques
                    </a>
                    <a href="{{ path('app_admin_prestataires_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_prestataires' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_prestataires' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
                        Prestataires
                    </a>
                    <a href="{{ path('app_admin_comptabilite_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_comptabilite' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_comptabilite' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 7h6m0 10v-3m-3 3h.01M9 17h.01M9 14h.01M12 14h.01M15 11h.01M12 11h.01M9 11h.01M7 21h10a2 2 0 002-2V5a2 2 0 00-2-2H7a2 2 0 00-2 2v14a2 2 0 002 2z"/></svg>
                        Comptabilite
                    </a>
                    <a href="{{ path('app_admin_status_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_status' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_status' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/></svg>
                        Status services
                    </a>
                    <a href="{{ path('app_admin_sync_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_sync' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_sync' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
                        Synchronisation
                    </a>
                    <a href="{{ path('app_admin_order_number') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_order_number' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_order_number' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14"/></svg>
                        Numerotation
                    </a>
                    <a href="{{ path('app_admin_logs') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_logs' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_logs' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
                        Logs
                    </a>
                    <a href="{{ path('app_admin_tarification') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_tarification' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_tarification' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                        Tarification
                    </a>
                    <a href="{{ path('app_admin_attestation_custom_index') }}" class="sidebar-nav-item {{ current_route starts with 'app_admin_attestation_custom' ? 'active-danger' : '' }}" style="color: {{ current_route starts with 'app_admin_attestation_custom' ? 'white' : 'rgba(248,113,113,0.7)' }}">
                        <svg class="w-4 h-4 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                        Attestations
                    </a>
                </div>
            {% endif %}
        </nav>

        <div class="p-4 border-t border-white/10">
            <a href="{{ path('app_admin_profil') }}" class="flex items-center gap-3 mb-3 p-2 -m-2 hover:bg-white/5 transition-colors">
                {% if app.user.avatar %}
                    <img src="{{ ('uploads/avatars/' ~ app.user.avatar) | imagine_filter('avatar_small') }}" alt="Avatar" class="w-8 h-8 border border-white/10 object-contain">
                {% else %}
                    <div class="w-8 h-8 bg-[#fabf04] flex items-center justify-center font-bold text-xs text-gray-900">
                        {{ app.user.firstName|first }}{{ app.user.lastName|first }}
                    </div>
                {% endif %}
                <div class="flex-1 min-w-0">
                    <p class="text-white text-xs font-bold truncate">{{ app.user.fullName }}</p>
                    <p class="text-white/40 text-[10px] truncate">{{ app.user.email }}</p>
                </div>
                {% if is_granted('ROLE_ROOT') %}
                    <span class="px-1.5 py-0.5 bg-red-500/80 text-white text-[8px] font-bold uppercase">Root</span>
                {% endif %}
            </a>
            <a href="{{ path('app_logout') }}" class="flex items-center justify-center gap-2 w-full px-3 py-2 border border-white/10 text-white/50 text-xs font-bold uppercase tracking-widest hover:bg-white/5 hover:text-white/80 transition-all">
                <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/></svg>
                Deconnexion
            </a>
        </div>
    </aside>

    <div class="admin-overlay" id="admin-overlay"></div>

    <div class="admin-content glass-bg flex flex-col">
        <div class="sticky top-0 z-30 glass-heavy px-4 py-3 flex items-center justify-between gap-4" style="border-bottom: 3px solid #fabf04;">
            <button id="admin-sidebar-toggle" class="lg:hidden text-gray-500 hover:text-gray-900" aria-label="Menu">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/></svg>
            </button>

            <div class="flex-1 max-w-xl relative">
                <input type="text" id="global-search" placeholder="Recherche rapide (client, domaine, site, contact...)"
                       class="w-full px-4 py-2 pl-9 input-glass text-xs font-medium" autocomplete="off">
                <svg class="w-3.5 h-3.5 absolute left-3 top-2.5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>
                <div id="global-search-results" class="hidden absolute left-0 right-0 top-full mt-1 glass-heavy border border-white/30 max-h-80 overflow-y-auto z-50" >
                </div>
            </div>

            <div class="flex items-center gap-3">
                <span class="hidden md:block text-[10px] font-bold uppercase tracking-wider text-gray-400">{{ app.user.fullName }}</span>
            </div>
        </div>

        {% block admin_content %}{% endblock %}
    </div>
</div>
{% endblock %}

{% block footer %}{% endblock %}
