"use strict";(this.webpackChunk=this.webpackChunk||[]).push([[761],{80761:function(i,e,t){t.r(e),t.d(e,{default:function(){return d}});var r=t(53774),n=t(72893),s=t(63552),o=t(52367),a=t(45966),u=t(17615),c=t(75319),h=t(74556);class p{constructor(i,e,t,r,n,s,o,a,u,c){this.qi=i,this.Ji=e,this.Qi=t,this.Zi=r+"/safari/"+e,this.Sr=n||"/service-worker.js",this._r=s,this.gt=o,this.Ur=a||!1,this.Wr=u||!1,this.h=c,this.Nr=h.Z.Ir(),this.Vr=h.Z.Cr()}Er(){return this.Wr}Or(i,e,t,r,n){i.unsubscribe().then((i=>{i?this.Br(e,t,r,n):(o.Z.D.error("Failed to unsubscribe device from push."),"function"==typeof n&&n(!1))})).catch((i=>{o.Z.D.error("Push unsubscription error: "+i),"function"==typeof n&&n(!1)}))}Mr(i,e,t){const r=(i=>{if("string"==typeof i)return i;if(0!==i.endpoint.indexOf("https://android.googleapis.com/gcm/send"))return i.endpoint;let e=i.endpoint;return i.Yr&&-1===i.endpoint.indexOf(i.Yr)&&(e=i.endpoint+"/"+i.Yr),e})(i);let n=null,s=null;if(null!=i.getKey)try{n=btoa(String.fromCharCode.apply(null,new Uint8Array(i.getKey("p256dh")))),s=btoa(String.fromCharCode.apply(null,new Uint8Array(i.getKey("auth"))))}catch(i){if("invalid arguments"!==i.message)throw i}const o=(i=>{let e;return i.options&&(e=i.options.applicationServerKey)&&e.byteLength&&e.byteLength>0?btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_"):null})(i);this.qi.Gr(r,t,n,s,o),r&&"function"==typeof e&&e(r,n,s)}Hr(){this.qi.Jr(!0)}Kr(i,e){this.qi.Jr(!1),o.Z.D.info(i),"function"==typeof e&&e(!1)}Lr(i,e,t,r){if("default"===e.permission)try{window.safari.pushNotification.requestPermission(this.Zi,i,{api_key:this.Ji,device_id:this.Qi.te().id},(e=>{"granted"===e.permission&&this.qi.setPushNotificationSubscriptionType(u.Z.NotificationSubscriptionTypes.OPTED_IN),this.Lr(i,e,t,r)}))}catch(i){this.Kr("Could not request permission for push: "+i,r)}else"denied"===e.permission?this.Kr("The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",r):"granted"===e.permission&&(o.Z.D.info("Device successfully subscribed to push."),this.Mr(e.deviceToken,t,new Date))}Qr(i,e,t){const r=r=>{switch(r){case"granted":return void("function"==typeof i&&i());case"default":return void("function"==typeof e&&e());case"denied":return void("function"==typeof t&&t());default:o.Z.D.error("Received unexpected permission result "+r)}};let n=!1;const s=window.Notification.requestPermission((i=>{n&&r(i)}));s?s.then((i=>{r(i)})):n=!0}Br(i,e,t,r){const n={userVisibleOnly:!0};null!=e&&(n.applicationServerKey=e),i.pushManager.subscribe(n).then((i=>{o.Z.D.info("Device successfully subscribed to push."),this.Mr(i,t,new Date)})).catch((i=>{h.Z.isPushBlocked()?(o.Z.D.info("Permission for push notifications was denied."),"function"==typeof r&&r(!1)):o.Z.D.error("Push subscription failed: "+i)}))}Xr(){return this.Ur?("undefined"!==typeof navigator?navigator:{userAgent:""}).serviceWorker.getRegistration():("undefined"!==typeof navigator?navigator:{userAgent:""}).serviceWorker.register(this.Sr).then((()=>("undefined"!==typeof navigator?navigator:{userAgent:""}).serviceWorker.ready.then((i=>(i&&"function"==typeof i.update&&i.update().catch((i=>{o.Z.D.info("ServiceWorker update failed: "+i)})),i)))))}Zr(i){this.Ur||(i.unregister(),o.Z.D.info("Service worker successfully unregistered."))}subscribe(i,e){if(h.Z.isPushSupported()){if(this.Nr){if(!this.Ur&&null!=window.location){let i=this.Sr;-1===i.indexOf(window.location.host)&&(i=window.location.host+i),-1===i.indexOf(window.location.protocol)&&(i=window.location.protocol+"//"+i);const e=i.substr(0,i.lastIndexOf("/")+1);if(0!==c.SD.hn().indexOf(e))return void o.Z.D.error("Cannot subscribe to push from a path higher than the service worker location (tried to subscribe from "+window.location.pathname+" but service worker is at "+i+")")}if(h.Z.isPushBlocked())return void this.Kr("Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",e);if(this.gt&&!this.gt.fn()&&0===this.gt.Zs())return o.Z.D.info("Waiting for VAPID key from server config before subscribing to push."),void this.gt.dn((()=>{this.subscribe(i,e)}));const t=()=>{o.Z.D.info("Permission for push notifications was denied."),"function"==typeof e&&e(!1)},r=()=>{let i="Permission for push notifications was ignored.";h.Z.isPushBlocked()&&(i+=" The browser has automatically blocked further permission requests for a period (probably 1 week)."),o.Z.D.info(i),"function"==typeof e&&e(!0)},p=h.Z.isPushPermissionGranted(),f=()=>{p||this.qi.setPushNotificationSubscriptionType(u.Z.NotificationSubscriptionTypes.OPTED_IN),this.Xr().then((t=>{if(null==t)return o.Z.D.error("No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush."),void("function"==typeof e&&e());t.pushManager.getSubscription().then((r=>{let u=null;if(this.gt&&null!=this.gt.fn()&&(u=o.Z.bn.pn(this.gt.fn())),r){let c=null,h=null;const p=this.h.I(a.I.q.gn);if(p&&!(0,n.kJ)(p)){let i;try{i=s.Z.yn(p).wn}catch(e){i=null}null==i||isNaN(i.getTime())||0===i.getTime()||(c=i,h=new Date(c),h.setMonth(c.getMonth()+6))}null!=u&&r.options&&r.options.applicationServerKey&&r.options.applicationServerKey.byteLength&&r.options.applicationServerKey.byteLength>0&&!(0,n.Xy)(u,new Uint8Array(r.options.applicationServerKey))?(r.options.applicationServerKey.byteLength>12?o.Z.D.info("Device was already subscribed to push using a different VAPID provider, creating new subscription."):o.Z.D.info("Attempting to upgrade a gcm_sender_id-based push registration to VAPID - depending on the browser this may or may not result in the same gcm_sender_id-based subscription."),this.Or(r,t,u,i,e)):r.expirationTime&&new Date(r.expirationTime)<=(new Date).valueOf()?(o.Z.D.info("Push subscription is expired, creating new subscription."),this.Or(r,t,u,i,e)):p&&(0,n.kJ)(p)?this.Or(r,t,u,i,e):null==h?(o.Z.D.info("No push subscription creation date found, creating new subscription."),this.Or(r,t,u,i,e)):h<=(new Date).valueOf()?(o.Z.D.info("Push subscription older than 6 months, creating new subscription."),this.Or(r,t,u,i,e)):(o.Z.D.info("Device already subscribed to push, sending existing subscription to backend."),this.Mr(r,i,c))}else this.Br(t,u,i,e)})).catch((i=>{o.Z.D.error("Error checking current push subscriptions: "+i)}))})).catch((i=>{o.Z.D.error("ServiceWorker registration failed: "+i)}))};this.Qr(f,r,t)}else if(this.Vr){if(null==this._r||""===this._r)return void o.Z.D.error("You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari");const t=window.safari.pushNotification.permission(this._r);this.Lr(this._r,t,i,e)}}else o.Z.D.info(this.vn)}unsubscribe(i,e){h.Z.isPushSupported()?this.Nr?("undefined"!==typeof navigator?navigator:{userAgent:""}).serviceWorker.getRegistration().then((t=>{t?t.pushManager.getSubscription().then((r=>{r&&(this.Hr(),r.unsubscribe().then((r=>{r?(o.Z.D.info("Device successfully unsubscribed from push."),"function"==typeof i&&i()):(o.Z.D.error("Failed to unsubscribe device from push."),"function"==typeof e&&e()),this.Zr(t)})).catch((i=>{o.Z.D.error("Push unsubscription error: "+i),"function"==typeof e&&e()})))})).catch((i=>{o.Z.D.error("Error unsubscribing from push: "+i),"function"==typeof e&&e()})):(o.Z.D.info("Device already unsubscribed from push."),"function"==typeof i&&i())})):this.Vr&&(this.Hr(),o.Z.D.info("Device unsubscribed from push."),"function"==typeof i&&i()):o.Z.D.info(this.vn)}}p.vn="Push notifications are not supported in this browser.";const f={t:!1,pushManager:null,aa:()=>(f.o(),f.pushManager||(f.pushManager=new p(r.ZP.gr(),r.ZP.ea(),r.ZP.ce(),r.ZP.Ks(),r.ZP.nn(r.JY.na),r.ZP.nn(r.JY.ra),r.ZP.ir(),r.ZP.nn(r.JY.ta),r.ZP.nn(r.JY.ia),r.ZP.l())),f.pushManager),o:()=>{f.t||(r.ZP.u(f),f.t=!0)},destroy:()=>{f.pushManager=null,f.t=!1}};var d=f}}]); //# sourceMappingURL=761-05f3fa0553901115e574.chunk.js.map