using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Threading;

namespace DansoriEQ.App;

/// <summary>Brand splash shown briefly at startup. Auto-closes after <see cref="HoldMs"/>.</summary>
public partial class SplashWindow : Window
{
    public const int HoldMs = 1700;

    public SplashWindow()
    {
        InitializeComponent();
        Loaded += (_, __) =>
        {
            Bars.Start();
            BeginAnimation(OpacityProperty, new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(280)));

            var t = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(HoldMs) };
            t.Tick += (s, e) =>
            {
                ((DispatcherTimer)s!).Stop();
                var fade = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(260));
                fade.Completed += (_, __2) => { Bars.Stop(); Close(); };
                BeginAnimation(OpacityProperty, fade);
            };
            t.Start();
        };
    }
}
