﻿using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace Calculators
{
	public partial class IntroductionSecondPage : ContentPage
	{
		public IntroductionSecondPage()
		{
			InitializeComponent();

			labelProposedSaveData.Text = Resx.AppResources.ResourceManager.GetString("ProposedSaveData", App.CultureInfo);
			buttonNext.Text = Resx.AppResources.ResourceManager.GetString("Launch", App.CultureInfo).ToUpper();
			buttonNext.Clicked += async (sender, e) =>
			{
				var masterDetailPage = new MainMasterDetailPage();
				NavigationPage.SetHasNavigationBar(masterDetailPage, false);
				await Navigation.PushAsync(masterDetailPage);
			};

			var saveDataList = new[]
			{
				new { Description = Resx.AppResources.ResourceManager.GetString("Never", App.CultureInfo), SaveData = false },
				new { Description = Resx.AppResources.ResourceManager.GetString("Always", App.CultureInfo), SaveData = true },
			};

			foreach (var item in saveDataList)
			{
				pickerSaveData.Items.Add(item.Description);
			}

			pickerSaveData.SelectedIndexChanged += (sender, e) =>
			{
				var selectedSaveData = saveDataList[pickerSaveData.SelectedIndex].SaveData;
				Settings.SaveDataApplication = selectedSaveData;
			};

			pickerSaveData.SelectedIndex = (!Settings.SaveDataApplication) ? 0 : 1;

		}
	}
}
