<?php require dirname(__DIR__) . '/layouts/app.php'; ?>

<section class="page-heading">
    <div>
        <p class="eyebrow">Audit</p>
        <h1>Historique des actions</h1>
    </div>
</section>

<form class="filter-panel client-filter" method="get" action="<?= url('/activity-logs') ?>">
    <label>
        Module
        <select name="module">
            <option value="">Tous</option>
            <?php foreach ($modules as $item): ?>
                <option value="<?= e($item['module']) ?>" <?= $module === $item['module'] ? 'selected' : '' ?>>
                    <?= e($item['module']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </label>
    <button type="submit">Filtrer</button>
</form>

<section class="table-panel">
    <table>
        <thead>
            <tr>
                <th>Date</th>
                <th>Utilisateur</th>
                <th>Action</th>
                <th>Module</th>
                <th>Description</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($logs as $log): ?>
                <tr>
                    <td><?= e($log['created_at']) ?></td>
                    <td><?= e($log['user_name'] ?: 'Systeme') ?></td>
                    <td><?= e($log['action']) ?></td>
                    <td><?= e($log['module']) ?></td>
                    <td><?= e($log['description']) ?></td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($logs)): ?>
                <tr>
                    <td colspan="5">Aucune action enregistree.</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
</section>

<?php require dirname(__DIR__) . '/partials/pagination.php'; ?>

<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
