#pragma once

#include "CoreMinimal.h"
#include "HyperTwistUX/HyperTwistPlayerControllerBase.h"
#include "HyperTwistMelindaProjectionPlayerController.generated.h"

class AHyperTwistMelindaProjectionActor;
class UHyperTwistFourDimensionalHUDWidget;

UCLASS(BlueprintType, Blueprintable)
class UNREALHYPERTWIST_API AHyperTwistMelindaProjectionPlayerController
	: public AHyperTwistPlayerControllerBase
{
	GENERATED_BODY()

public:
	AHyperTwistMelindaProjectionPlayerController();

	virtual void BeginPlay() override;
	virtual void SetupInputComponent() override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|Input")
	bool bUseGameAndUiInputMode = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|Input")
	bool bEnableCounterClockwiseRightClick = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|Input")
	bool bEnableTouchTurnInput = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|Input")
	bool bBindResetShortcut = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|Input")
	bool bBindRandomizeShortcut = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|Input")
	int32 NextRandomSeed = 2027;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|HUD")
	bool bShowPuzzleHud = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|HUD")
	int32 PuzzleHudZOrder = 120;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|Melinda|HUD")
	TSubclassOf<UHyperTwistFourDimensionalHUDWidget> PuzzleHudWidgetClass;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "HyperTwist|Melinda|HUD")
	TObjectPtr<UHyperTwistFourDimensionalHUDWidget> ActivePuzzleHudWidget = nullptr;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Melinda|Input")
	bool TryProcessProjectionClickFromCursor(bool bCounterClockwise = false);

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Melinda|Input")
	bool TryProcessProjectionClickFromScreenPosition(
		const FVector2D& ScreenPosition,
		bool bCounterClockwise = false
	);

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Melinda|Input")
	void ResetProjectionToSolved();

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Melinda|Input")
	bool GenerateProjectionRandomState();

protected:
	virtual FString GetPauseMenuTitle() const override;
	virtual FString GetPauseMenuSubtitle() const override;
	void ApplyInputMode();
	bool ShowPuzzleHud();
	void RefreshPuzzleHud();
	AHyperTwistMelindaProjectionActor* ResolveProjectionActor() const;
	void HandlePrimaryClick();
	void HandleSecondaryClick();
	void HandleResetShortcut();
	void HandleRandomizeShortcut();
	void HandleSaveShortcut();
	void HandleLoadShortcut();
	void HandleTouchPressed(ETouchIndex::Type FingerIndex, FVector Location);

	UFUNCTION()
	void HandleHudScramble();

	UFUNCTION()
	void HandleHudReset();

	UFUNCTION()
	void HandleHudSave();

	UFUNCTION()
	void HandleHudLoad();
};
