@model foundation_system.Models.ViewModels.Reportes.ReporteHistoricoSaldosViewModel

@{
    ViewData["Title"] = "Histórico de Saldos";
}

<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-chart-line me-2 text-primary"></i>Histórico de Saldos
            </h1>
            <p class="text-muted small mb-0">Evolución diaria del saldo de caja</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>
        </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="inicio" class="form-label fw-bold small">Desde</label>
                    <input type="date" class="form-control" id="inicio" name="inicio" 
                           value="@Model.FechaInicio.ToString("yyyy-MM-dd")">
                </div>
                <div class="col-auto">
                    <label for="fin" class="form-label fw-bold small">Hasta</label>
                    <input type="date" class="form-control" id="fin" name="fin" 
                           value="@Model.FechaFin.ToString("yyyy-MM-dd")">
                </div>
                <div class="col-auto">
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-sync-alt me-2"></i>Generar
                    </button>
                </div>
            </form>
        </div>
    </div>

    <!-- Tabla Detalle -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Saldos Diarios</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" width="100%" cellspacing="0">
                    <thead class="table-light">
                        <tr>
                            <th>Fecha</th>
                            <th class="text-end">Saldo Inicial</th>
                            <th class="text-end text-success">Ingresos</th>
                            <th class="text-end text-danger">Egresos</th>
                            <th class="text-end fw-bold">Saldo Final</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Saldos)
                        {
                            <tr>
                                <td>@item.Fecha.ToString("dd/MM/yyyy")</td>
                                <td class="text-end">@item.SaldoInicial.ToString("N2")</td>
                                <td class="text-end text-success">@item.Ingresos.ToString("N2")</td>
                                <td class="text-end text-danger">@item.Egresos.ToString("N2")</td>
                                <td class="text-end fw-bold">@item.SaldoFinal.ToString("C2")</td>
                            </tr>
                        }
                        @if (!Model.Saldos.Any())
                        {
                            <tr>
                                <td colspan="5" class="text-center text-muted py-4">No hay datos en este período.</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </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>
        @@media print {
            .d-print-none, .no-print { display: none !important; }
            .sidebar, .top-header, .footer { display: none !important; }
            .main-content { margin-left: 0 !important; padding: 0 !important; }
            .page-container { padding: 0 !important; }
            .container-fluid { width: 100% !important; padding: 0 !important; }
            body { background: white !important; }
            .card { border: 1px solid #ddd !important; box-shadow: none !important; }
            .card-body { padding: 1rem !important; }
            .btn { display: none !important; }
        }
    </style>
}
