// ©2023 Batty Bovine Productions, LLC. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

#include "ComboInputAssets.h"
#include "Ed/EdComboActionGraphNode.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Nodes/ComboActionGraphNode.h"
#include "Nodes/ComboActionGraphNode_ActionNodeBase.h"
#include "Settings/ComboActionGraphEditorSettings.h"

#include "ComboActionEditorBFC.generated.h"


/**
 * Editor Only helper functions.
 */
UCLASS()
class UComboActionEditorBFC : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
public:

#if WITH_EDITOR
	static FText GetNodeTitle(UComboActionGraphNode *Node)
	{
		if (!Node)
		{
			return FText::FromString("Invalid Node");
		}

		const UComboActionGraphEditorSettings *Settings = GetDefault<UComboActionGraphEditorSettings>();
		if (Settings)
		{
			if (Settings->ShowAutomaticNames())
			{
				if (const UComboActionGraphNode_ActionNodeBase *DialogueNodeBase = Cast<UComboActionGraphNode_ActionNodeBase>(Node))
				{
					if (const UComboInputAsset *ComboInput = DialogueNodeBase->GetComboInput())
					{
						return FText::FromString(ComboInput->GetName());
					}
				}

				return Node->GetInternalName();
			}
		}
		
		return Node->GetNodeTitle();
	}

	static EComboActionNodeTheme GetNodeTheme()
	{
		const UComboActionGraphEditorSettings *Settings = GetDefault<UComboActionGraphEditorSettings>();
		if (Settings != nullptr)
		{
			return Settings->GetNodeTheme();
		}

		return EComboActionNodeTheme::DarkTheme;
	}

	static void TriggerPreviewRefresh(TArray<UObject*> NodeObjects)
	{
		for (auto Itr : NodeObjects)
		{
			UEdComboActionGraphNode *SelectedNode = Cast<UEdComboActionGraphNode>(Itr);
			if (!SelectedNode || !SelectedNode->ComboActionGraphNode)
			{
				continue;
			}

			UComboActionGraphNode_ActionNodeBase *DialogueNodeBase = Cast<UComboActionGraphNode_ActionNodeBase>(SelectedNode->ComboActionGraphNode);
			if (!DialogueNodeBase)
			{
				continue;
			}

			DialogueNodeBase->UpdatePreviews();
		}
	}
#endif
	
};
