<?php $__env->startSection('title', 'All Instructors'); ?>
<?php $__env->startSection('breadcrumb'); ?>
    <div class="section-header-breadcrumb">
        <div class="breadcrumb-item active"><a href="<?php echo e(route('admin.dashboard')); ?>">Dashboard</a></div>
        <div class="breadcrumb-item">Instructors</div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('main-content'); ?>
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <form method="GET" action="<?php echo e(route('admin.instructors.index')); ?>">
                                <?php if(request('status')): ?>
                                    <input type="hidden" name="status" value="<?php echo e(request('status')); ?>">
                                <?php endif; ?>
                                <div class="input-group">
                                    <input type="text" class="form-control" name="search"
                                        placeholder="Search instructors..." value="<?php echo e(request('search')); ?>">
                                    <div class="input-group-btn">
                                        <button class="btn btn-primary" type="submit">
                                            <i class="fas fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="col-md-4">
                            <form method="GET" action="<?php echo e(route('admin.instructors.index')); ?>">
                                <?php if(request('search')): ?>
                                    <input type="hidden" name="search" value="<?php echo e(request('search')); ?>">
                                <?php endif; ?>
                                <select class="form-control" name="status" onchange="this.form.submit()">
                                    <option value="">All Status</option>
                                    <option value="approved" <?php echo e(request('status') == 'approved' ? 'selected' : ''); ?>>
                                        Approved</option>
                                    <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pending
                                    </option>
                                    <option value="rejected" <?php echo e(request('status') == 'rejected' ? 'selected' : ''); ?>>
                                        Rejected</option>
                                </select>
                            </form>
                        </div>
                        <div class="col-md-4 text-right">
                            <span class="badge badge-info">Total: <?php echo e($instructors->total()); ?> instructors</span>
                            <?php if($pendingCount > 0): ?>
                                <a href="<?php echo e(route('admin.instructors.index')); ?>?status=pending"
                                    class="badge badge-warning">
                                    Pending: <?php echo e($pendingCount); ?>

                                </a>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="table-responsive">
                        <table class="table table-striped" id="instructors-table">
                            <thead>
                                <tr>
                                    <th>Instructor</th>
                                    <th>Specialization</th>
                                    <th>Status</th>
                                    <th>Courses</th>
                                    <th>Enrollments</th>
                                    <th>Created</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $instructors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $instructor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                <?php if($instructor->profile_photo): ?>
                                                    <img src="<?php echo e(asset('storage/' . $instructor->profile_photo)); ?>"
                                                        alt="<?php echo e($instructor->name); ?>" class="mr-3 rounded-circle"
                                                        style="width: 50px; height: 50px; object-fit: cover;">
                                                <?php else: ?>
                                                    <div class="mr-3 bg-secondary rounded-circle d-flex align-items-center justify-content-center"
                                                        style="width: 50px; height: 50px;">
                                                        <i class="fas fa-user text-white"></i>
                                                    </div>
                                                <?php endif; ?>
                                                <div>
                                                    <h6 class="mb-0"><?php echo e($instructor->name); ?></h6>
                                                    <small class="text-muted"><?php echo e($instructor->email); ?></small>
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <?php echo e($instructor->specialization ?? 'N/A'); ?>

                                        </td>
                                        <td>
                                            <?php if($instructor->is_approved): ?>
                                                <span class="badge badge-success">Approved</span>
                                            <?php elseif($instructor->rejection_reason): ?>
                                                <span class="badge badge-danger">Rejected</span>
                                            <?php else: ?>
                                                <span class="badge badge-warning">Pending</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <span class="badge badge-info"><?php echo e($instructor->courses_count); ?></span>
                                        </td>
                                        <td>
                                            <span
                                                class="badge badge-primary"><?php echo e($instructor->total_enrollments ?? 0); ?></span>
                                        </td>
                                        <td>
                                            <small><?php echo e($instructor->created_at->format('M d, Y')); ?></small>
                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                <?php if(!$instructor->is_approved && !$instructor->rejection_reason): ?>
                                                    <button type="button"
                                                        class="btn btn-sm btn-success approve-instructor-btn"
                                                        data-instructor-id="<?php echo e($instructor->id); ?>"
                                                        data-instructor-name="<?php echo e($instructor->name); ?>" title="Approve">
                                                        <i class="fas fa-check"></i>
                                                    </button>
                                                    <button type="button"
                                                        class="btn btn-sm btn-warning reject-instructor-btn"
                                                        data-instructor-id="<?php echo e($instructor->id); ?>"
                                                        data-instructor-name="<?php echo e($instructor->name); ?>" title="Reject">
                                                        <i class="fas fa-times"></i>
                                                    </button>
                                                <?php endif; ?>
                                                <?php if($instructor->is_approved): ?>
                                                    <form
                                                        action="<?php echo e(route('admin.impersonate.instructor', $instructor->id)); ?>"
                                                        method="POST" class="d-inline">
                                                        <?php echo csrf_field(); ?>
                                                        <button type="submit" class="btn btn-sm btn-primary"
                                                            title="Login as Instructor">
                                                            <i class="fas fa-user-secret"></i>
                                                        </button>
                                                    </form>
                                                <?php endif; ?>
                                                <a href="<?php echo e(route('admin.instructors.edit', $instructor->id)); ?>"
                                                    class="btn btn-sm btn-warning" title="Edit">
                                                    <i class="fas fa-edit"></i>
                                                </a>
                                                <a href="<?php echo e(route('admin.instructors.show', $instructor->id)); ?>"
                                                    class="btn btn-sm btn-info" title="View">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="7" class="text-center">
                                            <div class="py-4">
                                                <i class="fas fa-user-tie fa-3x text-muted mb-3"></i>
                                                <p class="text-muted">No instructors found.</p>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>

                    <div class="mt-3 d-flex justify-content-between align-items-center">
                        <div>
                            <p class="text-muted mb-0">
                                Showing <?php echo e($instructors->firstItem() ?? 0); ?> to <?php echo e($instructors->lastItem() ?? 0); ?> of
                                <?php echo e($instructors->total()); ?> instructors
                            </p>
                        </div>
                        <div>
                            <?php echo e($instructors->links('vendor.pagination.stisla-default')); ?>

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

    <?php $__env->startPush('scripts'); ?>
        <script>
            $(document).ready(function() {
                $(document).on('click', '.approve-instructor-btn', function() {
                    const instructorId = $(this).data('instructor-id');
                    const instructorName = $(this).data('instructor-name');

                    Swal.fire({
                        title: 'Approve Instructor',
                        html: `
                <p>Are you sure you want to approve this instructor?</p>
                <p><strong>${instructorName}</strong></p>
                <textarea id="approve-reason" class="swal2-textarea" placeholder="Enter approval reason (optional)" style="width: 100%; min-height: 100px; margin-top: 10px;"></textarea>
            `,
                        icon: 'question',
                        showCancelButton: true,
                        confirmButtonColor: '#28a745',
                        cancelButtonColor: '#6c757d',
                        confirmButtonText: '<i class="fas fa-check"></i> Approve',
                        cancelButtonText: '<i class="fas fa-times"></i> Cancel',
                        preConfirm: () => {
                            return {
                                reason: document.getElementById('approve-reason').value
                            };
                        }
                    }).then((result) => {
                        if (result.isConfirmed) {
                            const reason = result.value.reason;

                            const form = $('<form>', {
                                'method': 'POST',
                                'action': '<?php echo e(route('admin.instructors.approve', ':id')); ?>'
                                    .replace(':id', instructorId)
                            });

                            form.append($('<input>', {
                                'type': 'hidden',
                                'name': '_token',
                                'value': '<?php echo e(csrf_token()); ?>'
                            }));

                            if (reason) {
                                form.append($('<input>', {
                                    'type': 'hidden',
                                    'name': 'reason',
                                    'value': reason
                                }));
                            }

                            $('body').append(form);
                            form.submit();
                        }
                    });
                });

                $(document).on('click', '.reject-instructor-btn', function() {
                    const instructorId = $(this).data('instructor-id');
                    const instructorName = $(this).data('instructor-name');

                    Swal.fire({
                        title: 'Reject Instructor',
                        html: `
                <p>Are you sure you want to reject this instructor application?</p>
                <p><strong>${instructorName}</strong></p>
                <textarea id="reject-reason" class="swal2-textarea" placeholder="Enter rejection reason (optional)" style="width: 100%; min-height: 100px; margin-top: 10px;"></textarea>
            `,
                        icon: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#ffc107',
                        cancelButtonColor: '#6c757d',
                        confirmButtonText: '<i class="fas fa-times"></i> Reject',
                        cancelButtonText: '<i class="fas fa-arrow-left"></i> Cancel',
                        preConfirm: () => {
                            return {
                                reason: document.getElementById('reject-reason').value
                            };
                        }
                    }).then((result) => {
                        if (result.isConfirmed) {
                            const reason = result.value.reason;

                            const form = $('<form>', {
                                'method': 'POST',
                                'action': '<?php echo e(route('admin.instructors.reject', ':id')); ?>'
                                    .replace(':id', instructorId)
                            });

                            form.append($('<input>', {
                                'type': 'hidden',
                                'name': '_token',
                                'value': '<?php echo e(csrf_token()); ?>'
                            }));

                            if (reason) {
                                form.append($('<input>', {
                                    'type': 'hidden',
                                    'name': 'reason',
                                    'value': reason
                                }));
                            }

                            $('body').append(form);
                            form.submit();
                        }
                    });
                });
            });
        </script>
    <?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/mahmudul/Codecanyone/edu_ex_full/Eduex_laravel/resources/views/admin/instructors/index.blade.php ENDPATH**/ ?>