import { UmbControllerBase } from '../../../../../libs/class-api/index.js';
import { createExtensionApi } from '../../../../../libs/extension-api/index.js';
import { umbExtensionsRegistry } from '../../../../core/extension-registry/index.js';
export class UmbClipboardCopyPropertyValueTranslatorValueResolver extends UmbControllerBase {
    async resolve(propertyValue, propertyEditorUiAlias) {
        if (!propertyValue) {
            throw new Error('Property value is required.');
        }
        if (!propertyEditorUiAlias) {
            throw new Error('Property editor UI alias is required.');
        }
        const manifests = umbExtensionsRegistry.getByTypeAndFilter('clipboardCopyPropertyValueTranslator', (x) => x.fromPropertyEditorUi === propertyEditorUiAlias);
        if (!manifests.length) {
            throw new Error('No clipboard copy translators found.');
        }
        // Create translators
        const apiPromises = manifests.map((manifest) => createExtensionApi(this, manifest).then((api) => {
            if (api) {
                api.manifest = manifest;
            }
            return api;
        }));
        const apis = await Promise.all(apiPromises);
        // Translate values
        const valuePromises = apis.map(async (api) => api?.translate(propertyValue));
        const translatedValues = await Promise.all(valuePromises);
        // Map to clipboard entry value models with entry type and value
        const entryValues = translatedValues.map((value, index) => {
            const valueType = manifests[index].toClipboardEntryValueType;
            return { type: valueType, value };
        });
        return entryValues;
    }
}
