importonly class ShowPointOfNoReturnPromptEvent extends Event
{
}

class PonrRewardsGameController extends BaseModalListPopupGameController
{
	private var m_gameInstance : GameInstance;
	private var m_inventoryManager : InventoryDataManagerV2;
	private var m_tooltipsManager : weak< gameuiTooltipsManager >;
	private editable var m_rewardListInventoryItemGrid : inkWidgetRef;
	private editable var m_rewardListInventoryWeaponGrid : inkWidgetRef;
	private editable var m_rewardListRipperdocGrid : inkWidgetRef;
	private editable var m_rewardListInventoryItemHolder : inkWidgetRef;
	private editable var m_rewardListRipperdocHolder : inkWidgetRef;
	private editable var m_tooltipsManagerRef : inkWidgetRef;
	private editable var m_okayButton : inkWidgetRef;
	private editable var m_endingAchievementArt : inkImageRef;
	private var m_pointOfNoReturnBB : weak< IBlackboard >;
	private var m_pointOfNoReturnRewardScreenDef : UI_PointOfNoReturnRewardScreenDef;

	protected event OnInitialize()
	{
		var owner : weak< GameObject >;
		super.OnInitialize();
		owner = ( ( GameObject )( GetPlayerControlledObject() ) );
		m_gameInstance = ( ( GameInstance )( owner.GetGame() ) );
		m_pointOfNoReturnRewardScreenDef = GetAllBlackboardDefs().UI_PointOfNoReturnRewardScreen;
		m_pointOfNoReturnBB = GetBlackboardSystem().Get( m_pointOfNoReturnRewardScreenDef );
		m_tooltipsManager = ( ( gameuiTooltipsManager )( inkWidgetRef.GetControllerByType( m_tooltipsManagerRef, 'gameuiTooltipsManager' ) ) );
		m_tooltipsManager.Setup( ETooltipsStyle.Menus );
		inkWidgetRef.RegisterToCallback( m_okayButton, 'OnRelease', this, 'OnOkayRelease' );
		Show();
	}

	protected event OnUninitialize()
	{
		super.OnUninitialize();
		inkWidgetRef.UnregisterFromCallback( m_okayButton, 'OnRelease', this, 'OnOkayRelease' );
		m_tooltipsManager.HideTooltips();
		m_inventoryManager.UnInitialize();
	}

	protected event OnPlayerAttach( playerPuppet : GameObject )
	{
		super.OnPlayerAttach( playerPuppet );
		m_inventoryManager = new InventoryDataManagerV2;
		m_inventoryManager.Initialize( ( ( PlayerPuppet )( playerPuppet ) ) );
		if( GameInstance.GetQuestsSystem( m_gameInstance ).GetFact( 'q201_done' ) == 1 )
		{
			inkImageRef.SetTexturePart( m_endingAchievementArt, 'devil' );
		}
		else if( GameInstance.GetQuestsSystem( m_gameInstance ).GetFact( 'q202_done' ) == 1 )
		{
			inkImageRef.SetTexturePart( m_endingAchievementArt, 'star' );
		}
		else if( GameInstance.GetQuestsSystem( m_gameInstance ).GetFact( 'q203_done' ) == 1 )
		{
			inkImageRef.SetTexturePart( m_endingAchievementArt, 'sun' );
		}
		else if( GameInstance.GetQuestsSystem( m_gameInstance ).GetFact( 'q204_done' ) == 1 )
		{
			inkImageRef.SetTexturePart( m_endingAchievementArt, 'temperance' );
		}
	}

