!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(){var e;const{dismiss:t=0,anchor:s}=this.element.dataset,{id:n}=this.element;if(t<=0||!n||s)return!1;const o=new Date,i=JSON.parse(null!==(e=localStorage.getItem(this.storageKey))&&void 0!==e?e:"[]")||[];if(i.some((e=>e.modalID===n)))return!1;const l=864e5*parseInt(t),a={expiry:o.getTime()+l,modalID:n};localStorage.setItem(this.storageKey,JSON.stringify([...i,a]))}isItemDismissed(){var e;const{id:t}=this.element,{dismiss:s=0}=this.element.dataset,n=JSON.parse(null!==(e=localStorage.getItem(this.storageKey))&&void 0!==e?e:"[]")||[],o=n.filter((e=>e.modalID===t));if(0===o.length)return!1;if(0===parseInt(s)&&0<o.length)return!0;const i=o[0],l=new Date;if(i.expiry>l.getTime())return!0;const a=n.filter((e=>e!==o[0]));return localStorage.setItem(this.storageKey,JSON.stringify(a)),!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(null!=e?e:"0")>=this.getScrolledPercent())return!1;this.openModal()}))}bindOnLoad(){const{time:e}=this.element.dataset;setTimeout((()=>{this.openModal()}),1e3*parseInt(null!=e?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())}();