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
    {
        bool inboxLoaded = false;
        string inboxId = null;
        public Settings()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if(!string.IsNullOrWhiteSpace(e.Parameter as string))
            {
                inboxId = e.Parameter as string;
                pivot.SelectedIndex = 2;
            }
        }

        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (pivot.SelectedIndex == 2 && !inboxLoaded)
            {
                (((pivot.Items[2] as PivotItem).Content as ScrollViewer).Content as Inbox).LoadItems();
                inboxLoaded = true;
                if(inboxId != null)
                {
                    (((pivot.Items[2] as PivotItem).Content as ScrollViewer).Content as Inbox).Open(inboxId as string);
                    inboxId = null;
                }
            }
        }
    }
}
