<?php
// $crud and session are available via index.php context
$sessionDate = date('Y-01-01');
$dateEnding = date('Y-12-31');

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="registeredStudentReportContent" dir="rtl" class="p-2">
    <!-- Filter Card -->
    <div class="card border-0 shadow-sm rounded-4 overflow-hidden mb-4 no-print">
        <div class="card-header bg-primary bg-opacity-10 border-0 py-3 px-4">
            <h5 class="mb-0 fw-bold text-primary d-flex align-items-center justify-content-start urdu-regular fs-4">
                <i class="bi bi-people-fill ms-2"></i> داخل شدہ طلباء کی لسٹ
            </h5>
        </div>
        <div class="card-body p-4 bg-white">
            <div class="row g-4 text-end">
                <!-- Darja -->
                <div class="col-md-4">
                    <label class="form-label fw-bold urdu-regular fs-5" for="rpt_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-primary"><i
                                class="bi bi-journal-bookmark"></i></span>
                        <?php $crud->darjaatCmb('rpt_darja', '', 'form-select border-0 text-end urdu-regular'); ?>
                    </div>
                </div>

                <!-- Date Start -->
                <div class="col-md-4">
                    <label class="form-label fw-bold urdu-regular fs-5" for="rpt_date_start">تاریخ ابتداء</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-primary"><i
                                class="bi bi-calendar-event"></i></span>
                        <input type="text" id="rpt_date_start" class="form-control border-0 text-end hijri-picker"
                            value="<?php echo $sessionDate; ?>" readonly>
                    </div>
                </div>

                <!-- Date End -->
                <div class="col-md-4">
                    <label class="form-label fw-bold urdu-regular fs-5" for="rpt_date_end">تاریخ انتہاء</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-primary"><i
                                class="bi bi-calendar-check"></i></span>
                        <input type="text" id="rpt_date_end" class="form-control border-0 text-end hijri-picker"
                            value="<?php echo $dateEnding; ?>" readonly>
                    </div>
                </div>
            </div>

            <!-- Action Buttons -->
            <div class="row mt-4">
                <div class="col-12 d-flex justify-content-end gap-3">
                    <button type="button" id="btnPrintReport"
                        class="btn btn-outline-secondary px-4 py-2 rounded-3 urdu-regular fs-5 d-none">
                        <i class="bi bi-printer ms-2"></i> پرنٹ
                    </button>
                    <button type="button" id="btnShowReport"
                        class="btn btn-primary px-5 py-2 rounded-3 urdu-regular fs-5">
                        <i class="bi bi-search ms-2"></i> تلاش کریں
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Results Container -->
    <div id="rpt-results" class="mt-2 text-center">
        <div class="py-5 text-muted urdu-regular fs-5">
            داخل شدہ طلباء کی لسٹ دیکھنے کے لیے اوپر دی گئی معلومات درج کر کے "تلاش کریں" پر کلک کریں۔
        </div>
    </div>
</div>

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

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

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

<script src="assets/js/registered_student_report.js"></script>