class StatsStreetCredReward extends inkLogicController
{
	private editable var m_prevRewardsList : inkCompoundRef;
	private editable var m_currentRewardsList : inkCompoundRef;
	private editable var m_nextRewardsList : inkCompoundRef;
	private editable var m_scrollSlider : inkCompoundRef;
	private editable var m_scrollButtonHint : inkCompoundRef;
	private var m_rewardSize : Int32;
	private var m_tooltipIndex : Int32;
	private var m_tooltipsManager : weak< gameuiTooltipsManager >;

	public function SetData( proficiencyData : ProficiencyDisplayData, tooltipsManager : weak< gameuiTooltipsManager >, tooltipIndex : Int32 )
	{
		SetData( proficiencyData.m_passiveBonusesData, tooltipsManager, proficiencyData.m_level, tooltipIndex, proficiencyData.m_localizedName );
	}

	public function SetData( rewardData : array< LevelRewardDisplayData >, tooltipsManager : weak< gameuiTooltipsManager >, currentLevel : Int32, tooltipIndex : Int32, const attributeName : ref< String > )
	{
		var i, lastUnlocked, lastUnlockedIndex, totalCount, prevTerm : Int32;
		var positiveIndex : Bool;
		var rewardItem : StatsStreetCredRewardItem;
		var parentWidget : weak< inkWidget >;
		var state : CName;
		var descPackage : UILocalizationDataPackage;
		this.RegisterToCallback( 'OnHoverOver', this, 'OnRewardsHoverOver' );
		this.RegisterToCallback( 'OnHoverOut', this, 'OnRewardsHoverOut' );
		inkCompoundRef.SetVisible( m_scrollSlider, false );
		inkCompoundRef.SetVisible( m_scrollButtonHint, false );
		m_tooltipIndex = tooltipIndex;
		inkCompoundRef.RemoveAllChildren( m_prevRewardsList );
		inkCompoundRef.RemoveAllChildren( m_currentRewardsList );
		inkCompoundRef.RemoveAllChildren( m_nextRewardsList );
		m_tooltipsManager = tooltipsManager;
		for( i = 0; i < rewardData.Size(); i += 1 )
		{
			if( ( rewardData[ i ].level < currentLevel ) || ( rewardData[ i ].level == currentLevel ) )
			{
				lastUnlocked = rewardData[ i ].level;
				lastUnlockedIndex = i;
			}
		}
		m_rewardSize = rewardData.Size();
		totalCount = 0;
		prevTerm = 0;
		i = lastUnlockedIndex;
		positiveIndex = true;
		while( totalCount < m_rewardSize )
		{
			i = ( ( positiveIndex ) ? ( i + prevTerm ) : ( i - prevTerm ) );
			if( ( i < m_rewardSize ) && ( i >= 0 ) )
			{
				descPackage = new UILocalizationDataPackage;
				descPackage.intValues.PushBack( rewardData[ i ].level );
				descPackage.nameValues.PushBack( StringToName( attributeName ) );
				rewardData[ i ].descPackage = descPackage;
				if( ( rewardData[ i ].level < currentLevel ) && ( rewardData[ i ].level != lastUnlocked ) )
				{
					parentWidget = inkCompoundRef.Get( m_prevRewardsList );
					rewardData[ i ].isLock = false;
					state = 'Default';
				}
				else if( ( rewardData[ i ].level == currentLevel ) || ( rewardData[ i ].level == lastUnlocked ) )
				{
					parentWidget = inkCompoundRef.Get( m_currentRewardsList );
					rewardData[ i ].isLock = false;
					state = 'Default';
				}
				else
				{
					parentWidget = inkCompoundRef.Get( m_nextRewardsList );
					rewardData[ i ].isLock = true;
					state = 'Unavailable';
				}
				rewardItem = ( ( StatsStreetCredRewardItem )( SpawnFromLocal( parentWidget, 'rewardItem' ).GetControllerByType( 'StatsStreetCredRewardItem' ) ) );
				rewardItem.RegisterToCallback( 'OnHoverOver', this, 'OnHoverOver' );
				rewardItem.RegisterToCallback( 'OnHoverOut', this, 'OnHoverOut' );
				rewardItem.SetData( rewardData[ i ], state );
				totalCount += 1;
			}
			positiveIndex = !( positiveIndex );
			prevTerm += 1;
		}
	}

	protected event OnHoverOver( evt : inkPointerEvent )
	{
		var widget : inkWidget;
		var tooltipData : MessageTooltipData;
		var data : LevelRewardDisplayData;
		widget = evt.GetCurrentTarget();
		data = ( ( StatsStreetCredRewardItem )( widget.GetController() ) ).GetRewardData();
		tooltipData = new MessageTooltipData;
		tooltipData.Title = GetLocalizedText( data.description );
		tooltipData.TitleLocalizationPackage = data.locPackage;
		if( data.isLock )
		{
			tooltipData.Description = GetLocalizedText( "LocKey#78909" );
			tooltipData.DescriptionLocalizationPackage = data.descPackage;
		}
		m_tooltipsManager.ShowTooltipAtWidget( m_tooltipIndex, widget, tooltipData, gameuiETooltipPlacement.RightCenter, , inkMargin( 40.0, 0.0, 0.0, 0.0 ) );
	}

	protected event OnHoverOut( evt : inkPointerEvent )
	{
		m_tooltipsManager.HideTooltips();
	}

	protected event OnRewardsHoverOver( evt : inkPointerEvent )
	{
		if( m_rewardSize > 8 )
		{
			inkCompoundRef.SetVisible( m_scrollSlider, true );
			inkCompoundRef.SetVisible( m_scrollButtonHint, true );
		}
		else
		{
			inkCompoundRef.SetVisible( m_scrollSlider, false );
			inkCompoundRef.SetVisible( m_scrollButtonHint, false );
		}
	}

	protected event OnRewardsHoverOut( evt : inkPointerEvent )
	{
		inkCompoundRef.SetVisible( m_scrollSlider, false );
		inkCompoundRef.SetVisible( m_scrollButtonHint, false );
	}

}

class StatsStreetCredRewardItem extends inkButtonController
{
	private editable var m_levelRef : inkTextRef;
	private editable var m_iconRef : inkImageRef;
	private editable var m_data : LevelRewardDisplayData;

	public function SetData( data : LevelRewardDisplayData, optional state : CName )
	{
		if( state != '' )
		{
			GetRootWidget().SetState( state );
		}
		m_data = data;
		inkTextRef.SetText( m_levelRef, IntToString( m_data.level ) );
	}

	public function GetRewardData() : LevelRewardDisplayData
	{
		return m_data;
	}

}

