import { CheckboxAttr, CheckboxNode } from "../const.js";
import { CHECKBOX_CLOSE_TOKEN, CHECKBOX_OPEN_TOKEN } from "./const.js";
const getCheckboxAttrs = (token, tokens, index) => {
    const tight = checkboxIsTight(tokens, index);
    const attrs = token.attrs ? Object.fromEntries(token.attrs) : {};
    return { ...attrs, [CheckboxAttr.Tight]: tight };
};
const getAttrs = (tok) => (tok.attrs ? Object.fromEntries(tok.attrs) : {});
export const parserTokens = {
    [CheckboxNode.Checkbox]: {
        name: CheckboxNode.Checkbox,
        type: 'block',
        getAttrs: getCheckboxAttrs,
    },
    [CheckboxNode.Input]: { name: CheckboxNode.Input, type: 'node', getAttrs },
    [CheckboxNode.Label]: { name: 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 === CHECKBOX_CLOSE_TOKEN) {
            closeTokenEndLine = tokens[i].map?.[1];
            if (tokens[i + 1]?.type === 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
