"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConditionalFormattingExtXform = void 0;
const composite_xform_1 = require("../../composite-xform.js");
const sqref_ext_xform_1 = require("./sqref-ext-xform.js");
const cf_rule_ext_xform_1 = require("./cf-rule-ext-xform.js");
class ConditionalFormattingExtXform extends composite_xform_1.CompositeXform {
    constructor() {
        super();
        this.map = {
            "xm:sqref": (this.sqRef = new sqref_ext_xform_1.SqrefExtXform()),
            "x14:cfRule": (this.cfRule = new cf_rule_ext_xform_1.CfRuleExtXform())
        };
    }
    get tag() {
        return "x14:conditionalFormatting";
    }
    prepare(model) {
        model.rules.forEach(rule => {
            this.cfRule.prepare(rule);
        });
    }
    render(xmlStream, model) {
        if (!model.rules.some(cf_rule_ext_xform_1.CfRuleExtXform.isExt)) {
            return;
        }
        xmlStream.openNode(this.tag, {
            "xmlns:xm": "http://schemas.microsoft.com/office/excel/2006/main"
        });
        model.rules.filter(cf_rule_ext_xform_1.CfRuleExtXform.isExt).forEach(rule => this.cfRule.render(xmlStream, rule));
        // for some odd reason, Excel needs the <xm:sqref> node to be after the rules
        this.sqRef.render(xmlStream, model.ref);
        xmlStream.closeNode();
    }
    createNewModel() {
        return {
            rules: []
        };
    }
    onParserClose(name, parser) {
        switch (name) {
            case "xm:sqref":
                this.model.ref = parser.model;
                break;
            case "x14:cfRule":
                this.model.rules.push(parser.model);
                break;
        }
    }
}
exports.ConditionalFormattingExtXform = ConditionalFormattingExtXform;
