!function(){"use strict";var e,t=class{canLock=!1;constructor(e){this.element=e,this.happened=!1,this.storageKey="otter-popup-dismiss";const{dismiss:t=0,anchor:s}=e.dataset;this.isItemDismissed()&&0<=t&&!s&&!Boolean(window.themeisleGutenberg?.isPreview)||(this.canLock=Boolean(this.element.dataset.lockScrolling),this.isDisabled()||this.init())}init(){this.bindOpen(),this.bindClose(),this.bindEscClose()}isDisabled(){const{disableOn:e}=this.element.dataset;return"mobile"===e&&window.matchMedia("(max-width: 600px)").matches}openModal(){this.element.classList.add("active"),this.happened=!0,this.lockScrolling()}closeModal(){this.element.classList.remove("active"),this.dismissModal(),this.unlockScrolling()}dismissModal(){const{dismiss:e=0,anchor:t}=this.element.dataset,{id:s}=this.element;if(e<=0||!s||t)return!1;const n=new Date,o=JSON.parse(localStorage.getItem(this.storageKey)??"[]")||[];if(o.some((e=>e.modalID===s)))return!1;const i=864e5*parseInt(e),l={expiry:n.getTime()+i,modalID:s};localStorage.setItem(this.storageKey,JSON.stringify([...o,l]))}isItemDismissed(){const{id:e}=this.element,{dismiss:t=0}=this.element.dataset,s=JSON.parse(localStorage.getItem(this.storageKey)??"[]")||[],n=s.filter((t=>t.modalID===e));if(0===n.length)return!1;if(0===parseInt(t)&&0<n.length)return!0;const o=n[0],i=new Date;if(o.expiry>i.getTime())return!0;const l=s.filter((e=>e!==n[0]));return localStorage.setItem(this.storageKey,JSON.stringify(l)),!1}bindOpen(){const{open:e}=this.element.dataset;switch(e){case"onClick":this.bindAnchors();break;case"onScroll":this.bindOpenAfterScroll();break;case"onExit":this.bindExitIntent();break;case"none":break;default:this.bindOnLoad()}}bindAnchors(){const{anchor:e}=this.element.dataset;if(!e)return!1;document.querySelectorAll(`a[href='#${e}'], #${e}`).forEach((t=>{t.addEventListener("click",(t=>{t.target?.href===`#${e}`&&t.preventDefault(),this.openModal()}))}))}bindOpenAfterScroll(){window.document.addEventListener("scroll",(()=>{if(this.happened)return!1;const{offset:e}=this.element.dataset;if(parseInt(e??"0")>=this.getScrolledPercent())return!1;this.openModal()}))}bindOnLoad(){const{time:e}=this.element.dataset;setTimeout((()=>{this.openModal()}),1e3*parseInt(e??"0"))}bindExitIntent(){document.body.addEventListener("mouseleave",(e=>{if(this.happened)return!1;0>e.clientY&&this.openModal()}))}getScrolledPercent(){const e=document.documentElement,{body:t}=document,s="scrollTop",n="scrollHeight";return(e[s]||t[s])/((e[n]||t[n])-e.clientHeight)*100}bindClose(){this.bindCloseButtons(),this.bindAnchorClose(),this.bindOverlayClosing()}bindAnchorClose(){const{anchorclose:e}=this.element.dataset;if(!e)return!1;document.querySelectorAll(`a[href='#${e}'], #${e}`).forEach((t=>{t.addEventListener("click",(t=>{t.target?.href===`#${e}`&&t.preventDefault(),this.closeModal()}))}))}bindCloseButtons(){this.element.querySelectorAll(".otter-popup__modal_header .components-button").forEach((e=>{e.addEventListener("click",(()=>{this.closeModal()}))}))}bindOverlayClosing(){const{outside:e}=this.element.dataset;if(!e)return!1;const t=this.element.querySelector(".otter-popup__modal_wrap_overlay");t?.addEventListener("click",(()=>{this.closeModal()}))}lockScrolling(){this.canLock&&document.body.classList.add("o-lock-body")}unlockScrolling(){this.canLock&&document.body.classList.remove("o-lock-body")}bindEscClose(){document.addEventListener("keydown",(e=>{"Escape"===e.key&&this.happened&&this.closeModal()}))}};e=()=>{const e=document.querySelectorAll(".wp-block-themeisle-blocks-popup, .wp-block-themeisle-blocks-modal");e.length&&e.forEach((e=>new t(e)))},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",e):e())}();