import { umbExtensionsRegistry } from '../../../extension-registry/index.js';
import { UMB_ACTION_EVENT_CONTEXT } from '../../../action/index.js';
import { UmbEntityActionBase, UmbRequestReloadStructureForEntityEvent } from '../../../entity-action/index.js';
import { umbConfirmModal } from '../../../modal/index.js';
import { html } from '../../../../../external/lit/index.js';
export class UmbUnregisterExtensionEntityAction extends UmbEntityActionBase {
    async execute() {
        if (!this.args.unique)
            throw new Error('Cannot delete an item without a unique identifier.');
        const extension = umbExtensionsRegistry.getByAlias(this.args.unique);
        if (!extension)
            throw new Error('Extension not found');
        await umbConfirmModal(this, {
            headline: 'Unregister extension',
            confirmLabel: 'Unregister',
            content: html `<p>Are you sure you want to unregister the extension <strong>${extension.alias}</strong>?</p>`,
            color: 'danger',
        });
        umbExtensionsRegistry.unregister(extension.alias);
        const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
        if (!actionEventContext) {
            throw new Error('Action event context not found');
        }
        const event = new UmbRequestReloadStructureForEntityEvent({
            unique: this.args.unique,
            entityType: this.args.entityType,
        });
        actionEventContext.dispatchEvent(event);
    }
}
export { UmbUnregisterExtensionEntityAction as api };
