{% extends 'admin/_layout.html.twig' %}

{% block title %}Revendeurs - Administration - Association E-Cosplay{% endblock %}

{% block admin_content %}
<div class="page-container">
    <div class="flex items-center justify-between mb-8">
        <h1 class="text-2xl font-bold heading-page">Revendeurs</h1>
        <a href="{{ path('app_admin_revendeurs_create') }}" class="px-4 py-2 btn-gold font-bold uppercase text-xs tracking-wider">+ Nouveau revendeur</a>
    </div>

    {% for type, messages in app.flashes %}
        {% for message in messages %}
            <div class="mb-6 p-4 glass font-medium text-sm {{ type == 'success' ? 'border-green-300 text-green-800' : 'border-red-300 text-red-800' }}">
                {{ message }}
            </div>
        {% endfor %}
    {% endfor %}

    {# Recherche #}
    <div class="mb-6 relative">
        <input type="text" id="search-revendeurs" placeholder="Rechercher un revendeur (nom, email, code, SIRET...)"
               class="w-full px-4 py-3 pl-10 input-glass text-sm font-medium">
        <svg class="w-4 h-4 absolute left-3 top-4 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="search-results-revendeurs" class="hidden glass border-t-0 bg-white max-h-64 overflow-y-auto absolute w-full z-10"></div>
    </div>

    {# Liste #}
    <div class="glass overflow-x-auto overflow-hidden">
        <table class="w-full text-sm">
            <thead>
                <tr class="glass-dark text-white">
                    <th class="px-4 py-3 text-left font-bold uppercase text-xs tracking-widest">Code</th>
                    <th class="px-4 py-3 text-left font-bold uppercase text-xs tracking-widest">Nom</th>
                    <th class="px-4 py-3 text-left font-bold uppercase text-xs tracking-widest">Raison sociale</th>
                    <th class="px-4 py-3 text-left font-bold uppercase text-xs tracking-widest">Email</th>
                    <th class="px-4 py-3 text-center font-bold uppercase text-xs tracking-widest">SIRET</th>
                    <th class="px-4 py-3 text-center font-bold uppercase text-xs tracking-widest">Stripe</th>
                    <th class="px-4 py-3 text-center font-bold uppercase text-xs tracking-widest">Statut</th>
                    <th class="px-4 py-3 text-left font-bold uppercase text-xs tracking-widest">Inscription</th>
                    <th class="px-4 py-3 text-center font-bold uppercase text-xs tracking-widest">Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for revendeur in revendeurs %}
                    <tr class="border-b border-white/20 hover:bg-white/50">
                        <td class="px-4 py-3">
                            <span class="px-2 py-1 bg-gray-900 text-[#fabf04] font-bold text-[10px] tracking-widest">{{ revendeur.codeRevendeur }}</span>
                        </td>
                        <td class="px-4 py-3 font-bold">{{ revendeur.user.fullName }}</td>
                        <td class="px-4 py-3 text-xs">{{ revendeur.raisonSociale ?? '—' }}</td>
                        <td class="px-4 py-3 text-xs font-mono">{{ revendeur.email ?? revendeur.user.email }}</td>
                        <td class="px-4 py-3 text-center text-xs font-mono">{{ revendeur.siret ?? '—' }}</td>
                        <td class="px-4 py-3 text-center">
                            {% if revendeur.isUseStripe %}
                                {% if revendeur.stripeConnectId %}
                                    <span class="px-2 py-0.5 bg-green-500/20 text-green-700 font-bold uppercase text-[10px]">Connecte</span>
                                {% else %}
                                    <span class="px-2 py-0.5 bg-yellow-100 text-yellow-800 font-bold uppercase text-[10px]">En attente</span>
                                {% endif %}
                            {% else %}
                                <span class="px-2 py-0.5 bg-gray-100 text-gray-500 font-bold uppercase text-[10px]">Desactive</span>
                            {% endif %}
                        </td>
                        <td class="px-4 py-3 text-center">
                            {% if revendeur.isActive %}
                                <span class="px-2 py-0.5 bg-green-500/20 text-green-700 font-bold uppercase text-[10px]">Actif</span>
                            {% else %}
                                <span class="px-2 py-0.5 bg-red-500/20 text-red-700 font-bold uppercase text-[10px]">Inactif</span>
                            {% endif %}
                        </td>
                        <td class="px-4 py-3 text-xs text-gray-500">{{ revendeur.createdAt|date('d/m/Y') }}</td>
                        <td class="px-4 py-3 text-center">
                            <div class="flex items-center justify-center gap-2">
                                <a href="{{ path('app_admin_revendeurs_edit', {id: revendeur.id}) }}" class="px-2 py-1 glass text-gray-900 font-bold uppercase text-[10px] tracking-widest hover:bg-gray-900 hover:text-white transition-all">Modifier</a>
                                <a href="{{ path('app_admin_revendeurs_contrat', {id: revendeur.id}) }}" target="_blank" class="px-2 py-1 btn-glass text-indigo-600 font-bold uppercase text-[10px] tracking-wider">Contrat</a>
                                <form method="post" action="{{ path('app_admin_revendeurs_toggle', {id: revendeur.id}) }}">
                                    {% if revendeur.isActive %}
                                        <button type="submit" class="px-2 py-1 btn-glass text-red-600 font-bold uppercase text-[10px] tracking-wider">Desactiver</button>
                                    {% else %}
                                        <button type="submit" class="px-2 py-1 border-2 border-green-600 bg-white text-green-600 font-bold uppercase text-[10px] tracking-widest hover:bg-green-600 hover:text-white transition-all">Activer</button>
                                    {% endif %}
                                </form>
                            </div>
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="9" class="px-4 py-8 text-center text-gray-400 font-bold">Aucun revendeur.</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    <p class="mt-3 text-xs text-gray-400">{{ revendeurs|length }} revendeur(s)</p>
</div>
{% endblock %}
