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

{% block title %}Verification Entreprise / Association - {{ siret }}{% endblock %}

{% block body %}
<div class="mb-8">
    <h1 class="text-3xl font-black uppercase tracking-tighter italic heading-page">Verification Entreprise / Association</h1>
    <p class="font-bold text-gray-500 italic">{{ user.firstName }} {{ user.lastName }} — {{ siret }}</p>
</div>

<div class="flex flex-wrap gap-6">
    <div class="flex-1 min-w-[300px]">
        <div class="admin-card">
            <h2 class="text-sm font-black uppercase tracking-widest mb-4">Informations declarees</h2>
            <table class="admin-detail-table">
                <thead>
                    <tr>
                        <th class="text-[10px] font-black uppercase tracking-widest text-gray-400">Champ</th>
                        <th class="text-[10px] font-black uppercase tracking-widest text-gray-400">Valeur</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Nom</td>
                        <td class="text-sm">{{ user.firstName }} {{ user.lastName }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Raison sociale</td>
                        <td class="text-sm">{{ user.companyName }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">SIRET</td>
                        <td class="text-sm font-mono">{{ user.siret }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Adresse</td>
                        <td class="text-sm">{{ user.address }}, {{ user.postalCode }} {{ user.city }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Telephone</td>
                        <td class="text-sm">{{ user.phone }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <div class="flex-1 min-w-[300px]">
        <div class="admin-card">
            <h2 class="text-sm font-black uppercase tracking-widest mb-4">Donnees API Gouvernement</h2>

            {% if data %}
            <div class="mb-4 flex gap-2 flex-wrap">
                {% if data.complements is defined and data.complements.est_association is defined and data.complements.est_association %}
                    <span class="admin-badge-blue text-xs font-black uppercase">Association</span>
                {% elseif data.complements is defined and data.complements.est_entrepreneur_individuel is defined and data.complements.est_entrepreneur_individuel %}
                    <span class="admin-badge-yellow text-xs font-black uppercase">Entrepreneur individuel</span>
                {% else %}
                    <span class="admin-badge-indigo-lg text-xs font-black uppercase">Entreprise</span>
                {% endif %}
                {% if data.complements is defined and data.complements.est_ess is defined and data.complements.est_ess %}
                    <span class="admin-badge-green text-xs font-black uppercase">ESS</span>
                {% endif %}
            </div>
            <table class="admin-detail-table">
                <thead>
                    <tr>
                        <th class="text-[10px] font-black uppercase tracking-widest text-gray-400">Champ</th>
                        <th class="text-[10px] font-black uppercase tracking-widest text-gray-400">Valeur</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Denomination</td>
                        <td class="text-sm">{{ data.nom_complet ?? '—' }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">SIREN</td>
                        <td class="text-sm font-mono">{{ data.siren ?? '—' }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Nature juridique</td>
                        <td class="text-sm">
                            {% if data.nature_juridique is defined and data.nature_juridique %}
                                <span class="font-mono">{{ data.nature_juridique }}</span> — {{ data.libelle_nature_juridique ?? '' }}
                            {% else %}
                                —
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Siege</td>
                        <td class="text-sm">
                            {% if data.siege is defined and data.siege %}
                                {{ data.siege.adresse ?? '' }}, {{ data.siege.code_postal ?? '' }} {{ data.siege.libelle_commune ?? '' }}
                            {% else %}
                                —
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Activite (NAF)</td>
                        <td class="text-sm">
                            {% if data.activite_principale is defined and data.activite_principale %}
                                <span class="font-mono">{{ data.activite_principale }}</span> — {{ data.libelle_activite_principale ?? '' }}
                            {% else %}
                                —
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Tranche effectif</td>
                        <td class="text-sm">
                            {% set te = data.tranche_effectif_salarie ?? 'NN' %}
                            {% set te_labels = {
                                'NN': 'Non renseigne',
                                '00': '0 salarie',
                                '01': '1 ou 2 salaries',
                                '02': '3 a 5 salaries',
                                '03': '6 a 9 salaries',
                                '11': '10 a 19 salaries',
                                '12': '20 a 49 salaries',
                                '21': '50 a 99 salaries',
                                '22': '100 a 199 salaries',
                                '31': '200 a 249 salaries',
                                '32': '250 a 499 salaries',
                                '41': '500 a 999 salaries',
                                '42': '1 000 a 1 999 salaries',
                                '51': '2 000 a 4 999 salaries',
                                '52': '5 000 a 9 999 salaries',
                                '53': '10 000 salaries et plus'
                            } %}
                            {{ te_labels[te] ?? te }}
                        </td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Date creation</td>
                        <td class="text-sm">{{ data.date_creation ?? '—' }}</td>
                    </tr>
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Statut</td>
                        <td>
                            {% if data.etat_administratif is defined and data.etat_administratif == 'A' %}
                                <span class="admin-badge-green text-xs font-black uppercase">Active</span>
                            {% else %}
                                <span class="admin-badge-red text-xs font-black uppercase">Fermee</span>
                            {% endif %}
                        </td>
                    </tr>
                    {% if data.complements is defined and data.complements.est_association is defined and data.complements.est_association %}
                    <tr>
                        <td class="font-bold text-sm text-gray-400">RNA</td>
                        <td class="text-sm font-mono">{{ data.complements.identifiant_association ?? '—' }}</td>
                    </tr>
                    {% endif %}
                    <tr>
                        <td class="font-bold text-sm text-gray-400">Coordonnees</td>
                        <td class="text-sm">
                            {% if data.siege is defined and data.siege.latitude is defined and data.siege.longitude is defined and data.siege.latitude and data.siege.longitude %}
                                <span class="font-mono">{{ data.siege.latitude }}, {{ data.siege.longitude }}</span>
                            {% else %}
                                —
                            {% endif %}
                        </td>
                    </tr>
                </tbody>
            </table>
            {% else %}
            <div class="py-8 text-center">
                <span class="admin-badge-red text-xs font-black uppercase">SIRET non trouve</span>
                <p class="text-gray-400 text-sm font-bold mt-2">Aucun resultat retourne par l'API pour ce SIRET.</p>
            </div>
            {% endif %}
        </div>
    </div>
</div>

{% if rnaData %}
<div class="mt-6">
    <div class="admin-card">
        <h2 class="text-sm font-black uppercase tracking-widest mb-4">Journal Officiel (JOAFE)</h2>
        <table class="admin-detail-table">
            <thead>
                <tr>
                    <th class="text-[10px] font-black uppercase tracking-widest text-gray-400 w-[180px]">Champ</th>
                    <th class="text-[10px] font-black uppercase tracking-widest text-gray-400">Valeur</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td class="font-bold text-sm text-gray-400 w-[180px]">RNA</td>
                    <td class="text-sm font-mono">{{ rnaData.numero_rna ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400">Regime</td>
                    <td class="text-sm">{{ rnaData.association_type_libelle ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400 align-top">Objet</td>
                    <td class="text-sm">{{ rnaData.objet ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400">Domaine d'activite</td>
                    <td class="text-sm">{{ rnaData.domaine_activite_libelle_categorise ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400">Date declaration</td>
                    <td class="text-sm">{{ rnaData.datedeclaration ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400">Date parution JOAFE</td>
                    <td class="text-sm">{{ rnaData.dateparution ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400">Lieu declaration</td>
                    <td class="text-sm">{{ rnaData.lieupref ?? '—' }}</td>
                </tr>
                <tr>
                    <td class="font-bold text-sm text-gray-400">PDF JOAFE</td>
                    <td>
                        {% if rnaData.url_pdf is defined and rnaData.url_pdf %}
                            <a href="{{ rnaData.url_pdf }}" target="_blank" class="admin-download text-xs font-black uppercase hover:bg-indigo-600 hover:text-black transition-all">Telecharger</a>
                        {% else %}
                            —
                        {% endif %}
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
{% endif %}

<div class="mt-8 flex gap-3 flex-wrap">
    <form method="post" action="{{ path('app_admin_siret_refresh', {id: user.id}) }}" class="inline">
        <button type="submit" class="admin-btn-outline font-black uppercase text-xs tracking-widest hover:bg-indigo-600 hover:text-black transition-all">Rafraichir SIRET</button>
    </form>
    <a href="{{ path('app_admin_organizers') }}" class="admin-btn-outline inline-block font-black uppercase text-xs tracking-widest hover:bg-gray-100 transition-all">Retour</a>
</div>

<div class="flex flex-wrap gap-6 mt-8">
    <div class="flex-1 min-w-[300px]">
        <div class="admin-card">
            <h2 class="text-sm font-black uppercase tracking-widest mb-4 text-green-600">Approuver l'organisateur</h2>
            <form method="post" action="{{ path('app_admin_approve_organizer', {id: user.id}) }}" class="flex flex-col gap-4">
                <div>
                    <label for="approve_offer" class="admin-form-label-lg font-black uppercase text-gray-400">Offre</label>
                    <select id="approve_offer" name="offer" class="admin-form-select">
                        <option value="free">Gratuit</option>
                        <option value="basic">Basique</option>
                        <option value="custom">Sur-mesure</option>
                    </select>
                </div>
                <div>
                    <label for="approve_commission" class="admin-form-label-lg font-black uppercase text-gray-400">Taux de commission (%)</label>
                    <input type="number" id="approve_commission" name="commission_rate" value="3" step="0.1" min="0" max="100"
                        class="admin-form-input-lg">
                </div>
                <button type="submit" class="admin-btn font-black uppercase text-xs tracking-widest hover:bg-green-500 hover:text-black transition-all">Approuver l'organisateur</button>
            </form>
        </div>
    </div>

    <div class="flex-1 min-w-[300px]">
        <div class="admin-card-reject">
            <h2 class="text-sm font-black uppercase tracking-widest mb-4 text-red-800">Refuser la demande</h2>
            <form method="post" action="{{ path('app_admin_reject_organizer', {id: user.id}) }}" data-confirm="Etes-vous sur de vouloir refuser et supprimer le compte de {{ user.firstName }} {{ user.lastName }} ? Cette action est irreversible." class="flex flex-col gap-4">
                <div>
                    <label for="reject_reason" class="admin-form-label-lg font-black uppercase text-gray-400">Motif du refus</label>
                    <textarea id="reject_reason" name="reason" required rows="4"
                        class="admin-form-textarea"
                        placeholder="Expliquez la raison du refus..."></textarea>
                </div>
                <button type="submit" class="admin-btn-danger font-black uppercase text-xs tracking-widest hover:bg-red-800 transition-all">Refuser et supprimer le compte</button>
            </form>
        </div>
    </div>
</div>
{% endblock %}
