<?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">
                <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">Upload Soal via Excel</h5>
                    </div>

                    <div class="bg-white rounded shadow-sm p-4">
                      <div class="container">

                        <div class="d-flex justify-content-end mb-3 gap-2">
                          <a href="/dashboard/dosen-lihatsoal" class="btn btn-secondary d-flex align-items-center gap-1">
                            <i class="bi bi-file-earmark-text"></i> Lihat Soal
                          </a>
                          
                          <a href="/dashboard/dosen-upload-soal" class="btn btn-primary d-flex align-items-center gap-1">
                            <i class="bi bi-pencil-square"></i> Upload Manual
                          </a>
                          
                        </div>


                        <?php if (!empty($_SESSION['message'])): ?>
                          <?= $_SESSION['message']; unset($_SESSION['message']); ?>
                        <?php endif; ?>

                        <form method="post" action="/dashboard/dosen-upload-soal-excel" enctype="multipart/form-data" class="mt-3">
                          <div class="mb-3">
                            <label for="kode_mk" class="form-label">Mata Kuliah dan Kelas</label>
                            <select name="kode_mk" id="kode_mk" class="form-select" required>
                              <option value="">Pilih Mata Kuliah dan Kelas</option>
                              <?php foreach ($courses as $course): ?>
                                <option value="<?= $course->kode_mk ?>|<?= $course->kode_kelas ?>">
                                  <?= $course->nama_mk ?> - Kelas <?= $course->kode_kelas ?>
                                </option>
                              <?php endforeach; ?>
                            </select>
                          </div>

                          <div class="mb-3">
                            <label for="tipe_soal" class="form-label">Tipe Soal</label>
                            <?php foreach ($jenis_soal as $jenis): ?>
                              <input type="text" class="form-control" value="<?= $jenis->jenis_soal ?>" disabled>
                              <input type="hidden" name="tipe_soal" value="<?= $jenis->jenis_soal ?>">
                            <?php endforeach; ?>
                          </div>

                          <div class="mb-3">
                            <label for="excelFile" class="form-label">Upload File Excel</label>
                            <input type="file" name="excelFile" id="excelFile" class="form-control" accept=".xls,.xlsx" required>
                            <small class="text-muted">
                              Gunakan <a href="/download_format_soal?file=template_soal.xlsx" download>template Excel</a> untuk format pengisian.
                            </small>
                          </div>

                          <div class="d-flex mb-3">
                            <button type="submit" name="uploadsoalexcel" class="btn btn-success">Upload Soal Excel</button>
                          </div>
                        </form>

                      </div>
                    </div>

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

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