"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("react/jsx-runtime"),o=require("react"),k=require("../../utils/cn/cn.cjs.js"),V=require("../../utils/useIsMobile.cjs.js"),A=require("../../src/components/InfiniteScroll/infiniteScroll.module.css");function Y({items:p,speed:S=50,direction:x="left",contentClassName:_,itemClassName:H,rootClassName:O,slowOnTouch:F=!1,enableManualScroll:b=!1,renderItem:U},$){const C=o.useRef(null),W=o.useRef(null),g=o.useRef(null),q=o.useRef(!1),y=o.useRef(performance.now()),[f,h]=o.useState(0),[c,B]=o.useState(0),[m,G]=o.useState(4),[j,D]=o.useState(!1),z=V.useIsMobile(),E=o.useCallback(e=>{if(c===0)return e;const t=c;let n=e;for(;n<=-t;)n+=t;for(;n>0;)n-=t;return n},[c]),T=o.useCallback(()=>{if(!W.current||!C.current||p.length===0)return;const e=W.current,t=e.children.length;if(t===0)return;let n=0;for(let r=0;r<Math.min(p.length,t);r++){const d=e.children[r];n+=d.offsetWidth}if(n===0&&(n=e.scrollWidth/m),n<=0)return;const l=C.current.offsetWidth,u=Math.ceil(l*2.5/n),a=Math.max(4,Math.min(20,u%2===0?u:u+1)),i=c,v=m;if(G(a),B(n),i>0&&v>0){const r=Math.floor(v/2),d=Math.floor(a/2),R=(f+i*r)/i,s=-n*d+R*n;h(s)}else{const r=Math.floor(a/2);h(-n*r)}},[p.length,m,c,f]);o.useEffect(()=>{T();const e=new ResizeObserver(()=>{T()});return C.current&&e.observe(C.current),()=>e.disconnect()},[T]);const X=o.useCallback(e=>{if(q.current||c===0){g.current=requestAnimationFrame(X);return}const t=e!=null?e:performance.now(),n=t-y.current||16.67;y.current=t,h(l=>{const u=j?S*.5:S,a=x==="right"?-u:u;let i=l-a*(n/1e3);return E(i)}),g.current=requestAnimationFrame(X)},[x,S,c,j,E]);o.useEffect(()=>(y.current=performance.now(),g.current=requestAnimationFrame(X),()=>{g.current&&cancelAnimationFrame(g.current)}),[X]);const w=o.useCallback((e,t)=>{!(t==="mouse")&&!(t==="touch"&&z)||(e?F?D(!0):q.current=!0:(q.current=!1,D(!1),y.current=performance.now()))},[z,F]),J=o.useCallback(e=>{w(!0,e.pointerType)},[w]),K=o.useCallback(e=>{w(!1,e.pointerType)},[w]),N=o.useCallback((e,t=300)=>{const n=f,l=e-n,u=performance.now(),a=i=>{const v=i-u,r=Math.min(v/t,1),d=1-Math.pow(1-r,3);h(n+l*d),r<1&&requestAnimationFrame(a)};requestAnimationFrame(a)},[f]);return o.useEffect(()=>{if(!b)return;const e=C.current;if(!e)return;let t=null,n=!1,l=null;const u=s=>{if(s.deltaX!==0){s.preventDefault();const M=s.deltaX*2;h(L=>E(L-M))}},a=s=>{n=!0,l=s.clientX,s.preventDefault()},i=s=>{if(!n||l===null)return;const M=s.clientX,L=M-l;l=M,h(P=>E(P+L))},v=()=>{n=!1,l=null},r=s=>{t=s.touches[0].clientX},d=s=>{if(t===null)return;s.preventDefault();const L=s.touches[0].clientX,P=L-t;t=L,h(Q=>E(Q+P))},R=()=>{t=null};return e.addEventListener("wheel",u,{passive:!1}),e.addEventListener("mousedown",a,{passive:!1}),e.addEventListener("mousemove",i,{passive:!1}),e.addEventListener("touchstart",r),e.addEventListener("touchmove",d,{passive:!1}),e.addEventListener("touchend",R),document.addEventListener("mouseup",v),document.addEventListener("mousemove",i),()=>{e.removeEventListener("wheel",u),e.removeEventListener("mousedown",a),e.removeEventListener("mousemove",i),e.removeEventListener("touchstart",r),e.removeEventListener("touchmove",d),e.removeEventListener("touchend",R),document.removeEventListener("mouseup",v),document.removeEventListener("mousemove",i)}},[b,E]),o.useImperativeHandle($,()=>({scrollLeft:()=>{const e=c*m,t=-c*Math.floor(m/2);let n=f-200;n<-e+t&&(n+=c),N(n)},scrollRight:()=>{const e=-c*Math.floor(m/2);let t=f+200;t>e&&(t-=c),N(t)}})),I.jsx("div",{className:k.cn(A.root,O),ref:C,"data-manual-scroll":b,onPointerEnter:J,onPointerLeave:K,children:I.jsx("div",{className:k.cn(A.content,_),ref:W,style:{transform:`translate3d(${f}px, 0, 0)`},children:Array.from({length:p.length*m},(e,t)=>I.jsx("div",{className:k.cn(A.item,H),children:U(p[t%p.length],t)},t))})})}const Z=o.forwardRef(Y);exports.InfiniteScroll=Z;
