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

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

<div class="card" style="padding:0;">
  <table>
    <thead>
      <tr>
        <th>Judul</th>
        <th>Lokasi</th>
        <th>Tanggal Mulai</th>
        <th>Status</th>
        <th style="text-align:right;">Aksi</th>
      </tr>
    </thead>
    <tbody>
      <?php if (empty($daftarAgenda)): ?>
        <tr><td colspan="5" style="text-align:center; color:var(--admin-muted); padding:24px;">Belum ada agenda.</td></tr>
      <?php endif; ?>

      <?php foreach ($daftarAgenda as $item): ?>
        <?php $sudahLewat = strtotime($item['tanggal_mulai']) < time(); ?>
        <tr>
          <td><?= htmlspecialchars($item['judul']) ?></td>
          <td style="color:var(--admin-muted);"><?= htmlspecialchars($item['lokasi'] ?? '—') ?></td>
          <td><?= date('d M Y, H:i', strtotime($item['tanggal_mulai'])) ?></td>
          <td>
            <?php if ($sudahLewat): ?>
              <span class="badge badge-inactive">Selesai</span>
            <?php else: ?>
              <span class="badge badge-active">Akan Datang</span>
            <?php endif; ?>
          </td>
          <td style="text-align:right; white-space:nowrap;">
            <a href="<?= APP_URL ?>/admin/agenda/<?= $item['id'] ?>/edit" class="btn btn-secondary btn-sm">Edit</a>
            <form action="<?= APP_URL ?>/admin/agenda/<?= $item['id'] ?>/delete" method="POST" style="display:inline;"
                  onsubmit="return confirm('Hapus agenda &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'; ?>
