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

#pragma once

#include "CoreMinimal.h"
#include "Misc/Attribute.h"
#include "Layout/Visibility.h"
#include "Widgets/SWidget.h"
#include "IDetailCustomization.h"
#include "Input/Reply.h"

class FLODRecipeDetailsCustomization : public IDetailCustomization
{
public:
	static TSharedRef<IDetailCustomization> MakeInstance();

	// IDetailCustomization interface
	virtual void CustomizeDetails(IDetailLayoutBuilder& DetailLayout) override;
	// End of IDetailCustomization interface

protected:
	FLODRecipeDetailsCustomization();

	void GenerateStaticMeshesWidget(TSharedRef<IPropertyHandle> PropertyHandle, int32 ArrayIndex, IDetailChildrenBuilder& ChildrenBuilder, class ULODRecipe* LODRecipe);
	void GenerateSkeletalMeshesWidget(TSharedRef<IPropertyHandle> PropertyHandle, int32 ArrayIndex, IDetailChildrenBuilder& ChildrenBuilder, class ULODRecipe* LODRecipe);
	void GeneratePerLODPipelineWidget(TSharedRef<IPropertyHandle> PropertyHandle, int32 ArrayIndex, IDetailChildrenBuilder& ChildrenBuilder, class ULODRecipe* LODRecipe);
	
	TSharedRef<SWidget> GenerateStreamedLODsWidget(FName PlatformGroupName, class ULODRecipe* LODRecipe) const;
	bool AddStreamedLODsPlatform(FName PlatformGroupName, class ULODRecipe* LODRecipe);
	bool RemoveStreamedLODsPlatform(FName PlatformGroupName, class ULODRecipe* LODRecipe);
	TArray<FName> GetStreamedLODsPlatformOverrideNames(class ULODRecipe* LODRecipe) const;
	int32 GetNumStreamedLODs(FName Platform, class ULODRecipe* LODRecipe) const;
	void OnNumStreamedLODsChanged(int32 NewValue, FName Platform, class ULODRecipe* LODRecipe);
	void OnNumStreamedLODsCommited(int32 InValue, ETextCommit::Type CommitInfo, FName Platform, class ULODRecipe* LODRecipe);
	void SetNumStreamedLODsValue(int32 NewValue, FName Platform, ULODRecipe* LODRecipe);
	
	void GenerateMeshArrayItem(TSharedRef<IPropertyHandle> PropertyHandle, IDetailChildrenBuilder& ChildrenBuilder, TSharedRef<SWidget> RemoveButton);

	void OnRemoveStaticMesh(ULODRecipe* LODRecipe, const int32 MeshIndex);
	void OnRemoveSkeletalMesh(ULODRecipe* LODRecipe, const int32 MeshIndex);

	void UpdateLODSettingsVisibiility();
	EVisibility IsLODSettingsVisibile(const int32 LODIndex) const;

	void OnNumLODsChanged();

	FReply ApplyStreamedLODs(ULODRecipe* LODRecipe);

private:
	TArray<EVisibility> SettingsVisibility;
	TSharedPtr<IPropertyHandle> StaticMeshesHandle; 
	TSharedPtr<IPropertyHandle> SkeletalMeshesHandle;
	TSharedPtr<IPropertyHandle> PipelineSettingsHandle;
	TSharedPtr<IPropertyHandle> MiscSettingsHandle;
	TSharedPtr<IPropertyHandle> NumLODsHandle;
	TSharedPtr<IPropertyHandle> NumStreamedLODsHandle;

	class IDetailLayoutBuilder* Builder;
};
