using MainShell.HeightMeasure.ViewModel;
using MainShell.Models;
using MaxwellFramework.Core.Interfaces;
using Stylet;
using StyletIoC;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace MainShell.DeviceMaintance.ViewModel
{
    public class DeviceMaintanceViewModel : BaseScreen, IPage
    {
        public string Name => "MenuDeviceMaint";
        private const string NEEDLEBASE = "刺晶头维护";
        private const string IOMONITOR = "IO监控";
        private const string HARDWARETEST = "硬件维护";
        private const string LASERCOMPENSATION = "激光补偿";
        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 NeedleBaseViewModel _needleBaseViewModel;
        [Inject]
        public NeedleBaseViewModel NeedleBaseViewModel
        {
            get { return _needleBaseViewModel; }
            set { _needleBaseViewModel = value; }
        }

        private IOMaintanceViewModel _ioMaintanceViewModel;
        [Inject]
        public IOMaintanceViewModel IOMaintanceViewModel
        {
            get { return _ioMaintanceViewModel; }
            set { _ioMaintanceViewModel = value; }
        }

        private HardwareTestViewModel _hardwareTestViewModel;
        [Inject]
        public HardwareTestViewModel HardwareTestViewModel
        {
            get { return _hardwareTestViewModel; }
            set { _hardwareTestViewModel = value; }
        }

        private LaserCompensationViewModel _laserCompensationViewModel;
        [Inject]
        public LaserCompensationViewModel LaserCompensationViewModel
        {
            get { return _laserCompensationViewModel; }
            set { _laserCompensationViewModel = value; }
        }

        public DeviceMaintanceViewModel()
        {
            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 = NEEDLEBASE, Tag = NEEDLEBASE },
                new MenuItemWrap() { Header = IOMONITOR, Tag = IOMONITOR },
                new MenuItemWrap() { Header = HARDWARETEST, Tag = HARDWARETEST },
                new MenuItemWrap() { Header = LASERCOMPENSATION, Tag = LASERCOMPENSATION },
            };
        }

        private void InitViewModelDict()
        {
            _viewModelDict.Clear();
            _viewModelDict.Add(NEEDLEBASE, NeedleBaseViewModel);
            _viewModelDict.Add(IOMONITOR, IOMaintanceViewModel);
            _viewModelDict.Add(HARDWARETEST, HardwareTestViewModel);
            _viewModelDict.Add(LASERCOMPENSATION, LaserCompensationViewModel);
        }
    }
}
