<?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">
                        Soal Ujian - <?= htmlspecialchars($nama_mk) ?> (<?= htmlspecialchars($tipe_soal) ?>)
                      </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($soalList)): ?>
                              <div class="alert alert-warning">
                                Belum ada soal yang tersedia untuk ujian ini.
                              </div>
                            <?php else: ?>
                              <form method="POST" action="/ujian/simpan" id="form-ujian">
                                <input type="hidden" name="kode_mk" value="<?= htmlspecialchars($kode_mk) ?>">
                                <input type="hidden" name="tipe_soal" value="<?= htmlspecialchars($tipe_soal) ?>">
                                <input type="hidden" name="id_jadwal_u" value="<?= htmlspecialchars($id_jadwal_u) ?>">

                                <?php foreach ($soalList as $index => $soal): ?>
                                  <div class="card mb-4 shadow-sm">
                                    <div class="card-body">
                                      <h6>Soal <?= $index + 1 ?>:</h6>
                                      <p><?= nl2br(htmlspecialchars($soal['soal'])) ?></p>

                                      <div class="form-group">
                                        <label for="jawaban_<?= $soal['id_soal'] ?>">Jawaban Anda:</label>
                                        <textarea
                                          name="jawaban[<?= $soal['id_soal'] ?>]"
                                          id="jawaban_<?= $soal['id_soal'] ?>"
                                          rows="5"
                                          class="form-control prevent-paste"
                                          data-terisi="<?= ! empty($jawabanSebelumnya[$soal['id_soal']]) ? '1' : '0' ?>"
                                        ><?= htmlspecialchars($jawabanSebelumnya[$soal['id_soal']] ?? '') ?></textarea>
                                      </div>
                                    </div>
                                  </div>
                                <?php endforeach; ?>

                                <button type="submit" class="btn btn-info">Kirim Jawaban</button>
                              </form>
                            <?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'; ?>


