<h1 class="mb-8">Audit log.</h1>

<div class="card p-0 overflow-hidden">
<table class="table-base">
  <thead>
    <tr>
      <th>waktu</th>
      <th>user</th>
      <th>aksi</th>
      <th>entitas</th>
      <th>id</th>
      <th>metadata</th>
    </tr>
  </thead>
  <tbody>
    <% if (logs.length === 0) { %>
      <tr><td colspan="6" class="text-center text-mute py-8">Belum ada log.</td></tr>
    <% } %>
    <% logs.forEach(l => { %>
      <tr>
        <td class="mono-label whitespace-nowrap"><%= new Date(l.createdAt).toLocaleString('id-ID') %></td>
        <td><%= l.userNama || '—' %></td>
        <td><span class="badge-neutral font-mono"><%= l.action %></span></td>
        <td class="text-body"><%= l.entityType || '—' %></td>
        <td class="mono-label"><%= l.entityId || '—' %></td>
        <td class="mono-label max-w-[200px] truncate"><%= l.metadata ? JSON.stringify(l.metadata) : '—' %></td>
      </tr>
    <% }) %>
  </tbody>
</table>
</div>

<div class="mt-4 flex gap-2">
  <% if (page > 1) { %><a href="/audit?page=<%= page - 1 %>" class="btn-secondary btn-xs">← Sebelumnya</a><% } %>
  <% if (logs.length === 50) { %><a href="/audit?page=<%= page + 1 %>" class="btn-secondary btn-xs">Berikutnya →</a><% } %>
</div>
