using Blazored.Modal;
using Blazored.Toast;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using phronCare.UIBlazor;
using phronCare.UIBlazor.Services.Authorization;
using phronCare.UIBlazor.Services.Integrations;
using phronCare.UIBlazor.Services.Lookups;
using phronCare.UIBlazor.Services.Sales.DeliveryNotes;
using phronCare.UIBlazor.Services.Sales;
using phronCare.UIBlazor.Services.Sales.Quotes;
using phronCare.UIBlazor.Services.Sales.SalesDocuments;
using phronCare.UIBlazor.Services.Stock;
using phronCare.UIBlazor.Services.Stock.Expeditions;
using phronCare.UIBlazor.Services.Tickets;
using phronCare.UIBlazor.Services.UI;
using System.Globalization;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

var culture = new CultureInfo("es-AR");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
#region Proveedor de Autorizacion
builder.Services.AddScoped<CustomAuthorizationProvider>();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthorizationProvider>(p => p.GetRequiredService<CustomAuthorizationProvider>());
builder.Services.AddScoped<ILoginService, CustomAuthorizationProvider>(p => p.GetRequiredService<CustomAuthorizationProvider>());
builder.Services.AddAuthorizationCore();

#endregion

#region Load Configuration
var config = builder.Configuration.GetSection("BaseAd").Value;
if (config != null)
{
    builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(config) });
}
#endregion
#region Injection Dependencis
InjectDependencies(builder);
#endregion
#region UI
builder.Services.AddBlazoredModal();
builder.Services.AddBlazoredToast();
builder.Services.AddSingleton<NavMenuService>();
#endregion

await builder.Build().RunAsync();

static void InjectDependencies(WebAssemblyHostBuilder builder)
{
    builder.Services.AddScoped<ISalesLookupService, SalesLookupService>();
    builder.Services.AddScoped<IStockLookUpService, StockLookUpService>();
    builder.Services.AddScoped<IExchangeRateService, ExchangeRateService>();
    builder.Services.AddScoped<IStockScanService, StockScanService>();
    builder.Services.AddScoped<IExpeditionService, ExpeditionService>();
    builder.Services.AddScoped<IQuoteService,QuoteService>();
    builder.Services.AddScoped<IDeliveryNoteService, DeliveryNoteService>();
    builder.Services.AddScoped<ISalesDocumentService, SalesDocumentService>();

    builder.Services.AddScoped<ExchangeRateService>();
    builder.Services.AddScoped<TicketsService>();
    builder.Services.AddScoped<CustomerService>();
    builder.Services.AddScoped<TaxConditionService>();
    builder.Services.AddScoped<AccountTypeService>();
    builder.Services.AddScoped<DocumentTypeService>();
    builder.Services.AddScoped<InstitutionService>();
    builder.Services.AddScoped<ProductService>();
    builder.Services.AddScoped<BusinessUnitService>();
    builder.Services.AddScoped<ProfessionalService>();
    builder.Services.AddScoped<PeopleService>();
    builder.Services.AddScoped<ProfessionalSpecialtyService>();
    builder.Services.AddScoped<ProductCategoryService>();
    builder.Services.AddScoped<PatientService>();
    builder.Services.AddScoped<ProductDivisionService>();
    builder.Services.AddScoped<LSProductService>();
    builder.Services.AddScoped<LSUnitOfMeasureService>();
    builder.Services.AddScoped<ExpeditionService>();
}