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

<div class="page-head">
  <h2>Galeri Video</h2>
  <a href="<?= APP_URL ?>/admin/galeri-video/create" class="btn">+ Tambah Video</a>
</div>

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

      <?php foreach ($daftarVideo as $video): ?>
        <tr>
          <td>
            <?php if (!empty($video['thumbnail'])): ?>
              <img src="<?= htmlspecialchars($video['thumbnail']) ?>" alt="" style="width:80px; aspect-ratio:16/9; object-fit:cover; border-radius:6px;">
            <?php else: ?>
              <div style="width:80px; aspect-ratio:16/9; border-radius:6px; background:#eee;"></div>
            <?php endif; ?>
          </td>
          <td><?= htmlspecialchars($video['judul']) ?></td>
          <td style="text-align:right; white-space:nowrap;">
            <a href="<?= APP_URL ?>/admin/galeri-video/<?= $video['id'] ?>/edit" class="btn btn-secondary btn-sm">Edit</a>
            <form action="<?= APP_URL ?>/admin/galeri-video/<?= $video['id'] ?>/delete" method="POST" style="display:inline;"
                  onsubmit="return confirm('Hapus video &quot;<?= htmlspecialchars(addslashes($video['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'; ?>
