<?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="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" aria-labelledby="v-pills-home-tab">
						<div class="p-4">
							<div class="mb-4">
								<h5 class="mb-0 fw-bold">Input Nilai UAS/UTS</h5>
							</div>

							<div class="bg-white rounded shadow-sm p-4">
							<!-- letakan disini perbaikannya -->

								<?php if (!$id_j_soal): ?>
									<div id="popup" class="popup-overlay">
										<div class="popup-content">
											<h4>Data Belum Dipilih</h4>
											<p>Silahkan pilih jenis ujian yang akan dinilai.</p>
											<a href="/dashboard/dosen-view-utsuas?id_j_soal=1" class="btn btn-primary">UTS</a>
											<a href="/dashboard/dosen-view-utsuas?id_j_soal=2" class="btn btn-success">UAS</a>
										</div>
									</div>
									<style>
										.popup-overlay {
											position: fixed;
											top: 0; left: 0; width: 100%; height: 100%;
											background: rgba(0,0,0,0.5); display: flex;
											justify-content: center; align-items: center; z-index: 1000;
										}
										.popup-content {
											background: white; padding: 20px; border-radius: 8px; text-align: center;
											box-shadow: 0px 0px 10px rgba(0,0,0,0.3);
										}
										.btn { margin: 5px; padding: 10px 15px; border-radius: 5px; text-decoration: none; display: inline-block; }
										.btn-primary { background-color: blue; color: white; }
										.btn-success { background-color: green; color: white; }
									</style>
								<?php else: ?>
									<a href="/dashboard/dosen-view-utsuas?id_j_soal=<?= $id_j_soal ?>" class="text-light text-decoration-none btn btn-danger" title="Back">
										<i class="bi bi-skip-backward-circle"></i> Back
									</a>
															
									<a href="/dashboard/dosen-pdf_uas_uts?kode_mk=<?= $info_kelas['kode_mk'] ?>&kode_kelas=<?= $info_kelas['kode_kelas'] ?>&id_j_soal=<?= $id_j_soal ?>&tahun_akademik=<?= $tahun_akademik ?>" target="_blank" class="btn btn-info">
										Export PDF <?= ($id_j_soal == 1) ? 'UTS' : 'UAS' ?>
									</a>
									<form method="POST" action="/dashboard/dosen-input-uasuts">
										<input type="hidden" name="id_j_soal" value="<?= htmlspecialchars($id_j_soal) ?>">
										<input type="hidden" name="kode_mk" value="<?= $info_kelas['kode_mk'] ?? '' ?>">
										<input type="hidden" name="kode_kelas" value="<?= $info_kelas['kode_kelas'] ?? '' ?>">
										<input type="hidden" name="id_dmk" value="<?= $info_kelas['id_dmk'] ?? '' ?>">
										<input type="hidden" name="tahun_akademik" value="<?= $tahun_akademik ?>">

										<div class="mb-3">
											<strong>Matakuliah:</strong> <?= $info_kelas['kode_mk'] ?? '-' ?> |
											<strong>Kelas:</strong> <?= $info_kelas['kode_kelas'] ?? '-' ?> |
											<strong>Semester:</strong> <?= $tahun_akademik ?>
										</div>

										<table class="table table-bordered">
											<thead>
												<tr>
													<th>No</th>
													<th>NIM</th>
													<th>Nama</th>
													<th>Nilai <?= ($id_j_soal == 1) ? 'UTS' : 'UAS' ?></th>
												</tr>
											</thead>
											<tbody>
												<?php $i = 1; foreach ($daftar_mahasiswa as $mhs): ?>
													<tr>
														<td><?= $i++ ?></td>
														<td><input type="hidden" name="nim[]" value="<?= $mhs['nim'] ?>"><?= $mhs['nim'] ?></td>
														<td><?= $mhs['nama'] ?></td>
														<td><input type="number" name="nilai[]" class="form-control" value="<?= $mhs['nilai'] ?? 0 ?>" min="0" max="100" required></td>
													</tr>
												<?php endforeach; ?>
											</tbody>
										</table>

										<button type="submit" class="btn btn-success">Simpan Nilai</button>
									</form>
								<?php endif; ?>

							
							
							</div>
							
						</div>

					</div>

			</div>
			</div>


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