"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const useDidUpdateEffect = require("./useDidUpdateEffect.cjs");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
function useDebounce(throttleTime = 500, hardValue, onChange) {
  const [actualValue, setActualValue] = React__namespace.useState(hardValue);
  const [throttledValue, setThrottledValue] = React__namespace.useState(hardValue);
  const setValue = React__namespace.useCallback(() => {
    setThrottledValue(actualValue);
    onChange == null ? void 0 : onChange(actualValue);
  }, [actualValue, setThrottledValue, onChange]);
  const resetToHardValue = React__namespace.useCallback(() => {
    setActualValue(hardValue);
    setThrottledValue(hardValue);
  }, [hardValue, setActualValue, setThrottledValue]);
  React__namespace.useEffect(() => {
    resetToHardValue();
  }, [hardValue]);
  React__namespace.useEffect(() => {
    const throttleTimer = setTimeout(setValue, throttleTime);
    return () => clearTimeout(throttleTimer);
  }, [actualValue]);
  return [actualValue, setActualValue, throttledValue, resetToHardValue];
}
function useDebounceEffect(fn, ms, deps) {
  const throttleRef = React__namespace.useRef();
  useDidUpdateEffect.useDidUpdateEffect(() => {
    if (throttleRef.current) {
      clearTimeout(throttleRef.current);
    }
    throttleRef.current = setTimeout(() => {
      fn();
    }, ms);
  }, deps);
}
exports.useDebounce = useDebounce;
exports.useDebounceEffect = useDebounceEffect;
//# sourceMappingURL=useDebounce.cjs.map
