using MahApps.Metro.Controls;
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 ZKuP
{
    /// <summary>
    /// Interaktionslogik für XMessageBox.xaml
    /// </summary>
    public partial class XMessageBoxFahrzeugAnzahl : MetroWindow
    {
        string _Watermark = "";
        public string OldFzgAnzahl { get; set; } = "1";
        public string FzgAnzahlText { get; set; } = " Fahrzeug wird";
        public string bereitsGenehmigt { get; set; } = "";
        public string ResultText { get; set; }
        public MessageBoxResult ResultButton {  get; set; }

        public XMessageBoxFahrzeugAnzahl(int oldFzgAnzahl = 1, int id = 0)
        {
            this.DataContext = this;
            OldFzgAnzahl = oldFzgAnzahl.ToString();
            if (oldFzgAnzahl > 1)
            {
                FzgAnzahlText = " Fahrzeuge sind";
                bereitsGenehmigt = "Die bereits genehmigten ";
            }

            InitializeComponent();


            _Watermark = "Email-Adresse zur Benachrichtigung";

            this.Title = "Fahrzeuganzahl > 1";

            this.Topmost = true;

            MahApps.Metro.Controls.TextBoxHelper.SetWatermark(tbTextBox, _Watermark);

            var selectedImage = System.Drawing.SystemIcons.Question;
            //switch (image)
            //{
            //    case MessageBoxImage.Error:
            //        selectedImage = System.Drawing.SystemIcons.Error;
            //        break;
            //    case MessageBoxImage.Information:
            //        selectedImage = System.Drawing.SystemIcons.Information;
            //        break;
            //    case MessageBoxImage.Question:
            //        selectedImage = System.Drawing.SystemIcons.Question;
            //        break;
            //    case MessageBoxImage.Warning:
            //        selectedImage = System.Drawing.SystemIcons.Warning;
            //        break;
            //    default:
            //        selectedImage = System.Drawing.SystemIcons.Error;
            //        break;
            //}

            this.Image.Source = Helper.ConvertBitmapToImage(selectedImage.ToBitmap());

            tbTextBox.Text = SQL.ReadSingleValue($"SELECT Email FROM {MainWindow.table}.fzgAnmeldung WHERE idFirmen = '{id}'");
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            //timerCount += 1;
            //btnBox.Content = $"OK - {(10 - timerCount).ToString()}";

            //if (timerCount >= 10)
            //    Application.Current.Shutdown();
        }


        private void tbTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (Helper.IsValidEmailAddress((sender as TextBox).Text)) btnYes.IsEnabled = true;
            else btnYes.IsEnabled = false;
        }

        private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //if (string.IsNullOrWhiteSpace(tbTextBox.Text) && !string.IsNullOrWhiteSpace(_errorMessageIfNothingProvided))
            //{
            //    e.Cancel = true;
            //    MessageBox.Show($"{_Watermark} muss angegeben werden!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
            //    return;
            //}
            //else
            //{
                //ResultText = tbTextBox.Text;

                //this.DialogResult = true;
            //}
        }

        private void btnYes_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbTextBox.Text))
            {
                MessageBox.Show($"{_Watermark} muss angegeben werden!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Helper.IsValidEmailAddress(tbTextBox.Text))
            {
                MessageBox.Show($"{tbTextBox.Text} ist keine gültige Email-Adresse!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            ResultText = tbTextBox.Text;
            ResultButton = MessageBoxResult.Yes;

            this.DialogResult = true;
            this.Close();
        }

        private void btnNo_Click(object sender, RoutedEventArgs e)
        {
            ResultText = tbTextBox.Text;
            ResultButton = MessageBoxResult.No;

            this.DialogResult = true;
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            ResultButton = MessageBoxResult.Cancel;
            this.Close();
        }
    }
}
