#pragma once

#include "CoreMinimal.h"
#include "CoreButtonSelector.h"
#include "Templates/SubclassOf.h"
#include "Layout/Margin.h"
#include "CorePaginationContainerWidget.generated.h"

class UCoreSelectableButtonWidget;
class UGridPanel;
class UDBDTextBlock;

UCLASS(Blueprintable, EditInlineNew)
class UCorePaginationContainerWidget : public UCoreButtonSelector
{
	GENERATED_BODY()

public:
	DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnSelectedPageDelegate, int32, selectedPage, bool, isUpdate);

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintAssignable)
	FOnSelectedPageDelegate OnSelectedPageDelegate;

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	TSubclassOf<UCoreSelectableButtonWidget> PaginationWidgetClass;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	int32 MaxNumberOfPages;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	bool CanLoop;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	bool ShowPageNumbers;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	FMargin WidgetPadding;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	int32 PreviewSelectedPageIndex;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, NoClear)
	int32 PreviewNumberOfPages;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidgetOptional))
	UGridPanel* PaginationContainer;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidgetOptional))
	UCoreSelectableButtonWidget* FirstPage;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidgetOptional))
	UDBDTextBlock* FirstEllipsis;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidgetOptional))
	UDBDTextBlock* LastEllipsis;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(BindWidgetOptional))
	UCoreSelectableButtonWidget* LastPage;

private:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Export, meta=(AllowPrivateAccess=true))
	TArray<UCoreSelectableButtonWidget*> _paginationWidgetList;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, Export, meta=(AllowPrivateAccess=true))
	TMap<int32, UCoreSelectableButtonWidget*> _pageWidgetMap;

public:
	UFUNCTION(BlueprintCallable)
	void UpdateSelectedWidget(int32 currentIndex, int32 numberOfPages);

private:
	UFUNCTION(BlueprintCallable)
	void OnPaginationSelected(UCoreSelectableButtonWidget* selectedButton);

public:
	UFUNCTION(BlueprintPure)
	int32 GetNumberOfPages() const;

	UFUNCTION(BlueprintPure)
	int32 GetCurrentPage() const;

protected:
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
	UCoreSelectableButtonWidget* CreatePaginationWidget(int32 index);

public:
	UCorePaginationContainerWidget();
};

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