using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using eNavigator;
using MudBlazor.Services;
using eNavigator.Models;
using MudBlazor;
using Microsoft.AspNetCore.Components.Authorization;
using eNavigator.Authentication;
using eNavigator.Service;
using eNavigator.Interfaces;
//using eNavigator.Model;
//using eNavigator.Model;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddMudServices();
Console.WriteLine($"HostEnvironment.BaseAddress={builder.HostEnvironment.BaseAddress}");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddSingleton<IStateContainer, StateContainer>();
// builder.Services.AddScoped<IModelBase, ModelBase>();

builder.Services.AddHttpClient<IMarketDataServiceClient, MarketDataServiceClient>(httpClient =>
{
  String baseUri = builder.Configuration["Service_BaseUri"];
  String baseUriPort = builder.Configuration["Service_BaseUriPort"];
  String serviceProtocol = builder.Configuration["Service_Protocol"];

  String baseAddress = $"{serviceProtocol}{baseUri}:{baseUriPort}";
  Console.WriteLine($"Configuring {nameof(MarketDataServiceClient)} to {baseAddress}");
  httpClient.BaseAddress = new Uri(baseAddress);
});

builder.Services.AddMudServices(config =>
{
    config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomRight;
    config.SnackbarConfiguration.PreventDuplicates = false;
    config.SnackbarConfiguration.NewestOnTop = true;
    config.SnackbarConfiguration.ShowCloseIcon = true;
    config.SnackbarConfiguration.VisibleStateDuration = 10000;
    config.SnackbarConfiguration.HideTransitionDuration = 500;
    config.SnackbarConfiguration.ShowTransitionDuration = 500;
    config.SnackbarConfiguration.SnackbarVariant = Variant.Filled;
});

builder.Services.AddScoped<AuthenticationStateProvider, NavigatorAuthenticationStateProvider > ();

var app = builder.Build();

await app.RunAsync();

