namespace EEMSUIClient;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{
    protected override Window CreateShell()
    {
        return Container.Resolve<MainWindow>();
    }

    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterSingleton<TrayController>();
        containerRegistry.RegisterSingleton<ClientService>();

        containerRegistry.RegisterSingleton<ConfigPath>();
        containerRegistry.RegisterSingleton<RunningData>();
        containerRegistry.RegisterSingleton<AddressInfo>();
        containerRegistry.RegisterSingleton<LocalFilePathInfo>();
        containerRegistry.RegisterSingleton<ConfigService>();
        containerRegistry.RegisterSingleton<IClientBaseProvider, ClientBaseProvider>();
    }

    protected override void OnInitialized()
    {
        Container.Resolve<TrayController>().Tray = (TaskbarIcon)App.Current.FindResource("TrayIcon");
        Container.Resolve<TrayController>().ShowBalloonTip();

        ConfigService configPath = Container.Resolve<ConfigService>();
        configPath.LoadConnectionInfo();
        configPath.LoadDeviceInfo();
        configPath.LoadDirectoryInfo();

        base.OnInitialized();
    }

    private void TrayIcon_TrayMouseDoubleClick(object sender, RoutedEventArgs e)
    {
        Container.Resolve<TrayController>().ShowMainWindow();
    }

    private void ShowMenu_Click(object sender, RoutedEventArgs e)
    {
        Container.Resolve<TrayController>().ShowMainWindow();
    }

    private void ExitMenu_Click(object sender, RoutedEventArgs e)
    {
        Container.Resolve<TrayController>().Exit();
    }

    private void OnExit(object sender, ExitEventArgs e)
    {
        Container.Resolve<ClientService>().Dispose();
        Container.Resolve<TrayController>().Dispose();
    }
}
