"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandMenu = void 0;
const markdown_1 = require("../../markdown/index.js");
const yfm_1 = require("../../yfm/index.js");
const logger_1 = require("../../../logger.js");
const Autocomplete_1 = require("../Autocomplete/index.js");
const const_1 = require("./const.js");
const handler_1 = require("./handler.js");
const getCommandMenuAutocompleteItem = (opts, logger) => ({ actions }) => ({
    trigger: {
        name: 'command',
        trigger: /(?:^|\s)(\/)$/,
        allArrowKeys: false,
        cancelOnFirstSpace: true,
        decorationAttrs: { class: const_1.DecoClassName },
    },
    handler: new handler_1.CommandHandler({
        logger,
        storage: actions,
        actions: opts.actions,
        // TODO: add commandMenu=false flag to specs:
        nodesIgnoreList: (opts.nodesIgnoreList ?? []).concat([
            markdown_1.DeflistNode.Term,
            markdown_1.TableNode.HeaderCell,
            markdown_1.TableNode.DataCell,
            yfm_1.CheckboxNode.Label,
            yfm_1.YfmNoteNode.NoteTitle,
            yfm_1.CutNode.CutTitle,
            yfm_1.TabsNode.Tab,
        ]),
    }),
});
const CommandMenu = (builder, opts) => {
    if (!Array.isArray(opts.actions) || opts.actions.length === 0) {
        logger_1.globalLogger.log("[CommandMenu extension]: Skip because 'actions' is not an array or is empty");
        builder.logger.log("[CommandMenu extension]: Skip because 'actions' is not an array or is empty");
        return;
    }
    if (!builder.context.has('autocomplete')) {
        builder.use(Autocomplete_1.Autocomplete);
    }
    builder.context.get('autocomplete').add(getCommandMenuAutocompleteItem(opts, builder.logger));
};
exports.CommandMenu = CommandMenu;
//# sourceMappingURL=index.js.map
