class InventorySlotTooltip extends AGenericTooltipController
{
	private editable var m_itemName : inkTextRef;
	private editable var m_itemCategory : inkTextRef;
	private editable var m_itemPrice : inkTextRef;
	private editable var m_descriptionText : inkTextRef;
	private editable var m_lockedText : inkTextRef;
	private editable var m_requiredLevelText : inkTextRef;
	private editable var m_additionalStatsTextRef : inkTextRef;
	private editable var m_equippedHeader : inkWidgetRef;
	private editable var m_primaryStatsList : inkWidgetRef;
	private editable var m_comparedStatsList : inkWidgetRef;
	private editable var m_additionalStatsList : inkWidgetRef;
	private editable var m_itemPriceGroup : inkWidgetRef;
	private editable var m_damageIndicator : inkWidgetRef;
	private editable var m_requiredLevelGroup : inkWidgetRef;
	private editable var m_damageIndicatorRef : inkWidgetRef;
	private editable var m_attachmentsListVertRef : inkWidgetRef;
	private editable var m_attachmentsCtrlHorRef : inkWidgetRef;
	private editable var m_specialAbilitiesListRef : inkWidgetRef;
	private editable var m_rarityBarRef : inkWidgetRef;
	private const editable var m_elementsToSetRarityState : array< inkWidgetRef >;
	private const editable var m_rarityElementsRefs : array< inkImageRef >;
	private editable var m_tooltipCycleIndicatorsContainer : inkCompoundRef;
	private editable var m_tooltipCycleHintContainer : inkCompoundRef;
	private var m_primaryStatsCtrl : weak< InventoryItemStatList >;
	private var m_comparedStatsCtrl : weak< InventoryItemStatList >;
	private var m_additionalStatsCtrl : weak< InventoryItemStatList >;
	private var m_attachmentsCtrlVert : weak< InventoryItemAttachmentsList >;
	private var m_attachmentsCtrlHor : weak< InventoryItemAttachmentsList >;
	private var m_damageTypeIndicator : weak< DamageTypeIndicator >;
	private var m_specialAbilitiesList : weak< TooltipSpecialAbilityList >;
	private var m_data : InventoryTooltipData;
	private var m_tooltipCycleHint : weak< ButtonHintListItem >;
	private var anim : inkAnimProxy;

	protected event OnInitialize()
	{
		super.OnInitialize();
		m_primaryStatsCtrl = ( ( InventoryItemStatList )( inkWidgetRef.GetController( m_primaryStatsList ) ) );
		if( inkWidgetRef.IsValid( m_comparedStatsList ) )
		{
			m_comparedStatsCtrl = ( ( InventoryItemStatList )( inkWidgetRef.GetController( m_comparedStatsList ) ) );
		}
		if( inkWidgetRef.IsValid( m_additionalStatsList ) )
		{
			m_additionalStatsCtrl = ( ( InventoryItemStatList )( inkWidgetRef.GetController( m_additionalStatsList ) ) );
		}
		if( inkWidgetRef.IsValid( m_attachmentsListVertRef ) )
		{
			m_attachmentsCtrlVert = ( ( InventoryItemAttachmentsList )( inkWidgetRef.GetController( m_attachmentsListVertRef ) ) );
		}
		if( inkWidgetRef.IsValid( m_attachmentsCtrlHorRef ) )
		{
			m_attachmentsCtrlHor = ( ( InventoryItemAttachmentsList )( inkWidgetRef.GetController( m_attachmentsCtrlHorRef ) ) );
		}
		m_damageTypeIndicator = ( ( DamageTypeIndicator )( inkWidgetRef.GetController( m_damageIndicatorRef ) ) );
		m_specialAbilitiesList = ( ( TooltipSpecialAbilityList )( inkWidgetRef.GetController( m_specialAbilitiesListRef ) ) );
	}

	public override function SetStyle( styleResPath : ResRef )
	{
		m_Root.SetStyle( styleResPath );
		inkWidgetRef.SetStyle( m_primaryStatsList, styleResPath );
		if( inkWidgetRef.IsValid( m_comparedStatsList ) )
		{
			inkWidgetRef.SetStyle( m_comparedStatsList, styleResPath );
		}
		if( inkWidgetRef.IsValid( m_additionalStatsList ) )
		{
			inkWidgetRef.SetStyle( m_additionalStatsList, styleResPath );
		}
		if( inkWidgetRef.IsValid( m_attachmentsListVertRef ) )
		{
			inkWidgetRef.SetStyle( m_attachmentsListVertRef, styleResPath );
		}
		if( inkWidgetRef.IsValid( m_attachmentsCtrlHorRef ) )
		{
			inkWidgetRef.SetStyle( m_attachmentsCtrlHorRef, styleResPath );
		}
		inkWidgetRef.SetStyle( m_specialAbilitiesListRef, styleResPath );
	}

