"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NumFmtXform = void 0;
const defaultnumformats_1 = require("../../defaultnumformats.js");
const base_xform_1 = require("../base-xform.js");
function hashDefaultFormats() {
    const hash = {};
    Object.entries(defaultnumformats_1.defaultNumFormats).forEach(([id, dnf]) => {
        if (dnf.f) {
            hash[dnf.f] = parseInt(id, 10);
        }
        // at some point, add the other cultures here...
    });
    return hash;
}
const defaultFmtHash = hashDefaultFormats();
// NumFmt encapsulates translation between number format and xlsx
class NumFmtXform extends base_xform_1.BaseXform {
    constructor(id, formatCode) {
        super();
        this.id = id;
        this.formatCode = formatCode;
    }
    get tag() {
        return "numFmt";
    }
    render(xmlStream, model) {
        xmlStream.leafNode("numFmt", { numFmtId: model.id, formatCode: model.formatCode });
    }
    parseOpen(node) {
        switch (node.name) {
            case "numFmt":
                this.model = {
                    id: parseInt(node.attributes.numFmtId, 10),
                    formatCode: node.attributes.formatCode.replace(/[\\](.)/g, "$1")
                };
                return true;
            default:
                return false;
        }
    }
    parseText() { }
    parseClose() {
        return false;
    }
    static getDefaultFmtId(formatCode) {
        return defaultFmtHash[formatCode];
    }
    static getDefaultFmtCode(numFmtId) {
        return defaultnumformats_1.defaultNumFormats[numFmtId] && defaultnumformats_1.defaultNumFormats[numFmtId].f;
    }
}
exports.NumFmtXform = NumFmtXform;
