"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IconSetExtXform = void 0;
const base_xform_1 = require("../../base-xform.js");
const composite_xform_1 = require("../../composite-xform.js");
const cfvo_ext_xform_1 = require("./cfvo-ext-xform.js");
const cf_icon_ext_xform_1 = require("./cf-icon-ext-xform.js");
class IconSetExtXform extends composite_xform_1.CompositeXform {
    constructor() {
        super();
        this.map = {
            "x14:cfvo": (this.cfvoXform = new cfvo_ext_xform_1.CfvoExtXform()),
            "x14:cfIcon": (this.cfIconXform = new cf_icon_ext_xform_1.CfIconExtXform())
        };
    }
    get tag() {
        return "x14:iconSet";
    }
    render(xmlStream, model) {
        xmlStream.openNode(this.tag, {
            iconSet: base_xform_1.BaseXform.toStringAttribute(model.iconSet),
            reverse: base_xform_1.BaseXform.toBoolAttribute(model.reverse, false),
            showValue: base_xform_1.BaseXform.toBoolAttribute(model.showValue, true),
            custom: base_xform_1.BaseXform.toBoolAttribute(model.icons, false)
        });
        model.cfvo.forEach(cfvo => {
            this.cfvoXform.render(xmlStream, cfvo);
        });
        if (model.icons) {
            model.icons.forEach((icon, i) => {
                icon.iconId = i;
                this.cfIconXform.render(xmlStream, icon);
            });
        }
        xmlStream.closeNode();
    }
    createNewModel({ attributes }) {
        return {
            cfvo: [],
            iconSet: base_xform_1.BaseXform.toStringValue(attributes.iconSet, "3TrafficLights"),
            reverse: base_xform_1.BaseXform.toBoolValue(attributes.reverse, false),
            showValue: base_xform_1.BaseXform.toBoolValue(attributes.showValue, true)
        };
    }
    onParserClose(name, parser) {
        const [, prop] = name.split(":");
        switch (prop) {
            case "cfvo":
                this.model.cfvo.push(parser.model);
                break;
            case "cfIcon":
                if (!this.model.icons) {
                    this.model.icons = [];
                }
                this.model.icons.push(parser.model);
                break;
            default:
                this.model[prop] = parser.model;
                break;
        }
    }
}
exports.IconSetExtXform = IconSetExtXform;
