"use client";
import { useCallback, useInsertionEffect, useRef } from "react";
//#region node_modules/framer-motion/dist/es/motion/utils/use-motion-ref.mjs
/**
* Creates a ref function that, when called, hydrates the provided
* external ref and VisualElement.
*/
function useMotionRef(visualState, visualElement, externalRef) {
	/**
	* Store externalRef in a ref to avoid including it in the useCallback
	* dependency array. Including externalRef in dependencies causes issues
	* with libraries like Radix UI that create new callback refs on each render
	* when using asChild - this would cause the callback to be recreated,
	* triggering element remounts and breaking AnimatePresence exit animations.
	*/
	const externalRefContainer = useRef(externalRef);
	useInsertionEffect(() => {
		externalRefContainer.current = externalRef;
	});
	const refCleanup = useRef(null);
	return useCallback((instance) => {
		if (instance) visualState.onMount?.(instance);
		const ref = externalRefContainer.current;
		if (typeof ref === "function") if (instance) {
			const cleanup = ref(instance);
			if (typeof cleanup === "function") refCleanup.current = cleanup;
		} else if (refCleanup.current) {
			refCleanup.current();
			refCleanup.current = null;
		} else ref(instance);
		else if (ref) ref.current = instance;
		if (visualElement) instance ? visualElement.mount(instance) : visualElement.unmount();
	}, [visualElement]);
}
//#endregion
export { useMotionRef };

//# sourceMappingURL=index330.js.map