class InventoryCyberwareItemChooser extends InventoryGenericItemChooser
{
	protected editable var m_leftSlotsContainer : inkCompoundRef;
	protected editable var m_rightSlotsContainer : inkCompoundRef;
	private var m_itemData : InventoryItemData;

	protected override function GetDisplayToSpawn() : CName
	{
		return 'itemDisplay';
	}

	protected override function GetIntroAnimation() : CName
	{
		return 'cyberwareItemChoser_intro';
	}

	protected override function GetSlots() : array< InventoryItemAttachments >
	{
		return InventoryItemData.GetAttachments( m_itemData );
	}

	public override function RefreshSelectedItem()
	{
		ChangeSelectedItem( NULL );
	}

	public override function RequestClose() : Bool
	{
		return true;
	}

	protected override function RebuildSlots()
	{
		var i, numberOfSlots, emptyIndex : Int32;
		var slot : InventoryItemDisplayController;
		var slots : array< InventoryItemAttachments >;
		slots = GetSlots();
		numberOfSlots = slots.Size();
		while( inkCompoundRef.GetNumChildren( m_leftSlotsContainer ) > numberOfSlots )
		{
			inkCompoundRef.RemoveChildByIndex( m_leftSlotsContainer, inkCompoundRef.GetNumChildren( m_leftSlotsContainer ) - 1 );
		}
		while( inkCompoundRef.GetNumChildren( m_leftSlotsContainer ) < numberOfSlots )
		{
			slot = ( ( InventoryItemDisplayController )( ItemDisplayUtils.SpawnCommonSlotController( this, m_leftSlotsContainer, 'itemDisplay' ) ) );
			if( slot )
			{
				slot.GetRootWidget().RegisterToCallback( 'OnRelease', this, 'OnItemInventoryClick' );
				slot.GetRootWidget().RegisterToCallback( 'OnHoverOver', this, 'OnInventoryItemHoverOver' );
				slot.GetRootWidget().RegisterToCallback( 'OnHoverOut', this, 'OnInventoryItemHoverOut' );
			}
			else
			{
				break;
			}
		}
		for( i = 0; i < numberOfSlots; i += 1 )
		{
			slot = ( ( InventoryItemDisplayController )( inkCompoundRef.GetWidgetByIndex( m_leftSlotsContainer, i ).GetController() ) );
			if( TDBID.IsValid( slots[ i ].SlotID ) )
			{
				if( !( InventoryItemData.IsEmpty( slots[ i ].ItemData ) ) )
				{
					InventoryItemData.SetIsEquipped( slots[ i ].ItemData, true );
				}
				slot.SetParentItem( InventoryItemData.GetGameItemData( m_itemData ) );
				slot.Setup( inventoryDataManager, slots[ i ].ItemData, slots[ i ].SlotID, ItemDisplayContext.Attachment );
			}
		}
		if( selectedItem == NULL )
		{
			emptyIndex = GetFirstEmptySlotIndex( slots );
			if( ( inkCompoundRef.GetNumChildren( m_leftSlotsContainer ) > 0 ) && ( emptyIndex != -1 ) )
			{
				ChangeSelectedItem( ( ( InventoryItemDisplayController )( inkCompoundRef.GetWidgetByIndex( m_leftSlotsContainer, emptyIndex ).GetController() ) ) );
			}
			else
			{
				ChangeSelectedItem( NULL );
			}
		}
	}

	private function GetFirstEmptySlotIndex( const slots : ref< array< InventoryItemAttachments > > ) : Int32
	{
		var i : Int32;
		var slot : InventoryItemDisplayController;
		var slotData : InventoryItemData;
		for( i = 0; i < slots.Size(); i += 1 )
		{
			slot = ( ( InventoryItemDisplayController )( inkCompoundRef.GetWidgetByIndex( m_leftSlotsContainer, i ).GetController() ) );
			slotData = slot.GetItemData();
			if( InventoryItemData.IsEmpty( slotData ) )
			{
				return i;
			}
		}
		return 0;
	}

	protected override function RefreshMainItem( optional isClothingSetEquipped : Bool, optional clothingSetIndex : Int32, optional showTransmogedIcon : Bool )
	{
		var itemID : ItemID;
		var slot : InventoryItemDisplayController;
		if( inventoryDataManager.GetNumberOfSlots( equipmentArea ) < 1 )
		{
			return;
		}
		itemID = inventoryDataManager.GetEquippedItemIdInArea( equipmentArea, slotIndex );
		m_itemData = inventoryDataManager.GetItemDataFromIDInLoadout( itemID );
		inkCompoundRef.RemoveAllChildren( m_itemContainer );
		slot = ( ( InventoryItemDisplayController )( ItemDisplayUtils.SpawnCommonSlotController( this, m_itemContainer, 'itemDisplay' ) ) );
		slot.GetRootWidget().RegisterToCallback( 'OnRelease', this, 'OnItemInventoryClick' );
		slot.GetRootWidget().RegisterToCallback( 'OnHoverOver', this, 'OnInventoryItemHoverOver' );
		slot.GetRootWidget().RegisterToCallback( 'OnHoverOut', this, 'OnInventoryItemHoverOut' );
		slot.Bind( inventoryDataManager, equipmentArea, slotIndex, ItemDisplayContext.Ripperdoc );
	}

	public override function GetModifiedItemData() : InventoryItemData
	{
		return m_itemData;
	}

	public override function GetModifiedItemID() : ItemID
	{
		return InventoryItemData.GetID( m_itemData );
	}

}

