<?php
$labels=[
    ''=>'Toutes',
    'a_etudier'=>'À étudier',
    'file_attente'=>'File d’attente',
    'creneau_propose'=>'Proposition transmise',
    'validee'=>'Validées',
    'refusee'=>'Refusées',
    'abandonnee'=>'Abandonnées',
];
?>
<section class="page-header">
    <div>
        <span class="page-kicker">Inscriptions</span>
        <h2>Files d’attente</h2>
        <p>Demandes conservées même si l’année de l’adhérent n’est pas encore activée.</p>
    </div>
    <div style="display:flex;gap:8px;flex-wrap:wrap"><a class="button button-primary" href="/public/demandes-inscription/assistant-ia">Assistant IA</a>    <a class="button button-secondary" href="/public/dashboard">Retour au tableau de bord</a></div>
</section>

<nav style="display:flex;gap:8px;flex-wrap:wrap;margin:16px 0">
    <?php foreach($labels as $value=>$label): ?>
    <a class="button <?= $selectedStatus===$value?'button-primary':'button-secondary' ?>"
       href="/public/demandes-inscription<?= $value!==''?'?statut='.rawurlencode($value):'' ?>">
        <?= htmlspecialchars($label) ?>
    </a>
    <?php endforeach; ?>
</nav>

<section class="card">
    <?php if(empty($requests)): ?>
    <p>Aucune demande dans ce filtre.</p>
    <?php else: ?>
    <div style="overflow-x:auto">
        <table class="table">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Participant</th>
                    <th>Adhérent titulaire</th>
                    <th>Activité demandée</th>
                    <th>Statut</th>
                    <?php if(\App\Core\Permission::canViewFullProfessorRh()): ?><th>Action</th><?php endif; ?>
                </tr>
            </thead>
            <tbody>
            <?php foreach($requests as $request): ?>
                <tr>
                    <td><?= date('d/m/Y',strtotime((string)$request['created_at'])) ?></td>
                    <td><strong><?= htmlspecialchars(trim((string)$request['membre_prenom'].' '.(string)$request['membre_nom'])) ?></strong></td>
                    <td><?= htmlspecialchars(trim((string)$request['adherent_prenom'].' '.(string)$request['adherent_nom'])) ?></td>
                    <td><?= htmlspecialchars((string)$request['atelier_libelle']) ?></td>
                    <td><?= htmlspecialchars($labels[(string)$request['statut']] ?? ucfirst(str_replace('_',' ',(string)$request['statut']))) ?></td>
                    <?php if(\App\Core\Permission::canViewFullProfessorRh()): ?><td>
                        <a href="/public/adherents/fiche?ref=<?= rawurlencode((string)$request['code_client']) ?>#demandes-inscription">
                            Ouvrir
                        </a>
                    </td><?php endif; ?>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
</section>
