using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using ReAct_PME.WebUI.ServicesUI;

namespace ReAct_PME.WebUI.Pages.AuthLogin
{
    public partial class AuthLogout : ComponentBase
    {
        [Inject] private NavigationManager Navigation { get; set; } = default!;
        [Inject] private Blazored.LocalStorage.ILocalStorageService localStorage { get; set; } = default!;
        [Inject] private ReAct_PME.WebUI.ServicesUI.AuthService AuthService { get; set; } = default!;
        [Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;

        protected override async Task OnInitializedAsync()
        {
            await LogoutAsync();
            Navigation.NavigateTo("/login");
        }

        public async Task LogoutAsync()
        {
            var authProvider = (CustomAuthenticationStateProvider)AuthenticationStateProvider;
            authProvider.NotifyUserLogout();
            await localStorage.RemoveItemAsync("authToken");
            AuthService.Deconnect();
        }
    }
}

                