class InventoryWeaponItemChooser extends InventoryGenericItemChooser
{
	protected editable var m_scopeRootContainer : inkCompoundRef;
	protected editable var m_magazineRootContainer : inkCompoundRef;
	protected editable var m_silencerRootContainer : inkCompoundRef;
	protected editable var m_scopeContainer : inkCompoundRef;
	protected editable var m_magazineContainer : inkCompoundRef;
	protected editable var m_silencerContainer : inkCompoundRef;
	protected editable var m_attachmentsLabel : inkTextRef;
	protected editable var m_attachmentsContainer : inkWidgetRef;
	protected editable var m_softwareModsLabel : inkTextRef;
	protected editable var m_softwareModsPush : inkWidgetRef;
	protected editable var m_softwareModsContainer : inkWidgetRef;

	protected override function GetSlots() : array< InventoryItemAttachments >
	{
		return InventoryUtils.GetMods( itemDisplay.GetItemData(), true );
	}

	protected override function RebuildSlots()
	{
		super.RebuildSlots();
		RebuildParts();
	}

	protected override function ForceDisplayLabel() : Bool
	{
		var itemParts : array< InventoryItemAttachments >;
		itemParts = InventoryUtils.GetParts( itemDisplay.GetItemData() );
		return itemParts.Size() > 0;
	}

	private function UpdateModsLabel( const parts : ref< array< InventoryItemAttachments > > )
	{
		var hasMods, hasParts : Bool;
		var i, limit, attachmentsCounter : Int32;
		var attachments : array< InventoryItemAttachments >;
		attachments = InventoryItemData.GetAttachments( itemDisplay.GetItemData() );
		for( i = 0, limit = attachments.Size(); i < limit; i += 1 )
		{
			if( attachments[ i ].SlotType == InventoryItemAttachmentType.Generic )
			{
				attachmentsCounter += 1;
			}
		}
		hasMods = ( attachmentsCounter - parts.Size() ) > 0;
		hasParts = parts.Size() > 0;
		inkTextRef.SetVisible( m_attachmentsLabel, hasParts );
		inkWidgetRef.SetVisible( m_attachmentsContainer, hasParts );
		inkTextRef.SetVisible( m_softwareModsLabel, hasMods );
		inkWidgetRef.SetVisible( m_softwareModsContainer, hasMods );
		inkWidgetRef.SetVisible( m_softwareModsPush, hasParts );
	}

	private function GetRootSlotContainerFromType( partType : WeaponPartType ) : inkCompoundRef
	{
		var emptyResult : inkCompoundRef;
		switch( partType )
		{
			case WeaponPartType.Silencer:
				return m_silencerRootContainer;
			case WeaponPartType.Magazine:
				return m_magazineRootContainer;
			case WeaponPartType.Scope:
				return m_scopeRootContainer;
		}
		return emptyResult;
	}

	private function GetSlotContainerFromType( partType : WeaponPartType ) : inkCompoundRef
	{
		var emptyResult : inkCompoundRef;
		switch( partType )
		{
			case WeaponPartType.Silencer:
				return m_silencerContainer;
			case WeaponPartType.Magazine:
				return m_magazineContainer;
			case WeaponPartType.Scope:
				return m_scopeContainer;
		}
		return emptyResult;
	}

	private function GetAtlasPartFromType( partType : WeaponPartType ) : CName
	{
		switch( partType )
		{
			case WeaponPartType.Silencer:
				return 'mod_silencer-1';
			case WeaponPartType.Magazine:
				return 'mod_magazine-1';
			case WeaponPartType.Scope:
				return 'mod_scope-1';
		}
		return 'item_grid_accent';
	}

	private function GetAllPartsTypes() : array< WeaponPartType >
	{
		var result : array< WeaponPartType >;
		result.PushBack( WeaponPartType.Silencer );
		result.PushBack( WeaponPartType.Magazine );
		result.PushBack( WeaponPartType.Scope );
		return result;
	}

	private function GetPartDataByType( const parts : ref< array< InventoryItemAttachments > >, type : WeaponPartType ) : InventoryItemAttachments
	{
		var i : Int32;
		var emptyResult : InventoryItemAttachments;
		for( i = 0; i < parts.Size(); i += 1 )
		{
			if( InventoryUtils.GetPartType( parts[ i ] ) == type )
			{
				return parts[ i ];
			}
		}
		return emptyResult;
	}

	protected virtual function RebuildParts()
	{
		var i, j : Int32;
		var part : InventoryItemAttachments;
		var itemParts : array< InventoryItemAttachments >;
		var allParts : array< WeaponPartType >;
		var slot : InventoryItemDisplayController;
		var slotContainer : inkCompoundRef;
		var slotRootContainer : inkCompoundRef;
		var inventoryItemData : InventoryItemData;
		var itemData : weak< gameItemData >;
		inventoryItemData = itemDisplay.GetItemData();
		itemData = InventoryItemData.GetGameItemData( inventoryItemData );
		allParts = GetAllPartsTypes();
		itemParts = InventoryUtils.GetParts( inventoryItemData );
		UpdateModsLabel( itemParts );
		for( i = 0; i < allParts.Size(); i += 1 )
		{
			slot = NULL;
			part = GetPartDataByType( itemParts, allParts[ i ] );
			slotRootContainer = GetRootSlotContainerFromType( allParts[ i ] );
			slotContainer = GetSlotContainerFromType( allParts[ i ] );
			if( TDBID.IsValid( part.SlotID ) )
			{
				inkCompoundRef.SetVisible( slotRootContainer, true );
				for( j = 0; j < inkCompoundRef.GetNumChildren( slotContainer ); j += 1 )
				{
					if( ( ( InventoryItemDisplayController )( inkCompoundRef.GetWidgetByIndex( slotContainer, j ).GetController() ) ) )
					{
						slot = ( ( InventoryItemDisplayController )( inkCompoundRef.GetWidgetByIndex( slotContainer, j ).GetController() ) );
					}
				}
				if( !( slot ) )
				{
					slot = ( ( InventoryItemDisplayController )( ItemDisplayUtils.SpawnCommonSlotController( this, slotContainer, GetSlotDisplayToSpawn() ) ) );
					slot.GetRootWidget().RegisterToCallback( 'OnRelease', this, 'OnItemInventoryClick' );
					slot.GetRootWidget().RegisterToCallback( 'OnHoverOver', this, 'OnInventoryItemHoverOver' );
					slot.GetRootWidget().RegisterToCallback( 'OnHoverOut', this, 'OnInventoryItemHoverOut' );
				}
				slot.SetDefaultShadowIcon( GetAtlasPartFromType( allParts[ i ] ) );
				slot.SetParentItem( itemData );
				slot.Setup( inventoryDataManager, part.ItemData, part.SlotID, ItemDisplayContext.Attachment, true );
			}
			else
			{
				inkCompoundRef.SetVisible( slotRootContainer, false );
			}
		}
	}

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

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

}

