// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.

#pragma once

#include "CoreMinimal.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SCompoundWidget.h"

class FMorpTargetItem
{
public:
	FMorpTargetItem() = default;
	FMorpTargetItem(class UMorphTarget* InMorphTarget, class ULODRecipe* InLODRecipeBeingEdited);

	TWeakObjectPtr<class UMorphTarget> MorphTarget;
	TWeakObjectPtr<class ULODRecipe> LODRecipeBeingEdited;
};
typedef TSharedPtr<FMorpTargetItem> FMorpTargetItemPtr;

class SAllowMorphTargetsList : public SCompoundWidget
{
	SLATE_BEGIN_ARGS(SAllowMorphTargetsList)
	{
	}

	SLATE_END_ARGS()

	/** Widget constructor */
	void Construct(const FArguments& Args, const TSharedRef<class SAllowMorphTargetsWidget> Owner);
	~SAllowMorphTargetsList();

	void Refresh();

private:
	void RebuildMorphTargetList();
	EActiveTimerReturnType TriggerRebuildMorphTargetList(double InCurrentTime, float InDeltaTime);

	TSharedRef<ITableRow> OnGenerateRow(FMorpTargetItemPtr Item, const TSharedRef<STableViewBase>& OwnerTable);

	void OnPropertyChanged(UObject* ObjectBeingModified, FPropertyChangedEvent& PropertyChangedEvent);
	void RefreshColumns(); 
	void RefreshMainContent();
private:
	TWeakPtr<class SAllowMorphTargetsWidget> OwnerWidget;

	TSharedPtr<SListView<FMorpTargetItemPtr>> MorphTargetListView;
	TArray<FMorpTargetItemPtr> MorphTargetListItems;

	TSharedPtr<SHeaderRow> ListHeaders;
	TSharedPtr<SVerticalBox> MainContent;

	/** Whether the active timer to refresh the list is registered */
	bool bIsActiveTimerRegistered;

	FDelegateHandle OnPropertyChangedDelegateHandle;
};