using MinicsUI.ViewModels.Regions;
using MinicsUI.Views.Regions;

namespace BlankPrism;

public partial class App : PrismApplication
{
    protected override Window CreateShell() => Container.Resolve<MainWindow>();

    protected override void OnStartup(StartupEventArgs e)
    {
        Mutex mutex = new(true, "1E8B4FF8-C1BF-33AB-AE6D-6DF9BEBDB5B9", out bool flag);
        if (!flag)
            return;

        DispatcherUnhandledException += App_DispatcherUnhandledException;
        base.OnStartup(e);
    }

    private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
    {
        MessageBox.Show(e.Exception!.ToString()!);
    }

    protected override void OnExit(ExitEventArgs e)
    {
        SetWindow.ExitParent();
        App.Current?.Dispatcher.InvokeShutdown();
        base.OnExit(e);
    }

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterDialogWindow<Window1>();
        containerRegistry.RegisterDialog<SettingDialog, SettingDialogViewModel>("Setting");
        containerRegistry.RegisterDialog<FileLoader, FileLoaderViewModel>("File");
        containerRegistry.RegisterDialog<ChannelDetail, ChannedDetailViewModel>("Channel");
        containerRegistry.RegisterDialog<ThemeMessageBox, ThemeMessageBoxViewModel>("MessageBox");
        containerRegistry.RegisterDialog<ConfigFileComparision, ConfigFileComparisionViewModel>("Compare");
        containerRegistry.RegisterDialog<TraceLog, TraceLogViewModel>("TraceLog");

        containerRegistry.RegisterForNavigation<Alarm, AlarmViewModel>("Alarm");
        containerRegistry.RegisterForNavigation<HistoryView.Views.Regions.Monitor, MonitorViewModel>("Monitor");
        containerRegistry.RegisterForNavigation<ChannelMultiEdit, ChannelMultiEditViewModel>("MultiEdit");
        containerRegistry.RegisterForNavigation<Settings, SettingViewModel>("Setting");
        containerRegistry.RegisterForNavigation<GasPanelHolder, GasPanelViewModel>("GasPanel");
        containerRegistry.RegisterForNavigation<HeaterGramHolder, HeaterGramHolderViewModel>("HeaterGram");

        containerRegistry.RegisterForNavigation<ConfigEditor, ConfigEditorViewModel>("ConfigEditor");

        containerRegistry.RegisterSingleton<MessageBoxHelper>();
        containerRegistry.RegisterSingleton<DatabaseCleaner>();
        containerRegistry.RegisterSingleton<LanguageLoader>();
        containerRegistry.RegisterSingleton<MonitorHelper>();
        containerRegistry.RegisterSingleton<Hardwares>();
        containerRegistry.RegisterSingleton<Alarms>();
        containerRegistry.RegisterSingleton<TemperatureConfigs>();
        containerRegistry.RegisterSingleton<UserInformation>();
        containerRegistry.RegisterSingleton<HubSender>();
        containerRegistry.RegisterSingleton<HubReceiver>();
        containerRegistry.RegisterSingleton<AlarmRealtime>();
        containerRegistry.RegisterSingleton<HistoryViewer>();
        containerRegistry.RegisterSingleton<UserCollection>();
    }
}
