<?php
require_once __DIR__ . '/../admin/_nav.php';
$pageTitle  = 'Activity Logs';
$sidebarNav = adminNav();
$u = fn($p) => \Core\View::url($p);
?>
<div class="page-header"><div><h1>Activity Logs</h1></div></div>
<div class="card">
  <div class="table-wrap">
    <table>
      <thead><tr><th>User</th><th>Action</th><th>Model</th><th>IP</th><th>Time</th></tr></thead>
      <tbody>
        <?php foreach($logs['data'] as $log): ?>
        <tr>
          <td><?= htmlspecialchars($log['user_name'] ?? 'System') ?></td>
          <td><span class="badge badge-info"><?= htmlspecialchars(ucfirst($log['action'])) ?></span></td>
          <td><?= htmlspecialchars($log['model'] ?? '-') ?> <?= $log['model_id'] ? '#'.$log['model_id'] : '' ?></td>
          <td style="font-size:12px;color:var(--gray)"><?= htmlspecialchars($log['ip_address'] ?? '') ?></td>
          <td style="font-size:12px;color:var(--gray)"><?= $log['created_at'] ?></td>
        </tr>
        <?php endforeach; ?>
        <?php if(empty($logs['data'])): ?><tr><td colspan="5" style="text-align:center;padding:40px;color:var(--gray)">No logs yet</td></tr><?php endif; ?>
      </tbody>
    </table>
  </div>
  <div style="padding:14px"><?= \Core\View::paginate($logs, $u('admin/logs')) ?></div>
</div>
