class PhotoModeTopBarController extends inkRadioGroupController
{
	private const editable var m_photoModeTogglesArray : array< inkWidgetRef >;

	protected event OnInitialize()
	{
		var i : Int32;
		var toggle : PhotoModeToggle;
		for( i = 0; i < m_photoModeTogglesArray.Size(); i += 1 )
		{
			toggle = ( ( PhotoModeToggle )( inkWidgetRef.GetController( m_photoModeTogglesArray[ i ] ) ) );
			if( toggle )
			{
				toggle.m_photoModeGroupController = this;
				AddToggle( toggle );
			}
		}
		Toggle( 0 );
	}

	public function SetInteractive( interactive : Bool )
	{
		var i : Int32;
		for( i = 0; i < m_photoModeTogglesArray.Size(); i += 1 )
		{
			inkWidgetRef.SetInteractive( m_photoModeTogglesArray[ i ], interactive );
		}
	}

	public function SelectToggle( toggleToSelect : PhotoModeToggle )
	{
		var i : Int32;
		var toggle : PhotoModeToggle;
		for( i = 0; i < m_photoModeTogglesArray.Size(); i += 1 )
		{
			toggle = ( ( PhotoModeToggle )( inkWidgetRef.GetController( m_photoModeTogglesArray[ i ] ) ) );
			if( toggle == toggleToSelect )
			{
				if( i != GetCurrentIndex() )
				{
					Toggle( i );
				}
				return;
			}
		}
	}

	public function SetToggleEnabled( index : Int32, enabled : Bool )
	{
		var photoModeToggle : weak< PhotoModeToggle >;
		photoModeToggle = ( ( weak< weak< PhotoModeToggle > > )( GetController( index ) ) );
		if( photoModeToggle )
		{
			photoModeToggle.SetEnabledOnTopBar( enabled );
		}
		if( !( enabled ) && ( index == GetCurrentIndex() ) )
		{
			if( !( SelectNextToggle( index ) ) )
			{
				SelectPreviousToggle( index );
			}
		}
	}

	protected function SelectNextToggle( currentIndex : Int32 ) : Bool
	{
		var indexToSet : Int32;
		var photoModeToggle : weak< PhotoModeToggle >;
		indexToSet = currentIndex + 1;
		if( indexToSet < m_photoModeTogglesArray.Size() )
		{
			photoModeToggle = ( ( weak< weak< PhotoModeToggle > > )( GetController( indexToSet ) ) );
			if( !( photoModeToggle.GetEnabledOnTopBar() ) )
			{
				return SelectNextToggle( indexToSet );
			}
			else
			{
				Toggle( indexToSet );
				return true;
			}
		}
		return false;
	}

	protected function SelectPreviousToggle( currentIndex : Int32 ) : Bool
	{
		var indexToSet : Int32;
		var photoModeToggle : weak< PhotoModeToggle >;
		indexToSet = currentIndex - 1;
		if( indexToSet >= 0 )
		{
			photoModeToggle = ( ( weak< weak< PhotoModeToggle > > )( GetController( indexToSet ) ) );
			if( !( photoModeToggle.GetEnabledOnTopBar() ) )
			{
				return SelectPreviousToggle( indexToSet );
			}
			else
			{
				Toggle( indexToSet );
				return true;
			}
		}
		return false;
	}

	public function HandleInput( e : inkPointerEvent, optional gameCtrl : weak< inkGameController > )
	{
		if( e.IsAction( 'PhotoMode_Next_Menu' ) )
		{
			SelectNextToggle( GetCurrentIndex() );
		}
		else if( e.IsAction( 'PhotoMode_Prior_Menu' ) )
		{
			SelectPreviousToggle( GetCurrentIndex() );
		}
	}

}

