import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{i as n,t as r}from"./emotion-styled.browser.esm.BYv_Qzcq.js";import{t as i}from"./loglevel.xXLtmX_e.js";import{V as a}from"./protobuf.Ckf-kxfD.js";import{t as o}from"./useCrossOriginAttribute.K-ObP1Bx.js";var s=e(t(),1),c=e(i(),1),l=r(`iframe`,{target:`eers5hb0`})(({theme:e})=>({colorScheme:`normal`,border:`none`,padding:e.spacing.none,margin:e.spacing.none,width:`100%`,aspectRatio:`16 / 9`,borderRadius:e.radii.default,overflow:`hidden`})),u=r(`video`,{target:`eers5hb1`})(({theme:e})=>({display:`block`,width:`100%`,borderRadius:e.radii.default,overflow:`hidden`})),d=(0,c.getLogger)(`Video`);function f({element:e,endpoints:t,elementMgr:r}){let i=(0,s.useRef)(null),{type:c,url:f,startTime:p,subtitles:m,endTime:h,loop:g,autoplay:_,muted:v}=e,y=o(f),b=(0,s.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]),x=(0,s.useMemo)(()=>JSON.stringify(m?m.map(e=>t.buildMediaURL(`${e.url}`)):[]),[m,t]);return(0,s.useEffect)(()=>{let e=JSON.parse(x);e.length!==0&&e.forEach(e=>{t.checkSourceUrlResponse(e,`Video Subtitle`)})},[x,t]),(0,s.useEffect)(()=>{i.current&&(i.current.currentTime=p)},[p]),(0,s.useEffect)(()=>{let t=i.current,n=()=>{t&&(t.currentTime=e.startTime)};return t&&t.addEventListener(`loadedmetadata`,n),()=>{t&&t.removeEventListener(`loadedmetadata`,n)}},[e]),(0,s.useEffect)(()=>{let e=i.current;if(!e)return;let t=!1,n=()=>{h>0&&e.currentTime>=h&&(g?(e.currentTime=p||0,e.play()):t||(t=!0,e.pause()))};return h>0&&e.addEventListener(`timeupdate`,n),()=>{e&&h>0&&e.removeEventListener(`timeupdate`,n)}},[h,g,p]),(0,s.useEffect)(()=>{let e=i.current;if(!e)return;let t=()=>{g&&(e.currentTime=p||0,e.play())};return e.addEventListener(`ended`,t),()=>{e&&e.removeEventListener(`ended`,t)}},[g,p]),c===a.Type.YOUTUBE_IFRAME?n(l,{className:`stVideo`,"data-testid":`stVideo`,title:f,src:(e=>{let t=new URL(e);if(p&&!isNaN(p)&&t.searchParams.append(`start`,p.toString()),h&&!isNaN(h)&&t.searchParams.append(`end`,h.toString()),g){t.searchParams.append(`loop`,`1`);let e=t.pathname.split(`/`).pop();e&&t.searchParams.append(`playlist`,e)}return _&&t.searchParams.append(`autoplay`,`1`),v&&t.searchParams.append(`mute`,`1`),t.toString()})(f),allow:`autoplay; encrypted-media`,allowFullScreen:!0}):n(u,{className:`stVideo`,"data-testid":`stVideo`,ref:i,controls:!0,muted:v,autoPlay:_&&!b,src:t.buildMediaURL(f),crossOrigin:y,onError:e=>{let n=e.currentTarget.src;d.error(`Client Error: Video source error - ${n}`),t.sendClientErrorToHost(`Video`,`Video source failed to load`,`onerror triggered`,n)},children:m?.map((e,r)=>n(`track`,{kind:`captions`,src:t.buildMediaURL(`${e.url}`),label:`${e.label}`,default:r===0,"data-testid":`stVideoSubtitle`},r))})}var p=(0,s.memo)(f);export{p as default};