"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CfRuleExtXform = void 0;
const base_xform_1 = require("../../base-xform.js");
const composite_xform_1 = require("../../composite-xform.js");
const databar_ext_xform_1 = require("./databar-ext-xform.js");
const icon_set_ext_xform_1 = require("./icon-set-ext-xform.js");
const uuid_1 = require("../../../../../../utils/uuid.js");
const extIcons = {
    "3Triangles": true,
    "3Stars": true,
    "5Boxes": true
};
class CfRuleExtXform extends composite_xform_1.CompositeXform {
    constructor() {
        super();
        this.map = {
            "x14:dataBar": (this.databarXform = new databar_ext_xform_1.DatabarExtXform()),
            "x14:iconSet": (this.iconSetXform = new icon_set_ext_xform_1.IconSetExtXform())
        };
    }
    get tag() {
        return "x14:cfRule";
    }
    static isExt(rule) {
        // is this rule primitive?
        if (rule.type === "dataBar") {
            return databar_ext_xform_1.DatabarExtXform.isExt(rule);
        }
        if (rule.type === "iconSet") {
            if (rule.custom || extIcons[rule.iconSet]) {
                return true;
            }
        }
        return false;
    }
    prepare(model) {
        if (CfRuleExtXform.isExt(model)) {
            model.x14Id = `{${(0, uuid_1.uuidV4)()}}`.toUpperCase();
        }
    }
    render(xmlStream, model) {
        if (!CfRuleExtXform.isExt(model)) {
            return;
        }
        switch (model.type) {
            case "dataBar":
                this.renderDataBar(xmlStream, model);
                break;
            case "iconSet":
                this.renderIconSet(xmlStream, model);
                break;
        }
    }
    renderDataBar(xmlStream, model) {
        xmlStream.openNode(this.tag, {
            type: "dataBar",
            id: model.x14Id
        });
        this.databarXform.render(xmlStream, model);
        xmlStream.closeNode();
    }
    renderIconSet(xmlStream, model) {
        xmlStream.openNode(this.tag, {
            type: "iconSet",
            priority: model.priority,
            id: model.x14Id || `{${(0, uuid_1.uuidV4)()}}`
        });
        this.iconSetXform.render(xmlStream, model);
        xmlStream.closeNode();
    }
    createNewModel({ attributes }) {
        return {
            type: attributes.type,
            x14Id: attributes.id,
            priority: base_xform_1.BaseXform.toIntValue(attributes.priority)
        };
    }
    onParserClose(name, parser) {
        Object.assign(this.model, parser.model);
    }
}
exports.CfRuleExtXform = CfRuleExtXform;
