using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Dashboard.Components;
///
/// ViewComponent for rendering a quick stat item in the sidebar.
///
public class QuickStatViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public QuickStatViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = QuickStatCatalog.Get(key, _localization);
return View(model);
}
}
///
/// ViewModel for the QuickStat component.
///
public class QuickStatViewModel
{
public required string Key { get; init; }
public required string Value { get; init; }
public required string Label { get; init; }
}
internal class QuickStatData
{
public required string Key { get; init; }
public required string Value { get; init; }
public required string LabelKey { get; init; }
}
///
/// Catalog of available quick stats with their data.
///
public static class QuickStatCatalog
{
private static readonly Dictionary Stats = new()
{
["bookings-week"] = new QuickStatData
{
Key = "bookings-week",
Value = "47",
LabelKey = "dashboard.quickStats.bookings"
},
["revenue-week"] = new QuickStatData
{
Key = "revenue-week",
Value = "38.200 kr",
LabelKey = "dashboard.quickStats.revenue"
},
["new-customers"] = new QuickStatData
{
Key = "new-customers",
Value = "8",
LabelKey = "dashboard.quickStats.newCustomers"
},
["avg-occupancy"] = new QuickStatData
{
Key = "avg-occupancy",
Value = "72%",
LabelKey = "dashboard.quickStats.avgOccupancy"
}
};
public static QuickStatViewModel Get(string key, ILocalizationService localization)
{
if (!Stats.TryGetValue(key, out var stat))
throw new KeyNotFoundException($"QuickStat with key '{key}' not found");
return new QuickStatViewModel
{
Key = stat.Key,
Value = stat.Value,
Label = localization.Get(stat.LabelKey)
};
}
public static IEnumerable AllKeys => Stats.Keys;
}