@page "/"
@using phronCare.UIBlazor.Pages.Authorization
@inject NavigationManager Navigation

<PageTitle>PhronCare</PageTitle>

<AuthorizeView>
    <Authorized>
        <section class="home-dashboard">
            <div class="home-hero">
                <div>
                    <span class="home-eyebrow">BackOffice operativo</span>
                    <h1>Bienvenido a PhronCare</h1>
                    <p>
                        Gestion integral para empresas de internacion domiciliaria,
                        ortopedia y prestaciones medicas.
                    </p>
                </div>
                <div class="home-hero-status" aria-label="Estado general">
                    <span class="home-status-dot"></span>
                    Plataforma operativa
                </div>
            </div>

            <div class="home-section-header">
                <h2>Accesos rapidos</h2>
                <span>Modulos principales</span>
            </div>

            <div class="quick-access-grid">
                @foreach (var item in QuickAccessItems)
                {
                    <button type="button" class="quick-access-card" @onclick="() => NavigateTo(item.Url)">
                        <span class="quick-access-icon @item.AccentClass">
                            <i class="@item.Icon" aria-hidden="true"></i>
                        </span>
                        <span class="quick-access-content">
                            <strong>@item.Title</strong>
                            <small>@item.Description</small>
                        </span>
                        <i class="fas fa-chevron-right quick-access-arrow" aria-hidden="true"></i>
                    </button>
                }
            </div>

            <div class="home-content-grid">
                <section>
                    <div class="home-section-header">
                        <h2>Resumen operativo</h2>
                        <span>Valores temporales</span>
                    </div>

                    <div class="kpi-grid">
                        @foreach (var item in SummaryItems)
                        {
                            <div class="kpi-card">
                                <div class="kpi-icon @item.AccentClass">
                                    <i class="@item.Icon" aria-hidden="true"></i>
                                </div>
                                <div>
                                    <strong>@item.Value</strong>
                                    <span>@item.Title</span>
                                </div>
                            </div>
                        }
                    </div>
                </section>

                <section>
                    <div class="home-section-header">
                        <h2>Actividad reciente</h2>
                        <span>Simulada</span>
                    </div>

                    <div class="activity-list">
                        @foreach (var item in RecentActivity)
                        {
                            <div class="activity-item">
                                <span class="activity-icon @item.AccentClass">
                                    <i class="@item.Icon" aria-hidden="true"></i>
                                </span>
                                <div>
                                    <strong>@item.Title</strong>
                                    <small>@item.Description</small>
                                </div>
                            </div>
                        }
                    </div>
                </section>
            </div>
        </section>
    </Authorized>
    <NotAuthorized>
        <LoginPage />
    </NotAuthorized>
</AuthorizeView>

@code
{
    private readonly List<QuickAccessItem> QuickAccessItems =
    [
        new("Pacientes", "Gestion de pacientes y datos asistenciales.", "/sales/patients", "fas fa-user-injured", "accent-blue"),
        new("Presupuestos", "Consulta y seguimiento de presupuestos.", "/quotes/dashboard", "fas fa-file-invoice-dollar", "accent-green"),
        new("Ventas", "Clientes, productos y circuito comercial.", "/sales/customers", "fas fa-briefcase", "accent-indigo"),
        new("Remitos", "Emision y control de remitos.", "/deliverynotes", "fas fa-truck", "accent-orange"),
        new("Sales Documents", "Documentos comerciales y facturacion.", "/salesdocuments", "fas fa-receipt", "accent-teal"),
        new("Stock", "Productos medicos y trazabilidad.", "/stock/products", "fas fa-boxes-stacked", "accent-violet"),
        new("Tickets", "Alta y seguimiento de tickets.", "/dashboardpanel", "fas fa-ticket-alt", "accent-red")
    ];

    private readonly List<SummaryItem> SummaryItems =
    [
        new("Presupuestos Activos", "128", "fas fa-file-signature", "accent-green"),
        new("Remitos Emitidos", "42", "fas fa-truck-fast", "accent-orange"),
        new("Facturas Pendientes", "15", "fas fa-file-invoice", "accent-teal"),
        new("Tickets Abiertos", "6", "fas fa-headset", "accent-red")
    ];

    private readonly List<ActivityItem> RecentActivity =
    [
        new("Presupuesto aprobado", "Hace 12 minutos", "fas fa-check-circle", "accent-green"),
        new("Remito emitido", "Hace 38 minutos", "fas fa-truck", "accent-orange"),
        new("Factura generada", "Hoy, 10:45", "fas fa-receipt", "accent-teal"),
        new("Ticket cerrado", "Hoy, 09:20", "fas fa-circle-check", "accent-red")
    ];

    private void NavigateTo(string url)
    {
        Navigation.NavigateTo(url);
    }

    private sealed record QuickAccessItem(string Title, string Description, string Url, string Icon, string AccentClass);
    private sealed record SummaryItem(string Title, string Value, string Icon, string AccentClass);
    private sealed record ActivityItem(string Title, string Description, string Icon, string AccentClass);
}
