#pragma once

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

class AHyperTwistClassicCubeActor;

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

public:
	AHyperTwistClassicCubePlayerController();

	virtual void BeginPlay() override;
	virtual void SetupInputComponent() override;
	virtual bool InputKey(const FInputKeyEventArgs& Params) override;

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

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

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

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Input")
	bool bBindFreshAttemptShortcut = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Input")
	bool bBindHintShortcut = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Input")
	bool bBindSubmitSolveShortcut = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Input")
	bool bBindModeToggleShortcut = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Input")
	bool bBindVoiceHoldShortcut = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist|ClassicCube|Input")
	bool bBindVoiceCycleShortcut = false;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|ClassicCube|Input")
	bool TryProcessCubeClickFromCursor(bool bCounterClockwise = false);

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

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|ClassicCube|Input")
	void RequestFreshAttempt();

protected:
	virtual FString GetPauseMenuTitle() const override;
	virtual FString GetPauseMenuSubtitle() const override;
	virtual void PrepareForModalUi() override;
	void ApplyClassicCubeInputMode();
	AHyperTwistClassicCubeActor* ResolveClassicCubeActor() const;
	void HandlePrimaryClick();
	void HandleSecondaryClick();
	void HandleFreshAttemptShortcut();
	void HandleHintShortcut();
	void HandleSubmitSolveShortcut();
	void HandleModeToggleShortcut();
	void HandleVoicePressed();
	void HandleVoiceReleased();
	void HandleVoiceCycleShortcut();
	void HandleTouchPressed(ETouchIndex::Type FingerIndex, FVector Location);
	bool TryApplyKeyboardPuzzleMove(const FInputKeyEventArgs& Params);

	bool bToggleVoiceCaptureActive = false;
};
