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;

namespace FSI.Lib.Guis.AutoPw
{
    /// <summary>
    /// Interaktionslogik für FrmMain.xaml
    /// </summary>
    public partial class FrmMain : Window
    {
        public bool CloseAtLostFocus { get; set; }
        public bool PwOk { get; set; }
        public FrmMain()
        {
            InitializeComponent();

            BtnOk.IsEnabled = false;
            Deactivated += FrmMain_Deactivated;
            DataContext = new MVVM.ViewModel.CurrentTimeViewModel();
        }

        private void FrmMain_Deactivated(object sender, System.EventArgs e)
        {
            if (CloseAtLostFocus)
                Visibility = Visibility.Hidden;
        }

        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
            PwOk = false;
        }


        private void TbPw_PasswordChanged(object sender, RoutedEventArgs e)
        {

            if (((PasswordBox)sender).Password.Equals(DateTime.Now.ToString("yyyyMMdd")))
            {
                BtnOk.IsEnabled = true;
                PwOk = true;
            }
            else
            {
                BtnOk.IsEnabled = false;
                PwOk = false;
            }

        }

        private void TbPw_KeyDown(object sender, KeyEventArgs e)
        {
            if (BtnOk.IsEnabled == true)
            {                
                PwOk = true;
            }
            else
            {             
                PwOk = false;
            }
        }
    }
}
