import s from "./get.mjs";
function g(e, r, o, c) {
  if (!r.length)
    return o;
  const [t, ...i] = r;
  let n;
  return !e && typeof t == "number" ? n = [] : Array.isArray(e) ? n = [...e] : n = { ...e }, c && o === void 0 && i.length === 1 ? delete n[t][i[0]] : n[t] = g(n[t], i, o, c), n;
}
function l(e, r, o, c = !1) {
  return r.length && c && o === void 0 && !s(e, r.slice(0, -1)) ? e : g(e, r, o, c);
}
function b(e) {
  return typeof e == "object" && e !== null && Object.getPrototypeOf(e) === Object.prototype;
}
function a(e) {
  return Array.isArray(e) ? [] : {};
}
const O = typeof Reflect > "u" ? Object.keys : Reflect.ownKeys;
function j(...e) {
  let r = a(e[0]);
  return e.forEach((o) => {
    function c(t, i) {
      const n = new Set(i), f = s(o, t), u = Array.isArray(f);
      if (u || b(f)) {
        if (!n.has(f)) {
          n.add(f);
          const y = s(r, t);
          u ? r = l(r, t, []) : (!y || typeof y != "object") && (r = l(r, t, a(f))), O(f).forEach((A) => {
            c([...t, A], n);
          });
        }
      } else
        r = l(r, t, f);
    }
    c([]);
  }), r;
}
export {
  l as default,
  j as merge
};
