<!DOCTYPE html>
<html dir="ltr" lang="en">

<?php
include 'partial/head.php';
include 'partial/status.php';
?>

<body>
<!-- ============================================================== -->
<!-- Preloader - style you can find in spinners.css -->
<!-- ============================================================== -->
<div class="preloader">
    <div class="lds-ripple">
        <div class="lds-pos"></div>
        <div class="lds-pos"></div>
    </div>
</div>
<!-- ============================================================== -->
<!-- Main wrapper - style you can find in pages.scss -->
<!-- ============================================================== -->
<div id="main-wrapper" data-theme="light" data-layout="vertical" data-navbarbg="skin6" data-sidebartype="full"
     data-sidebar-position="fixed" data-header-position="fixed" data-boxed-layout="full">
    <!-- ============================================================== -->
    <!-- Topbar header - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <?php
    include 'partial/topbar.php';
    ?>
    <!-- ============================================================== -->
    <!-- End Topbar header -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- Left Sidebar - style you can find in sidebar.scss  -->
    <!-- ============================================================== -->
    <?php
    include 'partial/sidebar.php';
    ?>
    <!-- ============================================================== -->
    <!-- End Left Sidebar - style you can find in sidebar.scss  -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- Page wrapper  -->
    <!-- ============================================================== -->
    <div class="page-wrapper">
        <!-- ============================================================== -->
        <!-- Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <div class="page-breadcrumb">
            <div class="row">
                <div class="col-7 align-self-center">
                    <h2 class="page-title text-truncate text-dark font-weight-medium mb-1">Class Type</h2>
                    <div class="d-flex align-items-center">
                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb m-0 p-0">
                                <li class="breadcrumb-item"><a href="<?= base_url() ?>" class="text-muted">Home</a></li>
                                <li class="breadcrumb-item text-muted active" aria-current="page">Class Type</li>
                            </ol>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- Container fluid  -->
        <!-- ============================================================== -->

        <div class="container-fluid">
            <!-- ============================================================== -->
            <!-- Start Page Content -->
            <!-- ============================================================== -->
            <div class="row">
                <div class="col-sm-12 col-md-12 col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <form method="post" action="<?= base_url('classtype/save') ?>">
                                <div class="form-body">
                                    <div class="row">
                                        <?php
                                        include 'partial/alerts.php';
                                        ?>
                                        <div class="col-md-3">
                                            <div class="form-group mb-3">
                                                <label class="form-label">Class Type Code</label>
                                                <input type="text" class="form-control" placeholder="" id="code" name="code" style="text-transform: uppercase;" required>
                                            </div>
                                        </div>
                                        <div class="col-md-9">
                                            <div class="form-group mb-3">
                                                <label class="form-label">Class Type Name</label>
                                                <input type="text" class="form-control" placeholder="" id="name" name="name" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group mb-3">
                                                <label class="form-label">Description</label>
                                                <input type="text" class="form-control" placeholder="" id="description" name="description">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group mb-4">
                                                <label class="form-label">Status</label>
                                                <select class="form-select mr-sm-2" id="status" name="status" required>
                                                    <option value="1">Active</option>
                                                    <option value="2">Inactive</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-4">
                                            <button type="submit" class="btn btn-primary btn-rounded" style="width:100px;"><i class="fas fa-check"></i>
                                                Save</button>
                                            <button type="reset" class="btn btn-danger btn-rounded" style="width:100px;"><i class="fas fa-undo"></i>
                                                Reset</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title"></h4>
                            <h6 class="card-subtitle"></h6>
                            <div class="table-responsive">
                                <table id="zero_config" class="table border table-striped table-bordered text-nowrap">
                                    <thead>
                                    <tr>
                                        <th>Code</th>
                                        <th>Name</th>
                                        <th>Description</th>
                                        <th style="text-align: center">Status</th>
                                        <th style="text-align: center">Actions</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach($classTypes as $type): ?>

                                        <tr>
                                            <td><?= $type['code'] ?></td>
                                            <td><?= $type['name'] ?></td>
                                            <td><?= $type['description'] ?></td>
                                            <td style="text-align: center"><?= $statusMap[$type['status']] ?? 'Unknown' ?></td>
                                            <td style="text-align: center"><button id="btnUpdate" data-id="<?= $type['id'] ?>" data-bs-toggle="modal" data-bs-target="#bs-example-modal-lg" type="button" class="btn btn-secondary btn-circle" style="padding: 3px 3px; width: 30px; height: 30px;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top" ><i class="fa fa-pencil-alt"></i></button>
                                                <button id="btnDelete" data-id="<?= $type['id'] ?>" data-bs-toggle="modal" data-bs-target="#deleteModal" type="button" class="btn btn-danger btn-circle" style="padding: 3px 3px; width: 30px; height: 30px;"><i class="fa fa-trash"></i></button></td>
                                        </tr>

                                    <?php endforeach; ?>


                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- ============================================================== -->
    <!-- End Page wrapper  -->
    <!-- ============================================================== -->
