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

<?= $this->section('content') ?>
<div class="row g-3 mb-4">
    <?php foreach ($stats as $label => $value): ?>
        <div class="col-md-3">
            <div class="core-card stat-card p-3">
                <div class="text-muted small text-uppercase"><?= esc(str_replace('_', ' ', $label)) ?></div>
                <div class="h3 mb-0"><?= esc((string) $value) ?></div>
            </div>
        </div>
    <?php endforeach; ?>
</div>

<div class="core-card p-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h2 class="h5 mb-0">Dernières actions</h2>
        <a class="btn btn-outline-primary btn-sm" href="<?= site_url('/audit') ?>">Voir l’audit</a>
    </div>
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
            <tr>
                <th>Action</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['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="4" class="text-muted">Aucune action enregistrée.</td></tr>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?= $this->endSection() ?>
