<?php $pageTitle = 'Halaman Statis'; ?>
<?php require BASE_PATH . '/app/Views/admin/layouts/header.php'; ?>

<div class="page-head">
  <h2>Daftar Halaman Statis</h2>
  <a href="<?= APP_URL ?>/admin/halaman/create" class="btn">+ Tambah Halaman</a>
</div>

<div class="card" style="padding:0;">
  <table>
    <thead>
      <tr>
        <th>Judul</th>
        <th>URL</th>
        <th>Status</th>
        <th style="text-align:right;">Aksi</th>
      </tr>
    </thead>
    <tbody>
      <?php if (empty($daftarHalaman)): ?>
        <tr><td colspan="4" style="text-align:center; color:var(--admin-muted); padding:24px;">
          Belum ada halaman. Contoh yang bisa dibuat: Sambutan Dekan, Visi &amp; Misi, Struktur Organisasi.
        </td></tr>
      <?php endif; ?>

      <?php foreach ($daftarHalaman as $item): ?>
        <tr>
          <td><?= htmlspecialchars($item['judul']) ?></td>
          <td style="color:var(--admin-muted);">/halaman/<?= htmlspecialchars($item['slug']) ?></td>
          <td>
            <?php if ($item['is_active']): ?>
              <span class="badge badge-active">Aktif</span>
            <?php else: ?>
              <span class="badge badge-inactive">Nonaktif</span>
            <?php endif; ?>
          </td>
          <td style="text-align:right; white-space:nowrap;">
            <a href="<?= APP_URL ?>/halaman/<?= htmlspecialchars($item['slug']) ?>" target="_blank" class="btn btn-secondary btn-sm">Lihat</a>
            <a href="<?= APP_URL ?>/admin/halaman/<?= $item['id'] ?>/edit" class="btn btn-secondary btn-sm">Edit</a>
            <form action="<?= APP_URL ?>/admin/halaman/<?= $item['id'] ?>/delete" method="POST" style="display:inline;"
                  onsubmit="return confirm('Hapus halaman &quot;<?= htmlspecialchars(addslashes($item['judul'])) ?>&quot;?');">
              <?= \App\Core\Csrf::field() ?>
              <button type="submit" class="btn btn-danger btn-sm">Hapus</button>
            </form>
          </td>
        </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
</div>

<?php require BASE_PATH . '/app/Views/admin/layouts/footer.php'; ?>
