<?php $__env->startSection('content'); ?>

    <div class="content-wrapper">
        <!-- Content -->
        <div class="container-xxl flex-grow-1 container-p-y">
            <h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light">List of All /</span> Enrollments </h4>
            
            <div class="row table-controls mb-2">
                <div class="col-md-2">
                    <label for="entries">Show Per Page</label>
                    <select id="entries" class="form-select">
                        <option value="10">10</option>
                        <option value="25">25</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
                    </select>
                </div>
                <div class="col-md-7"></div>
                <div class="col-md-3">
                    <label for="entries">Search</label>
                    <input type="text" class="form-control" id="search" placeholder="Search Here...">
                </div>
            </div>

            <div class="card">
                <div class="table-responsive text-nowrap">
                    <table class="table" id="myDataTable" style="max-width: 100%">
                        <thead>
                            <tr>
                                <th>Branch Manager</th>
                                <th>Subscription</th>
                                <th>Subscriber</th>
                                <th>Benificiary</th>
                                <th>Dealing Rep</th>
                                <th>Trusted</th>
                                <th>Manager Review</th>
                                <?php if(Auth::user()->role == 'admin'): ?>
                                    <th>Company Review</th>
                                <?php endif; ?>
                                <th>Status</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody class="table-border-bottom-0">
                            <?php if($enrollments->isNotEmpty()): ?>
                                <?php $__currentLoopData = $enrollments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k => $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e(ucfirst($e->manager->name)); ?></td>
                                        <td><?php echo e(ucfirst($e->subscription_type)); ?></td>
                                        <td><?php echo e(ucfirst($e->subscription_fname . ' ' . $e->subscription_lname)); ?></td>
                                        <td><?php echo e(ucfirst($e->benificiary_fname . ' ' . $e->benificiary_lname)); ?></td>
                                        <td><?php echo e(ucfirst($e->dealing_rep_name)); ?></td>
                                        <td><?php echo e(ucfirst($e->trusted_name)); ?></td>
                                        <td><?php echo e(ucfirst($e->is_branch_review)); ?></td>
                                        <?php if(Auth::user()->role == 'admin'): ?>
                                            <td><?php echo e(ucfirst($e->is_admin_review)); ?></td>
                                            <td>
                                                <?php if($e->is_admin_review != 'approved'): ?>
                                                    <button type="button" class="btn btn-primary status_btn"
                                                        data-bs-toggle="modal" data-bs-target="#modalStatus"
                                                        data-id="<?php echo e($e->id); ?>">
                                                        CHANGE
                                                    </button>
                                                <?php else: ?>
                                                    <p class="text-primary">Approved</p>
                                                <?php endif; ?>
                                            </td>
                                        <?php endif; ?>

                                        <?php if(Auth::user()->role !== 'admin'): ?>
                                        <td>
                                            <?php if($e->is_branch_review != 'approved'): ?>
                                                <button type="button" class="btn btn-primary status_btn"
                                                    data-bs-toggle="modal" data-bs-target="#modalStatus"
                                                    data-id="<?php echo e($e->id); ?>">
                                                    CHANGE
                                                </button>
                                            <?php else: ?>
                                                <p class="text-primary">Approved</p>
                                            <?php endif; ?>
                                        </td>
                                        <?php endif; ?>

                                        <td>
                                            <a class="btn btn-success p-1" href="<?php echo e(route('admin.enrollmentHistory', $e->id)); ?>" title="View History"><i
                                                    class="bx bx-show-alt me-1"></i></a>
                                            <a class="btn btn-primary p-1" href="<?php echo e(route('admin.enrollDetail')); ?>" title="View Pdf"><i
                                                    class="bx bx-file me-1"></i></a>
                                            <a class="btn btn-danger p-1" title="Delete"
                                                href="<?php echo e(route('admin.enrollmentDelete', $e->id)); ?>"
                                                onclick="return confirm('Are you sure you want to delete this item?');">
                                                <i class="bx bx-trash me-1"></i>
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php else: ?>
                                <tr>
                                    <td class="text-center text-danger" colspan="9">No data found.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>

                </div>

            </div>

        </div>
    </div>


    
    <div class="modal fade" id="modalStatus" tabindex="-1" style="display: none;" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalCenterTitle">Change Enrollment Status</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form action="<?php echo e(route('admin.changeStatus')); ?>" method="post" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="id" class="enroll_id" />
                        <div class="row">
                            <div class="col mb-3">
                                <label for="exampleFormControlSelect1" class="form-label">Update Status</label>
                                <select class="form-select" name="status" id="statusSelect">
                                    <option selected="">Select Status</option>
                                    <option value="approved">Approved</option>
                                    
                                    <?php if(Auth::user()->role == 'manager'): ?>
                                        <option value="reject">Reject</option>
                                    <?php endif; ?>
                                </select>
                                <?php if(Auth::user()->role == 'manager'): ?>
                                    <div class="mt-2" id="noteDiv">
                                        <label>Note</label>
                                        <textarea class="form-control" name="note" placeholder="Add Note"></textarea>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                        <input type="submit" class="btn btn-primary" value="Save changes">
                    </form>
                </div>
            </div>
        </div>
    </div>

    <?php $__env->startPush('scripts'); ?>
        <script>
            $(document).ready(function() {
                $('.status_btn').click(function() {
                    var id = $(this).data('id');
                    $('.enroll_id').val(id);
                })
            });
        </script>

        <script>
            document.addEventListener("DOMContentLoaded", function() {
                // Get the select element and note div
                var statusSelect = document.getElementById("statusSelect");
                var noteDiv = document.getElementById("noteDiv");
                var noteTextarea = document.querySelector("#noteDiv textarea[name='note']");

                // Initially hide the note div
                noteDiv.style.display = "none";

                // Add an event listener to the select element
                statusSelect.addEventListener("change", function() {
                    if (statusSelect.value === "reject") {
                        // Show the note div if "Reject" is selected
                        noteTextarea.setAttribute("required", "required");
                        noteDiv.style.display = "block";
                    } else {
                        // Hide the note div for other options
                        noteTextarea.removeAttribute("required");
                        noteDiv.style.display = "none";
                    }
                });
            });
        </script>
    <?php $__env->stopPush(); ?>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/netmente/Desktop/Alefi/resources/views/admin/enrollment/index.blade.php ENDPATH**/ ?>