import { isPlainObject as e } from "../predicate/isPlainObject.js";
import { getSymbols as t } from "../_internal/getSymbols.js";
import { isBuffer as n } from "../../predicate/isBuffer.js";
import { isUnsafeProperty as r } from "../../_internal/isUnsafeProperty.js";
import { isPrimitive as i } from "../../predicate/isPrimitive.js";
import { cloneDeep as a } from "./cloneDeep.js";
import { isArguments as o } from "../predicate/isArguments.js";
import { isObjectLike as s } from "../predicate/isObjectLike.js";
import { isArrayLikeObject as c } from "../predicate/isArrayLikeObject.js";
import { isTypedArray as l } from "../predicate/isTypedArray.js";
import { clone as u } from "../../object/clone.js";
//#region ../../node_modules/es-toolkit/dist/compat/object/mergeWith.mjs
function d(e, ...t) {
	let n = t.slice(0, -1), r = t[t.length - 1], i = e;
	for (let e = 0; e < n.length; e++) {
		let t = n[e];
		i = f(i, t, r, /* @__PURE__ */ new Map());
	}
	return i;
}
function f(d, p, m, h) {
	if (i(d) && (d = Object(d)), typeof p != "object" || !p) return d;
	if (h.has(p)) return u(h.get(p));
	if (h.set(p, d), Array.isArray(p)) {
		p = p.slice();
		for (let e = 0; e < p.length; e++) p[e] = p[e] ?? void 0;
	}
	let g = [...Object.keys(p), ...t(p)];
	for (let t = 0; t < g.length; t++) {
		let i = g[t];
		if (r(i)) continue;
		let u = p[i], _ = d[i];
		if (o(u) && (u = { ...u }), o(_) && (_ = { ..._ }), n(u) && (u = a(u)), Array.isArray(u)) if (Array.isArray(_)) {
			let e = [], t = Reflect.ownKeys(_);
			for (let n = 0; n < t.length; n++) {
				let r = t[n];
				e[r] = _[r];
			}
			_ = e;
		} else if (c(_)) {
			let e = [];
			for (let t = 0; t < _.length; t++) e[t] = _[t];
			_ = e;
		} else _ = [];
		let v = m(_, u, i, d, p, h);
		v === void 0 ? Array.isArray(u) || s(_) && s(u) && (e(_) || e(u) || l(_) || l(u)) ? d[i] = f(_, u, m, h) : _ == null && e(u) ? d[i] = f({}, u, m, h) : _ == null && l(u) ? d[i] = a(u) : (_ === void 0 || u !== void 0) && (d[i] = u) : d[i] = v;
	}
	return d;
}
//#endregion
export { d as mergeWith };

//# sourceMappingURL=mergeWith.js.map