import { Obj, evalWithScope } from "@intelligentgraphics/ig.utilities";
export const evaluateTemplate = (rawTemplate, config) => {
    const template = Obj.deepClone(rawTemplate);
    const evaluateStringValues = (obj) => {
        for (const key in obj) {
            const value = obj[key];
            if (value === null || value === undefined) {
                continue;
            }
            if (typeof value === "string" &&
                value.indexOf("{") === 0 &&
                value.lastIndexOf("}") === value.length - 1) {
                obj[key] = evalWithScope(value.substring(1, value.length - 1), config);
                continue;
            }
            if (typeof value === "object") {
                evaluateStringValues(value);
            }
        }
    };
    evaluateStringValues(template);
    return template;
};
