<div>
    <style>
        /* Slider Styling */
        input[type="range"].slider {
            -webkit-appearance: none;
            appearance: none;
            background: transparent;
            cursor: pointer;
        }

        input[type="range"].slider::-webkit-slider-track {
            background: #e5e7eb;
            height: 8px;
            border-radius: 4px;
        }

        input[type="range"].slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            background: #3b82f6;
            height: 20px;
            width: 20px;
            border-radius: 50%;
            margin-top: -6px;
            transition: background 0.2s;
        }

        input[type="range"].slider::-webkit-slider-thumb:hover {
            background: #2563eb;
        }

        input[type="range"].slider::-moz-range-track {
            background: #e5e7eb;
            height: 8px;
            border-radius: 4px;
        }

        input[type="range"].slider::-moz-range-thumb {
            background: #3b82f6;
            height: 20px;
            width: 20px;
            border: none;
            border-radius: 50%;
            cursor: pointer;
            transition: background 0.2s;
        }

        input[type="range"].slider::-moz-range-thumb:hover {
            background: #2563eb;
        }
    </style>
    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">

            <!-- Flash Messages -->
            <?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; ?>

            <?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; ?>

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

            <!-- Current Weights Info -->
            <?php if($latestWeights): ?>
                <div class="bg-white rounded-lg shadow p-6 mb-6">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-lg font-semibold text-gray-900 mb-2">Current Active Weights</h3>
                            <p class="text-sm text-gray-600">
                                Created by: <?php echo e($latestWeights->creator->name ?? 'Unknown'); ?> on
                                <?php echo e($latestWeights->created_at->format('M d, Y H:i')); ?>

                            </p>
                        </div>
                        <div class="text-right">
                            <div class="text-sm text-gray-600 mb-1">Consistency Ratio</div>
                            <div
                                class="text-lg font-bold <?php echo e($latestWeights->is_consistent ? 'text-green-600' : 'text-red-600'); ?>">
                                <?php echo e(number_format($latestWeights->consistency_ratio, 4)); ?>

                            </div>
                        </div>
                    </div>
                    <div class="mt-4 grid grid-cols-4 gap-4">
                        <?php $__currentLoopData = ['course_match', 'preference_match', 'distance_score', 'workload_score']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $criterion): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="text-center">
                                <div class="text-sm text-gray-600"><?php echo e(ucfirst(str_replace('_', ' ', $criterion))); ?>

                                </div>
                                <div class="text-xl font-bold text-gray-900">
                                    <?php echo e(number_format($latestWeights->getWeight($criterion) * 100, 1)); ?>%
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </div>
            <?php endif; ?>

            <!-- Mode Toggle -->
            <div class="bg-white rounded-lg shadow p-4 mb-6">
                <div class="flex items-center justify-between">
                    <div>
                        <h3 class="text-lg font-medium text-gray-900 mb-1">Configuration Mode</h3>
                        <p class="text-sm text-gray-600">
                            Choose how you want to set the weights for supervisor assignment scoring
                        </p>
                    </div>
                    <div class="flex gap-2">
                        <button wire:click="switchMode('simple')"
                            class="px-4 py-2 rounded-md text-sm font-medium transition <?php echo e($mode === 'simple' ? 'bg-blue-600 text-white' : 'bg-gray-200 text-gray-700 hover:bg-gray-300'); ?>">
                            🎯 Simple Mode (Sliders)
                        </button>
                        <button wire:click="switchMode('advanced')"
                            class="px-4 py-2 rounded-md text-sm font-medium transition <?php echo e($mode === 'advanced' ? 'bg-blue-600 text-white' : 'bg-gray-200 text-gray-700 hover:bg-gray-300'); ?>">
                            📊 Advanced Mode (AHP Matrix)
                        </button>
                    </div>
                </div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
                <!-- Left Column: Configuration Interface -->
                <div class="lg:col-span-2">
                    <?php if($mode === 'simple'): ?>
                        <!-- Simple Mode: Slider Interface -->
                        <div class="bg-white rounded-lg shadow">
                            <div class="px-6 py-4 border-b border-gray-200">
                                <h2 class="text-lg font-medium text-gray-900">Simple Weight Configuration</h2>
                                <p class="text-sm text-gray-600 mt-1">
                                    Adjust the sliders to set the importance of each factor. Weights will automatically
                                    normalize to 100%.
                                </p>
                            </div>

                            <div class="p-6 space-y-6">
                                <?php $__currentLoopData = ['course_match' => 'Course Match', 'preference_match' => 'Preference Match', 'distance_score' => 'Distance Score', 'workload_score' => 'Workload Score']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div>
                                        <div class="flex items-center justify-between mb-2">
                                            <label class="text-sm font-medium text-gray-700">
                                                <?php echo e($label); ?>

                                            </label>
                                            <div class="flex items-center gap-3">
                                                <input type="number"
                                                    wire:model.live.debounce.300ms="directWeights.<?php echo e($key); ?>"
                                                    min="0" max="100" step="0.1"
                                                    class="w-20 text-center border border-gray-300 rounded-md px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                                <span class="text-sm font-bold text-gray-900 w-12 text-right">
                                                    <?php echo e(number_format($directWeights[$key] ?? 0, 1)); ?>%
                                                </span>
                                            </div>
                                        </div>
                                        <input type="range"
                                            wire:model.live.debounce.300ms="directWeights.<?php echo e($key); ?>"
                                            min="0" max="100" step="0.1"
                                            class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer slider">
                                        <div class="flex justify-between text-xs text-gray-500 mt-1">
                                            <span>0%</span>
                                            <span>50%</span>
                                            <span>100%</span>
                                        </div>
                                        <p class="text-xs text-gray-500 mt-1">
                                            <?php if($key === 'course_match'): ?>
                                                How important is matching the student's program with the supervisor's
                                                program?
                                            <?php elseif($key === 'preference_match'): ?>
                                                How important is matching the supervisor's travel preference with the
                                                placement location?
                                            <?php elseif($key === 'distance_score'): ?>
                                                How important is the distance between supervisor and placement location?
                                            <?php elseif($key === 'workload_score'): ?>
                                                How important is the supervisor's current workload (availability)?
                                            <?php endif; ?>
                                        </p>
                                    </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                <!-- Total Display -->
                                <div class="mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg">
                                    <div class="flex items-center justify-between">
                                        <span class="text-sm font-medium text-blue-900">Total Weight:</span>
                                        <span
                                            class="text-lg font-bold <?php echo e(abs(array_sum($directWeights) - 100) < 0.1 ? 'text-green-600' : 'text-red-600'); ?>">
                                            <?php echo e(number_format(array_sum($directWeights), 1)); ?>%
                                        </span>
                                    </div>
                                    <?php if(abs(array_sum($directWeights) - 100) >= 0.1): ?>
                                        <p class="text-xs text-red-600 mt-1">Weights will be automatically normalized to
                                            100%</p>
                                    <?php endif; ?>
                                </div>

                                <!-- Action Buttons -->
                                <div class="mt-6 flex gap-3">
                                    <button wire:click="resetToEqual"
                                        class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm font-medium transition">
                                        Reset to Equal (25% each)
                                    </button>
                                </div>
                            </div>
                        </div>
                    <?php else: ?>
                        <!-- Advanced Mode: Pairwise Comparison Matrix -->
                        <div class="bg-white rounded-lg shadow">
                            <div class="px-6 py-4 border-b border-gray-200">
                                <h2 class="text-lg font-medium text-gray-900">Pairwise Comparison Matrix</h2>
                                <p class="text-sm text-gray-600 mt-1">
                                    Compare each criterion with others. Values are automatically reciprocated.
                                </p>
                            </div>

                            <div class="p-6">
                                <?php if($errorMessage): ?>
                                    <div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
                                        <p class="text-red-700 text-sm"><?php echo e($errorMessage); ?></p>
                                    </div>
                                <?php endif; ?>

                                <!-- AHP Scale Reference -->
                                <div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6">
                                    <h4 class="text-sm font-semibold text-blue-900 mb-2">AHP Scale Reference:</h4>
                                    <div class="grid grid-cols-2 gap-2 text-xs text-blue-800">
                                        <div>1 = Equal Importance</div>
                                        <div>3 = Moderate Importance</div>
                                        <div>5 = Strong Importance</div>
                                        <div>7 = Very Strong Importance</div>
                                        <div>9 = Extreme Importance</div>
                                        <div>1/3, 1/5, 1/7, 1/9 = Inverse values</div>
                                    </div>
                                </div>

                                <!-- Matrix Table -->
                                <div class="overflow-x-auto">
                                    <table class="min-w-full divide-y divide-gray-200">
                                        <thead>
                                            <tr>
                                                <th
                                                    class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider bg-gray-50">
                                                </th>
                                                <?php $__currentLoopData = $criteriaLabels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <th
                                                        class="px-4 py-3 text-center text-xs font-medium text-gray-500 uppercase tracking-wider bg-gray-50">
                                                        <?php echo e($label); ?>

                                                    </th>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </tr>
                                        </thead>
                                        <tbody class="bg-white divide-y divide-gray-200">
                                            <?php $__currentLoopData = $matrix; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rowIndex => $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <tr>
                                                    <td class="px-4 py-3 text-sm font-medium text-gray-900 bg-gray-50">
                                                        <?php echo e($criteriaLabels[$rowIndex]); ?>

                                                    </td>
                                                    <?php $__currentLoopData = $row; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $colIndex => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <td class="px-4 py-3 text-center">
                                                            <?php if($rowIndex == $colIndex): ?>
                                                                <!-- Diagonal: Always 1 -->
                                                                <input type="text" value="1" disabled
                                                                    class="w-20 text-center border border-gray-300 rounded-md px-2 py-1 text-sm bg-gray-100">
                                                            <?php elseif($rowIndex < $colIndex): ?>
                                                                <!-- Upper triangle: Editable -->
                                                                <input type="number" step="0.01" min="0.11"
                                                                    max="9"
                                                                    wire:model.live.debounce.500ms="matrix.<?php echo e($rowIndex); ?>.<?php echo e($colIndex); ?>"
                                                                    class="w-20 text-center border border-gray-300 rounded-md px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
                                                                    placeholder="1.0">
                                                            <?php else: ?>
                                                                <!-- Lower triangle: Auto-calculated reciprocal (read-only) -->
                                                                <input type="text"
                                                                    value="<?php echo e(number_format($value, 3)); ?>" disabled
                                                                    class="w-20 text-center border border-gray-300 rounded-md px-2 py-1 text-sm bg-gray-100 text-gray-600">
                                                            <?php endif; ?>
                                                        </td>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </tbody>
                                    </table>
                                </div>

                                <!-- Action Buttons -->
                                <div class="mt-6 flex gap-3">
                                    <button wire:click="resetToDefault"
                                        class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm font-medium transition">
                                        Reset to Default
                                    </button>
                                    <button wire:click="resetToEqual"
                                        class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 text-sm font-medium transition">
                                        Reset to Equal (25% each)
                                    </button>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>

                <!-- Right Column: Results -->
                <div class="lg:col-span-1">
                    <div class="bg-white rounded-lg shadow">
                        <div class="px-6 py-4 border-b border-gray-200">
                            <h2 class="text-lg font-medium text-gray-900">Calculated Weights</h2>
                        </div>

                        <div class="p-6">
                            <?php if(!empty($calculatedWeights) || $mode === 'simple'): ?>
                                <!-- Consistency Ratio -->
                                <?php if($mode === 'advanced'): ?>
                                    <div class="mb-6">
                                        <div class="flex items-center justify-between mb-2">
                                            <span class="text-sm font-medium text-gray-700">Consistency Ratio
                                                (CR)</span>
                                            <span
                                                class="text-sm font-bold <?php echo e($isConsistent ? 'text-green-600' : 'text-red-600'); ?>">
                                                <?php echo e($consistencyRatio ? number_format($consistencyRatio, 4) : 'N/A'); ?>

                                            </span>
                                        </div>
                                        <div class="w-full bg-gray-200 rounded-full h-2">
                                            <div class="h-2 rounded-full <?php echo e($isConsistent ? 'bg-green-500' : 'bg-red-500'); ?>"
                                                style="width: <?php echo e(min(($consistencyRatio ?? 0) * 1000, 100)); ?>%"></div>
                                        </div>
                                        <p class="text-xs text-gray-500 mt-1">
                                            <?php echo e($isConsistent ? '✓ Acceptable (CR < 0.1)' : '✗ Inconsistent (CR ≥ 0.1)'); ?>

                                        </p>
                                        <?php if($lambdaMax): ?>
                                            <p class="text-xs text-gray-400 mt-1">λ_max:
                                                <?php echo e(number_format($lambdaMax, 4)); ?>

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

                                <!-- Weights Display -->
                                <div class="space-y-4">
                                    <?php $__currentLoopData = ['course_match', 'preference_match', 'distance_score', 'workload_score']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $criterion): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <div>
                                            <div class="flex items-center justify-between mb-1">
                                                <span class="text-sm font-medium text-gray-700">
                                                    <?php echo e(ucfirst(str_replace('_', ' ', $criterion))); ?>

                                                </span>
                                                <span class="text-lg font-bold text-gray-900">
                                                    <?php echo e($this->getWeightPercentage($criterion)); ?>

                                                </span>
                                            </div>
                                            <div class="w-full bg-gray-200 rounded-full h-2">
                                                <div class="h-2 rounded-full bg-blue-500"
                                                    style="width: <?php echo e(($calculatedWeights[$criterion] ?? 0) * 100); ?>%">
                                                </div>
                                            </div>
                                        </div>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </div>

                                <!-- Save Button -->
                                <div class="mt-6">
                                    <button wire:click="saveWeights"
                                        class="w-full px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm font-medium transition">
                                        Save Weights
                                    </button>
                                    <?php if($mode === 'advanced' && !$isConsistent): ?>
                                        <p class="text-xs text-red-600 mt-2 text-center">
                                            Fix consistency issues before saving
                                        </p>
                                    <?php endif; ?>
                                    <?php if($mode === 'simple'): ?>
                                        <p class="text-xs text-gray-500 mt-2 text-center">
                                            Simple mode automatically ensures consistency
                                        </p>
                                    <?php endif; ?>
                                </div>
                            <?php else: ?>
                                <div class="text-center text-gray-500 py-8">
                                    <p class="text-sm">Enter pairwise comparisons to calculate weights</p>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <!-- Instructions Card -->
                    <div class="bg-white rounded-lg shadow mt-6">
                        <div class="px-6 py-4 border-b border-gray-200">
                            <h3 class="text-lg font-medium text-gray-900">Instructions</h3>
                        </div>
                        <div class="p-6">
                            <?php if($mode === 'simple'): ?>
                                <div class="space-y-2 text-sm text-gray-600">
                                    <p class="font-semibold text-gray-900 mb-2">Simple Mode:</p>
                                    <ol class="list-decimal list-inside space-y-1">
                                        <li>Use the sliders to adjust the importance of each factor</li>
                                        <li>You can also type values directly in the number inputs</li>
                                        <li>Weights automatically normalize to 100% total</li>
                                        <li>The system converts your weights to an AHP-compatible format</li>
                                        <li>Click "Save Weights" to apply for supervisor assignments</li>
                                    </ol>
                                    <p class="mt-3 text-xs text-gray-500 italic">
                                        💡 Tip: Start with equal weights (25% each) and adjust based on your priorities
                                    </p>
                                </div>
                            <?php else: ?>
                                <ol class="list-decimal list-inside space-y-2 text-sm text-gray-600">
                                    <li>Compare each criterion in the upper triangle of the matrix</li>
                                    <li>Use values from 1 (equal) to 9 (extreme importance)</li>
                                    <li>Lower triangle values are automatically calculated</li>
                                    <li>Ensure Consistency Ratio (CR) is below 0.1</li>
                                    <li>Click "Save Weights" to apply for supervisor assignments</li>
                                </ol>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div><?php /**PATH C:\Users\User\Desktop\Laravel\Internlink\resources\views\livewire\a-h-p-weight-calculator.blade.php ENDPATH**/ ?>