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 XMessageBox : MetroWindow
    {
        System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
        int timerCount = 0;
        int _CountdownFrom = 10;

        public XMessageBox(string Title, string Message, MessageBoxImage image, bool withTimer = true, int CountdownFrom = 10)
        {
            InitializeComponent();

            _CountdownFrom = CountdownFrom;

            if (withTimer)
            {
                timer.Interval = TimeSpan.FromSeconds(1);
                timer.Tick += Timer_Tick;
                timer.Start();
            }

            this.Title = Title;
            this.Message.Text = Message;

            var selectedImage = System.Drawing.SystemIcons.Error;
            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());
        }

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

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

        private void Window_Closed(object sender, EventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}
