function addPrefetch(e,t,n){let r=document.createElement("link");r.rel=e,r.href=t,n&&(r.as=n),r.crossOrigin="true",document.head.append(r)}window.ytPreconnected=!1;const warmConnections=()=>{window.ytPreconnected||(addPrefetch("preconnect","https://www.youtube.com"),addPrefetch("preconnect","https://www.google.com"),window.ytPreconnected=!0)};function onPlayerReady(e){/iPad|iPhone|iPod|android|webOS|Windows Phone/i.test(navigator.userAgent)&&e.target.mute()}const addIframe=e=>{window.requestIdleCb(()=>{let t=e.getAttribute("id"),n=t.split("-lyt-"),r=encodeURIComponent(n[0]);e.parentNode.classList.add("lyt-activated"),new YT.Player(t,{width:"100%",height:"100%",videoId:r,playerVars:{autoplay:1,playsinline:1,enablejsapi:1},events:{onReady:onPlayerReady}})})},initListeners=e=>{e.addEventListener("pointerover",warmConnections,{once:!0}),e.addEventListener("click",()=>addIframe(e),{once:!0})},initIntersectionObserver=e=>{if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window){let t={root:null,rootMargin:"0px",threshold:0},n=new IntersectionObserver((e,t)=>{e.forEach(e=>{e.isIntersecting&&(e.target.className.includes("auto")?(warmConnections(),addIframe(e.target)):initListeners(e.target),t.unobserve(e.target))})},t);n.observe(e)}},initLiteYoutube=()=>{window.lytVideos.forEach(e=>{e.className.includes("lyt-lazy")?initIntersectionObserver(e):initListeners(e)})};function onYouTubeIframeAPIReady(){window.requestIdleCb(()=>initLiteYoutube())}const loadYoutubeIframeAPI=()=>{let e=document.createElement("script");e.src="https://www.youtube.com/iframe_api",e.async=!0;let t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)};window.lytVideos=[],window.requestIdleCb(()=>{window.lytVideos=Array.from(document.body.querySelectorAll(".lyt-player")),window.lytVideos.length>0&&loadYoutubeIframeAPI()});
