"use client";
import { useCallback, useEffect, useRef, useState } from "react";
//#region packages/@mantine/hooks/src/use-debounced-state/use-debounced-state.ts
function useDebouncedState(defaultValue, wait, options = { leading: false }) {
	const [value, setValue] = useState(defaultValue);
	const timeoutRef = useRef(null);
	const leadingRef = useRef(true);
	const clearTimeout = () => window.clearTimeout(timeoutRef.current);
	useEffect(() => clearTimeout, []);
	return [value, useCallback((newValue) => {
		clearTimeout();
		if (leadingRef.current && options.leading) setValue(newValue);
		else timeoutRef.current = window.setTimeout(() => {
			leadingRef.current = true;
			setValue(newValue);
		}, wait);
		leadingRef.current = false;
	}, [options.leading, wait])];
}
//#endregion
export { useDebouncedState };

//# sourceMappingURL=use-debounced-state.mjs.map