import { UmbExtensionInitializerBase, loadManifestPlainJs, hasInitExport, hasOnUnloadExport, } from '../../../../libs/extension-api/index.js';
/**
 * Extension initializer for the `appEntryPoint` extension type
 */
export class UmbAppEntryPointExtensionInitializer extends UmbExtensionInitializerBase {
    #instanceMap = new Map();
    constructor(host, extensionRegistry) {
        super(host, extensionRegistry, 'appEntryPoint');
    }
    async instantiateExtension(manifest) {
        if (manifest.js) {
            const moduleInstance = await loadManifestPlainJs(manifest.js);
            if (!moduleInstance)
                return;
            this.#instanceMap.set(manifest.alias, moduleInstance);
            // If the extension has known exports, be sure to run those
            if (hasInitExport(moduleInstance)) {
                await moduleInstance.onInit(this.host, this.extensionRegistry);
            }
        }
    }
    async unloadExtension(manifest) {
        const moduleInstance = this.#instanceMap.get(manifest.alias);
        if (!moduleInstance)
            return;
        if (hasOnUnloadExport(moduleInstance)) {
            moduleInstance.onUnload(this.host, this.extensionRegistry);
        }
        this.#instanceMap.delete(manifest.alias);
    }
}
