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

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

<div class="card" style="padding:0;">
  <table>
    <thead>
      <tr>
        <th>Gambar</th>
        <th>Nama</th>
        <th>Urutan</th>
        <th style="text-align:right;">Aksi</th>
      </tr>
    </thead>
    <tbody>
      <?php if (empty($daftarFasilitas)): ?>
        <tr><td colspan="4" style="text-align:center; color:var(--admin-muted); padding:24px;">Belum ada fasilitas.</td></tr>
      <?php endif; ?>

      <?php foreach ($daftarFasilitas as $item): ?>
        <tr>
          <td>
            <?php if (!empty($item['gambar'])): ?>
              <img src="<?= APP_URL . '/uploads/fasilitas/' . htmlspecialchars($item['gambar']) ?>" 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; display:flex; align-items:center; justify-content:center; font-size:20px;"><?= htmlspecialchars($item['icon'] ?? '🏢') ?></div>
            <?php endif; ?>
          </td>
          <td><?= htmlspecialchars($item['nama']) ?></td>
          <td><?= (int) $item['urutan'] ?></td>
          <td style="text-align:right; white-space:nowrap;">
            <a href="<?= APP_URL ?>/admin/fasilitas/<?= $item['id'] ?>/edit" class="btn btn-secondary btn-sm">Edit</a>
            <form action="<?= APP_URL ?>/admin/fasilitas/<?= $item['id'] ?>/delete" method="POST" style="display:inline;"
                  onsubmit="return confirm('Hapus fasilitas &quot;<?= htmlspecialchars(addslashes($item['nama'])) ?>&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'; ?>
