

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h2 class="fw-bold text-dark mb-0"><i class="bi bi-box-seam-fill me-2"></i>Inventario de Productos</h2>
        <p class="text-muted mb-0">Gestión de carta y existencias</p>
    </div>
    <div>
        <a href="<?php echo e(route('inventory.logs')); ?>" class="btn btn-dark me-2">
            <i class="bi bi-clock-history me-1"></i> Ver Kardex
        </a>
        <a href="<?php echo e(route('products.create')); ?>" class="btn btn-primary fw-bold shadow-sm">
            <i class="bi bi-plus-lg me-1"></i> Nuevo Producto
        </a>
    </div>
</div>

<div class="card border-0 shadow-sm">
    <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-uppercase text-muted small fw-bold">Producto</th>
                        <th class="text-uppercase text-muted small fw-bold">Categoría</th>
                        <th class="text-uppercase text-muted small fw-bold">Precio</th>
                        <th class="text-uppercase text-muted small fw-bold">Stock</th>
                        <th class="text-center text-uppercase text-muted small fw-bold">Estado</th>
                        <th class="text-end pe-4 text-uppercase text-muted small fw-bold">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $products; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td class="ps-4">
                                <div class="d-flex align-items-center">
                                    <?php if($product->image): ?>
                                        <img src="<?php echo e(asset('storage/'.$product->image)); ?>" class="rounded me-3 border" width="48" height="48" style="object-fit: cover;">
                                    <?php else: ?>
                                        <div class="bg-light rounded me-3 d-flex align-items-center justify-content-center border text-muted" style="width: 48px; height: 48px;">
                                            <i class="bi bi-image"></i>
                                        </div>
                                    <?php endif; ?>
                                    <div>
                                        <div class="fw-bold text-dark"><?php echo e($product->name); ?></div>
                                        
                                        <?php if($product->barcode): ?>
                                            <small class="text-muted d-block" style="font-size: 0.75rem;">
                                                <i class="bi bi-upc-scan me-1"></i><?php echo e($product->barcode); ?>

                                            </small>
                                        <?php endif; ?>

                                        <?php if(!$product->is_saleable): ?>
                                            <span class="badge bg-secondary" style="font-size: 0.65rem;"><i class="bi bi-eye-slash me-1"></i>Solo Insumo</span>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <span class="badge bg-light text-dark border"><?php echo e($product->category->name); ?></span>
                            </td>
                            <td class="fw-bold text-primary">S/ <?php echo e(number_format($product->price, 2)); ?></td>
                            <td>
                                <?php if(is_null($product->stock)): ?>
                                    <span class="text-muted small">--</span>
                                <?php elseif($product->stock <= 5): ?>
                                    <span class="badge bg-warning text-dark border border-warning">Bajo: <?php echo e($product->stock); ?></span>
                                <?php else: ?>
                                    <span class="badge bg-light text-success border border-success fw-bold"><?php echo e($product->stock); ?></span>
                                <?php endif; ?>
                            </td>
                            <td class="text-center">
                                <form action="<?php echo e(route('products.toggle', $product->id)); ?>" method="POST">
                                    <?php echo csrf_field(); ?>
                                    <button type="submit" class="btn btn-sm <?php echo e($product->is_active ? 'btn-outline-success' : 'btn-outline-secondary'); ?> rounded-pill px-3 fw-bold" style="font-size: 0.75rem;">
                                        <?php echo e($product->is_active ? 'ACTIVO' : 'INACTIVO'); ?>

                                    </button>
                                </form>
                            </td>
                            <td class="text-end pe-4">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#adjustStock<?php echo e($product->id); ?>" title="Ajustar Stock">
                                        <i class="bi bi-arrow-left-right"></i>
                                    </button>
                                    <a href="<?php echo e(route('products.edit', $product->id)); ?>" class="btn btn-sm btn-outline-primary" title="Editar">
                                        <i class="bi bi-pencil-square"></i>
                                    </a>
                                    <button type="button" class="btn btn-sm btn-outline-danger" onclick="if(confirm('¿Eliminar producto?')) document.getElementById('del-<?php echo e($product->id); ?>').submit()" title="Eliminar">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </div>
                                <form id="del-<?php echo e($product->id); ?>" action="<?php echo e(route('products.destroy', $product->id)); ?>" method="POST" class="d-none"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?></form>
                                
                                <div class="modal fade" id="adjustStock<?php echo e($product->id); ?>" tabindex="-1">
                                    <div class="modal-dialog modal-sm modal-dialog-centered">
                                        <form action="<?php echo e(route('products.adjust', $product->id)); ?>" method="POST" class="modal-content">
                                            <?php echo csrf_field(); ?>
                                            <div class="modal-header py-2 bg-light">
                                                <h6 class="modal-title fw-bold">Ajustar Stock</h6>
                                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                            </div>
                                            <div class="modal-body text-start">
                                                <p class="small mb-2">Producto: <strong><?php echo e($product->name); ?></strong></p>
                                                <div class="input-group mb-3">
                                                    <select name="type" class="form-select" style="max-width: 90px;">
                                                        <option value="add">➕</option>
                                                        <option value="sub">➖</option>
                                                    </select>
                                                    <input type="number" name="quantity" class="form-control" placeholder="Cantidad" required min="1">
                                                </div>
                                            </div>
                                            <div class="modal-footer p-1">
                                                <button class="btn btn-primary w-100 btn-sm">Guardar Ajuste</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>

                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="6" class="text-center py-5 text-muted">No hay productos registrados.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="card-footer bg-white border-0 py-3">
        <?php echo e($products->links()); ?>

    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\restaurante\resources\views/products/index.blade.php ENDPATH**/ ?>