using MECF.Framework.Common.OperationCenter;
using System;
using System.Collections.Generic;
using System.Linq;
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
{
    /// 
    /// TransporterOperationControl.xaml 的交互逻辑
    /// 
    public partial class TransporterOperationControl : UserControl
    {
        #region 属性
        public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register("ModuleName", typeof(string), typeof(TransporterOperationControl),
         new FrameworkPropertyMetadata("Transporter",new PropertyChangedCallback(ModuleNamePropertyChanged)));
        /// 
        /// 模块名称
        /// 
        public string ModuleName
        {
            get
            {
                return (string)this.GetValue(ModuleNameProperty);
            }
            set
            {
                this.SetValue(ModuleNameProperty, value);
            }
        }
        private static void ModuleNamePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
        }
        public static readonly DependencyProperty ClampedProperty = DependencyProperty.Register(
       "Clamped", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// Clamped
        /// 
        public bool Clamped
        {
            get
            {
                return (bool)this.GetValue(ClampedProperty);
            }
            set
            {
                this.SetValue(ClampedProperty, value);
            }
        }
        public static readonly DependencyProperty UnclampedProperty = DependencyProperty.Register(
       "Unclamped", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// Unclamped
        /// 
        public bool Unclamped
        {
            get
            {
                return (bool)this.GetValue(UnclampedProperty);
            }
            set
            {
                this.SetValue(UnclampedProperty, value);
            }
        }
        public static readonly DependencyProperty LockedProperty = DependencyProperty.Register(
       "Locked", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// Locked
        /// 
        public bool Locked
        {
            get
            {
                return (bool)this.GetValue(LockedProperty);
            }
            set
            {
                this.SetValue(LockedProperty, value);
            }
        }
        public static readonly DependencyProperty UnlockedProperty = DependencyProperty.Register(
       "Unlocked", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// Unlocked
        /// 
        public bool Unlocked
        {
            get
            {
                return (bool)this.GetValue(UnlockedProperty);
            }
            set
            {
                this.SetValue(UnlockedProperty, value);
            }
        }
        public static readonly DependencyProperty DripOpenedProperty = DependencyProperty.Register(
       "DripOpened", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// DripOpened
        /// 
        public bool DripOpened
        {
            get
            {
                return (bool)this.GetValue(DripOpenedProperty);
            }
            set
            {
                this.SetValue(DripOpenedProperty, value);
            }
        }
        public static readonly DependencyProperty DripClosedProperty = DependencyProperty.Register(
       "DripClosed", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// DripClosed
        /// 
        public bool DripClosed
        {
            get
            {
                return (bool)this.GetValue(DripClosedProperty);
            }
            set
            {
                this.SetValue(DripClosedProperty, value);
            }
        }
        public static readonly DependencyProperty DripHorizontalProperty = DependencyProperty.Register(
       "DripHorizontal", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// DripHorizontal
        /// 
        public bool DripHorizontal
        {
            get
            {
                return (bool)this.GetValue(DripHorizontalProperty);
            }
            set
            {
                this.SetValue(DripHorizontalProperty, value);
            }
        }
        public static readonly DependencyProperty DripVerticalProperty = DependencyProperty.Register(
       "DripVertical", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// DripVertical
        /// 
        public bool DripVertical
        {
            get
            {
                return (bool)this.GetValue(DripVerticalProperty);
            }
            set
            {
                this.SetValue(DripVerticalProperty, value);
            }
        }
        public static readonly DependencyProperty ManualModeProperty = DependencyProperty.Register(
       "ManualMode", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// ManualMode
        /// 
        public bool ManualMode
        {
            get
            {
                return (bool)this.GetValue(ManualModeProperty);
            }
            set
            {
                this.SetValue(ManualModeProperty, value);
            }
        }
        public static readonly DependencyProperty TargetStationProperty = DependencyProperty.Register(
      "TargetStation", typeof(string), typeof(TransporterOperationControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// TargetStation
        /// 
        public string TargetStation
        {
            get
            {
                return (string)this.GetValue(TargetStationProperty);
            }
            set
            {
                this.SetValue(TargetStationProperty, value);
            }
        }
        public static readonly DependencyProperty IsElevatorInUpPlaceProperty = DependencyProperty.Register(
            "IsElevatorInUpPlace", typeof(bool), typeof(TransporterOperationControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// IsElevatorInUpPlace
        /// 
        public bool IsElevatorInUpPlace
        {
            get
            {
                return (bool)this.GetValue(IsElevatorInUpPlaceProperty);
            }
            set
            {
                this.SetValue(IsElevatorInUpPlaceProperty, value);
            }
        }
        #endregion
        public TransporterOperationControl()
        {
            InitializeComponent();
        }
        private void Clamp_Click(object sender, RoutedEventArgs e)
        {
            if (!IsElevatorInUpPlace)
            {
                MessageBox.Show("Elevator is not in 'UP' place", "Clamp", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Extend");
        }
        private void Unclamp_Click(object sender, RoutedEventArgs e)
        {
            if (!IsElevatorInUpPlace)
            {
                MessageBox.Show("Elevator is not in 'UP' place", "Clamp", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Retract");
        }
        private void Lock_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Lock");
        }
        private void Unlock_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Unlock");
        }
        private void Pick_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(TargetStation))
            {
                MessageBox.Show("Gantry is not in station", "pick", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.PickUpFrom", TargetStation);
        }
        private void Place_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(TargetStation))
            {
                MessageBox.Show("Gantry is not in station", "place", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.PutDownTo", TargetStation);
        }
    }
}