using Microsoft.AspNetCore.Mvc;

namespace PlanTempus.Application.Features.Dashboard.Components;

/// <summary>
/// ViewComponent for rendering a waitlist item in the waitlist drawer.
/// </summary>
public class WaitlistItemViewComponent : ViewComponent
{
    public IViewComponentResult Invoke(string key)
    {
        var model = WaitlistItemCatalog.Get(key);
        return View(model);
    }
}

/// <summary>
/// ViewModel for the WaitlistItem component.
/// </summary>
public class WaitlistItemViewModel
{
    public required string Key { get; init; }
    public required string CustomerName { get; init; }
    public required string CustomerInitials { get; init; }
    public required string CustomerPhone { get; init; }
    public required string Service { get; init; }
    public required IReadOnlyList<string> PreferredPeriods { get; init; }
    public required string RegisteredDate { get; init; }
    public required string ExpiresDate { get; init; }
    public bool ExpiresSoon { get; init; }
}

/// <summary>
/// Catalog of waitlist items with demo data.
/// </summary>
public static class WaitlistItemCatalog
{
    private static readonly Dictionary<string, WaitlistItemViewModel> Items = new()
    {
        ["waitlist-1"] = new WaitlistItemViewModel
        {
            Key = "waitlist-1",
            CustomerName = "Emma Christensen",
            CustomerInitials = "EC",
            CustomerPhone = "+45 12 34 56 78",
            Service = "Dameklip + Farve",
            PreferredPeriods = ["Mandag-Onsdag", "Formiddag"],
            RegisteredDate = "2. jan 2026",
            ExpiresDate = "16. jan 2026",
            ExpiresSoon = false
        },
        ["waitlist-2"] = new WaitlistItemViewModel
        {
            Key = "waitlist-2",
            CustomerName = "Mikkel Sørensen",
            CustomerInitials = "MS",
            CustomerPhone = "+45 23 45 67 89",
            Service = "Herreklip",
            PreferredPeriods = ["Weekend"],
            RegisteredDate = "30. dec 2025",
            ExpiresDate = "6. jan 2026",
            ExpiresSoon = true
        },
        ["waitlist-3"] = new WaitlistItemViewModel
        {
            Key = "waitlist-3",
            CustomerName = "Lise Andersen",
            CustomerInitials = "LA",
            CustomerPhone = "+45 34 56 78 90",
            Service = "Balayage",
            PreferredPeriods = ["Tirsdag-Torsdag", "Eftermiddag"],
            RegisteredDate = "28. dec 2025",
            ExpiresDate = "11. jan 2026",
            ExpiresSoon = false
        },
        ["waitlist-4"] = new WaitlistItemViewModel
        {
            Key = "waitlist-4",
            CustomerName = "Peter Hansen",
            CustomerInitials = "PH",
            CustomerPhone = "+45 45 67 89 01",
            Service = "Herreklip + Skæg",
            PreferredPeriods = ["Fleksibel"],
            RegisteredDate = "27. dec 2025",
            ExpiresDate = "10. jan 2026",
            ExpiresSoon = false
        }
    };

    public static WaitlistItemViewModel Get(string key)
    {
        if (Items.TryGetValue(key, out var item))
            return item;

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

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