using System;
using System.Collections.Generic;
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;
using nukakto.Models;

namespace nukakto
{
    /// <summary>
    /// Логика взаимодействия для Regist.xaml
    /// </summary>
    public partial class Regist : Window
    {
        public Regist()
        {
            InitializeComponent();
        }
        private void HedeText(object sender, MouseEventArgs e)
        {
            Password.IsReadOnly = false;
            Password.Text = ""; // Clear textBox

        }

        private void LeaveCursor(object sender, MouseEventArgs e)
        {


            if (Password.Text == "")
            {
                Password.Text = "Придумайте пароль!";
                Password.IsReadOnly = true;
            }
        }

        private void Emailhade(object sender, MouseEventArgs e)
        {
            Email.IsReadOnly = false;
            Email.Text = "";
        }

        private void LeaveEmail(object sender, MouseEventArgs e)
        {
            if (Email.Text == "")
            {
                Email.Text = "Введите электроную почту";
                Email.IsReadOnly = true;
            }
        }

        private void MiddleHede(object sender, MouseEventArgs e)
        {
            Middle.IsReadOnly = false;
            Middle.Text = "";
        }

        private void LeaveMiddle(object sender, MouseEventArgs e)
        {
            if (Middle.Text == "")
            {
                Middle.Text = "Отчество";
                Middle.IsReadOnly = true;
            }
        }


        private void FirstHede(object sender, MouseEventArgs e)
        {
            First.IsReadOnly = false;
            First.Text = "";
        }

        private void LeaveFirst(object sender, MouseEventArgs e)
        {
            if (First.Text == "")
            {
                First.Text = "Имя";
                First.IsReadOnly = true;
            }
        }

        private void LastHede(object sender, MouseEventArgs e)
        {
            Last.IsReadOnly = false;
            Last.Text = "";
        }

        private void LeaveLast(object sender, MouseEventArgs e)
        {
            if (Last.Text == "")
            {
                Last.Text = "Фамилия";
                Last.IsReadOnly = true;
            }
        }

       
        private void regist_Click(object sender, RoutedEventArgs e)
        {
            if (First.Text != "" && Last.Text != "" && Middle.Text != "" && Email.Text != "" && Password.Text != "")
            {
                gr606_kusanContext context = new gr606_kusanContext();
                var users = context.Users;





                //context.SaveChanges(); // Сохраняю

                User newUser = new User()
                {
                    FirstName = First.Text,
                    LastName = Last.Text,
                    MiddleName = Middle.Text,
                    Password = Password.Text,
                    Login = Email.Text,
                };
                users.Add(newUser);
                context.SaveChanges();
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                this.Hide();


            }
            else
            {
                MessageBox.Show("Все поля должны быть заполнены!");
            }
        }
    }
}
