using Dm.filter;
using ProximaAnalizer.PublicEvent;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProximaAnalizer.Views;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow(IEventAggregator eventAggregator, IRegionManager regionManager)
    {
        InitializeComponent();
        this._eventAggregator = eventAggregator;
        this._eventAggregator.GetEvent<WindowSwitch>().Subscribe(SwitchWindow);

        this.Loaded += MainWindow_Loaded;
        this._regionManager = regionManager;
    }

    private readonly IRegionManager _regionManager;
    private readonly IEventAggregator _eventAggregator;
    private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.WindowStyle = WindowStyle.None;
        this.ResizeMode = ResizeMode.NoResize;
        this.Content = new Loading();
    }

    private object? Summary;
    private object? RecipeNavi;

    private void SwitchWindow()
    {
        switch (this._eventAggregator.GetEvent<WindowSwitch>().Page)
        {
            case Pages.Loading:
                Width = 800;
                Height = 160;
                break;
            case Pages.RecipeStepNavi:
                Width = 1280;
                Height = 800;
                this.WindowStyle = WindowStyle.ThreeDBorderWindow;
                this.ResizeMode = ResizeMode.CanResize;
                this.WindowState = WindowState.Maximized;

                this.RecipeNavi ??= new RecipeStepNavi();
                this.Content = this.RecipeNavi;
                break;
            case Pages.MainWindow:
                Width = 1280;
                Height = 800;
                this.WindowStyle = WindowStyle.ThreeDBorderWindow;
                this.ResizeMode = ResizeMode.CanResize;
                this.WindowState = WindowState.Maximized;

                this.Summary ??= new Summary();
                this.Content = this.Summary;
                _regionManager.RequestNavigate("MainRegion", "DBInfoTrace");
                break;
            case Pages.HistoryData:
                Width = 1280;
                Height = 800;
                this.WindowStyle = WindowStyle.ThreeDBorderWindow;
                this.ResizeMode = ResizeMode.CanResize;
                this.WindowState = WindowState.Maximized;

                this.Summary ??= new Summary();
                this.Content = this.Summary;
                _regionManager.RequestNavigate("MainRegion", "DBInfoAlarm");
                break;
            default:
                break;
        }
    }

}