<?php
require_once('includes/auth_check.php');
include_once('includes/header.php');
include_once('includes/sidebar.php');

?>

<main>
    <div class="container-fluid px-4">
        <h1 class="mt-4">Dashboard</h1>
        <ol class="breadcrumb mb-4">
            <li class="breadcrumb-item active">Dashboard</li>
        </ol>
        <!-- class crud oparation start  -->
        <div class="row g-6">

            <div class="col-md-4  ">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-white py-3">
                        <h6 class="m-0 fw-bold text-primary">Add New classes</h6>
                    </div>

                    <div class="card-body">
                        <form>
                            <label class="my-2 fw-bold">Class Name</label>
                            <input type="text" id="class_name" class="form-control"
                                placeholder="Example: Class 1, Class 2, Class 8">


                            <button onclick="addClass()" class=" my-3 btn btn-outline-success px-3 py-1 rounded-1"
                                type="button">Add
                                Class</button>

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

            <div class="col-md-8 ">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
                        <h6 class="m-0 fw-bold text-dark">Existing Classes </h6>
                        <div class="input-group input-group-sm" style="width: 250px;">
                            <span class="input-group-text bg-light border-end-0"><i class="bi bi-search"></i></span>
                            <input type="text" id="searchBox" placeholder="Search class..." onkeyup="filterTable()"
                                class="form-control bg-light border-start-0 shadow-none">

                        </div>
                    </div>
                    <div class="card-body">
                     <div class=" table-responsive">
                         <table class="table table-hover align-middle mb-0">
                            <thead>
                                <tr>
                                    <th scope="col">Class Name</th>
                                    <th scope="col">Class Edit</th>
                                    <th scope="col">Class Delete</th>
                                    <th scope="col">Class status</th>
                                </tr>
                            </thead>
                            <tbody id="classTable">
                            </tbody>
                        </table>
                     </div>
                        <!-- pagination  -->
                        <div>
                            <button onclick="prevPage()" class="badge text-bg-light border-1">Prev</button>
                            <span id="pageInfo"></span>
                            <button onclick="nextPage()" class="badge text-bg-light border-1">Next</button>

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

            </div>
        </div>



    </div>
    <!--======== add section ui ========== -->
    <div class="container-fluid py-4">
        <div class="row g-4">
            <div class="col-md-4">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-white py-3">
                        <h6 class="m-0 fw-bold text-primary">Add New Section</h6>
                    </div>
                    <div class="card-body">
                        <form id="sectionForm">
                            <div class="mb-3">
                                <label class="form-label small fw-bold">Select Class</label>
                                <select id="class_dropdown" name="class_id" class="form-select" required>
                                    <option value="">-- Choose Class --</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label class="form-label small fw-bold">Section Name</label>
                                <input type="text" id="section_name" name="section_name" class="form-control"
                                    placeholder="e.g. Section A" required>
                            </div>
                            <div class="mb-3">
                                <label class="form-label small fw-bold">Status</label>
                                <select id="status" name="status" class="form-select">
                                    <option value="active">Active</option>
                                    <option value="inactive">Inactive</option>
                                </select>
                            </div>
                            <button type="submit" id="saveBtn" class="btn btn-primary w-100 fw-bold">
                                Save Section
                            </button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="col-md-8">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
                        <h6 class="m-0 fw-bold text-dark">Existing Sections</h6>
                        <div class="input-group input-group-sm" style="width: 250px;">
                            <span class="input-group-text bg-light border-end-0"><i class="bi bi-search"></i></span>
                            <input type="text" id="tableSearch" class="form-control bg-light border-start-0 shadow-none"
                                placeholder="Search sections...">
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-hover align-middle mb-0" id="sectionTable">
                            <thead class="table-light">
                                <tr>
                                    <th class="ps-3">Class</th>
                                    <th>Section</th>
                                    <th>Status</th>
                                    <th class="text-end pe-3">Actions</th>
                                </tr>
                            </thead>
                            <tbody id="sectionTableBody">
                            </tbody>
                        </table>
                    </div>
                    <div class="card-footer bg-white border-0 py-3">
                        <nav class="d-flex justify-content-between align-items-center">
                            <span class="small text-muted" id="pageInfoSection"></span>

                            <ul class="pagination pagination-sm m-0" id="paginationControls">
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="toast-container position-fixed bottom-0 end-0 p-3">
        <div id="successToast" class="toast align-items-center text-white bg-success border-0" role="alert"
            aria-live="assertive" aria-atomic="true">
            <div class="d-flex">
                <div class="toast-body">
                    <i class="bi bi-check-circle-fill me-2"></i> Section saved successfully!
                </div>
                <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
            </div>
        </div>
    </div>
</main>






<!--================ section edit modal ================= -->
<div class="modal fade" id="editSectionModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Edit Section</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="editSectionForm">
                <div class="modal-body">
                    <input type="hidden" name="id" id="edit_id">
                    <div class="mb-3">
                        <label class="form-label">Class</label>
                        <select name="class_id" id="edit_section_class_id" class="form-select" required>
                            <option value="">Loading classes...</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Section Name</label>
                        <input type="text" name="section_name" id="edit_section_name" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Status</label>
                        <select name="status" id="edit_status" class="form-control">
                            <option value="active">Active</option>
                            <option value="inactive">Inactive</option>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary">Update Section</button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="toast-container position-fixed top-0 end-0 p-3" style="z-index: 1080;">
    <div id="liveToast" class="toast align-items-center text-white border-0" role="alert" aria-live="assertive"
        aria-atomic="true">
        <div class="d-flex">
            <div class="toast-body">
                <strong id="toastTitle" class="me-auto"></strong>
                <div id="toastMessage"></div>
            </div>
            <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"
                aria-label="Close"></button>
        </div>
    </div>
</div>
<?php include_once('includes/footer.php') ?>