using MECF.Framework.Common.Equipment;
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
{
    /// <summary>
    /// WHClampControl.xaml 的交互逻辑
    /// </summary>
    public partial class WHClampControl : UserControl
    {
        public WHClampControl()
        {
            InitializeComponent();
        }
        public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
          "ModuleName", typeof(string), typeof(WHClampControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
        /// <summary>
        /// 模块名称
        /// </summary>
        public string ModuleName
        {
            get
            {
                return (string)this.GetValue(ModuleNameProperty);
            }
            set
            {
                this.SetValue(ModuleNameProperty, value);
            }
        }

        public static readonly DependencyProperty IsWHClampProperty = DependencyProperty.Register(
            "IsWHClamp", typeof(bool), typeof(WHClampControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// <summary>
        /// IsWHClamp
        /// </summary>
        public bool IsWHClamp
        {
            get
            {
                return (bool)this.GetValue(IsWHClampProperty);
            }
            set
            {
                this.SetValue(IsWHClampProperty, value);
            }
        }

        public static readonly DependencyProperty IsWHUnclampProperty = DependencyProperty.Register(
            "IsWHUnclamp", typeof(bool), typeof(WHClampControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// <summary>
        /// IsWHUnclamp
        /// </summary>
        public bool IsWHUnclamp
        {
            get
            {
                return (bool)this.GetValue(IsWHUnclampProperty);
            }
            set
            {
                this.SetValue(IsWHUnclampProperty, value);
            }
        }

        public static readonly DependencyProperty IsButtonEnabledProperty = DependencyProperty.Register(
            "IsButtonEnabled", typeof(bool), typeof(WHClampControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// <summary>
        /// IsButtonEnabled(WHDisconncect)
        /// </summary>
        public bool IsButtonEnabled
        {
            get
            {
                return (bool)this.GetValue(IsButtonEnabledProperty);
            }
            set
            {
                this.SetValue(IsButtonEnabledProperty, value);
            }
        }

        public static readonly DependencyProperty ClampStatusProperty = DependencyProperty.Register(
           "ClampStatus", typeof(string), typeof(WHClampControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnItemsSourceChanged)));
        /// <summary>
        /// ClampStatus
        /// </summary>
        public string ClampStatus
        {
            get
            {
                return (string)this.GetValue(ClampStatusProperty);
            }
            set
            {
                this.SetValue(ClampStatusProperty, value);
            }
        }
        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null)
            {
                string currentMode = (string)e.NewValue;
                switch (currentMode)
                {
                    case "Clamped":
                        d.SetValue(IsWHClampProperty, true);
                        d.SetValue(IsWHUnclampProperty, false); break;
                    case "Unclamped":
                        d.SetValue(IsWHClampProperty, false);
                        d.SetValue(IsWHUnclampProperty, true); break;
                    case "Disconnect":
                        d.SetValue(IsWHClampProperty, false);
                        d.SetValue(IsWHUnclampProperty, false); break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// WH Clamp
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WHClamp_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.WaferHolderClampOn");
        }
        /// <summary>
        /// WH Clamp
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WHUnclamp_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.WaferHolderUnclampOn");
        }
        /// <summary>
        /// WH Disconnect
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WHDisconnect_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.WaferHolderDisconnect");
        }
    }
}