import { BaseXform } from "../base-xform.js";
import { AlignmentXform } from "./alignment-xform.js";
import { BorderXform } from "./border-xform.js";
import { FillXform } from "./fill-xform.js";
import { FontXform } from "./font-xform.js";
import { NumFmtXform } from "./numfmt-xform.js";
import { ProtectionXform } from "./protection-xform.js";
// Style assists translation from style model to/from xlsx
class DxfXform extends BaseXform {
    constructor() {
        super();
        this.map = {
            alignment: new AlignmentXform(),
            border: new BorderXform(),
            fill: new FillXform(),
            font: new FontXform(),
            numFmt: new NumFmtXform(),
            protection: new ProtectionXform()
        };
    }
    get tag() {
        return "dxf";
    }
    // how do we generate dxfid?
    render(xmlStream, model) {
        xmlStream.openNode(this.tag);
        if (model.font) {
            this.map.font.render(xmlStream, model.font);
        }
        if (model.numFmt && model.numFmtId) {
            const numFmtModel = { id: model.numFmtId, formatCode: model.numFmt };
            this.map.numFmt.render(xmlStream, numFmtModel);
        }
        if (model.fill) {
            this.map.fill.render(xmlStream, model.fill);
        }
        if (model.alignment) {
            this.map.alignment.render(xmlStream, model.alignment);
        }
        if (model.border) {
            this.map.border.render(xmlStream, model.border);
        }
        if (model.protection) {
            this.map.protection.render(xmlStream, model.protection);
        }
        xmlStream.closeNode();
    }
    parseOpen(node) {
        if (this.parser) {
            this.parser.parseOpen(node);
            return true;
        }
        switch (node.name) {
            case this.tag:
                // this node is often repeated. Need to reset children
                this.reset();
                return true;
            default:
                this.parser = this.map[node.name];
                if (this.parser) {
                    this.parser.parseOpen(node);
                }
                return true;
        }
    }
    parseText(text) {
        if (this.parser) {
            this.parser.parseText(text);
        }
    }
    parseClose(name) {
        if (this.parser) {
            if (!this.parser.parseClose(name)) {
                this.parser = undefined;
            }
            return true;
        }
        if (name === this.tag) {
            this.model = {
                alignment: this.map.alignment.model,
                border: this.map.border.model,
                fill: this.map.fill.model,
                font: this.map.font.model,
                numFmt: this.map.numFmt.model,
                protection: this.map.protection.model
            };
            return false;
        }
        return true;
    }
}
export { DxfXform };
