"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConditionalFormattingXform = void 0;
const composite_xform_1 = require("../../composite-xform.js");
const cf_rule_xform_1 = require("./cf-rule-xform.js");
class ConditionalFormattingXform extends composite_xform_1.CompositeXform {
    constructor() {
        super();
        this.map = {
            cfRule: new cf_rule_xform_1.CfRuleXform()
        };
    }
    get tag() {
        return "conditionalFormatting";
    }
    render(xmlStream, model) {
        // if there are no primitive rules, exit now
        if (!model.rules.some(cf_rule_xform_1.CfRuleXform.isPrimitive)) {
            return;
        }
        xmlStream.openNode(this.tag, { sqref: model.ref });
        model.rules.forEach((rule) => {
            if (cf_rule_xform_1.CfRuleXform.isPrimitive(rule)) {
                rule.ref = model.ref;
                this.map.cfRule.render(xmlStream, rule);
            }
        });
        xmlStream.closeNode();
    }
    createNewModel({ attributes }) {
        return {
            ref: attributes.sqref,
            rules: []
        };
    }
    onParserClose(name, parser) {
        this.model.rules.push(parser.model);
    }
}
exports.ConditionalFormattingXform = ConditionalFormattingXform;
