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

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

#define LOCTEXT_NAMESPACE "MappingImageSettingsCustomizations"

namespace {
	template<typename T>
	TArray<T*> GetDetailObject(IDetailLayoutBuilder* DetailBuilder){
	}
}

TSharedRef<IPropertyTypeCustomization> FMappingImageSettingsPropertyCustomization::MakeInstance()
{
	return MakeShareable(new FMappingImageSettingsPropertyCustomization());
}

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

	
}

void FMappingImageSettingsPropertyCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle, IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
	bool bIsAggregationPipeline = false;
	TArray<UObject*> OuterObjects;
	StructPropertyHandle->GetOuterObjects( OuterObjects );
	for( auto Outer : OuterObjects )
	{
		if( Outer->IsA<UAggregationPipeline>() )
		{
			bIsAggregationPipeline = true;
			break;
		}
	}

	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 );
		}
	}

	// Hide settings
	if( bIsAggregationPipeline )
	{
		PropertyHandles.FindAndRemoveChecked( GET_MEMBER_NAME_CHECKED( FMappingImageSettings, TexCoordGeneratorType ) );
	}

	IDetailGroup& MappingImageSettingsGroup =
	    ChildBuilder.AddGroup( StructPropertyHandle->GetProperty()->GetFName(), StructPropertyHandle->GetPropertyDisplayName() );

	for( auto Iter( PropertyHandles.CreateConstIterator() ); Iter; ++Iter )
	{
		IDetailPropertyRow& SettingsRow = MappingImageSettingsGroup.AddPropertyRow( Iter.Value().ToSharedRef() );
	}
}

FMappingImageSettingsPropertyCustomization::FMappingImageSettingsPropertyCustomization()
{

}

#undef LOCTEXT_NAMESPACE
