<?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">
                <div class="tab-pane fade show active">
                  <div class="p-4">
                    <div class="mb-4">
                      <h5 class="mb-0 fw-bold">Pilih Kelas</h5>
                    </div>

                    <div class="row row-cols-1 row-cols-md-12 g-12">
                      <div class="col">
                        <div class="border rounded d-flex gap-12 p-12">
                          <div class="p-4">
                            <div class="mb-4">

                              <?php if (!$hasToken): ?>
                                <!-- FORM INPUT TOKEN -->
                                <form method="post" action="/dashboard/maba-token" class="d-flex">
                                  <div class="input-group">
                                    <input type="text" id="token" name="token" class="form-control rounded-start-pill <?= isset($errors['token']) ? 'is-invalid' : '' ?>" placeholder="Masukan Token" required>
                                    <button type="submit" name="submit_token" class="btn btn-outline-danger rounded-end">Kirim Token</button>
                                  </div>
                                  <?php if (isset($errors['token'])): ?>
                                    <div class="invalid-feedback d-block">
                                      <?= $errors['token'] ?>
                                    </div>
                                  <?php endif; ?>
                                </form>
                              
                              <?php else: ?>
                                <!-- FORM PILIH KELAS -->
                                <form action="/dashboard/maba-pilihkelas" method="POST">
                                  <div class="row g-4">

                                    <div class="col-12">
                                      <label>Kelas <span class="text-danger">*</span></label>
                                      <select 
                                        name="kelas" 
                                        class="form-control <?= isset($errors['kelas']) ? 'is-invalid' : '' ?>" 
                                        required
                                      >
                                        <option value="">-- Pilih Kelas --</option>
                                        <option value="Reguler" <?= ($mahasiswa['kelas'] ?? '') == 'Reguler' ? 'selected' : '' ?>>Reguler</option>
                                        <option value="Karyawan" <?= ($mahasiswa['kelas'] ?? '') == 'Karyawan' ? 'selected' : '' ?>>Karyawan</option>
                                      </select>
                                      <?php if (isset($errors['kelas'])): ?>
                                          <div class="invalid-feedback">
                                              <?= $errors['kelas'] ?>
                                          </div>
                                      <?php endif; ?>
                                    </div>
                                    
                                    <div class="col-12">
                                      <label>Jenis Pembiayaan <span class="text-danger">*</span></label>
                                      <select 
                                        name="jenis_pembiayaan" 
                                        class="form-control <?= isset($errors['jenis_pembiayaan']) ? 'is-invalid' : '' ?>" 
                                        required
                                      >
                                        <option value="">-- Pilih Jenis Pembiayaan --</option>
                                        <option value="1" <?= ($mahasiswa['jenis_pembiayaan'] ?? '') == '1' ? 'selected' : '' ?>>Mandiri</option>
                                        <option value="2" <?= ($mahasiswa['jenis_pembiayaan'] ?? '') == '2' ? 'selected' : '' ?>>Beasiswa Tidak Penuh</option>
                                        <option value="3" <?= ($mahasiswa['jenis_pembiayaan'] ?? '') == '3' ? 'selected' : '' ?>>Beasiswa Penuh</option>
                                      </select>
                                      <?php if (isset($errors['jenis_pembiayaan'])): ?>
                                          <div class="invalid-feedback">
                                              <?= $errors['jenis_pembiayaan'] ?>
                                          </div>
                                      <?php endif; ?>
                                    </div>

                                    <div class="col-12">
                                      <label>Lokasi Daftar Kuliah <span class="text-danger">*</span></label>
                                      <select 
                                        name="pusat_pokjar" 
                                        class="form-control <?= isset($errors['pusat_pokjar']) ? 'is-invalid' : '' ?>" 
                                        required
                                      >
                                        <option value="">-- Diamana Daftar Kuliah Dilakukan --</option>
                                        <option value="Pusat/Kampus Menes" <?= ($mahasiswa['pusat_pokjar'] ?? '') == 'Pusat/Kampus Menes' ? 'selected' : '' ?>>Pusat/Kampus Menes</option>
                                        <option value="Cibaliung" <?= ($mahasiswa['pusat_pokjar'] ?? '') == 'Cibaliung' ? 'selected' : '' ?>>Cibaliung</option>
                                        <option value="Cikeusik" <?= ($mahasiswa['pusat_pokjar'] ?? '') == 'Cikeusik' ? 'selected' : '' ?>>Cikeusik</option>
                                        <option value="Cigeulis" <?= ($mahasiswa['pusat_pokjar'] ?? '') == 'Cigeulis' ? 'selected' : '' ?>>Cigeulis</option>
                                        <option value="Ciekek" <?= ($mahasiswa['pusat_pokjar'] ?? '') == 'Ciekek' ? 'selected' : '' ?>>Ciekek</option>
                                        <option value="Lainnya" <?= ($mahasiswa['pusat_pokjar'] ?? '') == 'Lainnya' ? 'selected' : '' ?>>Lainnya</option>
                                      </select>
                                      <?php if (isset($errors['pusat_pokjar'])): ?>
                                          <div class="invalid-feedback">
                                              <?= $errors['pusat_pokjar'] ?>
                                          </div>
                                      <?php endif; ?>
                                    </div>                                    

                                    <div class="col-12">
                                      <label>Jumlah Biaya Masuk <span class="text-danger">*</span></label>
                                      <input 
                                        type="number" 
                                        step="0.01" 
                                        name="jumlah_biaya_masuk" 
                                        class="form-control <?= isset($errors['jumlah_biaya_masuk']) ? 'is-invalid' : '' ?>" 
                                        value="<?= htmlspecialchars($mahasiswa['jumlah_biaya_masuk'] ?? '') ?>" 
                                        required
                                      >
                                      <?php if (isset($errors['jumlah_biaya_masuk'])): ?>
                                          <div class="invalid-feedback">
                                              <?= $errors['jumlah_biaya_masuk'] ?>
                                          </div>
                                      <?php endif; ?>
                                    </div>

                                  </div>
                                
                                  <div class="mt-4">
                                    <button type="submit" class="btn btn-primary">Simpan Kelas</button>
                                  </div>
                                </form>
                              <?php endif; ?>

                            </div>
                          </div>
                        </div>
                      </div>                        
                    </div>

                  </div>
                </div>
              </div>
            </div>

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