using JM1.VisionModule;
using MainShell.AlgorithmCalib.ViewModel;
using MainShell.HeightMeasure.ViewModel;
using MainShell.Models;
using MainShell.PageCalib.OriginCalib.ViewModel;
using MainShell.PageCalib.View;
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.PageCalib.ViewModel
{
    public class PageCalibViewModel: BaseScreen,IPage
    {
        public string Name => "PageCalib";
        private const string HEIGHTMEARSURE = "高度标定";
        private const string ORIGINCALIB = "原点标定";
        private const string PIXRATIOCALIB = "像素比标定";
        private const string DISTORTIONCORRECTIONCALIB = "畸变校准标定";
        private const string MOTIONCALIB = "运动系标定";
        private const string ROTATECENTERCALIB = "旋转中心标定";
        private const string ROTATEFORMCALIB = "旋转表标定";
        private const string FUSIONCALIB = "融合标定";
        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))
                {
                    CurrentScreen = _viewModelDict[value.Header];
                }
            }
        }
        private Screen _currentScreen;

        public Screen CurrentScreen
        {
            get { return _currentScreen; }
            set { SetAndNotify(ref _currentScreen, value); }
        }

        private HeightViewModel _heightViewModel;
        [Inject]
        public HeightViewModel HeightViewModel
        {
            get { return _heightViewModel; }
            set { _heightViewModel = value; }
        }

        private OriginCalibViewModel _originCalibViewModel;
        [Inject]
        public OriginCalibViewModel OriginCalibViewModel
        {
            get { return _originCalibViewModel; }
            set { _originCalibViewModel = value; }
        }

        private PixRatioCalibContentsViewModel _pixRatioCalibViewModel;
        [Inject]
        public PixRatioCalibContentsViewModel PixRatioCalibViewModel
        {
            get { return _pixRatioCalibViewModel; }
            set { _pixRatioCalibViewModel = value; }
        }

        private DistortionCorrectionCalibContentsViewModel _distortionCorrectionCalibViewModel;
        [Inject]
        public DistortionCorrectionCalibContentsViewModel DistortionCorrectionCalibViewModel
        {
            get { return _distortionCorrectionCalibViewModel; }
            set { _distortionCorrectionCalibViewModel = value; }
        }

        private MotionCalibContentsViewModel _motionCalibViewModel;
        [Inject]
        public MotionCalibContentsViewModel MotionCalibViewModel
        {
            get { return _motionCalibViewModel; }
            set { _motionCalibViewModel = value; }
        }

        private RotateCenterCalibContentsViewModel _rotateCenterCalibViewModel;
        [Inject]
        public RotateCenterCalibContentsViewModel RotateCenterCalibViewModel
        {
            get { return _rotateCenterCalibViewModel; }
            set { _rotateCenterCalibViewModel = value; }
        }

        private RotateMatixFormCalibViewModel _rotateFormCalibViewModel;
        [Inject]
        public RotateMatixFormCalibViewModel RotateFormCalibViewModel
        {
            get { return _rotateFormCalibViewModel; }
            set { _rotateFormCalibViewModel = value; }
        }

        private FusionCalibViewModel _fusionCalibViewModel;
        [Inject]
        public FusionCalibViewModel FusionCalibViewModel
        {
            get { return _fusionCalibViewModel; }
            set { _fusionCalibViewModel = value; }
        }

        public PageCalibViewModel()
        {
            InitMenuItems();
        }

        protected override void OnViewLoaded()
        {
            base.OnViewLoaded();
            if (_viewModelDict.Count == 0)
            {
                InitViewModelDict();
            }
            if (SelectedMenuItem == null)
                SelectedMenuItem = MenuItemWraps[0];
        }
        private void InitMenuItems()
        {
            MenuItemWraps = new ObservableCollection<MenuItemWrap>
            {
                new MenuItemWrap() { Header=HEIGHTMEARSURE,Tag=HEIGHTMEARSURE },
                new MenuItemWrap() { Header=ORIGINCALIB,Tag=ORIGINCALIB },
                new MenuItemWrap() { Header=PIXRATIOCALIB,Tag=PIXRATIOCALIB },
                new MenuItemWrap() { Header=DISTORTIONCORRECTIONCALIB,Tag=DISTORTIONCORRECTIONCALIB },
                new MenuItemWrap() { Header=MOTIONCALIB,Tag=MOTIONCALIB },
                new MenuItemWrap() { Header=ROTATECENTERCALIB,Tag=ROTATECENTERCALIB },
                new MenuItemWrap() { Header=ROTATEFORMCALIB,Tag=ROTATEFORMCALIB },
                new MenuItemWrap() { Header=FUSIONCALIB,Tag=FUSIONCALIB },
            };
        }
        private void InitViewModelDict()
        {
            _viewModelDict.Clear();
            _viewModelDict.Add(HEIGHTMEARSURE, HeightViewModel);
            _viewModelDict.Add(ORIGINCALIB, OriginCalibViewModel);
            _viewModelDict.Add(PIXRATIOCALIB, PixRatioCalibViewModel);
            _viewModelDict.Add(DISTORTIONCORRECTIONCALIB, DistortionCorrectionCalibViewModel);
            _viewModelDict.Add(MOTIONCALIB, MotionCalibViewModel);
            _viewModelDict.Add(ROTATECENTERCALIB, RotateCenterCalibViewModel);
            _viewModelDict.Add(ROTATEFORMCALIB, RotateFormCalibViewModel);
            _viewModelDict.Add(FUSIONCALIB, FusionCalibViewModel);
        }
    }
}
