"use client";
let react = require("react");
//#region packages/@mantine/hooks/src/use-long-press/use-long-press.ts
function useLongPress(onLongPress, options = {}) {
	const { threshold = 400, onStart, onFinish, onCancel } = options;
	const isLongPressActive = (0, react.useRef)(false);
	const isPressed = (0, react.useRef)(false);
	const timeout = (0, react.useRef)(-1);
	(0, react.useEffect)(() => () => window.clearTimeout(timeout.current), []);
	return (0, react.useMemo)(() => {
		if (typeof onLongPress !== "function") return {};
		const start = (event) => {
			if (!isMouseEvent(event) && !isTouchEvent(event)) return;
			if (onStart) onStart(event);
			isPressed.current = true;
			timeout.current = window.setTimeout(() => {
				onLongPress(event);
				isLongPressActive.current = true;
			}, threshold);
		};
		const cancel = (event) => {
			if (!isMouseEvent(event) && !isTouchEvent(event)) return;
			if (isLongPressActive.current) {
				if (onFinish) onFinish(event);
			} else if (isPressed.current) {
				if (onCancel) onCancel(event);
			}
			isLongPressActive.current = false;
			isPressed.current = false;
			if (timeout.current !== -1) {
				window.clearTimeout(timeout.current);
				timeout.current = -1;
			}
		};
		return {
			onMouseDown: start,
			onMouseUp: cancel,
			onMouseLeave: cancel,
			onTouchStart: start,
			onTouchEnd: cancel,
			onTouchCancel: cancel
		};
	}, [
		onLongPress,
		threshold,
		onCancel,
		onFinish,
		onStart
	]);
}
function isTouchEvent(event) {
	return window.TouchEvent ? event.nativeEvent instanceof TouchEvent : "touches" in event.nativeEvent;
}
function isMouseEvent(event) {
	return event.nativeEvent instanceof MouseEvent;
}
//#endregion
exports.useLongPress = useLongPress;

//# sourceMappingURL=use-long-press.cjs.map