import { UMB_MODAL_MANAGER_CONTEXT } from '../context/modal-manager.context.js';
import { UmbControllerBase } from '../../../../libs/class-api/index.js';
export class UmbOpenModalController extends UmbControllerBase {
    async open(modalAlias, args = {}) {
        const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
        if (!modalManagerContext) {
            this.destroy();
            throw new Error('Modal manager not found.');
        }
        const modalContext = modalManagerContext.open(this, modalAlias, args);
        return await modalContext.onSubmit();
    }
}
/**
 *
 * @param host {UmbControllerHost} - The host controller
 * @param modalAlias
 * @param args {UmbConfirmModalArgs} - The data to pass to the modal
 * @returns {UmbConfirmModalController} The modal controller instance
 */
export function umbOpenModal(host, modalAlias, args = {}) {
    return new UmbOpenModalController(host).open(modalAlias, args);
}
