
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Input;

using C4IT.Logging;
using C4IT.FASD.Cockpit.Communication;

using FasdCockpitCommunication;

using static C4IT.Logging.cLogManager;

namespace FasdDesktopUi.Pages.SplashScreenView
{
    /// <summary>
    /// Interaction logic for IntroView.xaml
    /// </summary>
    public partial class IntroView : Window
    {
        public const string IntroPath = "MediaContent/F4SD-Intro-001.mov";

        public IntroView()
        {
            MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }

            try
            {
                InitializeComponent();

                var _mediaUri = cFasdCockpitCommunicationBase.Instance.GetMediaContentUri(IntroPath);
                if (_mediaUri != null)
                    VideoPlayer.Source = _mediaUri;

            }
            catch (Exception E)
            {
                LogException(E);
            }
            finally
            {
                if (CM != null) LogMethodEnd(CM);
            }

        }

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

        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
                Close();
        }

        private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (Visibility != Visibility.Visible)
                return;

            VideoPlayer.Play();
        }
    }
}
