using Microsoft.AspNetCore.Mvc;

namespace PlanTempus.Application.Features.Dashboard.Components;

/// <summary>
/// ViewComponent for rendering a quick stat item in the sidebar.
/// </summary>
public class QuickStatViewComponent : ViewComponent
{
    public IViewComponentResult Invoke(string key)
    {
        var model = QuickStatCatalog.Get(key);
        return View(model);
    }
}

/// <summary>
/// ViewModel for the QuickStat component.
/// </summary>
public class QuickStatViewModel
{
    public required string Key { get; init; }
    public required string Value { get; init; }
    public required string Label { get; init; }
}

/// <summary>
/// Catalog of available quick stats with their data.
/// </summary>
public static class QuickStatCatalog
{
    private static readonly Dictionary<string, QuickStatViewModel> Stats = new()
    {
        ["bookings-week"] = new QuickStatViewModel
        {
            Key = "bookings-week",
            Value = "47",
            Label = "Bookinger"
        },
        ["revenue-week"] = new QuickStatViewModel
        {
            Key = "revenue-week",
            Value = "38.200 kr",
            Label = "Omsætning"
        },
        ["new-customers"] = new QuickStatViewModel
        {
            Key = "new-customers",
            Value = "8",
            Label = "Nye kunder"
        },
        ["avg-occupancy"] = new QuickStatViewModel
        {
            Key = "avg-occupancy",
            Value = "72%",
            Label = "Gns. belægning"
        }
    };

    public static QuickStatViewModel Get(string key)
    {
        if (Stats.TryGetValue(key, out var stat))
            return stat;

        throw new KeyNotFoundException($"QuickStat with key '{key}' not found");
    }

    public static IEnumerable<string> AllKeys => Stats.Keys;
}
