<?php
$pageTitle = 'Audit Log';
$breadcrumb = [['label' => 'Settings', 'url' => APP_URL . '/settings'], ['label' => 'Audit Log', 'url' => null]];
ob_start();
?>
<div class="page-header">
    <div>
        <h1 class="page-title">Audit Log</h1>
        <p class="page-subtitle">A record of actions taken across the platform</p>
    </div>
</div>

<div class="tabs">
    <a href="<?= APP_URL ?>/settings" class="tab-item">General</a>
    <a href="<?= APP_URL ?>/settings/security" class="tab-item">Security</a>
    <a href="<?= APP_URL ?>/settings/billing" class="tab-item">Billing</a>
    <?php if (\Core\Auth::isSuperAdmin()): ?>
    <a href="<?= APP_URL ?>/settings/email" class="tab-item">Email/SMTP</a>
    <a href="<?= APP_URL ?>/admin/system" class="tab-item">System</a>
    <a href="<?= APP_URL ?>/settings/audit" class="tab-item active">Audit Log</a>
    <?php endif; ?>
</div>

<div class="card">
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>User</th>
                    <th>Action</th>
                    <th>Module</th>
                    <th>Entity</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($logs)): ?>
                <tr><td colspan="5" class="text-center" style="padding:32px;color:var(--text-muted);">No activity recorded yet.</td></tr>
                <?php else: ?>
                    <?php foreach ($logs as $log): ?>
                    <tr>
                        <td><?= htmlspecialchars($log['created_at']) ?></td>
                        <td><?= htmlspecialchars($log['user_name'] ?? 'System') ?></td>
                        <td><?= htmlspecialchars(ucwords(str_replace('_', ' ', $log['action']))) ?></td>
                        <td><?= htmlspecialchars($log['module']) ?></td>
                        <td><?= htmlspecialchars(($log['entity_type'] ?? '') . ($log['entity_id'] ? ' #' . $log['entity_id'] : '')) ?></td>
                    </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
    <div style="padding:16px 20px;">
        <?php @include ROOT_PATH . '/modules/shared/views/partials/pagination.php'; ?>
    </div>
</div>
<?php
$content = ob_get_clean();
require ROOT_PATH . '/modules/shared/views/layouts/main.php';
?>
