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 DataTag : UserControl, IBoostStationPoint
    {
        public static readonly DependencyProperty IsEditModelProperty = DependencyProperty.Register("IsEditModel", typeof(bool), typeof(DataTag));
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(DataTag));
        public static readonly DependencyProperty InfoProperty = DependencyProperty.Register("Info", typeof(string), typeof(DataTag));
        public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
        public double Value { get; set; }
        public bool IsTemplete { get; set; }
        public bool IsEditModel { get => (bool)GetValue(IsEditModelProperty); set => SetValue(IsEditModelProperty, value); }
        public int Proportion { get; set; }
        public string Info { get => GetValue(InfoProperty) as string; set => SetValue(InfoProperty, value); }
        public Action<Control> Clicked { get; set; }
        string IBoostStationPoint.DataTag { get; set; }
        public bool IsNegate { get; set; }

        /// <summary>
        /// 原始宽
        /// </summary>
        private double _Width;
        /// <summary>
        /// 原始高
        /// </summary>
        private double _Height;
        public DataTag()
        {
            InitializeComponent();
        }

        public void Zoom(int times)
        {
            Proportion += times;
            ToZoom();
        }

        private void ToZoom()
        {
            this.Width = _Width * (1 + Proportion * 0.1);
            this.Height = _Height * (1 + Proportion * 0.1);
        }

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

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            _Width = Width;
            _Height = Height;
            ToZoom();
        }

        private void TextBox_MouseEnter(object sender, MouseEventArgs e)
        {
            (sender as TextBox).Focus();
        }
    }
}