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

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

namespace CommunityServer.Controls
{
	/// <summary>
	/// Summary description for FormLabel.
	/// </summary>
	public class FormLabel : Control
	{
		public FormLabel()
		{
		}

		private string _controlToLabel = null;
		private string _cssClass = null;
		private string _text = null;
		private string _resourceName = null;
		private string _resourceFile = null;
        
		public string ControlToLabel
		{
			get { return _controlToLabel;}
			set { _controlToLabel = value;}
		}

		
		public string CssClass
		{
			get { return _cssClass;}
			set { _cssClass = value;}
		}

		public string Text
		{
			get{return _text;}
			set { _text = value;}
		}

		public string ResourceName
		{
			get { return _resourceName;}
			set { _resourceName = value;}
		}

		public virtual string ResourceFile
		{
			get { return _resourceFile;}
			set { _resourceFile = value;}
		}

		protected override void Render(HtmlTextWriter writer)
		{
			writer.Write("<label");

			if(!Globals.IsNullorEmpty(this.ControlToLabel))
			{
				Control cntrl = this.FindControl(this.ControlToLabel);
				if(cntrl != null)
					writer.Write(" for=\"{0}\"",cntrl.ClientID);
			}

			if(!Globals.IsNullorEmpty(this.CssClass))
			{
				writer.Write(" class=\"{0}\"", this.CssClass);
			}

			writer.Write(" id=\"{0}\"", this.ClientID);
			
			string text = Globals.IsNullorEmpty(this.Text) ? GetResourceString() : this.Text;
			if(text != null)
				writer.Write(">{0}</label>", text);
		}

		protected string GetResourceString()
		{
			if (Globals.IsNullorEmpty(_resourceFile))
                return ResourceManager.GetString(_resourceName);
			else
				return ResourceManager.GetString(_resourceName, _resourceFile);
		}

	}
}
