"use client";
import * as React from "react";
function useInFlightGuard(options = {}) {
  const { onDuplicate } = options;
  const runningRef = React.useRef(false);
  const [isPending, setIsPending] = React.useState(false);
  const onDuplicateRef = React.useRef(onDuplicate);
  React.useEffect(() => {
    onDuplicateRef.current = onDuplicate;
  }, [onDuplicate]);
  const run = React.useCallback(async function run2(operation) {
    if (runningRef.current) {
      onDuplicateRef.current?.();
      return void 0;
    }
    runningRef.current = true;
    setIsPending(true);
    try {
      return await operation();
    } finally {
      runningRef.current = false;
      setIsPending(false);
    }
  }, []);
  const guard = React.useCallback(function guard2(fn) {
    return async (...args) => run(() => fn(...args));
  }, [run]);
  return { isPending, run, guard };
}
export {
  useInFlightGuard
};
//# sourceMappingURL=useInFlightGuard.js.map
