using Rkis29.Model;
using Rkis29.View;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Rkis29.ViewModel
{
    public class VMAutor : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string prop = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
        }

        public string Login { get; set; }

        private RelayCommand _autho_ready;
        public RelayCommand Autho_ready
        {
            get
            {
                return _autho_ready ?? new RelayCommand(obj =>
                {
                    var value = (object[])obj;//создание массива значений объекта окна
                    var password = (PasswordBox)value[0];
                    var mainWnd = (Window)value[1];
                    var User = ModelPublic.GetContext().Person.FirstOrDefault(f => f.Logins == Login && f.Passwords == password.Password); //свойство для поиска пользователя
                    if (User != null)
                    {
                        Users.Id = User.Id;
                        Registration registration = new Registration();
                        registration.Show();
                        mainWnd.Close();
                    }
                    else
                    {
                        MessageBox.Show("Неверные данные");
                    }
                });
            }
        }

        public RelayCommand _registrWND;
        public RelayCommand RegistrWND
        {
            get
            {
                return _registrWND ?? new RelayCommand(obj =>
                {
                    
                    Profile profile = new Profile();
                    profile.Show();
                    Window window = (Window)obj;
                    window.Close();
                });
            }
        }
    }
}
