"use client";
import { useCallback, useEffect, useState } from "react";
//#region packages/@mantine/hooks/src/use-mouse/use-mouse.ts
function useMouse(options = { resetOnExit: false }) {
	const [position, setPosition] = useState({
		x: 0,
		y: 0
	});
	return {
		ref: useCallback((node) => {
			const setMousePosition = (event) => {
				const mouseEvent = event;
				if (node) {
					const rect = node.getBoundingClientRect();
					setPosition({
						x: Math.max(0, Math.round(mouseEvent.clientX - rect.left)),
						y: Math.max(0, Math.round(mouseEvent.clientY - rect.top))
					});
				} else setPosition({
					x: mouseEvent.clientX,
					y: mouseEvent.clientY
				});
			};
			const resetMousePosition = () => setPosition({
				x: 0,
				y: 0
			});
			node?.addEventListener("mousemove", setMousePosition);
			if (options.resetOnExit) node?.addEventListener("mouseleave", resetMousePosition);
			return () => {
				node?.removeEventListener("mousemove", setMousePosition);
				if (options.resetOnExit) node?.removeEventListener("mouseleave", resetMousePosition);
			};
		}, [options.resetOnExit]),
		...position
	};
}
function useMousePosition() {
	const [position, setPosition] = useState({
		x: 0,
		y: 0
	});
	useEffect(() => {
		const setMousePosition = (event) => {
			setPosition({
				x: event.clientX,
				y: event.clientY
			});
		};
		document.addEventListener("mousemove", setMousePosition);
		return () => {
			document.removeEventListener("mousemove", setMousePosition);
		};
	}, []);
	return position;
}
//#endregion
export { useMouse, useMousePosition };

//# sourceMappingURL=use-mouse.mjs.map