<?php
require_once __DIR__ . '/../includes/auth.php';
requireLogin();
requirePermission('users.manage');

require_once __DIR__ . '/../config/database.php';

$userId = (int)$_GET['id'];

$auditLogs = $pdo->prepare("
    SELECT * FROM audit_logs
    WHERE user_id = ?
    ORDER BY created_at DESC
    LIMIT 50
");
$auditLogs->execute([$userId]);
$logs = $auditLogs->fetchAll(PDO::FETCH_ASSOC);
?>

<?php require_once '../includes/header.php'; ?>
<?php require_once '../includes/sidebar.php'; ?>

<div class="main-content">

<div class="page-header">
    <h2>User Activity</h2>
    <p class="page-subtitle">Recent actions performed by this user.</p>
</div>

<div class="table-wrap">
<table>
<thead>
<tr>
<th>Action</th>
<th>Date</th>
</tr>
</thead>
<tbody>

<?php foreach ($logs as $log): ?>
<tr>
<td><?= htmlspecialchars($log['action']) ?></td>
<td><?= htmlspecialchars($log['created_at']) ?></td>
</tr>
<?php endforeach; ?>

</tbody>
</table>
</div>

</div>

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