using System;
using iElection.Services;
using iElection.Services.Contracts;
using iElection.Utilities;
using iElection.ViewModels;
using iElection.Views;
using Prism;
using Prism.Ioc;
using Sharpnado.MaterialFrame;
using Xamarin.Essentials.Implementation;
using Xamarin.Essentials.Interfaces;
using Xamarin.Forms;

namespace iElection
{
    public partial class App
    {
        public App(IPlatformInitializer initializer)
            : base(initializer)
        {
        }

        protected override async void OnInitialized()
        {
            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mzk5NEAzMTM5MmUzMTJlMzBTRzBTYllmTDM4d1J5QktZZXMwWi9lM3ZZWS9XTlpQcHhXcDFYdldaY2g4PQ==");
            InitializeComponent();
            Sharpnado.MaterialFrame.Initializer.Initialize(false,false);
            try
            {

                if (UtilitiesWrapper.Instance.UserUtilities.IsAuthorized)
                    await NavigationService.NavigateAsync("NavigationPage/MainPage");
                else
                    await NavigationService.NavigateAsync("NavigationPage/LoginPage");
            }
            catch (Exception e)
            {
                
            }
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.Register<IRestWrapper, RestWrapper>();
            containerRegistry.RegisterSingleton<IAppInfo, AppInfoImplementation>();

            containerRegistry.RegisterForNavigation<NavigationPage>();
            containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();
            containerRegistry.RegisterForNavigation<LoginPage, LoginPageViewModel>();
            containerRegistry.RegisterForNavigation<SignUpPage, SignUpPageViewModel>();

            containerRegistry.RegisterForNavigation<AddContactPage, AddContactPageViewModel>();
        }
    }
}
