class LiteYTEmbed extends HTMLElement{connectedCallback(){this.addEventListener("pointerover",LiteYTEmbed.warmConnections,{once:!0}),this.addEventListener("click",this.addIframe),this.needsYTApiForAutoplay=navigator.vendor.includes("Apple")||navigator.userAgent.includes("Mobi"),this.videoId=this.getAttribute("videoid"),this.credit=this.getAttribute("credit");let e=this.querySelector(".lty-playbtn");if(this.playLabel=e&&e.textContent.trim()||this.getAttribute("playlabel")||"Play",e||(e=document.createElement("button"),e.type="button",e.classList.add("lty-playbtn"),e.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">\n            <defs />\n            <g fill="none" fill-rule="evenodd">\n                <circle cx="50" cy="50" r="48.5" stroke="#FFF" stroke-width="3" />\n                <path fill="#FFF" fill-rule="nonzero" d="M40 31v38l30-19z" />\n            </g>\n        </svg><span class="lyt-visually-hidden">Play Video</span>',this.append(e)),!e.textContent){const t=document.createElement("span");t.className="lyt-visually-hidden",t.textContent=this.playLabel,e.append(t)}if(e.removeAttribute("href"),this.style.backgroundImage||(this.style.backgroundImage=`url("https://i.ytimg.com/vi/${this.videoId}/hqdefault.jpg")`),null!==this.credit){var t=document.createElement("cite");t.classList.add("lty-cite"),t.textContent=this.credit,this.append(t)}}static addPrefetch(e,t,i){const n=document.createElement("link");n.rel=e,n.href=t,i&&(n.as=i),document.head.append(n)}static warmConnections(){LiteYTEmbed.preconnected||(LiteYTEmbed.addPrefetch("preconnect","https://www.youtube.com"),LiteYTEmbed.addPrefetch("preconnect","https://www.google.com"),LiteYTEmbed.preconnected=!0)}fetchYTPlayerApi(){window.YT||window.YT&&window.YT.Player||(this.ytApiPromise=new Promise(((e,t)=>{var i=document.createElement("script");i.src="https://www.youtube.com/iframe_api",i.async=!0,i.onload=t=>{YT.ready(e)},i.onerror=t,this.append(i)})))}async addYTPlayerIframe(e){this.fetchYTPlayerApi(),await this.ytApiPromise;const t=document.createElement("div");this.append(t);const i=Object.fromEntries(e.entries());new YT.Player(t,{width:"100%",videoId:this.videoId,playerVars:i,events:{onReady:e=>{e.target.playVideo()}}})}async addIframe(){const e=setInterval((function(){window.plausible&&(clearInterval(e),window.plausible("articlevideoview",{u:location.href,props:{Platform:"STV News Website","Video View":"Article Video"}}))}),100);if(this.style.backgroundImage="none",this.classList.contains("lyt-activated"))return;this.classList.add("lyt-activated");const t=new URLSearchParams(this.getAttribute("params")||[]);if(t.append("autoplay","1"),t.append("playsinline","1"),t.append("modestbranding","1"),t.append("showinfo","0"),t.append("rel","0"),this.needsYTApiForAutoplay)return this.addYTPlayerIframe(t);const i=document.createElement("iframe");i.width=560,i.height=315,i.title=this.playLabel,i.allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",i.allowFullscreen=!0,i.src=`https://www.youtube.com/embed/${encodeURIComponent(this.videoId)}?${t.toString()}`,this.append(i),i.focus()}}customElements.define("lite-youtube",LiteYTEmbed);