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

<div class="page-head">
  <h2>Kategori Berita</h2>
  <a href="<?= APP_URL ?>/admin/berita" class="btn btn-secondary">Kembali ke Berita</a>
</div>

<div style="display:grid; grid-template-columns: 1fr 320px; gap:20px; align-items:start;">
  <div class="card" style="padding:0;">
    <table>
      <thead><tr><th>Nama</th><th>Slug</th><th style="text-align:right;">Aksi</th></tr></thead>
      <tbody>
        <?php if (empty($kategori)): ?>
          <tr><td colspan="3" style="text-align:center; color:var(--admin-muted); padding:24px;">Belum ada kategori.</td></tr>
        <?php endif; ?>
        <?php foreach ($kategori as $k): ?>
          <tr>
            <td><?= htmlspecialchars($k['nama']) ?></td>
            <td style="color:var(--admin-muted);"><?= htmlspecialchars($k['slug']) ?></td>
            <td style="text-align:right;">
              <form action="<?= APP_URL ?>/admin/kategori-berita/<?= $k['id'] ?>/delete" method="POST"
                    onsubmit="return confirm('Hapus kategori &quot;<?= htmlspecialchars(addslashes($k['nama'])) ?>&quot;? Berita di kategori ini akan jadi tanpa kategori.');">
                <?= \App\Core\Csrf::field() ?>
                <button type="submit" class="btn btn-danger btn-sm">Hapus</button>
              </form>
            </td>
          </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
  </div>

  <div class="card">
    <h3 style="margin-top:0; font-size:14px;">Tambah Kategori</h3>
    <form method="POST" action="<?= APP_URL ?>/admin/kategori-berita">
      <?= \App\Core\Csrf::field() ?>
      <div class="form-group">
        <label for="nama">Nama Kategori</label>
        <input type="text" id="nama" name="nama" class="form-control" required placeholder="Contoh: Prestasi">
      </div>
      <button type="submit" class="btn" style="width:100%; justify-content:center;">Tambah</button>
    </form>
  </div>
</div>

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