using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Components;
using RpgRoller.Contracts;

namespace RpgRoller.Components.Pages.HomeControls;

[ExcludeFromCodeCoverage]
public partial class AppHeader
{
    private Task SelectMenuItemAsync(AppHeaderMenuItem item)
    {
        return item.OnSelected?.Invoke() ?? Task.CompletedTask;
    }

    [Parameter] public string Title { get; set; } = "RpgRoller";

    [Parameter] public UserSummary? User { get; set; }

    [Parameter] public bool ShowCampaign { get; set; }

    [Parameter] public string? CampaignName { get; set; }

    [Parameter] public bool ShowConnectionState { get; set; } = true;

    [Parameter] public string ConnectionStateLabel { get; set; } = "Offline fallback";

    [Parameter] public string ConnectionStateCssClass { get; set; } = "offline";

    [Parameter] public bool IsMenuOpen { get; set; }

    [Parameter] public string MenuButtonId { get; set; } = "screen-menu-button";

    [Parameter] public string MenuId { get; set; } = "screen-menu";

    [Parameter] public IReadOnlyList<AppHeaderMenuItem> MenuItems { get; set; } = [];

    [Parameter] public EventCallback ToggleMenuRequested { get; set; }

    [Parameter] public EventCallback LogoutRequested { get; set; }
}

public sealed class AppHeaderMenuItem
{
    public string Label { get; init; } = string.Empty;
    public bool IsActive { get; init; }
    public Func<Task>? OnSelected { get; init; }
}