using Microsoft.AspNetCore.Mvc; using PlanTempus.Application.Features.Localization.Services; namespace PlanTempus.Application.Features.Services.Components; public class ServiceStatCardViewComponent : ViewComponent { private readonly ILocalizationService _localization; public ServiceStatCardViewComponent(ILocalizationService localization) { _localization = localization; } public IViewComponentResult Invoke(string key) { var model = ServiceStatCardCatalog.Get(key, _localization); return View(model); } } public class ServiceStatCardViewModel { public required string Key { get; init; } public required string Value { get; init; } public required string Label { get; init; } public string? Variant { get; init; } } internal class ServiceStatCardData { public required string Key { get; init; } public required string Value { get; init; } public required string LabelKey { get; init; } public string? Variant { get; init; } } public static class ServiceStatCardCatalog { private static readonly Dictionary Cards = new() { ["total-services"] = new ServiceStatCardData { Key = "total-services", Value = "78", LabelKey = "services.stats.totalServices", Variant = "teal" }, ["active-categories"] = new ServiceStatCardData { Key = "active-categories", Value = "14", LabelKey = "services.stats.activeCategories", Variant = "purple" }, ["average-price"] = new ServiceStatCardData { Key = "average-price", Value = "856 kr", LabelKey = "services.stats.averagePrice", Variant = "amber" } }; public static ServiceStatCardViewModel Get(string key, ILocalizationService localization) { if (!Cards.TryGetValue(key, out var card)) throw new KeyNotFoundException($"ServiceStatCard with key '{key}' not found"); return new ServiceStatCardViewModel { Key = card.Key, Value = card.Value, Label = localization.Get(card.LabelKey), Variant = card.Variant }; } public static IEnumerable AllKeys => Cards.Keys; }