	public function Show( const data : ref< ItemViewData > )
	{
		Show( InventoryTooltipData.FromItemViewData( data ) );
	}

	public function Show( data : InventoryTooltipData )
	{
		SetData( data );
		Show();
	}

	public function SetData( const data : ref< ItemViewData > )
	{
		SetData( InventoryTooltipData.FromItemViewData( data ) );
		UpdateLayout();
	}

	public override function SetData( tooltipData : ATooltipData )
	{
		SetData( ( ( InventoryTooltipData )( tooltipData ) ) );
	}

	public function SetData( data : InventoryTooltipData )
	{
		if( data )
		{
			m_data = data;
			UpdateLayout();
		}
	}

	private function UpdateLayout()
	{
		var i, limit : Int32;
		inkTextRef.SetLetterCase( m_itemName, textLetterCase.UpperCase );
		inkTextRef.SetText( m_itemName, GetLocalizedItemNameByString( StringToName( m_data.itemName ) ) );
		anim.Stop();
		if( inkTextRef.IsValid( m_itemCategory ) )
		{
			inkTextRef.SetLetterCase( m_itemCategory, textLetterCase.UpperCase );
			inkTextRef.SetText( m_itemCategory, m_data.category );
			if( IsNameValid( m_data.qualityStateName ) )
			{
				inkTextRef.SetText( m_itemCategory, ( GetLocalizedText( m_data.quality ) + " " ) + GetLocalizedText( m_data.category ) );
			}
		}
		if( inkWidgetRef.IsValid( m_itemPriceGroup ) )
		{
			if( m_data.price > 0.0 )
			{
				if( m_data.isVendorItem )
				{
					inkTextRef.SetTextFromParts( m_itemPrice, FloatToStringPrec( m_data.buyPrice, 0 ), " ", "Common-Characters-EuroDollar" );
				}
				else
				{
					inkTextRef.SetTextFromParts( m_itemPrice, FloatToStringPrec( m_data.price, 0 ), " ", "Common-Characters-EuroDollar" );
				}
				inkWidgetRef.SetVisible( m_itemPriceGroup, true );
			}
			else
			{
				inkWidgetRef.SetVisible( m_itemPriceGroup, false );
			}
		}
		UpdateDescription();
		UpdateRarityBar();
		if( m_data.isBroken )
		{
			m_data.qualityStateName = 'Common';
		}
		for( i = 0, limit = m_elementsToSetRarityState.Size(); i < limit; i += 1 )
		{
			inkWidgetRef.SetState( m_elementsToSetRarityState[ i ], m_data.qualityStateName );
		}
		if( inkWidgetRef.IsValid( m_equippedHeader ) )
		{
			inkWidgetRef.SetVisible( m_equippedHeader, m_data.isEquipped );
		}
		if( inkWidgetRef.IsValid( m_requiredLevelGroup ) )
		{
			inkTextRef.SetText( m_requiredLevelText, IntToString( m_data.levelRequired ) );
			inkWidgetRef.SetVisible( m_requiredLevelGroup, m_data.levelRequired > 0 );
		}
		SetStats( m_primaryStatsCtrl, m_data.primaryStats );
		SetStats( m_comparedStatsCtrl, m_data.comparedStats );
		SetStats( m_additionalStatsCtrl, m_data.additionalStats );
		SetAdditionalStatsText();
		if( !( m_data.isBroken ) )
		{
			if( m_attachmentsCtrlVert )
			{
				m_attachmentsCtrlVert.SetData( m_data.attachments );
			}
			if( m_attachmentsCtrlHor )
			{
				m_attachmentsCtrlHor.SetData( m_data.attachments );
			}
			m_damageTypeIndicator.Setup( m_data.damageType );
			m_specialAbilitiesList.SetData( m_data.qualityStateName, m_data.specialAbilities );
		}
		else
		{
			if( m_attachmentsCtrlVert )
			{
				m_attachmentsCtrlVert.ClearData( 0 );
			}
			if( m_attachmentsCtrlHor )
			{
				m_attachmentsCtrlHor.ClearData( 0 );
			}
			m_specialAbilitiesList.ClearData( 0 );
			m_damageTypeIndicator.Setup( gamedataDamageType.Invalid );
		}
		m_primaryStatsCtrl.UpdateVisibility( true );
		if( m_attachmentsCtrlVert )
		{
			m_attachmentsCtrlVert.UpdateVisibility();
			m_attachmentsCtrlVert.UpdateVisibility( m_data.additionalStats.Size() > 0 );
		}
		if( m_attachmentsCtrlHor )
		{
			m_attachmentsCtrlHor.UpdateVisibility();
			m_attachmentsCtrlHor.UpdateVisibility( m_data.additionalStats.Size() == 0 );
		}
		m_specialAbilitiesList.UpdateVisibility();
		UpdateCyclingDots();
		anim = PlayLibraryAnimation( 'intro' );
	}