	protected event OnOkayRelease( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			OnClose();
		}
	}

	private function GetInventoryItemDisplayControllerFromTarget( evt : inkPointerEvent ) : InventoryItemDisplayController
	{
		var widget : inkWidget;
		var controller : weak< InventoryItemDisplayController >;
		widget = evt.GetCurrentTarget();
		controller = ( ( InventoryItemDisplayController )( widget.GetController() ) );
		return controller;
	}

	protected event OnInventoryItemHoverOver( evt : inkPointerEvent )
	{
		var controller : InventoryItemDisplayController;
		var itemData : InventoryItemData;
		controller = GetInventoryItemDisplayControllerFromTarget( evt );
		itemData = controller.GetItemData();
		InventoryItemHoverOver( itemData, evt.GetCurrentTarget() );
	}

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

	private function InventoryItemHoverOver( const itemData : ref< InventoryItemData >, widget : weak< inkWidget > )
	{
		var tooltipData : InventoryTooltipData;
		m_tooltipsManager.HideTooltips();
		if( !( InventoryItemData.IsEmpty( itemData ) ) )
		{
			tooltipData = m_inventoryManager.GetTooltipDataForInventoryItem( itemData, InventoryItemData.IsEquipped( itemData ), InventoryItemData.IsVendorItem( itemData ) );
			if( InventoryItemData.GetGameItemData( itemData ).HasTag( 'Cyberdeck' ) )
			{
				m_tooltipsManager.ShowTooltipAtWidget( 'cyberdeckTooltip', widget, tooltipData, gameuiETooltipPlacement.RightTop, true );
			}
			else if( InventoryItemData.GetItemType( itemData ) == gamedataItemType.Prt_Program )
			{
				m_tooltipsManager.ShowTooltipAtWidget( 'programTooltip', widget, tooltipData, gameuiETooltipPlacement.RightTop, true );
			}
			else
			{
				m_tooltipsManager.ShowTooltipAtWidget( 'itemTooltip', widget, tooltipData, gameuiETooltipPlacement.RightTop, true );
			}
		}
	}

	protected override function OnClose()
	{
		Hide();
		m_popupData.token.TriggerCallback( m_popupData );
	}

	private function Show()
	{
		GetRootWidget().SetVisible( true );
		PopulateData();
		PopupStateUtils.SetBackgroundBlur( this, true );
	}

	private function Hide()
	{
		var player : GameObject;
		player.UnregisterInputListener( this );
		GetRootWidget().SetVisible( false );
		PopupStateUtils.SetBackgroundBlur( this, false );
		m_tooltipsManager.HideTooltips();
	}

	private function PopulateData()
	{
		var slot : InventoryItemDisplayController;
		var itemData : InventoryItemData;
		var itemDataArray : array< ItemID >;
		var i : Int32;
		var itemCategory : gamedataItemCategory;
		itemDataArray = ( ( array< ItemID > )( m_pointOfNoReturnBB.GetVariant( m_pointOfNoReturnRewardScreenDef.Rewards ) ) );
		inkWidgetRef.SetVisible( m_rewardListInventoryItemHolder, false );
		inkWidgetRef.SetVisible( m_rewardListRipperdocHolder, false );
		for( i = 0; i < itemDataArray.Size(); i += 1 )
		{
			itemData = ToInventoryItemData( GetPlayerControlledObject(), itemDataArray[ i ] );
			itemCategory = RPGManager.GetItemCategory( InventoryItemData.GetID( itemData ) );
			if( itemCategory == gamedataItemCategory.Cyberware )
			{
				slot = ( ( InventoryItemDisplayController )( ItemDisplayUtils.SpawnCommonSlotController( this, m_rewardListRipperdocGrid, 'itemDisplay' ) ) );
				inkWidgetRef.SetVisible( m_rewardListRipperdocHolder, true );
			}
			else if( itemCategory == gamedataItemCategory.Weapon )
			{
				slot = ( ( InventoryItemDisplayController )( ItemDisplayUtils.SpawnCommonSlotController( this, m_rewardListInventoryWeaponGrid, 'weaponDisplay' ) ) );
				inkWidgetRef.SetVisible( m_rewardListInventoryItemHolder, true );
			}
			else
			{
				slot = ( ( InventoryItemDisplayController )( ItemDisplayUtils.SpawnCommonSlotController( this, m_rewardListInventoryItemGrid, 'itemDisplay' ) ) );
				inkWidgetRef.SetVisible( m_rewardListInventoryItemHolder, true );
			}
			slot.GetRootWidget().RegisterToCallback( 'OnHoverOver', this, 'OnInventoryItemHoverOver' );
			slot.GetRootWidget().RegisterToCallback( 'OnHoverOut', this, 'OnInventoryItemHoverOut' );
			slot.Setup( itemData, ItemDisplayContext.Backpack, true );
		}
	}

}

