document.addEventListener("UAGModalEditor",function(e){UAGBModal.init(".uagb-block-"+e.detail.block_id,!0,{...e.detail})}),document.addEventListener("AstraQuickViewForModal",function(e){UAGBModal.init(e.detail.class_name,!1,{...e.detail})}),window.UAGBModal={_getVariables(e){var o=UAGBModal._getDocumentElement();return{document_element:o,modalWrapper:o.querySelector(e),modalPopup:o.querySelector(e+".uagb-modal-popup"),closeModal:o.querySelector(e+" .uagb-modal-popup-close"),bodyWrap:o.querySelector("body"),pageTemplate:o.getElementsByClassName("block-editor-iframe__body")}},_addTriggers(t,a={},l){var e=UAGBModal._getVariables(t)["document_element"],e=e.querySelectorAll(t);if(e&&0!==e.length)for(const c of e){const i=c?.querySelector(".uagb-modal-popup");i&&(document.addEventListener("keyup",function(e){var o;i.classList.contains("active")&&(o=c.dataset.escpress,27===e.keyCode)&&"enable"===o&&(UAGBModal._hide(t,i),"button"===a?.modalTrigger)&&l?.focus()}),i.querySelector(t+" .uagb-modal-popup-close").addEventListener("click",function(){"automatic"===a?.modalTrigger&&a?.enableCookies&&"close-action"===a?.setCookiesOn&&UAGBModal._setPopupCookie(t,a.hideForDays),UAGBModal._hide(t,i),"button"===a?.modalTrigger&&l?.focus()}))}},_exitIntent(o,t,a,l){document.addEventListener("mouseleave",function(e){20<e.clientY||UAGBModal._canShow(o,l)&&a&&UAGBModal._show(o,t)})},_canShow(e,o={}){var t=UAGBModal._getCookie("uagb-block-popup-"+e);if(o?.enableCookies){if(void 0!==t&&"automatic"===o?.modalTrigger)return!1}else document.cookie=`uagb-block-popup-${e};max-age=-1`;t=UAGBModal._getVariables(e).modalPopup;return!t||!t.classList.contains("active")},_show(o,t){var e,{bodyWrap:a,pageTemplate:l,modalWrapper:c}=UAGBModal._getVariables(o),i=document.getElementsByClassName("edit-site");t&&!t.classList.contains("active")&&(t.classList.add("active"),(e=document.createElement("button")).style.position="absolute",e.style.opacity="0",(e=t.insertBefore(e,t.firstChild)).focus(),e.remove(),!a||a.classList.contains("hide-scroll")||i?.length||l?.length||a.classList.contains("wp-admin")||a.classList.add("hide-scroll"),"enable"===c.dataset.overlayclick)&&t.addEventListener("click",function(e){t.classList.contains("active")&&!t.querySelector(".uagb-modal-popup-wrap").contains(e.target)&&UAGBModal._hide(o,t)})},_hide(e,o){var{modalPopup:e,bodyWrap:t}=UAGBModal._getVariables(e);o&&o.classList.contains("active")&&o.classList.remove("active"),e&&e.classList.contains("active")&&e.classList.remove("active"),t&&t.classList.contains("hide-scroll")&&UAGBModal.closeModalScrollCheck(t)},_getDocumentElement(){let e=document;var o=document.querySelectorAll('iframe[name="editor-canvas"]');return e=o?.length&&(o=o?.[0]?.contentWindow?.document||o?.[0]?.contentDocument)?o:e},_afterOpen(e,o){o?.enableCookies&&"page-refresh"===o?.setCookiesOn&&UAGBModal._setPopupCookie(e,o?.hideForDays)},_getCookie(e){e=("; "+document.cookie).split("; "+e+"=");if(2===e.length)return e.pop().split(";").shift()},_setPopupCookie(e,o){void 0===UAGBModal._getCookie("uagb-block-popup-"+e)&&void 0!==o&&(document.cookie=`uagb-block-popup-${e}=true; expires=`+new Date(Date.now()+24*o*60*60*1e3).toUTCString())},triggerAction(t,a,l,c=!1){const{document_element:i,bodyWrap:s}=UAGBModal._getVariables(t);var e=i.querySelectorAll(t);if(e?.length)for(const n of e)if(a=a&&c?a:n.querySelector(".uagb-modal-trigger")){let o=n?.querySelector(".uagb-modal-popup");const r=n.dataset.overlayclick;a.style.pointerEvents="auto";let e=!0;!o&&c&&(o=i.querySelector(".uagb-modal-popup"+t),e=!1),o&&(!l&&e&&document.body?.appendChild(o),a.addEventListener("click",function(e){e.preventDefault(),UAGBModal._show(t,o)}),"disable"!==r)&&o.addEventListener("click",function(e){"enable"===r&&o.classList.contains("active")&&!o.querySelector(".uagb-modal-popup-wrap").contains(e.target)&&UAGBModal._hide(t,o),s&&s.classList.contains("hide-scroll")&&UAGBModal.closeModalScrollCheck(s)})}},init(o,t,e){const{document_element:a,modalWrapper:l}=UAGBModal._getVariables(o);var{modalTrigger:c,cssClass:i,cssID:s,exitIntent:n,showAfterSeconds:r,noOfSecondsToShow:d}=e="string"==typeof e?JSON.parse(e):e;if(l){var u=l.querySelector(".uagb-modal-trigger");UAGBModal._addTriggers(o,e,u);const g=l.querySelector(".uagb-modal-popup");switch(c){case"custom-class":i&&0<(p=a.querySelectorAll("."+i)).length&&p.forEach(function(e){UAGBModal.triggerAction(o,e,t,!0)});break;case"custom-id":t&&UAGBModal._show(o,g),s&&(p=a.querySelector("#"+s))&&UAGBModal.triggerAction(o,p,t,!0);break;case"automatic":var p=r?1e3*parseInt(d):1;UAGBModal._canShow(o,e)&&!n&&setTimeout(function(){UAGBModal._show(o,g),UAGBModal._afterOpen(o,e),"enable"===l.dataset.overlayclick&&g.addEventListener("click",function(e){g.classList.contains("active")&&!g.querySelector(".uagb-modal-popup-wrap").contains(e.target)&&UAGBModal._hide(o,g)})},p),UAGBModal._exitIntent(o,g,n,e);break;default:UAGBModal.triggerAction(o,u,t,!1)}}},closeModalScrollCheck(e){0===document.querySelectorAll(".uagb-modal-popup.active").length&&e.classList.remove("hide-scroll")}};