<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
    <div class="card">

        <div class="card-header">
            <div class="row align-items-center">
                <div class="col">
                    <h5 class="mb-0">Course Enrollments</h5>
                    <small class="text-muted">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(auth()->user()->hasRole('teacher')): ?>
                            Enrolled Students (Only Name + Student ID)
                        <?php elseif(auth()->user()->hasRole('student')): ?>
                            My Courses
                        <?php else: ?>
                            All Enrollments
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </small>
                </div>

                <div class="col-auto">
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('course_enrollments create')): ?>
                        <a href="<?php echo e(route('course-enrollments.create')); ?>" class="btn btn-primary btn-sm">
                            + New Enrollment
                        </a>
                    <?php endif; ?>
                </div>
            </div>
            <hr class="mb-0" />
        </div>

        <div class="card-body">
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('success')): ?>
                <div class="alert alert-success"><?php echo e(session('success')); ?></div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('error')): ?>
                <div class="alert alert-danger"><?php echo e(session('error')); ?></div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

            <div class="table-responsive">
                <table <?php if($enrollments->count() > 0): ?> id="bookings-table" <?php endif; ?> class="table table-bordered align-middle text-center">
                    <thead class="table-light">
                        <tr>
                            <th>#</th>
                            <th>Course</th>
                            <th>Category</th>
                            <th>Teacher</th>
                            <th>Student</th>
                            <th>Course Period</th>
                            <th>Enrolled At</th>
                            <th class="text-center">Action</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $enrollments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $enrollment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($enrollment->id); ?></td>
                                <td>
                                    <div class="fw-semibold"><?php echo e($enrollment->course->title ?? '-'); ?></div>
                                </td>
                                <td>
                                    <div class="text-muted small"><?php echo e($enrollment->course->category->name ?? '-'); ?></div>
                                </td>
                                <td><?php echo e($enrollment->course->teacher->name ?? '-'); ?></td>
                                <td>
                                    <div class="fw-semibold"><?php echo e($enrollment->student->name ?? '-'); ?></div>
                                </td>
                                <td>
                                    <div><?php echo e($enrollment->course->start_date?->format('Y-m-d') ?? 'N/A'); ?></div>
                                    <div class="text-muted small">
                                        to <?php echo e($enrollment->course->expire_date?->format('Y-m-d') ?? 'N/A'); ?>

                                    </div>
                                </td>
                                <td><?php echo e(optional($enrollment->enrolled_at)->format('Y-m-d H:i')); ?></td>
                                <td class="text-center">
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('course_enrollments update')): ?>
                                        <a href="<?php echo e(route('course-enrollments.edit', $enrollment->id)); ?>"
                                           class="btn btn-primary btn-sm">
                                            Edit
                                        </a>
                                    <?php endif; ?>

                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('course_enrollments delete')): ?>
                                        <form action="<?php echo e(route('course-enrollments.destroy', $enrollment->id)); ?>"
                                              method="POST"
                                              onsubmit="return confirm('Delete this enrollment?')"
                                              style="display:inline-block;">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button class="btn btn-danger btn-sm">
                                                Delete
                                            </button>
                                        </form>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="8" class="text-center text-muted">No enrollments found.</td>
                            </tr>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </tbody>

                </table>
            </div>

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

<?php $__env->startPush('script'); ?>
<script>
$(document).ready(function () {
    $('#bookings-table').DataTable({
        responsive: false,
        scrollX: true,
        pageLength: 10,
        lengthMenu: [5, 10, 25, 50, 100],
        order: [[0, 'desc']],
        columnDefs: [
            { orderable: false, targets: -1 }
        ]
    });
});
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xampp\htdocs\digitizing-academy.lifelinehealthcare.com.pk\resources\views/course_enrollments/index.blade.php ENDPATH**/ ?>