"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSerializerTokens = getSerializerTokens;
const nodes_1 = require("../../../../utils/nodes.js");
const placeholder_1 = require("../../../../utils/placeholder.js");
const const_1 = require("./const.js");
function getSerializerTokens({ directiveSyntax, }) {
    const isDirectiveCut = (node) => {
        return directiveSyntax?.shouldSerializeToDirective('yfmCut', node.attrs[const_1.CutAttr.Markup]);
    };
    return {
        [const_1.CutNode.Cut]: (state, node) => {
            state.renderContent(node);
            state.write(isDirectiveCut(node) ? ':::' : '{% endcut %}');
            state.closeBlock(node);
        },
        [const_1.CutNode.CutTitle]: (state, node, parent) => {
            if (isDirectiveCut(parent)) {
                state.write(':::cut [');
                state.renderInline(node);
                state.write(']');
                state.ensureNewLine();
                state.closeBlock();
                return;
            }
            state.write('{% cut "');
            if (node.nodeSize > 2)
                state.renderInline(node);
            else
                state.write((0, placeholder_1.getPlaceholderContent)(node));
            state.write('" %}\n');
            state.write('\n');
            state.closeBlock();
        },
        [const_1.CutNode.CutContent]: (state, node, parent) => {
            if (isDirectiveCut(parent)) {
                state.renderContent(node);
                return;
            }
            if (!(0, nodes_1.isNodeEmpty)(node))
                state.renderInline(node);
            else
                state.write((0, placeholder_1.getPlaceholderContent)(node) + '\n\n');
        },
    };
}
//# sourceMappingURL=serializer.js.map
