class interactionItemLogicController extends inkLogicController
{
	private editable var m_inputButtonContainer : inkCompoundRef;
	private editable var m_inputDisplayControllerRef : inkWidgetRef;
	private editable var m_QuickHackCostHolder : inkWidgetRef;
	private editable var m_QuickHackCost : inkTextRef;
	private editable var m_QuickHackIcon : inkImageRef;
	private editable var m_QuickHackHolder : inkCompoundRef;
	private editable var m_label : inkTextRef;
	private editable var m_labelFail : inkTextRef;
	private editable var m_SkillCheckPassBG : inkWidgetRef;
	private editable var m_SkillCheckFailBG : inkWidgetRef;
	private editable var m_QHIllegalIndicator : inkWidgetRef;
	private editable var m_SCIllegalIndicator : inkWidgetRef;
	private editable var m_additionalReqsNeeded : inkWidgetRef;
	private editable var m_skillCheck : inkCompoundRef;
	private editable var m_skillCheckNormalReqs : inkCompoundRef;
	private editable var m_skillCheckIcon : inkImageRef;
	private editable var m_skillCheckText : inkTextRef;
	private var m_RootWidget : weak< inkCompoundWidget >;
	private var m_inActiveTransparency : Float;
	default m_inActiveTransparency = 0.0;
	private var m_inputDisplayController : weak< inkInputDisplayController >;
	private var m_animProxy : inkAnimProxy;
	private var m_isSelected : Bool;

	protected event OnInitialize()
	{
		m_RootWidget = GetRootCompoundWidget();
		m_inputDisplayController = ( ( inkInputDisplayController )( inkWidgetRef.GetControllerByType( m_inputDisplayControllerRef, 'inkInputDisplayController' ) ) );
		inkCompoundRef.SetVisible( m_QuickHackHolder, false );
		inkWidgetRef.SetVisible( m_SCIllegalIndicator, false );
		inkWidgetRef.SetVisible( m_QHIllegalIndicator, false );
		inkWidgetRef.SetVisible( m_QuickHackCostHolder, false );
		PlayLibraryAnimation( 'interaction_intro' );
	}

	public function SetData( data : ref< InteractionChoiceData >, optional skillCheck : UIInteractionSkillCheck, optional isItemBroken : Bool )
	{
		var keyData : inkInputKeyData;
		var iconID : TweakDBID;
		var skillReqParams : inkTextParams;
		keyData = inkInputKeyData();
		inkInputKeyData.SetInputKey( keyData, data.rawInputKey );
		m_inputDisplayController.SetInputAction( data.inputAction );
		inkCompoundRef.SetVisible( m_skillCheck, skillCheck.isValid );
		if( skillCheck.isValid )
		{
			skillReqParams = new inkTextParams;
			if( skillCheck.skillCheck == EDeviceChallengeSkill.Hacking )
			{
				iconID = T"ChoiceIcons.HackingIcon";
				skillReqParams.AddLocalizedString( "NAME", "LocKey#22278" );
			}
			else if( skillCheck.skillCheck == EDeviceChallengeSkill.Engineering )
			{
				iconID = T"ChoiceIcons.EngineeringIcon";
				skillReqParams.AddLocalizedString( "NAME", "LocKey#22276" );
			}
			else
			{
				iconID = T"ChoiceIcons.AthleticsIcon";
				skillReqParams.AddLocalizedString( "NAME", "LocKey#22271" );
			}
			if( skillCheck.isPassed )
			{
				skillReqParams.AddNumber( "REQUIRED_SKILL", skillCheck.requiredSkill );
				inkTextRef.SetLocalizedTextScript( m_skillCheckText, "LocKey#49423", skillReqParams );
			}
			else
			{
				skillReqParams.AddNumber( "PLAYER_SKILL", skillCheck.playerSkill );
				skillReqParams.AddNumber( "REQUIRED_SKILL", skillCheck.requiredSkill );
				inkTextRef.SetLocalizedTextScript( m_skillCheckText, "LocKey#49421", skillReqParams );
			}
			SetTexture( m_skillCheckIcon, iconID );
			inkTextRef.SetVisible( m_label, skillCheck.isPassed );
			inkTextRef.SetVisible( m_labelFail, !( skillCheck.isPassed ) );
			inkWidgetRef.SetVisible( m_SkillCheckPassBG, skillCheck.isPassed );
			inkWidgetRef.SetVisible( m_SkillCheckFailBG, !( skillCheck.isPassed ) );
			inkCompoundRef.SetVisible( m_skillCheckNormalReqs, skillCheck.isPassed || !( skillCheck.hasAdditionalRequirements ) );
			inkWidgetRef.SetVisible( m_additionalReqsNeeded, !( skillCheck.isPassed ) && skillCheck.hasAdditionalRequirements );
		}
		SetLabel( data, isItemBroken );
		if( data.captionParts.parts.Size() > 0 )
		{
			EmptyCaptionParts();
			SetCaptionParts( data.captionParts.parts );
		}
		else
		{
			EmptyCaptionParts();
		}
		if( ChoiceTypeWrapper.IsType( data.type, gameinteractionsChoiceType.Illegal ) )
		{
			inkWidgetRef.SetVisible( m_QHIllegalIndicator, true );
			if( data.captionParts.parts.Size() == 0 )
			{
				inkWidgetRef.SetVisible( m_SCIllegalIndicator, false );
			}
		}
		else
		{
			inkWidgetRef.SetVisible( m_QHIllegalIndicator, false );
			inkWidgetRef.SetVisible( m_SCIllegalIndicator, false );
		}
		if( ChoiceTypeWrapper.IsType( data.type, gameinteractionsChoiceType.Inactive ) || ChoiceTypeWrapper.IsType( data.type, gameinteractionsChoiceType.CheckFailed ) )
		{
			m_RootWidget.SetState( 'Inactive' );
			inkWidgetRef.SetVisible( m_SkillCheckPassBG, false );
			inkWidgetRef.SetVisible( m_SkillCheckFailBG, true );
			inkTextRef.SetVisible( m_label, false );
			inkTextRef.SetVisible( m_labelFail, true );
		}
		else
		{
			m_RootWidget.SetState( 'Active' );
			inkWidgetRef.SetVisible( m_SkillCheckPassBG, true );
			inkWidgetRef.SetVisible( m_SkillCheckFailBG, false );
			inkTextRef.SetVisible( m_label, true );
			inkTextRef.SetVisible( m_labelFail, false );
		}
		if( ChoiceTypeWrapper.IsType( data.type, gameinteractionsChoiceType.Selected ) && !( m_isSelected ) )
		{
			PlayAnim( 'Select' );
		}
	}

