using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace TheGameExtreme.view
{
    public partial class GamePreparationPage : ContentPage
    {
        private string instructionText;
        public string InstructionText
        {
            get { return instructionText; }
            set
            {
                instructionText = value;
                OnPropertyChanged("InstructionText");
            }
        }
        public List<int> listNbPlayer = new List<int> { 1, 2, 3, 4, 5 };
        public List<string> listGameMode = new List<string> { "entières",  "relatives", "décimales", "fractionnées" };
        public List<int> listNbStack = new List<int> { 4, 5, 6, 7, 8 };
 

        public GamePreparationPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);
            //Instruction.SetBinding(Label.TextProperty, new Binding("InstructionText", source: this));
            InstructionText = AppRessource.StrPlayerSelection;

            PlayerSelecter.ItemsSource = listNbPlayer;
            PlayerSelecter.SelectedIndex = 0;

            SelectMode.ItemsSource = listGameMode;
            SelectMode.SelectedIndex = 0;

            SelectNbStack.ItemsSource = listNbStack;
            SelectNbStack.SelectedIndex = 0;
        }

        private async void Back(object sender, EventArgs e)
        {
            await Navigation.PopAsync();
        }

        private async void Play(object sender, EventArgs args)
        {
            List<string> playersNames = new List<string>();
            

            for (int i = 0; i < NameList.Children.Count; i++)
            {
                playersNames.Add(((Entry)NameList.Children[i]).Text);
                if (string.IsNullOrWhiteSpace(playersNames[playersNames.Count - 1]))
                {
                    await DisplayAlert("Erreur pseudo", AppRessource.StrEnterPseudo, "OK");
                    return;
                }
            }

            await Navigation.PushAsync(new MainPage(playersNames));
        }

        private void ChangedPseudo(object sender, EventArgs args)
        {
            while (NameList.Children.Count != (int)PlayerSelecter.SelectedItem)
            {
                if (NameList.Children.Count < (int)PlayerSelecter.SelectedItem)
                {

                    Entry e = new Entry
                    {
                        Placeholder = "Pseudo",
                        BackgroundColor = (Color)Application.Current.Resources["SkyBlueColor"]
                    };
                    //Frame myFrame = new Frame
                    //{
                    //    BackgroundColor = (Color)Application.Current.Resources["SkyBlueColor"],
                    //    HeightRequest = 45,
                    //    VerticalOptions = LayoutOptions.Center,
                    //    HorizontalOptions = LayoutOptions.Center,
                    //    WidthRequest = 120,
                    //    CornerRadius = 10,
                    //    Content = e
                    //};

                    NameList.Children.Add(e);
                }
                else
                {
                    NameList.Children.RemoveAt(NameList.Children.Count - 1);
                }
            }
        }

        

        private void SelectNbStack_Changed(object sender, EventArgs args)
        {

        }

        private void SelectMode_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
