using System;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;

namespace AgApp
{
	public static class NavigationHelper
	{
		private static Panel root = null;

		public static bool EnsureRoot(Panel rootPanel)
		{
			if (NavigationHelper.root == null)
			{
				NavigationHelper.root = rootPanel ?? new Grid();
				Application.Current.RootVisual = NavigationHelper.root;
			}
			return NavigationHelper.root != null;
		}

		public static void Navigate(UserControl newPage)
		{
			if (EnsureRoot(null))
			{
				UserControl oldPage = null;
				if (NavigationHelper.root.Children.Count > 0)
				{
					oldPage = NavigationHelper.root.Children[0] as UserControl;
				}
				NavigationHelper.root.Children.Add(newPage);
				if (oldPage != null)
				{
					NavigationHelper.root.Children.Remove(oldPage);
				}
			}
		}

		public static void LoadDefaultAspx()
		{
			HtmlPage.Window.Navigate(new Uri("Default.aspx", UriKind.RelativeOrAbsolute));
		}

		public static void LoadPageIndex()
		{
			NavigationHelper.Navigate(new PageIndex());
		}

		public static void LoadPageTestCombo()
		{
			NavigationHelper.Navigate(new PageTestCombo());
		}
	}
}