import defaultOutputCallout from './defaultOutputCallout';
import ArenaCallout from './ArenaCallout';
const defaultOptions = {
    name: 'callout',
    title: 'Внимание',
    tag: 'ARENA-CALLOUT',
    attributes: {},
    shortcut: 'Alt + KeyC',
    hint: 'c',
    command: 'add-callout',
    component: 'arena-callout',
    componentConstructor: ArenaCallout,
    marks: [
        {
            tag: 'ARENA-CALLOUT',
            attributes: [],
        },
    ],
    output: defaultOutputCallout,
};
const calloutPlugin = (opts) => ({
    register(textarena) {
        const { name, icon, title, tag, attributes, shortcut, hint, command, component, componentConstructor, marks, output, } = Object.assign(Object.assign({}, defaultOptions), (opts || {}));
        if (component && componentConstructor && !customElements.get(component)) {
            customElements.define(component, componentConstructor);
        }
        const paragraph = textarena.getDefaultTextArena();
        if (!paragraph) {
            throw new Error('Default Arena for text not found');
        }
        const allowedArenas = textarena.getSimpleArenas();
        const calloutBodyContainer = textarena.registerArena({
            name: 'callout-body-container',
            tag: 'ARENA-CALLOUT-BODY',
            attributes: {
                slot: 'body',
            },
            hasChildren: true,
            allowedArenas,
            arenaForText: paragraph,
        }, [
            {
                tag: 'ARENA-CALLOUT-BODY',
                attributes: [],
            },
        ], []);
        const arena = textarena.registerArena({
            name,
            tag,
            attributes,
            protectedChildren: [
                paragraph,
                calloutBodyContainer,
            ],
            arenaForText: calloutBodyContainer,
            output,
        }, marks, [textarena.getRootArenaName()]);
        if (command) {
            textarena.registerCommand(command, (ta, selection) => {
                const sel = ta.applyArenaToSelection(selection, arena);
                return sel;
            });
            if (shortcut) {
                textarena.registerShortcut(shortcut, command);
            }
            textarena.registerCreator({
                name,
                icon,
                title,
                shortcut,
                hint,
                command,
                canShow: (node) => textarena.isAllowedNode(node, arena),
            });
        }
    },
});
export default calloutPlugin;
//# sourceMappingURL=calloutPlugin.js.map