using Aitex.Core.Common;
using Aitex.Core.UI.MVVM;
using MECF.Framework.Common.Equipment;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
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.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Aitex.Core.UI.Control
{
    /// 
    /// ATMDualArmRobot.xaml 的交互逻辑
    /// 
    public partial class BoatElevatorMap : UserControl, INotifyPropertyChanged
    {
        protected readonly int MoveTime = 300;
        private const int AnimationTimeout = 3000; // seconds
        private SolidColorBrush SDBrush = new SolidColorBrush(Color.FromArgb(255, 251, 147, 85));
        private SolidColorBrush FDBrush = new SolidColorBrush(Color.FromArgb(255, 170, 147, 255));
        private SolidColorBrush PDBrush = new SolidColorBrush(Color.FromArgb(255, 2, 255, 255));
        private SolidColorBrush M1Brush = new SolidColorBrush(Color.FromArgb(255, 3, 149, 255));
        private SolidColorBrush M2Brush = new SolidColorBrush(Color.FromArgb(255, 255, 111, 171));
        private SolidColorBrush NoneBrush = new SolidColorBrush(Color.FromArgb(255, 213, 210, 200));
        public WaferInfo[] RobotWafers
        {
            get { return (WaferInfo[])GetValue(RobotWafersProperty); }
            set { SetValue(RobotWafersProperty, value); }
        }
        // Using a DependencyProperty as the backing store for RobotWafers.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RobotWafersProperty =
            DependencyProperty.Register("RobotWafers", typeof(WaferInfo[]), typeof(BoatElevatorMap), new PropertyMetadata(null, PropertyChangedCallback));
        public List BoatWafers
        {
            get { return (List)GetValue(BoatWafersProperty); }
            set { SetValue(BoatWafersProperty, value); }
        }
        // Using a DependencyProperty as the backing store for RobotWafers.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BoatWafersProperty =
            DependencyProperty.Register("BoatWafers", typeof(List), typeof(BoatElevatorMap), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender, BoatWafersPropertyChangedCallback));
        public event PropertyChangedEventHandler PropertyChanged;
        static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var self = (BoatElevatorMap)d;
        }
        static void BoatWafersPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var self = (BoatElevatorMap)d;
        }
        public BoatElevatorMap()
        {
#if DEBUG
            System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;
#endif
            InitializeComponent();
            rootCanvas.DataContext = this;
            bgImage = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"pack://application:,,,/FurnaceUI;component/Resources/Images/Controls3/Boat.png"));
        }
        private System.Windows.Media.Imaging.BitmapImage bgImage;
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (DesignerProperties.GetIsInDesignMode(this) || BoatWafers == null)
            {
                return;
            }
            int indexWafer = 0;
            if (bgImage != null)
            {
                drawingContext.DrawImage(bgImage, new Rect(13, 50, 150, 600));
            }
            int fristY = 610;
            foreach (var item in BoatWafers)
            {
                if (item == "----" || string.IsNullOrEmpty(item))
                {
                    // drawingContext.DrawEllipse(NoneBrush, new Pen(NoneBrush, 1), new Point(85, fristY - indexWafer * 3), 60, 30);
                }
                else
                {
                    if (item.StartsWith("P"))
                    {
                        drawingContext.DrawEllipse(PDBrush, new Pen(NoneBrush, 1), new Point(85, fristY - indexWafer * 3), 60, 30);
                    }
                    else if (item == "SD")
                    {
                        drawingContext.DrawEllipse(SDBrush, new Pen(NoneBrush, 1), new Point(85, fristY - indexWafer * 3), 60, 30);
                    }
                    else if (item == "FD" || item == "ED")
                    {
                        drawingContext.DrawEllipse(FDBrush, new Pen(NoneBrush, 1), new Point(85, fristY - indexWafer * 3), 60, 30);
                    }
                    else if (item == "M1")
                    {
                        drawingContext.DrawEllipse(M1Brush, new Pen(NoneBrush, 1), new Point(85, fristY - indexWafer * 3), 60, 30);
                    }
                    else if (item == "M2")
                    {
                        drawingContext.DrawEllipse(M2Brush, new Pen(NoneBrush, 1), new Point(85, fristY - indexWafer * 3), 60, 30);
                    }
                }
                indexWafer += 1;
            }
            base.OnRender(drawingContext);
        }
        private int oldCurrentValue = 0;
        int oldX = 0;
        private void Invoke(Action action)
        {
            Dispatcher.Invoke(action);
        }
        private void LogMsg(string msg)
        {
            var source = "ATMRobot";
            Console.WriteLine("{0} {1}", source, msg);
        }
    }
}