<?php
/**
 * Admin Activity Logs
 */
require_once 'includes/header.php';

$logs = dbFetchAll("SELECT al.*, u.email FROM activity_logs al LEFT JOIN users u ON al.user_id = u.id ORDER BY al.created_at DESC LIMIT 200");
?>

<div class="page-header">
    <h1 class="page-title">Activity Logs</h1>
</div>

<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive" style="max-height: 600px; overflow-y: auto;">
            <table class="table">
                <thead>
                    <tr>
                        <th>Time</th>
                        <th>User</th>
                        <th>Type</th>
                        <th>Action</th>
                        <th>Details</th>
                        <th>IP</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (empty($logs)): ?>
                    <tr><td colspan="6" class="text-center py-4">No activity logs found</td></tr>
                    <?php else: ?>
                    <?php foreach ($logs as $log): ?>
                    <tr>
                        <td class="font-mono text-sm"><?= date('d M H:i:s', strtotime($log['created_at'])) ?></td>
                        <td><?= htmlspecialchars($log['email'] ?? 'System') ?></td>
                        <td><span class="badge badge-secondary"><?= ucfirst($log['user_type'] ?? 'user') ?></span></td>
                        <td><span class="badge badge-primary"><?= $log['action'] ?></span></td>
                        <td class="text-sm"><?= htmlspecialchars($log['details'] ?? '') ?></td>
                        <td class="font-mono text-sm"><?= $log['ip_address'] ?? '-' ?></td>
                    </tr>
                    <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php require_once 'includes/footer.php'; ?>
