import { c as _c } from "react/compiler-runtime";
import { useCallback, useEffect, useRef } from "react";

// Taken and adapted from:
// https://www.joshwcomeau.com/snippets/react-hooks/use-random-interval/

const random = (min, max) => Math.floor(Math.random() * (max - min)) + min;
export default function useRandomInterval(callback, minDelay, maxDelay) {
  const $ = _c(8);
  const timeoutId = useRef(null);
  const savedCallback = useRef(callback);
  let t0;
  let t1;
  if ($[0] !== callback) {
    t0 = () => {
      savedCallback.current = callback;
    };
    t1 = [callback];
    $[0] = callback;
    $[1] = t0;
    $[2] = t1;
  } else {
    t0 = $[1];
    t1 = $[2];
  }
  useEffect(t0, t1);
  let t2;
  let t3;
  if ($[3] !== maxDelay || $[4] !== minDelay) {
    t2 = () => {
      const isEnabled = typeof minDelay === "number" && typeof maxDelay === "number";
      if (isEnabled) {
        const handleTick = () => {
          const nextTickAt = random(minDelay, maxDelay);
          timeoutId.current = window.setTimeout(() => {
            savedCallback.current();
            handleTick();
          }, nextTickAt);
        };
        handleTick();
      }
      return () => {
        if (typeof timeoutId.current === "number") {
          window.clearTimeout(timeoutId.current);
        }
      };
    };
    t3 = [minDelay, maxDelay];
    $[3] = maxDelay;
    $[4] = minDelay;
    $[5] = t2;
    $[6] = t3;
  } else {
    t2 = $[5];
    t3 = $[6];
  }
  useEffect(t2, t3);
  let t4;
  if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = () => {
      if (typeof timeoutId.current === "number") {
        window.clearTimeout(timeoutId.current);
      }
    };
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const cancel = t4;
  return cancel;
}
//# sourceMappingURL=useRandomInterval.jsx.map