#pragma once

#include "CoreMinimal.h"
#include "WingServer.h"
#include "WingHandler.h"
#include "WingWidgets.h"
#include "Widget_SearchTypes.generated.h"


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

UCLASS()
class UWing_Widget_SearchTypes : public UWingHandler
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, meta=(Description="Query string, can contain *"))
	FString Query;

	UPROPERTY(meta=(Optional, Description="Maximum number of results (default 50)"))
	int32 MaxResults = 50;

	virtual void Register() override
	{
		UWingServer::AddHandler(this,
			TEXT("Search for widget types that can be added to a Widget Blueprint. "
			"Returns names for use with Widget_Create."));
	}
	virtual void Handle() override
	{
		WingWidgets Widgets;
		TArray<WingWidgets::Type> Results = Widgets.Search(Query, MaxResults, false);
		for (const WingWidgets::Type& Entry : Results)
		{
			UWingServer::Printf(TEXT("%s\n"), *Entry.MenuName);
		}

		if (Results.Num() == 0)
		{
			UWingServer::Print(TEXT("No matching widget types found.\n"));
		}
		else if (Results.Num() >= MaxResults)
		{
			UWingServer::Printf(TEXT("WARNING: Reached limit of %d results. You may specify MaxResults.\n"), MaxResults);
		}
	}
};
