"use client";
import { useCallback } from "react";
//#region packages/@mantine/hooks/src/use-merged-ref/use-merged-ref.ts
function assignRef(ref, value) {
	if (typeof ref === "function") return ref(value);
	else if (typeof ref === "object" && ref !== null && "current" in ref) ref.current = value;
}
function mergeRefs(...refs) {
	const cleanupMap = /* @__PURE__ */ new Map();
	return (node) => {
		refs.forEach((ref) => {
			const cleanup = assignRef(ref, node);
			if (cleanup) cleanupMap.set(ref, cleanup);
		});
		if (cleanupMap.size > 0) return () => {
			refs.forEach((ref) => {
				const cleanup = cleanupMap.get(ref);
				if (cleanup && typeof cleanup === "function") cleanup();
				else assignRef(ref, null);
			});
			cleanupMap.clear();
		};
	};
}
function useMergedRef(...refs) {
	return useCallback(mergeRefs(...refs), refs);
}
//#endregion
export { assignRef, mergeRefs, useMergedRef };

//# sourceMappingURL=use-merged-ref.mjs.map