<link rel="stylesheet" href="/public/assets/css/cda-security.css?v=7220">

<section class="security-page-head">
    <div>
        <a href="/public/administration/securite" class="security-back">← Sécurité & autorisations</a>
        <span class="security-kicker">Traçabilité</span>
        <h2>Journal des autorisations</h2>
        <p>Historique des changements de rôles et des dérogations individuelles.</p>
    </div>
</section>

<section class="security-audit-table">
    <?php if (!$entries): ?>
        <div class="security-empty">
            <span>☰</span>
            <strong>Aucune modification enregistrée</strong>
        </div>
    <?php else: ?>
        <table>
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Auteur</th>
                    <th>Cible</th>
                    <th>Action</th>
                    <th>Détails</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($entries as $entry): ?>
                <tr>
                    <td><?= htmlspecialchars(date('d/m/Y H:i', strtotime($entry['created_at']))) ?></td>
                    <td><?= htmlspecialchars(trim($entry['auteur']) ?: 'Système') ?></td>
                    <td>
                        <?= htmlspecialchars($entry['cible_type']) ?>
                        #<?= (int)$entry['cible_id'] ?>
                    </td>
                    <td><span class="security-audit-action"><?= htmlspecialchars($entry['action']) ?></span></td>
                    <td>
                        <details>
                            <summary>Voir la modification</summary>
                            <div class="security-json-grid">
                                <pre><?= htmlspecialchars($entry['valeur_avant'] ?: '{}') ?></pre>
                                <pre><?= htmlspecialchars($entry['valeur_apres'] ?: '{}') ?></pre>
                            </div>
                        </details>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    <?php endif; ?>
</section>
