#pragma once

#include "CoreMinimal.h"
#include "UIActivatableScreen_Base.h"
#include "UIBootScreen_Base.generated.h"

class UUIButton_Base;
class UUISpinner_Base;
class UCommonTextBlock;
class UBorder;
class UZeusCharServerSubsystem;

/**
 * Tela de Boot — primeira tela do front-end. Reconstruída a partir do mock
 * do Zeus UMG Forge com os widgets compartilhados (UI_Button_Master,
 * UI_Spinner_Master). Camada Abstract; o WBP concreto (WBP_Boot) herda
 * DIRETO desta classe (ARQUITETURA.md §3.3).
 *
 * O UUIFrontEndFlowSubsystem dispara a conexão ao ZeusCharServer (WebSocket)
 * ao entrar no estado Boot. Esta tela OBSERVA o UZeusCharServerSubsystem:
 * enquanto não conecta, mostra o spinner e o botão desabilitado; ao conectar,
 * libera o botão "Iniciar" (clique → Flow::RequestEnterLogin → Login).
 * Sem hard-ref de asset de tema (§5): cores vêm do FUIStyle.
 */
UCLASS(Abstract, Blueprintable)
class ZMMO_API UUIBootScreen_Base : public UUIActivatableScreen_Base
{
	GENERATED_BODY()

protected:
	virtual void NativePreConstruct() override;
	virtual void NativeOnActivated() override;
	virtual void NativeOnDeactivated() override;
	virtual void RefreshUIStyle_Implementation() override;

	/** Texto exibido enquanto conecta / quando pronto / em erro. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Boot")
	FText ConnectingText = FText::FromString(TEXT("Conectando ao Gateway"));

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Boot")
	FText ReadyText = FText::FromString(TEXT("Pronto"));

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Boot")
	FText FailedText = FText::FromString(TEXT("Falha ao conectar — tentando novamente"));

	// ---- Widgets do WBP (nomes esperados) ----
	UPROPERTY(meta = (BindWidgetOptional))
	TObjectPtr<UUIButton_Base> Btn_Start;

	UPROPERTY(meta = (BindWidgetOptional))
	TObjectPtr<UUISpinner_Base> Spinner_Connect;

	UPROPERTY(meta = (BindWidgetOptional))
	TObjectPtr<UCommonTextBlock> Text_Status;

	UPROPERTY(meta = (BindWidgetOptional))
	TObjectPtr<UBorder> Border_Bg;

private:
	void SetReady(bool bReady);
	UZeusCharServerSubsystem* GetCharServer() const;

	UFUNCTION()
	void HandleStartClicked();

	UFUNCTION()
	void HandleCharConnected();

	UFUNCTION()
	void HandleCharConnectionFailed(FString Reason);

	bool bCharBound = false;
};
