using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;

namespace Insight.Web.Components.Navbars;

public partial class Account
{
    [CascadingParameter] public IReadOnlyDictionary<string, object>? RouteValues { get; set; }

    [Inject] private NavigationManager NavigationManager { get; init; } = default!;
    [Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; init; } = default!;

    private string Uri { get; set; } = string.Empty;
    private string Title { get; set; } = "Account";

    protected override async Task OnInitializedAsync()
    {
        var cp = (await AuthenticationStateProvider.GetAuthenticationStateAsync()).User;
        //Title = $"Account: {cp?.Identity?.Name}";

        Uri = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
    }

    protected override void OnAfterRender(bool firstRender)
    {
        Uri = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
    }
}