import{r as a,j as E}from"./index.B7J6suR-.js";function T({element:t,width:f,endpoints:c,elementMgr:o}){const i=a.useRef(null),{startTime:u,endTime:n,loop:d,autoplay:p}=t,l=a.useMemo(()=>{if(!t.id)return!0;const e=o.getElementState(t.id,"preventAutoplay");return e||o.setElementState(t.id,"preventAutoplay",!0),e??!1},[t.id,o]);a.useEffect(()=>{i.current&&(i.current.currentTime=u)},[u]),a.useEffect(()=>{const e=i.current,r=()=>{e&&(e.currentTime=t.startTime)};return e&&e.addEventListener("loadedmetadata",r),()=>{e&&e.removeEventListener("loadedmetadata",r)}},[t]),a.useEffect(()=>{const e=i.current;if(!e)return;let r=!1;const s=()=>{n>0&&e.currentTime>=n&&(d?(e.currentTime=u||0,e.play()):r||(r=!0,e.pause()))};return n>0&&e.addEventListener("timeupdate",s),()=>{e&&n>0&&e.removeEventListener("timeupdate",s)}},[n,d,u]),a.useEffect(()=>{const e=i.current;if(!e)return;const r=()=>{d&&(e.currentTime=u||0,e.play())};return e.addEventListener("ended",r),()=>{e&&e.removeEventListener("ended",r)}},[d,u]);const m=c.buildMediaURL(t.url);return E("audio",{className:"stAudio","data-testid":"stAudio",ref:i,controls:!0,autoPlay:p&&!l,src:m,style:{width:f}})}export{T as default};
