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

{% block title %}Prestataires{% endblock %}

{% block actions %}
    <a data-turbo="false"  href="{{ path('app_crm_prestataire_add') }}"
       class="inline-flex items-center px-4 py-2 text-sm font-black uppercase tracking-widest text-white bg-indigo-600 rounded-xl hover:bg-indigo-700 shadow-lg shadow-indigo-500/20 transition-all active:scale-95">
        <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
        </svg>
        Ajouter un Prestataire
    </a>
{% endblock %}

{% block body %}
    <div class="p-4 md:p-6 bg-gray-50 dark:bg-gray-900 min-h-screen w-full">
        <div class="w-full">
            {# HEADER #}
            <div class="flex justify-between items-center mb-8">
                <div>
                    <h1 class="text-3xl font-black text-gray-800 dark:text-white tracking-tight">Liste des Prestataires</h1>
                    <p class="text-sm text-gray-500 dark:text-gray-200 font-medium mt-1">Gestion des prestataires externes.</p>
                </div>
                <div class="flex items-center space-x-3">
                    <span class="px-4 py-2 text-xs font-black text-indigo-600 bg-indigo-100 rounded-full dark:bg-indigo-900/40 dark:text-indigo-300 uppercase tracking-widest shadow-sm border border-indigo-200 dark:border-indigo-800">
                        {{ prestataires|length }} Prestataires
                    </span>
                </div>
            </div>

            {# TABLE CARD #}
            <div class="bg-white dark:bg-[#1e293b] shadow-sm rounded-3xl border border-gray-200 dark:border-gray-800 overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="w-full text-sm text-left text-gray-500 dark:text-gray-200">
                        <thead class="text-[10px] text-gray-200 uppercase bg-gray-50/50 dark:bg-gray-900/50 dark:text-gray-500 border-b border-gray-100 dark:border-gray-800">
                        <tr>
                            <th scope="col" class="px-8 py-5 font-black tracking-widest">Identité</th>
                            <th scope="col" class="px-8 py-5 font-black tracking-widest">Téléphone</th>
                            <th scope="col" class="px-8 py-5 font-black tracking-widest text-right">Actions</th>
                        </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-100 dark:divide-gray-800">
                        {% for prestataire in prestataires %}
                            <tr class="bg-white dark:bg-[#1e293b] hover:bg-gray-50 dark:hover:bg-gray-800/50 transition-colors group">
                                {# COLONNE 1 : IDENTITÉ #}
                                <td class="px-8 py-5">
                                    <div class="flex items-center space-x-4">
                                        <div class="h-11 w-11 rounded-2xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center text-slate-300 dark:text-slate-400 font-black text-xs border border-slate-200 dark:border-slate-700 shadow-sm transition-transform group-hover:scale-110">
                                            {{ prestataire.surname|first|upper }}{{ prestataire.name|first|upper }}
                                        </div>
                                        <div class="flex flex-col">
                                            <span class="font-bold text-slate-900 dark:text-white text-base">{{ prestataire.surname }} {{ prestataire.name }}</span>
                                            <span class="text-xs text-slate-400 font-medium tracking-tight font-mono">{{ prestataire.email }}</span>
                                        </div>
                                    </div>
                                </td>

                                {# COLONNE 2 : TELEPHONE #}
                                <td class="px-8 py-5">
                                    <span class="text-slate-500 dark:text-slate-300">{{ prestataire.phone|default('N/A') }}</span>
                                </td>

                                {# COLONNE 3 : ACTIONS #}
                                <td class="px-8 py-5 text-right whitespace-nowrap">
                                    <div class="flex items-center justify-end space-x-3">
                                        {# Bouton Gérer #}
                                        <a data-turbo="false"  href="{{ path('app_crm_prestataire_view', {id: prestataire.id}) }}"
                                           class="flex items-center space-x-2 px-3 py-2 bg-slate-50 dark:bg-slate-800 text-slate-600 dark:text-slate-300 hover:bg-indigo-600 hover:text-white dark:hover:bg-indigo-600 dark:hover:text-white rounded-xl transition-all border border-slate-200 dark:border-slate-700 font-bold text-xs shadow-sm"
                                           title="Gérer le prestataire">
                                            <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="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
                                            <span>Gérer</span>
                                        </a>

                                        {# Bouton Supprimer #}
                                        <a data-turbo="false"  href="{{ path('app_crm_prestataire_delete', {id: prestataire.id}) }}?_token={{ csrf_token('delete' ~ prestataire.id) }}"
                                           data-turbo-method="post"
                                           data-turbo-confirm="Confirmer la suppression définitive du prestataire {{ prestataire.surname }} {{ prestataire.name }} ?"
                                           class="p-2.5 text-slate-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-500/10 rounded-xl transition-all border border-transparent hover:border-red-100 dark:hover:border-red-500/20"
                                           title="Supprimer">
                                            <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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        {% else %}
                            <tr>
                                <td colspan="3" class="px-8 py-24 text-center">
                                    <div class="flex flex-col items-center">
                                        <div class="w-20 h-20 bg-slate-50 dark:bg-slate-900/50 rounded-3xl flex items-center justify-center text-slate-200 dark:text-slate-800 mb-6">
                                            <svg class="w-10 h-10" 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 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg>
                                        </div>
                                        <p class="text-slate-400 font-bold text-lg">Aucun Prestataire enregistré</p>
                                        <p class="text-slate-400/60 text-sm mt-1">Commencez par en ajouter un via le bouton en haut à droite.</p>
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
