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

{% block title %}Tableau de bord{% endblock %}

{% block body %}
    <div class="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-500">

        {# WELCOME CARD #}
        <div class="bg-blue-600 rounded-[2rem] p-6 text-white shadow-xl shadow-blue-600/20 relative overflow-hidden">
            <div class="absolute top-0 right-0 -mr-8 -mt-8 w-32 h-32 bg-white/10 rounded-full blur-2xl"></div>

            <p class="text-[10px] font-black uppercase tracking-widest opacity-80 mb-1">Bienvenue</p>
            <h2 class="text-2xl font-black italic tracking-tighter">{{ app.user.userIdentifier }}</h2>

            <div class="mt-6 flex items-center gap-4">
                <div class="bg-white/20 backdrop-blur-md rounded-xl px-4 py-2 flex flex-col">
                    <span class="text-[9px] font-bold uppercase tracking-wide opacity-80">Missions</span>
                    <span class="text-lg font-black">{{ totalMissions }}</span>
                </div>
                <div class="bg-white/20 backdrop-blur-md rounded-xl px-4 py-2 flex flex-col">
                    <span class="text-[9px] font-bold uppercase tracking-wide opacity-80">À venir</span>
                    <span class="text-lg font-black">{{ upcomingMissions }}</span>
                </div>
            </div>
        </div>

        {# SECTIONS #}
        <div class="space-y-4">
            <h3 class="px-2 text-xs font-black text-slate-400 uppercase tracking-widest">Accès Rapide</h3>

                        <div class="grid grid-cols-2 gap-4">
                            <a href="{{ path('etl_contrats') }}" class="bg-white p-5 rounded-[1.5rem] border border-slate-100 shadow-sm hover:border-blue-100 transition-all group active:scale-95">
                                <div class="w-10 h-10 bg-blue-50 rounded-xl flex items-center justify-center text-blue-600 mb-3 group-hover:bg-blue-600 group-hover:text-white transition-colors">
                                    <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="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" /></svg>
                                </div>
                                <p class="text-xs font-bold text-slate-900">Mes Missions</p>
                                <p class="text-[9px] text-slate-400 font-medium mt-0.5">Planning & Détails</p>
                            </a>

                            <a href="{{ path('etl_contrats') }}" class="bg-white p-5 rounded-[1.5rem] border border-slate-100 shadow-sm hover:border-blue-100 transition-all group active:scale-95">
                                <div class="w-10 h-10 bg-emerald-50 rounded-xl flex items-center justify-center text-emerald-600 mb-3 group-hover:bg-emerald-600 group-hover:text-white transition-colors">
                                    <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="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>
                                </div>
                                <p class="text-xs font-bold text-slate-900">Validations</p>
                                <p class="text-[9px] text-slate-400 font-medium mt-0.5">États des lieux</p>
                            </a>
                        </div>
                    </div>

                    {# UPCOMING LIST #}
                    <div class="space-y-4">
                        <h3 class="px-2 text-xs font-black text-slate-400 uppercase tracking-widest">Prochainement</h3>

                                    {% if missions|length > 0 %}
                                        <div class="space-y-3">
                                                                {% for mission in missions %}
                                                                    <a href="{{ path('etl_contrat_view', {id: mission.id}) }}" class="block bg-white rounded-[1.5rem] p-4 border border-slate-100 flex items-center justify-between hover:bg-slate-50 transition-colors">
                                                                        <div>
                                                                            <p class="text-[9px] font-black uppercase text-blue-500 mb-0.5">
                                                                                {{ mission.dateAt|date('d/m H:i') }} <span class="text-slate-300 mx-1">➜</span> {{ mission.endAt|date('d/m H:i') }}
                                                                            </p>
                                                                            <p class="text-xs font-bold text-slate-900">{{ mission.numReservation }} - {{ mission.townEvent }}</p>
                                                                            <p class="text-xs font-bold text-slate-900"> {{ mission.customer.name }} {{ mission.customer.surname }}</p>
                                                                            {% if mission.etatLieux is not null and mission.etatLieux.status == "edl_validated" %}
                                                                                <p class="text-xs font-bold text-slate-900">En attends de l'état de retour</p>
                                                                            {% endif %}
                                                                        </div>
                                                                    </a>
                                                                {% endfor %}                                        </div>
                                    {% else %}                            <div class="bg-white rounded-[2rem] border border-slate-100 p-8 text-center">
                                <div class="inline-flex p-4 bg-slate-50 rounded-full text-slate-300 mb-3">
                                    <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><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>
                                <p class="text-xs font-bold text-slate-900">Aucune mission à venir</p>
                                <p class="text-[10px] text-slate-400 mt-1">Votre planning est vide pour le moment.</p>
                            </div>
                        {% endif %}
                    </div>
    </div>
{% endblock %}
