<?= $this->extend('layouts/app') ?>

<?= $this->section('content') ?>
<div class="core-card p-4">
    <h2 class="h5 mb-3">Journal d’audit</h2>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
            <tr>
                <th>Action</th>
                <th>Utilisateur</th>
                <th>Entité</th>
                <th>Description</th>
                <th>Date</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($logs as $log): ?>
                <tr>
                    <td><code><?= esc($log['action']) ?></code></td>
                    <td><?= esc($log['user_label'] ?? (string) ($log['user_id'] ?? '-')) ?></td>
                    <td><?= esc($log['entity_label'] ?? trim(($log['entity_type'] ?? '') . ' #' . ($log['entity_id'] ?? ''), ' #')) ?></td>
                    <td><?= esc($log['description'] ?? '') ?></td>
                    <td><?= esc($log['created_at']) ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if ($logs === []): ?>
                <tr><td colspan="5" class="text-muted">Aucune action enregistrée.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?= $this->endSection() ?>
