(()=>{class e{constructor(e){if(!e||!e?.dataset?.videoId)return;this.element=e,this.videoId=this.element.dataset.videoId;const t=this.element.parentNode.classList;this.needsYTApi=/Mobi/i.test(window.navigator.userAgent)||/Apple/i.test(navigator.vendor),this.forceIframe=t.contains("force-iframe")||t.contains("ifr-unsupported")&&/iPhone/.test(window.navigator.userAgent),this.init()}init(){this.forceIframe&&new IntersectionObserver((e,t)=>{e.forEach(e=>{e.isIntersecting&&(e.target.classList.contains("is-activated")||(this.createIframe(this.getParams(e.target)),e.target.classList.add("is-activated"),t.unobserve(e.target)))})},{rootMargin:"0px"}).observe(this.element),this.element.addEventListener("click",()=>{if(this.element.classList.contains("is-activated"))return;this.element.classList.add("is-activated");const e=this.getParams(this.element);this.needsYTApi?this.playVideo(Object.fromEntries(e.entries())):this.createIframe(e).focus()},{once:!0})}getParams(e){const t=new URLSearchParams(e?.dataset?.params?JSON.parse(e.dataset.params):{});return this.needsYTApi||this.forceIframe||t.append("autoplay","1"),t.append("playsinline","1"),t}async playVideo(e){this.loadYTAPI(),await this.ytApiPromise;const t=document.createElement("div");this.element.append(t);const a=this.videoId;new YT.Player(t,{width:"100%",videoId:a,playerVars:e,events:{onReady:e=>e.target.playVideo()}})}loadYTAPI(){window?.YT?.Player||(this.ytApiPromise=new Promise((e,t)=>{var a=document.createElement("script");a.src="https://www.youtube.com/iframe_api",a.async=!0,a.onload=()=>{YT.ready(e)},a.onerror=t,this.element.append(a)}))}createIframe(e){var t;const a=document.createElement("iframe");return a.width=560,a.height=315,a.title=null!==(t=this.element?.dataset?.title)&&void 0!==t?t:"Play",a.allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",a.allowFullscreen=!0,a.src=`https://www.youtube-nocookie.com/embed/${encodeURIComponent(this.videoId)}?${e.toString()}`,this.element.append(a),a}}var t;t=()=>{document.querySelectorAll(".wp-block-boldblocks-youtube-block .yb-player").forEach(t=>new e(t))},"loading"!==document.readyState?t():document.addEventListener("DOMContentLoaded",t)})();