<div>
    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">

            <!-- Statistics Cards -->
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
                <div class="bg-white rounded-lg shadow p-6">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-blue-100">
                            <span class="text-blue-600 text-xl">👥</span>
                        </div>
                        <div class="ml-4">
                            <p class="text-sm font-medium text-gray-600">Total Eligible</p>
                            <p class="text-2xl font-bold text-gray-900"><?php echo e($stats['total_eligible']); ?></p>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-lg shadow p-6">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-green-100">
                            <span class="text-green-600 text-xl">✅</span>
                        </div>
                        <div class="ml-4">
                            <p class="text-sm font-medium text-gray-600">Assigned</p>
                            <p class="text-2xl font-bold text-gray-900"><?php echo e($stats['assigned']); ?></p>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-lg shadow p-6">
                    <div class="flex items-center">
                        <div class="p-3 rounded-full bg-yellow-100">
                            <span class="text-yellow-600 text-xl">⏳</span>
                        </div>
                        <div class="ml-4">
                            <p class="text-sm font-medium text-gray-600">Unassigned</p>
                            <p class="text-2xl font-bold text-gray-900"><?php echo e($stats['unassigned']); ?></p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Flash Messages -->
            <!--[if BLOCK]><![endif]--><?php if(session()->has('success')): ?>
                <div class="bg-green-50 border border-green-200 rounded-lg p-4 mb-6">
                    <p class="text-green-700"><?php echo e(session('success')); ?></p>
                </div>
            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

            <?php if(session()->has('error')): ?>
                <div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
                    <p class="text-red-700"><?php echo e(session('error')); ?></p>
                </div>
            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

            <!-- Main Content Card -->
            <div class="bg-white shadow rounded-lg">
                <!-- Header -->
                <div class="px-6 py-4 border-b border-gray-200">
                    <h2 class="text-lg font-medium text-gray-900">Students Requiring Supervisor Assignment</h2>
                </div>

                <!-- Bulk Actions Bar -->
                <!--[if BLOCK]><![endif]--><?php if(count($selectedStudents) > 0 || $isBulkAssigning): ?>
                    <div class="px-6 py-3 border-b border-gray-200 bg-blue-50">
                        <div class="flex items-center justify-between">
                            <div class="flex items-center space-x-4">
                                <span class="text-sm font-medium text-gray-700">
                                    <?php echo e(count($selectedStudents)); ?> student(s) selected
                                </span>
                                <!--[if BLOCK]><![endif]--><?php if($isBulkAssigning): ?>
                                    <div class="flex items-center space-x-2">
                                        <div class="w-48 bg-gray-200 rounded-full h-2">
                                            <div class="bg-blue-600 h-2 rounded-full transition-all duration-300"
                                                 style="width: <?php echo e($bulkAssignTotal > 0 ? ($bulkAssignProgress / $bulkAssignTotal * 100) : 0); ?>%"></div>
                                        </div>
                                        <span class="text-xs text-gray-600">
                                            <?php echo e($bulkAssignProgress); ?> / <?php echo e($bulkAssignTotal); ?>

                                        </span>
                                    </div>
                                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                            </div>
                            <div class="flex items-center space-x-2">
                                <button wire:click="clearSelection"
                                        class="px-3 py-1 text-sm text-gray-700 hover:text-gray-900">
                                    Clear Selection
                                </button>
                                <button wire:click="bulkAutoAssign"
                                        wire:loading.attr="disabled"
                                        wire:target="bulkAutoAssign"
                                        <?php if($isBulkAssigning): ?> disabled <?php endif; ?>
                                        class="px-4 py-2 bg-green-600 text-white text-sm font-medium rounded-md hover:bg-green-700 disabled:bg-gray-400 disabled:cursor-not-allowed">
                                    <span wire:loading.remove wire:target="bulkAutoAssign">Bulk Auto Assign</span>
                                    <span wire:loading wire:target="bulkAutoAssign">Assigning...</span>
                                </button>
                            </div>
                        </div>
                    </div>
                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

                <!-- Advanced Filters -->
                <div class="px-6 py-4 border-b border-gray-200 bg-gray-50">
                    <div class="grid grid-cols-1 md:grid-cols-6 gap-4">
                        <!-- Search -->
                        <div class="md:col-span-2">
                            <input type="text" wire:model.live.debounce.300ms="search"
                                class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm"
                                placeholder="Search by student ID, name, email, or company...">
                        </div>

                        <!-- Assignment Type Filter -->
                        <div>
                            <select wire:model.live="assignmentTypeFilter"
                                class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm">
                                <option value="unassigned">Unassigned Only</option>
                                <option value="assigned">Assigned Only</option>
                                <option value="all">All Students</option>
                            </select>
                        </div>

                        <!-- Semester Filter -->
                        <div>
                            <select wire:model.live="semesterFilter"
                                class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm">
                                <option value="">All Semesters</option>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $availableSemesters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $semester): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($semester); ?>">Semester <?php echo e($semester); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </select>
                        </div>

                        <!-- Year Filter -->
                        <div>
                            <select wire:model.live="yearFilter"
                                class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm">
                                <option value="">All Years</option>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $availableYears; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $year): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($year); ?>"><?php echo e($year); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </select>
                        </div>

                        <!-- Per Page -->
                        <div>
                            <select wire:model.live="perPage"
                                class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm">
                                <option value="10">10 per page</option>
                                <option value="25">25 per page</option>
                                <option value="50">50 per page</option>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- Students Table -->
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    <label class="flex items-center cursor-pointer">
                                        <?php
                                            // Only count unassigned students for select all
                                            $unassignedStudentIDs = $students->filter(function ($student) {
                                                return !$student->supervisorAssignment ||
                                                       $student->supervisorAssignment->status !== \App\Models\SupervisorAssignment::STATUS_ASSIGNED;
                                            })->pluck('studentID')->toArray();
                                            $selectedUnassigned = array_intersect($selectedStudents, $unassignedStudentIDs);
                                            $allUnassignedSelected = !empty($unassignedStudentIDs) &&
                                                count($selectedUnassigned) === count($unassignedStudentIDs);
                                        ?>
                                        <input type="checkbox"
                                               <?php if($allUnassignedSelected): ?> checked <?php endif; ?>
                                               wire:click="toggleSelectAll"
                                               class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                                        <span class="ml-2">Select</span>
                                    </label>
                                </th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer"
                                    wire:click="sortBy('studentID')">
                                    Student ID
                                    <!--[if BLOCK]><![endif]--><?php if($sortField === 'studentID'): ?>
                                        <!--[if BLOCK]><![endif]--><?php if($sortDirection === 'asc'): ?> ↑ <?php else: ?> ↓ <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                </th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    Student Name
                                </th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    Company
                                </th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    Supervisor
                                </th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider cursor-pointer"
                                    wire:click="sortBy('assigned_at')">
                                    Assigned Date
                                    <!--[if BLOCK]><![endif]--><?php if($sortField === 'assigned_at'): ?>
                                        <!--[if BLOCK]><![endif]--><?php if($sortDirection === 'asc'): ?> ↑ <?php else: ?> ↓ <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                </th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                    Actions
                                </th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <!--[if BLOCK]><![endif]--><?php $__empty_1 = true; $__currentLoopData = $students; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <?php
                                    $hasAssignment = $student->supervisorAssignment &&
                                                     $student->supervisorAssignment->status === \App\Models\SupervisorAssignment::STATUS_ASSIGNED;
                                    $canSelect = !$hasAssignment;
                                ?>
                                <tr class="hover:bg-gray-50 <?php echo e($this->isStudentSelected($student->studentID) ? 'bg-blue-50' : ''); ?> <?php echo e(!$canSelect ? 'opacity-60' : ''); ?>">
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <input type="checkbox"
                                               <?php if($this->isStudentSelected($student->studentID)): ?> checked <?php endif; ?>
                                               <?php if(!$canSelect): ?> disabled <?php endif; ?>
                                               wire:click="toggleStudentSelection('<?php echo e($student->studentID); ?>')"
                                               class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed"
                                               title="<?php echo e($canSelect ? 'Select for bulk auto-assignment' : 'Student already has a supervisor assigned'); ?>">
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                                        <?php echo e($student->studentID); ?>

                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <div class="text-sm font-medium text-gray-900"><?php echo e($student->user->name); ?></div>
                                        <div class="text-sm text-gray-500"><?php echo e($student->user->email); ?></div>
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <!--[if BLOCK]><![endif]--><?php if($student->acceptedPlacementApplication): ?>
                                            <div class="text-sm text-gray-900"><?php echo e($student->acceptedPlacementApplication->companyName); ?></div>
                                            <div class="text-sm text-gray-500"><?php echo e($student->acceptedPlacementApplication->companyCity); ?>, <?php echo e($student->acceptedPlacementApplication->companyState); ?></div>
                                        <?php else: ?>
                                            <span class="text-sm text-gray-400">N/A</span>
                                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <!--[if BLOCK]><![endif]--><?php if($student->supervisorAssignment && $student->supervisorAssignment->supervisor): ?>
                                            <div class="flex items-center">
                                                <div>
                                                    <div class="text-sm font-medium text-gray-900"><?php echo e($student->supervisorAssignment->supervisor->user->name); ?></div>
                                                    <div class="text-sm text-gray-500"><?php echo e($student->supervisorAssignment->supervisor->lecturerID); ?></div>
                                                    <!--[if BLOCK]><![endif]--><?php if($student->supervisorAssignment->distance_km): ?>
                                                        <div class="text-xs text-gray-400">Distance: <?php echo e(number_format($student->supervisorAssignment->distance_km, 2)); ?> km</div>
                                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                </div>
                                            </div>
                                        <?php else: ?>
                                            <span class="text-sm text-yellow-600 font-medium">Unassigned</span>
                                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                        <!--[if BLOCK]><![endif]--><?php if($student->supervisorAssignment): ?>
                                            <?php echo e($student->supervisorAssignment->assigned_at->format('Y-m-d')); ?>

                                        <?php else: ?>
                                            <span class="text-gray-400">-</span>
                                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                        <div class="flex space-x-2">
                                            <!--[if BLOCK]><![endif]--><?php if(!$student->supervisorAssignment): ?>
                                                <button wire:click="openAssignModal('<?php echo e($student->studentID); ?>')"
                                                    class="text-blue-600 hover:text-blue-900 mr-2">
                                                    Assign
                                                </button>
                                                <button wire:click="autoAssignSupervisor('<?php echo e($student->studentID); ?>')"
                                                    wire:loading.attr="disabled"
                                                    wire:target="autoAssignSupervisor('<?php echo e($student->studentID); ?>')"
                                                    class="text-green-600 hover:text-green-900">
                                                    <span wire:loading.remove wire:target="autoAssignSupervisor('<?php echo e($student->studentID); ?>')">Auto Assign</span>
                                                    <span wire:loading wire:target="autoAssignSupervisor('<?php echo e($student->studentID); ?>')">Assigning...</span>
                                                </button>
                                            <?php else: ?>
                                                <button wire:click="viewAssignment(<?php echo e($student->supervisorAssignment->id); ?>)"
                                                    class="text-indigo-600 hover:text-indigo-900 mr-2"
                                                    wire:loading.attr="disabled"
                                                    wire:target="viewAssignment">
                                                    <span wire:loading.remove wire:target="viewAssignment">View Details</span>
                                                    <span wire:loading wire:target="viewAssignment">Loading...</span>
                                                </button>
                                                <button wire:click="openEditModal(<?php echo e($student->supervisorAssignment->id); ?>)"
                                                    class="text-yellow-600 hover:text-yellow-900 mr-2">
                                                    Edit
                                                </button>
                                                <button wire:click="removeAssignment(<?php echo e($student->supervisorAssignment->id); ?>)"
                                                    wire:confirm="Are you sure you want to remove this supervisor assignment?"
                                                    class="text-red-600 hover:text-red-900">
                                                    Remove
                                                </button>
                                            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="7" class="px-6 py-4 text-center text-sm text-gray-500">
                                        No students found.
                                    </td>
                                </tr>
                            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                        </tbody>
                    </table>
                </div>

                <!-- Pagination -->
                <div class="px-6 py-4 border-t border-gray-200">
                    <?php echo e($students->links()); ?>

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

    <!-- Assign Supervisor Modal -->
    <!--[if BLOCK]><![endif]--><?php if($showAssignModal && $selectedStudent): ?>
        <div class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50" wire:click="closeAssignModal">
            <div class="relative top-20 mx-auto p-5 border w-11/12 md:w-3/4 lg:w-1/2 shadow-lg rounded-md bg-white" wire:click.stop>
                <div class="mt-3">
                    <!-- Header -->
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-medium text-gray-900">Assign Supervisor</h3>
                        <button wire:click="closeAssignModal" class="text-gray-400 hover:text-gray-500">
                            <span class="text-2xl">&times;</span>
                        </button>
                    </div>

                    <!-- Student Info -->
                    <div class="mb-4 p-4 bg-gray-50 rounded-lg">
                        <h4 class="font-medium text-gray-900 mb-2">Student Information</h4>
                        <p><strong>Name:</strong> <?php echo e($selectedStudent->user->name); ?></p>
                        <p><strong>ID:</strong> <?php echo e($selectedStudent->studentID); ?></p>
                        <!--[if BLOCK]><![endif]--><?php if($selectedStudent->acceptedPlacementApplication): ?>
                            <p><strong>Company:</strong> <?php echo e($selectedStudent->acceptedPlacementApplication->companyName); ?></p>
                            <p><strong>Location:</strong> <?php echo e($selectedStudent->acceptedPlacementApplication->companyFullAddress); ?></p>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!-- Recommended Supervisors -->
                    <div class="mb-4">
                        <h4 class="font-medium text-gray-900 mb-2">Recommended Supervisors (Nearest First)</h4>

                        <div class="mb-3">
                            <label class="flex items-center">
                                <input type="checkbox" wire:model="quotaOverride" wire:change="toggleQuotaOverride"
                                    class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                                <span class="ml-2 text-sm text-gray-700">Include supervisors with full quota (Override)</span>
                            </label>
                        </div>

                        <!--[if BLOCK]><![endif]--><?php if(!empty($recommendedSupervisors)): ?>
                            <div class="max-h-64 overflow-y-auto border border-gray-200 rounded-lg">
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $recommendedSupervisors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supervisor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <label class="flex items-start p-3 hover:bg-gray-50 cursor-pointer border-b border-gray-100">
                                        <input type="radio" name="supervisor" value="<?php echo e($supervisor->lecturerID); ?>"
                                            wire:model="selectedSupervisorID"
                                            class="mt-1 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                                        <div class="ml-3 flex-1">
                                            <div class="flex justify-between">
                                                <div>
                                                    <p class="text-sm font-medium text-gray-900"><?php echo e($supervisor->user->name); ?></p>
                                                    <p class="text-xs text-gray-500">
                                                        <?php echo e($supervisor->lecturerID); ?> |
                                                        <?php echo e($supervisor->department ?? 'N/A'); ?> |
                                                        <?php echo e($supervisor->researchGroup ?? 'N/A'); ?>

                                                    </p>
                                                </div>
                                                <div class="text-right">
                                                    <!--[if BLOCK]><![endif]--><?php if(isset($supervisor->distance)): ?>
                                                        <p class="text-sm font-medium text-gray-900"><?php echo e(number_format($supervisor->distance, 2)); ?> km</p>
                                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                    <p class="text-xs text-gray-500">
                                                        Quota: <?php echo e($supervisor->current_assignments); ?>/<?php echo e($supervisor->supervisor_quota); ?>

                                                        <!--[if BLOCK]><![endif]--><?php if(isset($supervisor->available_quota) && $supervisor->available_quota > 0): ?>
                                                            <span class="text-green-600">(<?php echo e($supervisor->available_quota); ?> available)</span>
                                                        <?php else: ?>
                                                            <span class="text-red-600">(Full)</span>
                                                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                    </p>
                                                </div>
                                            </div>
                                        </div>
                                    </label>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </div>
                        <?php else: ?>
                            <div class="p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
                                <p class="text-sm text-yellow-800">No available supervisors found. Please check quota settings or enable override.</p>
                            </div>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!-- Override Reason -->
                    <!--[if BLOCK]><![endif]--><?php if($quotaOverride): ?>
                        <div class="mb-4">
                            <label class="block text-sm font-medium text-gray-700 mb-1">
                                Override Reason <span class="text-red-500">*</span>
                            </label>
                            <textarea wire:model="overrideReason" rows="3"
                                class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm"
                                placeholder="Explain why you need to override the quota limit..."></textarea>
                            <!--[if BLOCK]><![endif]--><?php $__errorArgs = ['overrideReason'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-red-500 text-xs"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><!--[if ENDBLOCK]><![endif]-->
                        </div>
                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

                    <!-- Assignment Notes -->
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            Assignment Notes (Optional)
                        </label>
                        <textarea wire:model="assignmentNotes" rows="3"
                            class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm"
                            placeholder="Add any notes about this assignment..."></textarea>
                    </div>

                    <!-- Validation Errors -->
                    <!--[if BLOCK]><![endif]--><?php $__errorArgs = ['selectedSupervisorID'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="mb-4 p-3 bg-red-50 border border-red-200 rounded-lg">
                            <p class="text-sm text-red-800"><?php echo e($message); ?></p>
                        </div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><!--[if ENDBLOCK]><![endif]-->

                    <!-- Actions -->
                    <div class="flex justify-end space-x-3">
                        <button wire:click="closeAssignModal"
                            class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50">
                            Cancel
                        </button>
                        <button wire:click="assignSupervisor"
                            wire:loading.attr="disabled"
                            wire:target="assignSupervisor"
                            class="px-4 py-2 bg-indigo-600 text-white rounded-md text-sm font-medium hover:bg-indigo-700 disabled:opacity-50">
                            <span wire:loading.remove wire:target="assignSupervisor">Assign Supervisor</span>
                            <span wire:loading wire:target="assignSupervisor">Assigning...</span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

    <!-- Edit Assignment Modal -->
    <!--[if BLOCK]><![endif]--><?php if($showEditModal && $editAssignmentID): ?>
        <div class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50" wire:click="closeEditModal">
            <div class="relative top-20 mx-auto p-5 border w-11/12 md:w-3/4 lg:w-1/2 shadow-lg rounded-md bg-white" wire:click.stop>
                <div class="mt-3">
                    <!-- Header -->
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-medium text-gray-900">Edit Supervisor Assignment</h3>
                        <button wire:click="closeEditModal" class="text-gray-400 hover:text-gray-500">
                            <span class="text-2xl">&times;</span>
                        </button>
                    </div>

                    <!-- Instructions -->
                    <div class="mb-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
                        <p class="text-sm text-blue-800">
                            <strong>Note:</strong> Select a new supervisor to replace the current assignment. This will update the quota counts accordingly.
                        </p>
                    </div>

                    <!-- Available Supervisors -->
                    <div class="mb-4">
                        <h4 class="font-medium text-gray-900 mb-2">Select New Supervisor (Nearest First)</h4>

                        <!--[if BLOCK]><![endif]--><?php if(!empty($recommendedSupervisors)): ?>
                            <div class="max-h-64 overflow-y-auto border border-gray-200 rounded-lg">
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $recommendedSupervisors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $supervisor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <label class="flex items-start p-3 hover:bg-gray-50 cursor-pointer border-b border-gray-100">
                                        <input type="radio" name="new_supervisor" value="<?php echo e($supervisor->lecturerID); ?>"
                                            wire:model="newSupervisorID"
                                            class="mt-1 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500">
                                        <div class="ml-3 flex-1">
                                            <div class="flex justify-between">
                                                <div>
                                                    <p class="text-sm font-medium text-gray-900"><?php echo e($supervisor->user->name); ?></p>
                                                    <p class="text-xs text-gray-500">
                                                        <?php echo e($supervisor->lecturerID); ?> |
                                                        <?php echo e($supervisor->department ?? 'N/A'); ?> |
                                                        <?php echo e($supervisor->researchGroup ?? 'N/A'); ?>

                                                    </p>
                                                </div>
                                                <div class="text-right">
                                                    <!--[if BLOCK]><![endif]--><?php if(isset($supervisor->distance)): ?>
                                                        <p class="text-sm font-medium text-gray-900"><?php echo e(number_format($supervisor->distance, 2)); ?> km</p>
                                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                    <p class="text-xs text-gray-500">
                                                        Quota: <?php echo e($supervisor->current_assignments); ?>/<?php echo e($supervisor->supervisor_quota); ?>

                                                        <!--[if BLOCK]><![endif]--><?php if(isset($supervisor->available_quota) && $supervisor->available_quota > 0): ?>
                                                            <span class="text-green-600">(<?php echo e($supervisor->available_quota); ?> available)</span>
                                                        <?php else: ?>
                                                            <span class="text-red-600">(Full)</span>
                                                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                    </p>
                                                </div>
                                            </div>
                                        </div>
                                    </label>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </div>
                        <?php else: ?>
                            <div class="p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
                                <p class="text-sm text-yellow-800">No supervisors available.</p>
                            </div>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!-- Assignment Notes -->
                    <div class="mb-4">
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            Assignment Notes (Optional)
                        </label>
                        <textarea wire:model="assignmentNotes" rows="3"
                            class="w-full border border-gray-300 rounded-md px-3 py-2 text-sm"
                            placeholder="Add any notes about this assignment change..."></textarea>
                    </div>

                    <!-- Validation Errors -->
                    <!--[if BLOCK]><![endif]--><?php $__errorArgs = ['newSupervisorID'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="mb-4 p-3 bg-red-50 border border-red-200 rounded-lg">
                            <p class="text-sm text-red-800"><?php echo e($message); ?></p>
                        </div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><!--[if ENDBLOCK]><![endif]-->

                    <!-- Actions -->
                    <div class="flex justify-end space-x-3">
                        <button wire:click="closeEditModal"
                            class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50">
                            Cancel
                        </button>
                        <button wire:click="updateAssignment"
                            wire:loading.attr="disabled"
                            wire:target="updateAssignment"
                            class="px-4 py-2 bg-yellow-600 text-white rounded-md text-sm font-medium hover:bg-yellow-700 disabled:opacity-50">
                            <span wire:loading.remove wire:target="updateAssignment">Update Assignment</span>
                            <span wire:loading wire:target="updateAssignment">Updating...</span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

    <!-- Assignment Detail Modal -->
    <!--[if BLOCK]><![endif]--><?php if($showDetailModal && $selectedAssignment): ?>
        <div class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50" wire:click="closeDetailModal">
            <div class="relative top-20 mx-auto p-5 border w-11/12 md:w-3/4 lg:w-1/2 shadow-lg rounded-md bg-white" wire:click.stop>
                <div class="mt-3">
                    <!-- Header -->
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-medium text-gray-900">Assignment Details</h3>
                        <button wire:click="closeDetailModal" class="text-gray-400 hover:text-gray-500">
                            <span class="text-2xl">&times;</span>
                        </button>
                    </div>

                    <!-- Student Info -->
                    <div class="mb-4 p-4 bg-gray-50 rounded-lg">
                        <h4 class="font-medium text-gray-900 mb-2">Student</h4>
                        <p><strong>Name:</strong> <?php echo e($selectedAssignment['student_name']); ?></p>
                        <p><strong>ID:</strong> <?php echo e($selectedAssignment['student_id']); ?></p>
                        <p><strong>Program:</strong> <?php echo e($selectedAssignment['student_program'] ?? 'N/A'); ?></p>
                        <!--[if BLOCK]><![endif]--><?php if($selectedAssignment['company_name']): ?>
                            <p><strong>Company:</strong> <?php echo e($selectedAssignment['company_name']); ?></p>
                            <p><strong>Location:</strong>
                                <?php echo e($selectedAssignment['company_city']); ?>,
                                <?php echo e($selectedAssignment['company_state']); ?>

                            </p>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!-- Supervisor Info -->
                    <div class="mb-4 p-4 bg-gray-50 rounded-lg">
                        <h4 class="font-medium text-gray-900 mb-2">Supervisor</h4>
                        <p><strong>Name:</strong> <?php echo e($selectedAssignment['supervisor_name']); ?></p>
                        <p><strong>ID:</strong> <?php echo e($selectedAssignment['supervisor_id']); ?></p>
                        <p><strong>Department:</strong> <?php echo e($selectedAssignment['supervisor_department'] ?? 'N/A'); ?></p>
                        <p><strong>Research Group:</strong> <?php echo e($selectedAssignment['supervisor_research_group'] ?? 'N/A'); ?></p>
                        <p><strong>Position:</strong> <?php echo e($selectedAssignment['supervisor_position'] ?? 'N/A'); ?></p>
                        <!--[if BLOCK]><![endif]--><?php if($selectedAssignment['distance_km']): ?>
                            <p><strong>Distance:</strong> <?php echo e(number_format($selectedAssignment['distance_km'], 2)); ?> km</p>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                        <!--[if BLOCK]><![endif]--><?php if($selectedAssignment['quota_override']): ?>
                            <p class="text-yellow-600"><strong>⚠️ Quota Override Applied</strong></p>
                            <!--[if BLOCK]><![endif]--><?php if($selectedAssignment['override_reason']): ?>
                                <p class="text-sm text-gray-600"><strong>Reason:</strong> <?php echo e($selectedAssignment['override_reason']); ?></p>
                            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!-- Assignment Info -->
                    <div class="mb-4 p-4 bg-gray-50 rounded-lg">
                        <h4 class="font-medium text-gray-900 mb-2">Assignment Details</h4>
                        <p><strong>Status:</strong>
                            <span class="px-2 py-1 text-xs rounded-full <?php echo e($selectedAssignment['status'] === 'assigned' ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800'); ?>">
                                <?php echo e($selectedAssignment['status_display']); ?>

                            </span>
                        </p>
                        <p><strong>Assigned By:</strong>
                            <?php echo e($selectedAssignment['assigned_by_name']); ?>

                            <!--[if BLOCK]><![endif]--><?php if($selectedAssignment['assigned_by_id']): ?>
                                (<?php echo e($selectedAssignment['assigned_by_id']); ?>)
                            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                        </p>
                        <p><strong>Assigned At:</strong> <?php echo e($selectedAssignment['assigned_at']); ?></p>
                        <!--[if BLOCK]><![endif]--><?php if($selectedAssignment['assignment_notes']): ?>
                            <p><strong>Notes:</strong> <?php echo e($selectedAssignment['assignment_notes']); ?></p>
                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                    </div>

                    <!-- Actions -->
                    <div class="flex justify-end">
                        <button wire:click="closeDetailModal"
                            class="px-4 py-2 bg-gray-600 text-white rounded-md text-sm font-medium hover:bg-gray-700">
                            Close
                        </button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
</div>
<?php /**PATH C:\Users\User\Desktop\Laravel\Internlink\resources\views/livewire/supervisor-assignment-table.blade.php ENDPATH**/ ?>