import{useState as e,useRef as t,useEffect as r}from"react";import{isSettingLoop as u}from"../common/helpers.js";let useLiteYoutubeEmbed=(o,a,l)=>{let{lazy:n,isHeroBanner:c}=o,[s,i]=e(!1),[m,d]=e(!n),p=()=>{s||i(!0)},F=()=>{m||d(!0)},b=t(!1),x=t(0),f=t(),v=e=>{let t=e.target;if(t&&c&&u(a)&&x.current>0){let e=parseFloat((x.current/100*5).toFixed(2));clearInterval(f.current),f.current=setInterval(()=>{let r=parseFloat(t.getCurrentTime().toFixed(2)),u=parseFloat((x.current-r).toFixed(2));u<=parseFloat((1.5*e).toFixed(2))&&t.seekTo(0)},1e3*e)}};return r(()=>()=>{f.current&&(clearInterval(f.current),b.current=!1)},[l,a]),{iframe:m,addIframe:F,intervalPlay:v,warmConnections:p,isVideoStarted:b,videoDuration:x}};export{useLiteYoutubeEmbed as default,useLiteYoutubeEmbed};
