using BDU.Models;
using MahApps.Metro.Controls;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
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 BDU.Windows
{
    /// <summary>
    /// UsersAdd.xaml 的交互逻辑
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class UserSettingWindow : MetroWindow
    {
        public UserModel UserInfo { get; set; } = new();

        public bool IsEdit { get; set; } = false;

        public bool IsSave = false;

        public UserSettingWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            IsEdit = false;
        }

        public UserSettingWindow(UserModel user)
        {
            InitializeComponent();
            this.DataContext = this;
            UserInfo = user;
            IsEdit = true;
        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            if (UserInfo.PassWord == null || !Regex.IsMatch(UserInfo.PassWord, @"^[^\s\u4e00-\u9fa5]+$"))
            {
                MessageBox.Show("密码格式错误！", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (UserInfo.UserAccount == null || !Regex.IsMatch(UserInfo.UserAccount, @"^[^\s\u4e00-\u9fa5]+$"))
            {
                MessageBox.Show("账号格式错误！", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            IsSave = true;
            this.Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            IsSave = false;
            this.Close();
        }

        private void GroupBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left) DragMove();
        }
    }
}
