/**
 * Copyright 2022-2025 Theai, Inc. dba Inworld AI
 */

#pragma once

#include "CoreMinimal.h"
#include "IDetailCustomization.h"
#include "Input/Reply.h"
#include "Layout/Visibility.h"

class IDetailLayoutBuilder;
class IPropertyHandle;
class UInworldTextEmbeddingAsset;

class INWORLDRUNTIMEEDITOR_API FInworldTextEmbeddingAssetDetailsCustomization : public IDetailCustomization
{
public:
	static TSharedRef<IDetailCustomization> MakeInstance();

	virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override;

private:
	// Determines if editing is enabled based on whether the asset is currently generating embeddings
	bool IsEditingEnabled() const;

	// Gets the visibility of the "working" throbber based on the asset's state
	EVisibility GetThrobberVisibility() const;

	// Handles the button click to start the embedding process
	FReply OnGenerateEmbeddingsClicked();

	// Populates the ConfigIdOptions array for the combobox
	void GenerateConfigIdOptions();

	// Called right before the combobox is opened to refresh the options list.
	void OnComboBoxOpening();

	// Handles the selection change event from the combobox
	void OnConfigIdChanged(TSharedPtr<FString> NewSelection, ESelectInfo::Type SelectInfo);

	// Gets the currently selected ConfigId to display in the combobox
	FText GetSelectedConfigId() const;

	// Generates a tooltip for a given configuration ID
	FText GetConfigIdTooltip(FString ConfigId) const;

	TWeakObjectPtr<UInworldTextEmbeddingAsset> CustomizedAsset;

	TArray<TSharedPtr<FString>> ConfigIdOptions;

	TSharedPtr<IPropertyHandle> SelectedConfigIdHandle;
};
