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

#pragma once

#include "CoreMinimal.h"
#include "IDetailCustomization.h"
#include "IPropertyTypeCustomization.h"
#include "PropertyHandle.h"
#include "Layout/Visibility.h"
#include "Algo/AnyOf.h"

class FCustomizationHelpers
{
public:
	template<typename TObject>
	static TArray<TObject*> GetObjectBeingCustomized(IDetailLayoutBuilder* DetailBuilder)
	{
		TArray<TWeakObjectPtr<UObject>> ObjectsBeingCustomized;
		DetailBuilder->GetObjectsBeingCustomized(ObjectsBeingCustomized);
		TArray<TObject*> Result;
		for (TWeakObjectPtr<UObject> Obj : ObjectsBeingCustomized)
		{
			if (Obj.IsValid())
			{
				TObject* ObjTemp = Cast<TObject>(Obj.Get());
				if (ObjTemp)
					Result.Add(ObjTemp);
			}
		}
		return Result;
	}

	static void HideCategories(IDetailLayoutBuilder& DetailBuilder, const TArray<FName>& CategoriesToHide)
	{
		TArray<FName> OutCategoryNames;
		DetailBuilder.GetCategoryNames(OutCategoryNames);

		for (const FName& CategoryName : OutCategoryNames)
		{
			bool HideCategory = Algo::AnyOf(CategoriesToHide, [CategoryName](const FName& CatName) { return CatName.IsEqual(CategoryName); });
			if (HideCategory)
				DetailBuilder.HideCategory(CategoryName);

		}
	}
};
