<?php
// defaulters_list.php
?>
<link rel="stylesheet" href="assets/css/accounts.css">

<div id="defaultersModule" dir="rtl" class="container-fluid py-4">
    <!-- Header -->
    <div class="d-flex flex-wrap justify-content-between align-items-center mb-4 gap-2">
        <div>
            <h2 class="fw-bold text-danger urdu-bold mb-1">
                <i class="bi bi-exclamation-triangle-fill me-2"></i>بقایا جات کی فہرست (Defaulters List)
            </h2>
            <p class="text-muted urdu-regular fs-5">وہ طلباء جنہوں نے ابھی تک فیس جمع نہیں کرائی</p>
        </div>
        <div class="d-flex gap-2">
            <a href="fee_collection" class="btn btn-success px-3 py-2 rounded-3 urdu-regular fs-5">
                <i class="bi bi-cash-coin me-1 px-2"></i> فیس وصول کریں
            </a>
            <a href="fee_dashboard" class="btn btn-outline-dark px-3 py-2 rounded-3 urdu-regular fs-5">
                <i class="bi bi-arrow-right me-1 px-2"></i> واپس
            </a>
        </div>
    </div>

    <!-- Filters Row -->
    <div class="card border-0 shadow-sm rounded-4 mb-4">
        <div class="card-body p-3">
            <div class="row g-3 align-items-end">
                <!-- Search -->
                <div class="col-md-4">
                    <label class="form-label urdu-regular fw-bold">تلاش کریں (Search)</label>
                    <div class="input-group">
                        <input type="text" class="form-control" id="searchInput"
                            placeholder="نام / والد کا نام / رجسٹریشن نمبر">
                        <button class="btn btn-outline-secondary" type="button" id="btnClearSearch" title="Clear">
                            <i class="bi bi-x-lg"></i>
                        </button>
                    </div>
                </div>
                <!-- Darja -->
                <div class="col-md-3 col-6">
                    <label class="form-label urdu-regular fw-bold">درجہ (Class)</label>
                    <?php $crud->darjaatCmb('filterDarja', 'class="form-select" id="filterDarja"'); ?>
                </div>
                <!-- Month -->
                <div class="col-md-2 col-6">
                    <label class="form-label urdu-regular fw-bold">مہینہ (Month)</label>
                    <select class="form-select" id="filterMonth">
                        <option value="1">جنوری (January)</option>
                        <option value="2">فروری (February)</option>
                        <option value="3">مارچ (March)</option>
                        <option value="4">اپریل (April)</option>
                        <option value="5">مئی (May)</option>
                        <option value="6">جون (June)</option>
                        <option value="7">جولائی (July)</option>
                        <option value="8">اگست (August)</option>
                        <option value="9">ستمبر (September)</option>
                        <option value="10">اکتوبر (October)</option>
                        <option value="11">نومبر (November)</option>
                        <option value="12">دسمبر (December)</option>
                    </select>
                </div>
                <!-- Year -->
                <div class="col-md-2 col-6">
                    <label class="form-label urdu-regular fw-bold">سال (Year)</label>
                    <select class="form-select" id="filterYear">
                        <?php
                        $currentYear = (int) date('Y');
                        for ($y = $currentYear; $y >= $currentYear - 5; $y--) {
                            echo "<option value=\"$y\">$y</option>";
                        }
                        ?>
                    </select>
                </div>
                <!-- Count Badge -->
                <div class="col-md-3 text-center">
                    <div class="bg-danger bg-opacity-10 rounded-3 p-2">
                        <span class="urdu-regular fs-5">بقایا طلباء:</span>
                        <span class="badge bg-danger fs-5 ms-2" id="defaultersCount">0</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Defaulters Table -->
    <div class="card border-0 shadow-sm rounded-4 overflow-hidden">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-danger-subtle urdu-bold">
                        <tr>
                            <th class="px-3 py-3 text-center" style="width:50px;">#</th>
                            <th class="py-3">طالب علم (Student)</th>
                            <th class="py-3">درجہ (Class)</th>
                            <th class="py-3">فیس کی قسم (Fee Type)</th>
                            <th class="py-3">مہینہ (Due Month)</th>
                            <th class="py-3 text-danger">رقم (Amount)</th>
                            <th class="py-3">واجب الادا تاریخ (Due)</th>
                            <th class="px-3 py-3 text-center" style="min-width:160px;">ایکشن (Action)</th>
                        </tr>
                    </thead>
                    <tbody id="defaultersTableBody">
                        <tr>
                            <td colspan="7" class="text-center py-5 text-muted urdu-regular fs-4">لوڈ ہو رہا ہے...</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- Collect Fee Modal -->
<div class="modal fade" id="payDuesModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered" dir="rtl">
        <div class="modal-content rounded-4 border-0 shadow">
            <div class="modal-header bg-light border-bottom-0 pb-0">
                <h5 class="modal-title urdu-bold">فیس وصول کریں (Collect Fee)</h5>
                <button type="button" class="btn-close m-0 ms-auto" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4 pt-3 text-end">
                <form id="payDuesForm">
                    <input type="hidden" id="pay_std_id">
                    <input type="hidden" id="pay_fee_type_id">
                    <input type="hidden" id="pay_month_year">

                    <div class="mb-3">
                        <label class="form-label urdu-bold small text-muted mb-1">طالب علم (Student)</label>
                        <input type="text" class="form-control bg-light border-0 fw-bold fs-5 text-end"
                            id="pay_std_name" readonly>
                    </div>

                    <div class="row mb-3">
                        <div class="col-6">
                            <label class="form-label urdu-bold small text-muted mb-1">فیس (Type)</label>
                            <input type="text" class="form-control bg-light border-0 text-end" id="pay_fee_name"
                                readonly>
                        </div>
                        <div class="col-6">
                            <label class="form-label urdu-bold small text-muted mb-1">ماہ / سال (Period)</label>
                            <input type="text" class="form-control bg-light border-0 text-end" id="pay_period_label"
                                readonly>
                        </div>
                    </div>

                    <hr class="my-4 opacity-10">

                    <div class="mb-3">
                        <label class="form-label urdu-bold">رقم (Amount) <span class="text-danger">*</span></label>
                        <input type="number" step="0.01"
                            class="form-control form-control-lg font-monospace fs-4 border-2 border-danger-subtle text-end"
                            id="pay_amount" required>
                    </div>

                    <div class="row mb-3">
                        <div class="col-6">
                            <label class="form-label urdu-regular">تاریخ (Date)</label>
                            <input type="text" class="form-control hijri-picker" id="pay_date"
                                value="<?php echo date('Y-m-d'); ?>" readonly required>
                        </div>
                        <div class="col-6">
                            <label class="form-label urdu-regular">طریقہ (Method)</label>
                            <select class="form-select" id="pay_method" required>
                                <option value="Cash">Cash (نقد)</option>
                                <option value="Bank">Bank (بینک)</option>
                            </select>
                        </div>
                    </div>

                    <div class="mb-4">
                        <label class="form-label urdu-regular">حوالہ نمبر (Reference)</label>
                        <input type="text" class="form-control" id="pay_ref" placeholder="Optional">
                    </div>

                    <button type="submit" class="btn btn-success w-100 py-3 urdu-bold rounded-3 fs-5 shadow"
                        id="btnSubmitPayment">
                        <i class="bi bi-check-circle me-2"></i> وصولی مکمل کریں (Submit Payment)
                    </button>
                    <div class="text-center mt-3 urdu-regular text-muted small">
                        فیس وصول کرنے پر خود بخود رسید تیار ہو جائے گی
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

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