using Aucma.Scada.UI.Page.AssemblyPlan;
using Aucma.Scada.UI.Page.InStoreInfo;
using Aucma.Scada.UI.Page.InventoryInfo;
using Aucma.Scada.UI.Page.OutStoreInfo;
using Aucma.Scada.UI.Page.TaskInfo;
using Aucma.Scada.UI.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using log4net;
using System;
using System.Windows;

namespace Aucma.Scada.UI.ViewModel
{
    public partial class MainViewModel : ObservableObject
    {
        private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(MainViewModel));
        private readonly LogInfoControl logInfoControl = new LogInfoControl();
        private readonly InStoreInfoControl inStoreInfoControl = new InStoreInfoControl();
        private readonly OutStoreInfoControl outStoreInfoControl = new OutStoreInfoControl();
        private readonly TaskInfoControl taskInfoControl = new TaskInfoControl();
        private readonly InventoryInfoControl inventoryInfoControl = new InventoryInfoControl();
        private readonly AssemblyPlanControl assemblyPlanControl = new AssemblyPlanControl();

        public MainViewModel()
        {
            UserContent = inStoreInfoControl;
        }

        #region 参数定义
        private int _PresentColor = 0;
        public int PresentColor
        {
            get => _PresentColor;
            set => SetProperty(ref _PresentColor, value);
        }

        public System.Windows.Controls.UserControl _content;

        public System.Windows.Controls.UserControl UserContent
        {
            get => _content;
            set => SetProperty(ref _content, value);
        }
        #endregion

        #region 事件定义
        /// <summary>
        /// 界面跳转按钮事件
        /// </summary>
        [RelayCommand]
        private void ControlOnClick(object obj)
        {
            try
            {
                string info = obj as string;
                switch (info)
                {
                    case "instoreInfo":
                        UserContent = inStoreInfoControl;
                        break;
                    case "outstoreInfo":
                        UserContent = outStoreInfoControl;
                        break;
                    case "taskInfo":
                        UserContent = taskInfoControl;
                        break;
                    case "inventoryInfo":
                        UserContent = inventoryInfoControl;
                        break;
                    case "assemblyPlan":
                        UserContent = assemblyPlanControl;
                        break;
                    case "logInfo":
                        UserContent = logInfoControl;
                        break;
                    default:
                        UserContent = inStoreInfoControl;
                        break;
                }
            }
            catch (Exception ex)
            {
                logHelper.Error("界面跳转逻辑异常", ex);
            }
        }

        /// <summary>
        /// 打开系统键盘
        /// </summary>
        [RelayCommand]
        public void OpenSystemKeyboard()
        {
            try
            {
                MessageBox.Show("打开系统键盘");
            }catch(Exception ex)
            {
                logHelper.Error("打开系统键盘逻辑异常", ex);
            }
        }

        /// <summary>
        /// 窗体控制
        /// </summary>
        [RelayCommand]
        public void FormControl(object obj)
        {
            try
            {
                string controlType = obj as string;
                switch (controlType)
                {
                    // 关闭当前窗口
                    case "Exit":
                        //Environment.Exit(0);
                        Application.Current.Shutdown();
                        break;

                    // 还原 或者 最大化当前窗口
                    case "Normal":
                        if (Application.Current.MainWindow.WindowState == WindowState.Normal)
                        {
                            Application.Current.MainWindow.WindowState = WindowState.Maximized;
                            break;
                        }
                        if (Application.Current.MainWindow.WindowState == WindowState.Maximized)
                        {
                            Application.Current.MainWindow.WindowState = WindowState.Normal;
                            break;
                        }
                        break;

                    // 最小化当前窗口
                    case "Minimized":
                        Application.Current.MainWindow.WindowState = WindowState.Minimized;
                        break;
                    default:
                        break;
                }
            }catch(Exception ex)
            {
                logHelper.Error("窗体控制逻辑异常", ex);
            }
        }
        #endregion


    }
}