using BellwetherBackend.Utility;
using System;
using System.Collections.Generic;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BellwetherBackend
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private UIElement currentPage;

        public MainWindow()
        {
            InitializeComponent();

            Closing += MainWindow_Closing;
        }

        private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SaveCurrentPage();
        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            SaveCurrentPage();
            int selectedTab = uxTopRButtonParent.Children.IndexOf(sender as UIElement);
            if (selectedTab == 0)
            {
                currentPage = new SubPage.UcBasicSetting();
                uxMainGrid.Children.Clear();
                uxMainGrid.Children.Add(currentPage);
            }
            else if (selectedTab == 1)
            {
                currentPage = new SubPage.UcFrontPage();
                uxMainGrid.Children.Clear();
                uxMainGrid.Children.Add(currentPage);
            }
            else if (selectedTab == 5)
            {
                currentPage = new SubPage.UpdatePage();
                uxMainGrid.Children.Clear();
                uxMainGrid.Children.Add(currentPage);
            }
            else
            {
                string pageFolderName = null;

                if (selectedTab == 2)
                    pageFolderName = Setting.PageFolderName[Setting.PageType.History];
                else if (selectedTab == 3)
                    pageFolderName = Setting.PageFolderName[Setting.PageType.Product];
                else if (selectedTab == 4)
                    pageFolderName = Setting.PageFolderName[Setting.PageType.CSR];

                if (!string.IsNullOrEmpty(pageFolderName))
                {
                    HistoryWallEditTool.GlobalFunction.historyWalldataFolderName = pageFolderName;
                    currentPage = new HistoryWallEditTool.HistoryWall();

                    uxMainGrid.Children.Clear();
                    uxMainGrid.Children.Add(currentPage);
                }
            }
        }

        private void SaveCurrentPage()
        {
            if (currentPage is HistoryWallEditTool.HistoryWall histortywall)
            {
                histortywall.SaveWholeConfig();
            }
            else if (currentPage is SubPage.UcBasicSetting basicSetting)
            {

            }
            else if (currentPage is SubPage.UpdatePage updatePage)
            {
                updatePage.Disconnect();
            }
        }
    }
}
