using EEMSUIClient.Services;
using EEMSUIClient.Views;
using Hardcodet.Wpf.TaskbarNotification;
using System.Windows;

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<ITrayControl, TrayController>();
        containerRegistry.RegisterSingleton<IClientService, ClientService>();
    }

    protected override void OnInitialized()
    {
        base.OnInitialized();

        Container.Resolve<ITrayControl>().Tray = (TaskbarIcon)App.Current.FindResource("TrayIcon");
        Container.Resolve<ITrayControl>().ShowBalloonTip();
    }

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

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

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

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