#pragma once

#include "CoreMinimal.h"
#include "CoreBaseUserWidget.h"
#include "UObject/NoExportTypes.h"
#include "Templates/SubclassOf.h"
#include "AnalyticsComponent.h"
#include "Input/Events.h"
#include "ColourSelectorWidget.generated.h"

class UCoreButtonWidget;
class UPanelWidget;
class UUniformGridPanel;
class UColourButtonWidget;
class UCorePreConstructableList;

UCLASS(Blueprintable, EditInlineNew)
class UColourSelectorWidget : public UCoreBaseUserWidget
{
	GENERATED_BODY()

protected:
	UPROPERTY(BlueprintReadWrite, meta=(BindWidgetOptional))
	UCoreButtonWidget* RootButton;

	UPROPERTY(BlueprintReadWrite, meta=(BindWidgetOptional))
	UPanelWidget* PaletteContainer;

	UPROPERTY(BlueprintReadWrite, meta=(BindWidgetOptional))
	UUniformGridPanel* ColoursGrid;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	int32 _preConstructedItemsCount;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	int32 _numberOfColumns;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FVector2D _colourImageSize;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	TSubclassOf<UColourButtonWidget> _colourButtonWidgetClass;

private:
	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	UCorePreConstructableList* _coloursList;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess=true))
	FAnalyticsComponent _analytics;

public:
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
	void UpdateRootButtonColour(const FColor& colour);

	UFUNCTION(BlueprintPure=false, BlueprintCallable)
	void UnselectCurrentColour() const;

protected:
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
	void SetPaletteIsVisible(bool isVisible);

public:
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
	void SetColours(const TArray<FColor>& colours, const FColor& selectedColour);

	UFUNCTION(BlueprintCallable)
	void SelectColour(UColourButtonWidget* colourButton);

private:
	UFUNCTION(BlueprintCallable)
	void OnRootButtonPressed(UCoreButtonWidget* button);

	UFUNCTION()
	void OnMouseDownAnywhere(const FPointerEvent& pointerEvent);

	UFUNCTION()
	void OnKeyDownAnywhere(const FKeyEvent& event);

	UFUNCTION(BlueprintCallable)
	void OnColourButtonPressed(UCoreButtonWidget* button);

public:
	UColourSelectorWidget();
};

FORCEINLINE uint32 GetTypeHash(const UColourSelectorWidget) { return 0; }
