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;
using System.Windows.Threading;

namespace eDosStation
{
    /// <summary>
    /// Interaction logic for InstMessage.xaml
    /// </summary>
    public partial class InstMessage : Window
    {
        DispatcherTimer dispatcherTimer;
        int UserSeconds; 
        public InstMessage(TextBlock comments)
        {
            InitializeComponent();
            sComments.Children.Add(comments);
        }

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

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            sComments.Children.Clear();
        }

        private void SwitchToTask(object sender, EventArgs e)
        {
            if (--UserSeconds > 0 )
            {
                //tUserSeconds.Text = UserSeconds.ToString();
                pUserSeconds.Value = UserSeconds;
            }
            else
            {
                dispatcherTimer.Stop();
                dispatcherTimer.Tick -= SwitchToTask;
                sComments.Children.Clear();
                Close();
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            UserSeconds = 20;
            pUserSeconds.Maximum = pUserSeconds.Value= UserSeconds;
            dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal);
            dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
            dispatcherTimer.Tick += SwitchToTask;
            dispatcherTimer.Start();
        }
    }
}
