@model foundation_system.Models.ViewModels.DashboardViewModel
@inject foundation_system.Services.IConfiguracionService ConfigService
@{
    ViewData["Title"] = "Dashboard";
    var nameFoundation = await ConfigService.GetValorOrDefaultAsync("NAME_FOUNDATION", "foundation_system");
    var description = await ConfigService.GetValorOrDefaultAsync("DESCRIPTION_FOUNDATION", "");
}


<div class="card-custom mt-4">
    <h4>Bienvenido al Sistema @nameFoundation</h4>

    <p class="mb-2">
        Este sistema ha sido diseñado para apoyar la gestión de la fundación,
        permitiendo administrar de forma segura los expedientes de los niños,
        el control de asistencia diaria, entre otros.
    </p>

    <hr />

    <p class="text-muted mb-0">
        @description;
    </p>
</div>

<div class="row g-4">
    @* Expediente Stats - Only visible if user has permission *@
    @if (Model.TienePermisoExpediente)
    {
        <div class="col-md-4">
            <div class="card-custom border-start border-4 border-primary">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 bg-primary bg-opacity-10 p-3 rounded">
                        <i class="bi bi-people-fill text-primary fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="text-muted small mb-1">Niños Activos</h6>
                        <h3 class="mb-0">@Model.TotalNinosActivos</h3>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card-custom border-start border-4 border-warning">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 bg-warning bg-opacity-10 p-3 rounded">
                        <i class="bi bi-cake-fill text-warning fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="text-muted small mb-1">Cumpleañeros del Mes</h6>
                        <h3 class="mb-0">@Model.CumpleanerosMes</h3>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card-custom border-start border-4 border-danger">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 bg-danger bg-opacity-10 p-3 rounded">
                        <i class="bi bi-exclamation-triangle-fill text-danger fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="text-muted small mb-1">Mayores de 14 años</h6>
                        <h3 class="mb-0">@Model.NinosMayores14</h3>
                    </div>
                </div>
            </div>
        </div>
    }

    @* Attendance Stats - Only visible if user has permission *@
    @if (Model.TienePermisoAsistencia)
    {
        <div class="col-md-4">
            <div class="card-custom border-start border-4 border-success">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 bg-success bg-opacity-10 p-3 rounded">
                        <i class="bi bi-calendar-check-fill text-success fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="text-muted small mb-1">Asistencia Hoy</h6>
                        <h3 class="mb-0">@Model.AsistenciasHoy <small class="text-muted fs-6">/ @Model.TotalNinosParaAsistencia</small></h3>
                        <small class="text-success">@Model.PorcentajeAsistenciaHoy%</small>
                    </div>
                </div>
            </div>
        </div>
    }

    @* Petty Cash Stats - Only visible if user has permission *@
    @if (Model.TienePermisoCajaChica)
    {
        <div class="col-md-4">
            <div class="card-custom border-start border-4 border-info">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 bg-info bg-opacity-10 p-3 rounded">
                        <i class="bi bi-wallet2 text-info fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="text-muted small mb-1">Saldo Caja Chica</h6>
                        <h3 class="mb-0">C$ @Model.SaldoCajaChica.ToString("N2")</h3>
                        @if (!string.IsNullOrEmpty(Model.NombreCajaActiva))
                        {
                            <small class="text-muted">@Model.NombreCajaActiva</small>
                        }
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card-custom border-start border-4 border-secondary">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0 bg-secondary bg-opacity-10 p-3 rounded">
                        <i class="bi bi-arrow-down-circle-fill text-secondary fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="text-muted small mb-1">Gastos del Mes</h6>
                        <h3 class="mb-0">C$ @Model.GastosMes.ToString("N2")</h3>
                        <small class="text-muted">@Model.MovimientosMes movimientos</small>
                    </div>
                </div>
            </div>
        </div>
    }
</div>

@* Birthday List - Only visible if user has permission and there are birthdays *@
@if (Model.TienePermisoExpediente && Model.ListaCumpleaneros.Any())
{
    <div class="card-custom mt-4">
        <h5 class="mb-3"><i class="bi bi-cake2 me-2"></i>Cumpleañeros de @DateTime.Now.ToString("MMMM")</h5>
        <div class="table-responsive">
            <table class="table table-sm table-hover mb-0">
                <thead>
                    <tr>
                        <th>Día</th>
                        <th>Nombre</th>
                        <th>Cumple</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var cumple in Model.ListaCumpleaneros)
                    {
                        <tr>
                            <td><span class="badge bg-warning text-dark">@cumple.DiaCumple</span></td>
                            <td>@cumple.NombreCompleto</td>
                            <td>@cumple.Edad años</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
}
