import { j as h } from "./index.es37.js";
import { useState as x, useRef as g, useEffect as i, useMemo as E } from "react";
import f from "./index.es22.js";
const H = (t) => {
  const [m, a] = x(0), n = g(), r = () => {
    let e;
    return t.context ? e = t.context.current : f.isBrowser() && (e = document.documentElement), e;
  }, s = () => {
    const e = r();
    if (e) {
      const { scrollTop: o, clientHeight: c, scrollHeight: l } = e;
      o + c >= l - t.offset && t.onBottomReached();
    }
  };
  i(() => {
    let e;
    if (t.context ? e = t.context.current : f.isBrowser() && (e = window), !!e)
      return e.addEventListener("scroll", s), () => e && e.removeEventListener("scroll", s);
  }, [t.context]);
  const u = () => {
    let e = !1;
    const o = r();
    if (o) {
      const { clientHeight: c, scrollHeight: l } = o;
      e = l > c;
    }
    return e;
  };
  i(() => {
    if (!u() && n && n.current) {
      const { clientHeight: e } = n.current;
      e > m && (a(e), t.onBottomReached());
    }
  });
  const d = E(() => t.as || "div", [t.as]);
  return /* @__PURE__ */ h.jsx(
    d,
    {
      className: t.className,
      ref: n,
      children: t.children
    }
  );
};
H.defaultProps = {
  offset: 0
};
export {
  H as default
};
//# sourceMappingURL=index.es6.js.map
