PlanTempusApp/PlanTempus.Application/Features/Employees/Components/EmployeeStatCard/EmployeeStatCardViewComponent.cs
Janus C. H. Knudsen 15579acba8 Various CSS work
2026-01-12 22:10:57 +01:00

80 lines
2.3 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;
namespace PlanTempus.Application.Features.Employees.Components;
public class EmployeeStatCardViewComponent : ViewComponent
{
private readonly ILocalizationService _localization;
public EmployeeStatCardViewComponent(ILocalizationService localization)
{
_localization = localization;
}
public IViewComponentResult Invoke(string key)
{
var model = EmployeeStatCardCatalog.Get(key, _localization);
return View(model);
}
}
public class EmployeeStatCardViewModel
{
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 EmployeeStatCardData
{
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 EmployeeStatCardCatalog
{
private static readonly Dictionary<string, EmployeeStatCardData> Cards = new()
{
["active-employees"] = new EmployeeStatCardData
{
Key = "active-employees",
Value = "4",
LabelKey = "employees.stats.activeEmployees",
Variant = "teal"
},
["pending-invitations"] = new EmployeeStatCardData
{
Key = "pending-invitations",
Value = "1",
LabelKey = "employees.stats.pendingInvitations",
Variant = "amber"
},
["roles-defined"] = new EmployeeStatCardData
{
Key = "roles-defined",
Value = "4",
LabelKey = "employees.stats.rolesDefined",
Variant = "purple"
}
};
public static EmployeeStatCardViewModel Get(string key, ILocalizationService localization)
{
if (!Cards.TryGetValue(key, out var card))
throw new KeyNotFoundException($"EmployeeStatCard with key '{key}' not found");
return new EmployeeStatCardViewModel
{
Key = card.Key,
Value = card.Value,
Label = localization.Get(card.LabelKey),
Variant = card.Variant
};
}
public static IEnumerable<string> AllKeys => Cards.Keys;
}