{% extends 'revervation/base.twig' %}

{# 1. SEO : Titre dynamique et sécurité noindex #}
{% block title %}
    {% if active == 'contrats' %}Mes Contrats
    {% elseif active == 'factures' %}Mes Factures
    {% elseif active == 'devis' %}Mes Devis
    {% elseif active == 'adresses' %}Mes Adresses
    {% elseif active == 'profils' %}Mon Profil
    {% else %}Mon Espace Client
    {% endif %} | Ludik Event
{% endblock %}

{% block extra_header %}
    <meta name="robots" content="noindex, nofollow">
{% endblock %}

{% block body %}
    <div class="bg-gray-50 min-h-screen py-10 px-4">
        <div class="max-w-6xl mx-auto">

            {# Header de bienvenue #}
            <div class="mb-10 flex flex-col md:flex-row md:items-end md:justify-between gap-4">
                <div>
                    <h1 class="text-3xl font-extrabold text-gray-900">Bonjour, {{ app.user.name|default('Client') }} !</h1>
                    <p class="text-gray-600">Gérez vos réservations et documents Ludik Event en un clic.</p>
                </div>
                {% if active != '' %}
                    <a href="{{ path('gestion_contrat', {active: ''}) }}" class="text-blue-600 hover:text-blue-800 font-medium flex items-center gap-2">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clip-rule="evenodd" />
                        </svg>
                        Retour au tableau de bord
                    </a>
                {% endif %}
            </div>
            {# Affichage des messages Flash (Succès / Erreur) #}
            {% for label, messages in app.flashes %}
                {% for message in messages %}
                    <div class="mb-6 p-4 rounded-2xl bg-green-50 border border-green-100 text-green-700 text-sm flex items-center gap-3 animate-fade-in">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
                        </svg>
                        {{ message }}
                    </div>
                {% endfor %}
            {% endfor %}
            {# Navigation Bento Grid #}
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">

                {# 1. Infos Compte #}
                <a href="{{ path('gestion_contrat',{active:'profils'}) }}#gestion-area"
                   class="group md:col-span-2 bg-white p-8 rounded-3xl shadow-sm border-2 transition-all flex justify-between items-center {{ active == 'profils' ? 'border-blue-500 ring-4 ring-blue-50' : 'border-transparent hover:shadow-md hover:border-blue-100' }}">
                    <div>
                        <div class="bg-blue-100 text-blue-600 p-3 rounded-2xl w-fit mb-4">
                            <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
                            </svg>
                        </div>
                        <h2 class="text-xl font-bold text-gray-900">Mes Informations</h2>
                        <p class="text-gray-500">Modifier vos identifiants et mot de passe.</p>
                    </div>
                    <div class="{{ active == 'profils' ? 'text-blue-600' : 'text-gray-300 group-hover:text-blue-600' }} transition-colors">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="9 5l7 7-7 7" />
                        </svg>
                    </div>
                </a>

                {# 2. Mes Adresses #}
                <a href="{{ path('gestion_contrat',{active:'adresses'}) }}#gestion-area"
                   class="group bg-white p-8 rounded-3xl shadow-sm border-2 transition-all {{ active == 'adresses' ? 'border-purple-500 ring-4 ring-purple-50' : 'border-transparent hover:shadow-md hover:border-purple-100' }}">
                    <div class="bg-purple-100 text-purple-600 p-3 rounded-2xl w-fit mb-4">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
                        </svg>
                    </div>
                    <h2 class="text-xl font-bold text-gray-900">Mes Adresses</h2>
                    <p class="text-gray-500 text-sm">Lieux de livraison habituels.</p>
                </a>

                {# 3. Mes Devis #}
                <a href="{{ path('gestion_contrat',{active:'devis'}) }}#gestion-area"
                   class="group bg-white p-8 rounded-3xl shadow-sm border-2 transition-all {{ active == 'devis' ? 'border-yellow-500 ring-4 ring-yellow-50' : 'border-transparent hover:shadow-md hover:border-yellow-100' }}">
                    <div class="bg-yellow-100 text-yellow-600 p-3 rounded-2xl w-fit mb-4">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <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>
                    </div>
                    <h2 class="text-xl font-bold text-gray-900">Mes Devis</h2>
                    <p class="text-gray-500 text-sm">Consulter vos demandes en cours.</p>
                </a>

                {# 4. Mes Factures #}
                <a style="display: none !important;" href="{{ path('gestion_contrat',{active:'factures'}) }}#gestion-area"
                   class="group bg-white p-8 rounded-3xl shadow-sm border-2 transition-all {{ active == 'factures' ? 'border-green-500 ring-4 ring-green-50' : 'border-transparent hover:shadow-md hover:border-green-100' }}">
                    <div class="bg-green-100 text-green-600 p-3 rounded-2xl w-fit mb-4">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <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>
                    </div>
                    <h2 class="text-xl font-bold text-gray-900">Mes Factures</h2>
                    <p class="text-gray-500 text-sm">Historique de vos paiements.</p>
                </a>

                {# 5. Mes Contrats #}
                <a href="{{ path('gestion_contrat',{active:'contrats'}) }}#gestion-area"
                   class="group bg-blue-600 p-8 rounded-3xl shadow-lg border-2 transition-all text-white {{ active == 'contrats' ? 'border-white ring-4 ring-blue-200' : 'border-transparent hover:bg-blue-700' }}">
                    <div class="bg-white/20 p-3 rounded-2xl w-fit mb-4">
                        <svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
                        </svg>
                    </div>
                    <h2 class="text-xl font-bold">Contrats</h2>
                    <p class="text-blue-100 text-sm">Locations validées et signatures.</p>
                </a>

            </div>

            {# Zone d'affichage dynamique #}
            <div id="gestion-area" class="mt-12 scroll-mt-10">
                {% if active is defined and active != '' %}
                    <div class="bg-white rounded-3xl p-6 md:p-10 shadow-xl border border-gray-100 animate-fade-in">
                        {# Inclusion dynamique sécurisée #}
                        {% if active == 'contrats' %}
                            {% include 'reservation/contrat/gestion_contrat/' ~ active ~ '.twig' with {'processedContrats': processedContrats}  %}
                        {% else %}
                            {% include 'reservation/contrat/gestion_contrat/' ~ active ~ '.twig'  %}
                        {% endif %}
                    </div>
                {% else %}
                    {# Message si aucune section n'est sélectionnée #}
                    <div class="hidden md:block text-center py-20 border-2 border-dashed border-gray-200 rounded-3xl">
                        <p class="text-gray-400">Sélectionnez une section ci-dessus pour afficher vos documents.</p>
                    </div>
                {% endif %}
            </div>

            {# Pied de page / Déconnexion #}
            <div class="mt-12 text-center">
                <a href="{{ path('app_logout') }}" class="text-gray-400 hover:text-red-500 transition-colors text-sm font-medium inline-flex items-center gap-2">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <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>
                    Se déconnecter de mon espace
                </a>
            </div>
        </div>
    </div>

    {# Petite animation CSS pour l'apparition du contenu #}
    <style>
        .animate-fade-in {
            animation: fadeIn 0.4s ease-out forwards;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
{% endblock %}
