web-push-notifications 3.39.8 → 3.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/service-worker.js +1 -1
- package/lib/service-worker.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Pushwoosh:()=>Bt});var n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var r=function(){return r=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},r.apply(this,arguments)};function s(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}function o(t,e,n,i){return new(n||(n=Promise))((function(r,s){function o(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}c((i=i.apply(t,e||[])).next())}))}function a(t,e){var n,i,r,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,i&&(r=2&a[0]?i.return:a[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,a[1])).done)return r;switch(i=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],i=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}Object.create;function c(t,e,n){if(n||2===arguments.length)for(var i,r=0,s=e.length;r<s;r++)!i&&r in e||(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}Object.create;"function"==typeof SuppressedError&&SuppressedError;const u={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let p;const d=new Uint8Array(16);const h=[];for(let t=0;t<256;++t)h.push((t+256).toString(16).slice(1));function l(t,e=0){return(h[t[e+0]]+h[t[e+1]]+h[t[e+2]]+h[t[e+3]]+"-"+h[t[e+4]]+h[t[e+5]]+"-"+h[t[e+6]]+h[t[e+7]]+"-"+h[t[e+8]]+h[t[e+9]]+"-"+h[t[e+10]]+h[t[e+11]]+h[t[e+12]]+h[t[e+13]]+h[t[e+14]]+h[t[e+15]]).toLowerCase()}const g=function(t,e,n){if(u.randomUUID&&!e&&!t)return u.randomUUID();const i=(t=t||{}).random??t.rng?.()??function(){if(!p){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");p=crypto.getRandomValues.bind(crypto)}return p(d)}();if(i.length<16)throw new Error("Random bytes length must be >= 16");if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,e){if((n=n||0)<0||n+16>e.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[n+t]=i[t];return e}return l(i)};var f="deviceRegistrationStatus",b="registered",v="unregistered",m="denied",w="granted",y="default",x="onLoad",_="onReady",C="onSubscribe",S="onUnsubscribe",E="onRegister",k="onPermissionPrompt",P="onPermissionDenied",T="onPermissionGranted",I="onSWInitError",M="onPushDelivery",B="onNotificationClick",D="onNotificationClose",O="onChangeCommunicationEnabled",W="onPutNewMessageToInboxStore",R="onUpdateInboxMessages",A="onShowNotificationPermissionDialog",L="onHideNotificationPermissionDialog",N="onShowSubscriptionWidget",U="onHideSubscriptionWidget",H="PW_SiteOpened",q={headerText:"Subscribe to our news",headerTextColor:"#000000",subheaderText:"Don't miss out on the latest news and updates!",subheaderTextColor:"#000000",buttonAcceptText:"Agree",buttonAcceptTextColor:"#1A72E8",buttonAcceptRound:"4px",buttonAcceptBackgroundColor:"#FFFFFF",buttonAcceptBorderColor:"#E3E4E8",buttonCancelText:"Deny",buttonCancelTextColor:"#1A72E8",buttonCancelRound:"4px",buttonCancelBackgroundColor:"#FFFFFF",buttonCancelBorderColor:"#E3E4E8",cappingCount:3,cappingDelay:144e5,backgroundColor:"#FFFFFF"},F=function(){var t=this;this.addEventHandler=function(e,n){var i=t.savedEventHandlersMap[e];i||(i=[]),i.push(n),t.savedEventHandlersMap[e]=i},this.removeEventHandler=function(e,n){var i=t.savedEventHandlersMap[e];i&&(t.savedEventHandlersMap[e]=i.filter((function(t){return t!==n})))},this.dispatchEvent=function(e,n){var i=n.eventId||g(),s=t.savedEventHandlersMap[e];return s?(s.forEach((function(t){"function"==typeof t&&setTimeout((function(){t(r(r({},n),{eventId:i}))}),0)})),i):i},this.savedEventHandlersMap={}},z="pushwoosh-subscription-widget",V=function(){function t(t,e){this.eventBus=t,this.pw=e}return t.prototype.init=function(t){if(!this.getRootElement()){var e=function(t){return'\n <div id="'.concat(z,'-root" class="').concat(z,'">\n <div class="').concat(z,'__body">\n <div class="').concat(z,'__header">\n ').concat(t.headerText,'\n </div>\n <div class="').concat(z,'__description">\n ').concat(t.subheaderText,'\n </div>\n <div class="').concat(z,'__controls">\n <button type="button" id="').concat(z,'-decline" class="').concat(z,"__control ").concat(z,'__control_decline">\n ').concat(t.buttonCancelText,'\n </button>\n <button type="button" id="').concat(z,'-accept" class="').concat(z,"__control ").concat(z,'__control_accept">\n ').concat(t.buttonAcceptText,"\n </button>\n </div>\n </div>\n </div>\n ")}(t),n=function(t){var e=document.createElement("style");return e.innerHTML="\n .".concat(z," * {\n box-sizing: border-box!important;\n }\n \n .").concat(z," {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n margin: 0 auto;\n width: 320px;\n display: none;\n z-index: 2147483648;\n opacity: 0.99;\n }\n \n .").concat(z,"_show {\n display: block;\n }\n \n .").concat(z,"__body {\n width: 320px;\n background-color: ").concat(t.backgroundColor?t.backgroundColor:"#FFFFFF",";\n box-shadow: 0 9px 15px rgba(0, 0, 0, 0.1), 0 0 6px rgba(0, 0, 0, 0.06);\n border-radius: 4px;\n padding: 20px 20px 12px;\n }\n \n .").concat(z,"__header {\n color: ").concat(t.headerTextColor,";\n font-size: 18px;\n font-weight: bold; \n }\n \n .").concat(z,"__description {\n color: ").concat(t.subheaderTextColor,";\n font-size: 14px;\n line-height: 1.5;\n margin-top: 14px;\n }\n \n .").concat(z,"__description:empty {\n display: none;\n }\n \n .").concat(z,"__controls {\n display: flex;\n flex-wrap: nowrap;\n justify-content: flex-end;\n margin: 20px 0 0;\n }\n \n .").concat(z,"__control {\n -webkit-appearance: none;\n border: 1px solid transparent;\n font-size: 12px;\n font-weight: bold;\n padding: 0 20px;\n height: 32px;\n cursor: pointer;\n }\n \n .").concat(z,"__control_decline {\n color: ").concat(t.buttonCancelTextColor,";\n background-color: ").concat(t.buttonCancelBackgroundColor,";\n border-radius: ").concat(t.buttonCancelRound,";\n border-color: ").concat(t.buttonCancelBorderColor,";\n }\n \n .").concat(z,"__control_accept {\n color: ").concat(t.buttonAcceptTextColor,";\n background-color: ").concat(t.buttonAcceptBackgroundColor,";\n border-radius: ").concat(t.buttonAcceptRound,";\n border-color: ").concat(t.buttonAcceptBorderColor,";\n margin: 0 0 0 12px;\n }\n "),e}(t);document.body.insertAdjacentHTML("beforeend",e),document.head.appendChild(n)}this.addEventListeners()},t.prototype.show=function(){var t=this.getRootElementWithCheckExist();this.eventBus.dispatchEvent("show-subscription-widget",{}),t.classList.add("".concat(z,"_show"))},t.prototype.hide=function(){var t=this.getRootElementWithCheckExist();t.classList.contains("".concat(z,"_show"))&&(this.eventBus.dispatchEvent("hide-subscription-widget",{}),t.classList.remove("".concat(z,"_show")))},t.prototype.getRootElement=function(){return document.getElementById("".concat(z,"-root"))},t.prototype.getRootElementWithCheckExist=function(){var t=this.getRootElement();if(!t)throw new Error("Can't find element by id \"".concat(z,'-root", please use method init first.'));return t},t.prototype.getDeclineButtonWithCheckExist=function(){var t=document.getElementById("".concat(z,"-decline"));if(!t)throw new Error("Can't find element by id \"".concat(z,'-decline", please use method init first.'));return t},t.prototype.getAcceptButtonWithCheckExist=function(){var t=document.getElementById("".concat(z,"-accept"));if(!t)throw new Error("Can't find element by id \"".concat(z,'-accept", please use method init first.'));return t},t.prototype.addEventListeners=function(){var t=this,e=this.getRootElementWithCheckExist(),n=this.getDeclineButtonWithCheckExist(),i=this.getAcceptButtonWithCheckExist();document.addEventListener("click",(function(n){e.contains(n.target)||t.hide()})),n.addEventListener("click",(function(){t.hide()})),i.addEventListener("click",(function(){t.hide(),t.pw.subscribe()}))},t}();function j(){return globalThis}function Y(){"history"in j()&&history.pushState?history.pushState(null,"","#"):location.hash="#"}var K="keyValue",G="messages",X="log",J="inboxMessages";function $(t,e){return function(n){n.objectStoreNames.contains(t)||e(n)}}const Q=[$(J,(function(t){var e="status",n=t.createObjectStore(J,{keyPath:"inbox_id",autoIncrement:!1});n.createIndex(e,e,{unique:!1,multiEntry:!0}),n.createIndex("rt","rt",{unique:!1,multiEntry:!0})}))];const Z=[$(K,(function(t){t.createObjectStore(K,{keyPath:"key"})})),$(X,(function(t){var e=t.createObjectStore(X,{keyPath:"id",autoIncrement:!0});e.createIndex("environment","environment",{unique:!1}),e.createIndex("date","date",{unique:!1}),e.createIndex("type","type",{unique:!1})})),$(G,(function(t){t.createObjectStore(G,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}))];const tt=function(){function t(t){void 0===t&&(t=new Date),this._date=t}return Object.defineProperty(t.prototype,"date",{get:function(){return this._date},set:function(t){this._date=t},enumerable:!1,configurable:!0}),t.prototype.getUtcTimestamp=function(){return Math.floor((this.date.getTime()+60*this.date.getTimezoneOffset()*1e3)/1e3)},t.prototype.getTimestamp=function(){return Math.round(this.date.getTime()/1e3)},t.prototype.setLocal=function(){var t=this._date.getTime()-60*this.date.getTimezoneOffset()*1e3;this._date=new Date(t)},t.prototype.addDays=function(t){var e=this._date.getTime()+24*t*60*60*1e3;this._date=new Date(e)},t.prototype.getInboxFakeOrder=function(){return(100*this._date.getTime()+9e9).toString()},t}();const et=function(){function t(t){void 0===t&&(t=new tt),this.migrations={initial:Z,"2018/11/26":Q},this.dateModule=t}return Object.defineProperty(t.prototype,"initial",{get:function(){return this.migrations.initial},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dateSorted",{get:function(){var t=this;return Object.keys(this.migrations).filter((function(t){return"initial"!==t})).sort((function(t,e){var n=new tt(new Date(t)),i=new tt(new Date(e));return n.getTimestamp()-i.getTimestamp()})).map((function(e){return t.migrations[e]}))},enumerable:!1,configurable:!0}),t}();const nt=function(){function t(t,e){void 0===e&&(e=new et),this.db=t,this.migrationsBuilder=e}return t.prototype.applyMigrations=function(){var t=this;this.applyMigrationsPack(this.migrationsBuilder.initial),this.migrationsBuilder.dateSorted.forEach((function(e){t.applyMigrationsPack(e)}))},t.prototype.applyMigrationsPack=function(t){var e=this;t.forEach((function(t){t(e.db)}))},t}();function it(t,e){console.info("onversionchange",e),t.close()}var rt;function st(t){return(rt||(rt=new Promise((function(t,e){var n=indexedDB.open("PUSHWOOSH_SDK_STORE",7);n.onsuccess=function(n){var i=n.target.result;i.onversionchange=it.bind(null,i,e),t(i)},n.onerror=function(){return e(n.error)},n.onupgradeneeded=function(t){var n=t.target.result;n.onversionchange=it.bind(null,n,e),new nt(n).applyMigrations()}}))),rt).then((function(e){return new Promise((function(n,i){return t(e,n,i)}))}))}var ot,at=function(){function t(){}return t.prototype._add=function(t){var e=this;return st((function(n,i,r){var s=n.transaction([e.name],"readwrite").objectStore(e.name).add(t);s.onsuccess=function(){i(t)},s.onerror=function(){r(s.error)}})).then((function(t){return e.getAll().then((function(n){if(Array.isArray(n)){var i=n.map((function(t){return t.id})).sort((function(t,e){return t==e?0:t<e?1:-1}));if(i.length>e.maxItems)return Promise.all(i.slice(e.maxItems).map((function(t){return e.delete(t)}))).then((function(){return t}))}return t}))}))},t.prototype.delete=function(t){var e=this;return st((function(n,i,r){var s=n.transaction([e.name],"readwrite").objectStore(e.name).delete(t);s.onsuccess=function(){i(s.result)},s.onerror=function(){r(s.error)}}))},t.prototype.getAll=function(){var t=this;return st((function(e,n,i){var r=[],s=e.transaction(t.name).objectStore(t.name).openCursor();s.onsuccess=function(t){var e=t.target.result;e?(e.value&&r.push(e.value),e.continue()):n(r)},s.onerror=function(){i(s.error)}}))},t}(),ct=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=X,e.maxItems=100,e.environment="undefined"!=typeof self&&self.registration?"worker":"browser",e}return i(e,t),e.prototype.add=function(t,e,n){var i={type:t,environment:this.environment,message:"".concat(e),date:new Date};return e instanceof Error&&(i.stack=e.stack),n&&(i.additional=n),this._add(i)},e}(at),ut=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.name=G,e.maxItems=25,e}return i(e,t),e.prototype.add=function(t){return this._add(r(r({},t),{date:new Date}))},e}(at),pt=(ot=K,{get:function(t,e){return st((function(n,i,r){var s,o=n.transaction(ot).objectStore(ot).get(t),a=!1,c=!1,u=function(){if(clearTimeout(s),a){var t=o.result;i(t&&t.value||e)}else c?r(o.error):s=setTimeout(u,0)};o.onsuccess=function(){return a=!0},o.onerror=function(){return c=!0},u()}))},getAll:function(){return st((function(t,e,n){var i,r={},s=t.transaction(ot).objectStore(ot).openCursor(),o=!1,a=!1,c=function(){clearTimeout(i),o?e(r):a?n(s.error):i=setTimeout(c,0)};s.onsuccess=function(t){var e=t.target.result;e?(r[e.key]=e.value.value,e.continue()):o=!0},s.onerror=function(){return a=!0},c()}))},extend:function(t,e){return o(this,void 0,void 0,(function(){var n,i;return a(this,(function(o){switch(o.label){case 0:return[4,this.get(t)];case 1:return n=o.sent(),i=s(e,[]),[4,this.set(t,r(r({},n),i))];case 2:return o.sent(),[2]}}))}))},set:function(t,e){return st((function(n,i,r){var s,o=n.transaction([ot],"readwrite").objectStore(ot).put({key:t,value:e}),a=!1,c=!1,u=function(){clearTimeout(s),a?i(t):c?r(o.error):s=setTimeout(u,0)};o.onsuccess=function(){return a=!0},o.onerror=function(){return c=!0},u()}))}}),dt=new ct,ht=new ut,lt={error:1,info:2,debug:3},gt=3;!function(){for(var t,e=function(){},n=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],i=n.length,r=j(),s=r.console=r.console||{};i--;)s[t=n[i]]||(s[t]=e)}();var ft={setLevel:function(t){lt[t]||(t="error"),gt=lt[t]},write:function(t,e,n){return"error"===t?this.error(e):this.info(e),dt.add(t,e,n)}};Object.keys(lt).forEach((function(t){var e=lt[t];ft[t]=function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];e<=gt&&(console.groupCollapsed(t),console.info.apply(console,c([""],n,!1)),console.trace("trace"),console.groupEnd())}}));var bt=function(){function t(t,e,n,i){void 0===i&&(i=new tt),this.data=t,this.api=e,this.inboxModel=n,this.dateModule=i,this.publicMessageBuilder=this.publicMessageBuilder.bind(this)}return t.prototype.messageTypeFactory=function(t,e){var n=0;return 2===t?n=1:"l"in e&&null!=e.l&&(n=e.l.startsWith("http")?2:3),n},t.prototype.updateMessagesStatusWithCodes=function(t,e,n){return o(this,void 0,void 0,(function(){var i,r,s=this;return a(this,(function(c){switch(c.label){case 0:return i=[],r=[],e.forEach((function(e){return o(s,void 0,void 0,(function(){return a(this,(function(s){return-1===t.indexOf(e.inbox_id)||(e.status=n,i.push(e),r.push(this.api.inboxStatus(e.order,e.status))),[2]}))}))})),[4,this.inboxModel.putBulkMessages(i)];case 1:return c.sent(),[4,Promise.all(r)];case 2:return c.sent(),[2]}}))}))},t.prototype.publicMessageBuilder=function(t){return o(this,arguments,void 0,(function(t){var e,n,i,r,s,o=t.action_type,c=t.action_params,u=t.image,p=t.title,d=t.send_date,h=t.inbox_id,l=t.text,g=t.status;return a(this,(function(t){switch(t.label){case 0:return(n=u)?[3,2]:[4,this.data.getDefaultNotificationImage()];case 1:n=t.sent(),t.label=2;case 2:return e=n,(r=p)?[3,4]:[4,this.data.getDefaultNotificationTitle()];case 3:r=t.sent(),t.label=4;case 4:return i=r,s=JSON.parse(c),this.dateModule.date=new Date(1e3*parseInt(d)),this.dateModule.setLocal(),[2,{title:i,imageUrl:e,code:h,message:l,sendDate:this.dateModule.date.toISOString(),type:this.messageTypeFactory(o,s),link:(null==s?void 0:s.l)||"/",isRead:2===g||3===g,isActionPerformed:3===g}]}}))}))},t.prototype.messagesWithNoActionPerformedCount=function(){return this.inboxModel.getDeliveredReadMessagesCount()},t.prototype.unreadMessagesCount=function(){return this.inboxModel.getDeliveredMessagesCount()},t.prototype.messagesCount=function(){return this.inboxModel.messagesCount()},t.prototype.loadMessages=function(){return o(this,void 0,void 0,(function(){var t,e,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.inboxModel.getReadOpenMessages()];case 1:return t=i.sent(),[4,this.inboxModel.getDeliveredMessages()];case 2:return e=i.sent(),n=c(c([],t,!0),e,!0).sort((function(t,e){return parseInt(e.send_date,10)-parseInt(t.send_date,10)})).sort((function(t,e){return parseInt(e.order||"0",10)-parseInt(t.order||"0",10)})).map(this.publicMessageBuilder),[2,Promise.all(n)]}}))}))},t.prototype.readMessagesWithCodes=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.inboxModel.getDeliveredMessages()];case 1:return e=n.sent(),[4,this.updateMessagesStatusWithCodes(t,e,2)];case 2:return n.sent(),[2]}}))}))},t.prototype.performActionForMessageWithCode=function(t){return o(this,void 0,void 0,(function(){var e,n,i;return a(this,(function(r){switch(r.label){case 0:return[4,this.inboxModel.getMessage(t)];case 1:return e=r.sent(),n=JSON.parse(e.action_params),2===(i=this.messageTypeFactory(e.action_type,n))&&null!=n.l?document.location.href=n.l:3===i&&null!=n.l&&window.history.go(n.l),e.status=3,[4,this.inboxModel.putMessage(e)];case 2:return r.sent(),[4,this.api.inboxStatus(e.order,e.status)];case 3:return r.sent(),[2]}}))}))},t.prototype.deleteMessagesWithCodes=function(t){return o(this,void 0,void 0,(function(){var e,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.inboxModel.getReadOpenMessages()];case 1:return e=i.sent(),[4,this.inboxModel.getDeliveredMessages()];case 2:return n=i.sent(),[4,this.updateMessagesStatusWithCodes(t,c(c([],e,!0),n,!0),4)];case 3:return i.sent(),[2]}}))}))},t.prototype.syncMessages=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.inboxModel.updateMessages()];case 1:return t.sent(),[2]}}))}))},t}();const vt=bt;var mt=function(){function t(t,e){this.name=e,this.store=t.transaction(this.name,"readwrite").objectStore(this.name)}return Object.defineProperty(t.prototype,"index",{set:function(t){this.store.indexNames.contains(t)?this._index=this.store.index(t):console.warn('Index "'.concat(t,'" in '))},enumerable:!1,configurable:!0}),t.prototype.writeRequestPromise=function(t,e){return new Promise((function(n,i){t.onsuccess=function(){n(e)},t.onerror=function(){i(t.error)}}))},t.prototype.readRequestPromise=function(t,e){return new Promise((function(n,i){t.onsuccess=function(t){var i=t.target;n(i.result||e)},t.onerror=function(){i(t.error)}}))},t.prototype.put=function(t,e){var n=this.store.put(t,e);return this.writeRequestPromise(n,e)},t.prototype.add=function(t,e){return this.put(t,e)},t.prototype.delete=function(t){var e=this.store.delete(t);return this.writeRequestPromise(e)},t.prototype.get=function(t,e){var n=this.store.get(t);return this.readRequestPromise(n,e)},t.prototype.getAll=function(){var t=this.store.openCursor(),e=[];return new Promise((function(n,i){t.onsuccess=function(t){var i=t.target.result;i?(e.push(i.value),i.continue()):n(e)},t.onerror=function(){i(t.error)}}))},t.prototype.count=function(t){var e=this.store.count(t);return this.readRequestPromise(e,0)},t.prototype.countByIndex=function(t){var e=this._index.count(t);return this.readRequestPromise(e,0)},t}();const wt=mt;const yt=function(){function t(){}return t.prototype.dbVersionChangeHandler=function(t,e){console.info("onversionchange",e),t.close()},t.prototype.dbRequestSuccessHandler=function(t,e){var n=this,i=e.target.result;i.onversionchange=function(t){n.dbVersionChangeHandler(i,t)},t(i)},t.prototype.dbRequestUpgradeNeededHandler=function(t){var e=this,n=t.target.result;n.onversionchange=function(t){e.dbVersionChangeHandler(n,t)},new nt(n).applyMigrations()},t.prototype.getDB=function(){var t=this;return new Promise((function(e,n){var i=indexedDB.open("PUSHWOOSH_SDK_STORE",7);i.onsuccess=function(n){t.dbRequestSuccessHandler(e,n)},i.onupgradeneeded=function(e){t.dbRequestUpgradeNeededHandler(e)},i.onerror=function(){return n(i.error)}}))},t.prototype.put=function(t,e,n){return o(this,void 0,void 0,(function(){var i,r;return a(this,(function(s){switch(s.label){case 0:return[4,this.getDB()];case 1:return i=s.sent(),[4,new wt(i,t).put(e,n)];case 2:return r=s.sent(),i.close(),[2,r]}}))}))},t.prototype.delete=function(t,e){return o(this,void 0,void 0,(function(){var n,i;return a(this,(function(r){switch(r.label){case 0:return[4,this.getDB()];case 1:return n=r.sent(),[4,new wt(n,t).delete(e)];case 2:return i=r.sent(),n.close(),[2,i]}}))}))},t.prototype.get=function(t,e,n){return o(this,void 0,void 0,(function(){var i,r;return a(this,(function(s){switch(s.label){case 0:return[4,this.getDB()];case 1:return i=s.sent(),[4,new wt(i,t).get(e,n)];case 2:return r=s.sent(),i.close(),[2,r]}}))}))},t.prototype.getAll=function(t){return o(this,void 0,void 0,(function(){var e,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.getDB()];case 1:return e=i.sent(),[4,new wt(e,t).getAll()];case 2:return n=i.sent(),e.close(),[2,n||[]]}}))}))},t.prototype.count=function(t,e){return o(this,void 0,void 0,(function(){var n,i;return a(this,(function(r){switch(r.label){case 0:return[4,this.getDB()];case 1:return n=r.sent(),[4,new wt(n,t).count(e)];case 2:return i=r.sent(),n.close(),[2,i]}}))}))},t.prototype.countByIndex=function(t,e,n){return o(this,void 0,void 0,(function(){var i,r,s;return a(this,(function(o){switch(o.label){case 0:return[4,this.getDB()];case 1:return i=o.sent(),(r=new wt(i,t)).index=e,[4,r.countByIndex(n)];case 2:return s=o.sent(),i.close(),[2,s]}}))}))},t}();var xt=function(){function t(t,e,n,i,r){void 0===i&&(i=new yt),void 0===r&&(r=new tt),this.eventBus=t,this.data=e,this.api=n,this.storage=i,this.storeName="inboxMessages",this.dateModule=r}return t.prototype.getInboxMessages=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.api.getInboxMessages()];case 1:return t=e.sent(),[4,this.storeGetInboxMessagesRequestParams(t.next,t.new_inbox)];case 2:return e.sent(),[2,t]}}))}))},t.prototype.storeGetInboxMessagesRequestParams=function(t,e){return o(this,void 0,void 0,(function(){return a(this,(function(n){switch(n.label){case 0:return this.dateModule.date=new Date,[4,this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp())];case 1:return n.sent(),[4,this.data.setInboxLastRequestCode(t)];case 2:return n.sent(),[4,this.data.setInboxNewMessagesCount(e)];case 3:return n.sent(),[2]}}))}))},t.prototype.putServerMessages=function(t){return o(this,void 0,void 0,(function(){var e,n=this;return a(this,(function(i){return e=t.map((function(t){return o(n,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.storage.get(this.storeName,t.inbox_id,{})];case 1:return"status"in(e=n.sent())&&(t.status=e.status),[2,this.putMessage(t)]}}))}))})),[2,Promise.all(e)]}))}))},t.prototype.putMessage=function(t){return this.storage.put(this.storeName,t)},t.prototype.putBulkMessages=function(t){var e=this,n=t.map((function(t){return e.putMessage(t)}));return Promise.all(n)},t.prototype.deleteMessages=function(t){var e=this,n=t.map((function(t){return e.storage.delete(e.storeName,t)}));return Promise.all(n)},t.prototype.deleteExpiredMessages=function(){return o(this,void 0,void 0,(function(){var t,e,n;return a(this,(function(i){switch(i.label){case 0:return this.dateModule.date=new Date,t=this.dateModule.getTimestamp().toString(),[4,this.storage.getAll(this.storeName)];case 1:return e=i.sent(),n=e.filter((function(e){return e.rt<t})).map((function(t){return t.inbox_id})),[2,this.deleteMessages(n)]}}))}))},t.prototype.getMessage=function(t){return this.storage.get(this.storeName,t)},t.prototype.getReadOpenMessages=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.storage.getAll(this.storeName)];case 1:return[2,t.sent().filter((function(t){return 2===t.status||3===t.status}))]}}))}))},t.prototype.getDeliveredMessages=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.storage.getAll(this.storeName)];case 1:return[2,t.sent().filter((function(t){return 1===t.status}))]}}))}))},t.prototype.messagesCount=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.storage.count(this.storeName)]}))}))},t.prototype.getDeliveredMessagesCount=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.storage.countByIndex(this.storeName,"status",1)]}))}))},t.prototype.getReadMessagesCount=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.storage.countByIndex(this.storeName,"status",2)]}))}))},t.prototype.getDeliveredReadMessagesCount=function(){return o(this,void 0,void 0,(function(){var t,e,n,i;return a(this,(function(r){return e=(t=[2,3])[0],n=t[1],i=IDBKeyRange.bound(e,n),[2,this.storage.countByIndex(this.storeName,"status",i)]}))}))},t.prototype.updateMessages=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.getInboxMessages()];case 1:return t=e.sent(),[4,this.deleteExpiredMessages()];case 2:return e.sent(),t.deleted?[4,this.deleteMessages(t.deleted)]:[3,4];case 3:e.sent(),e.label=4;case 4:return[4,this.putServerMessages(t.messages)];case 5:return e.sent(),this.eventBus.dispatchEvent("update-inbox-messages",{messages:new vt(this.data,this.api,this)}),[2]}}))}))},t}();const _t=xt;var Ct=function(){function t(t){void 0===t&&(t=pt),this.store=t}return t.prototype.clearAll=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.set("params.applicationCode",void 0)];case 1:return t.sent(),[4,this.store.set("params.hwid",void 0)];case 2:return t.sent(),[4,this.store.set("params.deviceType",void 0)];case 3:return t.sent(),[4,this.store.set("params.deviceModel",void 0)];case 4:return t.sent(),[4,this.store.set("params.language",void 0)];case 5:return t.sent(),[4,this.store.set("params.apiEntrypoint",void 0)];case 6:return t.sent(),[4,this.store.set("params.tokens",void 0)];case 7:return t.sent(),[4,this.store.set("params.applicationServerKey",void 0)];case 8:return t.sent(),[4,this.store.set("params.senderId",void 0)];case 9:return t.sent(),[4,this.store.set("params.webSitePushId",void 0)];case 10:return t.sent(),[4,this.store.set("params.defaultNotificationImage",void 0)];case 11:return t.sent(),[4,this.store.set("params.defaultNotificationTitle",void 0)];case 12:return t.sent(),[4,this.store.set("params.userId",void 0)];case 13:return t.sent(),[4,this.store.set("params.email",void 0)];case 14:return t.sent(),[4,this.store.set("params.userIdWasChanged",void 0)];case 15:return t.sent(),[4,this.store.set("params.isLastPermissionStatus",void 0)];case 16:return t.sent(),[4,this.store.set("params.isManualUnsubscribed",void 0)];case 17:return t.sent(),[4,this.store.set("params.isCommunicationDisabled",void 0)];case 18:return t.sent(),[4,this.store.set("params.isDropAllData",void 0)];case 19:return t.sent(),[4,this.store.set("params.sdkVersion",void 0)];case 20:return t.sent(),[4,this.store.set("params.serviceWorkerVersion",void 0)];case 21:return t.sent(),[4,this.store.set("params.serviceWorkerUrl",void 0)];case 22:return t.sent(),[4,this.store.set("params.serviceWorkerScope",void 0)];case 23:return t.sent(),[4,this.store.set("params.lastOpenMessage",void 0)];case 24:return t.sent(),[4,this.store.set("params.lastOpenApplicationTime",void 0)];case 25:return t.sent(),[4,this.store.set("params.features",void 0)];case 26:return t.sent(),[4,this.store.set("params.init",void 0)];case 27:return t.sent(),[4,this.store.set("API_PARAMS",void 0)];case 28:return t.sent(),[4,this.store.set("SENDER_ID",void 0)];case 29:return t.sent(),[4,this.store.set("COMMUNICATION_ENABLED",void 0)];case 30:return t.sent(),[4,this.store.set("DEVICE_DATA_REMOVED",void 0)];case 31:return t.sent(),[4,this.store.set("LAST_OPEN_MESSAGE",void 0)];case 32:return t.sent(),[4,this.store.set("DELAYED_EVENT",void 0)];case 33:return t.sent(),[2]}}))}))},t.prototype.setApplicationCode=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.applicationCode",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getApplicationCode=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.applicationCode")];case 1:return[2,t.sent()]}}))}))},t.prototype.setApiToken=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.apiToken",t)];case 1:return[2,e.sent()]}}))}))},t.prototype.getApiToken=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.apiToken")];case 1:return[2,t.sent()]}}))}))},t.prototype.setHwid=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.hwid",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getHwid=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.hwid")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDeviceType=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.deviceType",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDeviceType=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.deviceType")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDeviceModel=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.deviceModel",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDeviceModel=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.deviceModel")];case 1:return[2,t.sent()]}}))}))},t.prototype.setLanguage=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.language",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getLanguage=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.language","en")];case 1:return[2,t.sent()]}}))}))},t.prototype.setApiEntrypoint=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.apiEntrypoint",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getApiEntrypoint=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.apiEntrypoint","https://cp.pushwoosh.com/json/1.3/")];case 1:return[2,t.sent()]}}))}))},t.prototype.setTokens=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.getHwid()];case 1:return e=n.sent(),[4,this.store.set("API_PARAMS",r({hwid:e},t))];case 2:return n.sent(),[4,this.store.set("params.tokens",t)];case 3:return n.sent(),[2]}}))}))},t.prototype.getTokens=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("API_PARAMS")];case 1:return t=n.sent(),[4,this.store.get("params.tokens")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setApplicationServerKey=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.applicationServerKey",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getApplicationServerKey=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.applicationServerKey")];case 1:return[2,t.sent()]}}))}))},t.prototype.setIsVapidChanged=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.isVapidChanged",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getIsVapidChanged=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.isVapidChanged",!1)];case 1:return[2,t.sent()]}}))}))},t.prototype.setWebSitePushId=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.webSitePushId",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getWebSitePushId=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.webSitePushId")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDefaultNotificationImage=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.defaultNotificationImage",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDefaultNotificationImage=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.defaultNotificationImage","https://cp.pushwoosh.com/img/logo-medium.png")];case 1:return[2,t.sent()]}}))}))},t.prototype.setDefaultNotificationTitle=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.defaultNotificationTitle",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getDefaultNotificationTitle=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.defaultNotificationTitle","Pushwoosh notification")];case 1:return[2,t.sent()]}}))}))},t.prototype.setUserId=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t?[3,2]:[4,this.store.set("params.userId",void 0)];case 1:case 3:return e.sent(),[2];case 2:return[4,this.store.set("params.userId",t.toString())]}}))}))},t.prototype.getUserId=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.userId")];case 1:return[2,t.sent()]}}))}))},t.prototype.setStatusUserIdWasChanged=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.userIdWasChanged",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getStatusUserIdWasChanged=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.userIdWasChanged",!1)];case 1:return[2,t.sent()]}}))}))},t.prototype.setEmail=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t?[3,2]:[4,this.store.set("params.email",void 0)];case 1:case 3:return e.sent(),[2];case 2:return[4,this.store.set("params.email",t.toString())]}}))}))},t.prototype.getEmail=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.email")];case 1:return[2,t.sent()]}}))}))},t.prototype.setStatusEmailWasChanged=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.emailWasChanged",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getStatusEmailWasChanged=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.emailWasChanged",!1)];case 1:return[2,t.sent()]}}))}))},t.prototype.setLastPermissionStatus=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.isLastPermissionStatus",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getLastPermissionStatus=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.isLastPermissionStatus")];case 1:return[2,t.sent()]}}))}))},t.prototype.setStatusManualUnsubscribed=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("MANUAL_UNSUBSCRIBE",t)];case 1:return e.sent(),[4,this.store.set("params.isManualUnsubscribed",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getStatusManualUnsubscribed=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("MANUAL_UNSUBSCRIBE",!1)];case 1:return t=n.sent(),[4,this.store.get("params.isManualUnsubscribed",!1)];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setStatusCommunicationDisabled=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("COMMUNICATION_ENABLED",t?0:1)];case 1:return e.sent(),[4,this.store.set("params.isCommunicationDisabled",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getStatusCommunicationDisabled=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("COMMUNICATION_ENABLED")];case 1:return t=n.sent(),[4,this.store.get("params.isCommunicationDisabled",!1)];case 2:return[2,void 0!==(e=n.sent())?e:0==t]}}))}))},t.prototype.setStatusDropAllData=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("DEVICE_DATA_REMOVED",t)];case 1:return e.sent(),[4,this.store.set("params.isDropAllData",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getStatusDropAllData=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("DEVICE_DATA_REMOVED",!1)];case 1:return t=n.sent(),[4,this.store.get("params.isDropAllData",!1)];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setSdkVersion=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.sdkVersion",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getSdkVersion=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.sdkVersion")];case 1:return[2,t.sent()]}}))}))},t.prototype.setServiceWorkerVersion=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("WORKER_VERSION",t)];case 1:return e.sent(),[4,this.store.set("params.serviceWorkerVersion",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getServiceWorkerVersion=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("WORKER_VERSION")];case 1:return t=n.sent(),[4,this.store.get("params.serviceWorkerVersion")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setServiceWorkerUrl=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t?[4,this.store.set("params.serviceWorkerUrl",t)]:[2];case 1:return e.sent(),[2]}}))}))},t.prototype.getServiceWorkerUrl=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.serviceWorkerUrl","/pushwoosh-service-worker.js")];case 1:return[2,t.sent()]}}))}))},t.prototype.setServiceWorkerScope=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return t?[4,this.store.set("params.serviceWorkerScope",t)]:[2];case 1:return e.sent(),[2]}}))}))},t.prototype.getServiceWorkerScope=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.serviceWorkerScope")];case 1:return[2,t.sent()]}}))}))},t.prototype.setLastOpenMessage=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("LAST_OPEN_MESSAGE",t)];case 1:return e.sent(),[4,this.store.set("params.lastOpenMessage",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getLastOpenMessage=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("LAST_OPEN_MESSAGE")];case 1:return t=n.sent(),[4,this.store.get("params.lastOpenMessage")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setLastOpenApplicationTime=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.lastOpenApplicationTime",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getLastOpenApplicationTime=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.lastOpenApplicationTime")];case 1:return[2,t.sent()]}}))}))},t.prototype.setFeatures=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.features",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getFeatures=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.features")];case 1:return[2,t.sent()]}}))}))},t.prototype.setInitParams=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.init",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInitParams=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.init")];case 1:return[2,t.sent()]}}))}))},t.prototype.setInboxLastRequestCode=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.inbox.lastRequestCode",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInboxLastRequestCode=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.store.get("params.inbox.lastRequestCode","")];case 1:return[2,t.sent()]}}))}))},t.prototype.setInboxLastRequestTime=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.inbox.lastRequestTime",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInboxLastRequestTime=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.store.get("params.inbox.lastRequestTime",0)]}))}))},t.prototype.setInboxNewMessagesCount=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.inbox.newMessagesCount",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getInboxNewMessagesCount=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.store.get("params.inbox.newMessagesCount",0)]}))}))},t.prototype.setDelayedEvent=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("DELAYED_EVENT",t)];case 1:return e.sent(),[4,this.store.set("params.delayedEvent",t)];case 2:return e.sent(),[2]}}))}))},t.prototype.getDelayedEvent=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.store.get("DELAYED_EVENT")];case 1:return t=n.sent(),[4,this.store.get("params.delayedEvent")];case 2:return[2,void 0!==(e=n.sent())?e:t]}}))}))},t.prototype.setPromptDisplayCount=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.promptDisplayCount",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getPromptDisplayCount=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.store.get("params.promptDisplayCount",0)]}))}))},t.prototype.setPromptLastSeenTime=function(t){return o(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.store.set("params.promptLastSeenTime",t)];case 1:return e.sent(),[2]}}))}))},t.prototype.getPromptLastSeenTime=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.store.get("params.promptLastSeenTime",0)]}))}))},t}(),St=function(){function t(t,e){void 0===t&&(t=new Ct),void 0===e&&(e=ft),this.data=t,this.logger=e}return t.prototype.checkDevice=function(t){return this.createRequest("checkDevice",t)},t.prototype.getConfig=function(t){return this.createRequest("getConfig",t,"",!0)},t.prototype.applicationOpen=function(t){return this.createRequest("applicationOpen",t)},t.prototype.registerDevice=function(t){return this.createRequest("registerDevice",t)},t.prototype.unregisterDevice=function(t){return this.createRequest("unregisterDevice",t)},t.prototype.deleteDevice=function(t){return this.createRequest("deleteDevice",t)},t.prototype.messageDeliveryEvent=function(t){return this.createRequest("messageDeliveryEvent",t)},t.prototype.pushStat=function(t){return this.createRequest("pushStat",t)},t.prototype.setTags=function(t){return this.createRequest("setTags",t)},t.prototype.getTags=function(t){return this.createRequest("getTags",t)},t.prototype.registerUser=function(t){return this.createRequest("registerUser",t)},t.prototype.registerEmail=function(t){return this.createRequest("registerEmail",t)},t.prototype.registerEmailUser=function(t){return this.createRequest("registerEmailUser",t)},t.prototype.setEmailTags=function(t){return this.createRequest("setEmailTags",t)},t.prototype.postEvent=function(t){return this.createRequest("postEvent",t)},t.prototype.getInboxMessages=function(t){return this.createRequest("getInboxMessages",t)},t.prototype.inboxStatus=function(t){return this.createRequest("inboxStatus",t)},t.prototype.pageVisit=function(t,e){return this.createRequest("pageVisit",t,e)},t.prototype.setPurchase=function(t){return this.createRequest("setPurchase",t)},t.prototype.createRequest=function(t,e,n,i){return o(this,void 0,void 0,(function(){var s,o,c,u,p,d,h;return a(this,(function(a){switch(a.label){case 0:return[4,this.data.getApiEntrypoint()];case 1:return s=a.sent(),i?(c="",[3,4]):[3,2];case 2:return[4,this.data.getApiToken()];case 3:c=a.sent(),a.label=4;case 4:return u=n||s+t,p=(o=c)?{headers:{Authorization:"Token ".concat(o),"Content-Type":"text/plain;charset=UTF-8",Origin:globalThis.location.origin},credentials:"include"}:{},[4,fetch(u,r({method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:JSON.stringify({request:e})},p))];case 5:return d=a.sent(),[4,this.checkResponse(d)];case 6:return(h=a.sent()).base_url?[4,this.data.setApiEntrypoint(h.base_url)]:[3,8];case 7:a.sent(),a.label=8;case 8:return[4,this.logger.write("apirequest","".concat(t," call with arguments: ").concat(JSON.stringify(e)," to Pushwoosh has been successful. Result: ").concat(JSON.stringify(h.response)))];case 9:return a.sent(),[2,h.response]}}))}))},t.prototype.checkResponse=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:if(200!==t.status)throw new Error("Error code: ".concat(t.status,". Error text: ").concat(t.statusText));return[4,t.json()];case 1:if(200!==(e=n.sent()).status_code)throw new Error("Error code: ".concat(e.status_code,". Error text: ").concat(e.status_message));return[2,e]}}))}))},t}(),Et=function(){function t(t,e,n){void 0===e&&(e=new Ct),void 0===n&&(n=new St),this.eventBus=t,this.data=e,this.apiClient=n}return t.prototype.checkDevice=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return t=e.sent(),[4,this.apiClient.checkDevice(t)];case 2:return[2,e.sent()]}}))}))},t.prototype.checkDeviceSubscribeForPushNotifications=function(){return o(this,arguments,void 0,(function(t){var e,n,i,r;return void 0===t&&(t=!0),a(this,(function(s){switch(s.label){case 0:return void 0!==(e=localStorage.getItem(f))&&t?[3,2]:[4,this.checkDevice()];case 1:n=s.sent(),i=n.exist,r=n.push_token_exist,localStorage.setItem(f,i&&r?b:v),e=localStorage.getItem(f),s.label=2;case 2:return[2,e===b]}}))}))},t.prototype.getConfig=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.getRequestParams()];case 1:return e=n.sent(),[2,this.apiClient.getConfig(r(r({},e),{features:t}))]}}))}))},t.prototype.applicationOpen=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return t=e.sent(),[4,this.data.setLastOpenApplicationTime(Date.now())];case 2:return e.sent(),[2,this.apiClient.applicationOpen(t)]}}))}))},t.prototype.registerDevice=function(){return o(this,void 0,void 0,(function(){var t,e,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.data.getStatusCommunicationDisabled()];case 1:if(i.sent())throw new Error("Can't register device: Communication is disabled!");return[4,this.getRequestParams()];case 2:return t=i.sent(),[4,this.data.getTokens()];case 3:if(!(e=i.sent()).pushToken)throw new Error("Can't register device: pushToken is not exist!");return[4,this.apiClient.registerDevice(r(r({},t),{push_token:e.pushToken,auth_token:e.authToken,public_key:e.publicKey}))];case 4:return n=i.sent(),[4,this.data.setStatusManualUnsubscribed(!1)];case 5:return i.sent(),localStorage.setItem(f,b),this.eventBus.dispatchEvent("register",{}),[2,n]}}))}))},t.prototype.unregisterDevice=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.getRequestParams()];case 1:return t=n.sent(),e=this.apiClient.unregisterDevice(t),localStorage.setItem(f,v),this.eventBus.dispatchEvent("unsubscribe",{}),[2,e]}}))}))},t.prototype.deleteDevice=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.getRequestParams()];case 1:return t=n.sent(),e=this.apiClient.deleteDevice(t),[4,this.data.setStatusManualUnsubscribed(!0)];case 2:return n.sent(),localStorage.setItem(f,v),this.eventBus.dispatchEvent("unsubscribe",{}),[2,e]}}))}))},t.prototype.messageDeliveryEvent=function(t,e){return o(this,arguments,void 0,(function(t,e,n){var i;return void 0===n&&(n={}),a(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return i=e.sent(),[4,this.apiClient.messageDeliveryEvent(r(r({},i),{hash:t,metaData:n}))];case 2:return[2,e.sent()]}}))}))},t.prototype.pushStat=function(t,e){return o(this,arguments,void 0,(function(t,e,n){var i;return void 0===n&&(n={}),a(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return i=e.sent(),[4,this.apiClient.pushStat(r(r({},i),{hash:t,metaData:n}))];case 2:return[2,e.sent()]}}))}))},t.prototype.setTags=function(t){return o(this,void 0,void 0,(function(){var e,n,i,o,c;return a(this,(function(a){switch(a.label){case 0:return[4,this.getRequestParams()];case 1:return e=a.sent(),n=e.hwid,i=e.device_type,o=s(e,["hwid","device_type"]),[4,this.data.getEmail()];case 2:return(c=a.sent())?[4,this.apiClient.setEmailTags(r(r({},o),{email:c,tags:t}))]:[3,4];case 3:a.sent(),a.label=4;case 4:return[2,this.apiClient.setTags(r(r({},o),{hwid:n,device_type:i,tags:t}))]}}))}))},t.prototype.getTags=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.getRequestParams()];case 1:return t=e.sent(),[2,this.apiClient.getTags(t)]}}))}))},t.prototype.registerUser=function(t){return o(this,void 0,void 0,(function(){var e,n,i,o,c,u,p;return a(this,(function(a){switch(a.label){case 0:return[4,this.getRequestParams()];case 1:return e=a.sent(),n=e.hwid,e.device_type,i=s(e,["hwid","device_type"]),[4,this.data.getDeviceType()];case 2:return o=a.sent(),c="".concat(t),[4,this.data.getEmail()];case 3:return u=a.sent(),[4,this.apiClient.registerUser(r(r({},i),{hwid:n,userId:c,ts_offset:60*-(new Date).getTimezoneOffset(),device_type:o}))];case 4:return p=a.sent(),u?[4,this.apiClient.registerEmailUser(r(r({},i),{email:u,userId:c,ts_offset:60*-(new Date).getTimezoneOffset()}))]:[3,6];case 5:a.sent(),a.label=6;case 6:return[4,this.data.setUserId("".concat(t))];case 7:return a.sent(),[4,this.data.setStatusUserIdWasChanged(!0)];case 8:return a.sent(),[2,p]}}))}))},t.prototype.registerEmail=function(t){return o(this,void 0,void 0,(function(){var e,n,i;return a(this,(function(o){switch(o.label){case 0:return[4,this.getRequestParams()];case 1:return e=o.sent(),e.hwid,e.device_type,n=s(e,["hwid","device_type"]),[4,this.apiClient.registerEmail(r(r({},n),{email:t,ts_offset:60*-(new Date).getTimezoneOffset()}))];case 2:return i=o.sent(),[4,this.data.setEmail("".concat(t))];case 3:return o.sent(),[4,this.data.setStatusEmailWasChanged(!0)];case 4:return o.sent(),[2,i]}}))}))},t.prototype.postEvent=function(t,e){return o(this,void 0,void 0,(function(){var n,i,s,o,c,u,p;return a(this,(function(a){switch(a.label){case 0:return[4,this.getRequestParams()];case 1:return n=a.sent(),i=new Date,s=i.getTime(),o=Math.floor(s/1e3),c=o-i.getTimezoneOffset()/60*3600,[4,this.data.getLastOpenMessage()];case 2:if((u=a.sent())&&u.expiry>Date.now()){if(e.msgHash)return[2,Promise.reject("attribute msgHash already defined")];e=r(r({},e),{msgHash:u.messageHash})}return[4,this.data.setLastOpenMessage(void 0)];case 3:return a.sent(),[4,this.apiClient.postEvent(r(r({},n),{event:t,timestampUTC:o,timestampCurrent:c,attributes:e}))];case 4:return(p=a.sent())&&p.code&&this.eventBus.dispatchEvent("receive-in-app-code",{code:p.code}),[2,p]}}))}))},t.prototype.getInboxMessages=function(){return o(this,arguments,void 0,(function(t){var e,n,i;return void 0===t&&(t=0),a(this,(function(s){switch(s.label){case 0:return[4,this.getRequestParams()];case 1:return e=s.sent(),[4,this.data.getInboxLastRequestCode()];case 2:return n=s.sent(),[4,this.data.getInboxLastRequestTime()];case 3:return i=s.sent(),[2,this.apiClient.getInboxMessages(r(r({},e),{count:t,last_code:n,last_request_time:i}))]}}))}))},t.prototype.inboxStatus=function(t,e){return o(this,void 0,void 0,(function(){var n;return a(this,(function(i){switch(i.label){case 0:return[4,this.getRequestParams()];case 1:return n=i.sent(),[2,this.apiClient.inboxStatus(r(r({},n),{inbox_code:t,status:e,time:(new Date).getTime()}))]}}))}))},t.prototype.triggerEvent=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){throw new Error("Method has been deprecated, because we don't aggregate this statistics.")}))}))},t.prototype.pageVisit=function(t){return o(this,void 0,void 0,(function(){var e,n,i;return a(this,(function(s){switch(s.label){case 0:return[4,this.getRequestParams()];case 1:return e=s.sent(),[4,this.data.getFeatures()];case 2:return n=s.sent(),(i=n&&n.page_visit&&n.page_visit.entrypoint)?[2,this.apiClient.pageVisit(r(r({},e),t),i)]:[2]}}))}))},t.prototype.setPurchase=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.getRequestParams()];case 1:return e=n.sent(),[2,this.apiClient.setPurchase(r(r({},e),t))]}}))}))},t.prototype.getParams=function(){return o(this,void 0,void 0,(function(){var t,e,n,i;return a(this,(function(s){switch(s.label){case 0:return[4,this.data.getApplicationCode()];case 1:return t=s.sent(),[4,this.data.getHwid()];case 2:return e=s.sent(),[4,this.data.getTokens()];case 3:return n=s.sent(),[4,this.data.getInitParams()];case 4:return i=s.sent(),[2,r(r({applicationCode:t,hwid:e},n),i)]}}))}))},Object.defineProperty(t.prototype,"params",{get:function(){throw new Error('Property "Pushwoosh.api.params" have been deprecated. Use the async method "Pushwoosh.api.getParams()"')},enumerable:!1,configurable:!0}),t.prototype.getRequestParams=function(){return o(this,void 0,void 0,(function(){var t,e,n,i,r,s,o,c;return a(this,(function(a){switch(a.label){case 0:return[4,this.data.getApplicationCode()];case 1:return t=a.sent(),[4,this.data.getHwid()];case 2:return e=a.sent(),[4,this.data.getUserId()];case 3:return n=a.sent(),[4,this.data.getDeviceType()];case 4:return i=a.sent(),[4,this.data.getDeviceModel()];case 5:return r=a.sent(),[4,this.data.getLanguage()];case 6:return s=a.sent(),[4,this.data.getSdkVersion()];case 7:return o=a.sent(),c=60*-(new Date).getTimezoneOffset(),[2,{application:t,hwid:e,userId:n||e,device_type:i,device_model:r,timezone:c,language:s,v:o}]}}))}))},t}(),kt=function(){function t(t){this.global=t,this._isSafari=this.isSafariBrowser(),this._isOpera=this.isOperaBrowser(),this._isEdge=this.isEdgeBrowser(),this._isFirefox=this.isFirefoxBrowser(),this._isChrome=this.isChromeBrowser(),this._isMacOS=this.isMacOS(),this._isAvailablePromise=this.canUsePromise(),this._isAvailableServiceWorker=this.canUseServiceWorkers(),this._isAvailableNotifications=this.canReceiveNotifications(),this._platform=this.getPlatformType(),this._browserVersion=this.getBrowserVersion()}return Object.defineProperty(t.prototype,"isEdge",{get:function(){return this._isEdge},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isSafari",{get:function(){return this._isSafari},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isOpera",{get:function(){return this._isOpera},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAvailablePromise",{get:function(){return this._isAvailablePromise},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAvailableServiceWorker",{get:function(){return this._isAvailableServiceWorker},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAvailableNotifications",{get:function(){return this._isAvailableNotifications},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"platform",{get:function(){return this._platform},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"browserVersion",{get:function(){return this._browserVersion},enumerable:!1,configurable:!0}),t.prototype.isSafariBrowser=function(){return"safari"in this.global&&navigator.userAgent.indexOf("Safari")>-1},t.prototype.isOperaBrowser=function(){return-1!==navigator.userAgent.indexOf("Opera")||-1!==navigator.userAgent.indexOf("OPR")},t.prototype.isEdgeBrowser=function(){return navigator.userAgent.indexOf("Edge")>-1},t.prototype.isFirefoxBrowser=function(){return-1!==navigator.userAgent.toLowerCase().indexOf("firefox")},t.prototype.isChromeBrowser=function(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)&&!this._isOpera&&!this._isEdge},t.prototype.isMacOS=function(){return"platform"in navigator&&-1!==navigator.platform.toLowerCase().indexOf("mac")},t.prototype.canUseServiceWorkers=function(){return!!navigator.serviceWorker&&"PushManager"in this.global&&"Notification"in this.global},t.prototype.canUsePromise=function(){return"Promise"in this.global},t.prototype.canReceiveNotifications=function(){return this._isSafari&&this._isMacOS||this._isAvailableServiceWorker&&!this._isEdge},t.prototype.getPlatformType=function(){var t=11;switch(!0){case this._isSafari:t=10;break;case this._isOpera||this._isChrome:t=11;break;case this._isFirefox:t=12;break;case this._isEdge:t=150}return t},t.prototype.getBrowserVersion=function(){var t=navigator.userAgent,e=t.match(/\bOPR\/(\d+)/);if(null!==e)return"Opera ".concat(e[1]);var n=t.match(/\bEdge\/(\d+)/);if(null!==n)return"Edge ".concat(n[1]);var i=t.match(/\bEdg\/(\d+)/);if(null!==i)return"Edge ".concat(i[1]);var r=t.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[],s=r[1],o=void 0===s?"":s;if(/trident/i.test(t)){var a=/trident\/([.\d]+)/gi.exec(t)||[],c="7.0"===a[1]?"11":a[1];return"IE ".concat(c||"")}r=r[2]?[o,r[2]]:[navigator.appName,navigator.appVersion,"-?"];var u=t.match(/version\/([.\d]+)/i);return null!==u&&r.splice(1,1,u[1]),r.join(" ")},t}();const Pt=new kt(j());var Tt=function(){function t(t,e,n){this.api=t,this.data=e,this.config=n}return t.prototype.getPermission=function(){return Notification.permission},t.prototype.checkIsPermissionGranted=function(){return this.getPermission()===w},t.prototype.checkIsPermissionDefault=function(){return this.getPermission()===y},t.prototype.checkIsManualUnsubscribed=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.data.getStatusManualUnsubscribed()]}))}))},t.prototype.askPermission=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,Notification.requestPermission()];case 1:return t.sent(),[2]}}))}))},t.prototype.getTokens=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.data.getTokens()]}))}))},t.prototype.subscribe=function(t){return o(this,void 0,void 0,(function(){var e,n,i,r,s,o,c;return a(this,(function(a){switch(a.label){case 0:return(n=t)?[3,2]:[4,this.trySubscribe()];case 1:n=a.sent(),a.label=2;case 2:if(e=n,!this.checkIsPermissionGranted())return ft.error("You must have permission granted before subscribe!"),[2];if(i=this.getPushToken(e),r=e.getKey("p256dh"),s=e.getKey("auth"),!r||!s)throw new Error("Can't get subscription keys!");return o=btoa(String.fromCharCode.apply(String,new Uint8Array(r))),c=btoa(String.fromCharCode.apply(String,new Uint8Array(s))),[4,this.data.setTokens({publicKey:o,pushToken:i,authToken:c,endpoint:e.endpoint})];case 3:return a.sent(),[4,this.api.registerDevice()];case 4:return a.sent(),[2]}}))}))},t.prototype.unsubscribe=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.getServiceWorkerRegistration()];case 1:return[4,e.sent().pushManager.getSubscription()];case 2:return t=e.sent(),[4,this.data.setTokens({})];case 3:return e.sent(),[4,this.data.setStatusManualUnsubscribed(!0)];case 4:return e.sent(),[4,this.api.unregisterDevice()];case 5:return e.sent(),t?[4,t.unsubscribe()]:[2];case 6:return e.sent(),[2]}}))}))},t.prototype.checkIsRegister=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.api.checkDeviceSubscribeForPushNotifications()]}))}))},t.prototype.checkIsNeedResubscribe=function(){return o(this,void 0,void 0,(function(){var t,e,n,i,r,s,o,c;return a(this,(function(a){switch(a.label){case 0:return[4,this.data.getLastPermissionStatus()];case 1:return t=a.sent(),e=this.getPermission(),t===e?[3,3]:[4,this.data.setLastPermissionStatus(e)];case 2:return a.sent(),[2,!0];case 3:return[4,this.getCredentials()];case 4:return n=a.sent(),i=this.getPushToken(n),[4,this.data.getTokens()];case 5:return r=a.sent(),s=r&&r.pushToken||"",o=i===s,[4,this.data.getIsVapidChanged()];case 6:return c=a.sent(),[2,!o||c]}}))}))},t.prototype.getServiceWorkerRegistration=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return this.registration?[3,5]:[4,this.registerServiceWorker()];case 1:return n.sent(),[4,this.data.getServiceWorkerUrl()];case 2:return t=n.sent(),e=this,[4,navigator.serviceWorker.getRegistration(t)];case 3:return e.registration=n.sent(),[4,this.registration.update()];case 4:n.sent(),n.label=5;case 5:if(!this.registration)throw new Error("Internal Error: Can't register service worker!");return[2,this.registration]}}))}))},t.prototype.registerServiceWorker=function(){return o(this,void 0,void 0,(function(){var t,e,n,i,r;return a(this,(function(s){switch(s.label){case 0:return[4,this.data.getServiceWorkerUrl()];case 1:return t=s.sent(),[4,this.data.getServiceWorkerScope()];case 2:return e=s.sent(),[4,this.data.getSdkVersion()];case 3:return n=s.sent(),[4,this.data.getServiceWorkerVersion()];case 4:return i=s.sent(),r="",n!==i&&(r="?cache_clean=".concat(g())),[4,navigator.serviceWorker.register("".concat(t).concat(r),{scope:e})];case 5:return s.sent(),[2]}}))}))},t.prototype.trySubscribe=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,4]),[4,this.subscribePushManager()];case 1:return[2,e.sent()];case 2:return t=e.sent(),console.error(t),[4,this.unsubscribe()];case 3:return e.sent(),[2,this.subscribePushManager()];case 4:return[2]}}))}))},t.prototype.subscribePushManager=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.getServiceWorkerRegistration()];case 1:return t=n.sent(),[4,this.getApplicationServerKey()];case 2:return e=n.sent(),[2,t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:e?this.urlBase64ToUint8Array(e):null})]}}))}))},t.prototype.getCredentials=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.getServiceWorkerRegistration()];case 1:return[4,t.sent().pushManager.getSubscription()];case 2:return[2,t.sent()]}}))}))},t.prototype.getPushToken=function(t){return t?t.endpoint:""},t.prototype.getApplicationServerKey=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.getDeviceType()];case 1:return 11!==t.sent()?[2]:[4,this.data.getApplicationServerKey()];case 2:return[2,t.sent()]}}))}))},t.prototype.urlBase64ToUint8Array=function(t){for(var e=(t+"=".repeat((4-t.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),n=atob(e),i=new Uint8Array(n.length),r=0;r<n.length;++r)i[r]=n.charCodeAt(r);return i},t}(),It=function(){function t(t,e,n){this.api=t,this.config=n,this.data=e}return t.prototype.getPermission=function(){return this.getPermissionInfo().permission},t.prototype.checkIsPermissionGranted=function(){return this.getPermission()===w},t.prototype.checkIsPermissionDefault=function(){return this.getPermission()===y},t.prototype.checkIsManualUnsubscribed=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.getStatusManualUnsubscribed()];case 1:return[2,t.sent()]}}))}))},t.prototype.askPermission=function(){return o(this,void 0,void 0,(function(){var t,e,n,i=this;return a(this,(function(r){switch(r.label){case 0:return[4,this.data.getApplicationCode()];case 1:return t=r.sent(),[4,this.data.getHwid()];case 2:return e=r.sent(),n={application:t,hwid:e},[2,new Promise((function(t){safari.pushNotification.requestPermission(i.config.entrypoint||"https://cp.pushwoosh.com/json/1.3/safari",i.config.webSitePushId,n,(function(){return t()}))}))]}}))}))},t.prototype.getTokens=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.data.getTokens()]}))}))},t.prototype.subscribe=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return this.checkIsPermissionGranted()?[4,this.getPermissionInfo()]:(ft.error("You must have permission granted before subscribe!"),[2]);case 1:return t=e.sent().deviceToken,[4,this.data.setTokens({pushToken:t})];case 2:return e.sent(),[4,this.api.registerDevice()];case 3:return e.sent(),[2]}}))}))},t.prototype.unsubscribe=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.setTokens({})];case 1:return t.sent(),[4,this.data.setStatusManualUnsubscribed(!0)];case 2:return t.sent(),[4,this.api.unregisterDevice()];case 3:return t.sent(),[2]}}))}))},t.prototype.checkIsRegister=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.api.checkDeviceSubscribeForPushNotifications()]}))}))},t.prototype.checkIsNeedResubscribe=function(){return o(this,void 0,void 0,(function(){var t,e,n,i;return a(this,(function(r){switch(r.label){case 0:return[4,this.data.getWebSitePushId()];case 1:return t=r.sent(),e=void 0!==t&&this.config.webSitePushId!==t,[4,this.data.setWebSitePushId(this.config.webSitePushId)];case 2:return r.sent(),[4,this.data.getLastPermissionStatus()];case 3:return n=r.sent(),i=this.getPermission(),n===i?[3,5]:[4,this.data.setLastPermissionStatus(i)];case 4:return r.sent(),[2,!0];case 5:return[2,e]}}))}))},t.prototype.getPermissionInfo=function(){return safari.pushNotification.permission(this.config.webSitePushId)},t}(),Mt=function(){function t(){var t=this;this.ready=!1,this.addEventHandler=function(e,n){return t.eventBus.addEventHandler(e,n)},this.removeEventHandler=function(e,n){return t.eventBus.removeEventHandler(e,n)},this.dispatchEvent=function(e,n){return t.eventBus.dispatchEvent(e,n)},this.debug={showLog:function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,dt.getAll()];case 1:return t=e.sent(),console.log(t),[2]}}))}))},showKeyValues:function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,pt.getAll()];case 1:return t=e.sent(),console.log(t),[2]}}))}))},showMessages:function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,ht.getAll()];case 1:return t.sent().forEach((function(t){return console.log(t)})),[2]}}))}))}},this.eventBus=new F,this.data=new Ct,this.apiClient=new St(this.data),this.api=new Et(this.eventBus,this.data,this.apiClient),this.platformChecker=new kt(j()),this.inboxModel=new _t(this.eventBus,this.data,this.api),this.pwinbox=new vt(this.data,this.api,this.inboxModel),this.onServiceWorkerMessage=this.onServiceWorkerMessage.bind(this),this.subscriptionPromptWidget=new V(this.eventBus,this)}return t.prototype.push=function(t){if("function"!=typeof t){if(!Array.isArray(t))throw new Error("Invalid command!");switch(t[0]){case"init":this.initialize(t[1]);break;case x:case _:case E:case C:case S:case I:case M:case B:case D:case O:case W:case R:case A:case L:case N:case U:case P:case k:case T:this.subscribeToLegacyEvents(t[0],t[1]);break;default:throw new Error("Unknown command!")}}else this.subscribeToLegacyEvents("onReady",t)},t.prototype.subscribe=function(){return o(this,arguments,void 0,(function(t){var e,n,i,r;return void 0===t&&(t=!0),a(this,(function(s){switch(s.label){case 0:return this.isCommunicationDisabled&&ft.error("Communication is disabled!"),this.driver.checkIsPermissionDefault()?(this.eventBus.dispatchEvent("show-notification-permission-dialog",{}),[4,this.driver.askPermission()]):[3,2];case 1:s.sent(),e=this.driver.getPermission(),this.eventBus.dispatchEvent("hide-notification-permission-dialog",{permission:e}),s.label=2;case 2:return n=this.driver.getPermission(),[4,this.data.getStatusManualUnsubscribed()];case 3:return i=s.sent(),[4,this.api.checkDeviceSubscribeForPushNotifications(!1)];case 4:return r=s.sent(),n!==w?[3,7]:(this.eventBus.dispatchEvent("permission-granted",{}),!r&&!i||t?[4,this.driver.subscribe()]:[3,6]);case 5:s.sent(),s.label=6;case 6:return this.eventBus.dispatchEvent("subscribe",{}),[2];case 7:return n!==m?[3,10]:(this.eventBus.dispatchEvent("permission-denied",{}),r?[4,this.driver.unsubscribe()]:[3,9]);case 8:s.sent(),s.label=9;case 9:case 10:return[2]}}))}))},t.prototype.unsubscribe=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.driver.unsubscribe()];case 1:return e.sent(),[3,3];case 2:return t=e.sent(),ft.error(t,"Error occurred during the unsubscribe"),[3,3];case 3:return[2]}}))}))},t.prototype.forceSubscribe=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.subscribe(!0)];case 1:return t.sent(),[2]}}))}))},t.prototype.isDeviceRegistered=function(){return localStorage.getItem(f)===b},t.prototype.isDeviceUnregistered=function(){return localStorage.getItem(f)===v},t.prototype.isSubscribed=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){return[2,this.api.checkDeviceSubscribeForPushNotifications()]}))}))},t.prototype.isCommunicationEnabled=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.getStatusCommunicationDisabled()];case 1:return[2,!t.sent()]}}))}))},t.prototype.setCommunicationEnabled=function(){return o(this,arguments,void 0,(function(t){var e,n;return void 0===t&&(t=!0),a(this,(function(i){switch(i.label){case 0:return[4,this.data.getDeviceType()];case 1:return e=i.sent(),n=this.driver.checkIsPermissionGranted(),[4,this.data.setStatusCommunicationDisabled(!t)];case 2:return i.sent(),t?[4,this.data.setStatusDropAllData(!1)]:[3,6];case 3:return i.sent(),n?[4,this.api.registerDevice()]:[3,5];case 4:i.sent(),i.label=5;case 5:return[3,8];case 6:return[4,this.api.unregisterDevice()];case 7:i.sent(),i.label=8;case 8:return this.eventBus.dispatchEvent("change-enabled-communication",{isEnabled:t}),[4,this.api.postEvent("GDPRConsent",{channel:t,device_type:e})];case 9:return i.sent(),[2]}}))}))},t.prototype.removeAllDeviceData=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return[4,this.data.getDeviceType()];case 1:return t=e.sent(),[4,this.api.postEvent("GDPRDelete",{status:!0,device_type:t})];case 2:return e.sent(),[4,this.api.deleteDevice()];case 3:return e.sent(),[4,this.data.clearAll()];case 4:return e.sent(),[4,this.data.setStatusDropAllData(!0)];case 5:return e.sent(),[2]}}))}))},t.prototype.getHWID=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.getHwid()];case 1:return[2,t.sent()]}}))}))},t.prototype.getPushToken=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.getTokens()];case 1:return[2,t.sent().pushToken]}}))}))},t.prototype.getUserId=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.data.getUserId()];case 1:return[2,t.sent()]}}))}))},t.prototype.getParams=function(){return o(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return[4,this.api.getParams()];case 1:return[2,t.sent()]}}))}))},t.prototype.isAvailableNotifications=function(){return this.platformChecker.isAvailableNotifications},t.prototype.sendStatisticsVisitedPage=function(){return o(this,void 0,void 0,(function(){var t,e,n,i,r;return a(this,(function(s){switch(s.label){case 0:return t=window.document.title,e=window.location,n=e.origin,i=e.pathname,r=e.href,[4,this.api.pageVisit({title:t,url_path:"".concat(n).concat(i),url:r})];case 1:return s.sent(),[2]}}))}))},t.prototype.initialize=function(t){return o(this,void 0,void 0,(function(){var e,n,i,s,o,c,u,p,d,h,l,f,b,v,m,w;return a(this,(function(a){switch(a.label){case 0:return e=localStorage.getItem("PW_SET_LOGGER_LEVEL"),ft.setLevel(e||t.logLevel||"error"),this.platformChecker.isAvailableNotifications?[4,this.data.getApplicationCode()]:[2];case 1:if(n=a.sent(),!t.applicationCode)throw new Error("Can't find application code!");return i=!n,s=n&&n!==t.applicationCode,i||s?[4,this.data.clearAll()]:[3,4];case 2:return a.sent(),[4,this.data.setApplicationCode(t.applicationCode)];case 3:a.sent(),a.label=4;case 4:return[4,this.data.getHwid()];case 5:return a.sent()?[3,7]:(o=t.applicationCode+"_"+g(),[4,this.data.setHwid(o)]);case 6:a.sent(),a.label=7;case 7:return[4,this.data.setDeviceType(this.platformChecker.getPlatformType())];case 8:return a.sent(),[4,this.data.setDeviceModel(this.platformChecker.getBrowserVersion())];case 9:return a.sent(),[4,this.data.setLanguage(t.tags&&t.tags.Language||navigator.language)];case 10:return a.sent(),[4,this.data.setApiEntrypoint(t.pushwooshUrl||"")];case 11:return a.sent(),[4,this.data.setApiToken(t.apiToken||"")];case 12:return a.sent(),[4,this.data.setSdkVersion("3.39.8")];case 13:return a.sent(),[4,this.api.getConfig(["page_visit","vapid_key","web_in_apps","events","subscription_prompt"])];case 14:return c=a.sent(),this.onGetConfig(c&&c.features),this.subscribeWidgetConfig=r({enable:!1},t.subscribeWidget),this.inboxWidgetConfig=r({enable:!1},t.inboxWidget),this.subscribePopupConfig=r({enable:!1},t.subscribePopup),u=this,[4,this.data.getStatusCommunicationDisabled()];case 15:return u.isCommunicationDisabled=a.sent(),[4,this.open()];case 16:return a.sent(),[4,this.data.getStatusUserIdWasChanged()];case 17:return p=a.sent(),!t.userId||"user_id"===t.userId||p?[3,19]:[4,this.api.registerUser(t.userId)];case 18:a.sent(),a.label=19;case 19:return[4,this.data.getStatusEmailWasChanged()];case 20:return d=a.sent(),!t.email||""===t.email||d?[3,23]:/^\S+@\S+\.\S+$/.test(t.email)?[4,this.api.registerEmail(t.email)]:[3,22];case 21:return a.sent(),[3,23];case 22:ft.write("error","can't register invalid email: ".concat(t.email)),a.label=23;case 23:return t.tags&&this.api.setTags(t.tags),[4,this.data.getApplicationServerKey()];case 24:return h=a.sent(),this.platformChecker.isAvailableNotifications&&h?[4,this.initPushNotifications(t)]:[3,26];case 25:a.sent(),a.label=26;case 26:return a.trys.push([26,28,,29]),[4,this.inboxModel.updateMessages()];case 27:return a.sent(),[3,29];case 28:return l=a.sent(),ft.write("error",l),[3,29];case 29:return this.ready=!0,this.eventBus.dispatchEvent("ready",{}),[4,this.data.getDelayedEvent()];case 30:return(f=a.sent())?(b=f.type,v=f.payload,[4,this.emitLegacyEventsFromServiceWorker(b,v)]):[3,33];case 31:return a.sent(),[4,this.data.setDelayedEvent(null)];case 32:a.sent(),a.label=33;case 33:return"serviceWorker"in navigator&&(navigator.serviceWorker.onmessage=this.onServiceWorkerMessage),localStorage.setItem("pushwoosh-websdk-status","init"),document.dispatchEvent(new CustomEvent("pushwoosh.initialized",{detail:{pw:this}})),this.platformChecker.isSafari&&(m=/#P(.*)/,w=decodeURIComponent(document.location.hash),m.test(w)&&this.api.pushStat(m.exec(w)[1]).then(Y)),[2]}}))}))},t.prototype.defaultProcess=function(t){return o(this,void 0,void 0,(function(){var e,n,i,r,s,o,c,u,p,d,h;return a(this,(function(a){switch(a.label){case 0:return"granted"!==(e=this.driver.getPermission())?[3,2]:[4,this.data.setLastPermissionStatus(e)];case 1:a.sent(),a.label=2;case 2:return[4,this.data.getStatusCommunicationDisabled()];case 3:return n=a.sent(),[4,this.data.getStatusDropAllData()];case 4:return i=a.sent(),[4,this.driver.checkIsNeedResubscribe()];case 5:return r=a.sent(),[4,this.data.getFeatures()];case 6:return s=a.sent(),o=s.subscription_prompt&&s.subscription_prompt.use_case,n||i?[4,this.unsubscribe()]:[3,8];case 7:return a.sent(),[2];case 8:return r?[4,this.unsubscribe()]:[3,12];case 9:return a.sent(),[4,this.data.setStatusManualUnsubscribed(!1)];case 10:return a.sent(),[4,this.data.setIsVapidChanged(!1)];case 11:a.sent(),a.label=12;case 12:return c=t.autoSubscribe,[4,this.data.getStatusManualUnsubscribed()];case 13:return u=a.sent(),[4,this.api.checkDeviceSubscribeForPushNotifications(!1)];case 14:switch(p=a.sent(),e){case y:return[3,15];case m:return[3,21];case w:return[3,24]}return[3,29];case 15:return this.eventBus.dispatchEvent("permission-default",{}),p?[4,this.unsubscribe()]:[3,17];case 16:a.sent(),a.label=17;case 17:return[4,this.getWidgetConfig()];case 18:return d=a.sent(),[4,this.checkCanShowByCapping(d)];case 19:return a.sent()?(h="not-set"===o&&c,("default"===o||h)&&(this.subscriptionPromptWidget.init(d),this.subscriptionPromptWidget.show()),[4,this.updateCappingParams()]):[3,29];case 20:return a.sent(),[3,29];case 21:return this.eventBus.dispatchEvent("permission-denied",{}),p?[4,this.unsubscribe()]:[3,23];case 22:a.sent(),a.label=23;case 23:return[3,29];case 24:return this.eventBus.dispatchEvent("permission-granted",{}),u&&p?[4,this.unsubscribe()]:[3,26];case 25:a.sent(),a.label=26;case 26:return!p&&!u||r?[4,this.subscribe(!0)]:[3,28];case 27:a.sent(),a.label=28;case 28:return[3,29];case 29:return[2]}}))}))},t.prototype.getWidgetConfig=function(){return o(this,void 0,void 0,(function(){var t,e,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.data.getFeatures()];case 1:return t=i.sent(),e=t.subscription_prompt_widget&&t.subscription_prompt_widget.params,n=r({cappingCount:q.cappingCount,cappingDelay:q.cappingDelay},e),[2,e?n:q]}}))}))},t.prototype.checkCanShowByCapping=function(t){return o(this,void 0,void 0,(function(){var e,n,i,r,s;return a(this,(function(o){switch(o.label){case 0:return e=(new Date).getTime(),[4,this.data.getPromptDisplayCount()];case 1:return n=o.sent(),[4,this.data.getPromptLastSeenTime()];case 2:return i=o.sent(),r=t.cappingCount>n,s=e-i>t.cappingDelay,[2,r&&s]}}))}))},t.prototype.updateCappingParams=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return[4,this.data.getPromptDisplayCount()];case 1:return t=n.sent(),e=(new Date).getTime(),[4,this.data.setPromptDisplayCount(t+1)];case 2:return n.sent(),[4,this.data.setPromptLastSeenTime(e)];case 3:return n.sent(),[2]}}))}))},t.prototype.onServiceWorkerMessage=function(t){var e=(t||{}).data,n=(void 0===e?{}:e)||{},i=n.type,r=void 0===i?"":i,s=n.payload,o=void 0===s?{}:s;this.emitLegacyEventsFromServiceWorker(r,o)},t.prototype.open=function(t){return o(this,void 0,void 0,(function(){var e,n,i;return a(this,(function(r){switch(r.label){case 0:return[4,this.data.getLastOpenApplicationTime()];case 1:return e=r.sent(),n=Date.now(),e||(e=0),i=n-e<36e5,t||!i?[4,this.data.setLastOpenApplicationTime(n)]:[2];case 2:return r.sent(),[4,this.api.applicationOpen()];case 3:return r.sent(),[2]}}))}))},t.prototype.onGetConfig=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.data.setFeatures(t)];case 1:return n.sent(),t?t.page_visit&&t.page_visit.enabled?[4,pt.set("PAGE_VISITED_URL",t.page_visit.entrypoint)]:[3,3]:[3,7];case 2:n.sent(),this.sendStatisticsVisitedPage(),n.label=3;case 3:return t.events&&t.events.length&&t.events.some((function(t){return t===H}))&&this.sendPostEventVisitedPage(),t.vapid_key?[4,this.data.getApplicationServerKey()]:[3,7];case 4:return e=n.sent(),[4,this.data.setApplicationServerKey(t.vapid_key)];case 5:return n.sent(),e===t.vapid_key?[3,7]:[4,this.data.setIsVapidChanged(!0)];case 6:n.sent(),n.label=7;case 7:return[2]}}))}))},t.prototype.initPushNotifications=function(t){return o(this,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return[4,this.data.setDefaultNotificationImage(t.defaultNotificationImage)];case 1:return n.sent(),[4,this.data.setDefaultNotificationTitle(t.defaultNotificationTitle)];case 2:return n.sent(),[4,this.data.setServiceWorkerUrl(t.serviceWorkerUrl)];case 3:return n.sent(),[4,this.data.setServiceWorkerScope(t.scope)];case 4:return n.sent(),[4,this.data.setInitParams(r({autoSubscribe:!0},t))];case 5:return n.sent(),[4,this.initDriver()];case 6:n.sent(),n.label=7;case 7:return n.trys.push([7,9,,10]),[4,this.defaultProcess(t)];case 8:return n.sent(),[3,10];case 9:return e=n.sent(),ft.error(e,"Internal error: defaultProcess fail"),[3,10];case 10:return[2]}}))}))},t.prototype.initDriver=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:return this.platformChecker.isSafari?[4,this.data.getInitParams()]:[3,2];case 1:return(t=e.sent().safariWebsitePushID)?(this.driver=new It(this.api,this.data,{webSitePushId:t}),[2]):(ft.info("For work with Safari Push Notification add safariWebsitePushID to initParams!"),[2]);case 2:return this.platformChecker.isAvailableServiceWorker?(this.driver=new Tt(this.api,this.data,{}),[2]):[2]}}))}))},t.prototype.sendPostEventVisitedPage=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){return t=window.document.title,e=window.location.href,this.api.postEvent(H,{url:e,title:t,device_type:this.platformChecker.platform}),[2]}))}))},t.prototype.subscribeToLegacyEvents=function(t,e){var n=this;switch(t){case x:e();break;case _:if(this.ready){e(this.api);break}this.eventBus.addEventHandler("ready",(function(){return e(n.api)}));break;case E:this.eventBus.addEventHandler("register",(function(){return e(n.api)}));break;case C:this.eventBus.addEventHandler("subscribe",(function(){return e(n.api)}));break;case S:this.eventBus.addEventHandler("unsubscribe",(function(){return e(n.api)}));break;case I:this.eventBus.addEventHandler("initialize-service-worker-error",(function(t){var i=t.error;return e(n.api,i)}));break;case M:this.eventBus.addEventHandler("receive-push",(function(t){var i=t.notification;return e(n.api,i)}));break;case B:this.eventBus.addEventHandler("open-notification",(function(t){var i=t.notification;return e(n.api,i)}));break;case D:this.eventBus.addEventHandler("hide-notification",(function(t){var i=t.notification;return e(n.api,i)}));break;case O:this.eventBus.addEventHandler("change-enabled-communication",(function(t){var i=t.isEnabled;return e(n.api,i)}));break;case W:this.eventBus.addEventHandler("receive-inbox-message",(function(t){var i=t.message;return e(n.api,i)}));break;case R:this.eventBus.addEventHandler("update-inbox-messages",(function(t){var i=t.messages;return e(n.api,i)}));break;case A:this.eventBus.addEventHandler("show-notification-permission-dialog",(function(){return e(n.api)}));break;case L:this.eventBus.addEventHandler("hide-notification-permission-dialog",(function(t){var i=t.permission;return e(n.api,i)}));break;case N:this.eventBus.addEventHandler("show-subscription-widget",(function(){return e(n.api)}));break;case U:this.eventBus.addEventHandler("hide-subscription-widget",(function(){return e(n.api)}));break;case P:this.eventBus.addEventHandler("permission-denied",(function(){return e(n.api)}));break;case k:this.eventBus.addEventHandler("permission-default",(function(){return e(n.api)}));break;case T:this.eventBus.addEventHandler("permission-granted",(function(){return e(n.api)}))}},t.prototype.emitLegacyEventsFromServiceWorker=function(t,e){switch(t){case M:this.eventBus.dispatchEvent("receive-push",{notification:e});break;case B:this.eventBus.dispatchEvent("open-notification",{notification:e});break;case D:this.eventBus.dispatchEvent("hide-notification",{notification:e});break;case W:this.eventBus.dispatchEvent("receive-inbox-message",{message:e})}},t}();const Bt=Mt;var Dt=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],Ot=[{name:"widgetWidth",type:"size"},{name:"borderRadius",type:"size"},{name:"zIndex",type:"number"},{name:"fontFamily",type:"string"},{name:"bgColor",type:"color"},{name:"textColor",type:"color"},{name:"arrowBorderColor",type:"color"},{name:"borderColor",type:"color"},{name:"badgeBgColor",type:"color"},{name:"badgeTextColor",type:"color"},{name:"timeTextColor",type:"color"},{name:"messageTitleColor",type:"color"},{name:"emptyInboxTitleColor",type:"color"},{name:"emptyInboxTextColor",type:"color"}],Wt={enable:!1,triggerId:"pwInbox",position:"bottom",appendTo:"body",title:"Inbox",bgColor:"#ffffff",textColor:"#333333",fontFamily:"inherit",borderRadius:4,borderColor:"transparent",badgeBgColor:"#ff4c00",badgeTextColor:"#ffffff",widgetWidth:350,zIndex:100,messageTitleColor:"#7a7a7a",timeTextColor:"#c4c4c4",emptyInboxTitle:"You're all caught up",emptyInboxTitleColor:"#333333",emptyInboxText:"There are no new messages. Stay tuned!",emptyInboxTextColor:"#7a7a7a",emptyInboxIconUrl:"https://pushon.pushwoosh.com/images/icon-empty-inbox.png",arrowBorderColor:"rgba(0,0,0,.1)"},Rt=/^(#([\da-f]{3}){1,2}$|(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0?\.\d+)\)$|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/;function At(t){var e="fixed"===window.getComputedStyle(t).position;return!e&&t.parentElement&&(e=At(t.parentElement)),e}var Lt=function(t){var e=t.imageUrl,n=t.title,i=t.message,r=t.sendDate;return'\n<div class="pw-inbox_item-inner">\n <div class="pw-inbox_icon">\n <img src="'.concat(e,'" alt="').concat(n||i,'" class="pw-inbox_message-image">\n </div>\n <div class="pw-inbox_content">\n ').concat(n?'<div class="pw-inbox_item-title">\n '.concat(n,"\n </div>"):null,'\n <div class="pw-inbox_item-body">\n ').concat(i,'\n </div>\n <div class="pw-inbox_item-time">\n ').concat(function(t){var e=new Date(t),n=e.getHours()+e.getTimezoneOffset()/60;e.setHours(n);var i=(new Date).getTime()-e.getTime();if(i<=6e4)return"Just now";if(i<36e5&&i>0){var r=Math.floor(i/6e4);return"".concat(r," minutes ago")}if(i<864e5&&i>0){var s=Math.floor(i/36e5);return"".concat(s," hours ago")}var o=e.getDate(),a=Dt[e.getMonth()],c=e.getFullYear(),u=e.getHours(),p="0".concat(e.getMinutes().toString()).slice(-2);return"".concat(o," ").concat(a," ").concat(c,", ").concat(u,":").concat(p)}(r),'\n </div>\n </div>\n</div>\n<span class="pw-inbox_item-remove"></span>')},Nt=function(){function t(t){this.pw=t,this.config=r(r(r({},Wt),{arrowBorderColor:this.pw.inboxWidgetConfig.borderColor&&"transparent"!==this.pw.inboxWidgetConfig.borderColor?this.pw.inboxWidgetConfig.borderColor:"rgba(0,0,0,.1)"}),this.pw.inboxWidgetConfig),this.updateInbox=this.updateInbox.bind(this),this.markVisibleItemsAsRead=this.markVisibleItemsAsRead.bind(this),this.onWidgetClickHandler=this.onWidgetClickHandler.bind(this),this.onTriggerClickHandler=this.onTriggerClickHandler.bind(this),this.onWindowScrollHandler=this.onWindowScrollHandler.bind(this),this.toggle=this.toggle.bind(this);try{this.initTrigger(),this.updateInbox(),this.addListeners()}catch(t){console.warn(t)}}return t.prototype.toggle=function(t){(void 0===t?!this.isOpened:t)?this.openWidget():this.closeWidget()},t.prototype.initTrigger=function(){if(!this.pw.pwinbox)throw new Error("Web inbox is not allowed.");var t=document.getElementById(this.config.triggerId);if(!t)throw new Error("Inbox trigger element doesn't exist. You must set triggerId in inboxWidget config. See the documentation.");this.trigger=t,this.trigger.classList.add("pw-inbox-trigger"),this.defaultMargin=12,this.messagesElements={},this.messages=[],this.readItems=[],this.updateCounter(0),this.isOpened=!1,this.renderWidget(),this.isFixed=At(this.trigger)},t.prototype.renderWidget=function(){this.widget=document.createElement("div"),this.widget.id="pwInboxWidget",this.widget.className="pw-inbox-widget",this.widget.classList.toggle("pw-open",this.isOpened),this.widgetParent=document.querySelector(this.config.appendTo)||document.body,this.widgetParent.appendChild(this.widget),this.widgetParent.appendChild(this.getStyle()),this.renderWidgetInner()},t.prototype.getStyle=function(){var t=document.createElement("style");return t.innerHTML=this.configureStyle(".pw-inbox-trigger {\n position: relative;\n cursor: pointer;\n}\n\n.pw-inbox-trigger:after {\n content: attr(data-pw-count);\n display: block;\n position: absolute;\n right: 0;\n top: 0;\n background: var(--badgeBgColor);\n border-radius: 8px;\n color: var(--badgeTextColor);\n font-size: 10px;\n font-weight: normal;\n line-height: 16px;\n width: 16px;\n padding: 0 2px;\n box-sizing: border-box;\n text-align: center;\n}\n\n.pw-inbox-trigger.pw-empty:after {\n display: none;\n}\n\n.pw-inbox-widget * {\n position: static;\n box-sizing: border-box;\n font-size: 1em;\n outline: none;\n font-family: var(--fontFamily);\n}\n.pw-inbox-widget {\n font-size: 14px;\n position: absolute;\n top: 0;\n left: -1000px;\n background: var(--bgColor);\n border: solid 1px var(--borderColor);\n border-radius: var(--borderRadius);\n width: var(--widgetWidth);\n box-shadow: 0 1px 4px 0 rgba(0,0,0,.25);\n z-index: var(--zIndex);\n opacity: 0;\n transition: opacity .6s ease;\n transition-delay: 100ms;\n}\n.pw-inbox-widget.pw-open {\n opacity: 1;\n transition-delay: 0ms;\n}\n.pw-inbox-widget.pw-inbox-widget--inset {\n top: auto;\n left: auto;\n display: none;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-open {\n display: block;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-bottom {\n top: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-top {\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-right {\n left: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-left {\n right: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--empty {\n max-height: none;\n}\n.pw-inbox-widget .pw-inbox__arrow {\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget .pw-inbox__arrow:before {\n content: \"\";\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget.pw-top {\n margin-top: -12px;\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow {\n border-top-color: var(--arrowBorderColor);\n bottom: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow:before {\n border-top-color: var(--bgColor);\n top: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-bottom {\n margin-top: 12px;\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow {\n border-bottom-color: var(--arrowBorderColor);\n top: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow:before {\n border-bottom-color: var(--bgColor);\n bottom: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-left {\n margin-left: -12px;\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow {\n border-left-color: var(--arrowBorderColor);\n right: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow:before {\n border-left-color: var(--bgColor);\n left: -11px;\n top: -10px;\n}\n.pw-inbox-widget.pw-right {\n margin-left: 12px;\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow {\n border-right-color: var(--arrowBorderColor);\n left: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow:before {\n border-right-color: var(--bgColor);\n right: -11px;\n top: -10px;\n}\n.pw-inbox_inner {\n overflow: hidden;\n display: flex;\n flex-direction: column;\n height: 100%;\n}\n.pw-inbox_title {\n color: var(--textColor);\n margin: 0;\n padding: 28px 32px 12px;\n font-size: 24px;\n font-weight: 500;\n line-height: 1.1;\n text-align: left;\n flex: 0 0 66px;\n}\n.pw-inbox_list {\n overflow-x: hidden;\n overflow-y: auto;\n min-width: 200px;\n max-height: 300px;\n padding: 0;\n margin: 0;\n list-style: none;\n position: relative;\n flex: 1 1 auto;\n}\n\n.pw-inbox_item {\n position: relative;\n padding: 8px 32px;\n margin: 0;\n text-align: left;\n}\n.pw-inbox_item-inner {\n display: flex;\n cursor: pointer;\n}\n.pw-inbox_icon {\n flex: 0 0 40px;\n}\n.pw-inbox_message-image {\n width: 28px;\n}\n.pw-inbox_content {\n flex: 0 1 100%;\n}\n.pw-inbox_item-title {\n color: var(--messageTitleColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n}\n.pw-inbox_item-body {\n color: var(--textColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n}\n.pw-inbox_item-time {\n color: var(--timeTextColor);\n font-size: 12px;\n line-height: 17px;\n}\n.pw-inbox_item-remove {\n position: absolute;\n z-index: 2;\n top: 8px;\n right: 8px;\n display: none;\n width: 10px;\n height: 10px;\n background: transparent url('https://cdn.pushwoosh.com/webpush/img/iconClose.svg') 50% no-repeat;\n cursor: pointer;\n}\n.pw-inbox_item:hover .pw-inbox_item-remove {\n display: block;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-title {\n color: var(--textColor);\n font-weight: 700;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-body {\n font-weight: 700;\n}\n\n.pw-inbox_list--empty {\n padding: 50px 16px;\n text-align: center;\n max-height: 100%;\n overflow: auto;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-icon {\n text-align: center;\n margin-bottom: 30px;\n}\n.pw-inbox_list--empty .pw-inbox_list-icon img {\n max-width: 100%;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-title {\n font-size: 28px;\n line-height: 36px;\n color: var(--emptyInboxTitleColor);\n margin-bottom: 20px;\n}\n\n.pw-inbox_list--empty .ipw-inbox_list-body {\n font-size: 14px;\n line-height: 18px;\n color: var(--emptyInboxTextColor);\n}\n"),t},t.prototype.configureStyle=function(t){var e=this,n=t.toString();return Ot.forEach((function(t){var i=new RegExp("var\\(--".concat(t.name,"\\)"),"ig"),r=e.getStyleFormatter(t);n=n.replace(i,r)})),n},t.prototype.getStyleFormatter=function(t){switch(t.type){case"size":return"".concat(this.config[t.name]||0,"px");case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return"transparent"===(e=this.config[t.name].toString())||Rt.test(e)?e:"#333";default:return"none"}var e},t.prototype.renderWidgetInner=function(){if(this.messages.length>0)this.widget.classList.remove("pw-inbox-widget--empty"),this.widget.innerHTML=(r=this.config.title,'\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_inner">\n <div class="pw-inbox_title">\n '.concat(r,'\n </div>\n <ul class="pw-inbox_list">\n\n </ul>\n</div>')),this.renderMessages();else{this.widget.classList.add("pw-inbox-widget--empty");var t=this.config,e=t.emptyInboxTitle,n=t.emptyInboxText,i=t.emptyInboxIconUrl;this.widget.innerHTML=function(t,e,n){return'\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_list--empty">\n <div class="pw-inbox_list-icon">\n <img src="'.concat(t,'" alt="').concat(e,'">\n </div>\n <div class="pw-inbox_list-title">\n ').concat(e,'\n </div>\n <div class="ipw-inbox_list-body">\n ').concat(n,"\n </div>\n</div>")}(i,e,n)}var r},t.prototype.renderMessages=function(){var t=this;this.list=this.widget.querySelector(".pw-inbox_list")||document.createElement("ul"),this.messages.forEach((function(e){var n=document.createElement("li");n.className="pw-inbox_item",n.classList.toggle("pw-new",!e.isRead),n.classList.toggle("pw-unread",!e.isActionPerformed),n.setAttribute("data-pw-inbox-message-id",e.code),n.innerHTML=Lt(e),t.list.appendChild(n),t.messagesElements[e.code]=n}))},t.prototype.updateCounter=function(t){this.count=t,this.trigger.setAttribute("data-pw-count","".concat(this.count)),this.trigger.classList.toggle("pw-empty",0===this.count)},t.prototype.updateInboxMessages=function(t){this.messages=t.sort((function(t,e){var n,i,r,s,o,a=t.sendDate,c=e.sendDate;return n=c,i=new Date(a),r=i.getHours()+i.getTimezoneOffset()/60,s=new Date(n),o=s.getHours()+s.getTimezoneOffset()/60,i.setHours(r),s.setHours(o),s.getTime()-i.getTime()})),this.renderWidgetInner()},t.prototype.openWidget=function(){this.isOpened=!0,this.widget.classList.add("pw-open"),document.addEventListener("click",this.onWidgetClickHandler),window.addEventListener("scroll",this.onWindowScrollHandler),window.addEventListener("resize",this.onWindowScrollHandler),this.markVisibleItemsAsRead(),this.messages.length>0&&this.list.addEventListener("scroll",this.markVisibleItemsAsRead),this.positionWidget()},t.prototype.closeWidget=function(){this.isOpened=!1,document.removeEventListener("click",this.onWidgetClickHandler),document.removeEventListener("click",this.onWindowScrollHandler),window.removeEventListener("resize",this.onWindowScrollHandler),this.updateReadStatus(),this.messages.length>0&&this.list.removeEventListener("scroll",this.markVisibleItemsAsRead),this.widget.classList.remove("pw-open","pw-top","pw-bottom","pw-right","pw-left"),this.widget.removeAttribute("style")},t.prototype.positionWidget=function(){this.isOpened&&(this.widgetParent===document.body?this.defaultPlaceWidget():this.customPlaceWidget())},t.prototype.customPlaceWidget=function(){var t=this.config.position;this.widgetParent.style.position="relative",this.widget.classList.add("pw-inbox-widget--inset"),this.widget.classList.add("pw-".concat(t))},t.prototype.defaultPlaceWidget=function(){var t=this.pw.inboxWidgetConfig.position?this.config.position:this.getDefaultPosition(),e=this.widget.getBoundingClientRect();if(document.documentElement){var n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0);switch(e.width+2*this.defaultMargin>n&&(this.widget.style.width="".concat(n-2*this.defaultMargin,"px")),e.height+24>i&&(this.widget.style.height="".concat(i-2*this.defaultMargin,"px")),t){case"top":this.alignWidgetTop();break;case"right":this.alignWidgetRight();break;case"left":this.alignWidgetLeft();break;case"bottom":this.alignWidgetBottom()}}},t.prototype.alignWidgetTop=function(){var t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(document.documentElement){var n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-top");var r=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2),s=r<pageXOffset,o=r+e.width>pageXOffset+n;s&&(r=pageXOffset+this.defaultMargin),o&&(r=pageXOffset+n-e.width-this.defaultMargin);var a=pageYOffset+t.top-e.height;this.alignWidgetElement(r,a),i.style.left="".concat(t.left+Math.floor(t.width/2)-r,"px");var c=this.widget.getBoundingClientRect().top;if(c<0){var u=this.widget.getBoundingClientRect().height+c-this.defaultMargin,p=this.widget.getBoundingClientRect().top-c+this.defaultMargin;this.widget.style.height="".concat(u,"px"),this.widget.style.top="".concat(p,"px")}}},t.prototype.alignWidgetRight=function(){var t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(document.documentElement){var n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),r=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-right");var s=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2),o=s<pageYOffset,a=pageYOffset+i<s+e.height;o&&(s=pageYOffset+this.defaultMargin),a&&(s=pageYOffset+i-e.height-this.defaultMargin);var c=pageXOffset+t.left+t.width;this.alignWidgetElement(c,s),r.style.top="".concat(t.top+Math.floor(t.height/2)-s,"px");var u=n-this.widget.getBoundingClientRect().right;if(u<this.defaultMargin){var p=this.widget.getBoundingClientRect().width+u-this.defaultMargin;this.widget.style.width="".concat(p,"px")}}},t.prototype.alignWidgetLeft=function(){var t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(document.documentElement){var n=Math.max(document.documentElement.clientHeight,window.innerHeight||0),i=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-left");var r=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2),s=r<pageYOffset,o=pageYOffset+n<r+e.height;s&&(r=pageYOffset+this.defaultMargin),o&&(r=pageYOffset+n-e.height-this.defaultMargin);var a=pageXOffset+t.left-e.width;this.alignWidgetElement(a,r),i.style.top="".concat(t.top+Math.floor(t.height/2)-r,"px");var c=this.widget.getBoundingClientRect().left;if(c<0){var u=this.widget.getBoundingClientRect().width+c-this.defaultMargin,p=this.widget.getBoundingClientRect().left-c;this.widget.style.width="".concat(u,"px"),this.widget.style.left="".concat(p,"px")}}},t.prototype.alignWidgetBottom=function(){var t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(document.documentElement){var n=Math.max(document.documentElement.clientWidth,window.innerWidth||0),i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),r=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-bottom");var s=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2),o=s<pageXOffset,a=s+e.width>pageXOffset+n;o&&(s=pageXOffset+this.defaultMargin),a&&(s=pageXOffset+n-e.width-12);var c=pageYOffset+t.top+t.height;this.alignWidgetElement(s,c),r.style.left="".concat(t.left+Math.floor(t.width/2)-s,"px");var u=i-this.widget.getBoundingClientRect().bottom;if(u<this.defaultMargin){var p=this.widget.getBoundingClientRect().height+u-this.defaultMargin;this.widget.style.height="".concat(p,"px")}}},t.prototype.alignWidgetElement=function(t,e){this.widget.style.left="".concat(t,"px"),this.widget.style.top="".concat(e,"px")},t.prototype.getDefaultPosition=function(){var t=this.trigger.getBoundingClientRect(),e=t.left,n=t.top,i=t.width,r=t.height;if(!document.documentElement)return"";var s={right:e,bottom:n,left:Math.max(document.documentElement.clientWidth,window.innerWidth||0)-(e+i),top:Math.max(document.documentElement.clientHeight,window.innerHeight||0)-(n+r)},o=Math.min(e,n,s.left,s.top),a="bottom";return Object.keys(s).forEach((function(t){s[t]===o&&(a=t)})),a},t.prototype.addListeners=function(){var t=this;this.trigger.addEventListener("click",this.onTriggerClickHandler),this.pw.push(["onPutNewMessageToInboxStore",function(){t.updateInbox()}]),this.pw.push(["onUpdateInboxMessages",function(){t.updateInbox()}])},t.prototype.markVisibleItemsAsRead=function(){var t=this;if(0!==this.messages.length){var e=this.list.clientHeight+this.list.scrollTop-50;Object.keys(this.messagesElements).forEach((function(n){if(t.messagesElements[n]&&!(t.messagesElements[n].offsetTop>e)){var i=t.messages.find((function(t){return t.code===n}));!i||i.isRead||t.readItems.indexOf(n)+1||t.readItems.push(n)}}))}},t.prototype.updateReadStatus=function(){this.pw.pwinbox.readMessagesWithCodes(this.readItems).then(this.updateInbox)},t.prototype.updateInbox=function(){var t=this;this.pw.pwinbox.loadMessages().then((function(e){t.updateInboxMessages(e)})),this.pw.pwinbox.unreadMessagesCount().then((function(e){t.updateCounter(e)}))},t.prototype.performMessageAction=function(t){var e=this;this.pw.pwinbox.performActionForMessageWithCode(t).then((function(){e.updateInbox()}))},t.prototype.removeMessages=function(t){var e=this;t.forEach((function(t){e.readItems=e.readItems.slice(e.readItems.indexOf(t),1)})),this.pw.pwinbox.deleteMessagesWithCodes(t).then((function(){e.updateInbox()}))},t.prototype.onTriggerClickHandler=function(t){t.stopPropagation(),t.target&&this.toggle()},t.prototype.onWidgetClickHandler=function(t){if(t.target){var e=t.target.closest(".pw-inbox_item");if(e){var n=e.getAttribute("data-pw-inbox-message-id");if(n)t.target.closest(".pw-inbox_item-remove")?this.removeMessages([n]):this.performMessageAction(n)}else this.toggle()}},t.prototype.onWindowScrollHandler=function(){this.isFixed&&this.isOpened?this.toggle():this.positionWidget()},t}();const Ut=Nt;var Ht="bottomRight",qt="bottomLeft",Ft="topRight",zt="topLeft",Vt={position:qt,bgColor:"#12AE7E",bellColor:"white",bellStrokeColor:"#08754f",bellButtonBorder:"1px solid #379676",shadow:"0px 0px 6px rgba(0, 0, 0, 0.75)",size:"48px",indent:"20px",zIndex:"999999",tooltipText:{successSubscribe:"You are successfully subscribed!",needSubscribe:"Get notifications about important news!",blockSubscribe:"Click to see how to get notifications",alreadySubscribed:"You are already subscribed"}};const jt=function(){function t(){}return t.getBellPosition=function(t,e){var n;switch(t){case Ht:n={top:"auto",left:"auto",bottom:e,right:e};break;case qt:n={top:"auto",left:e,bottom:e,right:"auto"};break;case zt:n={top:e,left:e,bottom:"auto",right:"auto"};break;case Ft:n={top:e,left:"auto",bottom:"auto",right:e};break;default:n={top:"auto",left:"auto",bottom:e,right:e}}return n},t.getTooltipPosition=function(t,e){var n,i,r=parseInt(e)+12+"px";switch(t){case Ht:n={right:r},i="right";break;case qt:case zt:n={left:r},i="left";break;default:n={right:r},i="right"}return[n,i]},t.getPopoverPosition=function(t,e){var n,i,r=parseInt(e)+15+"px";switch(t){case Ht:n={bottom:r,right:"0",left:"auto",top:"auto"},i="bottom";break;case qt:n={bottom:r,left:"0",right:"auto",top:"auto"},i="bottom";break;case zt:n={top:r,left:"0",right:"auto",bottom:"auto"},i="top";break;case Ft:n={top:r,right:"0",left:"auto",bottom:"auto"},i="top";break;default:n={bottom:r,right:"0",left:"auto",top:"auto"},i="bottom"}return[n,i]},t.getPopoverArrowPosition=function(t,e){var n;switch(t){case Ht:n="\n.pushwoosh-subscribe-widget__popover__bottom:after {left: auto; right: ".concat(parseInt(e)/2-4+"px");break;case qt:n="\n.pushwoosh-subscribe-widget__popover__bottom:after {right: auto; left: ".concat(parseInt(e)/2-12+"px");break;case zt:n="\n.pushwoosh-subscribe-widget__popover__top:after {right: auto; left: ".concat(parseInt(e)/2-12+"px");break;case Ft:n="\n.pushwoosh-subscribe-widget__popover__top:after {left: auto; right: ".concat(parseInt(e)/2-4+"px");break;default:n="\n.pushwoosh-subscribe-widget__popover__bottom:after {left: auto; right: ".concat(parseInt(e)/2-4+"px")}return n},t}();var Yt=function(){function t(t){var e=this;if(this.pw=t,Pt.isAvailableNotifications){this.clickBell=this.clickBell.bind(this),this.onSubscribeEvent=this.onSubscribeEvent.bind(this),this.onUnsubscribeEvent=this.onUnsubscribeEvent.bind(this),this.onPermissionDeniedEvent=this.onPermissionDeniedEvent.bind(this),this.clickOutOfPopover=this.clickOutOfPopover.bind(this);var n=Object.assign(Vt.tooltipText,t.subscribeWidgetConfig.tooltipText);this.config=Object.assign({},Vt,t.subscribeWidgetConfig),this.config.tooltipText=n,t.isSubscribed().then((function(t){t||e.render()}))}else console.warn("Browser does not support push notifications")}return t.prototype.addStylesToElement=function(t,e){Object.keys(t).forEach((function(n){e.style[n]=t[n]}))},t.prototype.createContainer=function(){var t=document.createElement("div");t.id="pushwooshBellWidget",t.className="pushwoosh-subscribe-widget";var e=jt.getBellPosition(this.config.position,this.config.indent),n=Object.assign({zIndex:this.config.zIndex},e);return this.addStylesToElement(n,t),t},t.prototype.createStyle=function(){var t=document.createElement("style");return t.innerHTML='/* Widget */\n.pushwoosh-subscribe-widget {\n position: fixed;\n display: block;\n transform: translate3d(0, 0, 0);\n}\n\n.pushwoosh-subscribe-widget__subscribed {\n display: none;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__bell-button {\n border-radius: 50%;\n cursor: pointer;\n font-size: 0;\n text-align: center;\n transform: scale(0.9) translate3d(0, 0, 0);\n transition: transform .3s ease-in-out;\n position: relative;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__bell-button:hover {\n transform: scale(1);\n}\n\n/* Tooltip */\n.pushwoosh-subscribe-widget__tooltip {\n position: absolute;\n height: 48px;\n max-width: 300px;\n min-width: 200px;\n padding: 5px 7px;\n background-color: #3b444b;\n color: #ffffff;\n text-align: center;\n vertical-align: middle;\n box-sizing: border-box;\n line-height: 38px;\n font-size: 0;\n font-weight: normal;\n visibility: hidden;\n opacity: 0;\n transition: visibility 0s ease-in .3s,\n opacity .3s ease-in;\n top: 50%;\n transform: translate(0, -50%);\n box-shadow: 1px 1px 5px 0 rgba(0,0,0,0.5);\n}\n\n.pushwoosh-subscribe-widget__tooltip__right:after,\n.pushwoosh-subscribe-widget__tooltip__left:after {\n content: "";\n top: 50%;\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n border-top: 5px solid transparent;\n border-bottom: 5px solid transparent;\n background: #3b444b;\n}\n\n.pushwoosh-subscribe-widget__tooltip__right:after {\n left: calc(100% - 7px);\n border-top: 5px solid #3b444b;\n border-left: 5px solid #3b444b;\n border-right: 5px solid transparent;\n box-sizing: border-box;\n transform-origin: 0 0;\n transform: rotate(-45deg);\n box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.25);\n}\n\n.pushwoosh-subscribe-widget__tooltip__left:after {\n left: -7px;\n border-top: 5px solid #3b444b;\n border-right: 5px solid #3b444b;\n border-left: 5px solid transparent;\n box-sizing: border-box;\n transform-origin: 0 0;\n transform: rotate(-45deg);\n box-shadow: -2px -2px 2px 0 rgba(0, 0, 0, 0.25);\n}\n\n.pushwoosh-subscribe-widget__bell-button:hover + .pushwoosh-subscribe-widget__tooltip,\n.pushwoosh-subscribe-widget__tooltip.pushwoosh-subscribe-widget__tooltip__visible {\n display: block;\n visibility: visible;\n opacity: 1;\n transition-delay: 0s;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__tooltip-content {\n display: inline-block;\n vertical-align: middle;\n font-size: 14px;\n line-height: 1.4;\n white-space: nowrap;\n overflow: hidden;\n padding-right: 5px;\n text-overflow: ellipsis;\n max-width: 100%;\n}\n\n/* Popover */\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover {\n position: absolute;\n right: auto;\n box-shadow: 1px 1px 5px 0 rgba(0, 0, 0, 0.5);\n box-sizing: border-box;\n background: #9ca8b1;\n visibility: hidden;\n opacity: 0;\n transition: visibility 0s ease-in .5s,\n opacity .5s ease-in;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover__visible {\n display: block;\n visibility: visible;\n opacity: 1;\n transition-delay: 0s;\n}\n\n.pushwoosh-subscribe-widget__popover__bottom:after,\n.pushwoosh-subscribe-widget__popover__top:after {\n content: "";\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n border-right: 8px solid transparent;\n border-left: 8px solid #9ca8b1;\n background: #9ca8b1;\n transform-origin: 0 0;\n transform: rotate(-45deg);\n}\n\n.pushwoosh-subscribe-widget__popover__bottom:after {\n border-bottom: 8px solid #9ca8b1;\n border-top: 8px solid transparent;\n box-sizing: border-box;\n box-shadow: -2px 2px 1px 0 rgba(0, 0, 0, 0.25);\n bottom: -16px;\n}\n\n.pushwoosh-subscribe-widget__popover__top:after {\n top: 0;\n border-top: 8px solid #9ca8b1;\n border-bottom: 8px solid transparent;\n box-sizing: border-box;\n box-shadow: 1px -1px 1px 0 rgba(0, 0, 0, 0.25);\n}\n\n.pushwoosh-subscribe-widget__popover-content-wrapper {\n overflow: auto;\n max-width: 100%;\n}\n\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover-content {\n display: flex;\n flex-direction: column;\n padding: 14px;\n box-sizing: border-box;\n float: left;\n min-width: 100%;\n align-items: center;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img {\n display: block;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img:first-child {\n margin-bottom: 14px;\n}\n\n@media (max-width: 767px) and (orientation: portrait) {\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover-content {\n flex-direction: column;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img {\n max-width: 280px;\n height: auto;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img:first-child {\n margin-right: 0;\n margin-bottom: 14px;\n }\n}\n@media (max-width: 767px) and (orientation: landscape) {\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover-content {\n flex-direction: row;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img {\n max-width: 280px;\n height: auto;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img:first-child {\n margin-right: 14px;\n margin-bottom: 0;\n }\n}\n',t},t.prototype.createBell=function(){var t,e,n,i=this.config;return i.buttonImage?(t=document.createElement("img")).src=i.buttonImage:(t=document.createElement("div"),this.addStylesToElement({backgroundColor:i.bgColor,boxShadow:i.shadow,lineHeight:i.size,border:i.bellButtonBorder},t),t.innerHTML=(e=i.bellColor,n=i.bellStrokeColor,'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:cc="http://creativecommons.org/ns#"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:svg="http://www.w3.org/2000/svg"\n xmlns="http://www.w3.org/2000/svg"\n xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n version="1.1"\n id="Capa_1"\n x="0px"\n y="0px"\n viewBox="0 0 346.013 346.013"\n style="enable-background:new 0 0 346.013 346.013;width: 80%; height: auto; vertical-align: middle;"\n xml:space="preserve"\n inkscape:version="0.91 r13725"\n sodipodi:docname="alarm_white.svg"><metadata\n id="metadata51"><rdf:RDF><cc:Work\n rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type\n rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs\n id="defs49" /><sodipodi:namedview\n borderopacity="1"\n objecttolerance="10"\n gridtolerance="10"\n guidetolerance="10"\n inkscape:pageopacity="0"\n inkscape:pageshadow="2"\n inkscape:window-width="1618"\n inkscape:window-height="828"\n id="namedview47"\n showgrid="false"\n inkscape:zoom="0.6820553"\n inkscape:cx="173.0065"\n inkscape:cy="173.0065"\n inkscape:window-x="0"\n inkscape:window-y="0"\n inkscape:window-maximized="0"\n inkscape:current-layer="g3" /><g\n id="g3"><path\n d="m 256.76227,220.19006 c -1.77513,-2.69766 -3.45154,-5.24564 -3.98966,-7.46382 -0.042,-0.17861 -0.0911,-0.36128 -0.16237,-0.61436 -2.28354,-7.67647 0.69147,-24.43921 2.46886,-34.45124 0.26788,-1.50394 0.52274,-2.94197 0.75286,-4.29035 0.0232,-0.13675 0.044,-0.27211 0.0724,-0.48006 1.95582,-15.28051 2.58811,-37.91956 -5.51044,-58.99147 -5.6032,-14.57978 -14.45978,-25.82612 -26.3559,-33.48393 1.26598,-9.812938 -4.85967,-19.343691 -14.66682,-22.0511 -9.80715,-2.70741 -19.95724,2.33226 -23.90298,11.405413 -14.1382,0.467533 -27.51111,5.577097 -39.80114,15.219267 -17.76129,13.9298 -28.83431,33.68757 -34.99389,47.80757 l -0.0479,0.11335 c -0.0512,0.12175 -0.0998,0.24114 -0.13249,0.32962 -0.49733,1.28292 -1.01552,2.64514 -1.55689,4.07255 -3.61311,9.51043 -9.66004,25.42824 -15.611995,30.89342 -0.106524,0.10027 -0.208228,0.20187 -0.362362,0.35435 -1.636243,1.66563 -4.382941,2.99463 -7.288979,4.40101 -7.145531,3.45301 -22.013613,10.64166 -17.206389,31.67844 0.929154,4.07105 4.008437,7.29057 8.033861,8.40185 l 167.570804,46.2604 c 4.02253,1.11048 8.31521,-0.0729 11.2052,-3.08958 14.91617,-15.58874 5.84693,-29.38668 1.48625,-36.02133 z"\n id="path5"\n inkscape:connector-curvature="0"\n vector-effect="non-scaling-stroke"\n'+' style="fill:'.concat(e,"; stroke: ").concat(n,'; stroke-width: 1; " /><path\n')+' vector-effect="non-scaling-stroke"\n d="m 174.26737,259.72378 -38.76399,-10.70137 c -1.59243,-0.43962 -3.28183,-0.15596 -4.63548,0.7754 -2.53909,1.7494 -2.84182,4.93159 -3.02304,6.83188 l -0.0151,0.15247 c -1.22819,12.67106 6.79854,24.33046 19.08688,27.72284 12.51583,3.45518 25.8324,-2.91586 30.9681,-14.80385 l 0.0935,-0.19205 c 0.52305,-1.06418 1.74613,-3.55554 0.50882,-6.31116 -0.44302,-0.98439 -1.5794,-2.74529 -4.21964,-3.47416 z"\n id="path7"\n inkscape:connector-curvature="0"\n'+' style="fill:'.concat(e,"; stroke: ").concat(n,'; stroke-width: 1;" /></g><g\n')+' id="g17" /><g\n id="g19" /><g\n id="g21" /><g\n id="g23" /><g\n id="g25" /><g\n id="g27" /><g\n id="g29" /><g\n id="g31" /><g\n id="g33" /><g\n id="g35" /><g\n id="g37" /><g\n id="g39" /><g\n id="g41" /><g\n id="g43" /><g\n id="g45" /></svg>')),this.addStylesToElement({width:i.size,height:i.size},t),t.className="pushwoosh-subscribe-widget__bell-button",t},t.prototype.createTooltip=function(){return o(this,void 0,void 0,(function(){var t,e,n,i,r,s;return a(this,(function(o){switch(o.label){case 0:return t=document.createElement("div"),e=jt.getTooltipPosition(this.config.position,this.config.size),n=e[0],i=e[1],t.className="pushwoosh-subscribe-widget__tooltip pushwoosh-subscribe-widget__tooltip__".concat(i),this.addStylesToElement(n,t),s=(r=t).appendChild,[4,this.createTooltipContent()];case 1:return s.apply(r,[o.sent()]),[2,t]}}))}))},t.prototype.createTooltipContent=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return t=document.createElement("div"),e=t,[4,this.tooltipTextFactory()];case 1:return e.innerText=n.sent(),t.className="pushwoosh-subscribe-widget__tooltip-content",[2,t]}}))}))},t.prototype.tooltipTextFactory=function(){return o(this,void 0,void 0,(function(){var t,e,n;return a(this,(function(i){switch(i.label){case 0:return[4,this.pw.driver.getPermission()];case 1:return t=i.sent(),e=this.config.tooltipText,[4,pt.get("MANUAL_UNSUBSCRIBE")];case 2:switch(n=i.sent(),t){case w:return[2,n?e.needSubscribe:e.alreadySubscribed];case y:return[2,e.needSubscribe];case m:return[2,e.blockSubscribe];default:return[2,e.needSubscribe]}return[2]}}))}))},t.prototype.createPopover=function(){var t=document.createElement("div"),e=document.createElement("div"),n=jt.getPopoverPosition(this.config.position,this.config.size),i=n[0],r=n[1];e.className="pushwoosh-subscribe-widget__popover pushwoosh-subscribe-widget__popover__".concat(r),t.className="pushwoosh-subscribe-widget__popover-content-wrapper",this.style.innerHTML+=jt.getPopoverArrowPosition(this.config.position,this.config.size);var s=Object.assign({maxWidth:"calc(100vw - ".concat(this.config.indent," - ").concat(this.config.indent,")")},i);return this.addStylesToElement(s,e),t.appendChild(this.createPopoverContent()),e.appendChild(t),e},t.prototype.getBrowserName=function(){return Pt.isOpera?"opera":11===Pt.platform&&navigator.userAgent.match(/Android/i)?"mobileChrome":12===Pt.platform?"firefox":10===Pt.platform?"safari":150===Pt.platform?"edge":"chrome"},t.prototype.createPopoverContent=function(){var t=this.config,e=document.createElement("div");e.className="pushwoosh-subscribe-widget__popover-content";var n=this.getBrowserName(),i=t.contentImages&&t.contentImages[n];if(i){var r=document.createElement("img");r.src=i,e.appendChild(r)}else{var s={opera:"opera",mobileChrome:"mobile_chrome",firefox:"FF",safari:"safari"}[n]||"chrome";[{src:this.getImageSrc(s),width:500,height:130},{src:this.getImageSrc("".concat(s,"_unlock")),width:500,height:230}].forEach((function(t){var n=document.createElement("img");Object.assign(n,t),e.appendChild(n)}))}return e},t.prototype.getImageSrc=function(t){return"https://cdn.pushwoosh.com/webpush/img/".concat(t,".jpg")},t.prototype.render=function(){return o(this,void 0,void 0,(function(){var t,e,n;return a(this,(function(i){switch(i.label){case 0:return this.widget=this.createContainer(),this.style=this.createStyle(),t=this.createBell(),e=this,[4,this.createTooltip()];case 1:return e.tooltip=i.sent(),n=this,[4,this.createPopover()];case 2:return n.popover=i.sent(),this.widget.appendChild(this.style),this.widget.appendChild(t),this.widget.appendChild(this.tooltip),this.widget.appendChild(this.popover),document.body.appendChild(this.widget),this.pw.push(["onSubscribe",this.onSubscribeEvent]),this.pw.push(["onUnsubscribe",this.onUnsubscribeEvent]),this.pw.push(["onPermissionDenied",this.onPermissionDeniedEvent]),this.addEventListeners(),[2]}}))}))},t.prototype.addEventListeners=function(){this.widget.addEventListener("click",this.clickBell),window.addEventListener("click",this.clickOutOfPopover)},t.prototype.toggleHelpPopover=function(){this.popover.classList.toggle("pushwoosh-subscribe-widget__popover__visible")},t.prototype.clickBell=function(){return o(this,void 0,void 0,(function(){var t;return a(this,(function(e){switch(e.label){case 0:switch(t=this.pw.driver.getPermission(),t){case w:return[3,1];case y:return[3,3];case m:return[3,5]}return[3,6];case 1:return[4,this.pw.subscribe()];case 2:return e.sent(),[3,7];case 3:return[4,this.pw.subscribe()];case 4:return e.sent(),[3,7];case 5:return this.toggleHelpPopover(),[3,7];case 6:console.warn("Unknown browser notification permission"),e.label=7;case 7:return[2]}}))}))},t.prototype.onSubscribeEvent=function(){return o(this,void 0,void 0,(function(){var t,e=this;return a(this,(function(n){return null===(t=this.tooltip.querySelector("div"))||(t.innerText=this.config.tooltipText.successSubscribe,this.tooltip.classList.add("pushwoosh-subscribe-widget__tooltip__visible"),setTimeout((function(){return o(e,void 0,void 0,(function(){var e;return a(this,(function(n){switch(n.label){case 0:return this.tooltip.classList.remove("pushwoosh-subscribe-widget__tooltip__visible"),e=t,[4,this.tooltipTextFactory()];case 1:return e.innerText=n.sent(),this.widget.classList.add("pushwoosh-subscribe-widget__subscribed"),[2]}}))}))}),2e3)),[2]}))}))},t.prototype.onPermissionDeniedEvent=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return this.addEventListeners(),null===(t=this.tooltip.querySelector("div"))?[2]:(e=t,[4,this.tooltipTextFactory()]);case 1:return e.innerText=n.sent(),[2]}}))}))},t.prototype.clickOutOfPopover=function(t){this.popover.classList.contains("pushwoosh-subscribe-widget__popover__visible")&&!t.target.classList.contains("pushwoosh-subscribe-widget__popover")&&null===t.target.closest(".pushwoosh-subscribe-widget__popover")&&!t.target.classList.contains("pushwoosh-subscribe-widget__bell-button")&&null===t.target.closest(".pushwoosh-subscribe-widget__bell-button")&&this.popover.classList.remove("pushwoosh-subscribe-widget__popover__visible")},t.prototype.onUnsubscribeEvent=function(){return o(this,void 0,void 0,(function(){var t,e;return a(this,(function(n){switch(n.label){case 0:return null===(t=this.tooltip.querySelector("div"))?[2]:(e=t,[4,this.tooltipTextFactory()]);case 1:return e.innerText=n.sent(),[2]}}))}))},t}(),Kt={text:"Don’t miss out on our news and updates! Enable push notifications",askLaterButtonText:"Not now",confirmSubscriptionButtonText:"Subscribe",delay:5,retryOffset:604800,overlay:!1,position:"top",mobileViewMargin:"0",bgColor:"#fff",borderColor:"transparent",boxShadow:"0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)",textColor:"#000",textSize:"inherit",textWeight:"normal",fontFamily:"inherit",subscribeBtnBgColor:"#4285f4",subscribeBtnTextColor:"#fff",subscribeBtnTextWeight:"normal",subscribeBtnBorderColor:"transparent",subscribeBtnBorderRadius:"2px",askLaterBtnBgColor:"transparent",askLaterBtnTextColor:"#000",askLaterBtnTextWeight:"normal",askLaterBtnBorderColor:"transparent",askLaterBtnBorderRadius:"2px",theme:"material",viewport:"html"},Gt=/^(#([\da-f]{3}){1,2}$|(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0?\.\d+)\)$|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/,Xt=[{name:"mobileViewMargin",type:"string"},{name:"mobileViewPosition",type:"string"},{name:"mobileViewTransition",type:"string"},{name:"bgColor",type:"color"},{name:"borderColor",type:"color"},{name:"boxShadow",type:"string"},{name:"textColor",type:"color"},{name:"textSize",type:"string"},{name:"textWeight",type:"string"},{name:"fontFamily",type:"string"},{name:"subscribeBtnBgColor",type:"color"},{name:"subscribeBtnTextColor",type:"color"},{name:"subscribeBtnTextWeight",type:"string"},{name:"subscribeBtnBorderColor",type:"color"},{name:"subscribeBtnBorderRadius",type:"string"},{name:"askLaterBtnBgColor",type:"color"},{name:"askLaterBtnTextColor",type:"color"},{name:"askLaterBtnTextWeight",type:"string"},{name:"askLaterBtnBorderColor",type:"color"},{name:"askLaterBtnBorderRadius",type:"string"}];const Jt=function(){function t(t){this.pw=t;var e=(t.subscribePopupConfig||{}).mobileViewMargin,n=void 0===e?"":e;this.config=r(r(r({},Kt),this.pw.subscribePopupConfig),{mobileViewTransition:n?"none":"bottom .4s ease-out",mobileViewPosition:n?"auto!important":"auto"}),this.onAskLaterClick=this.onAskLaterClick.bind(this),this.onSubscribeClick=this.onSubscribeClick.bind(this)}return t.prototype.initPopup=function(){return o(this,void 0,void 0,(function(){var t,e,n,i,r,s,o=this;return a(this,(function(a){switch(a.label){case 0:return[4,this.pw.isSubscribed()];case 1:return t=a.sent(),[4,this.pw.data.getStatusManualUnsubscribed()];case 2:return e=a.sent(),t||e?[2]:[4,this.pw.driver.getPermission()];case 3:return"granted"===(n=a.sent())||"denied"===n||(this.renderPopup(),this.appendStyles(),i=localStorage.getItem("LAST_OPEN_SUBSCRIPTION_POPUP"),r=i?parseInt(i):0,s=(new Date).getTime(),r+1e3*this.config.retryOffset<s&&!this.config.manualToggle&&setTimeout((function(){o.toggle(!0)}),1e3*this.config.delay)),[2]}}))}))},t.prototype.toggle=function(t){("boolean"==typeof t?t:!this.isShown)?(this.showPopup(),this.pw.eventBus.dispatchEvent("subscribe-popup-show",{})):(this.closePopup(),this.pw.eventBus.dispatchEvent("subscribe-popup-hide",{}))},t.prototype.showPopup=function(){this.isShown=!0,this.popup.classList.add("pw-show"),document.body.classList.add("pw-popup-opened");var t=new CustomEvent("showPopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});if(this.popup.dispatchEvent(t),!(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)){var e=this.config,n=e.theme,i=e.viewport,r=e.position;if("topbar"===n&&"top"===r){var s=document.querySelector(i)||document.createElement("div"),o=window.getComputedStyle(s).marginTop||"0";s.style.transition="margin-top .3s ease-out",s.style.marginTop="".concat(parseInt(o)+this.popup.getBoundingClientRect().height,"px")}}},t.prototype.closePopup=function(){this.isShown=!1,this.popup.classList.remove("pw-show"),document.body.classList.remove("pw-popup-opened");var t=new CustomEvent("hidePopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);var e=(new Date).getTime().toString();if(localStorage.setItem("LAST_OPEN_SUBSCRIPTION_POPUP",e),!(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)){var n=this.config,i=n.theme,r=n.viewport,s=n.position;if("topbar"===i&&"top"===s){var o=document.querySelector(r)||document.createElement("div"),a=window.getComputedStyle(o).marginTop||"0";o.style.marginTop="".concat(parseInt(a)-this.popup.getBoundingClientRect().height,"px")}}},t.prototype.renderPopup=function(){this.popup=document.createElement("div"),this.popup.id="pwSubscribePopup";var t=this.config,e=t.text,n=t.askLaterButtonText,i=t.confirmSubscriptionButtonText,r=t.iconUrl,s=t.iconAlt,o=t.position,a=t.overlay,c=t.theme;this.popup.className="pw-subscribe-popup pw-position-".concat(o," pw-subscribe-popup-").concat(c),this.popup.classList.toggle("pw-subscribe-popup__overlay",a),this.popup.innerHTML=function(t){var e=t.iconUrl,n=t.iconAlt,i=t.text,r=t.askLaterButtonText,s=t.confirmSubscriptionButtonText;return'<div class="pw-subscription-popup-inner">\n <div class="pw-subscription-popup-content">\n '.concat(e?'<div class="pw-subscription-popup-icon"><img src="'.concat(e,'" alt="').concat(n||"Subscribe",'"></div>'):"",'\n <div class="pw-subscription-popup-text">\n ').concat(i,'\n </div>\n </div>\n <div class="pw-subscription-popup-controls">\n <button name="pwAskLater" class="pw-subscribe-popup-button">').concat(r,'</button>\n <button name="pwSubscribe" class="pw-subscribe-popup-button pw-subscribe-popup-button-active">').concat(s,"</button>\n </div>\n </div>")}({text:e,askLaterButtonText:n,confirmSubscriptionButtonText:i,iconUrl:r,iconAlt:s}),document.body.appendChild(this.popup),this.addListeners()},t.prototype.appendStyles=function(){var t=document.createElement("style");t.innerHTML=this.configureStyle(".pw-subscribe-popup {\n position: fixed;\n left: 50%;\n transform: translateX(-50%);\n justify-content: center;\n z-index: 1000000;\n display: flex;\n transition: all .4s ease-out;\n}\n\n.pw-subscribe-popup.pw-position-top {\n top: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-top.pw-show {\n top: 0;\n}\n\n.pw-subscribe-popup.pw-position-bottom {\n bottom: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-bottom.pw-show {\n bottom: 0;\n}\n\n.pw-subscribe-popup.pw-position-center {\n display: flex;\n\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n justify-content: center;\n align-items: center;\n\n transform: none;\n}\n\n.pw-subscribe-popup__overlay {\n background: rgba(0,0,0,.4);\n z-index: 1000000;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-subscribe-popup__overlay) {\n pointer-events: none;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-show) {\n display: none;\n}\n\n\n.pw-subscribe-popup__overlay.pw-position-top {\n align-items: flex-start;\n}\n\n.pw-subscribe-popup__overlay.pw-position-bottom {\n align-items: flex-end;\n}\n\n.pw-subscribe-popup__overlay.pw-position-center {\n align-items: center;\n}\n\n.pw-subscription-popup-inner {\n max-width: 400px;\n font-size: var(--textSize);\n color: var(--textColor);\n font-weight: var(--textWeight);\n font-family: var(--fontFamily);\n border-style: solid;\n border-width: 1px;\n border-color: var(--borderColor);\n background: var(--bgColor);\n box-shadow: var(--boxShadow);\n pointer-events: auto;\n}\n\n.pw-subscription-popup-content {\n padding: 16px 16px 4px;\n display: flex;\n justify-content: stretch;\n}\n\n.pw-subscription-popup-icon {\n flex: 0 0 50px;\n margin-right: 12px;\n padding-top: 4px;\n}\n\n.pw-subscription-popup-icon img {\n max-width: 60px;\n max-height: 60px;\n}\n\n.pw-subscription-popup-text {\n flex: 1 1 300px;\n}\n\n.pw-subscription-popup-controls {\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n padding: 8px 16px 16px;\n}\n\nbutton.pw-subscribe-popup-button {\n border: solid 1px var(--askLaterBtnBorderColor);\n border-radius: var(--askLaterBtnBorderRadius);\n display: inline-block;\n height: 36px;\n line-height: 36px;\n padding: 0 16px;\n text-transform: uppercase;\n font-weight: var(--askLaterBtnTextWeight);\n vertical-align: middle;\n -webkit-tap-highlight-color: transparent;\n font-size: 14px;\n outline: 0;\n text-decoration: none;\n color: var(--askLaterBtnTextColor);\n text-align: center;\n letter-spacing: .5px;\n cursor: pointer;\n background: var(--askLaterBtnBgColor);\n margin: 4px 8px;\n}\nbutton.pw-subscribe-popup-button:hover {\n background: rgba(0,0,0,.04);\n}\nbutton.pw-subscribe-popup-button:active {\n background: rgba(0,0,0,.12);\n}\n\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active {\n color: var(--subscribeBtnTextColor);\n background: var(--subscribeBtnBgColor);\n border-radius: var(--subscribeBtnBorderRadius);\n border: solid 1px var(--subscribeBtnBorderColor);\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n font-weight: var(--subscribeBtnTextWeight);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:hover {\n box-shadow: 0 3px 3px 0 rgba(0,0,0,0.14),\n 0 1px 7px 0 rgba(0,0,0,0.12),\n 0 3px 1px -1px rgba(0,0,0,0.2);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:active {\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n}\n\n@media screen and (min-width: 541px) {\n\n .pw-subscribe-popup-topbar {\n width: 100%;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n display: flex;\n flex-direction: row;\n padding: 2px 40px;\n justify-content: center;\n align-items: center;\n flex-wrap: nowrap;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-content {\n padding: 0;\n justify-content: flex-start;\n align-items: center;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-icon img {\n max-width: 28px;\n max-height: 28px;\n }\n\n .pw-subscribe-popup-topbar button.pw-subscribe-popup-button {\n height: 32px;\n line-height: 32px;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-controls {\n padding: 0 0 0 16px;\n align-items: center;\n }\n}\n@media screen and (max-width: 540px) {\n .pw-subscribe-popup,\n .pw-subscribe-popup.pw-position-top,\n .pw-subscribe-popup.pw-position-center,\n .pw-subscribe-popup.pw-position-bottom {\n top: var(--mobileViewPosition);\n bottom: -110%;\n left: 0;\n right: 0;\n transform: none;\n display: flex;\n transition: var(--mobileViewTransition);\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-subscribe-popup__overlay {\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-show {\n bottom: var(--mobileViewMargin);\n }\n\n .pw-subscribe-popup__overlay .pw-subscription-popup-inner {\n align-items: flex-end;\n justify-content: stretch;\n }\n\n .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n }\n}\n"),document.body.appendChild(t)},t.prototype.getStyleFormatter=function(t){switch(t.type){case"size":return"".concat(this.config[t.name]||0,"px");case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return"transparent"===(e=this.config[t.name].toString())||Gt.test(e)?e:"#333";default:return"none"}var e},t.prototype.configureStyle=function(t){var e=this,n=t.toString();return Xt.forEach((function(t){var i=new RegExp("var\\(--".concat(t.name,"\\)"),"ig"),r=e.getStyleFormatter(t);n=n.replace(i,r)})),n},t.prototype.addListeners=function(){var t=this.popup.querySelector('button[name="pwAskLater"]')||document.createElement("button"),e=this.popup.querySelector('button[name="pwSubscribe"]')||document.createElement("button");t.addEventListener("click",this.onAskLaterClick),e.addEventListener("click",this.onSubscribeClick)},t.prototype.onAskLaterClick=function(){this.toggle(!1),this.pw.eventBus.dispatchEvent("subscribe-popup-decline",{})},t.prototype.onSubscribeClick=function(){this.toggle(!1),this.pw.eventBus.dispatchEvent("subscribe-popup-accept",{}),this.pw.subscribe()},t}();return document.addEventListener("pushwoosh.initialized",(function(t){if(t.detail.pw.subscribeWidgetConfig.enable&&new Yt(t.detail.pw),t.detail.pw.subscribePopupConfig&&t.detail.pw.subscribePopupConfig.enable){var e=new Jt(t.detail.pw);e.initPopup().then((function(){t.detail.pw.subscribePopup=e}))}t.detail.pw.pwinbox&&t.detail.pw.inboxWidgetConfig.enable&&(t.detail.pw.pwinboxWidget=new Ut(t.detail.pw))})),e})()));
|
|
1
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Pushwoosh:()=>ft});const i={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let s;const n=new Uint8Array(16);const a=[];for(let t=0;t<256;++t)a.push((t+256).toString(16).slice(1));function o(t,e=0){return(a[t[e+0]]+a[t[e+1]]+a[t[e+2]]+a[t[e+3]]+"-"+a[t[e+4]]+a[t[e+5]]+"-"+a[t[e+6]]+a[t[e+7]]+"-"+a[t[e+8]]+a[t[e+9]]+"-"+a[t[e+10]]+a[t[e+11]]+a[t[e+12]]+a[t[e+13]]+a[t[e+14]]+a[t[e+15]]).toLowerCase()}const r=function(t,e,a){if(i.randomUUID&&!e&&!t)return i.randomUUID();const r=(t=t||{}).random??t.rng?.()??function(){if(!s){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");s=crypto.getRandomValues.bind(crypto)}return s(n)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,e){if((a=a||0)<0||a+16>e.length)throw new RangeError(`UUID byte range ${a}:${a+15} is out of buffer bounds`);for(let t=0;t<16;++t)e[a+t]=r[t];return e}return o(r)},c="deviceRegistrationStatus",p="registered",d="unregistered",h="denied",l="granted",u="default",g="onLoad",b="onReady",w="onSubscribe",m="onUnsubscribe",f="onRegister",v="onPermissionPrompt",x="onPermissionDenied",y="onPermissionGranted",_="onSWInitError",C="onPushDelivery",S="onNotificationClick",k="onNotificationClose",E="onChangeCommunicationEnabled",T="onPutNewMessageToInboxStore",P="onUpdateInboxMessages",I="onShowNotificationPermissionDialog",M="onHideNotificationPermissionDialog",B="onShowSubscriptionWidget",D="onHideSubscriptionWidget",W="PW_SiteOpened",R={headerText:"Subscribe to our news",headerTextColor:"#000000",subheaderText:"Don't miss out on the latest news and updates!",subheaderTextColor:"#000000",buttonAcceptText:"Agree",buttonAcceptTextColor:"#1A72E8",buttonAcceptRound:"4px",buttonAcceptBackgroundColor:"#FFFFFF",buttonAcceptBorderColor:"#E3E4E8",buttonCancelText:"Deny",buttonCancelTextColor:"#1A72E8",buttonCancelRound:"4px",buttonCancelBackgroundColor:"#FFFFFF",buttonCancelBorderColor:"#E3E4E8",cappingCount:3,cappingDelay:144e5,backgroundColor:"#FFFFFF"};class A{constructor(){this.addEventHandler=(t,e)=>{let i=this.savedEventHandlersMap[t];i||(i=[]),i.push(e),this.savedEventHandlersMap[t]=i},this.removeEventHandler=(t,e)=>{const i=this.savedEventHandlersMap[t];i&&(this.savedEventHandlersMap[t]=i.filter((t=>t!==e)))},this.dispatchEvent=(t,e)=>{const i=e.eventId||r(),s=this.savedEventHandlersMap[t];return s?(s.forEach((t=>{"function"==typeof t&&setTimeout((()=>{t({...e,eventId:i})}),0)})),i):i},this.savedEventHandlersMap={}}}const L="pushwoosh-subscription-widget";class O{constructor(t,e){this.eventBus=t,this.pw=e}init(t){if(!this.getRootElement()){const e=(t=>`\n <div id="${L}-root" class="${L}">\n <div class="${L}__body">\n <div class="${L}__header">\n ${t.headerText}\n </div>\n <div class="${L}__description">\n ${t.subheaderText}\n </div>\n <div class="${L}__controls">\n <button type="button" id="${L}-decline" class="${L}__control ${L}__control_decline">\n ${t.buttonCancelText}\n </button>\n <button type="button" id="${L}-accept" class="${L}__control ${L}__control_accept">\n ${t.buttonAcceptText}\n </button>\n </div>\n </div>\n </div>\n `)(t),i=(t=>{const e=document.createElement("style");return e.innerHTML=`\n .${L} * {\n box-sizing: border-box!important;\n }\n \n .${L} {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n margin: 0 auto;\n width: 320px;\n display: none;\n z-index: 2147483648;\n opacity: 0.99;\n }\n \n .${L}_show {\n display: block;\n }\n \n .${L}__body {\n width: 320px;\n background-color: ${t.backgroundColor?t.backgroundColor:"#FFFFFF"};\n box-shadow: 0 9px 15px rgba(0, 0, 0, 0.1), 0 0 6px rgba(0, 0, 0, 0.06);\n border-radius: 4px;\n padding: 20px 20px 12px;\n }\n \n .${L}__header {\n color: ${t.headerTextColor};\n font-size: 18px;\n font-weight: bold; \n }\n \n .${L}__description {\n color: ${t.subheaderTextColor};\n font-size: 14px;\n line-height: 1.5;\n margin-top: 14px;\n }\n \n .${L}__description:empty {\n display: none;\n }\n \n .${L}__controls {\n display: flex;\n flex-wrap: nowrap;\n justify-content: flex-end;\n margin: 20px 0 0;\n }\n \n .${L}__control {\n -webkit-appearance: none;\n border: 1px solid transparent;\n font-size: 12px;\n font-weight: bold;\n padding: 0 20px;\n height: 32px;\n cursor: pointer;\n }\n \n .${L}__control_decline {\n color: ${t.buttonCancelTextColor};\n background-color: ${t.buttonCancelBackgroundColor};\n border-radius: ${t.buttonCancelRound};\n border-color: ${t.buttonCancelBorderColor};\n }\n \n .${L}__control_accept {\n color: ${t.buttonAcceptTextColor};\n background-color: ${t.buttonAcceptBackgroundColor};\n border-radius: ${t.buttonAcceptRound};\n border-color: ${t.buttonAcceptBorderColor};\n margin: 0 0 0 12px;\n }\n `,e})(t);document.body.insertAdjacentHTML("beforeend",e),document.head.appendChild(i)}this.addEventListeners()}show(){const t=this.getRootElementWithCheckExist();this.eventBus.dispatchEvent("show-subscription-widget",{}),t.classList.add(`${L}_show`)}hide(){const t=this.getRootElementWithCheckExist();t.classList.contains(`${L}_show`)&&(this.eventBus.dispatchEvent("hide-subscription-widget",{}),t.classList.remove(`${L}_show`))}getRootElement(){return document.getElementById(`${L}-root`)}getRootElementWithCheckExist(){const t=this.getRootElement();if(!t)throw new Error(`Can't find element by id "${L}-root", please use method init first.`);return t}getDeclineButtonWithCheckExist(){const t=document.getElementById(`${L}-decline`);if(!t)throw new Error(`Can't find element by id "${L}-decline", please use method init first.`);return t}getAcceptButtonWithCheckExist(){const t=document.getElementById(`${L}-accept`);if(!t)throw new Error(`Can't find element by id "${L}-accept", please use method init first.`);return t}addEventListeners(){const t=this.getRootElementWithCheckExist(),e=this.getDeclineButtonWithCheckExist(),i=this.getAcceptButtonWithCheckExist();document.addEventListener("click",(e=>{t.contains(e.target)||this.hide()})),e.addEventListener("click",(()=>{this.hide()})),i.addEventListener("click",(()=>{this.hide(),this.pw.subscribe()}))}}function $(){return globalThis}function N(){"history"in $()&&history.pushState?history.pushState(null,"","#"):location.hash="#"}const U="keyValue",H="messages",q="log",F="inboxMessages";function z(t,e){return function(i){i.objectStoreNames.contains(t)||e(i)}}const V=[z(F,(function(t){const e="status",i=t.createObjectStore(F,{keyPath:"inbox_id",autoIncrement:!1});i.createIndex(e,e,{unique:!1,multiEntry:!0}),i.createIndex("rt","rt",{unique:!1,multiEntry:!0})}))];const j=[z(U,(function(t){t.createObjectStore(U,{keyPath:"key"})})),z(q,(function(t){const e=t.createObjectStore(q,{keyPath:"id",autoIncrement:!0});e.createIndex("environment","environment",{unique:!1}),e.createIndex("date","date",{unique:!1}),e.createIndex("type","type",{unique:!1})})),z(H,(function(t){t.createObjectStore(H,{keyPath:"id",autoIncrement:!0}).createIndex("date","date",{unique:!1})}))];class Y{constructor(t=new Date){this._date=t}set date(t){this._date=t}get date(){return this._date}getUtcTimestamp(){return Math.floor((this.date.getTime()+60*this.date.getTimezoneOffset()*1e3)/1e3)}getTimestamp(){return Math.round(this.date.getTime()/1e3)}setLocal(){const t=this._date.getTime()-60*this.date.getTimezoneOffset()*1e3;this._date=new Date(t)}addDays(t){const e=this._date.getTime()+24*t*60*60*1e3;this._date=new Date(e)}getInboxFakeOrder(){return(100*this._date.getTime()+9e9).toString()}}class K{constructor(t=new Y){this.migrations={initial:j,"2018/11/26":V},this.dateModule=t}get initial(){return this.migrations.initial}get dateSorted(){return Object.keys(this.migrations).filter((t=>"initial"!==t)).sort(((t,e)=>{const i=new Y(new Date(t)),s=new Y(new Date(e));return i.getTimestamp()-s.getTimestamp()})).map((t=>this.migrations[t]))}}class G{constructor(t,e=new K){this.db=t,this.migrationsBuilder=e}applyMigrations(){this.applyMigrationsPack(this.migrationsBuilder.initial),this.migrationsBuilder.dateSorted.forEach((t=>{this.applyMigrationsPack(t)}))}applyMigrationsPack(t){t.forEach((t=>{t(this.db)}))}}function X(t,e){console.info("onversionchange",e),t.close()}let J;function Q(t){return(J||(J=new Promise(((t,e)=>{const i=indexedDB.open("PUSHWOOSH_SDK_STORE",7);i.onsuccess=i=>{const s=i.target.result;s.onversionchange=X.bind(null,s,e),t(s)},i.onerror=()=>e(i.error),i.onupgradeneeded=t=>{const i=t.target.result;i.onversionchange=X.bind(null,i,e),new G(i).applyMigrations()}}))),J).then((e=>new Promise(((i,s)=>t(e,i,s)))))}class Z{_add(t){return Q(((e,i,s)=>{const n=e.transaction([this.name],"readwrite").objectStore(this.name).add(t);n.onsuccess=()=>{i(t)},n.onerror=()=>{s(n.error)}})).then((t=>this.getAll().then((e=>{if(Array.isArray(e)){const i=e.map((t=>t.id)).sort(((t,e)=>t==e?0:t<e?1:-1));if(i.length>this.maxItems)return Promise.all(i.slice(this.maxItems).map((t=>this.delete(t)))).then((()=>t))}return t}))))}delete(t){return Q(((e,i,s)=>{const n=e.transaction([this.name],"readwrite").objectStore(this.name).delete(t);n.onsuccess=()=>{i(n.result)},n.onerror=()=>{s(n.error)}}))}getAll(){return Q(((t,e,i)=>{const s=[],n=t.transaction(this.name).objectStore(this.name).openCursor();n.onsuccess=t=>{const i=t.target.result;i?(i.value&&s.push(i.value),i.continue()):e(s)},n.onerror=()=>{i(n.error)}}))}}const tt=(et=U,{get:(t,e)=>Q(((i,s,n)=>{const a=i.transaction(et).objectStore(et).get(t);let o,r=!1,c=!1;const p=()=>{clearTimeout(o),r?s(a.result?.value||e):c?n(a.error):o=setTimeout(p,0)};a.onsuccess=()=>r=!0,a.onerror=()=>c=!0,p()})),getAll:()=>Q(((t,e,i)=>{const s={},n=t.transaction(et).objectStore(et).openCursor();let a,o=!1,r=!1;const c=()=>{clearTimeout(a),o?e(s):r?i(n.error):a=setTimeout(c,0)};n.onsuccess=t=>{const e=t.target.result;e?(s[e.key]=e.value.value,e.continue()):o=!0},n.onerror=()=>r=!0,c()})),async extend(t,e){const i=await this.get(t),{...s}=e;await this.set(t,{...i,...s})},set:(t,e)=>Q(((i,s,n)=>{const a=i.transaction([et],"readwrite").objectStore(et).put({key:t,value:e});let o,r=!1,c=!1;const p=()=>{clearTimeout(o),r?s(t):c?n(a.error):o=setTimeout(p,0)};a.onsuccess=()=>r=!0,a.onerror=()=>c=!0,p()}))});var et;const it=new class extends Z{constructor(){super(...arguments),this.name=q,this.maxItems=100,this.environment="undefined"!=typeof self&&self.registration?"worker":"browser"}add(t,e,i){const s={type:t,environment:this.environment,message:`${e}`,date:new Date};return e instanceof Error&&(s.stack=e.stack),i&&(s.additional=i),this._add(s)}},st=new class extends Z{constructor(){super(...arguments),this.name=H,this.maxItems=25}add(t){return this._add({...t,date:new Date})}},nt={error:1,info:2,debug:3};let at=3;!function(){const t=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],e=$(),i=e.console=e.console||{};for(const e of t)i[e]||(i[e]=()=>{})}();const ot={setLevel(t){nt[t]||(t="error"),at=nt[t]},write(t,e,i){return"error"===t?this.error(e):this.info(e),it.add(t,e,i)}};Object.keys(nt).forEach((t=>{const e=nt[t];ot[t]=(...i)=>{e<=at&&(console.groupCollapsed(t),console.info("",...i),console.trace("trace"),console.groupEnd())}}));class rt{constructor(t,e,i,s=new Y){this.data=t,this.api=e,this.inboxModel=i,this.dateModule=s,this.publicMessageBuilder=this.publicMessageBuilder.bind(this)}messageTypeFactory(t,e){let i=0;return 2===t?i=1:"l"in e&&null!=e.l&&(i=e.l.startsWith("http")?2:3),i}async updateMessagesStatusWithCodes(t,e,i){const s=[],n=[];e.forEach((async e=>{-1!==t.indexOf(e.inbox_id)&&(e.status=i,s.push(e),n.push(this.api.inboxStatus(e.order,e.status)))})),await this.inboxModel.putBulkMessages(s),await Promise.all(n)}async publicMessageBuilder({action_type:t,action_params:e,image:i,title:s,send_date:n,inbox_id:a,text:o,status:r}){const c=i||await this.data.getDefaultNotificationImage(),p=s||await this.data.getDefaultNotificationTitle(),d=JSON.parse(e);return this.dateModule.date=new Date(1e3*parseInt(n)),this.dateModule.setLocal(),{title:p,imageUrl:c,code:a,message:o,sendDate:this.dateModule.date.toISOString(),type:this.messageTypeFactory(t,d),link:d?.l||"/",isRead:2===r||3===r,isActionPerformed:3===r}}messagesWithNoActionPerformedCount(){return this.inboxModel.getDeliveredReadMessagesCount()}unreadMessagesCount(){return this.inboxModel.getDeliveredMessagesCount()}messagesCount(){return this.inboxModel.messagesCount()}async loadMessages(){const t=[...await this.inboxModel.getReadOpenMessages(),...await this.inboxModel.getDeliveredMessages()].sort(((t,e)=>parseInt(e.send_date,10)-parseInt(t.send_date,10))).sort(((t,e)=>parseInt(e.order||"0",10)-parseInt(t.order||"0",10))).map(this.publicMessageBuilder);return Promise.all(t)}async readMessagesWithCodes(t){const e=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(t,e,2)}async performActionForMessageWithCode(t){const e=await this.inboxModel.getMessage(t),i=JSON.parse(e.action_params),s=this.messageTypeFactory(e.action_type,i);2===s&&null!=i.l?document.location.href=i.l:3===s&&null!=i.l&&window.history.go(i.l),e.status=3,await this.inboxModel.putMessage(e),await this.api.inboxStatus(e.order,e.status)}async deleteMessagesWithCodes(t){const e=await this.inboxModel.getReadOpenMessages(),i=await this.inboxModel.getDeliveredMessages();await this.updateMessagesStatusWithCodes(t,[...e,...i],4)}async syncMessages(){await this.inboxModel.updateMessages()}}class ct{constructor(t,e){this.name=e,this.store=t.transaction(this.name,"readwrite").objectStore(this.name)}set index(t){this.store.indexNames.contains(t)?this._index=this.store.index(t):console.warn(`Index "${t}" in `)}writeRequestPromise(t,e){return new Promise(((i,s)=>{t.onsuccess=()=>{i(e)},t.onerror=()=>{s(t.error)}}))}readRequestPromise(t,e){return new Promise(((i,s)=>{t.onsuccess=t=>{const s=t.target;i(s.result||e)},t.onerror=()=>{s(t.error)}}))}put(t,e){const i=this.store.put(t,e);return this.writeRequestPromise(i,e)}add(t,e){return this.put(t,e)}delete(t){const e=this.store.delete(t);return this.writeRequestPromise(e)}get(t,e){const i=this.store.get(t);return this.readRequestPromise(i,e)}getAll(){const t=this.store.openCursor(),e=[];return new Promise(((i,s)=>{t.onsuccess=t=>{const s=t.target.result;s?(e.push(s.value),s.continue()):i(e)},t.onerror=()=>{s(t.error)}}))}count(t){const e=this.store.count(t);return this.readRequestPromise(e,0)}countByIndex(t){const e=this._index.count(t);return this.readRequestPromise(e,0)}}class pt{dbVersionChangeHandler(t,e){console.info("onversionchange",e),t.close()}dbRequestSuccessHandler(t,e){const i=e.target.result;i.onversionchange=t=>{this.dbVersionChangeHandler(i,t)},t(i)}dbRequestUpgradeNeededHandler(t){const e=t.target.result;e.onversionchange=t=>{this.dbVersionChangeHandler(e,t)};new G(e).applyMigrations()}getDB(){return new Promise(((t,e)=>{const i=indexedDB.open("PUSHWOOSH_SDK_STORE",7);i.onsuccess=e=>{this.dbRequestSuccessHandler(t,e)},i.onupgradeneeded=t=>{this.dbRequestUpgradeNeededHandler(t)},i.onerror=()=>e(i.error)}))}async put(t,e,i){const s=await this.getDB(),n=new ct(s,t),a=await n.put(e,i);return s.close(),a}async delete(t,e){const i=await this.getDB(),s=new ct(i,t),n=await s.delete(e);return i.close(),n}async get(t,e,i){const s=await this.getDB(),n=new ct(s,t),a=await n.get(e,i);return s.close(),a}async getAll(t){const e=await this.getDB(),i=new ct(e,t),s=await i.getAll();return e.close(),s||[]}async count(t,e){const i=await this.getDB(),s=new ct(i,t),n=await s.count(e);return i.close(),n}async countByIndex(t,e,i){const s=await this.getDB(),n=new ct(s,t);n.index=e;const a=await n.countByIndex(i);return s.close(),a}}class dt{constructor(t,e,i,s=new pt,n=new Y){this.eventBus=t,this.data=e,this.api=i,this.storage=s,this.storeName="inboxMessages",this.dateModule=n}async getInboxMessages(){const t=await this.api.getInboxMessages();return await this.storeGetInboxMessagesRequestParams(t.next,t.new_inbox),t}async storeGetInboxMessagesRequestParams(t,e){this.dateModule.date=new Date,await this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp()),await this.data.setInboxLastRequestCode(t),await this.data.setInboxNewMessagesCount(e)}async putServerMessages(t){const e=t.map((async t=>{const e=await this.storage.get(this.storeName,t.inbox_id,{});return"status"in e&&(t.status=e.status),this.putMessage(t)}));return Promise.all(e)}putMessage(t){return this.storage.put(this.storeName,t)}putBulkMessages(t){const e=t.map((t=>this.putMessage(t)));return Promise.all(e)}deleteMessages(t){const e=t.map((t=>this.storage.delete(this.storeName,t)));return Promise.all(e)}async deleteExpiredMessages(){this.dateModule.date=new Date;const t=this.dateModule.getTimestamp().toString(),e=(await this.storage.getAll(this.storeName)).filter((e=>e.rt<t)).map((t=>t.inbox_id));return this.deleteMessages(e)}getMessage(t){return this.storage.get(this.storeName,t)}async getReadOpenMessages(){return(await this.storage.getAll(this.storeName)).filter((t=>2===t.status||3===t.status))}async getDeliveredMessages(){return(await this.storage.getAll(this.storeName)).filter((t=>1===t.status))}async messagesCount(){return this.storage.count(this.storeName)}async getDeliveredMessagesCount(){return this.storage.countByIndex(this.storeName,"status",1)}async getReadMessagesCount(){return this.storage.countByIndex(this.storeName,"status",2)}async getDeliveredReadMessagesCount(){const[t,e]=[2,3],i=IDBKeyRange.bound(t,e);return this.storage.countByIndex(this.storeName,"status",i)}async updateMessages(){const t=await this.getInboxMessages();await this.deleteExpiredMessages(),t.deleted&&await this.deleteMessages(t.deleted),await this.putServerMessages(t.messages),this.eventBus.dispatchEvent("update-inbox-messages",{messages:new rt(this.data,this.api,this)})}}class ht{constructor(t=tt){this.store=t}async clearAll(){await this.store.set("params.applicationCode",void 0),await this.store.set("params.hwid",void 0),await this.store.set("params.deviceType",void 0),await this.store.set("params.deviceModel",void 0),await this.store.set("params.language",void 0),await this.store.set("params.apiEntrypoint",void 0),await this.store.set("params.tokens",void 0),await this.store.set("params.applicationServerKey",void 0),await this.store.set("params.senderId",void 0),await this.store.set("params.webSitePushId",void 0),await this.store.set("params.defaultNotificationImage",void 0),await this.store.set("params.defaultNotificationTitle",void 0),await this.store.set("params.userId",void 0),await this.store.set("params.email",void 0),await this.store.set("params.userIdWasChanged",void 0),await this.store.set("params.isLastPermissionStatus",void 0),await this.store.set("params.isManualUnsubscribed",void 0),await this.store.set("params.isCommunicationDisabled",void 0),await this.store.set("params.isDropAllData",void 0),await this.store.set("params.sdkVersion",void 0),await this.store.set("params.serviceWorkerVersion",void 0),await this.store.set("params.serviceWorkerUrl",void 0),await this.store.set("params.serviceWorkerScope",void 0),await this.store.set("params.lastOpenMessage",void 0),await this.store.set("params.lastOpenApplicationTime",void 0),await this.store.set("params.features",void 0),await this.store.set("params.init",void 0),await this.store.set("API_PARAMS",void 0),await this.store.set("SENDER_ID",void 0),await this.store.set("COMMUNICATION_ENABLED",void 0),await this.store.set("DEVICE_DATA_REMOVED",void 0),await this.store.set("LAST_OPEN_MESSAGE",void 0),await this.store.set("DELAYED_EVENT",void 0)}async setApplicationCode(t){await this.store.set("params.applicationCode",t)}async getApplicationCode(){return await this.store.get("params.applicationCode")}async setApiToken(t){return await this.store.set("params.apiToken",t)}async getApiToken(){return await this.store.get("params.apiToken")}async setHwid(t){await this.store.set("params.hwid",t)}async getHwid(){return await this.store.get("params.hwid")}async setDeviceType(t){await this.store.set("params.deviceType",t)}async getDeviceType(){return await this.store.get("params.deviceType")}async setDeviceModel(t){await this.store.set("params.deviceModel",t)}async getDeviceModel(){return await this.store.get("params.deviceModel")}async setLanguage(t){await this.store.set("params.language",t)}async getLanguage(){return await this.store.get("params.language","en")}async setApiEntrypoint(t){await this.store.set("params.apiEntrypoint",t)}async getApiEntrypoint(){return await this.store.get("params.apiEntrypoint","https://cp.pushwoosh.com/json/1.3/")}async setTokens(t){const e=await this.getHwid();await this.store.set("API_PARAMS",{hwid:e,...t}),await this.store.set("params.tokens",t)}async getTokens(){const t=await this.store.get("API_PARAMS"),e=await this.store.get("params.tokens");return void 0!==e?e:t}async setApplicationServerKey(t){await this.store.set("params.applicationServerKey",t)}async getApplicationServerKey(){return await this.store.get("params.applicationServerKey")}async setIsVapidChanged(t){await this.store.set("params.isVapidChanged",t)}async getIsVapidChanged(){return await this.store.get("params.isVapidChanged",!1)}async setWebSitePushId(t){await this.store.set("params.webSitePushId",t)}async getWebSitePushId(){return await this.store.get("params.webSitePushId")}async setDefaultNotificationImage(t){await this.store.set("params.defaultNotificationImage",t)}async getDefaultNotificationImage(){return await this.store.get("params.defaultNotificationImage","https://cp.pushwoosh.com/img/logo-medium.png")}async setDefaultNotificationTitle(t){await this.store.set("params.defaultNotificationTitle",t)}async getDefaultNotificationTitle(){return await this.store.get("params.defaultNotificationTitle","Pushwoosh notification")}async setUserId(t){t?await this.store.set("params.userId",t.toString()):await this.store.set("params.userId",void 0)}async getUserId(){return await this.store.get("params.userId")}async setStatusUserIdWasChanged(t){await this.store.set("params.userIdWasChanged",t)}async getStatusUserIdWasChanged(){return await this.store.get("params.userIdWasChanged",!1)}async setEmail(t){t?await this.store.set("params.email",t.toString()):await this.store.set("params.email",void 0)}async getEmail(){return await this.store.get("params.email")}async setStatusEmailWasChanged(t){await this.store.set("params.emailWasChanged",t)}async getStatusEmailWasChanged(){return await this.store.get("params.emailWasChanged",!1)}async setLastPermissionStatus(t){await this.store.set("params.isLastPermissionStatus",t)}async getLastPermissionStatus(){return await this.store.get("params.isLastPermissionStatus")}async setStatusManualUnsubscribed(t){await this.store.set("MANUAL_UNSUBSCRIBE",t),await this.store.set("params.isManualUnsubscribed",t)}async getStatusManualUnsubscribed(){const t=await this.store.get("MANUAL_UNSUBSCRIBE",!1),e=await this.store.get("params.isManualUnsubscribed",!1);return void 0!==e?e:t}async setStatusCommunicationDisabled(t){await this.store.set("COMMUNICATION_ENABLED",t?0:1),await this.store.set("params.isCommunicationDisabled",t)}async getStatusCommunicationDisabled(){const t=await this.store.get("COMMUNICATION_ENABLED"),e=await this.store.get("params.isCommunicationDisabled",!1);return void 0!==e?e:0==t}async setStatusDropAllData(t){await this.store.set("DEVICE_DATA_REMOVED",t),await this.store.set("params.isDropAllData",t)}async getStatusDropAllData(){const t=await this.store.get("DEVICE_DATA_REMOVED",!1),e=await this.store.get("params.isDropAllData",!1);return void 0!==e?e:t}async setSdkVersion(t){await this.store.set("params.sdkVersion",t)}async getSdkVersion(){return await this.store.get("params.sdkVersion")}async setServiceWorkerVersion(t){await this.store.set("WORKER_VERSION",t),await this.store.set("params.serviceWorkerVersion",t)}async getServiceWorkerVersion(){const t=await this.store.get("WORKER_VERSION"),e=await this.store.get("params.serviceWorkerVersion");return void 0!==e?e:t}async setServiceWorkerUrl(t){t&&await this.store.set("params.serviceWorkerUrl",t)}async getServiceWorkerUrl(){return await this.store.get("params.serviceWorkerUrl","/pushwoosh-service-worker.js")}async setServiceWorkerScope(t){t&&await this.store.set("params.serviceWorkerScope",t)}async getServiceWorkerScope(){return await this.store.get("params.serviceWorkerScope")}async setLastOpenMessage(t){await this.store.set("LAST_OPEN_MESSAGE",t),await this.store.set("params.lastOpenMessage",t)}async getLastOpenMessage(){const t=await this.store.get("LAST_OPEN_MESSAGE"),e=await this.store.get("params.lastOpenMessage");return void 0!==e?e:t}async setLastOpenApplicationTime(t){await this.store.set("params.lastOpenApplicationTime",t)}async getLastOpenApplicationTime(){return await this.store.get("params.lastOpenApplicationTime")}async setFeatures(t){await this.store.set("params.features",t)}async getFeatures(){return await this.store.get("params.features")}async setInitParams(t){await this.store.set("params.init",t)}async getInitParams(){return await this.store.get("params.init")}async setInboxLastRequestCode(t){await this.store.set("params.inbox.lastRequestCode",t)}async getInboxLastRequestCode(){return await this.store.get("params.inbox.lastRequestCode","")}async setInboxLastRequestTime(t){await this.store.set("params.inbox.lastRequestTime",t)}async getInboxLastRequestTime(){return this.store.get("params.inbox.lastRequestTime",0)}async setInboxNewMessagesCount(t){await this.store.set("params.inbox.newMessagesCount",t)}async getInboxNewMessagesCount(){return this.store.get("params.inbox.newMessagesCount",0)}async setDelayedEvent(t){await this.store.set("DELAYED_EVENT",t),await this.store.set("params.delayedEvent",t)}async getDelayedEvent(){const t=await this.store.get("DELAYED_EVENT"),e=await this.store.get("params.delayedEvent");return void 0!==e?e:t}async setPromptDisplayCount(t){await this.store.set("params.promptDisplayCount",t)}async getPromptDisplayCount(){return this.store.get("params.promptDisplayCount",0)}async setPromptLastSeenTime(t){await this.store.set("params.promptLastSeenTime",t)}async getPromptLastSeenTime(){return this.store.get("params.promptLastSeenTime",0)}}class lt{constructor(t=new ht,e=ot){this.data=t,this.logger=e}checkDevice(t){return this.createRequest("checkDevice",t)}getConfig(t){return this.createRequest("getConfig",t,"",!0)}applicationOpen(t){return this.createRequest("applicationOpen",t)}registerDevice(t){return this.createRequest("registerDevice",t)}unregisterDevice(t){return this.createRequest("unregisterDevice",t)}deleteDevice(t){return this.createRequest("deleteDevice",t)}messageDeliveryEvent(t){return this.createRequest("messageDeliveryEvent",t)}pushStat(t){return this.createRequest("pushStat",t)}setTags(t){return this.createRequest("setTags",t)}getTags(t){return this.createRequest("getTags",t)}registerUser(t){return this.createRequest("registerUser",t)}registerEmail(t){return this.createRequest("registerEmail",t)}registerEmailUser(t){return this.createRequest("registerEmailUser",t)}setEmailTags(t){return this.createRequest("setEmailTags",t)}postEvent(t){return this.createRequest("postEvent",t)}getInboxMessages(t){return this.createRequest("getInboxMessages",t)}inboxStatus(t){return this.createRequest("inboxStatus",t)}pageVisit(t,e){return this.createRequest("pageVisit",t,e)}setPurchase(t){return this.createRequest("setPurchase",t)}async createRequest(t,e,i,s){const n=await this.data.getApiEntrypoint(),a=s?"":await this.data.getApiToken(),o=i||n+t,r=a?{headers:{Authorization:`Token ${a}`,"Content-Type":"text/plain;charset=UTF-8",Origin:globalThis.location.origin},credentials:"include"}:{},c=await fetch(o,{method:"POST",headers:{"Content-Type":"text/plain;charset=UTF-8"},body:JSON.stringify({request:e}),...r}),p=await this.checkResponse(c);return p.base_url&&await this.data.setApiEntrypoint(p.base_url),await this.logger.write("apirequest",`${t} call with arguments: ${JSON.stringify(e)} to Pushwoosh has been successful. Result: ${JSON.stringify(p.response)}`),p.response}async checkResponse(t){if(200!==t.status)throw new Error(`Error code: ${t.status}. Error text: ${t.statusText}`);const e=await t.json();if(200!==e.status_code)throw new Error(`Error code: ${e.status_code}. Error text: ${e.status_message}`);return e}}class ut{constructor(t,e=new ht,i=new lt){this.eventBus=t,this.data=e,this.apiClient=i}async checkDevice(){const t=await this.getRequestParams();return await this.apiClient.checkDevice(t)}async checkDeviceSubscribeForPushNotifications(t=!0){let e=localStorage.getItem(c);if(void 0===e||!t){const{exist:t,push_token_exist:i}=await this.checkDevice();localStorage.setItem(c,t&&i?p:d),e=localStorage.getItem(c)}return e===p}async getConfig(t){const e=await this.getRequestParams();return this.apiClient.getConfig({...e,features:t})}async applicationOpen(){const t=await this.getRequestParams();return await this.data.setLastOpenApplicationTime(Date.now()),this.apiClient.applicationOpen(t)}async registerDevice(){if(await this.data.getStatusCommunicationDisabled())throw new Error("Can't register device: Communication is disabled!");const t=await this.getRequestParams(),e=await this.data.getTokens();if(!e.pushToken)throw new Error("Can't register device: pushToken is not exist!");const i=await this.apiClient.registerDevice({...t,push_token:e.pushToken,auth_token:e.authToken,public_key:e.publicKey});return await this.data.setStatusManualUnsubscribed(!1),localStorage.setItem(c,p),this.eventBus.dispatchEvent("register",{}),i}async unregisterDevice(){const t=await this.getRequestParams(),e=this.apiClient.unregisterDevice(t);return localStorage.setItem(c,d),this.eventBus.dispatchEvent("unsubscribe",{}),e}async deleteDevice(){const t=await this.getRequestParams(),e=this.apiClient.deleteDevice(t);return await this.data.setStatusManualUnsubscribed(!0),localStorage.setItem(c,d),this.eventBus.dispatchEvent("unsubscribe",{}),e}async messageDeliveryEvent(t,e,i={}){const s=await this.getRequestParams();return await this.apiClient.messageDeliveryEvent({...s,hash:t,metaData:i})}async pushStat(t,e,i={}){const s=await this.getRequestParams();return await this.apiClient.pushStat({...s,hash:t,metaData:i})}async setTags(t){const{hwid:e,device_type:i,...s}=await this.getRequestParams(),n=await this.data.getEmail();return n&&await this.apiClient.setEmailTags({...s,email:n,tags:t}),this.apiClient.setTags({...s,hwid:e,device_type:i,tags:t})}async getTags(){const t=await this.getRequestParams();return this.apiClient.getTags(t)}async registerUser(t){const{hwid:e,device_type:i,...s}=await this.getRequestParams(),n=await this.data.getDeviceType(),a=`${t}`,o=await this.data.getEmail(),r=await this.apiClient.registerUser({...s,hwid:e,userId:a,ts_offset:60*-(new Date).getTimezoneOffset(),device_type:n});return o&&await this.apiClient.registerEmailUser({...s,email:o,userId:a,ts_offset:60*-(new Date).getTimezoneOffset()}),await this.data.setUserId(`${t}`),await this.data.setStatusUserIdWasChanged(!0),r}async registerEmail(t){const{hwid:e,device_type:i,...s}=await this.getRequestParams(),n=await this.apiClient.registerEmail({...s,email:t,ts_offset:60*-(new Date).getTimezoneOffset()});return await this.data.setEmail(`${t}`),await this.data.setStatusEmailWasChanged(!0),n}async postEvent(t,e){const i=await this.getRequestParams(),s=new Date,n=s.getTime(),a=Math.floor(n/1e3),o=a-s.getTimezoneOffset()/60*3600,r=await this.data.getLastOpenMessage();if(r&&r.expiry>Date.now()){if(e.msgHash)return Promise.reject("attribute msgHash already defined");e={...e,msgHash:r.messageHash}}await this.data.setLastOpenMessage(void 0);const c=await this.apiClient.postEvent({...i,event:t,timestampUTC:a,timestampCurrent:o,attributes:e});return c&&c.code&&this.eventBus.dispatchEvent("receive-in-app-code",{code:c.code}),c}async getInboxMessages(t=0){const e=await this.getRequestParams(),i=await this.data.getInboxLastRequestCode(),s=await this.data.getInboxLastRequestTime();return this.apiClient.getInboxMessages({...e,count:t,last_code:i,last_request_time:s})}async inboxStatus(t,e){const i=await this.getRequestParams();return this.apiClient.inboxStatus({...i,inbox_code:t,status:e,time:(new Date).getTime()})}async triggerEvent(){throw new Error("Method has been deprecated, because we don't aggregate this statistics.")}async pageVisit(t){const e=await this.getRequestParams(),i=await this.data.getFeatures(),s=i&&i.page_visit&&i.page_visit.entrypoint;if(s)return this.apiClient.pageVisit({...e,...t},s)}async setPurchase(t){const e=await this.getRequestParams();return this.apiClient.setPurchase({...e,...t})}async getParams(){return{applicationCode:await this.data.getApplicationCode(),hwid:await this.data.getHwid(),...await this.data.getTokens(),...await this.data.getInitParams()}}get params(){throw new Error('Property "Pushwoosh.api.params" have been deprecated. Use the async method "Pushwoosh.api.getParams()"')}async getRequestParams(){const t=await this.data.getApplicationCode(),e=await this.data.getHwid(),i=await this.data.getUserId(),s=await this.data.getDeviceType(),n=await this.data.getDeviceModel(),a=await this.data.getLanguage(),o=await this.data.getSdkVersion();return{application:t,hwid:e,userId:i||e,device_type:s,device_model:n,timezone:60*-(new Date).getTimezoneOffset(),language:a,v:o}}}class gt{constructor(t){this.global=t,this._isSafari=this.isSafariBrowser(),this._isOpera=this.isOperaBrowser(),this._isEdge=this.isEdgeBrowser(),this._isFirefox=this.isFirefoxBrowser(),this._isChrome=this.isChromeBrowser(),this._isMacOS=this.isMacOS(),this._isAvailablePromise=this.canUsePromise(),this._isAvailableServiceWorker=this.canUseServiceWorkers(),this._isAvailableNotifications=this.canReceiveNotifications(),this._platform=this.getPlatformType(),this._browserVersion=this.getBrowserVersion()}get isEdge(){return this._isEdge}get isSafari(){return this._isSafari}get isOpera(){return this._isOpera}get isAvailablePromise(){return this._isAvailablePromise}get isAvailableServiceWorker(){return this._isAvailableServiceWorker}get isAvailableNotifications(){return this._isAvailableNotifications}get platform(){return this._platform}get browserVersion(){return this._browserVersion}isSafariBrowser(){return"safari"in this.global&&navigator.userAgent.indexOf("Safari")>-1}isOperaBrowser(){return-1!==navigator.userAgent.indexOf("Opera")||-1!==navigator.userAgent.indexOf("OPR")}isEdgeBrowser(){return navigator.userAgent.indexOf("Edge")>-1}isFirefoxBrowser(){return-1!==navigator.userAgent.toLowerCase().indexOf("firefox")}isChromeBrowser(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)&&!this._isOpera&&!this._isEdge}isMacOS(){return"platform"in navigator&&-1!==navigator.platform.toLowerCase().indexOf("mac")}canUseServiceWorkers(){return!!navigator.serviceWorker&&"PushManager"in this.global&&"Notification"in this.global}canUsePromise(){return"Promise"in this.global}canReceiveNotifications(){return this._isSafari&&this._isMacOS||this._isAvailableServiceWorker&&!this._isEdge}getPlatformType(){let t=11;switch(!0){case this._isSafari:t=10;break;case this._isOpera||this._isChrome:t=11;break;case this._isFirefox:t=12;break;case this._isEdge:t=150}return t}getBrowserVersion(){const{userAgent:t}=navigator,e=t.match(/\bOPR\/(\d+)/);if(null!==e)return`Opera ${e[1]}`;const i=t.match(/\bEdge\/(\d+)/);if(null!==i)return`Edge ${i[1]}`;const s=t.match(/\bEdg\/(\d+)/);if(null!==s)return`Edge ${s[1]}`;let n=t.match(/(opera|chrome|safari|firefox(?=\/))\/?\s*(\d+)/i)||[];const[,a=""]=n;n=n[2]?[a,n[2]]:[navigator.appName,navigator.appVersion,"-?"];const o=t.match(/version\/([.\d]+)/i);return null!==o&&n.splice(1,1,o[1]),n.join(" ")}}const bt=new gt($());class wt{constructor(t,e,i){this.api=t,this.data=e,this.config=i}getPermission(){return Notification.permission}checkIsPermissionGranted(){return this.getPermission()===l}checkIsPermissionDefault(){return this.getPermission()===u}async checkIsManualUnsubscribed(){return this.data.getStatusManualUnsubscribed()}async askPermission(){await Notification.requestPermission()}async getTokens(){return this.data.getTokens()}async subscribe(t){const e=t||await this.trySubscribe();if(!this.checkIsPermissionGranted())return void ot.error("You must have permission granted before subscribe!");const i=this.getPushToken(e),s=e.getKey("p256dh"),n=e.getKey("auth");if(!s||!n)throw new Error("Can't get subscription keys!");const a=btoa(String.fromCharCode.apply(String,new Uint8Array(s))),o=btoa(String.fromCharCode.apply(String,new Uint8Array(n)));await this.data.setTokens({publicKey:a,pushToken:i,authToken:o,endpoint:e.endpoint}),await this.api.registerDevice()}async unsubscribe(){const t=await this.getServiceWorkerRegistration(),e=await t.pushManager.getSubscription();await this.data.setTokens({}),await this.data.setStatusManualUnsubscribed(!0),await this.api.unregisterDevice(),e&&await e.unsubscribe()}async checkIsRegister(){return this.api.checkDeviceSubscribeForPushNotifications()}async checkIsNeedResubscribe(){const t=await this.data.getLastPermissionStatus(),e=this.getPermission();if(t!==e)return await this.data.setLastPermissionStatus(e),!0;const i=await this.getCredentials(),s=this.getPushToken(i),n=await this.data.getTokens(),a=s===(n&&n.pushToken||""),o=await this.data.getIsVapidChanged();return!a||o}async getServiceWorkerRegistration(){if(!this.registration){await this.registerServiceWorker();const t=await this.data.getServiceWorkerUrl();this.registration=await navigator.serviceWorker.getRegistration(t),await this.registration.update()}if(!this.registration)throw new Error("Internal Error: Can't register service worker!");return this.registration}async registerServiceWorker(){const t=await this.data.getServiceWorkerUrl(),e=await this.data.getServiceWorkerScope();let i="";await this.data.getSdkVersion()!==await this.data.getServiceWorkerVersion()&&(i=`?cache_clean=${r()}`),await navigator.serviceWorker.register(`${t}${i}`,{scope:e})}async trySubscribe(){try{return await this.subscribePushManager()}catch(t){return console.error(t),await this.unsubscribe(),this.subscribePushManager()}}async subscribePushManager(){const t=await this.getServiceWorkerRegistration(),e=await this.getApplicationServerKey();return t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:e?this.urlBase64ToUint8Array(e):null})}async getCredentials(){const t=await this.getServiceWorkerRegistration();return await t.pushManager.getSubscription()}getPushToken(t){return t?t.endpoint:""}async getApplicationServerKey(){if(11===await this.data.getDeviceType())return await this.data.getApplicationServerKey()}urlBase64ToUint8Array(t){const e=(t+"=".repeat((4-t.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),i=atob(e),s=new Uint8Array(i.length);for(let t=0;t<i.length;++t)s[t]=i.charCodeAt(t);return s}}class mt{constructor(t,e,i){this.api=t,this.config=i,this.data=e}getPermission(){const{permission:t}=this.getPermissionInfo();return t}checkIsPermissionGranted(){return this.getPermission()===l}checkIsPermissionDefault(){return this.getPermission()===u}async checkIsManualUnsubscribed(){return await this.data.getStatusManualUnsubscribed()}async askPermission(){const t={application:await this.data.getApplicationCode(),hwid:await this.data.getHwid()};return new Promise((e=>{safari.pushNotification.requestPermission(this.config.entrypoint||"https://cp.pushwoosh.com/json/1.3/safari",this.config.webSitePushId,t,(()=>e()))}))}getTokens(){return this.data.getTokens()}async subscribe(){if(!this.checkIsPermissionGranted())return void ot.error("You must have permission granted before subscribe!");const{deviceToken:t}=this.getPermissionInfo();await this.data.setTokens({pushToken:t}),await this.api.registerDevice()}async unsubscribe(){await this.data.setTokens({}),await this.data.setStatusManualUnsubscribed(!0),await this.api.unregisterDevice()}async checkIsRegister(){return this.api.checkDeviceSubscribeForPushNotifications()}async checkIsNeedResubscribe(){const t=await this.data.getWebSitePushId(),e=void 0!==t&&this.config.webSitePushId!==t;await this.data.setWebSitePushId(this.config.webSitePushId);const i=await this.data.getLastPermissionStatus(),s=this.getPermission();return i!==s?(await this.data.setLastPermissionStatus(s),!0):e}getPermissionInfo(){return safari.pushNotification.permission(this.config.webSitePushId)}}class ft{constructor(){this.ready=!1,this.addEventHandler=(t,e)=>this.eventBus.addEventHandler(t,e),this.removeEventHandler=(t,e)=>this.eventBus.removeEventHandler(t,e),this.dispatchEvent=(t,e)=>this.eventBus.dispatchEvent(t,e),this.debug={async showLog(){const t=await it.getAll();console.log(t)},async showKeyValues(){const t=await tt.getAll();console.log(t)},async showMessages(){(await st.getAll()).forEach((t=>console.log(t)))}},this.eventBus=new A,this.data=new ht,this.apiClient=new lt(this.data),this.api=new ut(this.eventBus,this.data,this.apiClient),this.platformChecker=new gt($()),this.inboxModel=new dt(this.eventBus,this.data,this.api),this.pwinbox=new rt(this.data,this.api,this.inboxModel),this.onServiceWorkerMessage=this.onServiceWorkerMessage.bind(this),this.subscriptionPromptWidget=new O(this.eventBus,this)}push(t){if("function"!=typeof t){if(!Array.isArray(t))throw new Error("Invalid command!");switch(t[0]){case"init":this.initialize(t[1]);break;case g:case b:case f:case w:case m:case _:case C:case S:case k:case E:case T:case P:case I:case M:case B:case D:case x:case v:case y:this.subscribeToLegacyEvents(t[0],t[1]);break;default:throw new Error("Unknown command!")}}else this.subscribeToLegacyEvents("onReady",t)}async subscribe(t=!0){this.isCommunicationDisabled&&ot.error("Communication is disabled!");if(this.driver.checkIsPermissionDefault()){this.eventBus.dispatchEvent("show-notification-permission-dialog",{}),await this.driver.askPermission();const t=this.driver.getPermission();this.eventBus.dispatchEvent("hide-notification-permission-dialog",{permission:t})}const e=this.driver.getPermission(),i=await this.data.getStatusManualUnsubscribed(),s=await this.api.checkDeviceSubscribeForPushNotifications(!1);if(e===l){this.eventBus.dispatchEvent("permission-granted",{});return(!s&&!i||t)&&await this.driver.subscribe(),void this.eventBus.dispatchEvent("subscribe",{})}if(e===h)return this.eventBus.dispatchEvent("permission-denied",{}),void(s&&await this.driver.unsubscribe())}async unsubscribe(){try{await this.driver.unsubscribe()}catch(t){ot.error(t,"Error occurred during the unsubscribe")}}async forceSubscribe(){await this.subscribe(!0)}isDeviceRegistered(){return localStorage.getItem(c)===p}isDeviceUnregistered(){return localStorage.getItem(c)===d}async isSubscribed(){return this.api.checkDeviceSubscribeForPushNotifications()}async isCommunicationEnabled(){return!await this.data.getStatusCommunicationDisabled()}async setCommunicationEnabled(t=!0){const e=await this.data.getDeviceType(),i=this.driver.checkIsPermissionGranted();await this.data.setStatusCommunicationDisabled(!t),t?(await this.data.setStatusDropAllData(!1),i&&await this.api.registerDevice()):await this.api.unregisterDevice(),this.eventBus.dispatchEvent("change-enabled-communication",{isEnabled:t}),await this.api.postEvent("GDPRConsent",{channel:t,device_type:e})}async removeAllDeviceData(){const t=await this.data.getDeviceType();await this.api.postEvent("GDPRDelete",{status:!0,device_type:t}),await this.api.deleteDevice(),await this.data.clearAll(),await this.data.setStatusDropAllData(!0)}async getHWID(){return await this.data.getHwid()}async getPushToken(){const{pushToken:t}=await this.data.getTokens();return t}async getUserId(){return await this.data.getUserId()}async getParams(){return await this.api.getParams()}isAvailableNotifications(){return this.platformChecker.isAvailableNotifications}async sendStatisticsVisitedPage(){const{document:{title:t},location:{origin:e,pathname:i,href:s}}=window;await this.api.pageVisit({title:t,url_path:`${e}${i}`,url:s})}async initialize(t){const e=localStorage.getItem("PW_SET_LOGGER_LEVEL");if(ot.setLevel(e||t.logLevel||"error"),!this.platformChecker.isAvailableNotifications)return;const i=await this.data.getApplicationCode();if(!t.applicationCode)throw new Error("Can't find application code!");const s=!i,n=i&&i!==t.applicationCode;(s||n)&&(await this.data.clearAll(),await this.data.setApplicationCode(t.applicationCode));if(!await this.data.getHwid()){const e=t.applicationCode+"_"+r();await this.data.setHwid(e)}await this.data.setDeviceType(this.platformChecker.getPlatformType()),await this.data.setDeviceModel(this.platformChecker.getBrowserVersion()),await this.data.setLanguage(t.tags&&t.tags.Language||navigator.language),await this.data.setApiEntrypoint(t.pushwooshUrl||""),await this.data.setApiToken(t.apiToken||""),await this.data.setSdkVersion("3.40.0");const a=await this.api.getConfig(["page_visit","vapid_key","web_in_apps","events","subscription_prompt"]);this.onGetConfig(a&&a.features),this.subscribeWidgetConfig={enable:!1,...t.subscribeWidget},this.inboxWidgetConfig={enable:!1,...t.inboxWidget},this.subscribePopupConfig={enable:!1,...t.subscribePopup},this.isCommunicationDisabled=await this.data.getStatusCommunicationDisabled(),await this.open();const o=await this.data.getStatusUserIdWasChanged();t.userId&&"user_id"!==t.userId&&!o&&await this.api.registerUser(t.userId);const c=await this.data.getStatusEmailWasChanged();t.email&&""!==t.email&&!c&&(/^\S+@\S+\.\S+$/.test(t.email)?await this.api.registerEmail(t.email):ot.write("error",`can't register invalid email: ${t.email}`)),t.tags&&this.api.setTags(t.tags);const p=await this.data.getApplicationServerKey();this.platformChecker.isAvailableNotifications&&p&&await this.initPushNotifications(t);try{await this.inboxModel.updateMessages()}catch(t){ot.write("error",t)}this.ready=!0,this.eventBus.dispatchEvent("ready",{});const d=await this.data.getDelayedEvent();if(d){const{type:t,payload:e}=d;this.emitLegacyEventsFromServiceWorker(t,e),await this.data.setDelayedEvent(null)}if("serviceWorker"in navigator&&(navigator.serviceWorker.onmessage=this.onServiceWorkerMessage),localStorage.setItem("pushwoosh-websdk-status","init"),document.dispatchEvent(new CustomEvent("pushwoosh.initialized",{detail:{pw:this}})),this.platformChecker.isSafari){const t=/#P(.*)/,e=decodeURIComponent(document.location.hash);t.test(e)&&this.api.pushStat(t.exec(e)[1]).then(N)}}async defaultProcess(t){const e=this.driver.getPermission();"granted"===e&&await this.data.setLastPermissionStatus(e);const i=await this.data.getStatusCommunicationDisabled(),s=await this.data.getStatusDropAllData(),n=await this.driver.checkIsNeedResubscribe(),a=await this.data.getFeatures(),o=a.subscription_prompt&&a.subscription_prompt.use_case;if(i||s)return void await this.unsubscribe();n&&(await this.unsubscribe(),await this.data.setStatusManualUnsubscribed(!1),await this.data.setIsVapidChanged(!1));const{autoSubscribe:r}=t,c=await this.data.getStatusManualUnsubscribed(),p=await this.api.checkDeviceSubscribeForPushNotifications(!1);switch(e){case u:{this.eventBus.dispatchEvent("permission-default",{}),p&&await this.unsubscribe();const t=await this.getWidgetConfig();if(!await this.checkCanShowByCapping(t))break;("default"===o||"not-set"===o&&r)&&(this.subscriptionPromptWidget.init(t),this.subscriptionPromptWidget.show()),await this.updateCappingParams();break}case h:this.eventBus.dispatchEvent("permission-denied",{}),p&&await this.unsubscribe();break;case l:this.eventBus.dispatchEvent("permission-granted",{}),c&&p&&await this.unsubscribe(),(!p&&!c||n)&&await this.subscribe(!0)}}async getWidgetConfig(){const t=await this.data.getFeatures(),e=t.subscription_prompt_widget&&t.subscription_prompt_widget.params,i={cappingCount:R.cappingCount,cappingDelay:R.cappingDelay,...e};return e?i:R}async checkCanShowByCapping(t){const e=(new Date).getTime(),i=await this.data.getPromptDisplayCount(),s=await this.data.getPromptLastSeenTime(),n=t.cappingCount>i,a=e-s>t.cappingDelay;return n&&a}async updateCappingParams(){const t=await this.data.getPromptDisplayCount(),e=(new Date).getTime();await this.data.setPromptDisplayCount(t+1),await this.data.setPromptLastSeenTime(e)}onServiceWorkerMessage(t){const{data:e={}}=t||{},{type:i="",payload:s={}}=e||{};this.emitLegacyEventsFromServiceWorker(i,s)}async open(t){let e=await this.data.getLastOpenApplicationTime();const i=Date.now();e||(e=0);(t||!(i-e<36e5))&&(await this.data.setLastOpenApplicationTime(i),await this.api.applicationOpen())}async onGetConfig(t){if(await this.data.setFeatures(t),t){if(t.page_visit&&t.page_visit.enabled&&(await tt.set("PAGE_VISITED_URL",t.page_visit.entrypoint),this.sendStatisticsVisitedPage()),t.events&&t.events.length){t.events.some((t=>t===W))&&this.sendPostEventVisitedPage()}if(t.vapid_key){const e=await this.data.getApplicationServerKey();await this.data.setApplicationServerKey(t.vapid_key),e!==t.vapid_key&&await this.data.setIsVapidChanged(!0)}}}async initPushNotifications(t){await this.data.setDefaultNotificationImage(t.defaultNotificationImage),await this.data.setDefaultNotificationTitle(t.defaultNotificationTitle),await this.data.setServiceWorkerUrl(t.serviceWorkerUrl),await this.data.setServiceWorkerScope(t.scope),await this.data.setInitParams({autoSubscribe:!0,...t}),await this.initDriver();try{await this.defaultProcess(t)}catch(t){ot.error(t,"Internal error: defaultProcess fail")}}async initDriver(){if(this.platformChecker.isSafari){const{safariWebsitePushID:t}=await this.data.getInitParams();return t?void(this.driver=new mt(this.api,this.data,{webSitePushId:t})):void ot.info("For work with Safari Push Notification add safariWebsitePushID to initParams!")}this.platformChecker.isAvailableServiceWorker&&(this.driver=new wt(this.api,this.data,{}))}sendPostEventVisitedPage(){const{document:{title:t},location:{href:e}}=window;this.api.postEvent(W,{url:e,title:t,device_type:this.platformChecker.platform})}subscribeToLegacyEvents(t,e){switch(t){case g:e();break;case b:if(this.ready){e(this.api);break}this.eventBus.addEventHandler("ready",(()=>e(this.api)));break;case f:this.eventBus.addEventHandler("register",(()=>e(this.api)));break;case w:this.eventBus.addEventHandler("subscribe",(()=>e(this.api)));break;case m:this.eventBus.addEventHandler("unsubscribe",(()=>e(this.api)));break;case _:this.eventBus.addEventHandler("initialize-service-worker-error",(({error:t})=>e(this.api,t)));break;case C:this.eventBus.addEventHandler("receive-push",(({notification:t})=>e(this.api,t)));break;case S:this.eventBus.addEventHandler("open-notification",(({notification:t})=>e(this.api,t)));break;case k:this.eventBus.addEventHandler("hide-notification",(({notification:t})=>e(this.api,t)));break;case E:this.eventBus.addEventHandler("change-enabled-communication",(({isEnabled:t})=>e(this.api,t)));break;case T:this.eventBus.addEventHandler("receive-inbox-message",(({message:t})=>e(this.api,t)));break;case P:this.eventBus.addEventHandler("update-inbox-messages",(({messages:t})=>e(this.api,t)));break;case I:this.eventBus.addEventHandler("show-notification-permission-dialog",(()=>e(this.api)));break;case M:this.eventBus.addEventHandler("hide-notification-permission-dialog",(({permission:t})=>e(this.api,t)));break;case B:this.eventBus.addEventHandler("show-subscription-widget",(()=>e(this.api)));break;case D:this.eventBus.addEventHandler("hide-subscription-widget",(()=>e(this.api)));break;case x:this.eventBus.addEventHandler("permission-denied",(()=>e(this.api)));break;case v:this.eventBus.addEventHandler("permission-default",(()=>e(this.api)));break;case y:this.eventBus.addEventHandler("permission-granted",(()=>e(this.api)))}}emitLegacyEventsFromServiceWorker(t,e){switch(t){case C:this.eventBus.dispatchEvent("receive-push",{notification:e});break;case S:this.eventBus.dispatchEvent("open-notification",{notification:e});break;case k:this.eventBus.dispatchEvent("hide-notification",{notification:e});break;case T:this.eventBus.dispatchEvent("receive-inbox-message",{message:e})}}}const vt=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],xt=[{name:"widgetWidth",type:"size"},{name:"borderRadius",type:"size"},{name:"zIndex",type:"number"},{name:"fontFamily",type:"string"},{name:"bgColor",type:"color"},{name:"textColor",type:"color"},{name:"arrowBorderColor",type:"color"},{name:"borderColor",type:"color"},{name:"badgeBgColor",type:"color"},{name:"badgeTextColor",type:"color"},{name:"timeTextColor",type:"color"},{name:"messageTitleColor",type:"color"},{name:"emptyInboxTitleColor",type:"color"},{name:"emptyInboxTextColor",type:"color"}],yt={enable:!1,triggerId:"pwInbox",position:"bottom",appendTo:"body",title:"Inbox",bgColor:"#ffffff",textColor:"#333333",fontFamily:"inherit",borderRadius:4,borderColor:"transparent",badgeBgColor:"#ff4c00",badgeTextColor:"#ffffff",widgetWidth:350,zIndex:100,messageTitleColor:"#7a7a7a",timeTextColor:"#c4c4c4",emptyInboxTitle:"You're all caught up",emptyInboxTitleColor:"#333333",emptyInboxText:"There are no new messages. Stay tuned!",emptyInboxTextColor:"#7a7a7a",emptyInboxIconUrl:"https://pushon.pushwoosh.com/images/icon-empty-inbox.png",arrowBorderColor:"rgba(0,0,0,.1)"},_t=/^(#([\da-f]{3}){1,2}$|(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0?\.\d+)\)$|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/;function Ct(t){let e="fixed"===window.getComputedStyle(t).position;return!e&&t.parentElement&&(e=Ct(t.parentElement)),e}const St=({imageUrl:t,title:e,message:i,sendDate:s})=>`\n<div class="pw-inbox_item-inner">\n <div class="pw-inbox_icon">\n <img src="${t}" alt="${e||i}" class="pw-inbox_message-image">\n </div>\n <div class="pw-inbox_content">\n ${e?`<div class="pw-inbox_item-title">\n ${e}\n </div>`:null}\n <div class="pw-inbox_item-body">\n ${i}\n </div>\n <div class="pw-inbox_item-time">\n ${function(t){const e=new Date(t),i=e.getHours()+e.getTimezoneOffset()/60;e.setHours(i);const s=(new Date).getTime()-e.getTime();if(s<=6e4)return"Just now";if(s<36e5&&s>0)return`${Math.floor(s/6e4)} minutes ago`;if(s<864e5&&s>0)return`${Math.floor(s/36e5)} hours ago`;return`${e.getDate()} ${vt[e.getMonth()]} ${e.getFullYear()}, ${e.getHours()}:${`0${e.getMinutes().toString()}`.slice(-2)}`}(s)}\n </div>\n </div>\n</div>\n<span class="pw-inbox_item-remove"></span>`;class kt{constructor(t){this.pw=t,this.config={...yt,arrowBorderColor:this.pw.inboxWidgetConfig.borderColor&&"transparent"!==this.pw.inboxWidgetConfig.borderColor?this.pw.inboxWidgetConfig.borderColor:"rgba(0,0,0,.1)",...this.pw.inboxWidgetConfig},this.updateInbox=this.updateInbox.bind(this),this.markVisibleItemsAsRead=this.markVisibleItemsAsRead.bind(this),this.onWidgetClickHandler=this.onWidgetClickHandler.bind(this),this.onTriggerClickHandler=this.onTriggerClickHandler.bind(this),this.onWindowScrollHandler=this.onWindowScrollHandler.bind(this),this.toggle=this.toggle.bind(this);try{this.initTrigger(),this.updateInbox(),this.addListeners()}catch(t){console.warn(t)}}toggle(t){(void 0===t?!this.isOpened:t)?this.openWidget():this.closeWidget()}initTrigger(){if(!this.pw.pwinbox)throw new Error("Web inbox is not allowed.");const t=document.getElementById(this.config.triggerId);if(!t)throw new Error("Inbox trigger element doesn't exist. You must set triggerId in inboxWidget config. See the documentation.");this.trigger=t,this.trigger.classList.add("pw-inbox-trigger"),this.defaultMargin=12,this.messagesElements={},this.messages=[],this.readItems=[],this.updateCounter(0),this.isOpened=!1,this.renderWidget(),this.isFixed=Ct(this.trigger)}renderWidget(){this.widget=document.createElement("div"),this.widget.id="pwInboxWidget",this.widget.className="pw-inbox-widget",this.widget.classList.toggle("pw-open",this.isOpened),this.widgetParent=document.querySelector(this.config.appendTo)||document.body,this.widgetParent.appendChild(this.widget),this.widgetParent.appendChild(this.getStyle()),this.renderWidgetInner()}getStyle(){const t=document.createElement("style");return t.innerHTML=this.configureStyle(".pw-inbox-trigger {\n position: relative;\n cursor: pointer;\n}\n\n.pw-inbox-trigger:after {\n content: attr(data-pw-count);\n display: block;\n position: absolute;\n right: 0;\n top: 0;\n background: var(--badgeBgColor);\n border-radius: 8px;\n color: var(--badgeTextColor);\n font-size: 10px;\n font-weight: normal;\n line-height: 16px;\n width: 16px;\n padding: 0 2px;\n box-sizing: border-box;\n text-align: center;\n}\n\n.pw-inbox-trigger.pw-empty:after {\n display: none;\n}\n\n.pw-inbox-widget * {\n position: static;\n box-sizing: border-box;\n font-size: 1em;\n outline: none;\n font-family: var(--fontFamily);\n}\n.pw-inbox-widget {\n font-size: 14px;\n position: absolute;\n top: 0;\n left: -1000px;\n background: var(--bgColor);\n border: solid 1px var(--borderColor);\n border-radius: var(--borderRadius);\n width: var(--widgetWidth);\n box-shadow: 0 1px 4px 0 rgba(0,0,0,.25);\n z-index: var(--zIndex);\n opacity: 0;\n transition: opacity .6s ease;\n transition-delay: 100ms;\n}\n.pw-inbox-widget.pw-open {\n opacity: 1;\n transition-delay: 0ms;\n}\n.pw-inbox-widget.pw-inbox-widget--inset {\n top: auto;\n left: auto;\n display: none;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-open {\n display: block;\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-bottom {\n top: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-top {\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-right {\n left: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--inset.pw-left {\n right: 100%;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-inbox-widget--empty {\n max-height: none;\n}\n.pw-inbox-widget .pw-inbox__arrow {\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget .pw-inbox__arrow:before {\n content: \"\";\n display: block;\n width: 0;\n height: 0;\n border-width: 10px;\n border-style: solid;\n border-color: transparent;\n position: absolute;\n}\n.pw-inbox-widget.pw-top {\n margin-top: -12px;\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow {\n border-top-color: var(--arrowBorderColor);\n bottom: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-top .pw-inbox__arrow:before {\n border-top-color: var(--bgColor);\n top: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-bottom {\n margin-top: 12px;\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow {\n border-bottom-color: var(--arrowBorderColor);\n top: -21px;\n left: 50%;\n transform: translateX(-50%);\n}\n.pw-inbox-widget.pw-bottom .pw-inbox__arrow:before {\n border-bottom-color: var(--bgColor);\n bottom: -11px;\n left: -10px;\n}\n.pw-inbox-widget.pw-left {\n margin-left: -12px;\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow {\n border-left-color: var(--arrowBorderColor);\n right: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-left .pw-inbox__arrow:before {\n border-left-color: var(--bgColor);\n left: -11px;\n top: -10px;\n}\n.pw-inbox-widget.pw-right {\n margin-left: 12px;\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow {\n border-right-color: var(--arrowBorderColor);\n left: -21px;\n top: 50%;\n transform: translateY(-50%);\n}\n.pw-inbox-widget.pw-right .pw-inbox__arrow:before {\n border-right-color: var(--bgColor);\n right: -11px;\n top: -10px;\n}\n.pw-inbox_inner {\n overflow: hidden;\n display: flex;\n flex-direction: column;\n height: 100%;\n}\n.pw-inbox_title {\n color: var(--textColor);\n margin: 0;\n padding: 28px 32px 12px;\n font-size: 24px;\n font-weight: 500;\n line-height: 1.1;\n text-align: left;\n flex: 0 0 66px;\n}\n.pw-inbox_list {\n overflow-x: hidden;\n overflow-y: auto;\n min-width: 200px;\n max-height: 300px;\n padding: 0;\n margin: 0;\n list-style: none;\n position: relative;\n flex: 1 1 auto;\n}\n\n.pw-inbox_item {\n position: relative;\n padding: 8px 32px;\n margin: 0;\n text-align: left;\n}\n.pw-inbox_item-inner {\n display: flex;\n cursor: pointer;\n}\n.pw-inbox_icon {\n flex: 0 0 40px;\n}\n.pw-inbox_message-image {\n width: 28px;\n}\n.pw-inbox_content {\n flex: 0 1 100%;\n}\n.pw-inbox_item-title {\n color: var(--messageTitleColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n}\n.pw-inbox_item-body {\n color: var(--textColor);\n font-size: 14px;\n line-height: 20px;\n margin-bottom: 4px;\n}\n.pw-inbox_item-time {\n color: var(--timeTextColor);\n font-size: 12px;\n line-height: 17px;\n}\n.pw-inbox_item-remove {\n position: absolute;\n z-index: 2;\n top: 8px;\n right: 8px;\n display: none;\n width: 10px;\n height: 10px;\n background: transparent url('https://cdn.pushwoosh.com/webpush/img/iconClose.svg') 50% no-repeat;\n cursor: pointer;\n}\n.pw-inbox_item:hover .pw-inbox_item-remove {\n display: block;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-title {\n color: var(--textColor);\n font-weight: 700;\n}\n\n.pw-inbox_item.pw-new .pw-inbox_item-body {\n font-weight: 700;\n}\n\n.pw-inbox_list--empty {\n padding: 50px 16px;\n text-align: center;\n max-height: 100%;\n overflow: auto;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-icon {\n text-align: center;\n margin-bottom: 30px;\n}\n.pw-inbox_list--empty .pw-inbox_list-icon img {\n max-width: 100%;\n}\n\n.pw-inbox_list--empty .pw-inbox_list-title {\n font-size: 28px;\n line-height: 36px;\n color: var(--emptyInboxTitleColor);\n margin-bottom: 20px;\n}\n\n.pw-inbox_list--empty .ipw-inbox_list-body {\n font-size: 14px;\n line-height: 18px;\n color: var(--emptyInboxTextColor);\n}\n"),t}configureStyle(t){let e=t.toString();return xt.forEach((t=>{const i=new RegExp(`var\\(--${t.name}\\)`,"ig"),s=this.getStyleFormatter(t);e=e.replace(i,s)})),e}getStyleFormatter(t){switch(t.type){case"size":return`${this.config[t.name]||0}px`;case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return"transparent"===(e=this.config[t.name].toString())||_t.test(e)?e:"#333";default:return"none"}var e}renderWidgetInner(){if(this.messages.length>0)this.widget.classList.remove("pw-inbox-widget--empty"),this.widget.innerHTML=`\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_inner">\n <div class="pw-inbox_title">\n ${this.config.title}\n </div>\n <ul class="pw-inbox_list">\n\n </ul>\n</div>`,this.renderMessages();else{this.widget.classList.add("pw-inbox-widget--empty");const{emptyInboxTitle:t,emptyInboxText:e,emptyInboxIconUrl:i}=this.config;this.widget.innerHTML=((t,e,i)=>`\n<div class="pw-inbox__arrow"></div>\n<div class="pw-inbox_list--empty">\n <div class="pw-inbox_list-icon">\n <img src="${t}" alt="${e}">\n </div>\n <div class="pw-inbox_list-title">\n ${e}\n </div>\n <div class="ipw-inbox_list-body">\n ${i}\n </div>\n</div>`)(i,t,e)}}renderMessages(){this.list=this.widget.querySelector(".pw-inbox_list")||document.createElement("ul"),this.messages.forEach((t=>{const e=document.createElement("li");e.className="pw-inbox_item",e.classList.toggle("pw-new",!t.isRead),e.classList.toggle("pw-unread",!t.isActionPerformed),e.setAttribute("data-pw-inbox-message-id",t.code),e.innerHTML=St(t),this.list.appendChild(e),this.messagesElements[t.code]=e}))}updateCounter(t){this.count=t,this.trigger.setAttribute("data-pw-count",`${this.count}`),this.trigger.classList.toggle("pw-empty",0===this.count)}updateInboxMessages(t){this.messages=t.sort((({sendDate:t},{sendDate:e})=>function(t,e){const i=new Date(t),s=i.getHours()+i.getTimezoneOffset()/60,n=new Date(e),a=n.getHours()+n.getTimezoneOffset()/60;return i.setHours(s),n.setHours(a),n.getTime()-i.getTime()}(t,e))),this.renderWidgetInner()}openWidget(){this.isOpened=!0,this.widget.classList.add("pw-open"),document.addEventListener("click",this.onWidgetClickHandler),window.addEventListener("scroll",this.onWindowScrollHandler),window.addEventListener("resize",this.onWindowScrollHandler),this.markVisibleItemsAsRead(),this.messages.length>0&&this.list.addEventListener("scroll",this.markVisibleItemsAsRead),this.positionWidget()}closeWidget(){this.isOpened=!1,document.removeEventListener("click",this.onWidgetClickHandler),document.removeEventListener("click",this.onWindowScrollHandler),window.removeEventListener("resize",this.onWindowScrollHandler),this.updateReadStatus(),this.messages.length>0&&this.list.removeEventListener("scroll",this.markVisibleItemsAsRead),this.widget.classList.remove("pw-open","pw-top","pw-bottom","pw-right","pw-left"),this.widget.removeAttribute("style")}positionWidget(){this.isOpened&&(this.widgetParent===document.body?this.defaultPlaceWidget():this.customPlaceWidget())}customPlaceWidget(){const{position:t}=this.config;this.widgetParent.style.position="relative",this.widget.classList.add("pw-inbox-widget--inset"),this.widget.classList.add(`pw-${t}`)}defaultPlaceWidget(){const t=this.pw.inboxWidgetConfig.position?this.config.position:this.getDefaultPosition(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const i=Math.max(document.documentElement.clientWidth,window.innerWidth||0),s=Math.max(document.documentElement.clientHeight,window.innerHeight||0);switch(e.width+2*this.defaultMargin>i&&(this.widget.style.width=i-2*this.defaultMargin+"px"),e.height+24>s&&(this.widget.style.height=s-2*this.defaultMargin+"px"),t){case"top":this.alignWidgetTop();break;case"right":this.alignWidgetRight();break;case"left":this.alignWidgetLeft();break;case"bottom":this.alignWidgetBottom()}}alignWidgetTop(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const i=Math.max(document.documentElement.clientWidth,window.innerWidth||0),s=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-top");let n=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2);const a=n<pageXOffset,o=n+e.width>pageXOffset+i;a&&(n=pageXOffset+this.defaultMargin),o&&(n=pageXOffset+i-e.width-this.defaultMargin);const r=pageYOffset+t.top-e.height;this.alignWidgetElement(n,r),s.style.left=t.left+Math.floor(t.width/2)-n+"px";const c=this.widget.getBoundingClientRect().top;if(c<0){const t=this.widget.getBoundingClientRect().height+c-this.defaultMargin,e=this.widget.getBoundingClientRect().top-c+this.defaultMargin;this.widget.style.height=`${t}px`,this.widget.style.top=`${e}px`}}alignWidgetRight(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const i=Math.max(document.documentElement.clientWidth,window.innerWidth||0),s=Math.max(document.documentElement.clientHeight,window.innerHeight||0),n=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-right");let a=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2);const o=a<pageYOffset,r=pageYOffset+s<a+e.height;o&&(a=pageYOffset+this.defaultMargin),r&&(a=pageYOffset+s-e.height-this.defaultMargin);const c=pageXOffset+t.left+t.width;this.alignWidgetElement(c,a),n.style.top=t.top+Math.floor(t.height/2)-a+"px";const p=i-this.widget.getBoundingClientRect().right;if(p<this.defaultMargin){const t=this.widget.getBoundingClientRect().width+p-this.defaultMargin;this.widget.style.width=`${t}px`}}alignWidgetLeft(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const i=Math.max(document.documentElement.clientHeight,window.innerHeight||0),s=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-left");let n=pageYOffset+t.top+Math.floor(t.height/2)-Math.floor(e.height/2);const a=n<pageYOffset,o=pageYOffset+i<n+e.height;a&&(n=pageYOffset+this.defaultMargin),o&&(n=pageYOffset+i-e.height-this.defaultMargin);const r=pageXOffset+t.left-e.width;this.alignWidgetElement(r,n),s.style.top=t.top+Math.floor(t.height/2)-n+"px";const c=this.widget.getBoundingClientRect().left;if(c<0){const t=this.widget.getBoundingClientRect().width+c-this.defaultMargin,e=this.widget.getBoundingClientRect().left-c;this.widget.style.width=`${t}px`,this.widget.style.left=`${e}px`}}alignWidgetBottom(){const t=this.trigger.getBoundingClientRect(),e=this.widget.getBoundingClientRect();if(!document.documentElement)return;const i=Math.max(document.documentElement.clientWidth,window.innerWidth||0),s=Math.max(document.documentElement.clientHeight,window.innerHeight||0),n=this.widget.querySelector(".pw-inbox__arrow")||document.createElement("div");this.widget.classList.add("pw-bottom");let a=pageXOffset+t.left+Math.floor(t.width/2)-Math.floor(e.width/2);const o=a<pageXOffset,r=a+e.width>pageXOffset+i;o&&(a=pageXOffset+this.defaultMargin),r&&(a=pageXOffset+i-e.width-12);const c=pageYOffset+t.top+t.height;this.alignWidgetElement(a,c),n.style.left=t.left+Math.floor(t.width/2)-a+"px";const p=s-this.widget.getBoundingClientRect().bottom;if(p<this.defaultMargin){const t=this.widget.getBoundingClientRect().height+p-this.defaultMargin;this.widget.style.height=`${t}px`}}alignWidgetElement(t,e){this.widget.style.left=`${t}px`,this.widget.style.top=`${e}px`}getDefaultPosition(){const{left:t,top:e,width:i,height:s}=this.trigger.getBoundingClientRect();if(!document.documentElement)return"";const n={right:t,bottom:e,left:Math.max(document.documentElement.clientWidth,window.innerWidth||0)-(t+i),top:Math.max(document.documentElement.clientHeight,window.innerHeight||0)-(e+s)},a=Math.min(t,e,n.left,n.top);let o="bottom";return Object.keys(n).forEach((t=>{n[t]===a&&(o=t)})),o}addListeners(){this.trigger.addEventListener("click",this.onTriggerClickHandler),this.pw.push(["onPutNewMessageToInboxStore",()=>{this.updateInbox()}]),this.pw.push(["onUpdateInboxMessages",()=>{this.updateInbox()}])}markVisibleItemsAsRead(){if(0===this.messages.length)return;const t=this.list.clientHeight+this.list.scrollTop-50;Object.keys(this.messagesElements).forEach((e=>{if(!this.messagesElements[e]||this.messagesElements[e].offsetTop>t)return;const i=this.messages.find((t=>t.code===e));!i||i.isRead||this.readItems.indexOf(e)+1||this.readItems.push(e)}))}updateReadStatus(){this.pw.pwinbox.readMessagesWithCodes(this.readItems).then(this.updateInbox)}updateInbox(){this.pw.pwinbox.loadMessages().then((t=>{this.updateInboxMessages(t)})),this.pw.pwinbox.unreadMessagesCount().then((t=>{this.updateCounter(t)}))}performMessageAction(t){this.pw.pwinbox.performActionForMessageWithCode(t).then((()=>{this.updateInbox()}))}removeMessages(t){t.forEach((t=>{this.readItems=this.readItems.slice(this.readItems.indexOf(t),1)})),this.pw.pwinbox.deleteMessagesWithCodes(t).then((()=>{this.updateInbox()}))}onTriggerClickHandler(t){t.stopPropagation(),t.target&&this.toggle()}onWidgetClickHandler(t){if(!t.target)return;const e=t.target.closest(".pw-inbox_item");if(!e)return void this.toggle();const i=e.getAttribute("data-pw-inbox-message-id");if(!i)return;t.target.closest(".pw-inbox_item-remove")?this.removeMessages([i]):this.performMessageAction(i)}onWindowScrollHandler(){this.isFixed&&this.isOpened?this.toggle():this.positionWidget()}}const Et="bottomRight",Tt="bottomLeft",Pt="topRight",It="topLeft",Mt={position:Tt,bgColor:"#12AE7E",bellColor:"white",bellStrokeColor:"#08754f",bellButtonBorder:"1px solid #379676",shadow:"0px 0px 6px rgba(0, 0, 0, 0.75)",size:"48px",indent:"20px",zIndex:"999999",tooltipText:{successSubscribe:"You are successfully subscribed!",needSubscribe:"Get notifications about important news!",blockSubscribe:"Click to see how to get notifications",alreadySubscribed:"You are already subscribed"}};class Bt{static getBellPosition(t,e){let i;switch(t){case Et:i={top:"auto",left:"auto",bottom:e,right:e};break;case Tt:i={top:"auto",left:e,bottom:e,right:"auto"};break;case It:i={top:e,left:e,bottom:"auto",right:"auto"};break;case Pt:i={top:e,left:"auto",bottom:"auto",right:e};break;default:i={top:"auto",left:"auto",bottom:e,right:e}}return i}static getTooltipPosition(t,e){let i,s;const n=parseInt(e)+12+"px";switch(t){case Et:i={right:n},s="right";break;case Tt:case It:i={left:n},s="left";break;default:i={right:n},s="right"}return[i,s]}static getPopoverPosition(t,e){let i,s;const n=parseInt(e)+15+"px";switch(t){case Et:i={bottom:n,right:"0",left:"auto",top:"auto"},s="bottom";break;case Tt:i={bottom:n,left:"0",right:"auto",top:"auto"},s="bottom";break;case It:i={top:n,left:"0",right:"auto",bottom:"auto"},s="top";break;case Pt:i={top:n,right:"0",left:"auto",bottom:"auto"},s="top";break;default:i={bottom:n,right:"0",left:"auto",top:"auto"},s="bottom"}return[i,s]}static getPopoverArrowPosition(t,e){let i;switch(t){case Et:i="\n.pushwoosh-subscribe-widget__popover__bottom:after {left: auto; right: "+(parseInt(e)/2-4+"px");break;case Tt:i="\n.pushwoosh-subscribe-widget__popover__bottom:after {right: auto; left: "+(parseInt(e)/2-12+"px");break;case It:i="\n.pushwoosh-subscribe-widget__popover__top:after {right: auto; left: "+(parseInt(e)/2-12+"px");break;case Pt:i="\n.pushwoosh-subscribe-widget__popover__top:after {left: auto; right: "+(parseInt(e)/2-4+"px");break;default:i="\n.pushwoosh-subscribe-widget__popover__bottom:after {left: auto; right: "+(parseInt(e)/2-4+"px")}return i}}class Dt{constructor(t){if(this.pw=t,!bt.isAvailableNotifications)return void console.warn("Browser does not support push notifications");this.clickBell=this.clickBell.bind(this),this.onSubscribeEvent=this.onSubscribeEvent.bind(this),this.onUnsubscribeEvent=this.onUnsubscribeEvent.bind(this),this.onPermissionDeniedEvent=this.onPermissionDeniedEvent.bind(this),this.clickOutOfPopover=this.clickOutOfPopover.bind(this);const e=Object.assign(Mt.tooltipText,t.subscribeWidgetConfig.tooltipText);this.config=Object.assign({},Mt,t.subscribeWidgetConfig),this.config.tooltipText=e,t.isSubscribed().then((t=>{t||this.render()}))}addStylesToElement(t,e){Object.keys(t).forEach((i=>{e.style[i]=t[i]}))}createContainer(){const t=document.createElement("div");t.id="pushwooshBellWidget",t.className="pushwoosh-subscribe-widget";const e=Bt.getBellPosition(this.config.position,this.config.indent),i=Object.assign({zIndex:this.config.zIndex},e);return this.addStylesToElement(i,t),t}createStyle(){const t=document.createElement("style");return t.innerHTML='/* Widget */\n.pushwoosh-subscribe-widget {\n position: fixed;\n display: block;\n transform: translate3d(0, 0, 0);\n}\n\n.pushwoosh-subscribe-widget__subscribed {\n display: none;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__bell-button {\n border-radius: 50%;\n cursor: pointer;\n font-size: 0;\n text-align: center;\n transform: scale(0.9) translate3d(0, 0, 0);\n transition: transform .3s ease-in-out;\n position: relative;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__bell-button:hover {\n transform: scale(1);\n}\n\n/* Tooltip */\n.pushwoosh-subscribe-widget__tooltip {\n position: absolute;\n height: 48px;\n max-width: 300px;\n min-width: 200px;\n padding: 5px 7px;\n background-color: #3b444b;\n color: #ffffff;\n text-align: center;\n vertical-align: middle;\n box-sizing: border-box;\n line-height: 38px;\n font-size: 0;\n font-weight: normal;\n visibility: hidden;\n opacity: 0;\n transition: visibility 0s ease-in .3s,\n opacity .3s ease-in;\n top: 50%;\n transform: translate(0, -50%);\n box-shadow: 1px 1px 5px 0 rgba(0,0,0,0.5);\n}\n\n.pushwoosh-subscribe-widget__tooltip__right:after,\n.pushwoosh-subscribe-widget__tooltip__left:after {\n content: "";\n top: 50%;\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n border-top: 5px solid transparent;\n border-bottom: 5px solid transparent;\n background: #3b444b;\n}\n\n.pushwoosh-subscribe-widget__tooltip__right:after {\n left: calc(100% - 7px);\n border-top: 5px solid #3b444b;\n border-left: 5px solid #3b444b;\n border-right: 5px solid transparent;\n box-sizing: border-box;\n transform-origin: 0 0;\n transform: rotate(-45deg);\n box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.25);\n}\n\n.pushwoosh-subscribe-widget__tooltip__left:after {\n left: -7px;\n border-top: 5px solid #3b444b;\n border-right: 5px solid #3b444b;\n border-left: 5px solid transparent;\n box-sizing: border-box;\n transform-origin: 0 0;\n transform: rotate(-45deg);\n box-shadow: -2px -2px 2px 0 rgba(0, 0, 0, 0.25);\n}\n\n.pushwoosh-subscribe-widget__bell-button:hover + .pushwoosh-subscribe-widget__tooltip,\n.pushwoosh-subscribe-widget__tooltip.pushwoosh-subscribe-widget__tooltip__visible {\n display: block;\n visibility: visible;\n opacity: 1;\n transition-delay: 0s;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__tooltip-content {\n display: inline-block;\n vertical-align: middle;\n font-size: 14px;\n line-height: 1.4;\n white-space: nowrap;\n overflow: hidden;\n padding-right: 5px;\n text-overflow: ellipsis;\n max-width: 100%;\n}\n\n/* Popover */\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover {\n position: absolute;\n right: auto;\n box-shadow: 1px 1px 5px 0 rgba(0, 0, 0, 0.5);\n box-sizing: border-box;\n background: #9ca8b1;\n visibility: hidden;\n opacity: 0;\n transition: visibility 0s ease-in .5s,\n opacity .5s ease-in;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover__visible {\n display: block;\n visibility: visible;\n opacity: 1;\n transition-delay: 0s;\n}\n\n.pushwoosh-subscribe-widget__popover__bottom:after,\n.pushwoosh-subscribe-widget__popover__top:after {\n content: "";\n height: 0;\n width: 0;\n position: absolute;\n pointer-events: none;\n border-right: 8px solid transparent;\n border-left: 8px solid #9ca8b1;\n background: #9ca8b1;\n transform-origin: 0 0;\n transform: rotate(-45deg);\n}\n\n.pushwoosh-subscribe-widget__popover__bottom:after {\n border-bottom: 8px solid #9ca8b1;\n border-top: 8px solid transparent;\n box-sizing: border-box;\n box-shadow: -2px 2px 1px 0 rgba(0, 0, 0, 0.25);\n bottom: -16px;\n}\n\n.pushwoosh-subscribe-widget__popover__top:after {\n top: 0;\n border-top: 8px solid #9ca8b1;\n border-bottom: 8px solid transparent;\n box-sizing: border-box;\n box-shadow: 1px -1px 1px 0 rgba(0, 0, 0, 0.25);\n}\n\n.pushwoosh-subscribe-widget__popover-content-wrapper {\n overflow: auto;\n max-width: 100%;\n}\n\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover-content {\n display: flex;\n flex-direction: column;\n padding: 14px;\n box-sizing: border-box;\n float: left;\n min-width: 100%;\n align-items: center;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img {\n display: block;\n}\n\n.pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img:first-child {\n margin-bottom: 14px;\n}\n\n@media (max-width: 767px) and (orientation: portrait) {\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover-content {\n flex-direction: column;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img {\n max-width: 280px;\n height: auto;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img:first-child {\n margin-right: 0;\n margin-bottom: 14px;\n }\n}\n@media (max-width: 767px) and (orientation: landscape) {\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover-content {\n flex-direction: row;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img {\n max-width: 280px;\n height: auto;\n }\n .pushwoosh-subscribe-widget .pushwoosh-subscribe-widget__popover img:first-child {\n margin-right: 14px;\n margin-bottom: 0;\n }\n}\n',t}createBell(){const{config:t}=this;let e;var i,s;return t.buttonImage?(e=document.createElement("img"),e.src=t.buttonImage):(e=document.createElement("div"),this.addStylesToElement({backgroundColor:t.bgColor,boxShadow:t.shadow,lineHeight:t.size,border:t.bellButtonBorder},e),e.innerHTML=(i=t.bellColor,s=t.bellStrokeColor,`<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:cc="http://creativecommons.org/ns#"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:svg="http://www.w3.org/2000/svg"\n xmlns="http://www.w3.org/2000/svg"\n xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n version="1.1"\n id="Capa_1"\n x="0px"\n y="0px"\n viewBox="0 0 346.013 346.013"\n style="enable-background:new 0 0 346.013 346.013;width: 80%; height: auto; vertical-align: middle;"\n xml:space="preserve"\n inkscape:version="0.91 r13725"\n sodipodi:docname="alarm_white.svg"><metadata\n id="metadata51"><rdf:RDF><cc:Work\n rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type\n rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs\n id="defs49" /><sodipodi:namedview\n borderopacity="1"\n objecttolerance="10"\n gridtolerance="10"\n guidetolerance="10"\n inkscape:pageopacity="0"\n inkscape:pageshadow="2"\n inkscape:window-width="1618"\n inkscape:window-height="828"\n id="namedview47"\n showgrid="false"\n inkscape:zoom="0.6820553"\n inkscape:cx="173.0065"\n inkscape:cy="173.0065"\n inkscape:window-x="0"\n inkscape:window-y="0"\n inkscape:window-maximized="0"\n inkscape:current-layer="g3" /><g\n id="g3"><path\n d="m 256.76227,220.19006 c -1.77513,-2.69766 -3.45154,-5.24564 -3.98966,-7.46382 -0.042,-0.17861 -0.0911,-0.36128 -0.16237,-0.61436 -2.28354,-7.67647 0.69147,-24.43921 2.46886,-34.45124 0.26788,-1.50394 0.52274,-2.94197 0.75286,-4.29035 0.0232,-0.13675 0.044,-0.27211 0.0724,-0.48006 1.95582,-15.28051 2.58811,-37.91956 -5.51044,-58.99147 -5.6032,-14.57978 -14.45978,-25.82612 -26.3559,-33.48393 1.26598,-9.812938 -4.85967,-19.343691 -14.66682,-22.0511 -9.80715,-2.70741 -19.95724,2.33226 -23.90298,11.405413 -14.1382,0.467533 -27.51111,5.577097 -39.80114,15.219267 -17.76129,13.9298 -28.83431,33.68757 -34.99389,47.80757 l -0.0479,0.11335 c -0.0512,0.12175 -0.0998,0.24114 -0.13249,0.32962 -0.49733,1.28292 -1.01552,2.64514 -1.55689,4.07255 -3.61311,9.51043 -9.66004,25.42824 -15.611995,30.89342 -0.106524,0.10027 -0.208228,0.20187 -0.362362,0.35435 -1.636243,1.66563 -4.382941,2.99463 -7.288979,4.40101 -7.145531,3.45301 -22.013613,10.64166 -17.206389,31.67844 0.929154,4.07105 4.008437,7.29057 8.033861,8.40185 l 167.570804,46.2604 c 4.02253,1.11048 8.31521,-0.0729 11.2052,-3.08958 14.91617,-15.58874 5.84693,-29.38668 1.48625,-36.02133 z"\n id="path5"\n inkscape:connector-curvature="0"\n vector-effect="non-scaling-stroke"\n style="fill:${i}; stroke: ${s}; stroke-width: 1; " /><path\n vector-effect="non-scaling-stroke"\n d="m 174.26737,259.72378 -38.76399,-10.70137 c -1.59243,-0.43962 -3.28183,-0.15596 -4.63548,0.7754 -2.53909,1.7494 -2.84182,4.93159 -3.02304,6.83188 l -0.0151,0.15247 c -1.22819,12.67106 6.79854,24.33046 19.08688,27.72284 12.51583,3.45518 25.8324,-2.91586 30.9681,-14.80385 l 0.0935,-0.19205 c 0.52305,-1.06418 1.74613,-3.55554 0.50882,-6.31116 -0.44302,-0.98439 -1.5794,-2.74529 -4.21964,-3.47416 z"\n id="path7"\n inkscape:connector-curvature="0"\n style="fill:${i}; stroke: ${s}; stroke-width: 1;" /></g><g\n id="g17" /><g\n id="g19" /><g\n id="g21" /><g\n id="g23" /><g\n id="g25" /><g\n id="g27" /><g\n id="g29" /><g\n id="g31" /><g\n id="g33" /><g\n id="g35" /><g\n id="g37" /><g\n id="g39" /><g\n id="g41" /><g\n id="g43" /><g\n id="g45" /></svg>`)),this.addStylesToElement({width:t.size,height:t.size},e),e.className="pushwoosh-subscribe-widget__bell-button",e}async createTooltip(){const t=document.createElement("div"),[e,i]=Bt.getTooltipPosition(this.config.position,this.config.size);return t.className=`pushwoosh-subscribe-widget__tooltip pushwoosh-subscribe-widget__tooltip__${i}`,this.addStylesToElement(e,t),t.appendChild(await this.createTooltipContent()),t}async createTooltipContent(){const t=document.createElement("div");return t.innerText=await this.tooltipTextFactory(),t.className="pushwoosh-subscribe-widget__tooltip-content",t}async tooltipTextFactory(){const t=await this.pw.driver.getPermission(),{tooltipText:e}=this.config,i=await tt.get("MANUAL_UNSUBSCRIBE");switch(t){case l:return i?e.needSubscribe:e.alreadySubscribed;case u:return e.needSubscribe;case h:return e.blockSubscribe;default:return e.needSubscribe}}createPopover(){const t=document.createElement("div"),e=document.createElement("div"),[i,s]=Bt.getPopoverPosition(this.config.position,this.config.size);e.className=`pushwoosh-subscribe-widget__popover pushwoosh-subscribe-widget__popover__${s}`,t.className="pushwoosh-subscribe-widget__popover-content-wrapper",this.style.innerHTML+=Bt.getPopoverArrowPosition(this.config.position,this.config.size);const n=Object.assign({maxWidth:`calc(100vw - ${this.config.indent} - ${this.config.indent})`},i);return this.addStylesToElement(n,e),t.appendChild(this.createPopoverContent()),e.appendChild(t),e}getBrowserName(){let t;return t=bt.isOpera?"opera":11===bt.platform&&navigator.userAgent.match(/Android/i)?"mobileChrome":12===bt.platform?"firefox":10===bt.platform?"safari":150===bt.platform?"edge":"chrome",t}createPopoverContent(){const{config:t}=this,e=document.createElement("div");e.className="pushwoosh-subscribe-widget__popover-content";const i=this.getBrowserName(),s=t.contentImages&&t.contentImages[i];if(s){const t=document.createElement("img");t.src=s,e.appendChild(t)}else{const t={opera:"opera",mobileChrome:"mobile_chrome",firefox:"FF",safari:"safari"}[i]||"chrome";[{src:this.getImageSrc(t),width:500,height:130},{src:this.getImageSrc(`${t}_unlock`),width:500,height:230}].forEach((t=>{const i=document.createElement("img");Object.assign(i,t),e.appendChild(i)}))}return e}getImageSrc(t){return`https://cdn.pushwoosh.com/webpush/img/${t}.jpg`}async render(){this.widget=this.createContainer(),this.style=this.createStyle();const t=this.createBell();this.tooltip=await this.createTooltip(),this.popover=await this.createPopover(),this.widget.appendChild(this.style),this.widget.appendChild(t),this.widget.appendChild(this.tooltip),this.widget.appendChild(this.popover),document.body.appendChild(this.widget),this.pw.push(["onSubscribe",this.onSubscribeEvent]),this.pw.push(["onUnsubscribe",this.onUnsubscribeEvent]),this.pw.push(["onPermissionDenied",this.onPermissionDeniedEvent]),this.addEventListeners()}addEventListeners(){this.widget.addEventListener("click",this.clickBell),window.addEventListener("click",this.clickOutOfPopover)}toggleHelpPopover(){this.popover.classList.toggle("pushwoosh-subscribe-widget__popover__visible")}async clickBell(){switch(this.pw.driver.getPermission()){case l:case u:await this.pw.subscribe();break;case h:this.toggleHelpPopover();break;default:console.warn("Unknown browser notification permission")}}async onSubscribeEvent(){const t=this.tooltip.querySelector("div");null!==t&&(t.innerText=this.config.tooltipText.successSubscribe,this.tooltip.classList.add("pushwoosh-subscribe-widget__tooltip__visible"),setTimeout((async()=>{this.tooltip.classList.remove("pushwoosh-subscribe-widget__tooltip__visible"),t.innerText=await this.tooltipTextFactory(),this.widget.classList.add("pushwoosh-subscribe-widget__subscribed")}),2e3))}async onPermissionDeniedEvent(){this.addEventListeners();const t=this.tooltip.querySelector("div");null!==t&&(t.innerText=await this.tooltipTextFactory())}clickOutOfPopover(t){this.popover.classList.contains("pushwoosh-subscribe-widget__popover__visible")&&!t.target.classList.contains("pushwoosh-subscribe-widget__popover")&&null===t.target.closest(".pushwoosh-subscribe-widget__popover")&&!t.target.classList.contains("pushwoosh-subscribe-widget__bell-button")&&null===t.target.closest(".pushwoosh-subscribe-widget__bell-button")&&this.popover.classList.remove("pushwoosh-subscribe-widget__popover__visible")}async onUnsubscribeEvent(){const t=this.tooltip.querySelector("div");null!==t&&(t.innerText=await this.tooltipTextFactory())}}const Wt={text:"Don’t miss out on our news and updates! Enable push notifications",askLaterButtonText:"Not now",confirmSubscriptionButtonText:"Subscribe",delay:5,retryOffset:604800,overlay:!1,position:"top",mobileViewMargin:"0",bgColor:"#fff",borderColor:"transparent",boxShadow:"0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)",textColor:"#000",textSize:"inherit",textWeight:"normal",fontFamily:"inherit",subscribeBtnBgColor:"#4285f4",subscribeBtnTextColor:"#fff",subscribeBtnTextWeight:"normal",subscribeBtnBorderColor:"transparent",subscribeBtnBorderRadius:"2px",askLaterBtnBgColor:"transparent",askLaterBtnTextColor:"#000",askLaterBtnTextWeight:"normal",askLaterBtnBorderColor:"transparent",askLaterBtnBorderRadius:"2px",theme:"material",viewport:"html"},Rt=/^(#([\da-f]{3}){1,2}$|(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0?\.\d+)\)$|(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/,At=[{name:"mobileViewMargin",type:"string"},{name:"mobileViewPosition",type:"string"},{name:"mobileViewTransition",type:"string"},{name:"bgColor",type:"color"},{name:"borderColor",type:"color"},{name:"boxShadow",type:"string"},{name:"textColor",type:"color"},{name:"textSize",type:"string"},{name:"textWeight",type:"string"},{name:"fontFamily",type:"string"},{name:"subscribeBtnBgColor",type:"color"},{name:"subscribeBtnTextColor",type:"color"},{name:"subscribeBtnTextWeight",type:"string"},{name:"subscribeBtnBorderColor",type:"color"},{name:"subscribeBtnBorderRadius",type:"string"},{name:"askLaterBtnBgColor",type:"color"},{name:"askLaterBtnTextColor",type:"color"},{name:"askLaterBtnTextWeight",type:"string"},{name:"askLaterBtnBorderColor",type:"color"},{name:"askLaterBtnBorderRadius",type:"string"}];class Lt{constructor(t){this.pw=t;const{mobileViewMargin:e=""}=t.subscribePopupConfig||{};this.config={...Wt,...this.pw.subscribePopupConfig,mobileViewTransition:e?"none":"bottom .4s ease-out",mobileViewPosition:e?"auto!important":"auto"},this.onAskLaterClick=this.onAskLaterClick.bind(this),this.onSubscribeClick=this.onSubscribeClick.bind(this)}async initPopup(){const t=await this.pw.isSubscribed(),e=await this.pw.data.getStatusManualUnsubscribed();if(t||e)return;const i=await this.pw.driver.getPermission();if("granted"===i||"denied"===i)return;this.renderPopup(),this.appendStyles();const s=localStorage.getItem("LAST_OPEN_SUBSCRIPTION_POPUP"),n=s?parseInt(s):0,a=(new Date).getTime();n+1e3*this.config.retryOffset<a&&!this.config.manualToggle&&setTimeout((()=>{this.toggle(!0)}),1e3*this.config.delay)}toggle(t){("boolean"==typeof t?t:!this.isShown)?(this.showPopup(),this.pw.eventBus.dispatchEvent("subscribe-popup-show",{})):(this.closePopup(),this.pw.eventBus.dispatchEvent("subscribe-popup-hide",{}))}showPopup(){this.isShown=!0,this.popup.classList.add("pw-show"),document.body.classList.add("pw-popup-opened");const t=new CustomEvent("showPopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);if(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)return;const{theme:e,viewport:i,position:s}=this.config;if("topbar"===e&&"top"===s){const t=document.querySelector(i)||document.createElement("div"),e=window.getComputedStyle(t).marginTop||"0";t.style.transition="margin-top .3s ease-out",t.style.marginTop=`${parseInt(e)+this.popup.getBoundingClientRect().height}px`}}closePopup(){this.isShown=!1,this.popup.classList.remove("pw-show"),document.body.classList.remove("pw-popup-opened");const t=new CustomEvent("hidePopup",{bubbles:!1,cancelable:!1,detail:{popup:this.popup}});this.popup.dispatchEvent(t);const e=(new Date).getTime().toString();localStorage.setItem("LAST_OPEN_SUBSCRIPTION_POPUP",e);if(Math.max(document.documentElement.clientWidth,window.innerWidth||0)<541)return;const{theme:i,viewport:s,position:n}=this.config;if("topbar"===i&&"top"===n){const t=document.querySelector(s)||document.createElement("div"),e=window.getComputedStyle(t).marginTop||"0";t.style.marginTop=parseInt(e)-this.popup.getBoundingClientRect().height+"px"}}renderPopup(){this.popup=document.createElement("div"),this.popup.id="pwSubscribePopup";const{text:t,askLaterButtonText:e,confirmSubscriptionButtonText:i,iconUrl:s,iconAlt:n,position:a,overlay:o,theme:r}=this.config;this.popup.className=`pw-subscribe-popup pw-position-${a} pw-subscribe-popup-${r}`,this.popup.classList.toggle("pw-subscribe-popup__overlay",o),this.popup.innerHTML=(({iconUrl:t,iconAlt:e,text:i,askLaterButtonText:s,confirmSubscriptionButtonText:n})=>`<div class="pw-subscription-popup-inner">\n <div class="pw-subscription-popup-content">\n ${t?`<div class="pw-subscription-popup-icon"><img src="${t}" alt="${e||"Subscribe"}"></div>`:""}\n <div class="pw-subscription-popup-text">\n ${i}\n </div>\n </div>\n <div class="pw-subscription-popup-controls">\n <button name="pwAskLater" class="pw-subscribe-popup-button">${s}</button>\n <button name="pwSubscribe" class="pw-subscribe-popup-button pw-subscribe-popup-button-active">${n}</button>\n </div>\n </div>`)({text:t,askLaterButtonText:e,confirmSubscriptionButtonText:i,iconUrl:s,iconAlt:n}),document.body.appendChild(this.popup),this.addListeners()}appendStyles(){const t=document.createElement("style");t.innerHTML=this.configureStyle(".pw-subscribe-popup {\n position: fixed;\n left: 50%;\n transform: translateX(-50%);\n justify-content: center;\n z-index: 1000000;\n display: flex;\n transition: all .4s ease-out;\n}\n\n.pw-subscribe-popup.pw-position-top {\n top: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-top.pw-show {\n top: 0;\n}\n\n.pw-subscribe-popup.pw-position-bottom {\n bottom: calc(-100% - 24px);\n}\n.pw-subscribe-popup.pw-position-bottom.pw-show {\n bottom: 0;\n}\n\n.pw-subscribe-popup.pw-position-center {\n display: flex;\n\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n justify-content: center;\n align-items: center;\n\n transform: none;\n}\n\n.pw-subscribe-popup__overlay {\n background: rgba(0,0,0,.4);\n z-index: 1000000;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-subscribe-popup__overlay) {\n pointer-events: none;\n}\n\n.pw-subscribe-popup.pw-position-center:not(.pw-show) {\n display: none;\n}\n\n\n.pw-subscribe-popup__overlay.pw-position-top {\n align-items: flex-start;\n}\n\n.pw-subscribe-popup__overlay.pw-position-bottom {\n align-items: flex-end;\n}\n\n.pw-subscribe-popup__overlay.pw-position-center {\n align-items: center;\n}\n\n.pw-subscription-popup-inner {\n max-width: 400px;\n font-size: var(--textSize);\n color: var(--textColor);\n font-weight: var(--textWeight);\n font-family: var(--fontFamily);\n border-style: solid;\n border-width: 1px;\n border-color: var(--borderColor);\n background: var(--bgColor);\n box-shadow: var(--boxShadow);\n pointer-events: auto;\n}\n\n.pw-subscription-popup-content {\n padding: 16px 16px 4px;\n display: flex;\n justify-content: stretch;\n}\n\n.pw-subscription-popup-icon {\n flex: 0 0 50px;\n margin-right: 12px;\n padding-top: 4px;\n}\n\n.pw-subscription-popup-icon img {\n max-width: 60px;\n max-height: 60px;\n}\n\n.pw-subscription-popup-text {\n flex: 1 1 300px;\n}\n\n.pw-subscription-popup-controls {\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n padding: 8px 16px 16px;\n}\n\nbutton.pw-subscribe-popup-button {\n border: solid 1px var(--askLaterBtnBorderColor);\n border-radius: var(--askLaterBtnBorderRadius);\n display: inline-block;\n height: 36px;\n line-height: 36px;\n padding: 0 16px;\n text-transform: uppercase;\n font-weight: var(--askLaterBtnTextWeight);\n vertical-align: middle;\n -webkit-tap-highlight-color: transparent;\n font-size: 14px;\n outline: 0;\n text-decoration: none;\n color: var(--askLaterBtnTextColor);\n text-align: center;\n letter-spacing: .5px;\n cursor: pointer;\n background: var(--askLaterBtnBgColor);\n margin: 4px 8px;\n}\nbutton.pw-subscribe-popup-button:hover {\n background: rgba(0,0,0,.04);\n}\nbutton.pw-subscribe-popup-button:active {\n background: rgba(0,0,0,.12);\n}\n\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active {\n color: var(--subscribeBtnTextColor);\n background: var(--subscribeBtnBgColor);\n border-radius: var(--subscribeBtnBorderRadius);\n border: solid 1px var(--subscribeBtnBorderColor);\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n font-weight: var(--subscribeBtnTextWeight);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:hover {\n box-shadow: 0 3px 3px 0 rgba(0,0,0,0.14),\n 0 1px 7px 0 rgba(0,0,0,0.12),\n 0 3px 1px -1px rgba(0,0,0,0.2);\n}\nbutton.pw-subscribe-popup-button.pw-subscribe-popup-button-active:active {\n box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14),\n 0 3px 1px -2px rgba(0,0,0,0.12),\n 0 1px 5px 0 rgba(0,0,0,0.2);\n}\n\n@media screen and (min-width: 541px) {\n\n .pw-subscribe-popup-topbar {\n width: 100%;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n display: flex;\n flex-direction: row;\n padding: 2px 40px;\n justify-content: center;\n align-items: center;\n flex-wrap: nowrap;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-content {\n padding: 0;\n justify-content: flex-start;\n align-items: center;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-icon img {\n max-width: 28px;\n max-height: 28px;\n }\n\n .pw-subscribe-popup-topbar button.pw-subscribe-popup-button {\n height: 32px;\n line-height: 32px;\n }\n\n .pw-subscribe-popup-topbar .pw-subscription-popup-controls {\n padding: 0 0 0 16px;\n align-items: center;\n }\n}\n@media screen and (max-width: 540px) {\n .pw-subscribe-popup,\n .pw-subscribe-popup.pw-position-top,\n .pw-subscribe-popup.pw-position-center,\n .pw-subscribe-popup.pw-position-bottom {\n top: var(--mobileViewPosition);\n bottom: -110%;\n left: 0;\n right: 0;\n transform: none;\n display: flex;\n transition: var(--mobileViewTransition);\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-subscribe-popup__overlay {\n align-items: flex-end;\n }\n\n .pw-subscribe-popup.pw-show {\n bottom: var(--mobileViewMargin);\n }\n\n .pw-subscribe-popup__overlay .pw-subscription-popup-inner {\n align-items: flex-end;\n justify-content: stretch;\n }\n\n .pw-subscription-popup-inner {\n max-width: 100%;\n width: 100%;\n }\n}\n"),document.body.appendChild(t)}getStyleFormatter(t){switch(t.type){case"size":return`${this.config[t.name]||0}px`;case"number":return parseFloat(this.config[t.name].toString()).toString();case"string":return this.config[t.name].toString();case"color":return"transparent"===(e=this.config[t.name].toString())||Rt.test(e)?e:"#333";default:return"none"}var e}configureStyle(t){let e=t.toString();return At.forEach((t=>{const i=new RegExp(`var\\(--${t.name}\\)`,"ig"),s=this.getStyleFormatter(t);e=e.replace(i,s)})),e}addListeners(){const t=this.popup.querySelector('button[name="pwAskLater"]')||document.createElement("button"),e=this.popup.querySelector('button[name="pwSubscribe"]')||document.createElement("button");t.addEventListener("click",this.onAskLaterClick),e.addEventListener("click",this.onSubscribeClick)}onAskLaterClick(){this.toggle(!1),this.pw.eventBus.dispatchEvent("subscribe-popup-decline",{})}onSubscribeClick(){this.toggle(!1),this.pw.eventBus.dispatchEvent("subscribe-popup-accept",{}),this.pw.subscribe()}}return document.addEventListener("pushwoosh.initialized",(t=>{if(t.detail.pw.subscribeWidgetConfig.enable&&new Dt(t.detail.pw),t.detail.pw.subscribePopupConfig&&t.detail.pw.subscribePopupConfig.enable){const e=new Lt(t.detail.pw);e.initPopup().then((()=>{t.detail.pw.subscribePopup=e}))}t.detail.pw.pwinbox&&t.detail.pw.inboxWidgetConfig.enable&&(t.detail.pw.pwinboxWidget=new kt(t.detail.pw))})),e})()));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|