using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Net.Http.Json;
using System.Text.Json;
using Front.Program.Models;
using Front.Program.Services;
using Front.Program.ViewModels;

namespace Front.Program.Views.Project.Common;

public partial class TopProjectNav : ComponentBase
{
    [Inject] NavigationManager NavigationManager { get; set; } = default!;
    
    [Inject] UserStateService UserStateService { get; set; } = default!;
    
    [Inject] IJSRuntime JS { get; set; } = default!;

    [Inject] HttpClient Http { get; set; } = default!;

    protected bool isOpen = false;

    protected override async Task OnInitializedAsync()
    {
        LoggerService.Write("TOPNAV_OnInitializedAsync");
        
        if (!UserStateService.isFirstCheck) await UserStateService.GetUserDataAsync();
    }

    public void OnClickMenuDown()
    {
        isOpen = !isOpen;
    }

    public void OnClickRedirect()
    {
        if (isOpen) isOpen = !isOpen;
        NavigationManager.NavigateTo("/about");
    }
    
    public void OnClickLogin()
    {
        if (isOpen) isOpen = !isOpen;
        NavigationManager.NavigateTo("/auth");
    }

    public async Task OnClickLogout()
    {
        await UserStateService.ClearUserStateAsnyc();
        //
        // if (await UserViewModel.ClearUserData())
        // {
        //     isLogin = false;
        // }
    }
}