#pragma once

#include "CoreMinimal.h"
#include "CommonUserWidget.h"
#include "UI/UIStyleTokens.h"
#include "UISpinner_Base.generated.h"

class UCircularThrobber;

/**
 * Spinner/throbber indeterminado do ZMMO — mesmo padrão de UUIPanel_Base.
 * Fundação CommonUI (UCommonUserWidget). Camada Abstract; o WBP concreto
 * (UI_Spinner_Master) herda DIRETO desta classe C++ (UMG não encadeia
 * árvores — ARQUITETURA.md §3.3).
 *
 * Visual data-driven por FUIStyle.Spinner (UZMMOThemeSubsystem). C++ aplica
 * NumberOfPieces/Period/Radius no UCircularThrobber; cor/brush vão pelo hook
 * BP_ApplySpinnerStyle (o WBP tinge a imagem do throbber).
 */
UCLASS(Abstract, Blueprintable)
class ZMMO_API UUISpinner_Base : public UCommonUserWidget
{
	GENERATED_BODY()

public:
	/** Re-resolve os tokens do tema ativo e reaplica no throbber. */
	UFUNCTION(BlueprintCallable, Category = "UI Style")
	void RefreshUIStyle();

	/**
	 * Variante visual do spinner (dropdown vem de FUIStyle.Spinner.Colors/
	 * Layouts no DT_UI_Styles). Data-driven, sem enum fixo.
	 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spinner",
		meta = (GetOptions = "GetVariantOptions"))
	FName Variant = TEXT("Default");

	UFUNCTION()
	TArray<FString> GetVariantOptions() const;

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

	/** Hook opcional: o WBP aplica cor/brush do spinner (variante composta). */
	UFUNCTION(BlueprintImplementableEvent, Category = "UI Style",
		meta = (DisplayName = "Apply Spinner Style"))
	void BP_ApplySpinnerStyle(const FUIStyleSpinnerVariant& VariantStyle);

	/** Throbber circular (nome esperado no WBP: "Throbber"). */
	UPROPERTY(meta = (BindWidgetOptional))
	TObjectPtr<UCircularThrobber> Throbber;

private:
	UFUNCTION()
	void HandleThemeChanged(FName NewThemeId);

	bool bThemeBound = false;
};
