#pragma once

#include "Blueprint/UserWidget.h"
#include "CoreMinimal.h"
#include "ZMMOAttributeTypes.h"
#include "ZMMOHudHpSpWidget.generated.h"

class UProgressBar;
class UTextBlock;

/**
 *  Sub-widget do HUD: barras de HP/SP + label de level. Sem auto-bind no
 *  AttributeComponent — o parent (`UZMMOHudWidget`) propaga snapshots via
 *  `ApplySnapshot` / `ApplyHpSpDelta` quando o player local recebe updates.
 *
 *  Composicao do HUD (ver `UZMMOHudWidget`):
 *    WBP_HUD (UZMMOHudWidget root)
 *    |-- HpSpBar    (UZMMOHudHpSpWidget — este)
 *    |-- PlayerInfo (futuro — nome/job/level)
 *    |-- Minimap    (futuro)
 *    |-- QuickBar   (futuro — hotkeys)
 *    |-- Buffs      (futuro — icones SC)
 *    |-- Chat       (futuro)
 *    |-- TargetInfo (futuro — mob/player targetado)
 *
 *  Cada sub-widget tem responsabilidade unica (SRP). O parent (UZMMOHudWidget)
 *  faz binding com AttributeComponent e propaga deltas.
 *
 *  Convencao `meta=(BindWidget)`: o WBP filho deve ter widgets com nomes
 *  exatos (HpBar, SpBar). `BindWidgetOptional` permite omitir.
 */
UCLASS(Abstract, Blueprintable, BlueprintType)
class ZMMOATTRIBUTES_API UZMMOHudHpSpWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	/** Atualiza todos os campos a partir do snapshot. Chamado pelo UZMMOHudWidget. */
	UFUNCTION(BlueprintCallable, Category = "Zeus|HUD")
	void ApplySnapshot(const FZMMOAttributesSnapshot& 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 FZMMOAttributesSnapshot& Snapshot);
	virtual void OnSnapshotApplied_Implementation(const FZMMOAttributesSnapshot& 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)
	FZMMOAttributesSnapshot LastSnapshot;
};
