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

{% block title %}Signature EDL - #{{ mission.numReservation }}{% endblock %}

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

        {# HEADER #}
        <div class="flex items-center gap-4">
            <a href="{{ path('etl_contrat_view', {id: mission.id}) }}" class="w-10 h-10 bg-white rounded-xl border border-slate-100 flex items-center justify-center text-slate-400 hover:text-blue-600 transition-all shadow-sm">
                <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="M15 19l-7-7 7-7" /></svg>
            </a>
            <div>
                <h1 class="text-xl font-black text-slate-900 tracking-tight">Signature</h1>
                <p class="text-[10px] font-bold text-slate-400 uppercase tracking-widest">Réf: #{{ mission.numReservation }}</p>
            </div>
        </div>

        <div class="bg-blue-600 rounded-[2rem] p-8 text-white shadow-xl shadow-blue-600/20 text-center 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>
            <h2 class="text-2xl font-black mb-2">État des Lieux Terminé</h2>
            <p class="text-sm font-medium opacity-90 mb-6">Veuillez procéder à la signature du document.</p>

            <a href="{{ path('etl_edl_regenerate_view', {id: mission.id}) }}" target="_blank" class="inline-flex items-center px-6 py-3 bg-white/20 hover:bg-white/30 text-white rounded-xl text-xs font-bold uppercase tracking-widest backdrop-blur-sm transition-all border border-white/30">
                <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" /></svg>
                Voir le PDF (Actualiser)
            </a>
        </div>

        {# ACTIONS SIGNATURE #}
        <div class="space-y-4">
            <div class="p-6 bg-white rounded-[2rem] border border-slate-100 shadow-sm">
                <h3 class="text-xs font-black text-slate-400 uppercase tracking-widest mb-4">Signatures Requises</h3>

                <div class="space-y-3">
                    {% if providerSigned %}
                         <div class="w-full py-4 bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 rounded-2xl font-black uppercase text-sm tracking-widest flex items-center justify-center gap-3">
                            <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="M5 13l4 4L19 7" /></svg>
                            Signé (Prestataire)
                        </div>
                    {% else %}
                        <a href="{{ path('etl_sign_provider', {id: etatLieux.id}) }}" class="w-full py-4 bg-slate-900 text-white rounded-2xl font-black uppercase text-sm tracking-widest shadow-lg hover:bg-slate-800 transition-all flex items-center justify-center gap-3">
                            <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="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" /></svg>
                            Signer (Prestataire)
                        </a>
                    {% endif %}

                    {% if customerSigned %}
                         <div class="w-full py-4 bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 rounded-2xl font-black uppercase text-sm tracking-widest flex items-center justify-center gap-3">
                            <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="M5 13l4 4L19 7" /></svg>
                            Signé (Client)
                        </div>
                    {% else %}
                        <a href="{{ path('etl_sign_customer', {id: etatLieux.id}) }}" class="w-full py-4 bg-white border-2 border-slate-200 text-slate-900 rounded-2xl font-black uppercase text-sm tracking-widest hover:border-slate-900 hover:bg-slate-50 transition-all flex items-center justify-center gap-3">
                            <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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" /></svg>
                            Faire Signer (Client)
                        </a>
                        {# ... (sous le bouton "Faire Signer (Client)") ... #}

                        {% if etatLieux.status == "edl_return_done" %}
                            <div class="mt-4 p-4 bg-red-50 rounded-2xl border border-red-100">
                                <form action="{{ path('etl_edl_customer_refused', {id: mission.id}) }}" method="post" onsubmit="return confirm('Confirmer le refus de signature ?');">
                                    <label for="refusal_reason" class="block text-[10px] font-black text-red-400 uppercase tracking-widest mb-2 ml-1">
                                        Raison du refus (Optionnel)
                                    </label>

                                    <textarea
                                        name="refusal_reason"
                                        id="refusal_reason"
                                        rows="2"
                                        placeholder="Ex: Désaccord sur les dommages carrosserie..."
                                        class="w-full px-4 py-3 rounded-xl border-none text-sm text-slate-900 placeholder:text-slate-300 focus:ring-2 focus:ring-red-200 transition-all mb-3 shadow-inner"
                                    ></textarea>

                                    <button type="submit" class="w-full py-3 bg-red-600 text-white rounded-xl font-black uppercase text-[10px] tracking-widest hover:bg-red-700 transition-all flex items-center justify-center gap-2 shadow-lg shadow-red-600/20">
                                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
                                        </svg>
                                        Valider le refus de signer
                                    </button>
                                </form>
                            </div>
                        {% endif %}
                    {% endif %}
                </div>
            </div>

            {% if providerSigned and customerSigned %}
                <form action="{{ path('etl_edl_close', {id: mission.id}) }}" method="post">
                    <button type="submit" class="w-full py-4 bg-blue-600 hover:bg-blue-700 text-white rounded-2xl font-black uppercase text-sm tracking-widest shadow-lg shadow-blue-600/30 transition-all active:scale-95 flex items-center justify-center gap-3">
                        <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>
                        Clôturer l'état des lieux
                    </button>
                </form>
            {% endif %}

            {% if providerSigned and customerSigned and etatLieux.status == 'edl_validated' %}
                <form action="{{ path('etl_mission_edl_return_start', {id: mission.id}) }}" method="post">
                    <button type="submit" class="w-full py-4 bg-orange-600 hover:bg-orange-700 text-white rounded-2xl font-black uppercase text-sm tracking-widest shadow-lg shadow-orange-600/30 transition-all active:scale-95 flex items-center justify-center gap-3 mt-4">
                        <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 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" /></svg>
                        Faire état des lieux retour
                    </button>
                </form>
            {% endif %}
        </div>

        <div class="text-center">
            <a href="{{ path('etl_contrat_view', {id: mission.id}) }}" class="text-xs font-bold text-slate-400 hover:text-blue-600 transition-colors">Retour à la mission</a>
        </div>

    </div>
{% endblock %}
