<?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('title', null, []); ?> 
        Programación de Producción
     <?php $__env->endSlot(); ?>

    <!-- Filtros y Acciones -->
    <div class="card mb-4 border-0 shadow-sm rounded-4">
        <div class="card-body p-4">
            <form method="GET" action="<?php echo e(route('programaciones.index')); ?>">
                <div class="row g-3 align-items-center justify-content-between">
                    <div class="col-md-9 d-flex gap-2 align-items-center">
                        <label class="fw-bold text-muted me-2">Mes de Planificación:</label>
                        <div class="input-group flex-grow-1" style="max-width: 250px;">
                            <span class="input-group-text bg-white border-end-0 text-muted rounded-start-pill ps-3">
                                <i class="bi bi-calendar3"></i>
                            </span>
                            <input type="month" name="mes" class="form-control border-start-0 ps-0 pe-3 rounded-end-pill" 
                                value="<?php echo e(request('mes', now()->format('Y-m'))); ?>" onchange="this.form.submit()">
                        </div>
                    </div>
                    
                    <div class="col-md-3 text-md-end mt-3 mt-md-0">
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('crear.programacion')): ?>
                        <button type="button" class="btn btn-primary rounded-pill fw-bold shadow-sm w-100 w-md-auto text-nowrap" data-bs-toggle="modal" data-bs-target="#createProgramacionModal">
                            <i class="bi bi-plus-lg me-1"></i> Programar Día
                        </button>
                        <?php endif; ?>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- Tabla -->
    <div class="card border-0 shadow-sm rounded-4">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4 text-muted small text-uppercase py-3">Fecha</th>
                            <th class="text-muted small text-uppercase py-3">Platos Planificados</th>
                            <th class="text-center text-muted small text-uppercase py-3">Insumos (Picking)</th>
                            <th class="text-center text-muted small text-uppercase py-3">Estado Picking</th>
                            <th class="text-end pe-4 text-muted small text-uppercase py-3">Acciones</th>
                        </tr>
                    </thead>
                    <tbody class="border-top-0">
                        <?php $__empty_1 = true; $__currentLoopData = $programaciones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $prog): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td class="ps-4" style="width: 200px;">
                                    <div class="d-flex align-items-center">
                                        <div class="rounded-circle <?php echo e(\Carbon\Carbon::parse($prog->fecha)->isToday() ? 'bg-primary text-white' : 'bg-light text-secondary'); ?> d-flex flex-column align-items-center justify-content-center me-3 border fw-bold" style="width: 50px; height: 50px; line-height: 1.1;">
                                            <span style="font-size: 1.2rem;"><?php echo e(\Carbon\Carbon::parse($prog->fecha)->format('d')); ?></span>
                                            <span style="font-size: 0.65rem;" class="text-uppercase"><?php echo e(\Carbon\Carbon::parse($prog->fecha)->isoFormat('MMM')); ?></span>
                                        </div>
                                        <div>
                                            <div class="fw-bold"><?php echo e(\Carbon\Carbon::parse($prog->fecha)->dayName); ?></div>
                                            <?php if(\Carbon\Carbon::parse($prog->fecha)->isToday()): ?>
                                                <span class="badge bg-primary bg-opacity-10 text-primary py-1 px-2 mt-1" style="font-size: 0.65rem;">HOY</span>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <div class="d-flex flex-wrap gap-1">
                                    <?php $__currentLoopData = $prog->platos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $plato): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <span class="badge bg-light text-dark border rounded-pill px-2 py-1 mb-1 fw-normal" title="<?php echo e($plato->porciones); ?> porciones">
                                            <?php echo e($plato->receta->nombre); ?> <span class="bg-secondary bg-opacity-25 rounded px-1 ms-1 text-secondary fw-bold"><?php echo e($plato->porciones); ?></span>
                                        </span>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                </td>
                                <td class="text-center">
                                    <?php if($prog->picking): ?>
                                        <span class="badge bg-light text-dark border px-3 py-2 rounded-pill">
                                            <i class="bi bi-box-seam me-1 text-muted"></i> Generado
                                        </span>
                                    <?php else: ?>
                                        <span class="text-muted small fst-italic">Por generar</span>
                                    <?php endif; ?>
                                </td>
                                <td class="text-center">
                                    <?php if($prog->picking): ?>
                                        <?php if($prog->picking->porcentaje_completado == 100): ?>
                                            <span class="badge bg-success bg-opacity-10 text-success border border-success border-opacity-25 px-3 py-2 rounded-pill">
                                                <i class="bi bi-check-all me-1"></i> Completado
                                            </span>
                                        <?php elseif($prog->picking->porcentaje_completado > 0): ?>
                                            <div class="progress mt-1" style="height: 18px; border-radius: 12px;">
                                                <div class="progress-bar bg-warning text-dark fw-bold" role="progressbar" style="width: <?php echo e($prog->picking->porcentaje_completado); ?>%;" aria-valuenow="<?php echo e($prog->picking->porcentaje_completado); ?>" aria-valuemin="0" aria-valuemax="100"><?php echo e($prog->picking->porcentaje_completado); ?>%</div>
                                            </div>
                                        <?php else: ?>
                                            <span class="badge bg-secondary bg-opacity-10 text-secondary border border-secondary border-opacity-25 px-3 py-2 rounded-pill">
                                                Pendiente (0%)
                                            </span>
                                        <?php endif; ?>
                                    <?php else: ?>
                                        -
                                    <?php endif; ?>
                                </td>
                                <td class="text-end pe-4">
                                    <?php if($prog->picking): ?>
                                        <a href="<?php echo e(route('picking.show', $prog->picking)); ?>" class="btn btn-sm btn-info text-white rounded-pill mb-1 fw-bold shadow-sm px-3">
                                            <i class="bi bi-box-seam me-1"></i> Ver / Despachar
                                        </a>
                                    <?php endif; ?>

                                    <?php if(!$prog->picking && auth()->user()->can('confirmar.programacion')): ?>
                                        <form action="<?php echo e(route('programaciones.confirmar', $prog)); ?>" method="POST" class="d-inline" onsubmit="event.preventDefault(); confirmAction(this.querySelector('button'), 'Generar picking enviará exactamente la suma métrica de todos los ingredientes al almacén para su recolección. ¿Continuar?');">
                                            <?php echo csrf_field(); ?>
                                            <button type="submit" class="btn btn-sm btn-outline-primary rounded-pill mb-1 fw-bold">
                                                <i class="bi bi-gear-fill me-1"></i> Generar Picking
                                            </button>
                                        </form>
                                    <?php endif; ?>

                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('crear.programacion')): ?>
                                        <?php if(!$prog->picking || $prog->picking->porcentaje_completado == 0): ?>
                                        <form action="<?php echo e(route('programaciones.destroy', $prog)); ?>" method="POST" class="d-inline" onsubmit="event.preventDefault(); confirmAction(this.querySelector('button'), '¿Eliminar esta programación? Todos los cálculos de picking asociados no despachados se cancelarán.');">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="submit" class="btn btn-sm btn-light border rounded-circle mx-1" title="Eliminar Programación">
                                                <i class="bi bi-trash-fill text-danger"></i>
                                            </button>
                                        </form>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="5" class="text-center py-5 text-muted">
                                    <div class="mb-3"><i class="bi bi-calendar-x display-4 text-light"></i></div>
                                    <h5 class="fw-bold">Mes Vacío</h5>
                                    <p>No se ha programado producción para <?php echo e(\Carbon\Carbon::parse($mes)->monthName); ?>.</p>
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- Modal para Nueva Programación Rápida -->
    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('crear.programacion')): ?>
    <div class="modal fade" id="createProgramacionModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content border-0 shadow-lg rounded-4">
                <div class="modal-header bg-light border-bottom-0 pb-0 rounded-top-4 pt-4 px-4">
                    <h5 class="modal-title fw-bold"><i class="bi bi-calendar-plus text-primary me-2"></i> Programar Nuevo Día</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body p-4">
                    <form method="POST" action="<?php echo e(route('programaciones.store')); ?>">
                        <?php echo csrf_field(); ?>
                        
                        <div class="row mb-4">
                            <div class="col-md-6">
                                <label class="form-label fw-bold small text-muted">Fecha de Producción <span class="text-danger">*</span></label>
                                <input type="date" class="form-control" name="fecha" required min="<?php echo e(date('Y-m-d')); ?>" value="<?php echo e(date('Y-m-d')); ?>">
                            </div>
                        </div>

                        <div class="mb-3">
                            <label class="form-label fw-bold small text-muted">Platos y Porciones Recomendadas</label>
                            <div class="card border">
                                <ul class="list-group list-group-flush" style="max-height: 300px; overflow-y: auto;">
                                    <?php $__currentLoopData = $recetas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $receta): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <li class="list-group-item d-flex justify-content-between align-items-center py-2 px-3">
                                            <div class="form-check w-100">
                                                <input class="form-check-input receta-checkbox" type="checkbox" id="receta_<?php echo e($receta->id); ?>" name="platos[<?php echo e($receta->id); ?>][receta_id]" value="<?php echo e($receta->id); ?>">
                                                <label class="form-check-label ms-2 py-1 w-100 fw-medium" for="receta_<?php echo e($receta->id); ?>">
                                                    <?php echo e($receta->nombre); ?> <span class="text-muted small">(Receta base: <?php echo e($receta->porciones); ?> porc.)</span>
                                                </label>
                                            </div>
                                            <div class="input-group input-group-sm w-auto ms-3" style="min-width: 120px;">
                                                <span class="input-group-text bg-light text-muted border-end-0">Porc.</span>
                                                <input type="number" class="form-control border-start-0 receta-porciones" disabled name="platos[<?php echo e($receta->id); ?>][porciones]" value="<?php echo e($receta->porciones); ?>" min="1" step="1" id="porc_<?php echo e($receta->id); ?>">
                                            </div>
                                        </li>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </ul>
                            </div>
                            <small class="text-muted"><i class="bi bi-info-circle"></i> Marca la casilla (checkbox) para agregar el plato a la producción del día. Indica la cantidad final de porciones a cocinar.</small>
                        </div>

                        <div class="mt-4 pt-3 border-top text-end">
                            <button type="button" class="btn btn-light rounded-pill border fw-bold px-4 me-2" data-bs-dismiss="modal">Cancelar</button>
                            <button type="submit" class="btn btn-primary rounded-pill fw-bold px-4">Guardar Plan</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?>

    <?php $__env->startPush('scripts'); ?>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Habilitar y deshabilitar los inputs de porciones al marcar el checkbox
            const checkboxes = document.querySelectorAll('.receta-checkbox');
            checkboxes.forEach(chk => {
                chk.addEventListener('change', function() {
                    const inputPorciones = document.getElementById('porc_' + this.value);
                    if(this.checked) {
                        inputPorciones.removeAttribute('disabled');
                    } else {
                        inputPorciones.setAttribute('disabled', 'disabled');
                    }
                });
            });
        });
    </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 C:\laragon\www\gastrog\resources\views/programaciones/index.blade.php ENDPATH**/ ?>