using FLY.FilmCasting.AutoDie.IService;
using GalaSoft.MvvmLight.Command;
using MultiLayout.UiModule;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using Unity;

namespace FLY.FilmCasting.AutoDie.UI.Client.UiModule
{
    /// <summary>
    /// Page_DynArea.xaml 的交互逻辑
    /// </summary>
    public partial class DynAreaAutoDie : UserControl
    {

        DynAreaAutoDieVm airRingVm;

        public DynAreaAutoDie()
        {
            InitializeComponent();

        }
        [InjectionMethod]
        public void Init(
            IUnityContainer container
            )
        {
            //获取设备
            airRingVm = container.Resolve<DynAreaAutoDieVm>();

            grid_viewModel.DataContext = airRingVm;


        }
    }
    public class DynAreaAutoDieVm : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public double CurrR { get; set; }

        public DateTime LastChangedTime { get; set; }

        public string Msg { get; set; }

        //IBlowingService blowingService;
        IHeatBufService heatBufService;
        IUnityContainer container;
        IFeedbackHeatService feedbackHeatService;
        IHeatCellService heatCellService;

        DispatcherTimer timer;
        public DynAreaAutoDieVm()
        {

        }



        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IFeedbackHeatService feedbackHeatService,
            IHeatBufService heatBufService,
            IHeatCellService heatCellService
            //IBlowingService blowingService
            )
        {
            this.heatBufService = heatBufService;
            this.container = container;
            this.feedbackHeatService = feedbackHeatService;
            this.heatCellService = heatCellService;
            //this.blowingService = blowingService;

            //Misc.BindingOperations.SetBinding(blowingService, nameof(blowingService.OrgBoltNo), this, nameof(OrgBoltNo));

            Misc.BindingOperations.SetBinding(heatBufService, nameof(heatBufService.CurrR), this, nameof(CurrR));

            Misc.BindingOperations.SetBinding(heatCellService, nameof(heatCellService.LastHeatsChangedTime), this, nameof(LastChangedTime));

            UpdateMsg();

            heatBufService.PropertyChanged += HeatBufService_PropertyChanged;



        }

        private void HeatBufService_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(heatBufService.Stability))
            {
                UpdateMsg();
            }
        }

        void UpdateMsg()
        {
            StableConverter conv = new StableConverter();
            string msg = (string)conv.Convert(heatBufService.Stability, typeof(Common.STABILITY), null, null);
            Msg = msg;
        }
    }

    public class DynAreaAutoDieVmUt : DynAreaAutoDieVm
    {
    }


    public class UiModule2_DynAreaAutoDie : IUiModule2
    {
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
        public string Title => "自动模头.状态";

        public ComponentType Type => ComponentType.DynArea;

        public bool IsUnique => true;

        /// <summary>
        /// 控件
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetComponent(int id, IUnityContainer container)
        {
            return container.Resolve<DynAreaAutoDie>();
        }

        /// <summary>
        /// 控件缩略图,用于编辑界面时,大致看看
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetThumbnail()
        {
            return new System.Windows.Controls.Grid();
        }


        /// <summary>
        /// 给出全部控件ID, 控件自行删除没有的参数
        /// </summary>
        /// <param name="IDs"></param>
        public void MatchParam(int[] IDs)
        {
        }
    }
}