"use strict";var core=require("@gem-sdk/core"),React=require("react");const useMarqueeBase=(e,t)=>{let{style:r={},autoFill:u=!1,play:n=!0,pauseOnHover:a=!1,pauseOnClick:c=!1,direction:s="left",speed:i=50,delay:o=0,loop:d=0,onMount:l,children:R,isFullWidth:f}=e??{},h=core.useEditorMode(),[m,g]=React.useState(0),[p,w]=React.useState(0),[M,v]=React.useState(1),[q,y]=React.useState(!1),B=React.useRef(null),E=t||B,b=React.useRef(null),S=React.useRef(null),T=React.useCallback(()=>{if(b.current&&E.current){let e=E.current.getBoundingClientRect(),t=b.current.getBoundingClientRect(),r=e.width,n=t.width;n<40||(f?(n=r,b.current.style.width=`${n}px`):b.current.style.width="auto",("up"===s||"down"===s)&&(r=e.height,n=t.height),u&&r&&n?v(Math.min(60,n<r?Math.ceil(r/n)+1:1)):v(2),g(r),w(n))}},[u,E,s,f,R]);React.useEffect(()=>{if(q&&b.current&&E.current){let e=new ResizeObserver(()=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{T()},600)});return e.observe(b.current),e.observe(E.current),()=>{e&&e.disconnect()}}},[T,E,q]),React.useEffect(()=>{"edit"===h&&(S.current=setTimeout(()=>{T()},500))},[R,T,h]),React.useEffect(()=>(y(!0),()=>{S.current&&clearTimeout(S.current)}),[]),React.useEffect(()=>{"function"==typeof l&&l()},[l]);let $=React.useMemo(()=>u?p*M/i:p<m?m/i:p/i,[u,m,p,M,i]),k=React.useMemo(()=>({...r,marginLeft:"1px","--pause-on-hover":!n||a?"paused":"running","--pause-on-click":!n||a&&!c||c?"paused":"running","--width":"up"===s||"down"===s?"100vh":"100%","--transform":"up"===s?"rotate(-90deg)":"down"===s?"rotate(90deg)":"none"}),[r,n,a,c,s]),x=React.useMemo(()=>({"--play":n?"running":"paused","--direction":"left"===s?"normal":"reverse","--duration":`${$}s`,"--delay":`${o}s`,"--iteration-count":d?`${d}`:"infinite","--min-width":u?"auto":"100%",width:f?"100%":"auto"}),[n,s,$,o,d,u,f]),C=React.useMemo(()=>({"--transform":"up"===s?"rotate(90deg)":"down"===s?"rotate(-90deg)":"none",width:f?"100%":"auto",minWidth:f?"100%":"unset"}),[s,f]);return{containerStyle:k,marqueeStyle:x,childStyle:C,marqueeRef:b,containerRef:E,calculateWidth:T,multiplier:M}};exports.useMarqueeBase=useMarqueeBase;
