"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringifyDataValue = stringifyDataValue;
const deepSet_1 = require("../deepSet");
const clone_1 = require("../util/clone");
const object_1 = require("../util/object");
const fromUnitBundle_1 = require("./fromUnitBundle");
const stringify_1 = require("./stringify");
function stringifyDataValue(value, specs, classes) {
    const t = typeof value;
    if (t === 'string') {
        return value;
    }
    else if (t === 'object' && t !== null) {
        value = (0, clone_1.clone)(value);
        if (value.ref.length === 0) {
            return (0, stringify_1.stringify)(value.data);
        }
        else {
            for (const path of value.ref) {
                const bundle = (0, object_1.deepGet)(value.data, path);
                value.data = (0, deepSet_1.deepSet)(value.data, path, (0, stringify_1.stringify)((0, fromUnitBundle_1.fromUnitBundle)(bundle, specs, classes)));
            }
            return value.data;
        }
    }
}
//# sourceMappingURL=stringifyDataValue.js.map