using PlantBox.Client.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

namespace PlantBox.Client.Forms.Settings
{
	[XamlCompilation(XamlCompilationOptions.Compile)]
	public partial class LanguageSelectorPage : ContentPage
	{
        private CultureInfo[] _supportedCultures = new CultureInfo[]
        {
            new CultureInfo("en-US"),
            new CultureInfo("fr-FR")
        };

        public LanguageSelectorPage()
		{
			InitializeComponent();

            listView.ItemsSource = _supportedCultures;
		}

        private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item is CultureInfo culture)
            {
                App.Settings.Language = culture;
                Locale.Culture = culture;

                await App.Settings.SaveAsync();

                (Application.Current as App).MainPage = new MainPage();
                //await DisplayAlert(Locale.LanguageChangedTitle, Locale.LanguageChangedMessage, "Ok");
                //await Navigation.PopAsync();
            }
        }
    }
}