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

using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Discussions.Components;

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

		protected override void Render(HtmlTextWriter writer)
		{
			Forum f = null;
			BaseForumPage ForumPage = this.Page as BaseForumPage;

			if (ForumPage != null)
				f = ForumPage.CurrentForum;
			else
			{
				CSContext csContext = CSContext.Current;
				if (csContext.SectionID > 0)
					f = CommunityServer.Discussions.Components.Forums.GetForum(csContext.SectionID);
			}

			if(f != null)
			{
				HyperLink link = new HyperLink();
				link.Text = f.Name;
				link.NavigateUrl = ForumUrls.Instance().Forum(f.SectionID);
				link.RenderControl(writer);
			}
			else
			{

				writer.Write("Unknown");
			}
		}

	}
}
