#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"

#include "HyperTwistPauseMenuWidget.generated.h"

class UTextBlock;
class UWidgetSwitcher;
class UHyperTwistSettingsPanelWidget;

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FHyperTwistPauseResumeRequestedSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FHyperTwistPauseMainMenuRequestedSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FHyperTwistPauseQuitRequestedSignature);

UCLASS(BlueprintType, Blueprintable)
class UNREALHYPERTWIST_API UHyperTwistPauseMenuWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	UHyperTwistPauseMenuWidget(const FObjectInitializer& ObjectInitializer);

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Pause")
	bool PreparePauseSurface();

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Pause")
	bool IsPauseSurfaceReady() const;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Pause")
	void SetPuzzleContext(const FString& Title, const FString& Subtitle);

	UPROPERTY(BlueprintAssignable, Category = "HyperTwist|Pause")
	FHyperTwistPauseResumeRequestedSignature OnResumeRequested;

	UPROPERTY(BlueprintAssignable, Category = "HyperTwist|Pause")
	FHyperTwistPauseMainMenuRequestedSignature OnMainMenuRequested;

	UPROPERTY(BlueprintAssignable, Category = "HyperTwist|Pause")
	FHyperTwistPauseQuitRequestedSignature OnQuitRequested;

protected:
	virtual TSharedRef<SWidget> RebuildWidget() override;
	virtual FReply NativeOnKeyDown(
		const FGeometry& InGeometry,
		const FKeyEvent& InKeyEvent
	) override;

private:
	void EnsureWidgetTreeBuilt();

	UFUNCTION()
	void HandleResumeClicked();

	UFUNCTION()
	void HandleSettingsClicked();

	UFUNCTION()
	void HandleSettingsClosed();

	UFUNCTION()
	void HandleMainMenuClicked();

	UFUNCTION()
	void HandleQuitClicked();

	UPROPERTY(Transient)
	TObjectPtr<UWidgetSwitcher> PageSwitcher = nullptr;

	UPROPERTY(Transient)
	TObjectPtr<UTextBlock> PuzzleTitleText = nullptr;

	UPROPERTY(Transient)
	TObjectPtr<UTextBlock> PuzzleSubtitleText = nullptr;

	UPROPERTY(Transient)
	TObjectPtr<UHyperTwistSettingsPanelWidget> SettingsPanel = nullptr;

	FString PuzzleTitle = TEXT("HyperTwist");
	FString PuzzleSubtitle = TEXT("Puzzle paused");
};
