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