class ListItemStateMapper extends inkLogicController
{
	private var m_toggled : Bool;
	private var m_selected : Bool;
	private var m_new : Bool;
	private var m_widget : weak< inkWidget >;

	protected event OnInitialize()
	{
		var listController : weak< inkLogicController >;
		m_widget = GetRootWidget();
		listController = ( ( inkLogicController )( m_widget.GetControllerByBaseType( 'inkListItemController' ) ) );
		listController.RegisterToCallback( 'OnToggledOn', this, 'OnToggledOn' );
		listController.RegisterToCallback( 'OnToggledOff', this, 'OnToggledOff' );
		listController.RegisterToCallback( 'OnSelected', this, 'OnSelected' );
		listController.RegisterToCallback( 'OnDeselected', this, 'OnDeselected' );
	}

	protected event OnToggledOn( target : weak< ListItemController > )
	{
		m_toggled = true;
		UpdateState();
	}

	protected event OnToggledOff( target : weak< ListItemController > )
	{
		m_toggled = false;
		UpdateState();
	}

	protected event OnSelected( target : weak< ListItemController > )
	{
		m_selected = true;
		UpdateState();
	}

	protected event OnDeselected( target : weak< ListItemController > )
	{
		m_selected = false;
		UpdateState();
	}

	public function SetNew( isNew : Bool )
	{
		m_new = isNew;
		UpdateState();
	}

	private virtual function UpdateState()
	{
		var newState : String;
		newState = "";
		if( m_toggled )
		{
			newState = "Toggled";
		}
		if( m_selected )
		{
			newState += "Selected";
		}
		if( m_new )
		{
			newState += "New";
		}
		m_widget.SetState( StringToName( newState ) );
	}

}

