#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "EnhancedInputComponent.h"
#include "LuprexUserWidget.generated.h"

UCLASS(BlueprintType, Blueprintable)
class INTEGRATION_API UlxUserWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	using EventBinding = TUniquePtr<FEnhancedInputActionEventBinding>;

	UlxUserWidget(const FObjectInitializer& ObjectInitializer);

	virtual void NativeOnInitialized() override;

	// Clone every enhanced-input action binding currently on InputComponent
	// into SavedEnhancedActionEventBindings, so bindings can later be removed
	// from the component and reinstated without losing their delegates.
	void BackupInputComponent();

	// Removes all handlers for 'InputAction'.  That includes temporarily
	// deactivating event graph nodes that handle 'InputAction'.
	UFUNCTION(BlueprintCallable, Category="Luprex|Widget Enhanced Input")
	void DisableInputAction(const UInputAction* InputAction);

	// Reactivates any graph nodes that handle 'InputAction', and
	// removes any other handlers for 'InputAction'.
	UFUNCTION(BlueprintCallable, Category="Luprex|Widget Enhanced Input")
	void RestoreInputAction(const UInputAction* InputAction);

	// Any event graph nodes that handle 'to' are made to also
	// handle 'From' events.  Any other handlers of 'From' are removed.
	UFUNCTION(BlueprintCallable, Category="Luprex|Widget Enhanced Input")
	void RedirectInputAction(const UInputAction* From, const UInputAction* To);

	// Cloned bindings captured from InputComponent after construction.
	TArray<EventBinding> SavedEnhancedActionEventBindings;

private:
	// Strip the synthetic const off UEnhancedInputComponent::GetActionEventBindings
	// to get direct mutable access to the protected array. Well-defined because
	// the underlying object is not const; only the getter's return type is.
	static TArray<EventBinding>& GetMutableActionEventBindings(UEnhancedInputComponent* EIC);
};
