using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.OperationCenter;
using CyberX8_Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CyberX8_Themes.UserControls
{
    /// <summary>
    /// PufStationCommandControl.xaml 的交互逻辑
    /// </summary>
    public partial class PufStationCommandControl : UserControl
    {
        public PufStationCommandControl()
        {
            InitializeComponent();
        }


        public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register("ModuleName", typeof(string), typeof(PufStationCommandControl));
        /// <summary>
        /// ModuleName
        /// </summary>
        public string ModuleName
        {
            get
            {
                return (string)this.GetValue(ModuleNameProperty);
            }
            set
            {
                this.SetValue(ModuleNameProperty, value);
            }
        }

        public static readonly DependencyProperty VacuumAProperty = DependencyProperty.Register( "VacuumA", typeof(bool), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumA
        /// </summary>
        public bool VacuumA
        {
            get
            {
                return (bool)this.GetValue(VacuumAProperty);
            }
            set
            {
                this.SetValue(VacuumAProperty, value);
            }
        }
        public static readonly DependencyProperty VacuumBProperty = DependencyProperty.Register("VacuumB", typeof(bool), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumB
        /// </summary>
        public bool VacuumB
        {
            get
            {
                return (bool)this.GetValue(VacuumBProperty);
            }
            set
            {
                this.SetValue(VacuumBProperty, value);
            }
        }

        public static readonly DependencyProperty VacuumAValueProperty = DependencyProperty.Register("VacuumAValue", typeof(double), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumAValue
        /// </summary>
        public double VacuumAValue
        {
            get
            {
                return (double)this.GetValue(VacuumAValueProperty);
            }
            set
            {
                this.SetValue(VacuumAValueProperty, value);
            }
        }

        public static readonly DependencyProperty VacuumBValueProperty = DependencyProperty.Register("VacuumBValue", typeof(double), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumBValue
        /// </summary>
        public double VacuumBValue
        {
            get
            {
                return (double)this.GetValue(VacuumBValueProperty);
            }
            set
            {
                this.SetValue(VacuumBValueProperty, value);
            }
        }

        public static readonly DependencyProperty VacuumAStatusProperty = DependencyProperty.Register("VacuumAStatus", typeof(string), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumAStatus
        /// </summary>
        public string VacuumAStatus
        {
            get
            {
                return (string)this.GetValue(VacuumAStatusProperty);
            }
            set
            {
                this.SetValue(VacuumAStatusProperty, value);
            }
        }

        public static readonly DependencyProperty VacuumBStatusProperty = DependencyProperty.Register("VacuumBStatus", typeof(string), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumBStatus
        /// </summary>
        public string VacuumBStatus
        {
            get
            {
                return (string)this.GetValue(VacuumBStatusProperty);
            }
            set
            {
                this.SetValue(VacuumBStatusProperty, value);
            }
        }


        public static readonly DependencyProperty VacuumACheckedProperty = DependencyProperty.Register("VacuumAChecked", typeof(bool), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumAChecked
        /// </summary>
        public bool VacuumAChecked
        {
            get
            {
                return (bool)this.GetValue(VacuumACheckedProperty);
            }
            set
            {
                this.SetValue(VacuumACheckedProperty, value);
            }
        }
        public static readonly DependencyProperty VacuumBCheckedProperty = DependencyProperty.Register("VacuumBChecked", typeof(bool), typeof(PufStationCommandControl));
        /// <summary>
        /// VacuumBChecked
        /// </summary>
        public bool VacuumBChecked
        {
            get
            {
                return (bool)this.GetValue(VacuumBCheckedProperty);
            }
            set
            {
                this.SetValue(VacuumBCheckedProperty, value);
            }
        }
        public static readonly DependencyProperty PickSelectedItemProperty = DependencyProperty.Register("PickSelectedItem", typeof(string), typeof(PufStationCommandControl));
        /// <summary>
        /// PickSelectedItem
        /// </summary>
        public string PickSelectedItem
        {
            get
            {
                return (string)this.GetValue(PickSelectedItemProperty);
            }
            set
            {
                this.SetValue(PickSelectedItemProperty, value);
            }
        }
        public static readonly DependencyProperty PlaceSelectedItemProperty = DependencyProperty.Register("PlaceSelectedItem", typeof(string), typeof(PufStationCommandControl));
        /// <summary>
        /// PlaceSelectedItem
        /// </summary>
        public string PlaceSelectedItem
        {
            get
            {
                return (string)this.GetValue(PlaceSelectedItemProperty);
            }
            set
            {
                this.SetValue(PlaceSelectedItemProperty, value);
            }
        }
        public static readonly DependencyProperty PickCombomboxItemSourceProperty = DependencyProperty.Register("PickCombomboxItemSource", typeof(List<string>), typeof(PufStationCommandControl),
            new FrameworkPropertyMetadata(new List<string>() {"SideA"}, FrameworkPropertyMetadataOptions.AffectsRender));
        public List<string> PickCombomboxItemSource
        {
            get
            {
                return (List<string>)this.GetValue(PickCombomboxItemSourceProperty);
            }
            set
            {
                this.SetValue(PickCombomboxItemSourceProperty, value);
            }
        }
        public static readonly DependencyProperty PlaceCombomboxItemSourceProperty = DependencyProperty.Register("PlaceCombomboxItemSource", typeof(List<string>), typeof(PufStationCommandControl),
           new FrameworkPropertyMetadata(new List<string>() { "SideB" }, FrameworkPropertyMetadataOptions.AffectsRender));
        public List<string> PlaceCombomboxItemSource
        {
            get
            {
                return (List<string>)this.GetValue(PlaceCombomboxItemSourceProperty);
            }
            set
            {
                this.SetValue(PlaceCombomboxItemSourceProperty, value);
            }
        }
        #region button 事件



        private void MoveToPark_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.MoveToPark");
        }

        private void AllMotorOn_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{MotionOperation.SwitchOn}");
        }

        private void AllMotorOff_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{MotionOperation.SwitchOff}");
        }

        private void HomePuf_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{MotionOperation.HomeAll}");
        }

        private void Abort_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
        }
        private void Pick_Click(object sender, RoutedEventArgs e)
        {
            if(string.IsNullOrEmpty(PickSelectedItem))
            {
                MessageBox.Show("please select pick item", "pick", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Pick", PickSelectedItem);
        }

        private void Place_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(PlaceSelectedItem))
            {
                MessageBox.Show("please select place item", "place", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Place", PlaceSelectedItem);
        }

        private void MoveToRobot_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.MoveToRobot");
        }

        private void VacuumA_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumAOn", "VacuumAChecked", !VacuumAChecked);
        }
        private void VacuumB_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.VacuumBOn", "VacuumBChecked", !VacuumBChecked);
        }

        private void ClearError_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ClearError");
        }
        #endregion

    }
}