using FasdDesktopUi.Basics.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static C4IT.Logging.cLogManager;

namespace FasdDesktopUi.Pages.SuccessPage
{
    public partial class SuccessPage : Window, IBlurInvoker
    {
        public SuccessPage()
        {
            InitializeComponent();
        }

        private void CloseButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Close();
        }

        private void CloseButton_TouchDown(object sender, TouchEventArgs e)
        {
            Close();
        }

        public async void BlurInvoker_IsActiveChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                BlurInvoker.InvokeVisibilityChanged(this, new EventArgs());

                if (!IsVisible)
                    return;

                const int delayInMilliSeconds = 750;
                const int animationDurationInMilliSeconds = 750;

                await Task.Delay(delayInMilliSeconds);
                DoubleAnimation opacityAnimation = new DoubleAnimation(0, TimeSpan.FromMilliseconds(animationDurationInMilliSeconds));
                MainBorder.BeginAnimation(OpacityProperty, opacityAnimation);
                await Task.Delay(animationDurationInMilliSeconds);
                Close();

            }
            catch (Exception E)
            {
                LogException(E);
            }


        }

        public bool BlurInvoker_IsActive => IsVisible;

    }
}
