<?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, []); ?> 
        Gestión de Insumos
     <?php $__env->endSlot(); ?>

    <!-- Filtros y Acciones -->
    <div class="card mb-4 border-0 shadow-sm rounded-4">
        <div class="card-body p-4">
            <div class="row g-3 align-items-center justify-content-between">
                <div class="col-md-8">
                    <form method="GET" action="<?php echo e(route('insumos.index')); ?>" class="d-flex flex-wrap gap-2">
                        <input type="text" name="search" value="<?php echo e(request('search')); ?>" placeholder="Buscar insumo..." class="form-control" style="max-width: 250px;">
                        
                        <select name="estado" class="form-select tom-select" style="max-width: 200px;">
                            <option value="">Todos los stocks</option>
                            <option value="alerta" <?php echo e(request('estado') === 'alerta' ? 'selected' : ''); ?>>Stock Bajo / Alerta</option>
                        </select>

                        <select name="activo" class="form-select tom-select" style="max-width: 150px;">
                            <option value="">Estados</option>
                            <option value="1" <?php echo e(request('activo') === '1' ? 'selected' : ''); ?>>Activos</option>
                            <option value="0" <?php echo e(request('activo') === '0' ? 'selected' : ''); ?>>Inactivos</option>
                        </select>

                        <button type="submit" class="btn btn-outline-secondary rounded-pill">
                            <i class="bi bi-funnel-fill"></i> Filtrar
                        </button>
                        
                        <?php if(request()->hasAny(['search', 'estado', 'activo'])): ?>
                            <a href="<?php echo e(route('insumos.index')); ?>" class="btn btn-light rounded-pill border">Limpiar</a>
                        <?php endif; ?>
                    </form>
                </div>
                <div class="col-md-4 text-md-end mt-3 mt-md-0">
                    <button type="button" class="btn btn-primary rounded-pill fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#createInsumoModal">
                        <i class="bi bi-plus-circle-fill me-1"></i> Nuevo Insumo
                    </button>
                </div>
            </div>
        </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 py-3 text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Nombre</th>
                            <th class="py-3 text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Marca</th>
                            <th class="py-3 text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Compra/Uso</th>
                            <th class="py-3 text-end text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Costo Uni.</th>
                            <th class="py-3 text-end text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Stock Actual</th>
                            <th class="py-3 text-center text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Estado</th>
                            <th class="pe-4 py-3 text-end text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Acciones</th>
                        </tr>
                    </thead>
                    <tbody class="border-top-0">
                        <?php $__empty_1 = true; $__currentLoopData = $insumos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $insumo): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $stockEnSucursal = $insumo->stocks->firstWhere('sucursal_id', $sucursalId);
                                $cantidadActual = $stockEnSucursal ? $stockEnSucursal->cantidad_actual : 0;
                                $cantidadMinima = $stockEnSucursal ? $stockEnSucursal->cantidad_minima : 0;
                                $alertaStock = $cantidadActual < $cantidadMinima;
                            ?>
                            <tr>
                                <td class="ps-4 py-3">
                                    <div class="fw-bold text-dark"><?php echo e($insumo->nombre); ?></div>
                                </td>
                                <td class="py-3 text-muted">
                                    <?php echo e($insumo->marca ?: '-'); ?>

                                </td>
                                <td class="py-3">
                                    <span class="badge bg-primary bg-opacity-10 text-primary rounded-pill px-2">
                                        <?php echo e($insumo->unidad_compra); ?>

                                    </span>
                                    <span class="text-muted mx-1">/</span>
                                    <span class="badge bg-purple bg-opacity-10 text-purple border rounded-pill px-2" style="background-color: #f3e8ff; color: #7e22ce;">
                                        <?php echo e($insumo->unidad_uso); ?>

                                    </span>
                                </td>
                                <td class="py-3 text-end fw-bold text-dark">
                                    <?php echo e($moneda); ?><?php echo e(number_format($insumo->costo_unitario, 2)); ?>

                                </td>
                                <td class="py-3 text-end">
                                    <span class="badge rounded-pill px-3 py-2 <?php echo e($alertaStock ? 'bg-danger bg-opacity-10 text-danger' : 'bg-success bg-opacity-10 text-success'); ?>">
                                        <?php echo e(number_format($cantidadActual, 2)); ?> <?php echo e($insumo->unidad_uso); ?>

                                    </span>
                                </td>
                                <td class="py-3 text-center">
                                    <?php if($insumo->activo): ?>
                                        <span class="badge bg-success bg-opacity-10 text-success rounded-pill px-2">Activo</span>
                                    <?php else: ?>
                                        <span class="badge bg-secondary bg-opacity-10 text-secondary rounded-pill px-2">Inactivo</span>
                                    <?php endif; ?>
                                </td>
                                <td class="pe-4 py-3 text-end">
                                    <a href="<?php echo e(route('insumos.show', $insumo)); ?>" class="btn btn-sm btn-light border rounded-circle" title="Ver Detalles">
                                        <i class="bi bi-eye text-primary"></i>
                                    </a>
                                    <a href="<?php echo e(route('insumos.edit', $insumo)); ?>" class="btn btn-sm btn-light border rounded-circle mx-1" title="Editar">
                                        <i class="bi bi-pencil text-warning"></i>
                                    </a>
                                    <form action="<?php echo e(route('insumos.destroy', $insumo)); ?>" method="POST" class="d-inline-block" onsubmit="event.preventDefault(); confirmAction(this.querySelector('button'), '¿Estás seguro de eliminar este insumo?');">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="btn btn-sm btn-light border rounded-circle" title="Eliminar">
                                            <i class="bi bi-trash text-danger"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="text-center py-5 text-muted">
                                    <i class="bi bi-box-seam fs-1 d-block mb-3 text-light"></i>
                                    No se encontraron insumos registrados en esta sucursal.
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            
            <?php if($insumos->hasPages()): ?>
                <div class="p-3 border-top">
                    <?php echo e($insumos->links('pagination::bootstrap-5')); ?>

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

    <!-- Modal para Crear Nuevo Insumo -->
    <div class="modal fade" id="createInsumoModal" tabindex="-1" aria-labelledby="createInsumoModalLabel" 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" id="createInsumoModalLabel"><i class="bi bi-box-seam-fill text-primary me-2"></i> Registrar Nuevo Insumo</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('insumos.store')); ?>" id="createInsumoForm">
                        <?php echo csrf_field(); ?>

                        <div class="row g-4">
                            <!-- Nombre -->
                            <div class="col-md-6">
                                <label for="nombre_modal" class="form-label fw-bold small text-muted">Nombre del Insumo <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="nombre_modal" name="nombre" required autofocus>
                            </div>

                            <!-- Marca -->
                            <div class="col-md-6">
                                <label for="marca_modal" class="form-label fw-bold small text-muted">Marca (Opcional)</label>
                                <input type="text" class="form-control" id="marca_modal" name="marca">
                            </div>

                            <!-- Unidad de Compra -->
                            <div class="col-md-6">
                                <label for="unidad_compra_modal" class="form-label fw-bold small text-muted">Unidad de Compra <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="unidad_compra_modal" name="unidad_compra" placeholder="ej. Kilo, Litro, Caja" required>
                            </div>

                            <!-- Unidad de Uso -->
                            <div class="col-md-6">
                                <label for="unidad_uso_modal" class="form-label fw-bold small text-muted">Unidad de Uso <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="unidad_uso_modal" name="unidad_uso" placeholder="ej. Gramo, Mililitro, Unidad" required>
                            </div>

                            <!-- Costo Unitario -->
                            <div class="col-md-6">
                                <label for="costo_unitario_modal" class="form-label fw-bold small text-muted">Costo Unitario <span class="text-danger">*</span></label>
                                <div class="input-group">
                                    <span class="input-group-text bg-light border-end-0"><i class="bi bi-currency-dollar"></i></span>
                                    <input type="number" class="form-control border-start-0 ps-0" id="costo_unitario_modal" name="costo_unitario" step="0.01" min="0" placeholder="0.00" required>
                                </div>
                                <div class="form-text mt-1" style="font-size: 0.75rem;">Costo por la unidad de compra seleccionada.</div>
                            </div>

                            <!-- Factor de Conversión -->
                            <div class="col-md-6">
                                <label for="factor_conversion_modal" class="form-label fw-bold small text-muted">Factor de Conversión <span class="text-danger">*</span></label>
                                <input type="number" class="form-control" id="factor_conversion_modal" name="factor_conversion" step="0.0001" min="0.0001" placeholder="ej. 1000" required>
                                <div class="form-text mt-1" style="font-size: 0.75rem;">¿Cuántas unidades de uso tiene 1 unidad de compra? Ej: compra en Kg y usa en g → <strong>1000</strong>. Si compra y usa en la misma unidad → <strong>1</strong>.</div>
                            </div>

                            <!-- Activo -->
                            <div class="col-md-6 d-flex align-items-center">
                                <div class="form-check form-switch mt-3 custom-switch">
                                    <input class="form-check-input" type="checkbox" role="switch" id="activo_modal" name="activo" value="1" checked>
                                    <label class="form-check-label fw-bold small ms-2 text-muted" for="activo_modal">Insumo Activo</label>
                                </div>
                            </div>
                        </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 shadow-sm" data-bs-dismiss="modal">Cancelar</button>
                            <button type="submit" class="btn btn-primary rounded-pill fw-bold shadow-sm px-4">
                                <i class="bi bi-check-lg me-1"></i> Guardar Insumo
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
 <?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/insumos/index.blade.php ENDPATH**/ ?>