<?php
// Session dates logic
$sessionDate = date('Y-m-d');
$dateEnding = (date('Y') + 1) . date('-m-d');

if (isset($_SESSION["hijri"]) && !empty($_SESSION["hijri"])) {
	$sessionDate = new DateTime($_SESSION["hijri"]);
	$sessionDate = $sessionDate->format('Y-m-d');
	$dtAry = explode("-", $sessionDate);
	$dateEnding = ($dtAry[0] + 1) . '-' . $dtAry[1] . '-' . $dtAry[2];
}
?>

<div id="dmcPageContent" dir="rtl" class="p-2">

	<!-- Filter Card -->
	<div class="card border-0 shadow-sm rounded-4 overflow-hidden mb-4">
		<div class="card-header bg-success bg-opacity-10 border-0 py-3 px-4">
			<h5 class="mb-0 fw-bold text-success d-flex align-items-center justify-content-start urdu-regular fs-4">
				<i class="bi bi-file-earmark-text-fill ms-2"></i> کشف الدرجات (DMC) فارم
			</h5>
		</div>
		<div class="card-body p-4 bg-white">
			<div class="row g-4 text-end">

				<!-- Darja -->
				<div class="col-md-3">
					<label class="form-label fw-bold urdu-regular fs-5" for="darja">درجہ منتخب کریں</label>
					<div class="input-group input-group-lg shadow-sm rounded-3 overflow-hidden" dir="ltr">
						<span class="input-group-text bg-light border-0 text-success"><i
								class="bi bi-journal-bookmark"></i></span>
						<?php $crud->darjaatCmb('darja', '', 'form-select border-0 text-end urdu-regular'); ?>
					</div>
				</div>

				<!-- Date Start -->
				<div class="col-md-3">
					<label class="form-label fw-bold urdu-regular fs-5" for="promotionDate">تاریخ ابتداء</label>
					<div class="input-group input-group-lg shadow-sm rounded-3 overflow-hidden" dir="ltr">
						<span class="input-group-text bg-light border-0 text-success"><i
								class="bi bi-calendar-event"></i></span>
						<input type="text" id="promotionDate" class="form-control border-0 text-end hijri-picker"
							value="<?php echo $sessionDate; ?>" readonly>
					</div>
				</div>

				<!-- Date End -->
				<div class="col-md-3">
					<label class="form-label fw-bold urdu-regular fs-5" for="dateEnd">تاریخ انتہاء</label>
					<div class="input-group input-group-lg shadow-sm rounded-3 overflow-hidden" dir="ltr">
						<span class="input-group-text bg-light border-0 text-success"><i
								class="bi bi-calendar-check"></i></span>
						<input type="text" id="dateEnd" class="form-control border-0 text-end hijri-picker"
							value="<?php echo $dateEnding; ?>" readonly>
					</div>
				</div>

				<!-- Student Selection -->
				<div class="col-md-3">
					<label class="form-label fw-bold urdu-regular fs-5" for="regSno">طالب العلم</label>
					<div class="input-group input-group-lg shadow-sm rounded-3 overflow-hidden" dir="ltr">
						<span class="input-group-text bg-light border-0 text-success"><i
								class="bi bi-person-badge"></i></span>
						<select id="regSno" class="form-select border-0 text-end urdu-regular">
							<option value="">پہلے درجہ منتخب کریں</option>
						</select>
					</div>
				</div>
			</div>

			<!-- Action Buttons -->
			<div class="row mt-4">
				<div class="col-12 d-flex justify-content-between align-items-center">
					<div class="urdu-regular">
						<a href="dmcFrmSingleStdAll" class="text-decoration-none text-muted small">
							<i class="bi bi-info-circle ms-1"></i> ہر درجہ کی مکمل ڈی۔ایم۔سی کے لئے یہاں کلک کریں
						</a>
					</div>
					<button type="button" id="btnSearch"
						class="btn btn-success px-5 py-2 rounded-3 urdu-regular fs-5 shadow-sm">
						<i class="bi bi-search ms-2"></i> تلاش کریں
					</button>
				</div>
			</div>
		</div>
	</div>

	<!-- Results Container -->
	<div id="dmc-results" class="mt-2 text-end"></div>

</div>

<style>
	#dmcPageContent .input-group {
		flex-direction: row-reverse;
	}

	#dmcPageContent .form-select {
		background-position: left 0.75rem center;
		padding-left: 2.5rem;
		padding-right: 1rem;
	}

	#dmcPageContent .card {
		border: 1px solid rgba(25, 135, 84, 0.08) !important;
	}

	/* Urdu typography adjustment */
	.urdu-regular {
		font-family: 'Jameel Noori Nastaleeq', 'Noto Nastaliq Urdu', serif;
	}

	@media print {
		.no-print {
			display: none !important;
		}
	}
</style>

<!-- Page Specific JS -->
<script src="assets/js/dmc_frm.js"></script>