using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using 电子展板.Base;

namespace 电子展板.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
        private Window window;
        public DelegateCommand<Window> LoadedCommand { get; set; }
        public DelegateCommand<CancelEventArgs> WindowClosingCommand { get; set; }
        public MainWindowViewModel()
        {
            LoadedCommand = new DelegateCommand<Window>(Loaded);
            WindowClosingCommand = new DelegateCommand<CancelEventArgs>(WindowClosing);
        }

        private void Loaded(Window window)
        {
            this.window = window;
            int screenIndex = 0;
            this.window.Left = (int)(Screen.AllScreens[screenIndex].Bounds.Left / GetDpiScaleX());
            this.window.Top = (int)(Screen.AllScreens[screenIndex].Bounds.Top / GetDpiScaleX());
            this.window.Width = (int)(Screen.AllScreens[screenIndex].Bounds.Width / GetDpiScaleX());
            this.window.Height = (int)(Screen.AllScreens[screenIndex].Bounds.Height / GetDpiScaleX());
            WebServer.Start();
        }

        private void WindowClosing(CancelEventArgs args)
        {
            WebServer.Stop();
            Environment.Exit(0);
        }
        public double GetDpiScaleX()
        {
            return VisualTreeHelper.GetDpi(this.window).DpiScaleX;
        }
    }
}
