'use strict';
const AIOVGTemplate = document.createElement( 'template' );
AIOVGTemplate.innerHTML = `
`;
class AIOVGBaseElement extends HTMLElement{constructor(){super();let e=this.attachShadow({mode:"open"});this.shadowRoot.appendChild(AIOVGTemplate.content.cloneNode(!0)),this.$root=e.querySelector("#root"),this.$posterImage=e.querySelector("#posterimage"),this.$playButton=e.querySelector("#playbutton"),this.$cookieConsentButton=e.querySelector("#cookieconsent-button"),this._isRendered=!1,this._isCookieConsentLoaded=!1,this._isPosterImageLoaded=!1,this._isIframeLoaded=!1,this._forceIframeElement=navigator.vendor.includes("Apple")||navigator.userAgent.includes("Mobi"),this._intersectionObserver=null,this._isInViewport=!1}connectedCallback(){if(!this.src)return!1;if(this.lazyLoading||(this._forceIframeElement=!0),this.poster||(this._forceIframeElement=!0),!this._forceIframeElement){let e=new URL(this.src),t=new URLSearchParams(e.search),s=t.has("autoplay")&&(1==t.get("autoplay")||!0==t.get("autoplay"));s&&(this._forceIframeElement=!0)}this._render(),this.addEventListener("pointerover",()=>this._warmConnections(),{once:!0}),this.addEventListener("click",()=>this._addIframe(!0))}disconnectedCallback(){this.removeEventListener("pointerover",()=>this._warmConnections(),{once:!0}),this.removeEventListener("click",()=>this._addIframe(!0))}static get observedAttributes(){return["title","ratio","cookieconsent"]}attributeChangedCallback(e,t,s){if(t==s)return!1;switch(e){case"title":s?this.$posterImage.setAttribute("alt",s):this.$posterImage.setAttribute("alt","");break;case"ratio":s&&(this.$root.style.paddingBottom=`${parseFloat(s)}%`);break;case"cookieconsent":this._isRendered||(this._removeClass("cookieconsent"),this._render())}}get title(){return this.getAttribute("title")||""}get src(){let e=this.getAttribute("src")||"";return AIOVGBaseElement.isValidUrl(e)?e:""}get poster(){let e=this.getAttribute("poster")||"";return AIOVGBaseElement.isValidUrl(e)?e:""}get postId(){return parseInt(this.getAttribute("post_id")||0)}get postType(){return this.getAttribute("post_type")||""}get ajaxUrl(){let e=this.getAttribute("ajax_url")||"";return AIOVGBaseElement.isValidUrl(e)?e:""}get ajaxNonce(){return this.getAttribute("ajax_nonce")||""}get lazyLoading(){return this.hasAttribute("lazyloading")}get cookieConsent(){return this.hasAttribute("cookieconsent")}set cookieConsent(e){let t=Boolean(e);t?this.setAttribute("cookieconsent",""):this.removeAttribute("cookieconsent")}_render(){return(this._isRendered,this.lazyLoading&&!this._isInViewport)?(this._initIntersectionObserver(),!1):this.cookieConsent?(this._addCookieConsent(),!1):void(this._isRendered=!0,this._forceIframeElement?(this._warmConnections(),this._addIframe()):this._addPosterImage())}_addCookieConsent(){if(this._isCookieConsentLoaded)return!1;this._isCookieConsentLoaded=!0,this._addPosterImage(),this._addClass("cookieconsent"),this.$cookieConsentButton.addEventListener("click",()=>this._onCookieConsent())}_onCookieConsent(){this._isRendered=!0,this._removeClass("cookieconsent"),this.cookieConsent=!1,this._warmConnections(),this._addIframe(!0),this._setCookie()}_addPosterImage(){if(this._isPosterImageLoaded)return!1;this._isPosterImageLoaded=!0,this.poster&&(this.$posterImage.src=this.poster)}_addIframe(e=!1){if(this._isIframeLoaded)return!1;this._isIframeLoaded=!0;let t=document.createElement("iframe");if(t.width=560,t.height=315,t.title=this.title,t.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",t.allowFullscreen=!0,e){let s=new URL(this.src),o=s.searchParams;o.set("autoplay",1),s.search=o.toString(),t.src=s.toString()}else t.src=this.src;this.$root.append(t),this._addClass("initialized"),this._updateViewsCount(),this.dispatchEvent(new CustomEvent("AIOVGIframeLoaded",{detail:"iframe.loaded",bubbles:!0,cancelable:!0}))}_initIntersectionObserver(){if(this._intersectionObserver)return!1;this._intersectionObserver=new IntersectionObserver((e,t)=>{e.forEach(e=>{e.isIntersecting?(this._isInViewport=!0,this._render(),this._isRendered&&t.unobserve(this)):this._isInViewport=!1})},{root:null,rootMargin:"0px",threshold:0}),this._intersectionObserver.observe(this)}_hasClass(e){return this.$root.classList.contains(e)}_addClass(e){this.$root.classList.add(e)}_removeClass(e){this.$root.classList.remove(e)}async _updateViewsCount(){if("aiovg_videos"==this.postType&&this.ajaxUrl){let e=new FormData;e.append("action","aiovg_update_views_count"),e.append("post_id",this.postId),e.append("security",this.ajaxNonce),fetch(this.ajaxUrl,{method:"POST",body:e})}}async _setCookie(){try{if(this.ajaxUrl){let e=new FormData;e.append("action","aiovg_set_cookie"),e.append("security",this.ajaxNonce),fetch(this.ajaxUrl,{method:"POST",body:e})}let t=document.querySelectorAll(".aiovg-player-element[cookieconsent]");for(let s=0;s-1?AIOVGBaseElement.addPrefetch("preconnect","https://www.youtube-nocookie.com"):AIOVGBaseElement.addPrefetch("preconnect","https://www.youtube.com"),AIOVGBaseElement.addPrefetch("preconnect","https://www.google.com"),AIOVGBaseElement.addPrefetch("preconnect","https://googleads.g.doubleclick.net"),AIOVGBaseElement.addPrefetch("preconnect","https://static.doubleclick.net"),window.AIOVGYouTubeIsPreconnected=!0}}class AIOVGVimeoElement extends AIOVGBaseElement{constructor(){super(),this._addClass("vimeo")}_warmConnections(){if(window.AIOVGVimeoIsPreconnected)return!1;AIOVGBaseElement.addPrefetch("preconnect","https://i.vimeocdn.com"),AIOVGBaseElement.addPrefetch("preconnect","https://player.vimeo.com"),window.AIOVGVimeoIsPreconnected=!0}}class AIOVGDailymotionElement extends AIOVGBaseElement{constructor(){super(),this._addClass("dailymotion")}_warmConnections(){if(window.AIOVGDailymotionIsPreconnected)return!1;AIOVGBaseElement.addPrefetch("preconnect","https://s1.dmcdn.net"),AIOVGBaseElement.addPrefetch("preconnect","https://s2.dmcdn.net"),AIOVGBaseElement.addPrefetch("preconnect","https://www.dailymotion.com"),window.AIOVGDailymotionIsPreconnected=!0}}class AIOVGIframeElement extends AIOVGBaseElement{constructor(){super(),this._forceIframeElement=!0}}window.AIOVGYouTubeIsPreconnected=!1,window.AIOVGVimeoIsPreconnected=!1,window.AIOVGDailymotionIsPreconnected=!1,document.addEventListener("DOMContentLoaded",function(){customElements.define("aiovg-youtube",AIOVGYouTubeElement),customElements.define("aiovg-vimeo",AIOVGVimeoElement),customElements.define("aiovg-dailymotion",AIOVGDailymotionElement),customElements.define("aiovg-embed",AIOVGIframeElement)});