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