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.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.BallotNumber;

namespace Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.Header
{
    
    
    
    public partial class AffiliationHeaderView : UserControl
    {
        public AffiliationHeaderView()
        {
            InitializeComponent();
        }

        private void StopAndReRouteEventToUserControl(object sender, KeyEventArgs sourceEvent)
        {
            if (!sourceEvent.Key.Equals(Key.Left) && (!sourceEvent.Key.Equals(Key.Right)))
                return;

            sourceEvent.Handled = true;
            var relaunchedEvent = CreateNewKeyDownEventArgs(sourceEvent);
            RaiseEvent(relaunchedEvent);
        }

        private KeyEventArgs CreateNewKeyDownEventArgs(KeyEventArgs sourceEvent)
        {
            return new KeyEventArgs(
                sourceEvent.KeyboardDevice,
                sourceEvent.InputSource,
                sourceEvent.Timestamp,
                sourceEvent.Key)
            {
                RoutedEvent = Keyboard.KeyDownEvent,
                Source = sourceEvent.OriginalSource
            };
        }

        private void AffiliateDropDown_OnDropDownClosed(object sender, EventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(SetFocusOnContinueButtonAfterAffiliationSelection));
        }

        private void SetFocusOnContinueButtonAfterAffiliationSelection()
        {
            var ballotNumberViewModel = DataContext as AffiliationHeaderViewModel;
            if (ballotNumberViewModel != null)
            {
                NextButtonBlinking.Focus();
            }
        }
    }
}

