"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RelationshipsXform = void 0;
const xml_stream_1 = require("../../../utils/xml-stream.js");
const base_xform_1 = require("../base-xform.js");
const relationship_xform_1 = require("./relationship-xform.js");
class RelationshipsXform extends base_xform_1.BaseXform {
    constructor() {
        super();
        this.map = {
            Relationship: new relationship_xform_1.RelationshipXform()
        };
    }
    render(xmlStream, model) {
        const renderModel = model || this._values;
        xmlStream.openXml(xml_stream_1.XmlStream.StdDocAttributes);
        xmlStream.openNode("Relationships", RelationshipsXform.RELATIONSHIPS_ATTRIBUTES);
        renderModel.forEach(relationship => {
            this.map.Relationship.render(xmlStream, relationship);
        });
        xmlStream.closeNode();
    }
    parseOpen(node) {
        if (this.parser) {
            this.parser.parseOpen(node);
            return true;
        }
        switch (node.name) {
            case "Relationships":
                this.model = [];
                return true;
            default:
                this.parser = this.map[node.name];
                if (this.parser) {
                    this.parser.parseOpen(node);
                    return true;
                }
                throw new Error(`Unexpected xml node in parseOpen: ${JSON.stringify(node)}`);
        }
    }
    parseText(text) {
        if (this.parser) {
            this.parser.parseText(text);
        }
    }
    parseClose(name) {
        if (this.parser) {
            if (!this.parser.parseClose(name)) {
                this.model.push(this.parser.model);
                this.parser = undefined;
            }
            return true;
        }
        switch (name) {
            case "Relationships":
                return false;
            default:
                throw new Error(`Unexpected xml node in parseClose: ${name}`);
        }
    }
}
exports.RelationshipsXform = RelationshipsXform;
RelationshipsXform.RELATIONSHIPS_ATTRIBUTES = {
    xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
};
