import class MenuAccountLogicController extends inkLogicController
{
	private editable var m_playerId : inkTextRef;
	private editable var m_changeAccountLabelTextRef : inkTextRef;
	private editable var m_inputDisplayControllerRef : inkWidgetRef;
	private var m_changeAccountEnabled : Bool;

	protected event OnInitialize()
	{
		inkWidgetRef.RegisterToCallback( m_inputDisplayControllerRef, 'OnRelease', this, 'OnButtonClick' );
		RegisterToGlobalInputCallback( 'OnPostOnRelease', this, 'OnButtonRelease' );
	}

	protected event OnUninitialize()
	{
		UnregisterFromGlobalInputCallback( 'OnPostOnRelease', this, 'OnButtonRelease' );
	}

	protected event OnButtonClick( e : inkPointerEvent )
	{
		if( e.IsHandled() )
		{
			return false;
		}
		if( m_changeAccountEnabled && e.IsAction( 'click' ) )
		{
			ChangeAccountRequest();
		}
	}

	protected event OnButtonRelease( evt : inkPointerEvent )
	{
		if( m_changeAccountEnabled )
		{
			if( evt.IsAction( 'change_account' ) )
			{
				ChangeAccountRequest();
			}
		}
	}

	private export function SetChangeAccountEnabled( enabled : Bool )
	{
		m_changeAccountEnabled = enabled;
		inkWidgetRef.SetVisible( m_inputDisplayControllerRef, enabled );
		inkTextRef.SetVisible( m_changeAccountLabelTextRef, enabled );
		inkTextRef.SetVisible( m_playerId, enabled );
	}

	private export function SetPlayerName( playerName : String )
	{
		inkTextRef.SetText( m_playerId, playerName );
	}

	private import function ChangeAccountRequest();

	public function IsEnabled() : Bool
	{
		return m_changeAccountEnabled;
	}

	public function ShowAccountButton()
	{
		if( !( m_changeAccountEnabled ) )
		{
			SetChangeAccountEnabled( true );
			SetPlayerName( "XboxDebugAccountName#2077" );
		}
		else
		{
			SetChangeAccountEnabled( false );
		}
	}

}

