(()=>{"use strict";let e=null,t=null;function n(e,t,n){if("mp4"===e){const e=document.createElement("video");return e.className="flexa-video-popup__video",e.setAttribute("controls",""),e.setAttribute("playsinline",""),n&&e.setAttribute("autoplay",""),e.src=t,e}const o=document.createElement("iframe");return o.className="flexa-video-popup__iframe",o.src=function(e,t,n){if(!n)return t;const o=-1===t.indexOf("?")?"?":"&";return"vimeo"===e?`${t}${o}autoplay=1&muted=1`:`${t}${o}autoplay=1`}(e,t,n),o.setAttribute("allow","autoplay; fullscreen; picture-in-picture; encrypted-media"),o.setAttribute("allowfullscreen",""),o.setAttribute("frameborder","0"),o.setAttribute("title","Video"),o}function o(){e&&(t&&(t.textContent=""),e.setAttribute("hidden",""),e.classList.remove("is-open"),e=null,t=null,document.removeEventListener("keydown",i))}function i(e){"Escape"===e.key&&o()}function r(r){const a=r.querySelector(".flexa-video-popup__trigger");if(!a)return;const l=r.querySelector(".flexa-video-popup__image[data-vp-fallback]");l&&function(e){const t=e.getAttribute("data-vp-fallback");if(!t)return;const n=()=>{e.naturalWidth>0&&e.naturalWidth<=120&&(e.removeAttribute("data-vp-fallback"),e.src=t)};e.complete?n():e.addEventListener("load",n,{once:!0})}(l);const u=r.getAttribute("data-video-type")||"youtube",d=r.getAttribute("data-video-src")||"",c="0"!==r.getAttribute("data-autoplay");if("inline"===r.getAttribute("data-display-mode"))return void a.addEventListener("click",e=>{if(e.preventDefault(),!d)return;const t=document.createElement("div");t.className="flexa-video-popup__trigger flexa-video-popup__media is-playing",t.appendChild(n(u,d,c)),a.replaceWith(t)},{once:!0});const p=r.querySelector(".flexa-video-popup__lightbox");if(!p)return;const s=p.querySelector(".flexa-video-popup__player"),f=p.querySelector(".flexa-video-popup__backdrop"),v=p.querySelector(".flexa-video-popup__close");s&&(a.addEventListener("click",r=>{r.preventDefault(),d&&(o(),s.textContent="",s.appendChild(n(u,d,c)),p.removeAttribute("hidden"),p.classList.add("is-open"),e=p,t=s,document.addEventListener("keydown",i))}),f&&f.addEventListener("click",o),v&&v.addEventListener("click",o))}function a(){document.querySelectorAll(".flexa-video-popup").forEach(r)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",a):a()})();