using MainShell.Hardware;
using MainShell.Models;
using MainShell.Recipe.Models;
using MaxwellFramework.Core.Common;
using MaxwellFramework.Core.Interfaces;
using MwFramework.ManagerService;
using MXJM.Parameter.Maintance;
using Stylet;
using StyletIoC;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MainShell.DeviceMaintance.ViewModel
{
    public class NeedleBaseViewModel : CameraBaseViewModel, IPage
    {
        private readonly Dictionary<string, Screen> _screenDics = new Dictionary<string, Screen>();

        private const string NEEDLE_CAMERA_CALIB = "针尖相机校准";
        private const string CAMERA_ACCURACY_CALIB = "针印检测";
        private const string NEEDLECALIB = "针尖对刀检查";

        private Screen _currentScreen;
        public Screen CurrentScreen
        {
            get => _currentScreen;
            set { SetAndNotify(ref _currentScreen, value); }
        }

        private ObservableCollection<string> _navigationItems = new ObservableCollection<string>();
        public ObservableCollection<string> NavigationItems
        {
            get => _navigationItems;
            set
            {
                _navigationItems = value;
                OnPropertyChanged(nameof(NavigationItems));
            }
        }

        private string _selectedItem;
        public string SelectedItem
        {
            get => _selectedItem;
            set
            {
                _selectedItem = value;
                OnPropertyChanged(nameof(SelectedItem));
                // 当选择项改变时，更新当前ViewModel
                if (_selectedItem != null)
                {
                    CurrentScreen = _screenDics[value];
                }
            }
        }

        private NeedleCaliViewModel _needleCaliViewModel;
        [Inject]
        public NeedleCaliViewModel NeedleCaliViewModel
        {
            get { return _needleCaliViewModel; }
            set { _needleCaliViewModel = value; }
        }

        private NeedleCameraPrintViewModel _needleCameraPrintViewModel;
        [Inject]
        public NeedleCameraPrintViewModel NeedleCameraPrintViewModel
        {
            get { return _needleCameraPrintViewModel; }
            set { _needleCameraPrintViewModel = value; }
        }

        private CameraAccuracyCalibrationViewModel _cameraAccuracyCalibrationViewModel;
        [Inject]
        public CameraAccuracyCalibrationViewModel CameraAccuracyCalibrationViewModel
        {
            get { return _cameraAccuracyCalibrationViewModel; }
            set { _cameraAccuracyCalibrationViewModel = value; }
        }
        private HardwareManager _hardwareManager;
        public NeedleBaseViewModel(HardwareManager hardwareManager)
        {
            _hardwareManager = hardwareManager ?? throw new ArgumentNullException(nameof(hardwareManager));
            _cameraAxisViewModel = IoC.Get<Common.Display.ViewModel.CameraAxisViewModel>();
            _cameraAxisViewModel.CameraAxisDevices.HardwareDeviceList = hardwareManager.CameraAxisManager.TopCameraAxisDevices;
            InitNavigationItems();
        }

        protected override void OnViewLoaded()
        {
            base.OnViewLoaded();
            if (_screenDics.Count == 0)
            {
                InitScreenDics();
            }
            if (SelectedItem == null)
                SelectedItem = NavigationItems[0];
        }

        public void InitNavigationItems()
        {
            NavigationItems.Add(NEEDLE_CAMERA_CALIB);
            NavigationItems.Add(CAMERA_ACCURACY_CALIB);
            NavigationItems.Add(NEEDLECALIB);
        }

        public void InitScreenDics()
        {
            _screenDics.Add(NEEDLE_CAMERA_CALIB, NeedleCameraPrintViewModel);
            _screenDics.Add(NEEDLECALIB, NeedleCaliViewModel);
            _screenDics.Add(CAMERA_ACCURACY_CALIB, CameraAccuracyCalibrationViewModel);
        }

    }
}
