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

#include "ComboActionSearchResult.h"

#include "ComboActionGraph.h"
#include "ComboActionSearchUtils.h"
#include "Helpers/ComboActionGraphEditorUtilities.h"

#define LOCTEXT_NAMESPACE "ComboActionSearchResult"


TSharedRef<SWidget> FComboActionSearchResult::CreateIcon() const
{
	const FLinearColor IconColor = FLinearColor::White;
	const FSlateBrush *Brush = nullptr;

	return SNew(SImage)
		.Image(Brush)
		.ColorAndOpacity(IconColor)
		.ToolTipText(GetCategory());
}

TWeakObjectPtr<const UComboActionGraph> FComboActionSearchResult::GetParentDialogue() const
{
	if (this->Parent.IsValid())
	{
		return this->Parent.Pin()->GetParentDialogue();
	}
	return nullptr;
}

#pragma region Search_Actions

TWeakObjectPtr<const UComboActionGraph> FComboActionSearchResult_ActionNode::GetParentDialogue() const
{
	if (this->ComboActionGraph.IsValid())
	{
		return this->ComboActionGraph;
	}
	return FComboActionSearchResult::GetParentDialogue();
}

#pragma endregion 

#pragma region Search_Nodes

FReply FComboActionSearchResult_GraphNode::OnClick(TWeakPtr<FAssetEditor_ComboActionGraph> ActionEditorPtr)
{
	if (this->GraphNode.IsValid())
	{
		return FComboActionGraphEditorUtilities::OpenEditorAndJumpToGraphNode(ActionEditorPtr, this->GraphNode.Get()) ? FReply::Handled() : FReply::Unhandled();
	}
	return FReply::Unhandled();
}

TSharedRef<SWidget> FComboActionSearchResult_GraphNode::CreateIcon() const
{
	if (this->GraphNode.IsValid())
	{
		FLinearColor Color;
		const FSlateIcon Icon = this->GraphNode.Get()->GetIconAndTint(Color);
		return SNew(SImage)
			.Image(Icon.GetOptionalIcon())
			.ColorAndOpacity(Color)
			.ToolTipText(GetCategory());
	}
	
	return FComboActionSearchResult::CreateIcon();
}

#pragma endregion

#undef LOCTEXT_NAMESPACE