using System.Reflection;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Cogwheel;
using SessionZero.Cogwheel;

namespace SessionZero;

public partial class App : Application
{
    
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
        InitCogwheel();
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            AppManager.MainWindow = new MainWindow();
            desktop.MainWindow = AppManager.MainWindow;
        }

        base.OnFrameworkInitializationCompleted();
    }

    private void InitCogwheel()
    {
        AppManager.CommandsManager.AddAssembly(Assembly.GetAssembly(typeof(CommandsManager)));
        AppManager.CommandsManager.AddAssembly(Assembly.GetExecutingAssembly());
        COGWHEEL.Initialize(AppManager.CommandsManager, AppManager.SzConsole);
    }
}