/**
 * Copyright 2022-2025 Theai, Inc. dba Inworld AI
 */
#include "GraphEditor/AssetActions_InworldGraph.h"
#include "InworldRuntimeEditor.h"
#include "Framework/Notifications/NotificationManager.h"
#include "Widgets/Notifications/SNotificationList.h"
#include "GraphEditor/InworldGraphAssetEditor/AssetEditor_InworldGraph.h"

#define LOCTEXT_NAMESPACE "AssetActions_InworldGraph"

FAssetActions_InworldGraph::FAssetActions_InworldGraph(EAssetTypeCategories::Type InAssetCategory)
	: MyAssetCategory(InAssetCategory)
{
}

FText FAssetActions_InworldGraph::GetName() const
{
	return LOCTEXT("FInworldGraphAssetTypeActionsName", "Inworld Graph");
}

FColor FAssetActions_InworldGraph::GetTypeColor() const
{
	return FColor::White;
}

UClass* FAssetActions_InworldGraph::GetSupportedClass() const
{
	return UInworldGraphAsset::StaticClass();
}

void FAssetActions_InworldGraph::OpenAssetEditor(const TArray<UObject*>& InObjects, TSharedPtr<class IToolkitHost> EditWithinLevelEditor)
{
	const EToolkitMode::Type Mode = EditWithinLevelEditor.IsValid() ? EToolkitMode::WorldCentric : EToolkitMode::Standalone;

	for (auto ObjIt = InObjects.CreateConstIterator(); ObjIt; ++ObjIt)
	{
		if (UInworldGraphAsset* Graph = Cast<UInworldGraphAsset>(*ObjIt))
		{
			if (Graph->RuntimeGraph)
			{
				TSharedRef<FAssetEditor_InworldGraph> NewGraphEditor(new FAssetEditor_InworldGraph());
				NewGraphEditor->InitGraphAssetEditor(Mode, EditWithinLevelEditor, Graph);
			}
			else
			{
				FString Msg = FString::Printf(TEXT("RuntimeGraph is not valid for %s."), *Graph->GetName());
				FNotificationInfo Info(FText::FromString(Msg));
				Info.ExpireDuration = 2.0f;
				Info.bUseThrobber = true;
				Info.bUseSuccessFailIcons = true;
				FSlateNotificationManager::Get().AddNotification(Info);
				UE_LOG(LogInworldRuntimeEditor, Error, TEXT("UInworldGraphAsset: %s."), *Msg);
			}
		}
	}
}

uint32 FAssetActions_InworldGraph::GetCategories()
{
	return MyAssetCategory;
}

//////////////////////////////////////////////////////////////////////////

#undef LOCTEXT_NAMESPACE
