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

namespace Front.Program.Views.Project;

public partial class Auth : ComponentBase
{
    [Inject] NavigationManager NavigationManager { get; set; } = default!;
    // [Inject] IJSRuntime JS { get; set; } = default!;
    // [Inject] CookieService Cookie { get; set; } = default!;
    [Inject] HttpClient Http { get; set; } = default!;

    public async Task KakaoLogin()
    {
        var url = "/api/v1/out/user/kakao/auth";
        var response = await Http.GetFromJsonAsync<JsonElement>(url);
        var kakaoUrl = response.GetProperty("url").GetString();

        Console.WriteLine(kakaoUrl);
        
        if (!string.IsNullOrEmpty(kakaoUrl))
        {
            NavigationManager.NavigateTo(kakaoUrl, true); 
        }
    }
}