const posibleTags = ['h1', 'h2', 'h3', 'h4'];
const defaultOptions = {
    tags: ['h2', 'h3', 'h4'],
};
const headersPlugin = (opts) => ({
    register(textarena) {
        const options = Object.assign(Object.assign({}, defaultOptions), (opts || {}));
        options.tags.forEach((type) => {
            if (posibleTags.includes(type)) {
                const number = parseInt(type[1], 10);
                const paragraph = textarena.getDefaultTextArena();
                if (!paragraph) {
                    throw new Error('Default Arena for text not found');
                }
                const arena = textarena.registerArena({
                    name: `header${number}`,
                    tag: `H${number}`,
                    attributes: [],
                    hasText: true,
                    nextArena: paragraph,
                }, [
                    {
                        tag: `H${number}`,
                        attributes: [],
                    },
                ], [textarena.getRootArenaName()]);
                textarena.registerCommand(`convert-to-header${number}`, (ta, selection) => ta.applyArenaToSelection(selection, arena));
                textarena.registerShortcut(`Alt + Digit${number}`, `convert-to-header${number}`);
                textarena.registerTool({
                    name: `header${number}`,
                    title: `Header ${number}`,
                    icon: `<b>H${number}</b>`,
                    shortcut: `Alt + Digit${number}`,
                    hint: number.toString(),
                    command: `convert-to-header${number}`,
                    checkStatus: (node) => node.arena === arena,
                });
                textarena.registerCreator({
                    name: `header${number}`,
                    title: `Header ${number}`,
                    icon: `<b>H${number}</b>`,
                    shortcut: `Alt + Digit${number}`,
                    hint: number.toString(),
                    command: `convert-to-header${number}`,
                    canShow: (node) => node.parent.isAllowedNode(arena),
                });
            }
        });
    },
});
export default headersPlugin;
//# sourceMappingURL=headersPlugin.js.map