import{n as N,r as i,bi as b,j as l}from"./index.DmrHunjf.js";const w=N("iframe",{target:"eymnmwl0"})(({theme:a})=>({colorScheme:"normal",border:"none",padding:a.spacing.none,margin:a.spacing.none,width:"100%",aspectRatio:"16 / 9"})),P={width:"100%"};function R({element:a,endpoints:f,elementMgr:c}){const n=i.useRef(null),{type:v,url:p,startTime:o,subtitles:m,endTime:d,loop:u,autoplay:E,muted:T}=a,h=i.useMemo(()=>{if(!a.id)return!0;const e=c.getElementState(a.id,"preventAutoplay");return e||c.setElementState(a.id,"preventAutoplay",!0),e??!1},[a.id,c]);i.useEffect(()=>{n.current&&(n.current.currentTime=o)},[o]),i.useEffect(()=>{const e=n.current,t=()=>{e&&(e.currentTime=a.startTime)};return e&&e.addEventListener("loadedmetadata",t),()=>{e&&e.removeEventListener("loadedmetadata",t)}},[a]),i.useEffect(()=>{const e=n.current;if(!e)return;let t=!1;const s=()=>{d>0&&e.currentTime>=d&&(u?(e.currentTime=o||0,e.play()):t||(t=!0,e.pause()))};return d>0&&e.addEventListener("timeupdate",s),()=>{e&&d>0&&e.removeEventListener("timeupdate",s)}},[d,u,o]),i.useEffect(()=>{const e=n.current;if(!e)return;const t=()=>{u&&(e.currentTime=o||0,e.play())};return e.addEventListener("ended",t),()=>{e&&e.removeEventListener("ended",t)}},[u,o]);const S=e=>{const{startTime:t,endTime:s,loop:L,autoplay:V,muted:g}=a,r=new URL(e);if(t&&!isNaN(t)&&r.searchParams.append("start",t.toString()),s&&!isNaN(s)&&r.searchParams.append("end",s.toString()),L){r.searchParams.append("loop","1");const y=r.pathname.split("/").pop();y&&r.searchParams.append("playlist",y)}return V&&r.searchParams.append("autoplay","1"),g&&r.searchParams.append("mute","1"),r.toString()};return v===b.Type.YOUTUBE_IFRAME?l(w,{className:"stVideo","data-testid":"stVideo",title:p,src:S(p),allow:"autoplay; encrypted-media",allowFullScreen:!0}):l("video",{className:"stVideo","data-testid":"stVideo",ref:n,controls:!0,muted:T,autoPlay:E&&!h,src:f.buildMediaURL(p),style:P,crossOrigin:void 0,children:m&&m.map((e,t)=>l("track",{kind:"captions",src:f.buildMediaURL(`${e.url}`),label:`${e.label}`,default:t===0},t))})}const A=i.memo(R);export{A as default};
