<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('header', null, []); ?> 
        <div class="flex items-center justify-between gap-4 rounded-2xl border border-sky-200/70 bg-gradient-to-r from-sky-50 to-emerald-50 px-5 py-4">
            <div class="flex items-center gap-3">
                <div>
                    <h2 class="font-semibold text-xl text-sky-900 leading-tight">
                        Driver Management
                    </h2>
                    <p class="mt-1 text-sm text-sky-700">Manage your team, assignments, and package limits from one place.</p>
                </div>
                <?php if($driverLimit !== null): ?>
                    <span class="inline-flex items-center rounded-full border px-3 py-1 text-xs font-semibold <?php echo e($canAddDriver ? 'border-blue-200 bg-blue-50 text-blue-800' : 'border-amber-300 bg-amber-50 text-amber-800'); ?>">
                        <?php echo e($driverCount); ?>/<?php echo e($driverLimit); ?> used
                    </span>
                <?php endif; ?>
            </div>

            <?php if($canAddDriver): ?>
                <a href="<?php echo e(route('owner.drivers.create')); ?>" class="portal-primary-btn rounded-xl px-4 py-2 font-semibold transition">
                    Add Driver
                </a>
            <?php else: ?>
                <span class="cursor-not-allowed rounded-xl border border-gray-300 bg-gray-100 px-4 py-2 text-gray-600" aria-disabled="true" title="Driver limit reached for your current package">
                    Add Driver
                </span>
            <?php endif; ?>
        </div>
     <?php $__env->endSlot(); ?>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <?php if($errors->has('driver_limit')): ?>
                <div class="mb-4 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 shadow-sm">
                    <?php echo e($errors->first('driver_limit')); ?>

                </div>
            <?php endif; ?>

            <div class="overflow-hidden rounded-2xl border border-sky-200 bg-gradient-to-br from-white to-sky-50 shadow-lg shadow-slate-900/5">
                <div class="px-6 py-4 border-b border-emerald-200 bg-gradient-to-r from-emerald-50 to-white">
                    <div class="flex items-center justify-between gap-3">
                        <h3 class="text-lg font-medium text-gray-900">Drivers (<?php echo e($drivers->count()); ?>)</h3>
                        <?php if($driverLimit !== null): ?>
                            <p class="inline-flex items-center rounded-lg border px-3 py-1 text-sm <?php echo e($canAddDriver ? 'border-blue-200 bg-blue-50 text-blue-700' : 'border-amber-300 bg-amber-50 text-amber-800 font-semibold'); ?>">
                                <?php echo e($driverCount); ?> of <?php echo e($driverLimit); ?> allowed drivers
                            </p>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-emerald-50/40">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Phone</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Truck</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Salary</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">
                            <?php $__empty_1 = true; $__currentLoopData = $drivers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $driver): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <div class="text-sm font-medium text-gray-900"><?php echo e($driver->name); ?></div>
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo e($driver->email); ?></td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo e($driver->phone); ?></td>
                                    <td class="px-6 py-4 whitespace-nowrap">
                                        <?php if($driver->truck): ?>
                                            <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-green-100 text-green-800">
                                                <?php echo e($driver->truck->number); ?>

                                            </span>
                                        <?php else: ?>
                                            <span class="text-gray-500 text-sm">Unassigned</span>
                                        <?php endif; ?>
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                        <?php if($driver->salary_per_mile): ?>
                                            $<?php echo e(number_format($driver->salary_per_mile, 2)); ?>/mi
                                        <?php elseif($driver->salary_percent): ?>
                                            <?php echo e($driver->salary_percent); ?>%
                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2">
                                        <a href="<?php echo e(route('owner.drivers.edit', $driver)); ?>" class="text-emerald-700 hover:text-emerald-900">Edit</a>
                                        <form action="<?php echo e(route('owner.drivers.destroy', $driver)); ?>" method="POST" class="inline delete-driver-form">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="button" class="text-red-600 hover:text-red-900 delete-driver-btn">Delete</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="6" class="px-6 py-12 text-center text-gray-500 text-sm">
                                        No drivers yet.
                                        <?php if($canAddDriver): ?>
                                            <a href="<?php echo e(route('owner.drivers.create')); ?>" class="text-emerald-700 hover:underline">Add your first driver</a>
                                        <?php else: ?>
                                            <span class="text-amber-700">Driver limit reached for your current package.</span>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div id="deleteModal" class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-40 z-50" style="display: none;">
        <div class="w-full max-w-md rounded-2xl border border-sky-100 bg-white p-8 shadow-2xl">
            <h2 class="mb-4 text-lg font-semibold text-slate-900">Confirm Deletion</h2>
            <p class="mb-6">Are you sure you want to delete this driver?</p>
            <div class="flex justify-end space-x-4">
                <button id="cancelDelete" class="rounded-xl bg-gray-200 px-4 py-2 hover:bg-gray-300">Cancel</button>
                <button id="confirmDelete" class="rounded-xl bg-red-600 px-4 py-2 text-white hover:bg-red-700">Yes, Delete</button>
            </div>
        </div>
    </div>

    <div id="toaster" class="fixed top-6 right-6 bg-green-600 text-white px-6 py-3 rounded shadow-lg z-50 hidden">
        <span id="toasterMsg">Driver deleted successfully!</span>
    </div>

    <?php $__env->startPush('scripts'); ?>
    <script>
    let formToDelete = null;
    const modal = document.getElementById('deleteModal');
    const toaster = document.getElementById('toaster');
    const toasterMsg = document.getElementById('toasterMsg');

    document.querySelectorAll('.delete-driver-btn').forEach(btn => {
        btn.addEventListener('click', function(e) {
            e.preventDefault();
            formToDelete = btn.closest('form');
            modal.style.display = 'flex';
        });
    });

    document.getElementById('cancelDelete').onclick = function() {
        modal.style.display = 'none';
        formToDelete = null;
    };

    document.getElementById('confirmDelete').onclick = function() {
        if (formToDelete) {
            fetch(formToDelete.action, {
                method: 'POST',
                headers: {
                    'X-CSRF-TOKEN': formToDelete.querySelector('[name=_token]').value,
                    'X-Requested-With': 'XMLHttpRequest',
                    'Accept': 'application/json',
                },
                body: new FormData(formToDelete)
            })
            .then(response => {
                if (response.ok) {
                    modal.style.display = 'none';
                    toaster.classList.remove('hidden');
                    setTimeout(() => { location.reload(); }, 1200);
                } else {
                    return response.json().then(data => { throw data; });
                }
            })
            .catch(() => {
                modal.style.display = 'none';
                toasterMsg.textContent = 'Failed to delete driver.';
                toaster.classList.remove('hidden');
                setTimeout(() => { toaster.classList.add('hidden'); }, 2000);
            });
        }
    };
    </script>
    <?php $__env->stopPush(); ?>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php /**PATH D:\true-trucker\web\resources\views/drivers/index.blade.php ENDPATH**/ ?>