#include "ZMMOHUD.h"

#include "Engine/GameInstance.h"
#include "ZMMO.h"
#include "UI/InGame/UIInGameFlowSubsystem.h"

AZMMOHUD::AZMMOHUD()
{
	// AHUD nao precisa tick — toda atualizacao vem via UMG (delegates +
	// CommonUI). PrimaryActorTick default e' off; mantemos.
}

void AZMMOHUD::BeginPlay()
{
	Super::BeginPlay();

	// UI in-game assume responsabilidade aqui. Subsystem orquestra:
	// resolve DA_InGameScreenSet[Playing] -> WBP_HUD, pushea em UI.Layer.Game.
	if (const UGameInstance* GI = GetGameInstance())
	{
		if (UUIInGameFlowSubsystem* Flow = GI->GetSubsystem<UUIInGameFlowSubsystem>())
		{
			Flow->StartInGame();
		}
		else
		{
			UE_LOG(LogZMMO, Warning,
				TEXT("AZMMOHUD: UUIInGameFlowSubsystem nao encontrado — HUD nao sera spawnado"));
		}
	}
}

void AZMMOHUD::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	// UUIInGameFlowSubsystem persiste no GameInstance entre OpenLevel — nao
	// limpamos UI in-game aqui (o front-end flow vai tomar conta na proxima
	// transicao de estado). Cleanup do widget atual acontece no
	// NativeOnDeactivated quando o stack for esvaziado pelo flow.
	Super::EndPlay(EndPlayReason);
}
