import { UmbTiptapToolbarElementApiBase } from '../tiptap-toolbar-element-api-base.js';
import { UmbLocalizationController } from '../../../../libs/localization-api/index.js';
import { umbOpenModal } from '../../../core/modal/index.js';
import { UMB_CODE_EDITOR_MODAL } from '../../../code-editor/index.js';
export default class UmbTiptapToolbarSourceEditorExtensionApi extends UmbTiptapToolbarElementApiBase {
    #localize = new UmbLocalizationController(this);
    async execute(editor) {
        if (!editor)
            return;
        const data = await umbOpenModal(this, UMB_CODE_EDITOR_MODAL, {
            data: {
                headline: this.#localize.term('tiptap_sourceCodeEdit'),
                content: editor?.getHTML() ?? '',
                language: 'html',
                formatOnLoad: true,
            },
        }).catch(() => undefined);
        if (!data)
            return;
        editor?.commands.setContent(data.content);
    }
}
