<?php include_once __DIR__ . '/../layouts/head.php'; ?>
<div class="container py-4" style="max-width: 1350px; width: 100%;">
  <div class="row">
    <div class="col-lg-12">
      <div class="shadow-sm bg-white rounded overflow-hidden border">
        <div class="p-0">
          <div class="row px-0 m-0">

            <?php include_once __DIR__ . '/../layouts/menu_body.php'; ?>

            <div class="col-12 col-md-9 px-0">
              <div class="tab-content" id="v-pills-tabContent">

                <!-- Konten Utama -->
                <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel">
                  <div class="p-4">

                    <div class="mb-4">
                      <h5 class="mb-0 fw-bold">Daftar Peserta PPLK</h5>
                      <br>

                      <!-- Filter Tahun Akademik (AUTO SUBMIT) -->
                      <form method="GET" id="filterForm" class="row g-2 align-items-end">
                        <div class="col-md-4">
                          <label class="form-label">Tahun Akademik</label>
                          <select name="tahun_akademik" class="form-select"
                                  onchange="document.getElementById('filterForm').submit()">
                            <option value="">-- Semua Tahun Akademik --</option>
                            <?php foreach ($listAkademik as $ta): ?>
                              <option value="<?= htmlspecialchars($ta['tahun_akademik']) ?>"
                                <?= ($tahun_akademik == $ta['tahun_akademik']) ? 'selected' : '' ?>>
                                <?= htmlspecialchars($ta['tahun_akademik']) ?>
                              </option>
                            <?php endforeach; ?>
                          </select>
                        </div>

                        <!-- Download Excel -->
                        <div class="col-md-4">
                          <a id="btnDownload"
                             href="/dashboard/staff-data-pplk/download?tahun_akademik=<?= urlencode($tahun_akademik ?? '') ?>"
                             class="btn btn-success mt-4">
                            <i class="bi bi-file-earmark-excel"></i> Download Excel
                          </a>
                        </div>
                      </form>
                    </div>

                    <hr>

                    <!-- Tabel Data PPLK -->
                    <div class="table-responsive">
                      <table class="table table-striped table-bordered">
                        <thead class="table-light">
                          <tr>
                            <th>No</th>
                            <th>NIM</th>
                            <th>Nama</th>
                            <th>Prodi</th>
                            <th>Semester</th>
                            <th>JK</th>
                            <th>No WA</th>
                            <th>Tahun Akademik</th>
                          </tr>
                        </thead>
                        <tbody>
                          <?php if (empty($pplk)): ?>
                            <tr>
                              <td colspan="8" class="text-center">Tidak ada data ditemukan.</td>
                            </tr>
                          <?php else: ?>
                            <?php foreach ($pplk as $i => $row): ?>
                              <tr>
                                <td><?= $i + 1 ?></td>
                                <td><?= htmlspecialchars($row['nim']) ?></td>
                                <td><?= htmlspecialchars($row['nama']) ?></td>
                                <td><?= htmlspecialchars($row['prodi']) ?></td>
                                <td><?= htmlspecialchars($row['semester']) ?></td>
                                <td><?= htmlspecialchars($row['jenis_kelamin']) ?></td>
                                <td><?= htmlspecialchars($row['no_hp']) ?></td>
                                <td><?= htmlspecialchars($row['tahun_akademik']) ?></td>
                              </tr>
                            <?php endforeach; ?>
                          <?php endif; ?>
                        </tbody>
                      </table>
                    </div>

                  </div>
                </div>

              </div>
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php include_once __DIR__ . '/../layouts/footer.php'; ?>
