"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommentsXform = void 0;
const xml_stream_1 = require("../../../utils/xml-stream.js");
const base_xform_1 = require("../base-xform.js");
const comment_xform_1 = require("./comment-xform.js");
class CommentsXform extends base_xform_1.BaseXform {
    constructor() {
        super();
        this.map = {
            comment: new comment_xform_1.CommentXform()
        };
        this.model = { comments: [] };
    }
    render(xmlStream, model) {
        const renderModel = model || this.model;
        xmlStream.openXml(xml_stream_1.XmlStream.StdDocAttributes);
        xmlStream.openNode("comments", CommentsXform.COMMENTS_ATTRIBUTES);
        // authors
        // TODO: support authors properly
        xmlStream.openNode("authors");
        xmlStream.leafNode("author", null, "Author");
        xmlStream.closeNode();
        // comments
        xmlStream.openNode("commentList");
        renderModel.comments.forEach(comment => {
            this.map.comment.render(xmlStream, comment);
        });
        xmlStream.closeNode();
        xmlStream.closeNode();
    }
    parseOpen(node) {
        if (this.parser) {
            this.parser.parseOpen(node);
            return true;
        }
        switch (node.name) {
            case "commentList":
                this.model = {
                    comments: []
                };
                return true;
            case "comment":
                this.parser = this.map.comment;
                this.parser.parseOpen(node);
                return true;
            default:
                return false;
        }
    }
    parseText(text) {
        if (this.parser) {
            this.parser.parseText(text);
        }
    }
    parseClose(name) {
        switch (name) {
            case "commentList":
                return false;
            case "comment":
                this.model.comments.push(this.parser.model);
                this.parser = undefined;
                return true;
            default:
                if (this.parser) {
                    this.parser.parseClose(name);
                }
                return true;
        }
    }
}
exports.CommentsXform = CommentsXform;
CommentsXform.COMMENTS_ATTRIBUTES = {
    xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
};
