<?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">Halaman KRS & KHS</h5>
					</div>
					<div class="row row-cols-1 row-cols-md-2 g-4">
					  <div class="col">
						<div class="border rounded d-flex gap-3 p-4">
						  <i class="bi bi-printer m-0 rounded-pill rounded-icon"></i>
						  <div class="text-start">
							<h6 class="mb-1 fw-bold">KRS</h6>
							<div class="text-muted small text-opacity-50 mb-3">Cetak KRS</div>
							<div id="v-pills-tab" role="tablist" aria-orientation="vertical">
							  <a href="/dashboard/mahasiswa-krs" class="fw-bold text-danger text-decoration-none text-uppercase">Open</a>
							</div>
						  </div>
						  <i class="bi bi-check-circle-fill ms-auto"></i>
						</div>
					  </div>
					  <div class="col">
						<div class="border rounded d-flex gap-3 p-4">
						  <i class="bi bi-printer-fill m-0 rounded-pill rounded-icon"></i>
						  <div class="text-start">
							<h6 class="mb-1 fw-bold">KHS</h6>
							<div class="text-muted small text-opacity-50 mb-3">Cetak KHS</div>
							<a href="/dashboard/mahasiswa-khs" class="fw-bold text-danger text-decoration-none text-uppercase">Open</a>
						  </div>
						  <i class="bi bi-check-circle-fill ms-auto"></i>
						</div>
					  </div>
					</div>
					<div class="col">
					  </br>
					</div>
					
					<div class="container mt-4">
					  <h4>Kartu Hasil Studi - Semester <?= htmlspecialchars($smt) ?></h4>

					  <?php if (!$tokenUsed) : ?>
						<div class="alert alert-warning">Token belum tersedia untuk Semester <?= htmlspecialchars($smt) ?>. Silakan masukkan token di bawah ini:</div>

						<?php if (!empty($error)) : ?>
						  <div class="alert alert-danger"><?= $error ?></div>
						<?php endif; ?>

						<div class="d-flex gap-2 align-items-start">
						  <form method="POST" action="/dashboard/mahasiswa-khs/detail?smt=<?= urlencode($smt) ?>" class="d-flex gap-2">
							<input type="hidden" name="nim" value="<?= htmlspecialchars($nim) ?>">
							<input type="hidden" name="smt" value="<?= htmlspecialchars($smt) ?>">
							<div class="input-group">
							  <input type="text" name="token" class="form-control" placeholder="Masukkan token"
									 style="border-top-left-radius: 25px; border-bottom-left-radius: 25px; border-top-right-radius: 0; border-bottom-right-radius: 0;">
							  <button type="submit" class="btn btn-info" name="kirim_token"
									  style="border-top-right-radius: 25px; border-bottom-right-radius: 25px; border-top-left-radius: 0; border-bottom-left-radius: 0;">
								Kirim Token
							  </button>
							</div>
						  </form>
						  <a href="/dashboard/mahasiswa-khs" class="btn btn-secondary">Kembali</a>
						</div>

					  <?php else : ?>
						<div class="border rounded d-flex gap-3 p-4 mt-4">
						  <table class="table table-bordered-dinamis">
							<thead>
							  <tr>
								<th>No</th>
								<th>Matakuliah</th>
								<th>Nilai</th>
								<th><center>-</center></th>
							  </tr>
							</thead>
							<tbody>
							  <?php if (!empty($khs)) : ?>
								<?php $no = 1; foreach ($khs as $row) : ?>
								  <tr>
									<td><?= $no++ ?></td>
									<td><?= htmlspecialchars($row['nama_mk']) ?></td>
									<td><?= htmlspecialchars($row['nilai']) ?></td>
									
									<td>
                                        <a href="/dashboard/mahasiswa-khs/detailnilai?kode_mk=<?= urlencode($row['kode_mk']) ?>&nim=<?= urlencode($nim) ?>&smt=<?= urlencode($smt) ?>&id_krs=<?= urlencode($row['id_krs'] ?? '') ?>" 
                                           class="btn btn-sm btn-primary ms-2 <?= empty($row['id_krs']) ? 'disabled' : '' ?>">
                                          Detail Nilai
                                        </a>
                                    </td>
								  </tr>
								<?php endforeach; ?>
							  <?php else : ?>
								<tr><td colspan="3">Data tidak ditemukan..!</td></tr>
							  <?php endif; ?>
							</tbody>
						  </table>
						</div>
						<div class="d-flex gap-2 mt-3">

							<a href="/dashboard/cetak-khs?smt=<?= urlencode($smt) ?>" class="btn btn-info" target="_blank">
								<i class="fa fa-file-pdf"></i> Cetak PDF
							</a>
							<a href="/dashboard/mahasiswa-khs" class="btn btn-secondary">Kembali</a>
						</div>

					  <?php endif; ?>
					</div>
					
				  </div>
				</div>
				<!-- batas isi konten -->			  
			  
			  
			  </div>
            </div>

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