import { useRef as m, useMemo as T, useEffect as l } from "react";
const f = (s, t) => {
  const e = m(null), c = m(s);
  return l(() => {
    c.current = s;
  }, [s]), l(() => {
    const n = () => c.current();
    if (typeof t == "number")
      return e.current = setTimeout(n, t), () => {
        e.current !== null && clearTimeout(e.current);
      };
  }, [t]), e;
}, _ = () => {
  const t = (u, i, o) => {
    const r = o - Date.now();
    u.current = r <= 2147483647 ? setTimeout(i, r) : setTimeout(() => t(u, i, o), 2147483647);
  }, e = m(null), { set: c, clear: n } = T(() => {
    const u = () => clearTimeout(e.current);
    return {
      set: (o, r = 0) => {
        u(), r <= 2147483647 ? e.current = setTimeout(o, r) : t(e, o, Date.now() + r);
      },
      clear: u
    };
  }, []);
  return l(
    () => () => {
      n();
    },
    [n]
  ), {
    set: c,
    clear: n,
    handleRef: e
  };
};
export {
  f as default,
  _ as useChainedTimeout
};
//# sourceMappingURL=useTimeout.js.map
