<?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">

                <!-- Awal Isi Konten -->
                <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
                  <div class="p-4">
                    <div class="mb-4">
                      <h5 class="mb-0 fw-bold">Daftar Ujian yang Bisa Dikerjakan</h5>
                    </div>

                    <div class="col mb-3">
                      <br />
                    </div>

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

                            <?php if (empty($dataJadwal)): ?>
                              <div class="alert alert-warning w-100">
                                Belum ada jadwal ujian aktif untuk Anda.
                              </div>
                            <?php else: ?>
                              <?php foreach ($dataJadwal as $j): ?>
                                <form method="GET" action="/dashboard/mahasiswa-mulai-ujian?id=<?= $j['id_jadwal_u'] ?>" class="mb-1" id="formSoal<?= $j['id_jadwal_u'] ?>">
                                  <div class="d-flex flex-wrap justify-content-start gap-3">
                                    <div class="p-1">
                                      <div class="btn-group d-flex gap-3 my-3 osahan-btn-group" role="group" aria-label="Basic radio toggle button group">
                                        <input type="hidden" name="kode_mk" value="<?= htmlspecialchars($j['kode_mk']) ?>">
                                        <input type="hidden" name="id_jadwal_u" value="<?= htmlspecialchars($j['id_jadwal_u']) ?>">
                                        <input type="hidden" name="tipe_soal" value="<?= htmlspecialchars($j['jenis_soal']) ?>">
                                        <input type="hidden" name="tgl_berakhir" value="<?= htmlspecialchars($j['tgl_berakhir']) ?>">

                                        <button type="submit" class="btn btn-outline-light d-flex gap-4 rounded p-4 w-100 shadow-sm border">
                                          <i class="bi bi-stickies h5 mb-0"></i>
                                          <span class="text-start">
                                            <b class="h6 mb-1 d-block fw-bold"><?= htmlspecialchars($j['nama_mk']) ?></b>
                                            <small class="text-muted"><?= htmlspecialchars($j['jenis_soal']) ?></small><br>
                                            <small class="text-muted">Kode MK: <?= htmlspecialchars($j['kode_mk']) ?></small><br>
                                            <small class="text-danger">Batas Akhir: <?= htmlspecialchars($j['tgl_berakhir']) ?> | <?= htmlspecialchars($j['jam_berakhir']) ?></small>
                                          </span>
                                          <i class="bi bi-check-circle-fill ms-auto text-success"></i>
                                        </button>
                                      </div>
                                    </div>
                                  </div>
                                </form>
                              <?php endforeach; ?>
                            <?php endif; ?>

                            <script>
                              function submitForm(idJadwal) {
                                const form = document.createElement('form');
                                form.method = 'GET';
                                form.action = '/soal/mulai/' + idJadwal;
                                document.body.appendChild(form);
                                form.submit();
                              }
                            </script>
							
							<?php if (!empty($_SESSION['info'])): ?>
							<script>
								Swal.fire({
									icon: '<?= $_SESSION['info_type'] ?? 'info'; ?>',
									title: 'Informasi',
									text: '<?= $_SESSION['info']; ?>',
									timer: 2000,
									showConfirmButton: false
								});
							</script>
							<?php unset($_SESSION['info'], $_SESSION['info_type']); ?>
							<?php endif; ?>
				
                          </div>
                        </div>
                      </div>
                    </div>

                  </div>
                </div>
                <!-- Batas Isi Konten -->

              </div>
            </div>

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

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