using com.superscene.ui;
using System;
using System.Collections.Generic;
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 class DevMenuListBox : ListBox {
		static DevMenuListBox() {
			DefaultStyleKeyProperty.OverrideMetadata(typeof(DevMenuListBox), new FrameworkPropertyMetadata(typeof(DevMenuListBox)));
		}

		public DevMenuListBox() {
			CmdScale = new SupRelayCommand(new Action(onScale));

			PreviewMouseDown += (object sender, MouseButtonEventArgs e) => {
				SelectedIndex = -1;
				IsClickServer = false;
				IsClicenClient = false;
			};

			SelectionChanged += (object sender, SelectionChangedEventArgs e) => {
				if(e.OriginalSource != this) {
					e.Handled = true;
					return;
				}

				if(!IsServerClient) {
					return;
				}

				//发送事件
				if(IsClickServer) {
					RoutedEventArgs arg = new RoutedEventArgs(ServerClickProperty, this);
					RaiseEvent(arg);
				}else if(IsClicenClient) {
					RoutedEventArgs arg = new RoutedEventArgs(ClientClickProperty, this);
					RaiseEvent(arg);
				}

				e.Handled = true;
			};

		}

		//Content
		public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(string), typeof(DevMenuListBox), new PropertyMetadata(""));
		public string Content {
			get { return (string)GetValue(ContentProperty); }
			set { SetCurrentValue(ContentProperty, value); }
		}

		//Source
		public static readonly DependencyProperty SourcePro = DependencyProperty.Register("Source", typeof(ImageSource), typeof(DevMenuListBox), new PropertyMetadata(null));
		public ImageSource Source {
			get { return (ImageSource)GetValue(SourcePro); }
			set { SetCurrentValue(SourcePro, value); }
		}

		//附加图片资源
		public static readonly DependencyProperty MiniSourcePro = DependencyProperty.Register("MiniSource", typeof(ImageSource), typeof(DevMenuListBox), new PropertyMetadata(null));
		public ImageSource MiniSource {
			get { return (ImageSource)GetValue(MiniSourcePro); }
			set { SetCurrentValue(MiniSourcePro, value); }
		}

		//IsSmall
		public static readonly DependencyProperty IsSmallPro = DependencyProperty.Register("IsSmall", typeof(bool), typeof(DevMenuListBox), new PropertyMetadata(false));
		public bool IsSmall {
			get { return (bool)GetValue(IsSmallPro); }
			set { SetCurrentValue(IsSmallPro, value); }
		}

		//Is Server Client
		public static readonly DependencyProperty IsServerClientPro = DependencyProperty.Register("IsServerClient", typeof(bool), typeof(DevMenuListBox), new PropertyMetadata(false));
		public bool IsServerClient {
			get { return (bool)GetValue(IsServerClientPro); }
			set { SetCurrentValue(IsServerClientPro, value); }
		}

		//缩小/放大事件
		public static readonly DependencyProperty CmdScaleProperty = DependencyProperty.Register("CmdScale", typeof(ICommand), typeof(DevMenuListBox));
		public ICommand CmdScale {
			get { return (ICommand)GetValue(CmdScaleProperty); }
			set { SetCurrentValue(CmdScaleProperty, value); }
		}

		//public object Deb { get; }

		private void onScale() {
			IsSmall = !IsSmall;
		}

		//click server
		public static readonly DependencyProperty IsClickServerProperty = DependencyProperty.Register("IsClickServer", typeof(bool), typeof(DevMenuListBox), new PropertyMetadata(false));
		public bool IsClickServer {
			get { return (bool)GetValue(IsClickServerProperty); }
			set { SetCurrentValue(IsClickServerProperty, value); }
		}
		//click client
		public static readonly DependencyProperty IsClicenClientProperty = DependencyProperty.Register("IsClicenClient", typeof(bool), typeof(DevMenuListBox), new PropertyMetadata(false));
		public bool IsClicenClient {
			get { return (bool)GetValue(IsClicenClientProperty); }
			set { SetCurrentValue(IsClicenClientProperty, value); }
		}

		//选择服务器事件
		public static readonly RoutedEvent ServerClickProperty = EventManager.RegisterRoutedEvent("ServerClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(DevMenuListBox));
		public event RoutedEventHandler ServerClick {
			//将路由事件添加路由事件处理程序
			add { AddHandler(ServerClickProperty, value); }
			//从路由事件处理程序中移除路由事件
			remove { RemoveHandler(ServerClickProperty, value); }
		}

		//选择客户端事件
		public static readonly RoutedEvent ClientClickProperty = EventManager.RegisterRoutedEvent("ClientClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(DevMenuListBox));
		public event RoutedEventHandler ClientClick {
			//将路由事件添加路由事件处理程序
			add { AddHandler(ClientClickProperty, value); }
			//从路由事件处理程序中移除路由事件
			remove { RemoveHandler(ClientClickProperty, value); }
		}

	}
	
}
