"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.YfmHeading = exports.YfmHeadingAttr = void 0;
const keymap_1 = require("../../../utils/keymap.js");
const YfmHeadingSpecs_1 = require("./YfmHeadingSpecs/index.js");
const utils_1 = require("./YfmHeadingSpecs/utils.js");
const actions_1 = require("./actions.js");
const commands_1 = require("./commands.js");
const const_1 = require("./const.js");
var const_2 = require("./const.js");
Object.defineProperty(exports, "YfmHeadingAttr", { enumerable: true, get: function () { return const_2.YfmHeadingAttr; } });
/** YfmHeading extension needs markdown-it-attrs plugin */
const YfmHeading = (builder, opts) => {
    builder.use(YfmHeadingSpecs_1.YfmHeadingSpecs, opts);
    builder
        .addKeymap(() => {
        const { h1Key, h2Key, h3Key, h4Key, h5Key, h6Key } = opts ?? {};
        const bindings = { Backspace: commands_1.resetHeading };
        if (h1Key)
            bindings[h1Key] = (0, keymap_1.withLogAction)('heading1', (0, commands_1.toHeading)(1));
        if (h2Key)
            bindings[h2Key] = (0, keymap_1.withLogAction)('heading2', (0, commands_1.toHeading)(2));
        if (h3Key)
            bindings[h3Key] = (0, keymap_1.withLogAction)('heading3', (0, commands_1.toHeading)(3));
        if (h4Key)
            bindings[h4Key] = (0, keymap_1.withLogAction)('heading4', (0, commands_1.toHeading)(4));
        if (h5Key)
            bindings[h5Key] = (0, keymap_1.withLogAction)('heading5', (0, commands_1.toHeading)(5));
        if (h6Key)
            bindings[h6Key] = (0, keymap_1.withLogAction)('heading6', (0, commands_1.toHeading)(6));
        return bindings;
    })
        .addInputRules(({ schema }) => ({ rules: [(0, utils_1.headingRule)((0, utils_1.headingType)(schema), 6)] }));
    builder
        .addAction(const_1.HeadingAction.ToH1, () => (0, actions_1.headingAction)(1))
        .addAction(const_1.HeadingAction.ToH2, () => (0, actions_1.headingAction)(2))
        .addAction(const_1.HeadingAction.ToH3, () => (0, actions_1.headingAction)(3))
        .addAction(const_1.HeadingAction.ToH4, () => (0, actions_1.headingAction)(4))
        .addAction(const_1.HeadingAction.ToH5, () => (0, actions_1.headingAction)(5))
        .addAction(const_1.HeadingAction.ToH6, () => (0, actions_1.headingAction)(6));
};
exports.YfmHeading = YfmHeading;
//# sourceMappingURL=index.js.map
