import{isObject as V}from"../../../utils/guards/is-object.js";import{interpolateEnvVariables as E}from"./interpolate-env-variables.js";function u(t,c=[]){const s=new Set,a=new Set,o={};return!V(t)&&!Array.isArray(t)?{resolvedObj:t,unsetEnvVars:Array.from(s),interpolatedEnvVars:Array.from(a),replacedValues:o}:{resolvedObj:Object.entries(t).reduce((i,[d,r])=>{const f=c.concat(d);if(typeof r=="string"){const{interpolatedValue:e,unsetVars:n,interpolatedVars:p}=E(r);i[d]=e;for(const l of n)s.add(l);for(const l of p)a.add(l);p.length>0&&(o[f.join(":")]={original:r,replaced:e})}else if(V(r)||Array.isArray(r)){const e=u(r,f);i[d]=e.resolvedObj;for(const n of e.unsetEnvVars)s.add(n);for(const n of e.interpolatedEnvVars)a.add(n);Object.assign(o,e.replacedValues)}else i[d]=r;return i},Array.isArray(t)?[]:{}),unsetEnvVars:Array.from(s),interpolatedEnvVars:Array.from(a),replacedValues:o}}export{u as replaceEnvVariablesDeep};
