<?php
require_once __DIR__ . '/config/auth.php';
require_login();

$pageTitle = 'Activity Logs';
$activePage = 'logs';

$logs = db_all(
    $conn,
    'SELECT username, action, details, created_at
     FROM activity_logs
     ORDER BY created_at DESC
     LIMIT 150'
);

include __DIR__ . '/includes/header.php';
?>

<section class="content-panel">
    <div class="panel-heading">
        <div>
            <h2>Logs</h2>
            <p>Recent account and pass management activity.</p>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-hover align-middle">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>User</th>
                    <th>Action</th>
                    <th>Details</th>
                </tr>
            </thead>
            <tbody>
                <?php if (!$logs) : ?>
                    <tr>
                        <td class="empty-row" colspan="4">No activity logs found.</td>
                    </tr>
                <?php endif; ?>
                <?php foreach ($logs as $log) : ?>
                    <tr>
                        <td><?php echo htmlspecialchars($log['created_at']); ?></td>
                        <td><?php echo htmlspecialchars($log['username'] ?? 'System'); ?></td>
                        <td><?php echo htmlspecialchars($log['action']); ?></td>
                        <td><?php echo htmlspecialchars($log['details'] ?? ''); ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>
