function LoyJoy(e,o){function c(){var e,n=document.createElement("script");return n.type="text/javascript",n.charset="utf-8",n.src=(e=o.version||o.tenant||"cloud","localhost"===window.location.hostname?"http://localhost:8081/widget/app.js":"https://"+e+".loyjoy.com/widget/app.js"),n}var n,t,r,i,a,d,l,u,s,m,y=function(n){o.serviceWorkerPath&&"serviceWorker"in navigator&&"PushManager"in window&&(n.callbackAfterHasWebPushCapability(!0),navigator.serviceWorker.register(o.serviceWorkerPath,{updateViaCache:"none"}).then(function(e){navigator.serviceWorker.ready.then(function(){e.pushManager.getSubscription().then(function(e){n.callbackAfterCheck(null!==e)})}).catch(function(e){n.callbackOnError(e)})}).catch(function(e){n.callbackOnError(e)}))},h=function(t){o.serviceWorkerPath&&"serviceWorker"in navigator&&"PushManager"in window&&navigator.serviceWorker.register(o.serviceWorkerPath,{updateViaCache:"none"}).then(function(n){navigator.serviceWorker.ready.then(function(){n.pushManager.getSubscription().then(function(e){e?e.unsubscribe().then(function(){p(n,t)}):p(n,t)}).catch(function(e){t.callbackOnError(e)})}).catch(function(e){t.callbackOnError(e)})}).catch(function(e){t.callbackOnError(e)})},p=function(e,c){e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:w(c.subscribeArgument.public_key)}).then(function(e){var n=g(e.getKey("auth")),t=e.endpoint,o=g(e.getKey("p256dh"));c.callbackAfterSubscribe(n,t,o)}).catch(function(e){c.callbackOnError(e)})},w=function(e){for(var n=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),t=window.atob(n),o=new Uint8Array(t.length),c=0;c<t.length;++c)o[c]=t.charCodeAt(c);return o},g=function(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e)))};if(!(navigator&&navigator.userAgent&&/bot|crawler|crawling|googlebot|robot|spider/i.test(navigator.userAgent)||navigator&&navigator.userAgent&&/MSIE 9\.0/.test(navigator.userAgent)&&window.addEventListener&&!window.atob||"onpropertychange"in document&&window.matchMedia&&/MSIE 10\.0/.test(navigator.userAgent)))if("boot"===e&&o.bot&&!document.getElementById("loyjoy-frame"))!function(){var e=document.createElement("iframe");e.id="loyjoy-frame",e.style.borderStyle="none",e.style.bottom=0,e.style.height="1px",e.style.left=0,e.style.pointerEvents="none",e.style.position="fixed",e.style.width="1px",document.body.appendChild(e),e.contentWindow.document.open("text/html","replace"),e.contentWindow.document.close();var n,t=document.querySelector('meta[name="referrer"]');t&&((n=e.contentWindow.document.createElement("meta")).name="referrer",n.content=t.content,e.contentWindow.document.head.appendChild(n)),o.widgetCallbacks={serviceWorkerCheckSubscription:y,serviceWorkerRegister:h},o.queryParams=function(){for(var e=new RegExp("[?&](loyjoy-[^&#]*=[^&#]*)","g"),n={},t=e.exec(window.location.href);null!=t;){var o=t[1].split("="),c=o[0],r=o[1];n[c]=r;t=e.exec(window.location.href)}return n}(),e.contentWindow.document.params=o,e.contentWindow.document.head.appendChild(c())}();else if("close"===e)(m=document.getElementById("loyjoy-frame"))&&m.contentWindow&&m.contentWindow.document&&m.contentWindow.document.api&&m.contentWindow.document.api.close&&m.contentWindow.document.api.close();else{if("getVariable"===e)return u=o,(s=document.getElementById("loyjoy-frame"))&&s.contentWindow&&s.contentWindow.document&&s.contentWindow.document.api&&s.contentWindow.document.api.getVariable&&s.contentWindow.document.api.getVariable(u);"hide"===e?(l=document.getElementById("loyjoy-frame"))&&l.contentWindow&&l.contentWindow.document&&l.contentWindow.document.api&&l.contentWindow.document.api.hide&&l.contentWindow.document.api.hide():"open"===e?(d=document.getElementById("loyjoy-frame"))&&d.contentWindow&&d.contentWindow.document&&d.contentWindow.document.api&&d.contentWindow.document.api.open&&d.contentWindow.document.api.open():"remove"===e?((a=document.getElementById("loyjoy-container"))&&a.parentNode&&a.parentNode.removeChild(a),(i=document.getElementById("loyjoy-frame"))&&i.parentNode&&i.parentNode.removeChild(i),(r=document.getElementById("loyjoy-stylesheet"))&&r.parentNode&&r.parentNode.removeChild(r),document.body.style.height="",document.body.style.overflow="",document.body.style.position="",document.body.style.width="",(t=document.getElementById("loyjoy-host"))&&t.childNodes.forEach(function(e){t.removeChild(e)})):"show"===e&&(n=document.getElementById("loyjoy-frame"))&&n.contentWindow&&n.contentWindow.document&&n.contentWindow.document.api&&n.contentWindow.document.api.show&&n.contentWindow.document.api.show()}}window.LoyJoy=LoyJoy;