"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var m=require("../../_virtual/jsx-runtime.js"),r=require("react"),E=require("../../hooks/useDebounce.js");function R({element:s,loadMore:f,children:d,hasMore:u,threshold:o,axis:n,loader:a,...v}){const t=r.useRef(null),p=E.useDebouncedFn(f,300),c=r.useMemo(()=>typeof o=="number"?o:o[n],[o,n]),h=r.useCallback(e=>(n==="x"?(e.scrollLeft+c)/(e.scrollWidth-e.clientWidth):(e.scrollTop+c)/(e.scrollHeight-e.clientHeight))>=1,[n,c]);function l(e){u&&h(e.target)&&p()}if(r.useEffect(()=>{var i;const e=(i=t.current)==null?void 0:i.parentNode;return e==null||e.addEventListener("scroll",l),()=>{e==null||e.removeEventListener("scroll",l)}},[t.current]),!["x","y"].includes(n))throw new Error("Invalid axis provided.");if(c<0)throw new RangeError("Threshold is outside of the expected range");return r.createElement(s,{...v,ref:t,onScroll:l},[d,u&&m.jsxRuntimeExports.jsx(r.Fragment,{children:a},"infinite-scroll-loader-wrapper")])}exports.InfiniteScroll=R;
