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

{% block title %}Inviter un organisateur{% endblock %}

{% block body %}
<div class="flex flex-wrap items-center justify-between gap-4 mb-8">
    <div>
        <h1 class="text-3xl font-black uppercase tracking-tighter italic heading-page">Inviter un organisateur</h1>
        <p class="font-bold text-gray-500 italic">Envoyer une invitation par email.</p>
    </div>
    <a href="{{ path('app_admin_organizers') }}" class="admin-btn-sm-white inline-block text-xs font-black uppercase tracking-widest hover:bg-indigo-600 hover:text-black transition-all">Retour aux organisateurs</a>
</div>

<div class="admin-card mb-8">
    <h2 class="text-sm font-black uppercase tracking-widest mb-6">Nouvelle invitation</h2>
    <form method="post" action="{{ path('app_admin_invite_organizer') }}">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
            <div>
                <label for="inv_company" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Raison sociale</label>
                <input type="text" id="inv_company" name="company_name" required class="admin-form-input" placeholder="Association / Entreprise">
            </div>
            <div>
                <label for="inv_email" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Email</label>
                <input type="email" id="inv_email" name="email" required class="admin-form-input" placeholder="contact@association.fr">
            </div>
            <div>
                <label for="inv_last_name" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Nom</label>
                <input type="text" id="inv_last_name" name="last_name" required class="admin-form-input" placeholder="Dupont">
            </div>
            <div>
                <label for="inv_first_name" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Prenom</label>
                <input type="text" id="inv_first_name" name="first_name" required class="admin-form-input" placeholder="Jean">
            </div>
        </div>
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
            <div>
                <label for="inv_offer" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Offre</label>
                <select id="inv_offer" name="offer" class="admin-form-input">
                    <option value="free">Gratuit</option>
                    <option value="basic">Basic</option>
                    <option value="custom">Sur-mesure</option>
                </select>
            </div>
            <div>
                <label for="inv_commission" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Taux de commission E-Ticket (%)</label>
                <input type="number" id="inv_commission" name="commission_rate" step="0.1" min="0" max="100" value="3" class="admin-form-input" placeholder="3">
            </div>
        </div>
        <div class="mb-4">
            <label for="inv_message" class="block text-[10px] font-black uppercase tracking-widest text-gray-500 mb-1">Message personnalise (optionnel)</label>
            <textarea id="inv_message" name="message" rows="3" class="admin-form-input" placeholder="Bonjour, nous vous invitons a rejoindre E-Ticket..."></textarea>
        </div>
        <button type="submit" class="admin-btn-search font-black uppercase text-xs tracking-widest hover:bg-indigo-600 hover:text-black transition-all">Envoyer l'invitation</button>
    </form>
</div>

<div class="admin-card !p-0">
    <table class="admin-table">
        <thead>
            <tr>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Organisateur</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Raison sociale</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Email</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Offre</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white">Date</th>
                <th class="text-[10px] font-black uppercase tracking-widest text-white text-right">Statut</th>
            </tr>
        </thead>
        <tbody>
            {% for inv in invitations %}
            <tr class="hover:bg-gray-50 transition-all">
                <td>
                    <p class="font-bold text-sm">{{ inv.firstName }} {{ inv.lastName }}</p>
                </td>
                <td class="text-sm text-gray-600">{{ inv.companyName }}</td>
                <td class="text-sm text-gray-600">{{ inv.email }}</td>
                <td class="text-sm text-gray-600">
                    {% if inv.offer %}<span class="admin-badge-indigo text-xs font-black uppercase">{{ inv.offer }}</span>{% endif %}
                    {% if inv.commissionRate is not null %}<span class="text-xs text-gray-400 ml-1">{{ inv.commissionRate }}%</span>{% endif %}
                </td>
                <td class="text-sm text-gray-400">{{ inv.createdAt|date('d/m/Y H:i') }}</td>
                <td class="text-right">
                    {% if inv.status == 'sent' %}
                        <span class="admin-badge-yellow text-xs font-black uppercase">Envoyee</span>
                    {% elseif inv.status == 'opened' %}
                        <span class="admin-badge-yellow text-xs font-black uppercase">Ouverte</span>
                    {% elseif inv.status == 'accepted' %}
                        <span class="admin-badge-green text-xs font-black uppercase">Acceptee</span>
                    {% elseif inv.status == 'refused' %}
                        <span class="admin-badge-red text-xs font-black uppercase">Refusee</span>
                    {% endif %}
                    {% if inv.respondedAt %}
                        <span class="text-[10px] text-gray-400 ml-2">{{ inv.respondedAt|date('d/m/Y') }}</span>
                    {% endif %}
                    {% if inv.status != 'accepted' %}
                        <form method="post" action="{{ path('app_admin_resend_invitation', {id: inv.id}) }}" class="inline ml-2">
                            <button type="submit" class="admin-btn-sm-white inline-block text-xs font-black uppercase tracking-widest hover:bg-indigo-600 hover:text-black transition-all">Renvoyer</button>
                        </form>
                    {% endif %}
                    <form method="post" action="{{ path('app_admin_delete_invitation', {id: inv.id}) }}" data-confirm="Supprimer cette invitation ?" class="inline ml-1">
                        <button type="submit" class="admin-btn-sm-white inline-block text-xs font-black uppercase tracking-widest hover:bg-red-600 hover:text-white transition-all">&#10005;</button>
                    </form>
                </td>
            </tr>
            {% else %}
            <tr>
                <td colspan="6" class="!text-center !py-12 text-gray-400 font-bold text-sm">Aucune invitation envoyee.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}
