const defaultOptions = {
    h2: {
        name: 'header2',
        tag: 'H2',
        attributes: {},
        title: 'Header 2',
        icon: '<b>H2</b>',
        command: 'convert-to-header2',
        shortcut: 'Alt + Digit2',
        hint: '2',
        marks: [
            {
                tag: 'H2',
                attributes: [],
            },
        ],
    },
    h3: {
        name: 'header3',
        tag: 'H3',
        attributes: {},
        title: 'Header 3',
        icon: '<b>H3</b>',
        command: 'convert-to-header3',
        shortcut: 'Alt + Digit3',
        hint: '3',
        marks: [
            {
                tag: 'H3',
                attributes: [],
            },
        ],
    },
    h4: {
        name: 'header4',
        tag: 'H4',
        attributes: {},
        title: 'Header 4',
        icon: '<b>H4</b>',
        command: 'convert-to-header4',
        shortcut: 'Alt + Digit4',
        hint: '4',
        marks: [
            {
                tag: 'H4',
                attributes: [],
            },
        ],
    },
};
const headersPlugin = (opts) => ({
    register(textarena) {
        const paragraph = textarena.getDefaultTextArena();
        if (!paragraph) {
            throw new Error('Default Arena for text not found');
        }
        Object.entries(opts || defaultOptions).forEach(([type, options]) => {
            const { name, tag, attributes, title, icon, shortcut, hint, command, marks, } = defaultOptions[type] ? Object.assign(Object.assign({}, defaultOptions[type]), options) : options;
            if (name && tag && attributes) {
                const arena = textarena.registerArena({
                    name,
                    tag,
                    attributes,
                    hasText: true,
                    nextArena: paragraph,
                }, marks, [textarena.getRootArenaName()]);
                if (command) {
                    textarena.registerCommand(command, (ta, selection) => ta.applyArenaToSelection(selection, arena));
                    if (shortcut) {
                        textarena.registerShortcut(shortcut, command);
                    }
                    if (title && icon) {
                        textarena.registerTool({
                            name,
                            title,
                            icon,
                            shortcut,
                            hint,
                            command,
                            checkStatus: (node) => node.arena === arena,
                        });
                    }
                    if (title) {
                        textarena.registerCreator({
                            name,
                            title,
                            icon,
                            shortcut,
                            hint,
                            command,
                            canShow: (node) => textarena.isAllowedNode(node, arena),
                        });
                    }
                }
            }
        });
    },
});
export default headersPlugin;
//# sourceMappingURL=headersPlugin.js.map