using MainShell.Models;
using MainShell.Recipe.ViewModel;
using MaxwellFramework.Core.Interfaces;
using Stylet;
using StyletIoC;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MainShell.Manual.ViewModel
{
    public class ManualOperateViewModel : Stylet.Screen,IPage
    {
        public string Name => "ManualOperate";
        private const string LOGISTICS_OPERATION = "物流操作";
        private const string SUBSTRATEPOSITION = "基板定位";
        //基板测高
        private const string SUBSTRATEHEIGHTMEASUREMENT = "基板测高";
        //芯片拉直
        private const string CHIPSTRAIGHTENING = "芯片拉直";
        private const string WAFERPOSITION = "芯片定位";
        //Die转移
        private const string DIETRANSFER = "芯片转移";
        //精度复检
        private const string DIERECHECK = "精度复检";
        private readonly Dictionary<string, Screen> _viewModelDict = new Dictionary<string, Screen>();
        public ObservableCollection<MenuItemWrap> MenuItemWraps { get; private set; }

        private MenuItemWrap _selectedMenuItem;

        public MenuItemWrap SelectedMenuItem
        {
            get { return _selectedMenuItem; }
            set
            {
                if (SetAndNotify(ref _selectedMenuItem, value))
                {
                    if (value != null && _viewModelDict.TryGetValue(value.Header, out var screen))
                    {
                        CurrentScreen = screen;
                    }
                }
            }
        }
        private Screen _currentScreen;

        public Screen CurrentScreen
        {
            get { return _currentScreen; }
            set { SetAndNotify(ref _currentScreen, value); }
        }
        #region //界面ViewModel注入
        private LogisticsOperationViewModel  _logisticsOperationViewModel;
        [Inject]
        public LogisticsOperationViewModel LogisticsOperationViewModel
        {
            get { return _logisticsOperationViewModel; }
            set { SetAndNotify(ref _logisticsOperationViewModel, value); }
        }
        private SubstratePositionViewModel  _substratePositionViewModel;
        [Inject]
        public SubstratePositionViewModel  SubstratePositionViewModel
        {
            get { return  _substratePositionViewModel; }
            set { SetAndNotify(ref _substratePositionViewModel, value); }   
        }

        private WaferAngleAdjustmentViewModel  _waferAngleAdjustmentViewModel;
        [Inject]
        public WaferAngleAdjustmentViewModel WaferAngleAdjustmentViewModel
        {
            get { return  _waferAngleAdjustmentViewModel; }
            set { SetAndNotify(ref _waferAngleAdjustmentViewModel, value); }    
        }
        private DieBondingViewModel _dieBondingViewModel;
        [Inject]
        public DieBondingViewModel DieBondingViewModel
        {
            get { return _dieBondingViewModel; }
            set { SetAndNotify(ref _dieBondingViewModel, value); }
        }
        private DiePositionViewModel  _diePositionViewModel;
        [Inject]
        public DiePositionViewModel DiePositionViewModel
        {
            get { return _diePositionViewModel; }
            set { SetAndNotify(ref _diePositionViewModel, value); }  
        }


        private ChipStraighteningViewModel _chipStraighteningViewModel;
        [Inject]
        public ChipStraighteningViewModel ChipStraighteningViewModel
        {
            get { return _chipStraighteningViewModel; }
            set { SetAndNotify(ref _chipStraighteningViewModel, value); }
        }

        private SubstrateHeightMeasureViewModel _substrateHeightMeasureViewModel;
        [Inject]
        public SubstrateHeightMeasureViewModel SubstrateHeightMeasureViewModel
        {
            get { return _substrateHeightMeasureViewModel; }
            set { SetAndNotify(ref _substrateHeightMeasureViewModel, value); }
        }

        private DieRecheckViewModel _dieRecheckViewModel;
        [Inject]
        public DieRecheckViewModel DieRecheckViewModel
        {
            get { return _dieRecheckViewModel; }
            set { SetAndNotify(ref _dieRecheckViewModel, value); }
        }
        #endregion

        public ManualOperateViewModel()
        {
            MenuItemWraps = new ObservableCollection<MenuItemWrap>()
            {
                new MenuItemWrap
                {
                    Header=LOGISTICS_OPERATION,Tag=LOGISTICS_OPERATION
                },
                new MenuItemWrap
                {
                    Header= SUBSTRATEPOSITION, Tag=SUBSTRATEPOSITION
                },
                new MenuItemWrap
                {
                    Header=SUBSTRATEHEIGHTMEASUREMENT, Tag=SUBSTRATEHEIGHTMEASUREMENT
                },
                new MenuItemWrap
                {
                    Header=CHIPSTRAIGHTENING, Tag=CHIPSTRAIGHTENING
                },
                 new MenuItemWrap
                {
                    Header=WAFERPOSITION, Tag=WAFERPOSITION
                },
                new MenuItemWrap
                {
                    Header=DIETRANSFER, Tag=DIETRANSFER
                },
                new MenuItemWrap
                {
                    Header=DIERECHECK, Tag=DIERECHECK
                }
            };
        }
        protected override void OnViewLoaded()
        {
            base.OnViewLoaded();
            if (_viewModelDict.Count == 0)
            {
                InitViewModelDict();
            }
            if (SelectedMenuItem == null)
                SelectedMenuItem = MenuItemWraps[0];
        }
        private void InitViewModelDict()
        {
            _viewModelDict.Clear(); 
            _viewModelDict.Add(LOGISTICS_OPERATION, LogisticsOperationViewModel);
            _viewModelDict.Add(SUBSTRATEPOSITION, SubstratePositionViewModel);
            _viewModelDict.Add(SUBSTRATEHEIGHTMEASUREMENT, SubstrateHeightMeasureViewModel);
            _viewModelDict.Add(CHIPSTRAIGHTENING, WaferAngleAdjustmentViewModel);
          
            _viewModelDict.Add(DIETRANSFER, DieBondingViewModel);
            _viewModelDict.Add(WAFERPOSITION, DiePositionViewModel);
            _viewModelDict.Add(DIERECHECK, DieRecheckViewModel);
        }
    }
}
