<?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="container mt-5">
    <?php if (!empty($data)) : ?>
        <!-- FORM EDIT DATA KKN -->
        <div class="card">
            <div class="card-body">
                <h5 class="card-title text-center mb-4">Form Edit Data KKN</h5>

                <!-- Print Button -->
                <div class='mb-3'>
                    <a href="/dashboard/mahasiswa-frm_kkn" target="_blank" class="btn btn-warning float-end mb-3">
                        <i class="bi bi-printer"></i> Print
                    </a>
                </div>

                <form method="POST" action="">
                    <div class='mb-3'>
                        <label>NIM</label>
                        <input type="text" name="nim" class="form-control" value="<?= $data['nim'] ?>" readonly>
                    </div>

                    <div class='mb-3'>
                        <label>Nama</label>
                        <input type="text" name="nama" class="form-control" value="<?= $data['nama'] ?>" readonly>
                    </div>

                    <div class='mb-3'>
                        <label>Tempat Lahir</label>
                        <input type="text" name="tmpt_lahir" class="form-control" value="<?= $data['tmpt_lahir'] ?>">
                    </div>

                    <div class='mb-3'>
                        <label>Tanggal Lahir</label>
                        <input type="date" name="tgl_lahir" class="form-control" value="<?= $data['tgl_lahir'] ?>">
                    </div>

                    <div class='mb-3'>
                        <label>Program Studi</label>
                        <input type="text" name="prodi" class="form-control" value="<?= $data['prodi'] ?>" readonly>
                    </div>

                    <div class='mb-3'>
                        <label>Semester</label>
                        <input type="text" name="semester" class="form-control" value="<?= $data['semester'] ?>">
                    </div>

                    <div class='mb-3'>
                        <label>Jenis Kelamin</label>
                        <select name="jenis_kelamin" class="form-control">
                            <option value="Laki-laki" <?= $data['jenis_kelamin'] === 'Laki-laki' ? 'selected' : '' ?>>Laki-laki</option>
                            <option value="Perempuan" <?= $data['jenis_kelamin'] === 'Perempuan' ? 'selected' : '' ?>>Perempuan</option>
                        </select>
                    </div>

                    <div class='mb-3'>
                        <label>No HP</label>
                        <input type="text" name="no_hp" class="form-control" value="<?= $data['no_hp'] ?>">
                    </div>

                    <div class='mb-3'>
                        <label>Alamat</label>
                        <textarea name="alamat" class="form-control"><?= $data['alamat'] ?></textarea>
                    </div>

					<div class='mb-3'>
						<label>Status Pekerjaan</label>
						<select name="status_pekerjaan" class="form-control">
							<option value="" <?= empty($data['status_pekerjaan']) ? 'selected' : '' ?>>Pilih...</option>
							<option value="PNS" <?= ($data['status_pekerjaan'] ?? '') === 'PNS' ? 'selected' : '' ?>>PNS</option>
							<option value="Honorer" <?= ($data['status_pekerjaan'] ?? '') === 'Honorer' ? 'selected' : '' ?>>Honorer</option>
							<option value="Karyawan Swasta" <?= ($data['status_pekerjaan'] ?? '') === 'Karyawan Swasta' ? 'selected' : '' ?>>Karyawan Swasta</option>
							<option value="Wirausaha" <?= ($data['status_pekerjaan'] ?? '') === 'Wirausaha' ? 'selected' : '' ?>>Wirausaha</option>
							<option value="Belum Bekerja" <?= ($data['status_pekerjaan'] ?? '') === 'Belum Bekerja' ? 'selected' : '' ?>>Belum Bekerja</option>
						</select>
					</div>

					<div class='mb-3'>
						<label>Status Perkawinan</label>
						<select name="status_perkawinan" class="form-control">
							<option value="" <?= empty($data['status_perkawinan']) ? 'selected' : '' ?>>Pilih...</option>
							<option value="Menikah" <?= ($data['status_perkawinan'] ?? '') === 'Menikah' ? 'selected' : '' ?>>Menikah</option>
							<option value="Belum Menikah" <?= ($data['status_perkawinan'] ?? '') === 'Belum Menikah' ? 'selected' : '' ?>>Belum Menikah</option>
						</select>
					</div>

                    <button type="submit" name="update" value="1" class="btn btn-success">Update Data</button>
                </form>
            </div>
        </div>
    <?php else : ?>
        <!-- FORM INPUT TOKEN -->
        <div class="card">
            <div class="card-body">
                <h5 class="card-title text-center mb-4">Masukkan Token KKN</h5>
                <form method="post" action="/dashboard/mahasiswa-daftarkkn">
                    <div class="mb-3">
                        <label for="token" class="form-label">Token:</label>
                        <input type="text" name="token" id="token" class="form-control" required>
                    </div>
                    <button type="submit" class="btn btn-primary">Daftar</button>
                </form>
				</br>
				<?php if (isset($_SESSION['success'])): ?>
					<div class="alert alert-success" id="alert-success">
						<?= $_SESSION['success']; unset($_SESSION['success']); ?>
					</div>
				<?php endif; ?>

				<?php if (isset($_SESSION['error'])): ?>
					<div class="alert alert-danger" id="alert-error">
						<?= $_SESSION['error']; unset($_SESSION['error']); ?>
					</div>
				<?php endif; ?>

				<script>
					// Menghilangkan alert setelah 3 detik (3000 ms)
					setTimeout(() => {
						const successAlert = document.getElementById('alert-success');
						const errorAlert = document.getElementById('alert-error');
						if (successAlert) successAlert.style.display = 'none';
						if (errorAlert) errorAlert.style.display = 'none';
					}, 3000);
				</script>

						
            </div>
			
        </div>
    <?php endif; ?>
</div>



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

              </div> <!-- end tab-content -->
            </div> <!-- end col-9 -->

          </div> <!-- end row -->
        </div> <!-- end p-0 -->
      </div> <!-- end shadow-sm -->
    </div> <!-- end col -->
  </div> <!-- end row -->
</div> <!-- end container -->

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