import{r as n,u as x,a as y,j as m,c as f,l as A}from"./index-D3uELfdo.js";const h=f("div",{target:"exyuj7n1"})(()=>({lineHeight:0}),""),L=f("audio",{target:"exyuj7n0"})(({theme:r})=>({width:"100%",height:r.sizes.minElementHeight,margin:0,padding:0}),""),j=A.getLogger("Audio");function S({element:r,endpoints:d,elementMgr:i}){const s=n.useRef(null),{startTime:o,endTime:u,loop:a,autoplay:g}=r,p=n.useMemo(()=>{if(!r.id)return!0;const e=i.getElementState(r.id,"preventAutoplay");return e||i.setElementState(r.id,"preventAutoplay",!0),e??!1},[r.id,i]);n.useEffect(()=>{s.current&&(s.current.currentTime=o)},[o]),n.useEffect(()=>{const e=s.current,t=()=>{e&&(e.currentTime=r.startTime)};return e&&e.addEventListener("loadedmetadata",t),()=>{e&&e.removeEventListener("loadedmetadata",t)}},[r]),n.useEffect(()=>{const e=s.current;if(!e)return;let t=!1;const l=()=>{u>0&&e.currentTime>=u&&(a?(e.currentTime=o||0,e.play()):t||(t=!0,e.pause()))};return u>0&&e.addEventListener("timeupdate",l),()=>{e&&u>0&&e.removeEventListener("timeupdate",l)}},[u,a,o]),n.useEffect(()=>{const e=s.current;if(!e)return;const t=()=>{a&&(e.currentTime=o||0,e.play())};return e.addEventListener("ended",t),()=>{e&&e.removeEventListener("ended",t)}},[a,o]);const c=x(r.url),E=y(c),v=d.buildMediaURL(c),T=e=>{const t=e.currentTarget.src;j.error(`Client Error: Audio source error - ${t}`),d.sendClientErrorToHost("Audio","Audio source failed to load","onerror triggered",t)};return m.jsx(h,{children:m.jsx(L,{className:"stAudio","data-testid":"stAudio",ref:s,controls:!0,autoPlay:g&&!p,src:v,onError:T,crossOrigin:E})})}const H=n.memo(S);export{H as default};
