"use client";
import { useCallbackRef } from "../utils/use-callback-ref/use-callback-ref.mjs";
import { useCallback, useEffect, useRef } from "react";
//#region packages/@mantine/hooks/src/use-timeout/use-timeout.ts
function useTimeout(callback, delay, options = { autoInvoke: false }) {
	const timeoutRef = useRef(null);
	const handleCallback = useCallbackRef(callback);
	const start = useCallback((...args) => {
		if (!timeoutRef.current) timeoutRef.current = window.setTimeout(() => {
			handleCallback(...args);
			timeoutRef.current = null;
		}, delay);
	}, [delay]);
	const clear = useCallback(() => {
		if (timeoutRef.current) {
			window.clearTimeout(timeoutRef.current);
			timeoutRef.current = null;
		}
	}, []);
	useEffect(() => {
		if (options.autoInvoke) start();
		return clear;
	}, [clear, start]);
	return {
		start,
		clear
	};
}
//#endregion
export { useTimeout };

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