using Front.Program.Services;
using Front.Program.ViewModels;
using Microsoft.AspNetCore.Components;

namespace Front.Program.Views.Academy;

public partial class AcademyMain : ComponentBase
{
    [Inject] NavigationManager Navigation { get; set; } = default!;
    [Inject] UserStateService UserStateService { get; set; } = default!;
    [Inject] QueryParamService QueryParamService { get; set; } = default!;
    [Inject] StorageService StorageService { get; set; } = default!;
    [Inject] LoadingService LoadingService { get; set; } = default!;
    
    // [Inject] LoggerService Logger {get; set;} = default!;
    
    protected override async Task OnInitializedAsync()
    {
        // 초기화 작업
        // await UserStateService.GetUserDataAsync();
        // if (UserStateService.isFirstCheck)
        // {
        //     // 첫 번째 체크 후에만 Academy 정보를 가져옴
        //     var academyResult = await UserStateService.GetAcademy();
        //     
        //     if (academyResult.success && academyResult.simpleAcademy.Count > 0)
        //     {
        //         UserStateService.academyItems = academyResult.simpleAcademy.ToArray();
        //     }
        // }
        //
        // URL 파라미터 처리
        LoggerService.Write("로거 테스트");
        
        var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
        
        LoggerService.Write("쿼리 있나?");
        // 쿼리 파라미터가 있는 경우에만 처리
        if (!string.IsNullOrEmpty(uri.Query))
        {
            var queryParam = QueryParamService.ParseQueryParam(uri);
            LoggerService.Write($"Parsed Query Parameters: {string.Join(", ", queryParam.Select(kv => $"{kv.Key}={kv.Value}"))}");
        }
        LoggerService.Write("쿼리 검사");

    }
}