<div class="d-flex gap-2 mb-3">
  <a class="btn btn-sm btn-light" href="<?= url('/log-aktivitas') ?>"><i class="bi bi-arrow-left me-1"></i>Kembali</a>
</div>
<div class="row g-3">
  <div class="col-lg-4">
    <div class="card"><div class="card-header"><i class="bi bi-info-circle me-1"></i>Informasi</div>
      <div class="card-body"><dl class="dl-grid">
        <dt>Waktu</dt><dd><?= tglWaktu($row['created_at']) ?></dd>
        <dt>Pengguna</dt><dd><?= e($row['user_name'] ?: 'Sistem') ?><?= $row['user_id'] ? ' (#'.(int)$row['user_id'].')' : '' ?></dd>
        <dt>Modul</dt><dd><?= e($row['module']) ?></dd>
        <dt>Aksi</dt><dd><?= badge(\App\Core\Audit::actionLabel($row['action']),'secondary') ?></dd>
        <dt>Entitas</dt><dd><?= e($row['entity_type'] ?: '-') ?><?= $row['entity_id'] ? ' #'.(int)$row['entity_id'] : '' ?></dd>
        <dt>Alamat IP</dt><dd><?= e($row['ip_address']) ?></dd>
        <dt>Peramban</dt><dd class="small"><?= e($row['user_agent'] ?: '-') ?></dd>
        <?php if ($row['approval_request_id']): ?><dt>Persetujuan</dt>
          <dd><a href="<?= url('/persetujuan/'.(int)$row['approval_request_id']) ?>">#<?= (int)$row['approval_request_id'] ?></a></dd><?php endif; ?>
      </dl>
      <hr><div class="small"><strong>Keterangan:</strong><br><?= nlbr($row['description']) ?></div>
      </div></div>
  </div>
  <div class="col-lg-8">
    <div class="card"><div class="card-header"><i class="bi bi-arrow-left-right me-1"></i>Perbandingan Nilai</div>
      <div class="table-wrap"><table class="table table-sm mb-0">
        <thead><tr><th>Kolom</th><th>Nilai Sebelum</th><th>Nilai Sesudah</th></tr></thead>
        <tbody>
        <?php
        $keys = array_unique(array_merge(array_keys($old), array_keys($new)));
        if (!$keys): ?><tr><td colspan="3" class="text-center text-body-secondary py-3">Tidak ada perubahan nilai yang dicatat.</td></tr><?php endif;
        foreach ($keys as $k):
          $ov = $old[$k] ?? null; $nv = $new[$k] ?? null;
          $berubah = (string)$ov !== (string)$nv; ?>
          <tr class="<?= $berubah?'table-warning':'' ?>">
            <td class="fw-semibold"><?= e(str_replace('_',' ',(string)$k)) ?></td>
            <td class="small"><?= e(is_array($ov) ? json_encode($ov, JSON_UNESCAPED_UNICODE) : (string)($ov ?? '—')) ?></td>
            <td class="small"><?= e(is_array($nv) ? json_encode($nv, JSON_UNESCAPED_UNICODE) : (string)($nv ?? '—')) ?></td>
          </tr>
        <?php endforeach; ?>
        </tbody></table></div>
    </div>
  </div>
</div>
