"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppXform = void 0;
const xml_stream_1 = require("../../../utils/xml-stream.js");
const base_xform_1 = require("../base-xform.js");
const string_xform_1 = require("../simple/string-xform.js");
const app_heading_pairs_xform_1 = require("./app-heading-pairs-xform.js");
const app_titles_of_parts_xform_1 = require("./app-titles-of-parts-xform.js");
class AppXform extends base_xform_1.BaseXform {
    constructor() {
        super();
        this.map = {
            Company: new string_xform_1.StringXform({ tag: "Company" }),
            Manager: new string_xform_1.StringXform({ tag: "Manager" }),
            HeadingPairs: new app_heading_pairs_xform_1.AppHeadingPairsXform(),
            TitlesOfParts: new app_titles_of_parts_xform_1.AppTitlesOfPartsXform()
        };
    }
    render(xmlStream, model) {
        xmlStream.openXml(xml_stream_1.XmlStream.StdDocAttributes);
        xmlStream.openNode("Properties", AppXform.PROPERTY_ATTRIBUTES);
        xmlStream.leafNode("Application", undefined, "Microsoft Excel");
        xmlStream.leafNode("DocSecurity", undefined, "0");
        xmlStream.leafNode("ScaleCrop", undefined, "false");
        this.map.HeadingPairs.render(xmlStream, model.worksheets);
        this.map.TitlesOfParts.render(xmlStream, model.worksheets);
        this.map.Company.render(xmlStream, model.company || "");
        this.map.Manager.render(xmlStream, model.manager);
        xmlStream.leafNode("LinksUpToDate", undefined, "false");
        xmlStream.leafNode("SharedDoc", undefined, "false");
        xmlStream.leafNode("HyperlinksChanged", undefined, "false");
        xmlStream.leafNode("AppVersion", undefined, "16.0300");
        xmlStream.closeNode();
    }
    parseOpen(node) {
        if (this.parser) {
            this.parser.parseOpen(node);
            return true;
        }
        switch (node.name) {
            case "Properties":
                return true;
            default:
                this.parser = this.map[node.name];
                if (this.parser) {
                    this.parser.parseOpen(node);
                    return true;
                }
                // there's a lot we don't bother to parse
                return false;
        }
    }
    parseText(text) {
        if (this.parser) {
            this.parser.parseText(text);
        }
    }
    parseClose(name) {
        if (this.parser) {
            if (!this.parser.parseClose(name)) {
                this.parser = undefined;
            }
            return true;
        }
        switch (name) {
            case "Properties":
                this.model = {
                    worksheets: this.map.TitlesOfParts.model,
                    company: this.map.Company.model,
                    manager: this.map.Manager.model
                };
                return false;
            default:
                return true;
        }
    }
}
exports.AppXform = AppXform;
AppXform.DateFormat = function (dt) {
    return dt.toISOString().replace(/[.]\d{3,6}/, "");
};
AppXform.DateAttrs = { "xsi:type": "dcterms:W3CDTF" };
AppXform.PROPERTY_ATTRIBUTES = {
    xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
    "xmlns:vt": "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
};
