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