</div>
<!-- ============================================================== -->
<!-- End Wrapper -->
<!-- ============================================================== -->
<!-- End Wrapper -->
<!-- ============================================================== -->
<!-- All Jquery -->
<!-- ============================================================== -->

<!--  update modal -->
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog"
     aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myLargeModalLabel">Update Class Type</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"
                        aria-hidden="true"></button>
            </div>
            <div class="modal-body">
                <form method="post" action="<?= base_url('classtype/update') ?>">
                    <div class="form-body">
                        <div class="row">
                            <!-- hidden id to update -->
                            <input type="hidden" class="form-control" placeholder="" id="updid" name="updid">
                            <div class="col-md-3">
                                <div class="form-group mb-3">
                                    <label class="form-label">Class Type Code</label>
                                    <input type="text" class="form-control" placeholder="" id="updcode" name="updcode" style="text-transform: uppercase;" required>
                                </div>
                            </div>
                            <div class="col-md-9">
                                <div class="form-group mb-3">
                                    <label class="form-label">Class Type Name</label>
                                    <input type="text" class="form-control" placeholder="" id="updname" name="updname" required>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group mb-3">
                                    <label class="form-label">Description</label>
                                    <input type="text" class="form-control" placeholder="" id="upddescription" name="upddescription">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group mb-4">
                                    <label class="form-label">Status</label>
                                    <select class="form-select mr-sm-2" id="updstatus" name="updstatus" required>
                                        <option value="1">Active</option>
                                        <option value="2">Inactive</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-8">
                                <button type="submit" class="btn btn-primary btn-rounded" style="width:130px;"><i class="fas fa-check"></i>
                                    Update</button>
                                <button data-bs-dismiss="modal" aria-hidden="true" type="button" class="btn btn-danger btn-rounded" style="width:130px;"><i class="fas fa-window-close"></i>
                                    Cancel</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--  delete modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog"
     aria-labelledby="deleteModal" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="deleteModal">Delete Class Type</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"
                        aria-hidden="true"></button>
            </div>
            <div class="modal-body">
                <form method="post" action="<?= base_url('classtype/delete') ?>">
                    <div class="form-body">
                        <div class="row">
                            <!-- hidden id to update -->
                            <input type="hidden" class="form-control" placeholder="" id="delid" name="delid">
                            <label class="form-label">Are you sure to delete this item?</label>
                        </div>
                        <div class="row">
                            <div class="col-md-8">
                                <button type="submit" class="btn btn-danger btn-rounded" style="width:130px;"><i class="fas fa-trash"></i>
                                    Delete</button>
                                <button data-bs-dismiss="modal" aria-hidden="true" type="button" class="btn btn-info btn-rounded" style="width:130px;"><i class="fas fa-window-close"></i>
                                    Cancel</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</body>

<?php
include 'partial/footer.php';
?>


<script>
    var base_url = "<?= base_url() ?>";
</script>

<script src="<?= base_url('dist/js/custom_v1.js') ?>"></script>
<script src="<?= base_url('dist/js/classType.js') ?>"></script>

</html>
