

<?php $__env->startSection('title', 'Registros de Salida'); ?>
<?php $__env->startSection('subtitle', 'Historial de despachos de combustible'); ?>

<?php $__env->startSection('actions'); ?>
    <a class="btn primary" href="<?php echo e(route('registros_salidas.create')); ?>">Nuevo Despacho</a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <form method="GET" action="<?php echo e(route('registros_salidas.index')); ?>" style="display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-bottom:14px">
        <div>
            <label style="display:block;font-weight:700;margin-bottom:6px">Fecha desde</label>
            <input type="date" name="fecha_desde" value="<?php echo e($fechaDesde ?? date('Y-m-d')); ?>" style="width:100%;padding:10px;border:1px solid #e2e8f0;border-radius:10px">
        </div>
        <div>
            <label style="display:block;font-weight:700;margin-bottom:6px">Fecha hasta</label>
            <input type="date" name="fecha_hasta" value="<?php echo e($fechaHasta ?? date('Y-m-d')); ?>" style="width:100%;padding:10px;border:1px solid #e2e8f0;border-radius:10px">
        </div>
        <div>
            <label style="display:block;font-weight:700;margin-bottom:6px">Usuario</label>
            <select name="id_usuario" style="width:100%;padding:10px;border:1px solid #e2e8f0;border-radius:10px">
                <option value="">-- Todos --</option>
                <?php $__currentLoopData = $usuarios; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($u->id_usuario); ?>" <?php echo e((string)($usuarioId ?? '') === (string)$u->id_usuario ? 'selected' : ''); ?>>
                        <?php echo e($u->usuario ?? $u->name ?? $u->email); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div>
            <label style="display:block;font-weight:700;margin-bottom:6px">Turno</label>
            <select name="id_turno" style="width:100%;padding:10px;border:1px solid #e2e8f0;border-radius:10px">
                <option value="">-- Todos --</option>
                <?php $__currentLoopData = $turnos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($t->id_turno); ?>" <?php echo e((string)($turnoId ?? '') === (string)$t->id_turno ? 'selected' : ''); ?>>
                        <?php echo e($t->turnos); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div style="grid-column:1/-1;display:flex;gap:8px;align-items:end">
            <button class="btn primary" type="submit">Filtrar</button>
            <a class="btn" href="<?php echo e(route('registros_salidas.index')); ?>">Limpiar</a>
        </div>
    </form>

    <div style="overflow-x:auto">
        <table style="width:100%;border-collapse:collapse;margin-top:10px">
            <thead>
                <tr style="background:#f1f5f9;text-align:left">
                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">ID</th>
                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">Fecha</th>
                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">Usuario</th>
                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">Turno</th>
                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">ISLA / LADO / MANGUERA</th>

                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">Saldo final</th>


                    <th style="padding:12px;border-bottom:1px solid #e2e8f0">Acciones</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $userColorMap = [];
                    $userColorPalette = [
                        '#ef4444', '#f97316', '#eab308', '#22c55e', '#10b981',
                        '#06b6d4', '#3b82f6', '#6366f1', '#8b5cf6', '#d946ef',
                        '#ec4899', '#14b8a6', '#84cc16', '#f59e0b', '#0ea5e9'
                    ];
                    $userColorIndex = 0;
                ?>

                <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $username = $item->usuario?->usuario ?? $item->usuario?->name ?? '-';
                        if (!isset($userColorMap[$username])) {
                            $userColorMap[$username] = $userColorPalette[$userColorIndex % count($userColorPalette)];
                            $userColorIndex++;
                        }
                        $userColor = $userColorMap[$username];
                    ?>
                    <tr style="border-bottom:1px solid #e2e8f0">
                        <td style="padding:12px"><?php echo e($item->id_salida); ?></td>
                        <td style="padding:12px"><?php echo e(optional($item->fecha_inicio)->format('d/m/Y')); ?></td>
                        <td style="padding:12px">
                            <span style="display:inline-block;padding:4px 10px;border-radius:999px;background:<?php echo e($userColor); ?>;color:#fff;font-weight:700;font-size:12px;line-height:1.2">
                                <?php echo e($username); ?>

                            </span>
                        </td>
                        <td style="padding:12px"><?php echo e($item->turno?->turnos ?? '-'); ?></td>
                        <td style="padding:12px"><?php echo e($item->manguera?->cara?->estacion?->nombre ?? '-'); ?> | <?php echo e($item->manguera?->cara?->lado ?? $item->manguera?->cara?->nombre ?? '-'); ?> | M-<?php echo e($item->manguera?->numero_manguera ?? '-'); ?></td>

                        <td style="padding:12px"><?php echo e($item->saldo_final ?? '-'); ?></td>


                        <td style="padding:12px;display:flex;gap:8px">
                            <a class="btn" href="<?php echo e(route('registros_salidas.edit', $item->id_salida)); ?>" style="padding:6px 10px;font-size:13px">Editar</a>
                            <?php if(auth()->user()->rol === 'ADMIN'): ?>
                                <form action="<?php echo e(route('registros_salidas.destroy', $item->id_salida)); ?>" method="POST" onsubmit="return confirm('¿Eliminar registro?')">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('DELETE'); ?>
                                    <button type="submit" class="btn" style="padding:6px 10px;font-size:13px;background:#fee2e2;color:#991b1b;border-color:#fecaca">Eliminar</button>
                                </form>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                <?php if($items->isEmpty()): ?>
                    <tr>
                        <td colspan="7" style="padding:24px;text-align:center;color:#64748b">No hay registros de salida.</td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('partials.layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\laragon\www\grifo\resources\views/registros_salidas/index.blade.php ENDPATH**/ ?>