using Blazored.LocalStorage;
using FNZCM.BlazorWasm.Helpers;
using FNZCM.BlazorWasm.UI.Views.Default;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System.Text;

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddBlazoredLocalStorage();

builder.Services.AddScoped(sp =>
{
    var http = new HttpClient();

#if DEBUG
    http.BaseAddress = new Uri(
        //"http://fnz-server"
        "http://d3ns2.topcl.net:38964"
        );
#else
    var NavManager = sp.GetService<Microsoft.AspNetCore.Components.NavigationManager>();
    var ba = new Uri($"{NavManager.ToAbsoluteUri("/").GetLeftPart(UriPartial.Scheme | UriPartial.Authority)}");
    http.BaseAddress = ba;
#endif

    return http;
});

builder.Services.AddSingleton<FnzDataSetSingleto>();
builder.Services.AddScoped<ApiClient>();
builder.Services.AddScoped<FnzDataSetHelper>();
builder.Services.AddScoped<LocalStorageHelper>();
builder.Services.AddScoped<PlaylistHelper>();

builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

await builder.Build().RunAsync();
