#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "ZMMOWorldEntry.h"
#include "UIServerCard_Base.generated.h"

class UCommonTextBlock;
class UBorder;
class UUIButton_Base;
class UProgressBar;

/**
 * Card de servidor (mundo) instanciado dinamicamente pela ServerSelect.
 *
 * Recebe um `FZMMOWorldEntry` e renderiza nome/pop/status/bar; ao clicar
 * em "Entrar" dispara `OnCardPressed.Broadcast(WorldId, State)`. A tela
 * dona (UUIServerSelectScreen_Base) escuta esse delegate.
 *
 * WBP filho (`WBP_ServerCard`) precisa expor (via nomes de variavel):
 *   - Card_Bg        : Border  (opcional - background com estado)
 *   - Text_Name      : CommonTextBlock
 *   - Text_Pop       : CommonTextBlock
 *   - Text_Status    : CommonTextBlock
 *   - Btn_Enter      : Button
 *   - Bar_Pop        : ProgressBar (opcional)
 */
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FZMMOOnServerCardPressed, FString, WorldId, uint8, State);

UCLASS(Abstract, Blueprintable)
class ZMMO_API UUIServerCard_Base : public UUserWidget
{
	GENERATED_BODY()

public:
	/**
	 * Aplica os dados de um mundo no card.
	 */
	UFUNCTION(BlueprintCallable, Category = "Zeus|ServerCard")
	void SetFromEntry(const FZMMOWorldEntry& Entry);

	/** Dados atuais (copia). */
	UPROPERTY(BlueprintReadOnly, Category = "Zeus|ServerCard")
	FZMMOWorldEntry Entry;

	/**
	 * Disparado quando o botao "Entrar" do card e clicado.
	 * State e o wire state (0=Offline, 1=Online, 2=Maintenance).
	 */
	UPROPERTY(BlueprintAssignable, Category = "Zeus|ServerCard")
	FZMMOOnServerCardPressed OnCardPressed;

protected:
	virtual void NativePreConstruct() override;
	virtual void NativeConstruct() override;
	virtual void NativeDestruct() override;

	void HandleEnterClicked();

	/** Texto i18n correspondente ao state. Subclasse pode override em BP. */
	UFUNCTION(BlueprintNativeEvent, Category = "Zeus|ServerCard")
	FText FormatStatus(uint8 State) const;
	virtual FText FormatStatus_Implementation(uint8 State) const;

	UPROPERTY(meta = (BindWidgetOptional)) TObjectPtr<UBorder>          Card_Bg;
	UPROPERTY(meta = (BindWidgetOptional)) TObjectPtr<UCommonTextBlock> Text_Name;
	UPROPERTY(meta = (BindWidgetOptional)) TObjectPtr<UCommonTextBlock> Text_Pop;
	UPROPERTY(meta = (BindWidgetOptional)) TObjectPtr<UCommonTextBlock> Text_Status;
	UPROPERTY(meta = (BindWidget))         TObjectPtr<UUIButton_Base>   Btn_Enter;
	UPROPERTY(meta = (BindWidgetOptional)) TObjectPtr<UProgressBar>     Bar_Pop;

private:
	bool bBound = false;
};
