@model foundation_system.Models.ViewModels.Reportes.ReporteMovimientosViewModel

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

<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-list-alt me-2 text-primary"></i>Movimientos de Caja Chica
            </h1>
            <p class="text-muted small mb-0">Detalle de ingresos y egresos por período</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>

    <!-- Resumen -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <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>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <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>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <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">Flujo Neto</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">@Model.SaldoPeriodo.ToString("C2")</div>
                        </div>
                    </div>
                </div>
            </div>
        </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">Detalle de Transacciones</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-striped" width="100%" cellspacing="0">
                    <thead class="table-light">
                        <tr>
                            <th>Fecha</th>
                            <th>Tipo</th>
                            <th>Concepto</th>
                            <th>Categoría</th>
                            <th>Usuario</th>
                            <th class="text-end">Monto</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Movimientos)
                        {
                            <tr>
                                <td>@item.Fecha.ToString("dd/MM/yyyy")</td>
                                <td>
                                    <span class="badge @(item.Tipo == "INGRESO" || item.Tipo == "REPOSICION" ? "bg-success" : "bg-danger")">
                                        @item.Tipo
                                    </span>
                                </td>
                                <td>@item.Concepto</td>
                                <td>@item.Categoria</td>
                                <td class="small">@item.Usuario</td>
                                <td class="text-end fw-bold @(item.Tipo == "INGRESO" || item.Tipo == "REPOSICION" ? "text-success" : "text-danger")">
                                    @item.Monto.ToString("C2")
                                </td>
                            </tr>
                        }
                        @if (!Model.Movimientos.Any())
                        {
                            <tr>
                                <td colspan="6" class="text-center text-muted py-4">No hay movimientos 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>
        .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; }
            .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; }
            
            .row { display: flex !important; flex-wrap: nowrap !important; gap: 10px; }
            .col-md-4 { flex: 0 0 33% !important; max-width: 33% !important; }
        }
    </style>
}
