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

<div class="page-head">
  <h2>Album Galeri Foto</h2>
  <a href="<?= APP_URL ?>/admin/galeri-foto/create" class="btn">+ Buat Album</a>
</div>

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

      <?php foreach ($daftarAlbum as $album): ?>
        <tr>
          <td>
            <?php if (!empty($album['cover'])): ?>
              <img src="<?= APP_URL . '/uploads/galeri/' . htmlspecialchars($album['cover']) ?>" alt="" style="width:48px; height:48px; object-fit:cover; border-radius:6px;">
            <?php else: ?>
              <div style="width:48px; height:48px; border-radius:6px; background:#eee;"></div>
            <?php endif; ?>
          </td>
          <td><?= htmlspecialchars($album['judul']) ?></td>
          <td><?= (int) $album['jumlah_foto'] ?> foto</td>
          <td style="text-align:right; white-space:nowrap;">
            <a href="<?= APP_URL ?>/galeri-foto/<?= $album['id'] ?>" target="_blank" class="btn btn-secondary btn-sm">Lihat</a>
            <a href="<?= APP_URL ?>/admin/galeri-foto/<?= $album['id'] ?>/edit" class="btn btn-secondary btn-sm">Kelola</a>
            <form action="<?= APP_URL ?>/admin/galeri-foto/<?= $album['id'] ?>/delete" method="POST" style="display:inline;"
                  onsubmit="return confirm('Hapus album &quot;<?= htmlspecialchars(addslashes($album['judul'])) ?>&quot;? Semua foto di dalamnya ikut terhapus.');">
              <?= \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'; ?>
