using System.Windows.Controls;
using System.Windows.Input;

namespace Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.RenumberStrikeout
{
    public class RenumberListBox : ListBox
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            SelectRenumberValue(e);
        }

        private void SelectRenumberValue(KeyEventArgs e)
        {
            if (e.Key == Key.Enter || e.Key == Key.Space)
            {
                var listBox = (ListBox)FindName("RenumberValuesListBox");
                if (listBox != null)
                {
                    var selectedRenumberValue = (RenumberViewModel)listBox.SelectedValue;
                    selectedRenumberValue?.Command.Execute(selectedRenumberValue);
                }
            }
        }
    }
}
