using OpenSEMI.ClientBase;
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 PunkHPX8_Themes.UserControls
{
    /// 
    /// PufControl.xaml 的交互逻辑
    /// 
    public partial class PufControl : UserControl
    {
        public enum LoaderXLocation
        {
            Parker = 0,
            Efem = 1,
            Loader = 2
        }
        public enum LoaderRotation
        {
            Origin=0,
            Reverse = 1
        }
        public PufControl()
        {
            InitializeComponent();
        }
        public static readonly DependencyProperty RotateTransformValueProperty = DependencyProperty.Register("RotateTransformValue", typeof(int), typeof(PufControl));
        public int RotateTransformValue
        {
            get { return (int)this.GetValue(RotateTransformValueProperty); }
            set { this.SetValue(RotateTransformValueProperty, value); }
        }
        public static readonly DependencyProperty PufNameProperty = DependencyProperty.Register("PufName", typeof(string), typeof(PufControl));
        public string PufName
        {
            get { return this.GetValue(PufNameProperty).ToString(); }
            set { this.SetValue(PufNameProperty, value); }
        }
        public static readonly DependencyProperty RobotWaferAProperty = DependencyProperty.Register("RobotWaferA", typeof(WaferInfo), typeof(PufControl));
        public WaferInfo RobotWaferA
        {
            get => (WaferInfo)GetValue(RobotWaferAProperty);
            set => SetValue(RobotWaferAProperty, value);
        }
        public static readonly DependencyProperty RobotWaferBProperty = DependencyProperty.Register("RobotWaferB", typeof(WaferInfo), typeof(PufControl));
        public WaferInfo RobotWaferB
        {
            get => (WaferInfo)GetValue(RobotWaferBProperty);
            set => SetValue(RobotWaferBProperty, value);
        }
        //public static readonly DependencyProperty IsPufChangeProperty = DependencyProperty.Register("IsPufChange", typeof(bool), typeof(PufControl));
        //public bool IsPufChange
        //{
        //    get => (bool)GetValue(IsPufChangeProperty);
        //    set => SetValue(IsPufChangeProperty, value);
        //}
        /// 
        /// Puf Roation UI 动画位置
        /// 
        public static readonly DependencyProperty CurrentXLocationProperty = DependencyProperty.Register("CurrentXLocation", typeof(LoaderXLocation), typeof(PufControl),
            new PropertyMetadata(LoaderXLocation.Parker, PositionChangedCallback));
        public LoaderXLocation CurrentXLocation
        {
            get { return (LoaderXLocation)this.GetValue(CurrentXLocationProperty); }
            set
            {
                this.SetValue(CurrentXLocationProperty, value);
            }
        }
        /// 
        /// Puf Flip UI 动画位置
        /// 
        public static readonly DependencyProperty CurrentRotationProperty = DependencyProperty.Register("CurrentRotation", typeof(LoaderRotation), typeof(PufControl),
            new PropertyMetadata(LoaderRotation.Origin, RotationChangedCallback));
        public LoaderRotation CurrentRotation
        {
            get { return (LoaderRotation)this.GetValue(CurrentRotationProperty); }
            set
            {
                this.SetValue(CurrentRotationProperty, value);
            }
        }
        /// 
        /// Puf Rotation UI位置
        /// 
        public static readonly DependencyProperty PufRotationPositionProperty = DependencyProperty.Register("PufRotationPosition", typeof(double), typeof(PufControl),
       new PropertyMetadata((double)15));
        public double PufRotationPosition
        {
            get { return (double)this.GetValue(PufRotationPositionProperty); }
            set
            {
                this.SetValue(PufRotationPositionProperty, value);
            }
        }
        /// 
        /// Puf Flip UI位置
        /// 
        public static readonly DependencyProperty PufFlipPositionProperty = DependencyProperty.Register("PufFlipPosition", typeof(double), typeof(PufControl),
       new PropertyMetadata((double)15));
        public double PufFlipPosition
        {
            get { return (double)this.GetValue(PufFlipPositionProperty); }
            set
            {
                this.SetValue(PufFlipPositionProperty, value);
            }
        }
        private static void PositionChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var newAct = (LoaderXLocation)e.NewValue;
            var control = d as PufControl;
            GoToPosition(control, newAct);
        }
        private static void RotationChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var newAct = (LoaderRotation)e.NewValue;
            var control = d as PufControl;
            GoToRotation(control, newAct);
        }
        private static void GoToPosition(Control control, LoaderXLocation location)
        {
            VisualStateManager.GoToElementState(control, location.ToString(), false);
        }
        private static void GoToRotation(Control control, LoaderRotation rotation)
        {
            VisualStateManager.GoToElementState(control, rotation.ToString(), false);
        }
    }
}