import { UmbTiptapToolbarElementApiBase } from '../tiptap-toolbar-element-api-base.js';
import { UMB_TIPTAP_CHARACTER_MAP_MODAL } from './modals/index.js';
import { UMB_MODAL_MANAGER_CONTEXT } from '../../../core/modal/index.js';
export default class UmbTiptapToolbarCharacterMapExtensionApi extends UmbTiptapToolbarElementApiBase {
    async execute(editor) {
        if (!editor)
            return;
        const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
        if (!modalManager)
            throw new Error('Modal manager not found');
        const modal = modalManager.open(this, UMB_TIPTAP_CHARACTER_MAP_MODAL);
        if (!modal)
            return;
        const data = await modal.onSubmit().catch(() => undefined);
        if (!data)
            return;
        editor?.chain().focus().insertContent(data).run();
    }
}
