!function(t){!function(t){"use strict";var e,i,r,n,o,s,a,c,d,u,p,l=(t,e,i)=>{if(!e.has(t))throw TypeError("Cannot "+i)},h=(t,e,i)=>(l(t,e,"read from private field"),i?i.call(t):e.get(t)),g=(t,e,i)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,i)},w=(t,e,i,r)=>(l(t,e,"write to private field"),r?r.call(t,i):e.set(t,i),i),m=(t,e,i)=>(l(t,e,"access private method"),i);if(false){if("undefined"!=typeof navigator&&"ReactNative"===navigator.product&&"undefined"==typeof crypto)throw new Error("React Native does not have a built-in secure random generator. If you don’t need unpredictable IDs use `nanoid/non-secure`. For secure IDs, import `react-native-get-random-values` before Nano ID.");if("undefined"!=typeof msCrypto&&"undefined"==typeof crypto)throw new Error("Import file with `if (!window.crypto) window.crypto = window.msCrypto` before importing Nano ID to fix IE 11 support");if("undefined"==typeof crypto)throw new Error("Your browser does not have secure random generator. If you don’t need unpredictable IDs, you can use nanoid/non-secure.")}let f=(t=21)=>{let e="",i=crypto.getRandomValues(new Uint8Array(t));for(;t--;){let r=63&i[t];if(36>r)e+=r.toString(36);else if(62>r)e+=(r-26).toString(36).toUpperCase();else if(63>r)e+="_";else e+="-"}return e};const v="_grDebugMode",b=new class{isDebugEnabled(){return!!window.sessionStorage.getItem(v)}startDebug(){window.sessionStorage.setItem(v,"true")}},C=new class{get isLoggingEnabled(){return b.isDebugEnabled()}log(...t){this.displayLog("log",...t)}info(...t){this.displayLog("info",...t)}error(...t){if(t[0]instanceof Error)t.push(t[0].stack);this.displayLog("error",...t)}warn(...t){this.displayLog("warn",...t)}displayLog(t,...e){if(this.isLoggingEnabled)console[t](...e)}};function S(t){const e=document.cookie.match(new RegExp(`(^| )${t}=([^;]+)`));if(e)return e[2]}function _(){const t=new Date,e=location.hostname.split(".").reverse(),i=[],r=`gaDomain-${f(6)}`,n=f(6);let o="";for(t.setTime(t.getTime()+60*1e3),i.push(e.shift());e.length>0;){if(o=i.reverse().join("."),document.cookie=`${r}=${n}; expires=${t.toUTCString()}; domain=.${o}; path=/`,S(r)===n)return o;i.push(e.shift())}return location.hostname}const P="gr_webpush_database",I="gr_visitor_data",y="sub_data",E=480;var D=(t=>(t["DISPLAYED_CUSTOMIZED"]="dic",t["ACCEPTED_CUSTOMIZED"]="acc",t["DENIED_CUSTOMIZED"]="dec",t["DISPLAYED_NATIVE"]="din",t["ACCEPTED_NATIVE"]="acn",t["DENIED_NATIVE"]="den",t))(D||{}),k=(t=>(t["V1"]="1.0.0",t["V1_1"]="1.1.0",t["V2"]="2.0.0",t))(k||{});const U="https://",W="http://",A="www.",x=/^(http:\/\/|https:\/\/)/;class T{constructor(t){this.url=t,this.enhancedUrls=[]}static create(t){return new T(decodeURI(t))}withSlash(){if(!(this.url.endsWith("*")||this.url.endsWith("+")||this.url.includes("?")||this.url.endsWith("/")))this.url=`${this.url}/`;return this}withLackOfProtocolAndWww(){if(!this.url.startsWith("*")&&!this.hasProtocolIncluded()&&!this.hasWwwPart())this.enhancedUrls=[...this.enhancedUrls,`${U}${this.url}`,`${W}${this.url}`,`${U}${A}${this.url}`,`${W}${A}${this.url}`];return this}withEnforcedProtocol(){if(!this.hasProtocolIncluded())this.enhancedUrls=[...this.enhancedUrls,`${U}${this.url}`,`${W}${this.url}`];return this}withDecodeSpecialChars(){return this.enhancedUrls=this.enhancedUrls.map((t=>decodeURI(t))),this}withLackOfWww(){if(this.url.startsWith("*"))return this;if(this.hasProtocolIncluded()&&!this.hasWwwPart())this.enhancedUrls=[...this.enhancedUrls,`${U}${A}${this.url.replace(x,"")}`,`${W}${A}${this.url.replace(x,"")}`];return this}withLackOfProtocol(){if(this.url.startsWith("*"))return this;if(!this.hasProtocolIncluded()&&this.hasWwwPart())this.enhancedUrls=[...this.enhancedUrls,`${U}${this.url}`,`${W}${this.url}`];return this}enhance(){return[...this.enhancedUrls,this.url]}hasProtocolIncluded(){return this.url.startsWith(U)||this.url.startsWith(W)}hasWwwPart(){return this.url.replace(/^(http:\/\/|https:\/\/)/,"").startsWith(A)}}function N(t){return t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}async function $(){var t,e;if("serviceWorker"in navigator){const i=await navigator.serviceWorker.getRegistrations(),r=[];for(const n of i)if(!((null==(t=n.active)?void 0:t.scriptURL.endsWith("gr_sw_main.js"))||(null==(e=n.active)?void 0:e.scriptURL.endsWith("service-worker/service-worker.js"))))r.push(n.unregister());return Promise.all(r)}}function V(t){const e=new URL(document.location.href).host;return i=document.location.href,(t=>t.map((t=>T.create(t).withSlash().withLackOfProtocolAndWww().withLackOfProtocol().withLackOfWww().withDecodeSpecialChars().enhance())).flat(1))((Array.isArray(t)?t:[t]).map((t=>`${e}${t}`))).some((t=>{const e=Array.from(t.matchAll(/[*+]/g));let r;if(e.length)r=e.reduce(((e,i,r,n)=>{var o;const s=[...e,N(t.substring(((null==(o=n[r-1])?void 0:o.index)??-1)+1,i.index)),"*"===i[0]?".*":"."];if(r===n.length-1)s.push(N(t.substring(i.index+1)));return s}),[]).join("");else r=N(t);return new RegExp(`^${r}$`).test((t=>{if(!t.includes("?")&&!t.endsWith("/"))return`${decodeURI(t)}/`;else return decodeURI(t)})(i))}));var i}var R=(t=>(t["UuidHasBeenSet"]="grUuidHasBeenSet",t["PopupsRendererCustomUrl"]="grPopupsRendererCustomUrl",t))(R||{});class O{constructor(){g(this,e,new Proxy({},{get(t,e){if(e in t)return t[e];else return t[e]=[],t[e]}}))}addEvent(t,i){h(this,e)[t].push(i)}drainEvents(t){const i=h(this,e)[t];return h(this,e)[t]=[],i}getEvents(t){return h(this,e)[t]}hasDelayedEvents(t){return h(this,e)[t].length>0}}e=new WeakMap,i=new WeakMap,r=new WeakMap;const L=new class{constructor(){g(this,i,{}),g(this,r,new O)}publish(t,...e){var n;if(null==(n=h(this,i)[t])?void 0:n.length)h(this,i)[t].forEach((i=>{i(...e),C.log(`Event ${t} published with arguments'`,...e)}));else h(this,r).addEvent(t,e)}subscribe(t,e,n={}){const{preventEventDraining:o,ignoreQueuedEvents:s}=n;if(!h(this,i)[t])h(this,i)[t]=[];if(h(this,r).hasDelayedEvents(t)&&!s)if(o)h(this,r).getEvents(t).forEach((t=>e(...t)));else h(this,r).drainEvents(t).forEach((t=>e(...t)));h(this,i)[t].push(e)}unsubscribe(t,e){var r;const n=null==(r=h(this,i)[t])?void 0:r.indexOf(e);if(n>-1)h(this,i)[t].splice(n,1)}removeListeners(t){delete h(this,i)[t]}};var M,j,B,F,z,G,H,J,Y,X,Z,q=(t=>(t["DeviceType"]="debug_device_type",t["Location"]="debug_location",t["VisitUrlPath"]="debug_visit_url_path",t["BrowserStorageLastActivityDate"]="debug_browser_storage_last_activity_date",t["NewVisitor"]="debug_new_visitor",t["HasUserVisitPage"]="debug_has_user_visit_page",t["Events"]="debug_events",t))(q||{});function K(){const t=t=>{const e=sessionStorage.getItem(t);if(e){if([q.DeviceType,q.VisitUrlPath,q.Location].includes(t))return e;if(t===q.BrowserStorageLastActivityDate){const t=new Date(e);return isNaN(t.getTime())?void 0:t}if([q.NewVisitor,q.HasUserVisitPage,q.Events].includes(t))try{return JSON.parse(e)}catch(i){C.error(`Invalid debug data for: ${t}`)}}};return{enabled:true,data:{[q.DeviceType]:t(q.DeviceType),[q.BrowserStorageLastActivityDate]:t(q.BrowserStorageLastActivityDate),[q.Location]:t(q.Location),[q.NewVisitor]:t(q.NewVisitor),[q.VisitUrlPath]:t(q.VisitUrlPath),[q.HasUserVisitPage]:t(q.HasUserVisitPage),[q.Events]:t(q.Events)}}}(j=M||(M={}))["PageVisit"]="visit",j["Popup"]="popup",j["ViewItem"]="view_item",j["ViewCategory"]="view_category",j["WishlistItem"]="wishlist_item",j["LikeItem"]="like_item",j["UnlikeItem"]="unlike_item",j["OrderPlaced"]="order_placed",j["Cart"]="cart_update",void(j["ShopifyAbandonedCart"]="shopify_webhook_abandoned_cart"),Error,(Z=B||(B={}))["Inline"]="inline",void(Z["Popup"]="popup"),(X=F||(F={}))["Hq"]="Hq",void(X["Us"]="Us"),void((z||(z={}))["UserAid"]="X-Aid"),(Y=G||(G={}))["Active"]="active",void(Y["Inactive"]="inactive"),(J=H||(H={}))["ReactSendWebPush"]="react_web_webpush",J["ReactCollectWebPushConsent"]="react_web_collect_webpush_subscription",J["FilterWebUrl"]="filter_web_url",J["FilterWebSubscribers"]="filter_web_subscriber",J["FilterLocation"]="filter_web_geolocation",J["FilterDevice"]="filter_web_device",J["FilterReturningVisitor"]="filter_web_returning_visitor",J["ConditionProductViewed"]="await_web_view_item_event",J["ConditionCategoryViewed"]="await_web_view_category_event",J["ConditionWebPushConsent"]="await_web_webpush_subscribe",J["ConditionProductLiked"]="await_web_like_item_event",J["TransferToBackend"]="react_backend_transfer",J["AwaitScroll"]="await_scroll",J["ShowPopup"]="react_popup",n=new WeakMap;const Q=new class{constructor(){g(this,n,{[M.LikeItem]:[],[M.OrderPlaced]:[],[M.UnlikeItem]:[],[M.ViewCategory]:[],[M.ViewItem]:[],[M.WishlistItem]:[],[M.PageVisit]:[],[M.Popup]:[],[M.Cart]:[]})}getEvents(t){return Promise.resolve(h(this,n)[t])}getAllEvents(){return Promise.resolve(Object.values(h(this,n)).flat(1))}getAllECommerceEvents(){return Promise.resolve([...h(this,n)[M.ViewItem],...h(this,n)[M.ViewCategory],...h(this,n)[M.LikeItem],...h(this,n)[M.UnlikeItem],...h(this,n)[M.WishlistItem],...h(this,n)[M.OrderPlaced],...h(this,n)[M.Cart]])}getAllPopupEvents(){return Promise.resolve([...h(this,n)[M.Popup]])}saveEvent(t){return h(this,n)[t.eventType].push(t),Promise.resolve()}};var tt=(t=>(t["v2"]="v2",t["af"]="af",t["wp"]="wp",t["we"]="we",t["ec"]="ec",t))(tt||{}),et=(t=>(t["v2"]="GRV2",t["af"]="GRAF",t["wp"]="GRWP",t["we"]="GRWE",t["ec"]="GREC",t))(et||{});const it={[tt.af]:"autoFunnel",[tt.ec]:"ecommerce",[tt.v2]:"tracking",[tt.we]:"webEvents",[tt.wp]:"webPush"};o=new WeakSet,s=t=>it[t];const rt=new class{constructor(){g(this,o)}setScriptInitialized(t){const e=m(this,o,s).call(this,t);window.__grIntegrationConfig[e].isModuleInitialized=true}isScriptInitialized(t){var e,i;const r=m(this,o,s).call(this,t);return(null==(i=null==(e=null==window?void 0:window.__grIntegrationConfig)?void 0:e[r])?void 0:i.isModuleInitialized)??false}},nt=new class{constructor(){this.scriptModuleManager=rt}initialize(t){const{xsid:e,grid:i,clientLatestGrid:r,domain:n,aid:o,useNOStorage:s,useBetterSubscriberIdentification:a,isServedFromCustomDomain:c,scriptsDomain:d,scriptsVersion:u,tracking:p,isDebugMode:l,uuuid:h}=t;if(l)b.startDebug();window.__grIntegrationConfig=window.__grIntegrationConfig||{cData:{aid:o,grid:i,domain:n,useNOStorage:s,useBetterSubscriberIdentification:a,isServedFromCustomDomain:c,clientLatestGrid:r,uuuid:h},visitor:{email:null,eComId:null,xsid:e},tracking:{isModuleInitialized:false,isEnabled:p},webEvents:{isModuleInitialized:false,visitorApplicationEndpoint:null,automationJourneyGraphs:[],popupGraphs:[]},webPush:{isModuleInitialized:false,customSwPath:null,wpid:null,pushDomain:null,promptEndpoint:null},analyticsData:{scriptsDomain:d,scriptsVersion:u},ecommerce:{isModuleInitialized:false},autoFunnel:{isModuleInitialized:false},eventBus:L,temporaryEventsStorage:Q,debug:l?K():void 0,delayedScripts:{},scriptTypesInitialized:new Set}}canUseBackendForSubscriberIdentification(){return window.__grIntegrationConfig.cData.useBetterSubscriberIdentification}getUserAid(){return window.__grIntegrationConfig.cData.aid}getClientLatestGrid(){return window.__grIntegrationConfig.cData.clientLatestGrid}getUserAnalyticsDomain(){return window.__grIntegrationConfig.cData.domain}getUserUuid(){return window.__grIntegrationConfig.cData.uuuid}enablePopupDevMode(){window.__grIntegrationConfig.setCustomPopupRendererUrl=t=>{window.sessionStorage.setItem(R.PopupsRendererCustomUrl,t)}}getPopupRendererCustomUrl(){return window.sessionStorage.getItem(R.PopupsRendererCustomUrl)}setCustomSwPath(t){if("string"!=typeof t)throw new Error("Path type must be string");if(!t.match(/gr_sw_main.js|service-worker\/service-worker.js$/))throw new Error("Invalid sw file name");window.__grIntegrationConfig.webPush.customSwPath=t}getCustomSwPath(){var t;return null==(t=window.__grIntegrationConfig)?void 0:t.webPush.customSwPath}isTrackingEnabled(){return window.__grIntegrationConfig.tracking.isEnabled}isTrackingScriptServedFromCustomDomain(){return window.__grIntegrationConfig.cData.isServedFromCustomDomain}set visitorEmail(t){window.__grIntegrationConfig.visitor.email=t}get visitorEmail(){return window.__grIntegrationConfig.visitor.email}get pushWpid(){return window.__grIntegrationConfig.webPush.wpid}set pushWpid(t){window.__grIntegrationConfig.webPush.wpid=t}set pushDomain(t){window.__grIntegrationConfig.webPush.pushDomain=t}get pushDomain(){return window.__grIntegrationConfig.webPush.pushDomain}set pushPromptEndpoint(t){window.__grIntegrationConfig.webPush.promptEndpoint=t}get pushPromptEndpoint(){return window.__grIntegrationConfig.webPush.promptEndpoint}get eventBus(){return window.__grIntegrationConfig.eventBus}get canUseBackendStorageForEvents(){return window.__grIntegrationConfig.cData.useNOStorage}get webConnectScriptCdnUrl(){return window.__grIntegrationConfig.analyticsData.scriptsDomain}get webConnectCurrentScriptsVersion(){return window.__grIntegrationConfig.analyticsData.scriptsVersion}get isDebug(){var t,e;return!!(null==(e=null==(t=window.__grIntegrationConfig)?void 0:t.debug)?void 0:e.enabled)}set debugObject(t){window.__grIntegrationConfig.debug=t}get debugObject(){var t;return null==(t=window.__grIntegrationConfig)?void 0:t.debug}get delayedScripts(){var t;return(null==(t=window.__grIntegrationConfig)?void 0:t.delayedScripts)||{}}set delayedScripts(t){window.__grIntegrationConfig.delayedScripts=t}set visitorApplicationEndpoint(t){window.__grIntegrationConfig.webEvents.visitorApplicationEndpoint=t}get visitorApplicationEndpoint(){return window.__grIntegrationConfig.webEvents.visitorApplicationEndpoint}get userEventsStorageApplicationUrl(){return window.__grIntegrationConfig.ecommerce.webEventsSearchApplicationEndpoint}set userEventsStorageApplicationUrl(t){window.__grIntegrationConfig.ecommerce.webEventsSearchApplicationEndpoint=t}get temporaryEventsStorage(){return window.__grIntegrationConfig.temporaryEventsStorage}get automationJourneyGraphs(){return window.__grIntegrationConfig.webEvents.automationJourneyGraphs}get popupGraphs(){return window.__grIntegrationConfig.webEvents.popupGraphs}get visitorXsid(){return window.__grIntegrationConfig.visitor.xsid}};class ot{get promptId(){var t;return null==(t=this.promptData)?void 0:t.id}get statisticsEndpoint(){var t;return nt.pushDomain+(null==(t=this.promptData)?void 0:t.pst)}get hasMobile(){var t,e;return!!(null==(e=null==(t=this.promptData)?void 0:t.data)?void 0:e.mobile)}get hasDesktop(){var t,e;return!!(null==(e=null==(t=this.promptData)?void 0:t.data)?void 0:e.desktop)}get mobilePromptData(){var t,e;return null==(e=null==(t=this.promptData)?void 0:t.data)?void 0:e.mobile}get desktopPromptData(){var t,e;return null==(e=null==(t=this.promptData)?void 0:t.data)?void 0:e.desktop}}class st extends ot{constructor(t){super(),this.promptData={id:t.pid,pst:t.pst,data:t.pc}}setActivePrompt(){throw new Error("Method not implemented in Prompt v1")}}var at=(t=>(t["Includes"]="allowed",t["Excluded"]="excluded",t["Entire"]="entire",t))(at||{});class ct extends ot{constructor(t){super(),this.globalPromptConfig=t;const e=t.paths.map((t=>{switch(t.type){case at.Entire:return{...t,type:at.Includes,path:"*"};case at.Includes:case at.Excluded:return{...t,path:t.path.startsWith("/")?`${t.path}*`:`*${t.path}*`};default:return t}})).find((t=>t.type===at.Includes?V(t.path):!V(t.path)));if(t.nativePrompt&&t.nativePrompt.pid===(null==e?void 0:e.pid))return this.promptData={id:t.nativePrompt.pid,pst:t.nativePrompt.pst,data:null},void 0;const i=t.customPrompts.find((t=>t.pid===(null==e?void 0:e.pid)));if(i)this.promptData={id:i.pid,pst:i.pst,data:i.pc}}setActivePrompt(t){const e=this.globalPromptConfig.customPrompts.find((e=>e.pid===t));if(e)this.promptData={id:e.pid,pst:e.pst,data:e.pc}}}class dt{constructor(t){this.nativePromptPaths=[],this.version=t._v;const e=t,i=t;switch(this.version){case k.V1:case k.V1_1:this.prompt=new st(e),this.nativePromptPaths=e.paths;break;case k.V2:this.prompt=new ct(i);break;default:throw new Error("Unsupported version of prompt")}}get shouldShowNativePrompt(){var t,e,i;if(this.version===k.V2){if(!(null==(t=this.prompt)?void 0:t.hasDesktop)&&!(null==(e=this.prompt)?void 0:e.hasMobile)&&(null==(i=this.prompt)?void 0:i.promptId))return true}else if(V(this.nativePromptPaths))return true;return false}getVersion(){return this.version}}const ut=new class{async initialize(){await this.fetchSiteConfig(nt.pushPromptEndpoint),this.promptConfig=new dt(globalThis._grpr)}get prompt(){return this.promptConfig.prompt}get promptData(){return this.promptConfig}fetchSiteConfig(t){return new Promise(((e,i)=>{const r=document.createElement("script");r.type="text/javascript",r.src=t,document.body.appendChild(r),r.onload=()=>{e()},r.onerror=i}))}setActivePrompt(t){try{this.promptConfig.prompt.setActivePrompt(t)}catch(e){C.error(e)}}},pt=new class{async registerServiceWorker(){const t=nt.getCustomSwPath();if(t)return navigator.serviceWorker.register(`${t}`);try{return await navigator.serviceWorker.register("/gr_sw_main.js")}catch(e){return navigator.serviceWorker.register("./gr_sw_main.js")}}getExistingServiceWorkerRegistration(){return navigator.serviceWorker.getRegistration()}};var lt=(t=>(t["visitorUuid"]="gaVisitorUuid",t["visitorValuable"]="gaIsValuable",t["VisitorEmail"]="gaVisitorEId",t["VisitorResubscribed"]="gaVisitorResubscribed",t["NotificationConsentStatus"]="gaNotificationConsent",t["NotificationConsentAcceptedFromPrompt"]="gaWpnConAcc",t["NotificationConsentCustomPromptRejectedDEPRECATED"]="gaWpnConRej-{promptId}",t["NotificationConsentCustomPromptRejected"]="gaWpnConRej-promptId",t))(lt||{}),ht=(t=>(t[t["OneYear"]=31536e6]="OneYear",t[t["TwoWeeks"]=12096e5]="TwoWeeks",t))(ht||{});const gt=new class{constructor(){this.authToken=null}async getAuthToken(){const{pushWpid:t,pushDomain:e}=nt;if(t)try{if(this.authToken)return this.authToken;const i=await fetch(`${e}webpush/auth`,{method:"POST",mode:"cors",headers:{"X-WpId":t,"Content-Type":"application/json"},body:JSON.stringify({url:window.location.origin,gau:S("gaVisitorUuid")})});return this.authToken=await i.text(),this.authToken}catch(i){C.error(i)}}};function wt(t){this.message=t}(wt.prototype=new Error).name="InvalidCharacterError";var mt="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||(t=>{var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new wt("'atob' failed: The string to be decoded is not correctly encoded.");for(var i,r,n=0,o=0,s="";r=e.charAt(o++);~r&&(i=n%4?64*i+r:r,n++%4)?s+=String.fromCharCode(255&i>>(-2*n&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return s});function ft(t){this.message=t}function vt(t,e){if("string"!=typeof t)throw new ft("Invalid token specified");var i=true===(e=e||{}).header?0:1;try{return JSON.parse((t=>{var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return decodeURIComponent(mt(e).replace(/(.)/g,((t,e)=>{var i=e.charCodeAt(0).toString(16).toUpperCase();return 2>i.length&&(i="0"+i),"%"+i})))}catch(i){return mt(e)}})(t.split(".")[i]))}catch(r){throw new ft("Invalid token specified: "+r.message)}}function bt(t,e,i=nt.pushDomain,r=nt.pushWpid){window.indexedDB.deleteDatabase(P),window.indexedDB.open(P,1).onupgradeneeded=n=>{n.target.result.createObjectStore(I,{keyPath:"id"}).add({id:y,uuid:t,pushSubscription:e.toJSON(),domain:i,wpid:r})}}(ft.prototype=new Error).name="InvalidTokenError";const Ct=new class{sendConsentData(t,e,i){navigator.sendBeacon(new URL("wpn/consent-data",nt.getUserAnalyticsDomain()),new Blob([JSON.stringify({uuid:e,aid:i,publicVpk:t})],{type:"application/json"}))}async renewSubscription(t,e){const{pushWpid:i,pushDomain:r}=nt,n=await gt.getAuthToken();return fetch(`${r}webpush/renew`,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json","X-WpId":i,Authorization:`Bearer ${n}`},body:JSON.stringify({oldSubscription:null==t?void 0:t.toJSON(),newSubscription:null==e?void 0:e.toJSON()})})}},St=new class{sendStatsData(t){return fetch(`${ut.prompt.statisticsEndpoint}${t}`,{mode:"cors"})}},_t=new class{setCookie({expiresIn:t,domain:e="",value:i,name:r}){const n=this.getExpirationTimeString(t);document.cookie=`${r}=${i}; expires=${n}; path=/; ${e?`domain=${e}`:""}`}getExpirationTimeString(t){if(t instanceof Date)return t.toUTCString();const e=new Date;return e.setTime(e.getTime()+t),e.toUTCString()}getCookie(t){const e=document.cookie.match(new RegExp(`(^| )${t}=([^;]+)`));if(e)return e[2]}removeUuidCookieSessionInfo(){window.sessionStorage.removeItem(R.UuidHasBeenSet)}};class Pt extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}}class It extends Pt{constructor(t){if(super("User denied push notification consent"),t)this.cause=t}}var yt=(t=>(t["UserEventSaved"]="userEventSaved",t["WebPushConsentAccepted"]="webPushConsentAccepted",t["WebPushCustomConsentRejected"]="webPushCustomConsentRejected",t["WebPushNativeConsentRejected"]="webPushNativeConsentRejected",t))(yt||{});const Et=1e3*60*60*24*7,Dt=new class{async isSubscribed(){return null!==await this.checkIfUserIsSubscribed()}async isSubscribedFromPrompt(t){if(Boolean(await this.checkIfUserIsSubscribed()))return t===_t.getCookie(lt.NotificationConsentAcceptedFromPrompt);else return false}isPermissionPermanentlyDenied(){return"denied"===Notification.permission}isPermissionDeniedForCustomPrompt(t){const e=!!_t.getCookie(lt.NotificationConsentCustomPromptRejected.replace("promptId",t)),i=!!_t.getCookie(lt.NotificationConsentCustomPromptRejectedDEPRECATED.replace("promptId",t));return"default"===Notification.permission&&(e||i)}async registerUserForNotifications(){const t=ut.promptData.getVersion(),{pushWpid:e,pushDomain:i}=nt,r=S(lt.visitorUuid),n=await pt.registerServiceWorker();let o=await n.pushManager.getSubscription();if(!(null!==o))try{const n=await gt.getAuthToken(),s=vt(n),a=s.subEndp;return o=await this.getUserNotificationsSubscription(),bt(r,o,i,e),St.sendStatsData(D.ACCEPTED_NATIVE),await fetch(a,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json","X-WpId":e,Authorization:`Bearer ${n}`},body:JSON.stringify({sub:o,prv:t})}).then((t=>{if(!t.ok)throw new Error(`Subscription failed ${t.status}`);return true})),Ct.sendConsentData(s.vpk,r,nt.getUserAid()),_t.setCookie({value:ut.promptData.prompt.promptId,name:lt.NotificationConsentAcceptedFromPrompt,expiresIn:ht.OneYear,domain:_()}),_t.removeUuidCookieSessionInfo(),this.markVisitorAsResubscribed(),o}catch(s){if(0===s.code)throw St.sendStatsData(D.DENIED_NATIVE),nt.eventBus.publish(yt.WebPushNativeConsentRejected),new It(s);throw s}}async resubscribeVisitor(){if(this.shouldResubscribeVisitor()){const t=await pt.getExistingServiceWorkerRegistration(),e=await(null==t?void 0:t.pushManager.getSubscription());if(e)await e.unsubscribe();await $();const i=await this.getUserNotificationsSubscription();if(e||i)await Ct.renewSubscription(e,i).then((t=>{if(!t.ok)throw new Error(`Subscription failed ${t.status}`);return true})),_t.removeUuidCookieSessionInfo();if(i)this.markVisitorAsResubscribed(),bt(S(lt.visitorUuid),i);return i}}async getUserNotificationsSubscription(){const t=await pt.registerServiceWorker(),e=await t.pushManager.getSubscription();if(!(null!==e))try{const e=vt(await gt.getAuthToken());if("default"===Notification.permission)St.sendStatsData(D.DISPLAYED_NATIVE);return t.pushManager.subscribe({userVisibleOnly:true,applicationServerKey:e.vpk})}catch(i){C.error(i)}return e}markVisitorAsResubscribed(){_t.setCookie({name:lt.VisitorResubscribed,value:"true",expiresIn:Et})}shouldResubscribeVisitor(){return!_t.getCookie(lt.VisitorResubscribed)||!!window.sessionStorage.getItem(R.UuidHasBeenSet)}async checkIfUserIsSubscribed(){return(await pt.registerServiceWorker()).pushManager.getSubscription()}},kt={".gr-visual-prompt":{all:"initial !important",position:"fixed !important",left:"50% !important",top:"0 !important","z-index":"999999999 !important",transform:"translateX(-50%) !important"}},Ut={".gr-visual-prompt":{all:"initial !important",position:"fixed !important",left:"50% !important",bottom:"0 !important","z-index":"999999999 !important",transform:"translateX(-50%) !important"}};function Wt(t,e){return(t.shadowRoot||t).querySelector(e)}a=new WeakMap,c=new WeakMap,d=new WeakMap,u=new WeakSet,p=t=>{_t.setCookie({value:t,name:lt.NotificationConsentCustomPromptRejected.replace("promptId",t),expiresIn:ht.TwoWeeks,domain:_()})};const At=new class{constructor(){g(this,u),g(this,a,void 0),g(this,c,void 0),g(this,d,void 0),w(this,a,new AbortController),w(this,c,new AbortController),w(this,d,null),this.onImageError=t=>{const e=t.target;e.parentNode.removeChild(e)},this.closeNotificationPrompt=t=>{const e=document.documentElement.querySelector('[data-gr-prompt="content"]'),i=Wt(e,"img");if(null==i?void 0:i.removeEventListener("error",this.onImageError),!t){const t=Date.now()+(h(this,d)??ht.OneYear);_t.setCookie({name:lt.NotificationConsentStatus,value:"rejected",expiresIn:t}),St.sendStatsData(D.DENIED_CUSTOMIZED)}document.body.removeChild(e)}}get shouldCustomPromptBeDisplayed(){const{prompt:t}=ut;return t&&((null==t?void 0:t.hasMobile)||(null==t?void 0:t.hasDesktop))}async displayCustomPrompt(t){if(t)w(this,d,t);if(this.shouldCustomPromptBeDisplayed){const{prompt:t}=ut;if(Dt.isPermissionDeniedForCustomPrompt(null==t?void 0:t.promptId))throw new It;const r=function(t,e){const i=document.createElement("div"),r=/iPhone|iPad|iPod|Android|webOS|BlackBerry|Windows Phone/i.test(navigator.userAgent)||screen.availWidth{const e=document.createElement("style"),i=(r="mobile"===t?Ut:kt,Object.keys(r).reduce(((t,e)=>{const i=r[e];if("object"==typeof i){const r=Object.keys(i).reduce(((t,e)=>t+=`${e}: ${i[e]};`),"");t.push(`${e} {${r}}`)}return t}),[]));var r;let n;document.head.appendChild(e),n=e.sheet,i.forEach((t=>{n.insertRule(t,n.rules.length)}))})(r?"mobile":"desktop"),i}(t.desktopPromptData,t.mobilePromptData),n=Wt(r,'[data-gr-prompt-button="allow"]'),o=Wt(r,'[data-gr-prompt-button="cancel"]');Wt(r,"img").addEventListener("error",this.onImageError),n.style.cursor="pointer",o.style.cursor="pointer",e=r,i=()=>{St.sendStatsData(D.DISPLAYED_CUSTOMIZED)},void new MutationObserver(((t,r)=>{t.forEach((t=>{if(Array.from(t.addedNodes).includes(e))i(),r.disconnect()}))})).observe(document.body,{childList:true}),document.body.appendChild(r);const s=await Promise.race([this.getUserSubscriptionFromCustomPromptConfirm(r),this.waitForUserDenyConsent(r)]);if(this.isPushSubscription(s))return s;throw new It}var e,i}getUserSubscriptionFromCustomPromptConfirm(t){return new Promise(((e,i)=>{const r=Wt(t,'[data-gr-prompt-button="allow"]');if(r)r.addEventListener("click",(()=>{St.sendStatsData(D.ACCEPTED_CUSTOMIZED),Dt.registerUserForNotifications().then((t=>{const{promptId:i,hasDesktop:r,hasMobile:n}=ut.promptData.prompt;nt.eventBus.publish(yt.WebPushConsentAccepted,n||r?i:""),h(this,c).abort(),e(t)})).catch((t=>{i(t)})),this.closeNotificationPrompt(true)}),{once:true,signal:h(this,a).signal})}))}waitForUserDenyConsent(t){return new Promise((e=>{const i=Wt(t,'[data-gr-prompt-button="cancel"]');if(i)i.addEventListener("click",(()=>{const{promptId:t}=ut.promptData.prompt;this.closeNotificationPrompt(),h(this,a).abort(),m(this,u,p).call(this,t),nt.eventBus.publish(yt.WebPushCustomConsentRejected,t),e()}),{once:true,signal:h(this,c).signal})}))}isPushSubscription(t){return t instanceof PushSubscription||!!t&&"object"==typeof t&&"endpoint"in t&&"expirationTime"in t}};class xt{constructor(){this.assureUuidIsSet()}async initialize(){await ut.initialize();const t="default"===Notification.permission,e="granted"===Notification.permission,i=!!_t.getCookie(lt.NotificationConsentCustomPromptRejected.replace("promptId",ut.promptData.prompt.promptId)),r=!!_t.getCookie(lt.NotificationConsentCustomPromptRejectedDEPRECATED.replace("promptId",ut.promptData.prompt.promptId)),n="serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window,o=i||r;try{if(e)await Dt.resubscribeVisitor();else if(n&&!o&&t&&nt.pushPromptEndpoint)if(await $(),await pt.registerServiceWorker(),At.shouldCustomPromptBeDisplayed)await At.displayCustomPrompt();else if(ut.promptData.shouldShowNativePrompt)await Dt.registerUserForNotifications()}catch(s){console.error(s)}}assureUuidIsSet(){if(!S("gaVisitorUuid"))window.sessionStorage.setItem(R.UuidHasBeenSet,"true"),((t,e,i="")=>{const r=new Date;r.setTime(r.getTime()+365*24*60*60*1e3),document.cookie=`${t}=${e}; expires=${r.toUTCString()}; path=/; ${i?`domain=${i}`:""}`})("gaVisitorUuid","xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})))}}const Tt=new class{isScriptDelayed(t){return Object.keys(nt.delayedScripts).includes(t)}delay(t){if(!this.isScriptDelayed(t))nt.delayedScripts={...nt.delayedScripts,[t]:void 0}}storeDelayedScriptParams(t,e){if(this.isScriptDelayed(t))nt.delayedScripts={...nt.delayedScripts,[t]:e}}initScript(t){var e;const i=nt.delayedScripts[t];if(i){nt.delayedScripts=Object.fromEntries(Object.entries(nt.delayedScripts).filter((([e])=>e!==t)));const r=et[t];null==(e=null==window?void 0:window[r])?void 0:e.init(...i)}}};t.init=(t,e,i)=>{if(Tt.isScriptDelayed(tt.wp))return Tt.storeDelayedScriptParams(tt.wp,[t,e,i]),null;if(nt.initialize({}),!nt.scriptModuleManager.isScriptInitialized(tt.wp))nt.scriptModuleManager.setScriptInitialized(tt.wp),nt.pushWpid=i,nt.pushDomain=t,nt.pushPromptEndpoint=e,(new xt).initialize()},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}((t="undefined"!=typeof globalThis?globalThis:t||self).GRWP={})}(this);