"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatabarExtXform = void 0;
const base_xform_1 = require("../../base-xform.js");
const composite_xform_1 = require("../../composite-xform.js");
const color_xform_1 = require("../../style/color-xform.js");
const cfvo_ext_xform_1 = require("./cfvo-ext-xform.js");
class DatabarExtXform extends composite_xform_1.CompositeXform {
    constructor() {
        super();
        this.map = {
            "x14:cfvo": (this.cfvoXform = new cfvo_ext_xform_1.CfvoExtXform()),
            "x14:borderColor": (this.borderColorXform = new color_xform_1.ColorXform("x14:borderColor")),
            "x14:negativeBorderColor": (this.negativeBorderColorXform = new color_xform_1.ColorXform("x14:negativeBorderColor")),
            "x14:negativeFillColor": (this.negativeFillColorXform = new color_xform_1.ColorXform("x14:negativeFillColor")),
            "x14:axisColor": (this.axisColorXform = new color_xform_1.ColorXform("x14:axisColor"))
        };
    }
    static isExt(rule) {
        // not all databars need ext
        // TODO: refine this
        return !rule.gradient;
    }
    get tag() {
        return "x14:dataBar";
    }
    render(xmlStream, model) {
        xmlStream.openNode(this.tag, {
            minLength: base_xform_1.BaseXform.toIntAttribute(model.minLength, 0, true),
            maxLength: base_xform_1.BaseXform.toIntAttribute(model.maxLength, 100, true),
            border: base_xform_1.BaseXform.toBoolAttribute(model.border, false),
            gradient: base_xform_1.BaseXform.toBoolAttribute(model.gradient, true),
            negativeBarColorSameAsPositive: base_xform_1.BaseXform.toBoolAttribute(model.negativeBarColorSameAsPositive, true),
            negativeBarBorderColorSameAsPositive: base_xform_1.BaseXform.toBoolAttribute(model.negativeBarBorderColorSameAsPositive, true),
            axisPosition: base_xform_1.BaseXform.toAttribute(model.axisPosition, "auto"),
            direction: base_xform_1.BaseXform.toAttribute(model.direction, "leftToRight")
        });
        model.cfvo.forEach(cfvo => {
            this.cfvoXform.render(xmlStream, cfvo);
        });
        this.borderColorXform.render(xmlStream, model.borderColor);
        this.negativeBorderColorXform.render(xmlStream, model.negativeBorderColor);
        this.negativeFillColorXform.render(xmlStream, model.negativeFillColor);
        this.axisColorXform.render(xmlStream, model.axisColor);
        xmlStream.closeNode();
    }
    createNewModel({ attributes }) {
        return {
            cfvo: [],
            minLength: base_xform_1.BaseXform.toIntValue(attributes.minLength, 0),
            maxLength: base_xform_1.BaseXform.toIntValue(attributes.maxLength, 100),
            border: base_xform_1.BaseXform.toBoolValue(attributes.border, false),
            gradient: base_xform_1.BaseXform.toBoolValue(attributes.gradient, true),
            negativeBarColorSameAsPositive: base_xform_1.BaseXform.toBoolValue(attributes.negativeBarColorSameAsPositive, true),
            negativeBarBorderColorSameAsPositive: base_xform_1.BaseXform.toBoolValue(attributes.negativeBarBorderColorSameAsPositive, true),
            axisPosition: base_xform_1.BaseXform.toStringValue(attributes.axisPosition, "auto"),
            direction: base_xform_1.BaseXform.toStringValue(attributes.direction, "leftToRight")
        };
    }
    onParserClose(name, parser) {
        const [, prop] = name.split(":");
        switch (prop) {
            case "cfvo":
                this.model.cfvo.push(parser.model);
                break;
            default:
                this.model[prop] = parser.model;
                break;
        }
    }
}
exports.DatabarExtXform = DatabarExtXform;
