using parkMonitor.viewModel.devInfoPanel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
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 parkMonitor.view.util {
	/// <summary>
	/// 设备信息面板
	/// </summary>
	public partial class DevInfoPanel : UserControl {
		bool isAutoWidth = false;

		public DevInfoPanel() {
			InitializeComponent();

			//updateCavBoxSize();
		}

		//Left Width
		public static readonly DependencyProperty LeftWidthProperty = DependencyProperty.Register("LeftWidth", typeof(Double), typeof(DevInfoPanel), new PropertyMetadata(Double.NaN));
		public Double LeftWidth {
			get { return (Double)GetValue(LeftWidthProperty); }
			set { SetCurrentValue(LeftWidthProperty, value); }
		}

		//Line Border
		public static readonly DependencyProperty LineBorderProperty = DependencyProperty.Register("LineBorder", typeof(double), typeof(DevInfoPanel), new PropertyMetadata(1.0));
		public double LineBorder {
			get { return (double)GetValue(LineBorderProperty); }
			set { SetCurrentValue(LineBorderProperty, value); }
		}

		//Line Pos
		public static readonly DependencyProperty LineStartPosProperty = DependencyProperty.Register("LineStartPos", typeof(Point), typeof(DevInfoPanel), new FrameworkPropertyMetadata(new Point(0, 0)));
		public Point LineStartPos {
			get { return (Point)GetValue(LineStartPosProperty); }
			set { SetCurrentValue(LineStartPosProperty, value); }
		}

		//Line Pos
		public static readonly DependencyProperty LinePosProperty = DependencyProperty.Register("LinePos", typeof(Point), typeof(DevInfoPanel), new FrameworkPropertyMetadata(new Point(0,0)));
		public Point LinePos {
			get { return (Point)GetValue(LinePosProperty); }
			set { SetCurrentValue(LinePosProperty, value); }
		}
		
		//Line Color
		public static readonly DependencyProperty LineColorProperty = DependencyProperty.Register("LineColor", typeof(Brush), typeof(DevInfoPanel), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6ceff7"))));
		public Brush LineColor {
			get { return (Brush)GetValue(LineColorProperty); }
			set { SetCurrentValue(LineColorProperty, value); }
		}

		//ItemsSource
		public static readonly DependencyProperty ItemsSourcePro = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(DevInfoPanel), new FrameworkPropertyMetadata(null));
		public IEnumerable ItemsSource {
			get { return (IEnumerable)GetValue(ItemsSourcePro); }
			set { SetValue(ItemsSourcePro, value); }
		}

		private void updateCavBoxSize() {
			Point pos = new Point();
			pos.X = grdLineBox.ActualWidth / 2;
			pos.Y = grdLineBox.ActualHeight / 2;
			LineStartPos = pos;
		}

		private void grdLineBox_SizeChanged(object sender, SizeChangedEventArgs e) {
			updateCavBoxSize();
		}

		private void lblName_Loaded(object sender, RoutedEventArgs e) {
			if(Double.IsNaN(LeftWidth)) {
				LeftWidth = 0;
				isAutoWidth = true;
			}

			if(!isAutoWidth) {
				return;
			}

			Label lbl = sender as Label;
			if(lbl == null) {
				return;
			}
			
			LeftWidth = Math.Max(LeftWidth, lbl.ActualWidth + 2);
		}

	}
}
