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,autoplay:c,isHeroBanner:s,thumbnail:i}=o,m=!!i,[d,p]=e(!1),[F,b]=e(!n&&(!m||!!c)),x=()=>{d||p(!0)},f=()=>{F||b(!0)},v=t(!1),E=t(0),I=t(),L=e=>{let t=e.target;if(t&&s&&u(a)&&E.current>0){let e=parseFloat((E.current/100*5).toFixed(2));clearInterval(I.current),I.current=setInterval(()=>{let r=parseFloat(t.getCurrentTime().toFixed(2)),u=parseFloat((E.current-r).toFixed(2));u<=parseFloat((1.5*e).toFixed(2))&&t.seekTo(0)},1e3*e)}};return r(()=>()=>{I.current&&(clearInterval(I.current),v.current=!1)},[l,a]),{iframe:F,addIframe:f,intervalPlay:L,warmConnections:x,isVideoStarted:v,videoDuration:E}};export{useLiteYoutubeEmbed as default,useLiteYoutubeEmbed};
