using NEIntelligentControl2.Models.BoostStation;
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 NEIntelligentControl2.Views.BoostStation
{
    /// <summary>
    /// 数据标签
    /// </summary>
    public partial class DataLabel : UserControl, IBoostStationPoint
    {
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(DataLabel));
        public static readonly DependencyProperty IsEditModelProperty = DependencyProperty.Register("IsEditModel", typeof(bool), typeof(DataLabel));
        public static readonly DependencyProperty ProportionProperty = DependencyProperty.Register("Proportion", typeof(int), typeof(DataLabel));
        public static readonly DependencyProperty InfoProperty = DependencyProperty.Register("Info", typeof(string), typeof(DataLabel));
        public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
        public double Value { get { double.TryParse(Info, out double d); return d; } set => Info = Math.Round(value, 2).ToString(); }
        /// <summary>
        /// 是否是编辑模式
        /// </summary>
        public bool IsEditModel { get => (bool)GetValue(IsEditModelProperty); set => SetValue(IsEditModelProperty, value); }
        public bool IsTemplete { get; set; }
        public string DataTag { get; set; }
        public int Proportion { get => (int)GetValue(ProportionProperty); set => SetValue(ProportionProperty, value); }
        public string Info { get => GetValue(InfoProperty) as string; set => SetValue(InfoProperty, value); }
        public bool IsNegate { get; set; }
        public Action<Control> Clicked { get; set; }
        public DataLabel()
        {
            Proportion = 12;
            InitializeComponent();
        }

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            IsSelected = !IsSelected && !IsTemplete && IsEditModel;
            Clicked?.Invoke(this);
        }

        public void Zoom(int times)
        {
            Proportion += times;
            TextBlock tb = new TextBlock();
            Binding bd = new Binding("Value");
            RelativeSource rs = new RelativeSource() { AncestorType = typeof(UserControl), Mode = RelativeSourceMode.FindAncestor };
            bd.RelativeSource = rs;
            tb.SetBinding(TextBlock.TextProperty, bd);
            tb.FontSize = Proportion;
            tb.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
            tb.Background = new SolidColorBrush(Color.FromArgb(102, 255, 255, 255));

            _GMain.Children.Clear();
            _GMain.Children.Add(tb);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Info = "-.--";
        }
    }
}
