using parkMonitor.view.util;
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.startDeviceServerWin {
	/// <summary>设备启动窗口-服务器</summary>
	public partial class StartDeviceServerWin : Window {
		public StartDeviceClientWinVM winVM = new StartDeviceClientWinVM();

		public StartDeviceServerWin() {
			InitializeComponent();

			DataContext = winVM;
		}

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

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

			//详细信息ViewModel
			var detailVM = new NumMachineDetailVM() {
				name = item.Name,
				Pkey = item.Pkey,
				serNum = item.Pkey.ToString()
			};

			winVM.DevInfoDetail = detailVM.lstData;

			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;
			Debug.WriteLine(ip);
			Debug.WriteLine(port);
		}

		private void btnDisconnect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {

		}

	}
}
