using Microsoft.AspNetCore.Components;
using System.Net.Http.Json;
using GameIdeas.Resources;

namespace GameIdeas.BlazorApp.Layout;

public partial class MainLayout(
    IHttpClientFactory HttpClientFactory,
    TranslationService TranslationService,
    Translations Translations) : LayoutComponentBase
{
    protected override async Task OnInitializedAsync()
    {
        var client = HttpClientFactory.CreateClient("GameIdeas.WebAPI");
        var response = await client.GetAsync("api/Translations");
        var dictionary = await response.Content.ReadFromJsonAsync<Dictionary<string, string>>();
        if (dictionary != null)
        {
            TranslationService.Initialize(dictionary);
            ResourcesKey.Initialize(Translations);
        }

    }
}