#pragma once

#include "Blueprint/UserWidget.h"
#include "CoreMinimal.h"
#include "ZeusAttributesSnapshot.h"
#include "ZeusHudHpSpWidget.generated.h"

class UProgressBar;
class UTextBlock;

/**
 *  Sub-widget do HUD: barras de HP/SP + label de level. Sem auto-bind no
 *  GAS Component — o parent (`UZeusHudWidget`) propaga snapshots via
 *  `ApplySnapshot` / `ApplyHpSp` quando o player local recebe updates.
 *
 *  Migrado de ZeusAttributes plugin pra ZMMO em M7 (delecao do plugin
 *  legacy). API preservada — WBP que herda dele nao precisa mudar.
 *
 *  Convencao `meta=(BindWidget)`: o WBP filho deve ter widgets com nomes
 *  exatos (HpBar, SpBar). `BindWidgetOptional` permite omitir.
 */
UCLASS(Abstract, Blueprintable, BlueprintType)
class ZMMO_API UZeusHudHpSpWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	/** Atualiza todos os campos a partir do snapshot. Chamado pelo UZeusHudWidget. */
	UFUNCTION(BlueprintCallable, Category = "Zeus|HUD")
	void ApplySnapshot(const FZeusAttributesSnapshot& Snapshot);

	/** Atualiza apenas HP/SP (sem mexer no level/text). Otimizacao do tick. */
	UFUNCTION(BlueprintCallable, Category = "Zeus|HUD")
	void ApplyHpSp(int32 Hp, int32 MaxHp, int32 Sp, int32 MaxSp);

protected:
	/**
	 *  Hook BlueprintNativeEvent para skin visual reagir a um snapshot novo
	 *  (cores, animacao de level up, etc.). Impl default em C++ apenas
	 *  atualiza progress bars + textos via BindWidget/BindWidgetOptional.
	 */
	UFUNCTION(BlueprintNativeEvent, Category = "Zeus|HUD")
	void OnSnapshotApplied(const FZeusAttributesSnapshot& Snapshot);
	virtual void OnSnapshotApplied_Implementation(const FZeusAttributesSnapshot& Snapshot);

	// === BindWidget — devem existir no WBP com EXATAMENTE estes nomes ===
	UPROPERTY(BlueprintReadOnly, meta = (BindWidget), Category = "Zeus|HUD")
	UProgressBar* HpBar = nullptr;

	UPROPERTY(BlueprintReadOnly, meta = (BindWidget), Category = "Zeus|HUD")
	UProgressBar* SpBar = nullptr;

	UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional), Category = "Zeus|HUD")
	UTextBlock* HpText = nullptr;

	UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional), Category = "Zeus|HUD")
	UTextBlock* SpText = nullptr;

	UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional), Category = "Zeus|HUD")
	UTextBlock* LevelText = nullptr;

private:
	/// Ultimo snapshot recebido (cache pra ApplyHpSp manter MaxHp/MaxSp).
	UPROPERTY(Transient)
	FZeusAttributesSnapshot LastSnapshot;
};
