using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing360.IService;
using MultiLayout.UiModule;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Unity;

namespace FLY.Thick.Blowing360.UI.UiModule
{
    /// <summary>
    /// DynAreaBlowing.xaml 的交互逻辑
    /// </summary>
    public partial class DynAreaBlowing : UserControl
    {
        IBlowingService blowingService;
        IBlowingDetectService blowingDetectService;
        IUnityContainer container;
        public DynAreaBlowing()
        {
            InitializeComponent();
        }

        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IBlowingService blowingService,
            IBlowingDetectService blowingDetectService
            )
        {
            this.container = container;
            this.blowingService = blowingService;
            this.blowingDetectService = blowingDetectService;

            this.DataContext = blowingDetectService;
        }

        private void Border_Blowing_Click(object sender, RoutedEventArgs e)
        {
            var p = container.Resolve<PgBlowing>();
            MultiLayout.FlyLayoutManager.NavigationService.Navigate(p);
        }
    }
    public class DynAreaBlowingVmUt : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public double Angle { get; set; } = -170.2;
        public Misc.DIRECTION Direction { get; set; } = Misc.DIRECTION.FORWARD;
        public TimeSpan RenZiJiaPeriod { get; set; } = TimeSpan.FromMinutes(12.3);
        public TimeSpan PastTime { get; set; } = TimeSpan.FromMinutes(3.3);

        public double FilmVelocity { get; set; } = 50.1;
    }
    public class UiModule2_DynAreaBlowing : MultiLayout.UiModule.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<DynAreaBlowing>();
        }

        /// <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)
        {

        }
    }

    public class Angle2CWConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is double)
                && !(value is int)
                )
            {
                return null;
            }

            int angle = System.Convert.ToInt32(value);
            return -angle;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }


        #endregion
    }

}