class NewPerkTabsController extends inkLogicController
{
	private editable var m_tabText : inkTextRef;
	private editable var m_currentAttributePoints : inkTextRef;
	private editable var m_currentAttributeIcon : inkImageRef;
	private editable var m_leftArrow : inkWidgetRef;
	private editable var m_rightArrow : inkWidgetRef;
	private editable var m_attributePointsWrapper : inkWidgetRef;
	private editable var m_attributePointsText : inkTextRef;
	private editable var m_perkPointsWrapper : inkWidgetRef;
	private editable var m_perkPointsText : inkTextRef;
	private editable var m_espionagePointsWrapper : inkWidgetRef;
	private editable var m_espionagePointsText : inkTextRef;
	private const editable var m_bars : array< inkWidgetRef >;
	private var m_dataManager : weak< PlayerDevelopmentDataManager >;
	private var m_initData : NewPerksScreenInitData;
	private var m_isEspionageUnlocked : Bool;

	public function SetData( dataManager : weak< PlayerDevelopmentDataManager >, initData : weak< NewPerksScreenInitData >, optional isEspionageUnlocked : Bool )
	{
		var attributeData : AttributeData;
		m_dataManager = dataManager;
		m_initData = initData;
		m_isEspionageUnlocked = isEspionageUnlocked;
		attributeData = dataManager.GetAttribute( dataManager.GetAttributeRecordIDFromEnum( initData.perkMenuAttribute ) );
		inkTextRef.SetText( m_tabText, attributeData.label );
		inkTextRef.SetText( m_currentAttributePoints, IntToString( attributeData.value ) );
		inkTextRef.SetVisible( m_currentAttributePoints, initData.perkMenuAttribute != PerkMenuAttribute.Espionage );
		inkImageRef.SetTexturePart( m_currentAttributeIcon, PerkAttributeHelper.GetIconAtlasPart( initData.perkMenuAttribute ) );
		inkWidgetRef.SetVisible( m_attributePointsWrapper, initData.perkMenuAttribute != PerkMenuAttribute.Espionage );
		inkWidgetRef.SetVisible( m_perkPointsWrapper, initData.perkMenuAttribute != PerkMenuAttribute.Espionage );
		inkWidgetRef.SetVisible( m_espionagePointsWrapper, initData.perkMenuAttribute == PerkMenuAttribute.Espionage );
		inkTextRef.SetText( m_attributePointsText, IntToString( m_dataManager.GetAttributePoints() ) );
		inkTextRef.SetText( m_perkPointsText, IntToString( m_dataManager.GetPerkPoints() ) );
		inkTextRef.SetText( m_espionagePointsText, IntToString( m_dataManager.GetSpyPerkPoints() ) );
		UpdateBars();
	}

	public function SetValues( attributePointsVal : Int32, perkPointsVal : Int32, espionagePointsVal : Int32 )
	{
		var attributeData : AttributeData;
		attributeData = m_dataManager.GetAttribute( m_dataManager.GetAttributeRecordIDFromEnum( m_initData.perkMenuAttribute ) );
		inkTextRef.SetText( m_attributePointsText, IntToString( attributePointsVal ) );
		inkTextRef.SetText( m_perkPointsText, IntToString( perkPointsVal ) );
		inkTextRef.SetText( m_espionagePointsText, IntToString( espionagePointsVal ) );
		inkTextRef.SetText( m_currentAttributePoints, IntToString( attributeData.value ) );
	}

	private function UpdateBars()
	{
		var i, limit, attributeIndex : Int32;
		for( i = 0, limit = m_bars.Size(); i < limit; i += 1 )
		{
			attributeIndex = ( ( Int32 )( m_initData.perkMenuAttribute ) );
			inkWidgetRef.SetState( m_bars[ i ], ( ( i == attributeIndex ) ? ( 'Active' ) : ( 'Default' ) ) );
		}
		inkWidgetRef.SetVisible( m_bars[ limit - 1 ], m_isEspionageUnlocked );
	}

}

enum NewPerkTabsArrowDirection
{
	Left = 0,
	Right = 1,
	Invalid = 2,
}

class NewPerkTabsArrowController extends inkLogicController
{
	private editable var m_direction : NewPerkTabsArrowDirection;
	private var m_hovered : Bool;
	private var m_pressed : Bool;

	protected event OnInitialize()
	{
		RegisterToCallback( 'OnPress', this, 'OnPress' );
		RegisterToCallback( 'OnRelease', this, 'OnRelease' );
		RegisterToCallback( 'OnHoverOver', this, 'OnHoverOver' );
		RegisterToCallback( 'OnHoverOut', this, 'OnHoverOut' );
	}

	protected event OnPress( evt : inkPointerEvent )
	{
		if( evt.IsAction( 'click' ) )
		{
			m_pressed = true;
			UpdateState();
		}
	}

	protected event OnRelease( evt : inkPointerEvent )
	{
		var clickEvent : NewPerksTabArrowClickedEvent;
		if( evt.IsAction( 'click' ) )
		{
			clickEvent = new NewPerksTabArrowClickedEvent;
			clickEvent.direction = m_direction;
			QueueEvent( clickEvent );
			m_pressed = false;
			UpdateState();
		}
	}

	protected event OnHoverOver( evt : inkPointerEvent )
	{
		m_hovered = true;
		UpdateState();
	}

	protected event OnHoverOut( evt : inkPointerEvent )
	{
		m_hovered = false;
		m_pressed = false;
		UpdateState();
	}

	private function UpdateState()
	{
		var stateToSet : CName;
		if( m_pressed )
		{
			stateToSet = 'Press';
		}
		else
		{
			if( m_hovered )
			{
				stateToSet = 'Hover';
			}
			else
			{
				stateToSet = 'Default';
			}
		}
		GetRootWidget().SetState( stateToSet );
	}

}

class NewPerksTabArrowClickedEvent extends Event
{
	var direction : NewPerkTabsArrowDirection;
}

class NewPerksTabAttributeInvestHoldFinished extends Event
{
	var attribute : PerkMenuAttribute;
}