	private function UpdateCyclingDots()
	{
		var i : Int32;
		var dotController : TooltipCycleDotController;
		inkCompoundRef.SetVisible( m_tooltipCycleIndicatorsContainer, m_data.showCyclingDots );
		inkCompoundRef.SetVisible( m_tooltipCycleHintContainer, m_data.showCyclingDots );
		if( m_data.showCyclingDots )
		{
			inkCompoundRef.RemoveAllChildren( m_tooltipCycleIndicatorsContainer );
			for( i = 0; i < m_data.numberOfCyclingDots; i += 1 )
			{
				dotController = ( ( TooltipCycleDotController )( SpawnFromLocal( inkCompoundRef.Get( m_tooltipCycleIndicatorsContainer ), 'tooltipCycleDot' ).GetController() ) );
				dotController.Toggle( i == m_data.selectedCyclingDot );
			}
		}
	}

	private function UpdateRarityBar()
	{
		var numBars, i, limit : Int32;
		if( !( inkWidgetRef.IsValid( m_rarityBarRef ) ) )
		{
			return;
		}
		if( IsNameValid( m_data.qualityStateName ) && !( m_data.isBroken ) )
		{
			switch( m_data.qualityStateName )
			{
				case 'Legendary':
					numBars = 5;
				break;
				case 'Epic':
					numBars = 4;
				break;
				case 'Rare':
					numBars = 3;
				break;
				case 'Uncommon':
					numBars = 2;
				break;
				default:
					numBars = 1;
				break;
			}
			for( i = 0, limit = m_rarityElementsRefs.Size(); i < limit; i += 1 )
			{
				if( i < numBars )
				{
					inkImageRef.SetOpacity( m_rarityElementsRefs[ i ], 1.0 );
					inkImageRef.SetState( m_rarityElementsRefs[ i ], m_data.qualityStateName );
				}
				else
				{
					inkImageRef.SetOpacity( m_rarityElementsRefs[ i ], 0.30000001 );
					inkImageRef.SetState( m_rarityElementsRefs[ i ], 'Common' );
				}
			}
			inkWidgetRef.SetVisible( m_rarityBarRef, true );
		}
		else
		{
			inkWidgetRef.SetVisible( m_rarityBarRef, false );
		}
	}

	private function SetStats( statList : weak< InventoryItemStatList >, data : ref< array< InventoryTooltipData_StatData > > )
	{
		if( statList )
		{
			if( !( m_data.isBroken ) )
			{
				statList.SetData( data );
			}
			else
			{
				statList.ClearData( 0 );
			}
			statList.UpdateVisibility();
		}
	}

	private function SetAdditionalStatsText()
	{
		var i, limit : Int32;
		var outText : String;
		outText = "";
		if( inkTextRef.IsValid( m_additionalStatsTextRef ) )
		{
			for( i = 0, limit = m_data.additionalStats.Size(); i < limit; i += 1 )
			{
				if( i > 0 )
				{
					outText += ", ";
				}
				outText += m_data.additionalStats[ i ].statName;
			}
			inkTextRef.SetText( m_additionalStatsTextRef, outText );
		}
	}

	private function UpdateDescription()
	{
		var description : String;
		if( m_data.isBroken )
		{
			inkTextRef.SetText( m_descriptionText, GetLocalizedText( "Gameplay-Scanning-Devices-Broken" ) );
			inkTextRef.SetVisible( m_descriptionText, true );
			return;
		}
		else if( inkTextRef.IsValid( m_descriptionText ) )
		{
			description = GetLocalizedText( m_data.description );
			if( m_data && IsStringValid( m_data.additionalDescription ) )
			{
				if( IsStringValid( description ) )
				{
					description += "\n\n";
				}
				description += GetLocalizedText( m_data.additionalDescription );
			}
			inkTextRef.SetText( m_descriptionText, description );
			inkTextRef.SetVisible( m_descriptionText, IsStringValid( description ) );
		}
	}

}