	public function SetButtonVisibility( argBool : Bool )
	{
		m_inputDisplayController.SetVisible( argBool );
		inkTextRef.SetOpacity( m_label, ( ( argBool ) ? ( 1.0 ) : ( m_inActiveTransparency ) ) );
	}

	public function SetZoneChange( value : Int32 )
	{
		var zone : gamePSMZones;
		zone = ( ( gamePSMZones )( value ) );
		switch( zone )
		{
			case gamePSMZones.Public:
			case gamePSMZones.Safe:
				SetIllegalActionOpacity( 0.0 );
			break;
			case gamePSMZones.Restricted:
			case gamePSMZones.Dangerous:
				SetIllegalActionOpacity( 1.0 );
			break;
		}
	}

	private function SetLabel( data : ref< InteractionChoiceData >, isItemBroken : Bool )
	{
		var locText, captionTags : String;
		var action : DeviceAction;
		var deviceAction : ScriptableDeviceAction;
		var textParams : inkTextParams;
		locText = GetLocalizedText( ( ( isItemBroken ) ? ( "LocKey#6887" ) : ( data.localizedName ) ) );
		captionTags = GetCaptionTagsFromArray( data.captionParts.parts );
		if( captionTags != "" )
		{
			locText = ( captionTags + " " ) + locText;
		}
		if( data.data.Size() > 0 )
		{
			action = ( ( DeviceAction )( data.data[ 0 ] ) );
			deviceAction = ( ( ScriptableDeviceAction )( action ) );
		}
		if( ( deviceAction && deviceAction.IsInactive() ) && deviceAction.GetInactiveReason() != "" )
		{
			textParams = new inkTextParams;
			textParams.AddString( "ACTION", locText );
			textParams.AddLocalizedString( "ADDITIONALINFO", deviceAction.GetInactiveReason() );
			inkTextRef.SetLocalizedTextScript( m_label, "LocKey#42173", textParams );
			inkTextRef.SetLocalizedTextScript( m_labelFail, "LocKey#42173", textParams );
		}
		else
		{
			inkTextRef.SetText( m_label, locText );
			inkTextRef.SetText( m_labelFail, locText );
		}
	}

	public function SetCaptionParts( const argList : ref< array< InteractionChoiceCaptionPart > > )
	{
		var i : Int32;
		var currType : gamedataChoiceCaptionPartType;
		var mappinVariant : gamedataMappinVariant;
		var iconName : CName;
		var iconID : TweakDBID;
		var iconRecord : weak< ChoiceCaptionIconPart_Record >;
		var showQHHolder : Bool;
		for( i = 0; i < argList.Size(); i = i + 1 )
		{
			currType = ( ( InteractionChoiceCaptionPart )( argList[ i ] ) ).GetType();
			if( currType == gamedataChoiceCaptionPartType.Icon )
			{
				iconRecord = ( ( InteractionChoiceCaptionIconPart )( argList[ i ] ) ).iconRecord;
				iconID = iconRecord.TexturePartID().GetID();
				if( TDBID.IsValid( iconID ) )
				{
					SetTexture( m_QuickHackIcon, iconID );
					showQHHolder = true;
				}
				else
				{
					mappinVariant = iconRecord.MappinVariant().Type();
					iconName = MappinUIUtils.MappinToTexturePart( mappinVariant );
					inkImageRef.SetTexturePart( m_QuickHackIcon, iconName );
					if( iconName != 'invalid' && iconName != '' )
					{
						showQHHolder = true;
					}
				}
				if( showQHHolder )
				{
					inkCompoundRef.SetVisible( m_QuickHackHolder, true );
				}
			}
			else if( currType == gamedataChoiceCaptionPartType.QuickhackCost )
			{
				inkCompoundRef.SetVisible( m_QuickHackHolder, true );
				inkWidgetRef.SetVisible( m_QuickHackCostHolder, true );
				inkTextRef.SetText( m_QuickHackCost, IntToString( ( ( InteractionChoiceCaptionQuickhackCostPart )( argList[ i ] ) ).cost ) );
			}
		}
	}

	public function EmptyCaptionParts()
	{
		inkCompoundRef.SetVisible( m_QuickHackHolder, false );
	}

	private function SetIllegalActionOpacity( opacity : Float )
	{
		inkWidgetRef.SetOpacity( m_QHIllegalIndicator, opacity );
		inkWidgetRef.SetOpacity( m_SCIllegalIndicator, opacity );
	}

	private function PlayAnim( animName : CName )
	{
		m_animProxy = PlayLibraryAnimation( animName );
	}

}

