// Copyright (c) Microsoft Corporation. 
// Licensed under the MIT license.
#ifdef IMPOSTER_BAKER
#include "ImpostorFromSingleViewCustomizations.h"
#include "SimplygonCustomPipelines.h"
#include "CustomizationHelper.h"

#include "PropertyHandle.h"
#include "DetailLayoutBuilder.h"
#include "DetailCategoryBuilder.h"
#include "DetailWidgetRow.h"
#include "PropertyCustomizationHelpers.h"
#include "IDetailChildrenBuilder.h"
#include "IDetailPropertyRow.h"

//////// Detail Customization
FImpostorFromSingleViewCustomization::FImpostorFromSingleViewCustomization()

{
}

TSharedRef<IDetailCustomization> FImpostorFromSingleViewCustomization::MakeInstance()
{
	return MakeShareable(new FImpostorFromSingleViewCustomization());
}

void FImpostorFromSingleViewCustomization::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{

	FCustomizationHelpers::HideCategories(DetailBuilder, CategoriesToHide);
	
}


/////////// Property
TSharedRef<IPropertyTypeCustomization> FImpostorFromSingleViewPropertyCustomization::MakeInstance()
{
	return MakeShareable(new FImpostorFromSingleViewPropertyCustomization());
}

void FImpostorFromSingleViewPropertyCustomization::CustomizeHeader(TSharedRef<IPropertyHandle> StructPropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{

}

void FImpostorFromSingleViewPropertyCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle, IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
	// Retrieve structure's child properties
	uint32 NumChildren;
	StructPropertyHandle->GetNumChildren(NumChildren);
	TMap<FName, TSharedPtr< IPropertyHandle > > PropertyHandles;
	for (uint32 ChildIndex = 0; ChildIndex < NumChildren; ++ChildIndex)
	{
		TSharedRef<IPropertyHandle> ChildHandle = StructPropertyHandle->GetChildHandle(ChildIndex).ToSharedRef();
		FProperty* Property = ChildHandle->GetProperty();
		if (Property)
		{
			const FName PropertyName = ChildHandle->GetProperty()->GetFName();
			PropertyHandles.Add(PropertyName, ChildHandle);
		}
	}
		
	for (auto Iter(PropertyHandles.CreateConstIterator()); Iter; ++Iter)
	{
		IDetailPropertyRow& SettingsRow = ChildBuilder.AddProperty(Iter.Value().ToSharedRef());
	}

}

FImpostorFromSingleViewPropertyCustomization::FImpostorFromSingleViewPropertyCustomization()
{
}
#endif