<?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, []); ?> 
        Costos y Reportes — Recetas
     <?php $__env->endSlot(); ?>

    <!-- Resumen Cards -->
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="card border-0 shadow-sm rounded-4 h-100">
                <div class="card-body p-4 d-flex align-items-center">
                    <div class="rounded-circle bg-primary bg-opacity-10 d-flex align-items-center justify-content-center me-3" style="width: 48px; height: 48px;">
                        <i class="bi bi-journal-richtext text-primary fs-4"></i>
                    </div>
                    <div>
                        <div class="text-muted small fw-bold text-uppercase">Recetas Analizadas</div>
                        <div class="fs-4 fw-bold text-dark"><?php echo e($recetas->count()); ?></div>
                    </div>
                </div>
            </div>
        </div>
        
        <?php
            $criticas = $recetas->filter(fn($r) => $r['variacion'] > 15)->count();
            $alertas  = $recetas->filter(fn($r) => $r['variacion'] > 5 && $r['variacion'] <= 15)->count();
        ?>

        <div class="col-md-4">
            <div class="card border-0 shadow-sm rounded-4 h-100">
                <div class="card-body p-4 d-flex align-items-center">
                    <div class="rounded-circle bg-warning bg-opacity-10 d-flex align-items-center justify-content-center me-3" style="width: 48px; height: 48px;">
                        <i class="bi bi-exclamation-triangle-fill text-warning fs-4"></i>
                    </div>
                    <div>
                        <div class="text-muted small fw-bold text-uppercase">Costos en Alerta (>5%)</div>
                        <div class="fs-4 fw-bold text-warning"><?php echo e($alertas); ?></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="card border-0 shadow-sm rounded-4 h-100">
                <div class="card-body p-4 d-flex align-items-center">
                    <div class="rounded-circle bg-danger bg-opacity-10 d-flex align-items-center justify-content-center me-3" style="width: 48px; height: 48px;">
                        <i class="bi bi-x-octagon-fill text-danger fs-4"></i>
                    </div>
                    <div>
                        <div class="text-muted small fw-bold text-uppercase">Costos Críticos (>15%)</div>
                        <div class="fs-4 fw-bold text-danger"><?php echo e($criticas); ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Navegación Reportes -->
    <div class="card bg-white border-0 shadow-sm rounded-4 mb-4">
        <div class="card-body p-2">
            <ul class="nav nav-pills justify-content-center nav-fill gap-2 p-1">
                <li class="nav-item">
                    <a class="nav-link active rounded-pill fw-bold" href="<?php echo e(route('costos.index')); ?>">
                        <i class="bi bi-journal-richtext me-1"></i> Costeos de Recetas
                    </a>
                </li>
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('ver.reportes')): ?>
                <li class="nav-item">
                    <a class="nav-link text-muted rounded-pill fw-bold custom-nav-hover" href="<?php echo e(route('costos.compras')); ?>">
                        <i class="bi bi-cart-check me-1"></i> Análisis de Compras
                    </a>
                </li>
                <?php endif; ?>
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('ver.consolidado')): ?>
                <li class="nav-item">
                    <a class="nav-link text-muted rounded-pill fw-bold custom-nav-hover" href="<?php echo e(route('costos.consolidado')); ?>">
                        <i class="bi bi-bar-chart-fill me-1"></i> Consolidado Mensual
                    </a>
                </li>
                <?php endif; ?>
            </ul>
        </div>
    </div>

    <!-- Tabla de Costeos -->
    <div class="card border-0 shadow-sm rounded-4">
        <div class="card-header bg-white border-bottom pt-4 px-4 pb-3">
            <div class="d-flex justify-content-between align-items-center">
                <h5 class="fw-bold mb-0">Análisis de Costos por Receta</h5>
                <div class="text-muted small">
                    <i class="bi bi-info-circle me-1"></i> Los costos se calculan en base al último precio ingresado de los insumos.
                </div>
            </div>
        </div>
        <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;">Receta / Preparación</th>
                            <th class="py-3 text-center text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Porciones</th>
                            <th class="py-3 text-end text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Costo Esperado</th>
                            <th class="py-3 text-end text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Costo Real (Porción)</th>
                            <th class="py-3 text-center text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Variación</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 = $recetas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $r = $item['receta'];
                                $var = $item['variacion'];
                            ?>
                            <tr>
                                <td class="ps-4 py-3">
                                    <div class="fw-bold text-dark"><?php echo e($r->nombre); ?></div>
                                    <div class="text-muted small"><?php echo e($r->ingredientes->count()); ?> ingredientes</div>
                                </td>
                                <td class="py-3 text-center">
                                    <span class="badge bg-light text-dark border px-2 py-1 rounded-pill"><?php echo e($r->porciones); ?></span>
                                </td>
                                <td class="py-3 text-end text-muted fw-semibold">
                                    <?php echo e($moneda); ?> <?php echo e(number_format($r->costo_esperado, 2)); ?>

                                </td>
                                <td class="py-3 text-end">
                                    <div class="fw-bold text-dark"><?php echo e($moneda); ?> <?php echo e(number_format($item['costo_porcion'], 2)); ?></div>
                                    <div class="text-muted small" style="font-size: 0.7rem;">Total: <?php echo e($moneda); ?> <?php echo e(number_format($item['costo_real'], 2)); ?></div>
                                </td>
                                <td class="py-3 text-center">
                                    <?php if($var <= 5): ?>
                                        <span class="badge bg-success bg-opacity-10 text-success rounded-pill px-3 py-2 border border-success border-opacity-25" title="Costos estables">
                                            <?php if($var > 0): ?>+<?php endif; ?><?php echo e(number_format($var, 2)); ?>%
                                        </span>
                                    <?php elseif($var <= 15): ?>
                                        <span class="badge bg-warning bg-opacity-10 text-warning rounded-pill px-3 py-2 border border-warning border-opacity-25" title="Costos elevados">
                                            +<?php echo e(number_format($var, 2)); ?>%
                                        </span>
                                    <?php else: ?>
                                        <span class="badge bg-danger bg-opacity-10 text-danger rounded-pill px-3 py-2 border border-danger border-opacity-25" title="Costos críticos">
                                            +<?php echo e(number_format($var, 2)); ?>%
                                        </span>
                                    <?php endif; ?>
                                </td>
                                <td class="pe-4 py-3 text-end">
                                    <a href="<?php echo e(route('recetas.show', $r->id)); ?>" class="btn btn-sm btn-light border rounded-circle" title="Ver detalle de receta">
                                        <i class="bi bi-box-arrow-up-right text-primary"></i>
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="6" class="text-center py-5 text-muted">
                                    <i class="bi bi-book fs-1 d-block mb-3 text-light"></i>
                                    No hay recetas activas registradas para analizar.
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <?php $__env->startPush('styles'); ?>
    <style>
        .custom-nav-hover:hover {
            background-color: #f8fafc;
            color: var(--primary) !important;
        }
    </style>
    <?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/costos/index.blade.php ENDPATH**/ ?>