import{Ia as e,Ja as t,Ka as n,Qa as r,io as i,lr as a,vr as o}from"./index.dkY5s53S.js";var s=i(r(),1),c=i(n(),1),l=o(`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=o(`video`,{target:`eers5hb1`})(({theme:e})=>({display:`block`,width:`100%`,borderRadius:e.radii.default,overflow:`hidden`})),d=(0,c.getLogger)(`Video`);function f({element:n,endpoints:r,elementMgr:i}){let o=(0,s.useRef)(null),{type:c,url:f,startTime:p,subtitles:m,endTime:h,loop:g,autoplay:_,muted:v}=n,y=a(f),b=(0,s.useMemo)(()=>{if(!n.id)return!0;let e=i.getElementState(n.id,`preventAutoplay`);return e||i.setElementState(n.id,`preventAutoplay`,!0),e??!1},[n.id,i]),x=(0,s.useMemo)(()=>JSON.stringify(m?m.map(e=>r.buildMediaURL(`${e.url}`)):[]),[m,r]);return(0,s.useEffect)(()=>{let e=JSON.parse(x);e.length!==0&&e.forEach(e=>{r.checkSourceUrlResponse(e,`Video Subtitle`)})},[x,r]),(0,s.useEffect)(()=>{o.current&&(o.current.currentTime=p)},[p]),(0,s.useEffect)(()=>{let e=o.current,t=()=>{e&&(e.currentTime=n.startTime)};return e&&e.addEventListener(`loadedmetadata`,t),()=>{e&&e.removeEventListener(`loadedmetadata`,t)}},[n]),(0,s.useEffect)(()=>{let e=o.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=o.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===e.Type.YOUTUBE_IFRAME?t(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}):t(u,{className:`stVideo`,"data-testid":`stVideo`,ref:o,controls:!0,muted:v,autoPlay:_&&!b,src:r.buildMediaURL(f),crossOrigin:y,onError:e=>{let t=e.currentTarget.src;d.error(`Client Error: Video source error - ${t}`),r.sendClientErrorToHost(`Video`,`Video source failed to load`,`onerror triggered`,t)},children:m?.map((e,n)=>t(`track`,{kind:`captions`,src:r.buildMediaURL(`${e.url}`),label:`${e.label}`,default:n===0,"data-testid":`stVideoSubtitle`},n))})}var p=(0,s.memo)(f);export{p as default};