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 PunkHPX8_Themes.UserControls
{
    /// 
    /// RecipeModeControl.xaml 的交互逻辑
    /// 
    public partial class RecipeModeControl : UserControl
    {
        public RecipeModeControl()
        {
            InitializeComponent();
        }
        public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
         "ModuleName", typeof(string), typeof(RecipeModeControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// 模块名称
        /// 
        public string ModuleName
        {
            get
            {
                return (string)this.GetValue(ModuleNameProperty);
            }
            set
            {
                this.SetValue(ModuleNameProperty, value);
            }
        }
        public static readonly DependencyProperty IsEngineeringProperty = DependencyProperty.Register(
           "IsEngineering", typeof(bool), typeof(RecipeModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// IsEngineering
        /// 
        public bool IsEngineering
        {
            get
            {
                return (bool)this.GetValue(IsEngineeringProperty);
            }
            set
            {
                this.SetValue(IsEngineeringProperty, value);
            }
        }
        public static readonly DependencyProperty IsProductionProperty = DependencyProperty.Register(
            "IsProduction", typeof(bool), typeof(RecipeModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
        /// 
        /// IsProduction
        /// 
        public bool IsProduction
        {
            get
            {
                return (bool)this.GetValue(IsProductionProperty);
            }
            set
            {
                this.SetValue(IsProductionProperty, value);
            }
        }
        public static readonly DependencyProperty RecipeModeValueProperty = DependencyProperty.Register(
           "RecipeModeValue", typeof(string), typeof(RecipeModeControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnRecipeModeValueChanged)));
        /// 
        /// RecipeModeValue
        /// 
        public string RecipeModeValue
        {
            get
            {
                return (string)this.GetValue(RecipeModeValueProperty);
            }
            set
            {
                this.SetValue(RecipeModeValueProperty, value);
            }
        }
        private static void OnRecipeModeValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            string moduleName = (string)d.GetValue(ModuleNameProperty);
            RecipeModeControl control = (RecipeModeControl)d;
            if (e.NewValue != null)
            {
                string currentMode = (string)e.NewValue;
                switch (currentMode)
                {
                    case "Engineering":
                        d.SetValue(IsEngineeringProperty, true);
                        d.SetValue(IsProductionProperty, false); 
                        break;
                    case "Production":
                        d.SetValue(IsEngineeringProperty, false);
                        d.SetValue(IsProductionProperty, true); 
                        break;
                    default:
                        break;
                }
            }
        }
        private void Engineering_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EngineeringModeAction");
        }
        private void Production_Click(object sender, RoutedEventArgs e)
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ProductionModeAction");
        }
    }
}