using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.Common.RecipeCenter;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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
{
    /// 
    /// RecipeLoad.xaml 的交互逻辑
    /// 
    public partial class RecipeLoad : UserControl
    {
        public RecipeLoad()
        {
            InitializeComponent();
        }
        public static readonly DependencyProperty SelectedRecipeNodeProperty = DependencyProperty.Register("SelectedRecipeNode", typeof(RecipeNode), typeof(RecipeLoad),
               new FrameworkPropertyMetadata(null, new PropertyChangedCallback(SelectedRecipeNodeChanged)));
        /// 
        /// 当前选中recipe节点
        /// 
        public RecipeNode SelectedRecipeNode
        {
            get
            {
                return (RecipeNode)this.GetValue(SelectedRecipeNodeProperty);
            }
            set
            {
                this.SetValue(SelectedRecipeNodeProperty, value);
            }
        }
        public static readonly DependencyProperty RecipeTypeProperty = DependencyProperty.Register("RecipeType", typeof(string), typeof(RecipeLoad));
        /// 
        /// Recipe类型
        /// 
        public string RecipeType
        {
            get
            {
                return (string)this.GetValue(RecipeTypeProperty);
            }
            set
            {
                this.SetValue(RecipeTypeProperty, value);
            }
        }
        public static readonly DependencyProperty ModuleProperty = DependencyProperty.Register("Module", typeof(string), typeof(RecipeLoad));
        /// 
        /// Module
        /// 
        public string Module
        {
            get
            {
                return (string)this.GetValue(ModuleProperty);
            }
            set
            {
                this.SetValue(ModuleProperty, value);
            }
        }
        public static readonly DependencyProperty LoadEnabledProperty = DependencyProperty.Register("LoadEnabled", typeof(bool), typeof(RecipeLoad),
               new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// Load按钮可用性
        /// 
        public bool LoadEnabled
        {
            get
            {
                return (bool)this.GetValue(LoadEnabledProperty);
            }
            set
            {
                this.SetValue(SelectedRecipeNodeProperty, value);
            }
        }
        public static readonly DependencyProperty HeadNameProperty = DependencyProperty.Register("HeadName", typeof(string), typeof(RecipeLoad));
        /// 
        /// HeadName
        /// 
        public string HeadName
        {
            get
            {
                return (string)this.GetValue(HeadNameProperty);
            }
            set
            {
                this.SetValue(HeadNameProperty, value);
            }
        }
        public static readonly DependencyProperty ReplenNameProperty = DependencyProperty.Register("ReplenName", typeof(string), typeof(RecipeLoad));
        /// 
        /// ReplenName
        /// 
        public string ReplenName
        {
            get
            {
                return (string)this.GetValue(ReplenNameProperty);
            }
            set
            {
                this.SetValue(ReplenNameProperty, value);
            }
        }
        public static readonly DependencyProperty RecipeModeValueProperty = DependencyProperty.Register(
          "RecipeModeValue", typeof(string), typeof(RecipeLoad));
        /// 
        /// OpertationModeValue
        /// 
        public string RecipeModeValue
        {
            get
            {
                return (string)this.GetValue(RecipeModeValueProperty);
            }
            set
            {
                this.SetValue(RecipeModeValueProperty, value);
            }
        }
        private static void SelectedRecipeNodeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if(e.NewValue!=null)
            {
                d.SetValue(LoadEnabledProperty, true);
            }
            else
            {
                d.SetValue(LoadEnabledProperty, false);
            }
        }
        private void LoadRecipe_Click(object sender, RoutedEventArgs e)
        {
            if (RecipeType == "rds")
            {
                InvokeClient.Instance.Service.DoOperation($"{Module}.LoadRecipe", SelectedRecipeNode.RecipeFullFileName, ReplenName);
            }
            else
            {
                InvokeClient.Instance.Service.DoOperation($"{Module}.LoadRecipe", SelectedRecipeNode.RecipeFullFileName);
            }
        }
    }
}