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.DeEncryptMessage
{
    /// <summary>
    /// Interaktionslogik für FrmMain.xaml
    /// </summary>
    public partial class FrmMain : Window
    {
        public string Password { get; set; }
        public bool CloseAtLostFocus { get; set; }
        public FrmMain()
        {
            InitializeComponent();
            Deactivated += FrmMain_Deactivated;
            DataContext = new MVVM.ViewModel.CurrentTimeViewModel();
        }

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

        private void btnDeCrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tboutput.Text = DeEncryptString.DeEncrypt.DecryptString(tbInput.Text, Password);
            }
            catch (Exception)
            {
                MessageBox.Show("Text kann nicht entschlüsselt werden!", "Achtung", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnCrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                tboutput.Text = DeEncryptString.DeEncrypt.CryptString(tbInput.Text, Password);
            }
            catch (Exception)
            {
                MessageBox.Show("Text kann nicht verschlüsselt werden!", "Achtung", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
