using CCharLearn;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MudBlazor;
using Blazored.LocalStorage;
using MudBlazor.Services;
using Toolbelt.Blazor.Extensions.DependencyInjection;

namespace CCharLearn
{
    public class Program
    {

        public static int CCharsLeft = 0;
        public static Action UpdateUiEvent;

        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("#app");
            builder.RootComponents.Add<HeadOutlet>("head::after");

            builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
            builder.Services.AddMudServices(config =>
            {
                config.SnackbarConfiguration.ShowTransitionDuration = 100;
                config.SnackbarConfiguration.HideTransitionDuration = 100;
                config.SnackbarConfiguration.VisibleStateDuration = 5000;
                config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.TopCenter;
            });
            builder.Services.AddBlazoredLocalStorage();
            builder.Services.AddSpeechSynthesis();

            await builder.Build().RunAsync();
        }

        public static void InvokeUiUpdate() => UpdateUiEvent?.Invoke();
    }
}