@model foundation_system.Models.ViewModels.Reportes.ReporteArqueoViewModel

@{
    ViewData["Title"] = "Arqueo de Caja";
}

<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0 text-gray-800">
                <i class="fas fa-cash-register me-2 text-primary"></i>Arqueo de Caja
            </h1>
            <p class="text-muted small mb-0">Reporte diario de movimientos de efectivo</p>
        </div>
        <div class="d-flex gap-2">
            <button onclick="window.print()" class="btn btn-outline-secondary">
                <i class="fas fa-print me-2"></i>Imprimir
            </button>
            <!-- TODO: Implement Excel Export -->
            <button class="btn btn-success" disabled title="Próximamente">
                <i class="fas fa-file-excel me-2"></i>Exportar Excel
            </button>
        </div>
    </div>

    <!-- Filtro de Fecha -->
    <div class="card shadow-sm mb-4 d-print-none">
        <div class="card-body py-3">
            <form method="get" class="row g-3 align-items-end">
                <div class="col-auto">
                    <label for="fecha" class="form-label fw-bold small">Fecha de Arqueo</label>
                    <input type="date" class="form-control" id="fecha" name="fecha" 
                           value="@Model.Fecha.ToString("yyyy-MM-dd")" onchange="this.form.submit()">
                </div>
                <div class="col-auto">
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-sync-alt me-2"></i>Actualizar
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- Resumen Principal -->
    <div class="row g-4 mb-4">
        <!-- Saldo Inicial -->
        <div class="col-md-3">
            <div class="card border-left-primary shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Saldo Inicial</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">@Model.SaldoInicial.ToString("C2")</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-calendar-minus fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Ingresos -->
        <div class="col-md-3">
            <div class="card border-left-success shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Total Ingresos</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">@Model.TotalIngresos.ToString("C2")</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-arrow-up fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Egresos -->
        <div class="col-md-3">
            <div class="card border-left-danger shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-danger text-uppercase mb-1">Total Egresos</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">@Model.TotalEgresos.ToString("C2")</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-arrow-down fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Saldo Final -->
        <div class="col-md-3">
            <div class="card border-left-info shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-info text-uppercase mb-1">Saldo Final Teórico</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">@Model.SaldoFinalTeorico.ToString("C2")</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-wallet fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Detalle Impreso -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Detalle del Arqueo</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" width="100%" cellspacing="0">
                    <thead class="table-light">
                        <tr>
                            <th>Concepto</th>
                            <th class="text-end">Monto</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong>(+) Saldo Inicial</strong></td>
                            <td class="text-end">@Model.SaldoInicial.ToString("C2")</td>
                        </tr>
                        <tr>
                            <td colspan="2" class="bg-light small fw-bold text-uppercase">Ingresos</td>
                        </tr>
                        <tr>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;Efectivo / Reposiciones</td>
                            <td class="text-end">@Model.IngresosEfectivo.ToString("C2")</td>
                        </tr>
                        @if (Model.IngresosCheque > 0) {
                        <tr>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;Cheques</td>
                            <td class="text-end">@Model.IngresosCheque.ToString("C2")</td>
                        </tr>
                        }
                        @if (Model.IngresosTransferencia > 0) {
                        <tr>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;Transferencias</td>
                            <td class="text-end">@Model.IngresosTransferencia.ToString("C2")</td>
                        </tr>
                        }
                        <tr class="table-success">
                            <td><strong>(=) Total Ingresos</strong></td>
                            <td class="text-end fw-bold">@Model.TotalIngresos.ToString("C2")</td>
                        </tr>

                        <tr>
                            <td colspan="2" class="bg-light small fw-bold text-uppercase">Egresos</td>
                        </tr>
                        <tr>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;Gastos Operativos</td>
                            <td class="text-end">@Model.TotalEgresos.ToString("C2")</td>
                        </tr>
                        <tr class="table-danger">
                            <td><strong>(=) Total Egresos</strong></td>
                            <td class="text-end fw-bold">@Model.TotalEgresos.ToString("C2")</td>
                        </tr>
                        
                        <tr class="table-primary border-top-2">
                            <td class="h5"><strong>Saldo Final Teórico</strong></td>
                            <td class="text-end h5 fw-bold">@Model.SaldoFinalTeorico.ToString("C2")</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <!-- Sección de Firmas (Solo visible en impresión) -->
            <div class="row mt-5 pt-5 d-none d-print-flex">
                <div class="col-6 text-center">
                    <div class="border-top border-dark w-75 mx-auto pt-2">
                        <p class="mb-0 fw-bold">Entregado Por</p>
                        <small>Cajero / Responsable</small>
                    </div>
                </div>
                <div class="col-6 text-center">
                    <div class="border-top border-dark w-75 mx-auto pt-2">
                        <p class="mb-0 fw-bold">Revisado Por</p>
                        <small>Administrador / Auditor</small>
                    </div>
                </div>
            </div>
            
            <div class="text-center mt-4 text-muted small">
                <p>Generado por: @Model.GeneradoPor | Fecha: @Model.FechaGeneracion.ToString("g")</p>
            </div>
        </div>
    </div>
</div>

@section Styles {
    <style>
        .border-left-primary { border-left: .25rem solid #4e73df!important; }
        .border-left-success { border-left: .25rem solid #1cc88a!important; }
        .border-left-info { border-left: .25rem solid #36b9cc!important; }
        .border-left-danger { border-left: .25rem solid #e74a3b!important; }

        @@media print {
            .d-print-none, .no-print { display: none !important; }
            .d-print-flex { display: flex !important; }
            
            /* Hide Layout Elements */
            .sidebar, .top-header, .footer { display: none !important; }
            .main-content { margin-left: 0 !important; padding: 0 !important; }
            .page-container { padding: 0 !important; }
            
            /* Reset Container */
            .container-fluid { width: 100% !important; padding: 0 !important; }
            body { background: white !important; }
            
            /* Card Styling for Print */
            .card { border: 1px solid #ddd !important; box-shadow: none !important; }
            .card-body { padding: 1rem !important; }
            .btn { display: none !important; }

            /* Force Row Layout for Summary Cards */
            .row {
                display: flex !important;
                flex-wrap: nowrap !important;
                gap: 10px;
            }
            .col-md-3 {
                flex: 0 0 25% !important;
                max-width: 25% !important;
            }
        }
    </style>
}
