<?php include __DIR__ . '/../../views/layouts/header.php'; ?>
<div class="wrapper">
<?php include __DIR__ . '/../../views/layouts/sidebar.php'; ?>
<div class="main-content">
<?php include __DIR__ . '/../../views/layouts/topbar.php'; ?>
<div class="page-content">
  <div class="page-header d-flex justify-content-between align-items-start flex-wrap gap-2">
    <div>
      <h1><i class="bi bi-people-fill me-2 text-primary"></i>Anggota Kelas</h1>
    </div>
  </div>

  <!-- Pilih Kelas -->
  <div class="search-bar mb-3">
    <form method="GET" class="row g-2 align-items-end">
      <input type="hidden" name="page" value="kelas_anggota">
      <div class="col-12 col-md-4">
        <label class="form-label mb-1">Pilih Kelas</label>
        <select class="form-select" name="kelas_id" onchange="this.form.submit()">
          <option value="">-- Pilih Kelas --</option>
          <?php foreach ($kelasList as $k): ?>
          <option value="<?= $k['id'] ?>" <?= ($kelasId ?? 0) == $k['id'] ? 'selected' : '' ?>>
            <?= e($k['nama_kelas']) ?>
          </option>
          <?php endforeach; ?>
        </select>
      </div>
    </form>
  </div>

  <?php if ($kelas): ?>
  <div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
      <h6 class="mb-0">
        <i class="bi bi-building me-2"></i>
        Kelas <?= e($kelas['nama_kelas']) ?>
        <span class="badge bg-primary ms-1"><?= count($siswa) ?> siswa</span>
      </h6>
      <div class="text-muted fs-sm">
        Wali Kelas: <?= e($kelas['nama_wali_kelas'] ?? '-') ?>
      </div>
    </div>
    <div class="card-body p-0">
      <?php if (empty($siswa)): ?>
        <div class="empty-state"><div class="empty-icon">👨‍🎓</div><p>Belum ada siswa di kelas ini</p></div>
      <?php else: ?>
      <div class="table-responsive">
        <table class="table mb-0">
          <thead>
            <tr>
              <th>No</th>
              <th>Nama Siswa</th>
              <th>NIS</th>
              <th>Jenis Kelamin</th>
              <th>Agama</th>
              <th>Aksi</th>
            </tr>
          </thead>
          <tbody>
            <?php foreach ($siswa as $i => $s): ?>
            <tr>
              <td><?= $i + 1 ?></td>
              <td class="fw-600"><?= e($s['nama']) ?></td>
              <td class="text-muted"><?= e($s['nis'] ?? '-') ?></td>
              <td><?= e($s['jenis_kelamin']) ?></td>
              <td><?= e($s['agama'] ?? '-') ?></td>
              <td>
                <a href="<?= BASE_URL ?>/index.php?page=siswa_detail&id=<?= $s['id'] ?>"
                   class="btn btn-sm btn-outline-info btn-icon">
                  <i class="bi bi-eye"></i>
                </a>
              </td>
            </tr>
            <?php endforeach; ?>
          </tbody>
        </table>
      </div>
      <?php endif; ?>
    </div>
  </div>
  <?php else: ?>
    <div class="empty-state card py-5">
      <div class="empty-icon">🏫</div>
      <p>Pilih kelas untuk melihat anggota</p>
    </div>
  <?php endif; ?>
</div>
<?php include __DIR__ . '/../../views/layouts/footer.php'; ?>
</div>
</div>
