using Microsoft.AspNetCore.Mvc; using PlanTempus.Application.Features.Localization.Services; namespace PlanTempus.Application.Features.Dashboard.Components; public class QuickStatListViewComponent : ViewComponent { private readonly ILocalizationService _localization; public QuickStatListViewComponent(ILocalizationService localization) { _localization = localization; } public IViewComponentResult Invoke(string key) { var model = QuickStatListCatalog.Get(key, _localization); return View(model); } } public class QuickStatListViewModel { public required string Key { get; init; } public required string Title { get; init; } public required string Icon { get; init; } public required IReadOnlyList StatKeys { get; init; } } internal class QuickStatListData { public required string Key { get; init; } public required string TitleKey { get; init; } public required string Icon { get; init; } public required IReadOnlyList StatKeys { get; init; } } public static class QuickStatListCatalog { private static readonly Dictionary Lists = new() { ["this-week"] = new QuickStatListData { Key = "this-week", TitleKey = "dashboard.quickStats.title", Icon = "chart-line-up", StatKeys = ["bookings-week", "revenue-week", "new-customers", "avg-occupancy"] } }; public static QuickStatListViewModel Get(string key, ILocalizationService localization) { if (!Lists.TryGetValue(key, out var list)) throw new KeyNotFoundException($"QuickStatList with key '{key}' not found"); return new QuickStatListViewModel { Key = list.Key, Title = localization.Get(list.TitleKey), Icon = list.Icon, StatKeys = list.StatKeys }; } }