using Microsoft.AspNetCore.Mvc;
using PlanTempus.Application.Features.Localization.Services;

namespace PlanTempus.Application.Features.Dashboard.Components;

public class NotificationListViewComponent : ViewComponent
{
    private readonly ILocalizationService _localization;

    public NotificationListViewComponent(ILocalizationService localization)
    {
        _localization = localization;
    }

    public IViewComponentResult Invoke(string key)
    {
        var model = NotificationListCatalog.Get(key, _localization);
        return View(model);
    }
}

public class NotificationListViewModel
{
    public required string Key { get; init; }
    public required string Title { get; init; }
    public required string ActionText { get; init; }
    public required IReadOnlyList<string> NotificationKeys { get; init; }
}

internal class NotificationListData
{
    public required string Key { get; init; }
    public required string TitleKey { get; init; }
    public required string ActionTextKey { get; init; }
    public required IReadOnlyList<string> NotificationKeys { get; init; }
}

public static class NotificationListCatalog
{
    private static readonly Dictionary<string, NotificationListData> Lists = new()
    {
        ["recent-notifications"] = new NotificationListData
        {
            Key = "recent-notifications",
            TitleKey = "dashboard.notifications.title",
            ActionTextKey = "dashboard.notifications.markAllRead",
            NotificationKeys = ["notif-1", "notif-2", "notif-3", "notif-4"]
        }
    };

    public static NotificationListViewModel Get(string key, ILocalizationService localization)
    {
        if (!Lists.TryGetValue(key, out var list))
            throw new KeyNotFoundException($"NotificationList with key '{key}' not found");

        return new NotificationListViewModel
        {
            Key = list.Key,
            Title = localization.Get(list.TitleKey),
            ActionText = localization.Get(list.ActionTextKey),
            NotificationKeys = list.NotificationKeys
        };
    }
}
