using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using FoxTube.Pages.SettingsPages;

namespace FoxTube
{
    /// <summary>
    /// Settings tabs placeholder
    /// </summary>
    public sealed partial class Settings : Page, INavigationPage
    {
        public object Parameter { get; set; } = null;

        bool inboxLoaded = false;
        string inboxId = null;
        public Settings()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Parameter = e.Parameter;

            if(!string.IsNullOrWhiteSpace((string)e.Parameter))
                switch((string)e.Parameter)
                {
                    case "about":
                        pivot.SelectedItem = aboutTab;
                        break;
                    case "translate":
                        pivot.SelectedItem = translateTab;
                        break;
                    default:
                        inboxId = (string)e.Parameter;
                        pivot.SelectedItem = inboxTab;
                        break;
                }

            Methods.MainPage.PageContent.LoadingPage.Close();
        }

        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (pivot.SelectedItem == inboxTab && !inboxLoaded)
            {
                inbox.LoadItems(inboxId);
                inboxLoaded = true;
                inboxId = null;
            }
        }
    }
}
