import class SelectorController extends inkLogicController
{
	editable var m_labelPath : CName;
	default m_labelPath = 'Panel/Label';
	editable var m_valuePath : CName;
	default m_valuePath = 'Panel/Value';
	editable var m_leftArrowPath : CName;
	default m_leftArrowPath = 'Panel/LeftArrow';
	editable var m_rightArrowPath : CName;
	default m_rightArrowPath = 'Panel/RightArrow';
	protected var m_label : weak< inkText >;
	protected var m_value : weak< inkText >;
	protected var m_leftArrow : weak< inkWidget >;
	protected var m_rightArrow : weak< inkWidget >;
	protected var m_rightArrowButton : weak< inkButtonController >;
	protected var m_leftArrowButton : weak< inkButtonController >;

	public import function AddValues( values : array< String > );
	public import function AddValue( value : String );
	public import function Clear();
	public import function GetValues() : array< String >;
	public import function GetValuesCount() : Int32;
	public import function IsCyclical() : Bool;
	public import function GetCurrIndex() : Int32;
	public import function SetCurrIndex( index : Int32 );
	public import function SetCurrIndexWithDirection( index : Int32, changeDirection : inkSelectorChangeDirection );
	public import function Next() : Int32;
	public import function Prior();

	public function SetLabel( const label : ref< String > )
	{
		if( m_label )
		{
			m_label.SetText( label );
		}
	}

	protected event OnInitialize()
	{
		if( IsNameValid( m_labelPath ) )
		{
			m_label = ( ( inkText )( GetWidget( m_labelPath ) ) );
		}
		m_value = ( ( inkText )( GetWidget( m_valuePath ) ) );
		m_leftArrow = GetWidget( m_leftArrowPath );
		if( m_leftArrow )
		{
			m_leftArrow.RegisterToCallback( 'OnRelease', this, 'OnLeft' );
			m_leftArrowButton = ( ( inkButtonController )( m_leftArrow.GetControllerByType( 'inkButtonController' ) ) );
		}
		m_rightArrow = GetWidget( m_rightArrowPath );
		if( m_rightArrow )
		{
			m_rightArrow.RegisterToCallback( 'OnRelease', this, 'OnRight' );
			m_rightArrowButton = ( ( inkButtonController )( m_rightArrow.GetControllerByType( 'inkButtonController' ) ) );
		}
	}

	protected event OnUpdateValue( value : String, index : Int32, changeDirection : inkSelectorChangeDirection )
	{
		var isCyclical : Bool;
		var valuesCount : Int32;
		var hasMoreThanOneValue : Bool;
		valuesCount = GetValuesCount();
		hasMoreThanOneValue = valuesCount > 1;
		isCyclical = IsCyclical();
		if( m_value )
		{
			m_value.SetText( value );
		}
		if( hasMoreThanOneValue )
		{
			if( !( isCyclical ) && m_leftArrowButton )
			{
				m_leftArrowButton.SetEnabled( GetCurrIndex() != 0 );
			}
			if( !( isCyclical ) && m_rightArrowButton )
			{
				m_rightArrowButton.SetEnabled( GetCurrIndex() != ( valuesCount - 1 ) );
			}
		}
		else
		{
			m_leftArrowButton.SetEnabled( false );
			m_rightArrowButton.SetEnabled( false );
		}
	}

	protected event OnLeft( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			Prior();
		}
	}

	protected event OnRight( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			Next();
		}
	}

}

import enum inkSelectorChangeDirection
{
	None,
	Prior,
	Next,
}

