using Microsoft.AspNetCore.Mvc;

namespace PlanTempus.Application.Features.Dashboard.Components;

public class BookingItemViewComponent : ViewComponent
{
    public IViewComponentResult Invoke(string key)
    {
        var model = BookingItemCatalog.Get(key);
        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 string? IndicatorColor { get; init; }

    public string StatusText => Status switch
    {
        "completed" => "Gennemført",
        "inprogress" => "I gang",
        "confirmed" => "Bekræftet",
        "pending" => "Afventer",
        _ => Status
    };
}

public static class BookingItemCatalog
{
    private static readonly Dictionary<string, BookingItemViewModel> Bookings = new()
    {
        ["booking-1"] = new BookingItemViewModel
        {
            Key = "booking-1",
            TimeStart = "08:00",
            TimeEnd = "08:30",
            Service = "Herreklip",
            CustomerName = "Thomas Berg",
            EmployeeInitials = "MH",
            EmployeeName = "Maria Hansen",
            Status = "completed"
        },
        ["booking-2"] = new BookingItemViewModel
        {
            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 BookingItemViewModel
        {
            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 BookingItemViewModel
        {
            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 BookingItemViewModel
        {
            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 BookingItemViewModel
        {
            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)
    {
        if (Bookings.TryGetValue(key, out var booking))
            return booking;

        throw new KeyNotFoundException($"BookingItem with key '{key}' not found");
    }

    public static IEnumerable<string> AllKeys => Bookings.Keys;
}
