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

#include "PhoneAppIconWidget.h"

#include "Components/Button.h"
#include "Components/Image.h"
#include "CommonTextBlock.h"

void UPhoneAppIconWidget::Init(const FText& InName, UTexture2D* InIcon, UMaterialInterface* InBgMaterial, TSubclassOf<UPhoneAppWidget> InAppClass)
{
	AppClass = InAppClass;

	NameText->SetText(InName);

	IconImage->SetBrushFromTexture(InIcon);
	IconImage->SetVisibility(InIcon ? ESlateVisibility::HitTestInvisible : ESlateVisibility::Collapsed);
	
	BackgroundImage->SetBrushFromMaterial(InBgMaterial);

	IconButton->OnClicked.AddUniqueDynamic(this, &UPhoneAppIconWidget::HandleClicked);
}

void UPhoneAppIconWidget::HandleClicked()
{
	OnClicked.ExecuteIfBound(AppClass);
}