using Microsoft.AspNetCore.Mvc; using PlanTempus.Application.Features.Localization.Services; namespace PlanTempus.Application.Features.Employees.Components; public class EmployeeRowViewComponent : ViewComponent { private readonly ILocalizationService _localization; public EmployeeRowViewComponent(ILocalizationService localization) { _localization = localization; } public IViewComponentResult Invoke(string key) { var model = EmployeeRowCatalog.Get(key, _localization); return View(model); } } public class EmployeeRowViewModel { public required string Key { get; init; } public required string Initials { get; init; } public required string Name { get; init; } public required string Email { get; init; } public required string Role { get; init; } public required string RoleText { get; init; } public required string Status { get; init; } public required string StatusText { get; init; } public required string LastActive { get; init; } public string? AvatarColor { get; init; } public bool IsOwner { get; init; } public bool IsInvited { get; init; } } internal class EmployeeRowData { public required string Key { get; init; } public required string Initials { get; init; } public required string Name { get; init; } public required string Email { get; init; } public required string Role { get; init; } public required string RoleKey { get; init; } public required string Status { get; init; } public required string StatusKey { get; init; } public required string LastActive { get; init; } public string? AvatarColor { get; init; } } public static class EmployeeRowCatalog { private static readonly Dictionary Employees = new() { ["employee-1"] = new EmployeeRowData { Key = "employee-1", Initials = "MJ", Name = "Maria Jensen", Email = "maria@salonbeauty.dk", Role = "owner", RoleKey = "employees.roles.owner", Status = "active", StatusKey = "employees.status.active", LastActive = "I dag, 14:32" }, ["employee-2"] = new EmployeeRowData { Key = "employee-2", Initials = "AS", Name = "Anna Sørensen", Email = "anna@salonbeauty.dk", Role = "admin", RoleKey = "employees.roles.admin", Status = "active", StatusKey = "employees.status.active", LastActive = "I dag, 12:15", AvatarColor = "purple" }, ["employee-3"] = new EmployeeRowData { Key = "employee-3", Initials = "LP", Name = "Louise Pedersen", Email = "louise@salonbeauty.dk", Role = "leader", RoleKey = "employees.roles.leader", Status = "active", StatusKey = "employees.status.active", LastActive = "I går, 17:45", AvatarColor = "blue" }, ["employee-4"] = new EmployeeRowData { Key = "employee-4", Initials = "KN", Name = "Katrine Nielsen", Email = "katrine@salonbeauty.dk", Role = "employee", RoleKey = "employees.roles.employee", Status = "active", StatusKey = "employees.status.active", LastActive = "27. dec, 09:30", AvatarColor = "amber" }, ["employee-5"] = new EmployeeRowData { Key = "employee-5", Initials = "SH", Name = "Sofie Hansen", Email = "sofie@salonbeauty.dk", Role = "employee", RoleKey = "employees.roles.employee", Status = "invited", StatusKey = "employees.status.invited", LastActive = "-", AvatarColor = "purple" } }; public static EmployeeRowViewModel Get(string key, ILocalizationService localization) { if (!Employees.TryGetValue(key, out var employee)) throw new KeyNotFoundException($"Employee with key '{key}' not found"); return new EmployeeRowViewModel { Key = employee.Key, Initials = employee.Initials, Name = employee.Name, Email = employee.Email, Role = employee.Role, RoleText = localization.Get(employee.RoleKey), Status = employee.Status, StatusText = localization.Get(employee.StatusKey), LastActive = employee.LastActive, AvatarColor = employee.AvatarColor, IsOwner = employee.Role == "owner", IsInvited = employee.Status == "invited" }; } public static IEnumerable AllKeys => Employees.Keys; }