//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Web.UI;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for WeblogThemedControl.
	/// </summary>
	public abstract class GalleryThemedControl : GalleryTemplatedWebControl
	{
		public GalleryThemedControl()
		{
			GalleryConfig = GalleryConfiguration.Instance();
		}

        protected GalleryConfiguration GalleryConfig = null;


        protected override string ThemeName
        {
            get { return CurrentGallery.Theme; }
        }

		private ThemeConfig themeConfig = null;
		protected ThemeConfig ThemeConfig
		{
			get
			{
				if(themeConfig == null)
					themeConfig = ThemeManager.Instance().GetTheme(ThemeName);

				return themeConfig;
			}
		}

		/// <summary>
		/// All skins should be found in the skin directory and named after the control.
		/// </summary>
		protected override string ExternalSkinFileName
		{
			get { return (SkinFile == null) ? string.Format("Skins/Skin-{0}.ascx", this.GetType().Name) : string.Concat("Skins/", SkinFile); }
		}

		/// <summary>
		/// A property which allows skin designers to specify the skin file to use for the control.
		/// eg. This can allow for the same control to appear differently in a sidebar or main content area.
		/// It must be the full filename of a file in the current themes Skins/ folder.
		/// </summary>
		private string _skinfilename = null;
		public virtual string SkinFile
		{
			get {return _skinfilename;}
			set {_skinfilename = value;}
		}

        protected override bool LoadThemedControl()
        {
            if(this.Page != null)
            {
                string path = ThemeManager.Instance().SkinPath(this.ThemeName,ExternalSkinFileName);
                Control skin = this.Page.LoadControl( path );
                skin.ID="_";
                this.Controls.Add( skin );
                return true;
            }

            return false;
        }

        protected override bool LoadDefaultThemedControl()
        {
            return false;
        }



		protected void SetPageTitle(string title)
		{
			SetPageTitle(null, title);
		}
		protected void SetPageTitle(string categoryName, string imageName)
        {
            string title = null;
			if(Globals.IsNullorEmpty(imageName) && Globals.IsNullorEmpty(categoryName))
				title = string.Format("{0} : {1}",ResourceManager.GetString("Gallery_PageTitlePrefix"), CurrentGallery.Name);
			else if (!Globals.IsNullorEmpty(imageName) && !Globals.IsNullorEmpty(categoryName))
				title = string.Format("{0} : {1} : {2} : {3}",ResourceManager.GetString("Gallery_PageTitlePrefix"), CurrentGallery.Name, categoryName,imageName);
			else if (!Globals.IsNullorEmpty(imageName))
				title = string.Format("{0} : {1} : {2}",ResourceManager.GetString("Gallery_PageTitlePrefix"), CurrentGallery.Name, imageName);
			else if (!Globals.IsNullorEmpty(categoryName))
				title = string.Format("{0} : {1} : {2}",ResourceManager.GetString("Gallery_PageTitlePrefix"), CurrentGallery.Name, categoryName);
            else
                title = CurrentGallery.Name;

            Head.AddTitle(title,Context);

            if(this.IsPublicGallery)
            {
                UsersOnline.SetLocation(title);
            }
            else
            {
                UsersOnline.PrivateLocation();
            }


		}

	}
}
