using Bellwether.Utility;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Bellwether
{
    public enum PageType : int
    {
        FrontPage,
        History,
        Product,
        CSR,
    }

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private UpdateProcess updateProcess;

        private Storyboard showStoryboard = new Storyboard();
        private Storyboard hideStoryboard = new Storyboard();

        public MainWindow()
        {
            InitializeComponent();

            AddHideAndShowSt();

            updateProcess = new UpdateProcess();
            updateProcess.OnUpdateReady += UpdateProcess_OnUpdateReady;
            updateProcess.OnUpdateComplete += UpdateProcess_OnUpdateComplete;

            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //Process process = Process.GetCurrentProcess();
            //EdgeGesture.EdgeGestureUtil.EnableEdgeGestures(process.MainWindowHandle, true);

            uxMainGrid.Children.Add(new ucMainControlPage());
        }

        private void AddHideAndShowSt()
        {
            showStoryboard = FindResource("ShowStoryboard") as Storyboard;
            hideStoryboard = FindResource("HideStoryboard") as Storyboard;
            hideStoryboard.Completed += hideStoryboard_Completed;
        }
        private void UpdateProcess_OnUpdateReady(object sender, EventArgs e)
        {
            hideStoryboard.Begin();
        }

        private void hideStoryboard_Completed(object sender, EventArgs e)
        {
            uxMainGrid.Children.Clear();
            GC.Collect();
            updateProcess.StartUpdateProcess();
        }

        private void UpdateProcess_OnUpdateComplete(object sender, EventArgs e)
        {
            Setting.Reload();
            uxMainGrid.Children.Add(new ucMainControlPage());
            showStoryboard.Begin();
        }
    }
}
