using System;
using System.Collections.Generic;
using System.Web;

namespace B4Restore.Common.Control
{
	public class NavigationHistory
	{
		private const int maxLength = 5;

        public static string PathsString
        {
            get
            {
                string sResult = string.Empty;
                List<string> ls = Path;
                foreach (string sPath in ls)
                {
                    if (!string.IsNullOrEmpty(sResult))
                        sResult += ",";
                    sResult += @"javascript:tv_NodePassiveClick(""" + sPath+ @""");";
                }
                return sResult;
            }
        }

        public static string TitlesString
        {
            get
            {
                string sResult = string.Empty;
                List<string> ls = Title;
                foreach (string sTitle in ls)
                {
                    if (!string.IsNullOrEmpty(sResult))
                        sResult += ",";
                    sResult += sTitle;
                }
                return sResult;
            }
        }

		protected static List<string> Path
		{
			get
			{
				var result = (List<string>) HttpContext.Current.Session["NavigationHistory_Path"];
				
				if (result == null)
				{
					result = new List<string>();
					HttpContext.Current.Session["NavigationHistory_Path"] = result;
				}
				return result;
			}
		}

        protected static List<string> Title
        {
            get
            {
                List<string> result = (List<string>)HttpContext.Current.Session["NavigationHistory_Title"];

                if (result == null)
                {
                    result = new List<string>();
                    HttpContext.Current.Session["NavigationHistory_Title"] = result;
                }
                return result;
            }
        }

		public static string Current
		{
			get
			{
				var result = String.Empty;
				
				if (Path.Count > 0)
				{
					result = Path[Path.Count - 1];
				}

				return result;
			}
		}

		public static string Previous
		{
			get
			{
				var result = Current;

				if (Path.Count > 1)
				{
					result = Path[Path.Count - 2];
				}

				return result;
			}
		}
		
		public static void Add(string path)
		{
			if (Path.Count == maxLength)
			{
				Path.RemoveAt(0);
			}
			Path.Add(path);            
		}

        public static void Add(string path, string title)
        {
            if (Path.Count == maxLength)
            {
                Path.RemoveAt(0);
                Title.RemoveAt(0);
            }
            Path.Add(path);
            Title.Add(title);
        }

       
        // Title
        //System.Windows.Browser.HtmlPage.Document.


		/*public static string MoveBack()
		{
			var listItem = Current;
			
			if (Path.Count > 0)
			{
				Path.RemoveAt(Path.Count - 1);
				if (Path.Count > 0)
				{
					listItem = Path[Path.Count - 1];
				}
			}

			return listItem;
		}*/
	}
}