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

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

namespace CommunityServer.Controls
{
	/// <summary>
	/// Summary description for AnonymousUserControl.
	/// </summary>
	public class RegisteredUserControl : TemplatedWebControl
	{
		public RegisteredUserControl()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		IText message = null;

		/// <summary>
		/// No Being Span
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderBeginTag(System.Web.UI.HtmlTextWriter writer)
		{
			//we don't need a span tag
		}

		/// <summary>
		/// No End Span
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderEndTag(System.Web.UI.HtmlTextWriter writer)
		{
			//we don't need a span tag
		}


		protected override void AttachChildControls()
		{
			CSContext cntx = CSContext.Current;
			message = FindText("Message");
			if(message != null)
				message.Text = String.Format( ResourceManager.GetString("DisplayUserWelcome_UserWelcome"), "<a href=\"" + Globals.GetSiteUrls().UserEditProfile + "\">" + cntx.User.DisplayName + "</a>");

			switch(cntx.AuthenticationType)
			{

				case "passport":

					PlaceHolder passport = FindControl("PassportPanel") as PlaceHolder;
					if(passport != null)
						passport.Visible = true;					

					Literal lit = FindControl("PassportButton") as Literal;
					if(lit != null)
						lit.Text = (new PassportIdentity()).LogoTag() ;

					HyperLink invitePassport = FindControl("InvitePassport") as HyperLink;
					if (invitePassport != null)
					{
						if (cntx.SiteSettings.AccountActivation == AccountActivation.InvitationOnly)
						{
							invitePassport.Text = ResourceManager.GetString("invite");
							invitePassport.NavigateUrl = Globals.GetSiteUrls().UserInvite;
						}
						else
						{
							invitePassport.Visible = false;

							Control inviteArea = FindControl("InviteAreaPassport");
							if (inviteArea != null)
								inviteArea.Visible = false;
						}
					}

					break;

				case "windows":

					PlaceHolder windows = FindControl("WindowsPanel") as PlaceHolder;
					if(windows != null)
						windows.Visible = true;					


					break;

				case "forms":
				default:

					PlaceHolder formspanel = FindControl("FormsPanel") as PlaceHolder;
					if(formspanel != null)
						formspanel.Visible = true;
					
					HyperLink logout = FindControl("logout") as HyperLink;
					if(logout != null)
					{
						logout.Text = ResourceManager.GetString("logout");
						logout.NavigateUrl = Globals.GetSiteUrls().Logout;
					}

					HyperLink invite = FindControl("invite") as HyperLink;
					if (invite != null)
					{
						if (cntx.SiteSettings.AccountActivation == AccountActivation.InvitationOnly)
						{
							invite.Text = ResourceManager.GetString("invite");
							invite.NavigateUrl = Globals.GetSiteUrls().UserInvite;
						}
						else
						{
							invite.Visible = false;

							Control inviteArea = FindControl("InviteArea");
							if (inviteArea != null)
								inviteArea.Visible = false;
						}
					}

					break;


			}

		}
	}
}
