"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parserTokens = void 0;
const const_1 = require("../const.js");
const const_2 = require("./const.js");
const getCheckboxAttrs = (token, tokens, index) => {
    const tight = checkboxIsTight(tokens, index);
    const attrs = token.attrs ? Object.fromEntries(token.attrs) : {};
    return { ...attrs, [const_1.CheckboxAttr.Tight]: tight };
};
const getAttrs = (tok) => (tok.attrs ? Object.fromEntries(tok.attrs) : {});
exports.parserTokens = {
    [const_1.CheckboxNode.Checkbox]: {
        name: const_1.CheckboxNode.Checkbox,
        type: 'block',
        getAttrs: getCheckboxAttrs,
    },
    [const_1.CheckboxNode.Input]: { name: const_1.CheckboxNode.Input, type: 'node', getAttrs },
    [const_1.CheckboxNode.Label]: { name: const_1.CheckboxNode.Label, type: 'block', getAttrs },
};
function checkboxIsTight(tokens, index) {
    let closeTokenEndLine;
    let nextOpenTokenStartLine;
    for (let i = index + 1; i < tokens.length; i++) {
        if (tokens[i].type === const_2.CHECKBOX_CLOSE_TOKEN) {
            closeTokenEndLine = tokens[i].map?.[1];
            if (tokens[i + 1]?.type === const_2.CHECKBOX_OPEN_TOKEN) {
                nextOpenTokenStartLine = tokens[i + 1].map?.[0];
            }
            break;
        }
    }
    if (!Number.isFinite(closeTokenEndLine) || !Number.isFinite(nextOpenTokenStartLine))
        return null;
    return closeTokenEndLine === nextOpenTokenStartLine;
}
//# sourceMappingURL=parser.js.map
