using System;
using System.Collections.Generic;
using System.Collections.Specialized;
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 InteractiveKiosk
{
    /// <summary>
    /// Interaction logic for AuthorizationWindow.xaml
    /// </summary>
    public partial class AuthorizationWindow : Window
    {
        InteractiveKioskEntities db = new InteractiveKioskEntities();
        public AuthorizationWindow()
        {
            InitializeComponent();
        }

        //public void TextBox_GotFocus(object sender, RoutedEventArgs e)
        //{
        //    TextBox tb = (TextBox)sender;
        //    tb.Text = string.Empty;
        //    tb.GotFocus -= TextBox_GotFocus;
        //}

        private void username_TextChanged(object sender, RoutedEventArgs e)
        {
            if (username.Text == "Логин")
            {
                username.Foreground = Brushes.Gray;
            }
            else if (username.Text == "")
            {
                username.Foreground = Brushes.Black;
            }
        }

        private void password_TextChanged(object sender, RoutedEventArgs e)
        {
            if (password.Text == "Пароль")
            {
                password.Foreground = Brushes.Gray;
            }
            else if (password.Text == "")
            {
                password.Foreground = Brushes.Black;
            }

        }

        private const string defaultText = "Логин";
        private const string defaultText1 = "Пароль";

        private void Username_GotFocus(object sender, RoutedEventArgs e)
        {
            username.Text = username.Text == defaultText ?
            string.Empty : username.Text;
        }

        private void Password_GotFocus(object sender, RoutedEventArgs e)
        {
            password.Text = password.Text == defaultText1 ?
            string.Empty : password.Text;
        }

        private void Username_LostFocus(object sender, RoutedEventArgs e)
        {
            username.Text = username.Text == string.Empty ?
            defaultText : username.Text;
            
        }
        private void Password_LostFocus(object sender, RoutedEventArgs e)
        {
            password.Text = password.Text == string.Empty ?
            defaultText1 : password.Text;
        }


        private void LoginButton(object sender, RoutedEventArgs e)
        {
            if (username.Text == "" || password.Text == "")
            {
                MessageBox.Show("Введено неверное значение!");
                return;
            }
            if (db.ParkManagers.Select(item => item.Username + " " + item.Password).Contains(username.Text + " " + password.Text))
            {
                MessageBox.Show("Добро пожаловать, вы авторизированы");
                this.Close();
            }
            else
            {
                MessageBox.Show("Введено неверное значение логина/пароля");
            }
        }
    }
}
