import{o as e}from"./chunk.DuxOD-Sk.js";import{r as t}from"./emotion-is-prop-valid.esm.DV_OErv-.js";import{c as n,t as r}from"./emotion-styled.browser.esm.BPUx6WuE.js";import{t as i}from"./loglevel.H4SN4KQm.js";import{t as a}from"./useCrossOriginAttribute.wOZu23rZ.js";var o=e(t()),s=e(i()),c=r(`div`,{target:`e1z085g90`})(()=>({lineHeight:0})),l=r(`audio`,{target:`e1z085g91`})(({theme:e})=>({width:`100%`,height:e.sizes.minElementHeight,margin:0,padding:0})),u=(0,s.getLogger)(`Audio`);function d({element:e,endpoints:t,elementMgr:r}){let i=(0,o.useRef)(null),{startTime:s,endTime:d,loop:f,autoplay:p}=e,m=(0,o.useMemo)(()=>{if(!e.id)return!0;let t=r.getElementState(e.id,`preventAutoplay`);return t||r.setElementState(e.id,`preventAutoplay`,!0),t??!1},[e.id,r]);(0,o.useEffect)(()=>{i.current&&(i.current.currentTime=s)},[s]),(0,o.useEffect)(()=>{let t=i.current,n=()=>{t&&(t.currentTime=e.startTime)};return t&&t.addEventListener(`loadedmetadata`,n),()=>{t&&t.removeEventListener(`loadedmetadata`,n)}},[e]),(0,o.useEffect)(()=>{let e=i.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=i.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=a(e.url),g=t.buildMediaURL(e.url);return n(c,{children:n(l,{className:`stAudio`,"data-testid":`stAudio`,ref:i,controls:!0,autoPlay:p&&!m,src:g,onError:e=>{let n=e.currentTarget.src;u.error(`Client Error: Audio source error - ${n}`),t.sendClientErrorToHost(`Audio`,`Audio source failed to load`,`onerror triggered`,n)},crossOrigin:h})})}var f=(0,o.memo)(d);export{f as default};