// © 2025 Naked People Team. All Rights Reserved.


#include "EquipmentPanelWidget.h"

#include "EquipmentSlotWidget.h"
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/Clothing/ClothingManager.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"

void UEquipmentPanelWidget::NativeConstruct()
{
	Super::NativeConstruct();
	
	InitSlotTypes();
	
	const ANakedDesireCharacter* Player = Cast<ANakedDesireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));

	const TArray<UEquipmentSlotWidget*> AllSlots = {
		NipplesSlot, AnalSlot, VaginaSlot,
		HeadSlot, NeckSlot, FaceSlot, EyesSlot,
		BodysuitSlot, TopSlot, BottomSlot,
		UnderwearTopSlot, UnderwearBottomSlot,
		SocksSlot, FootwearSlot, OuterwearSlot,
		WristRestraintSlot, AnkleRestraintSlot, NeckRestraintSlot
	};

	for (UEquipmentSlotWidget* SlotWidget : AllSlots)
	{
		if (SlotWidget)
		{
			SlotWidget->OnEquipmentSlotClicked.BindUObject(this, &UEquipmentPanelWidget::HandleSlotClicked);
			if (UClothingItemInstance* Item = Player->ClothingManager->GetSlotClothing(SlotWidget->GetSlotType()))
				SlotWidget->SetItem(Item);
			else
				SlotWidget->ClearItem();
		}
	}
}

void UEquipmentPanelWidget::NativePreConstruct()
{
	Super::NativePreConstruct();
	
	InitSlotTypes();
}

void UEquipmentPanelWidget::HandleSlotClicked(UEquipmentSlotWidget* SlotWidget)
{
	OnSlotClicked.ExecuteIfBound(SlotWidget);
}

void UEquipmentPanelWidget::InitSlotTypes()
{
	if (NipplesSlot)          NipplesSlot->SetSlotType(EClothingSlotType::Nipples);
	if (AnalSlot)             AnalSlot->SetSlotType(EClothingSlotType::Anal);
	if (VaginaSlot)           VaginaSlot->SetSlotType(EClothingSlotType::Vagina);
	if (HeadSlot)             HeadSlot->SetSlotType(EClothingSlotType::Head);
	if (NeckSlot)             NeckSlot->SetSlotType(EClothingSlotType::Neck);
	if (FaceSlot)             FaceSlot->SetSlotType(EClothingSlotType::Face);
	if (EyesSlot)             EyesSlot->SetSlotType(EClothingSlotType::Eyes);
	if (BodysuitSlot)         BodysuitSlot->SetSlotType(EClothingSlotType::Bodysuit);
	if (TopSlot)              TopSlot->SetSlotType(EClothingSlotType::Top);
	if (BottomSlot)           BottomSlot->SetSlotType(EClothingSlotType::Bottom);
	if (UnderwearTopSlot)     UnderwearTopSlot->SetSlotType(EClothingSlotType::UnderwearTop);
	if (UnderwearBottomSlot)  UnderwearBottomSlot->SetSlotType(EClothingSlotType::UnderwearBottom);
	if (SocksSlot)            SocksSlot->SetSlotType(EClothingSlotType::Socks);
	if (FootwearSlot)         FootwearSlot->SetSlotType(EClothingSlotType::Footwear);
	if (OuterwearSlot)        OuterwearSlot->SetSlotType(EClothingSlotType::Outerwear);
	if (WristRestraintSlot)   WristRestraintSlot->SetSlotType(EClothingSlotType::WristRestraint);
	if (AnkleRestraintSlot)   AnkleRestraintSlot->SetSlotType(EClothingSlotType::AnkleRestraint);
	if (NeckRestraintSlot)    NeckRestraintSlot->SetSlotType(EClothingSlotType::NeckRestraint);
}
