namespace EEMSUIClient.Views;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private readonly TrayController _trayController;

    public MainWindow(TrayController trayController)
    {
        InitializeComponent();

        _trayController = trayController;
        this.Closing += MainWindow_Closing;
        this.StateChanged += MainWindow_StateChanged;
    }

    private void MainWindow_StateChanged(object? sender, EventArgs e)
    {
        switch (this.WindowState)
        {
            case WindowState.Minimized:
                _trayController.HideToTray();
                break;
            case WindowState.Normal:
            case WindowState.Maximized:
            default:
                break;
        }
    }

    private void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
    {
        MessageBoxResult result = MessageBox.Show("确认退出 EEMS Client?", "", MessageBoxButton.YesNo);
        if (result == MessageBoxResult.No)
            e.Cancel = true;

        App.Current.Shutdown();
    }
}
