using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Moshaverino.Views.ActivePhone
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class EnterCode : ContentView
    {
        public EnterCode()
        {
            InitializeComponent();
            codeEntryA.Focus();
        }

        public event EventHandler SubmitCodeClicked;
        private void SubmitCodeButton_OnClicked(object sender, EventArgs e)
        {
            SubmitCodeClicked?.Invoke($"{codeEntryA.Text}{codeEntryB.Text}{codeEntryC.Text}{codeEntryD.Text}{codeEntryE.Text}{codeEntryF.Text}",e);
        }

        private void CodeEntryA_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (e.NewTextValue.Length == 1)
                codeEntryB.Focus();
        }
        private void CodeEntryB_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (e.NewTextValue.Length == 1)
                codeEntryC.Focus();
        }
        private void CodeEntryC_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (e.NewTextValue.Length == 1)
                codeEntryD.Focus();
        }
        private void CodeEntryD_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (e.NewTextValue.Length == 1)
                codeEntryE.Focus();
        }
        private void CodeEntryE_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (e.NewTextValue.Length == 1)
                codeEntryF.Focus();
        }
        private void CodeEntryF_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (e.NewTextValue.Length == 1) ;
        }
    }
}