"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toHeading = exports.resetHeading = void 0;
const prosemirror_commands_1 = require("prosemirror-commands");
// @ts-ignore // TODO: fix cjs build
const prosemirror_utils_1 = require("prosemirror-utils");
const base_1 = require("../../base/index.js");
const utils_1 = require("./YfmHeadingSpecs/utils.js");
const const_1 = require("./const.js");
var commands_1 = require("../../markdown/Heading/commands.js");
Object.defineProperty(exports, "resetHeading", { enumerable: true, get: function () { return commands_1.resetHeading; } });
const toHeading = (level) => (state, dispatch, view) => {
    const attrs = {};
    const parentHeading = (0, prosemirror_utils_1.findParentNodeOfType)((0, utils_1.headingType)(state.schema))(state.selection);
    if (parentHeading) {
        if (parentHeading.node.attrs[const_1.headingLevelAttr] === level) {
            return (0, base_1.toParagraph)(state, dispatch, view);
        }
        Object.assign(attrs, parentHeading.node.attrs);
    }
    // const text = state.selection.$head.parent.textContent;
    // attrs[YfmHeadingAttr.Id] = slugify(text);
    attrs[const_1.YfmHeadingAttr.Level] = level;
    return (0, prosemirror_commands_1.setBlockType)((0, utils_1.headingType)(state.schema), attrs)(state, dispatch);
};
exports.toHeading = toHeading;
//# sourceMappingURL=commands.js.map
