using Microsoft.AspNetCore.Mvc; using PlanTempus.Application.Features.Localization.Services; namespace PlanTempus.Application.Features.Dashboard.Components; public class BookingItemViewComponent : ViewComponent { private readonly ILocalizationService _localization; public BookingItemViewComponent(ILocalizationService localization) { _localization = localization; } public IViewComponentResult Invoke(string key) { var model = BookingItemCatalog.Get(key, _localization); return View(model); } } public class BookingItemViewModel { public required string Key { get; init; } public required string TimeStart { get; init; } public required string TimeEnd { get; init; } public required string Service { get; init; } public required string CustomerName { get; init; } public required string EmployeeInitials { get; init; } public required string EmployeeName { get; init; } public required string Status { get; init; } public required string StatusText { get; init; } public string? IndicatorColor { get; init; } } internal class BookingItemData { public required string Key { get; init; } public required string TimeStart { get; init; } public required string TimeEnd { get; init; } public required string Service { get; init; } public required string CustomerName { get; init; } public required string EmployeeInitials { get; init; } public required string EmployeeName { get; init; } public required string Status { get; init; } public string? IndicatorColor { get; init; } } public static class BookingItemCatalog { private static readonly Dictionary StatusKeys = new() { ["completed"] = "dashboard.bookings.status.completed", ["inprogress"] = "dashboard.bookings.status.inProgress", ["confirmed"] = "dashboard.bookings.status.confirmed", ["pending"] = "dashboard.bookings.status.pending" }; private static readonly Dictionary Bookings = new() { ["booking-1"] = new BookingItemData { Key = "booking-1", TimeStart = "08:00", TimeEnd = "08:30", Service = "Herreklip", CustomerName = "Thomas Berg", EmployeeInitials = "MH", EmployeeName = "Maria Hansen", Status = "completed" }, ["booking-2"] = new BookingItemData { Key = "booking-2", TimeStart = "08:30", TimeEnd = "09:00", Service = "Dameklip", CustomerName = "Katrine Holm", EmployeeInitials = "AS", EmployeeName = "Anna Sørensen", Status = "completed" }, ["booking-3"] = new BookingItemData { Key = "booking-3", TimeStart = "09:00", TimeEnd = "09:30", Service = "Skægtrimning", CustomerName = "Mikkel Skov", EmployeeInitials = "PK", EmployeeName = "Peter Kristensen", Status = "completed" }, ["booking-4"] = new BookingItemData { Key = "booking-4", TimeStart = "10:30", TimeEnd = "11:00", Service = "Herreklip", CustomerName = "Jonas Petersen", EmployeeInitials = "MH", EmployeeName = "Maria Hansen", Status = "inprogress", IndicatorColor = "blue" }, ["booking-5"] = new BookingItemData { Key = "booking-5", TimeStart = "10:00", TimeEnd = "11:00", Service = "Føn + Styling", CustomerName = "Rikke Dam", EmployeeInitials = "LJ", EmployeeName = "Louise Jensen", Status = "inprogress", IndicatorColor = "purple" }, ["booking-6"] = new BookingItemData { Key = "booking-6", TimeStart = "11:00", TimeEnd = "12:00", Service = "Balayage", CustomerName = "Emma Christensen", EmployeeInitials = "AS", EmployeeName = "Anna Sørensen", Status = "confirmed", IndicatorColor = "teal" } }; public static BookingItemViewModel Get(string key, ILocalizationService localization) { if (!Bookings.TryGetValue(key, out var booking)) throw new KeyNotFoundException($"BookingItem with key '{key}' not found"); var statusText = StatusKeys.TryGetValue(booking.Status, out var statusKey) ? localization.Get(statusKey) : booking.Status; return new BookingItemViewModel { Key = booking.Key, TimeStart = booking.TimeStart, TimeEnd = booking.TimeEnd, Service = booking.Service, CustomerName = booking.CustomerName, EmployeeInitials = booking.EmployeeInitials, EmployeeName = booking.EmployeeName, Status = booking.Status, StatusText = statusText, IndicatorColor = booking.IndicatorColor }; } public static IEnumerable AllKeys => Bookings.Keys; }