using parkMonitor.viewModel;
using parkMonitor.viewModel.detail;
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.Shapes;

namespace parkMonitor.view.startNumMachineWin {
	/// <summary>启动号牌机窗口</summary>
	public partial class StartNumMachineWin : Window {
		public StartNumMachineWinVM winVM = new StartNumMachineWinVM();

		public StartNumMachineWin() {
			InitializeComponent();

			DataContext = winVM = new DesignStartNumMachineWinVM();
		}

		public void show(Window parent, DevMenuItemVM item) {
			Owner = parent;

			Title = language.Language.ins.startClient + " - " + item.Name;

			ShowDialog();
		}

		/// <summary>
		/// 命令日志框-鼠标弹起事件
		/// 没有选中文字时，输入框获得焦点
		/// </summary>
		private void txtCmdLog_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
			string txt = txtCmdLog.SelectedText;

			if(txt == "") {
				txtCmdInput.Focus();
			}
		}

		/// <summary>
		/// 命令输入框-键盘弹起事件
		/// </summary>
		private void txtCmdInput_KeyUp(object sender, KeyEventArgs e) {
			//不是回车键
			if(e.Key != Key.Return) {
				return;
			}

			//当前输入的命令
			string txt = winVM.CommanddInput.Trim();
			if(txt == "") {
				return;
			}

			winVM.CommanddLog += txt + "\r\n";
			winVM.CommanddInput = "";

			//滚动到最后一行
			txtCmdLog.ScrollToEnd();
		}

		private void btnConnect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
			string ip = winVM.Ip;
			int port = winVM.port;
		}

		private void btnSearch_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
			
		}
	}
}
