cap-hydra-web-sdk 1.10.5 → 1.10.6
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/README.md +24 -27
- package/dist/index.d.ts +6 -10
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/index.umd.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).WebSDK={})}(this,function(t){"use strict";var i="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},n="URLSearchParams"in i,e="Symbol"in i&&"iterator"in Symbol,r="FileReader"in i&&"Blob"in i&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in i,o="ArrayBuffer"in i;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var i={next:function(){var i=t.shift();return{done:void 0===i,value:i}}};return e&&(i[Symbol.iterator]=function(){return i}),i}function f(t){this.map={},t instanceof f?t.forEach(function(t,i){this.append(i,t)},this):Array.isArray(t)?t.forEach(function(t){if(2!=t.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+t.length);this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(i){this.append(i,t[i])},this)}function l(t){if(!t.t)return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function v(t){return new Promise(function(i,n){t.onload=function(){i(t.result)},t.onerror=function(){n(t.error)}})}function m(t){var i=new FileReader,n=v(i);return i.readAsArrayBuffer(t),n}function g(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}function p(){return this.bodyUsed=!1,this.i=function(t){var i;this.bodyUsed=this.bodyUsed,this.o=t,t?"string"==typeof t?this.u=t:r&&Blob.prototype.isPrototypeOf(t)?this.h=t:s&&FormData.prototype.isPrototypeOf(t)?this.l=t:n&&URLSearchParams.prototype.isPrototypeOf(t)?this.u=t.toString():o&&r&&((i=t)&&DataView.prototype.isPrototypeOf(i))?(this.v=g(t.buffer),this.o=new Blob([this.v])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this.v=g(t):this.u=t=Object.prototype.toString.call(t):(this.t=!0,this.u=""),this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this.h&&this.h.type?this.headers.set("content-type",this.h.type):n&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var t=l(this);if(t)return t;if(this.h)return Promise.resolve(this.h);if(this.v)return Promise.resolve(new Blob([this.v]));if(this.l)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this.u]))}),this.arrayBuffer=function(){if(this.v){var t=l(this);return t||(ArrayBuffer.isView(this.v)?Promise.resolve(this.v.buffer.slice(this.v.byteOffset,this.v.byteOffset+this.v.byteLength)):Promise.resolve(this.v))}if(r)return this.blob().then(m);throw new Error("could not read as ArrayBuffer")},this.text=function(){var t,i,n,e,r,s=l(this);if(s)return s;if(this.h)return t=this.h,i=new FileReader,n=v(i),e=/charset=([A-Za-z0-9_-]+)/.exec(t.type),r=e?e[1]:"utf-8",i.readAsText(t,r),n;if(this.v)return Promise.resolve(function(t){for(var i=new Uint8Array(t),n=new Array(i.length),e=0;e<i.length;e++)n[e]=String.fromCharCode(i[e]);return n.join("")}(this.v));if(this.l)throw new Error("could not read FormData body as text");return Promise.resolve(this.u)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(t,i){t=c(t),i=h(i);var n=this.map[t];this.map[t]=n?n+", "+i:i},f.prototype.delete=function(t){delete this.map[c(t)]},f.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},f.prototype.set=function(t,i){this.map[c(t)]=h(i)},f.prototype.forEach=function(t,i){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(i,this.map[n],n,this)},f.prototype.keys=function(){var t=[];return this.forEach(function(i,n){t.push(n)}),d(t)},f.prototype.values=function(){var t=[];return this.forEach(function(i){t.push(i)}),d(t)},f.prototype.entries=function(){var t=[];return this.forEach(function(i,n){t.push([n,i])}),d(t)},e&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function y(t,n){if(!(this instanceof y))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var e,r,s=(n=n||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,n.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,s||null==t.o||(s=t.o,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=n.credentials||this.credentials||"same-origin",!n.headers&&this.headers||(this.headers=new f(n.headers)),this.method=(e=n.method||this.method||"GET",r=e.toUpperCase(),w.indexOf(r)>-1?r:e),this.mode=n.mode||this.mode||null,this.signal=n.signal||this.signal||function(){if("AbortController"in i)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");if(this.i(s),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==n.cache&&"no-cache"!==n.cache)){var o=/([?&])_=[^&]*/;if(o.test(this.url))this.url=this.url.replace(o,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function E(t){var i=new FormData;return t.trim().split("&").forEach(function(t){if(t){var n=t.split("="),e=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");i.append(decodeURIComponent(e),decodeURIComponent(r))}}),i}function _(t,i){if(!(this instanceof _))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(i||(i={}),this.type="default",this.status=void 0===i.status?200:i.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===i.statusText?"":""+i.statusText,this.headers=new f(i.headers),this.url=i.url||"",this.i(t)}y.prototype.clone=function(){return new y(this,{body:this.o})},p.call(y.prototype),p.call(_.prototype),_.prototype.clone=function(){return new _(this.o,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},_.error=function(){var t=new _(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var I=[301,302,303,307,308];_.redirect=function(t,i){if(-1===I.indexOf(i))throw new RangeError("Invalid status code");return new _(null,{status:i,headers:{location:t}})};var b=i.DOMException;try{new b}catch(t){(b=function(t,i){this.message=t,this.name=i;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),b.prototype.constructor=b}function T(t,n){return new Promise(function(e,s){var u=new y(t,n);if(u.signal&&u.signal.aborted)return s(new b("Aborted","AbortError"));var a=new XMLHttpRequest;function d(){a.abort()}if(a.onload=function(){var t,i,n={statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",i=new f,t.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t}).forEach(function(t){var n=t.split(":"),e=n.shift().trim();if(e){var r=n.join(":").trim();try{i.append(e,r)}catch(t){console.warn("Response "+t.message)}}}),i)};0===u.url.indexOf("file://")&&(a.status<200||a.status>599)?n.status=200:n.status=a.status,n.url="responseURL"in a?a.responseURL:n.headers.get("X-Request-URL");var r="response"in a?a.response:a.responseText;setTimeout(function(){e(new _(r,n))},0)},a.onerror=function(){setTimeout(function(){s(new TypeError("Network request failed"))},0)},a.ontimeout=function(){setTimeout(function(){s(new TypeError("Network request timed out"))},0)},a.onabort=function(){setTimeout(function(){s(new b("Aborted","AbortError"))},0)},a.open(u.method,function(t){try{return""===t&&i.location.href?i.location.href:t}catch(i){return t}}(u.url),!0),"include"===u.credentials?a.withCredentials=!0:"omit"===u.credentials&&(a.withCredentials=!1),"responseType"in a&&(r?a.responseType="blob":o&&(a.responseType="arraybuffer")),n&&"object"==typeof n.headers&&!(n.headers instanceof f||i.Headers&&n.headers instanceof i.Headers)){var l=[];Object.getOwnPropertyNames(n.headers).forEach(function(t){l.push(c(t)),a.setRequestHeader(t,h(n.headers[t]))}),u.headers.forEach(function(t,i){-1===l.indexOf(i)&&a.setRequestHeader(i,t)})}else u.headers.forEach(function(t,i){a.setRequestHeader(i,t)});u.signal&&(u.signal.addEventListener("abort",d),a.onreadystatechange=function(){4===a.readyState&&u.signal.removeEventListener("abort",d)}),a.send(void 0===u.o?null:u.o)})}T.polyfill=!0,i.fetch||(i.fetch=T,i.Headers=f,i.Request=y,i.Response=_);var S,N,D="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},k={};function O(){if(N)return S;N=1;var t=function(t){return t&&t.Math===Math&&t};return S=t("object"==typeof globalThis&&globalThis)||t("object"==typeof window&&window)||t("object"==typeof self&&self)||t("object"==typeof D&&D)||t("object"==typeof S&&S)||function(){return this}()||Function("return this")()}var A,C,R,x,P,M,U,L,F={};function G(){return C?A:(C=1,A=function(t){try{return!!t()}catch(t){return!0}})}function V(){if(x)return R;x=1;var t=G();return R=!t(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})}function B(){if(M)return P;M=1;var t=G();return P=!t(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})}function z(){if(L)return U;L=1;var t=B(),i=Function.prototype.call;return U=t?i.bind(i):function(){return i.apply(i,arguments)},U}var j,H,q,K,W,X,Y,Q,J,$,Z,tt,it,nt,et,rt,st,ot,ut,at,ct,ht,dt,ft,lt,vt,mt,gt,pt,wt,yt,Et,_t,It,bt,Tt,St,Nt,Dt,kt,Ot,At={};function Ct(){return q?H:(q=1,H=function(t,i){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:i}})}function Rt(){if(W)return K;W=1;var t=B(),i=Function.prototype,n=i.call,e=t&&i.bind.bind(n,n);return K=t?e:function(t){return function(){return n.apply(t,arguments)}},K}function xt(){if(J)return Q;J=1;var t=Rt(),i=G(),n=function(){if(Y)return X;Y=1;var t=Rt(),i=t({}.toString),n=t("".slice);return X=function(t){return n(i(t),8,-1)}}(),e=Object,r=t("".split);return Q=i(function(){return!e("z").propertyIsEnumerable(0)})?function(t){return"String"===n(t)?r(t,""):e(t)}:e}function Pt(){return Z?$:(Z=1,$=function(t){return null==t})}function Mt(){if(it)return tt;it=1;var t=Pt(),i=TypeError;return tt=function(n){if(t(n))throw new i("Can't call method on "+n);return n}}function Ut(){if(et)return nt;et=1;var t=xt(),i=Mt();return nt=function(n){return t(i(n))}}function Lt(){if(st)return rt;st=1;var t="object"==typeof document&&document.all;return rt=void 0===t&&void 0!==t?function(i){return"function"==typeof i||i===t}:function(t){return"function"==typeof t}}function Ft(){if(ut)return ot;ut=1;var t=Lt();return ot=function(i){return"object"==typeof i?null!==i:t(i)}}function Gt(){if(ct)return at;ct=1;var t=O(),i=Lt();return at=function(n,e){return arguments.length<2?(r=t[n],i(r)?r:void 0):t[n]&&t[n][e];var r},at}function Vt(){if(mt)return vt;mt=1;var t,i,n=O(),e=function(){if(lt)return ft;lt=1;var t=O().navigator,i=t&&t.userAgent;return ft=i?String(i):""}(),r=n.process,s=n.Deno,o=r&&r.versions||s&&s.version,u=o&&o.v8;return u&&(i=(t=u.split("."))[0]>0&&t[0]<4?1:+(t[0]+t[1])),!i&&e&&(!(t=e.match(/Edge\/(\d+)/))||t[1]>=74)&&(t=e.match(/Chrome\/(\d+)/))&&(i=+t[1]),vt=i}function Bt(){if(pt)return gt;pt=1;var t=Vt(),i=G(),n=O().String;return gt=!!Object.getOwnPropertySymbols&&!i(function(){var i=Symbol("symbol detection");return!n(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&t&&t<41})}function zt(){if(yt)return wt;yt=1;var t=Bt();return wt=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function jt(){if(_t)return Et;_t=1;var t=Gt(),i=Lt(),n=function(){if(dt)return ht;dt=1;var t=Rt();return ht=t({}.isPrototypeOf)}(),e=zt(),r=Object;return Et=e?function(t){return"symbol"==typeof t}:function(e){var s=t("Symbol");return i(s)&&n(s.prototype,r(e))}}function Ht(){if(bt)return It;bt=1;var t=String;return It=function(i){try{return t(i)}catch(t){return"Object"}}}function qt(){if(St)return Tt;St=1;var t=Lt(),i=Ht(),n=TypeError;return Tt=function(e){if(t(e))return e;throw new n(i(e)+" is not a function")}}function Kt(){if(Dt)return Nt;Dt=1;var t=qt(),i=Pt();return Nt=function(n,e){var r=n[e];return i(r)?void 0:t(r)}}function Wt(){if(Ot)return kt;Ot=1;var t=z(),i=Lt(),n=Ft(),e=TypeError;return kt=function(r,s){var o,u;if("string"===s&&i(o=r.toString)&&!n(u=t(o,r)))return u;if(i(o=r.valueOf)&&!n(u=t(o,r)))return u;if("string"!==s&&i(o=r.toString)&&!n(u=t(o,r)))return u;throw new e("Can't convert object to primitive value")}}var Xt,Yt,Qt,Jt,$t,Zt,ti,ii,ni,ei,ri,si,oi,ui,ai,ci,hi,di,fi,li,vi,mi,gi,pi,wi={exports:{}};function yi(){if(Jt)return Qt;Jt=1;var t=O(),i=Object.defineProperty;return Qt=function(n,e){try{i(t,n,{value:e,configurable:!0,writable:!0})}catch(i){t[n]=e}return e}}function Ei(){if($t)return wi.exports;$t=1;var t=Yt?Xt:(Yt=1,Xt=!1),i=O(),n=yi(),e="__core-js_shared__",r=wi.exports=i[e]||n(e,{});return(r.versions||(r.versions=[])).push({version:"3.50.0",mode:t?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.50.0/LICENSE",source:"https://github.com/zloirock/core-js"}),wi.exports}function _i(){if(ti)return Zt;ti=1;var t=Ei(),i=Object.create||Object;return Zt=function(n,e){return t[n]||(t[n]=e||i(null))}}function Ii(){if(ni)return ii;ni=1;var t=Mt(),i=Object;return ii=function(n){return i(t(n))}}function bi(){if(ri)return ei;ri=1;var t=Rt(),i=Ii(),n=t({}.hasOwnProperty);return ei=Object.hasOwn||function(t,e){return n(i(t),e)}}function Ti(){if(oi)return si;oi=1;var t=Rt(),i=0,n=Math.random(),e=t(1.1.toString);return si=function(t){return"Symbol("+(void 0===t?"":t)+")_"+e(++i+n,36)}}function Si(){if(ai)return ui;ai=1;var t=O(),i=_i(),n=bi(),e=Ti(),r=Bt(),s=zt(),o=t.Symbol,u=i("wks"),a=s?o.for||o:o&&o.withoutSetter||e;return ui=function(t){return n(u,t)||(u[t]=r&&n(o,t)?o[t]:a("Symbol."+t)),u[t]}}function Ni(){if(hi)return ci;hi=1;var t=z(),i=Ft(),n=jt(),e=Kt(),r=Wt(),s=Si(),o=TypeError,u=s("toPrimitive");return ci=function(s,a){if(!i(s)||n(s))return s;var c,h=e(s,u);if(h){if(void 0===a&&(a="default"),c=t(h,s,a),!i(c)||n(c))return c;throw new o("Can't convert object to primitive value")}return void 0===a&&(a="number"),r(s,a)}}function Di(){if(fi)return di;fi=1;var t=Ni(),i=jt();return di=function(n){var e=t(n,"string");return i(e)?e:e+""}}function ki(){if(vi)return li;vi=1;var t=O(),i=Ft(),n=t.document,e=i(n)&&i(n.createElement);return li=function(t){return e?n.createElement(t):{}}}function Oi(){if(gi)return mi;gi=1;var t=V(),i=G(),n=ki();return mi=!t&&!i(function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a})}function Ai(){if(pi)return F;pi=1;var t=V(),i=z(),n=function(){if(j)return At;j=1;var t={}.propertyIsEnumerable,i=Object.getOwnPropertyDescriptor,n=i&&!t.call({1:2},1);return At.f=n?function(t){var n=i(this,t);return!!n&&n.enumerable}:t,At}(),e=Ct(),r=Ut(),s=Di(),o=bi(),u=Oi(),a=Object.getOwnPropertyDescriptor;return F.f=t?a:function(t,c){if(t=r(t),c=s(c),u)try{return a(t,c)}catch(t){}if(o(t,c))return e(!i(n.f,t,c),t[c])},F}var Ci,Ri,xi,Pi,Mi,Ui,Li,Fi={};function Gi(){if(Ri)return Ci;Ri=1;var t=V(),i=G();return Ci=t&&i(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})}function Vi(){if(Pi)return xi;Pi=1;var t=Ft(),i=String,n=TypeError;return xi=function(e){if(t(e))return e;throw new n(i(e)+" is not an object")}}function Bi(){if(Mi)return Fi;Mi=1;var t=V(),i=Oi(),n=Gi(),e=Vi(),r=Di(),s=TypeError,o=Object.defineProperty,u=Object.getOwnPropertyDescriptor,a="enumerable",c="configurable",h="writable";return Fi.f=t?n?function(t,i,n){if(e(t),i=r(i),e(n),"function"==typeof t&&"prototype"===i&&"value"in n&&h in n&&!n[h]){var s=u(t,i);s&&s[h]&&(t[i]=n.value,n={configurable:c in n?n[c]:s[c],enumerable:a in n?n[a]:s[a],writable:!1})}return o(t,i,n)}:o:function(t,n,u){if(e(t),n=r(n),e(u),i)try{return o(t,n,u)}catch(t){}if("get"in u||"set"in u)throw new s("Accessors not supported");return"value"in u&&(t[n]=u.value),t},Fi}function zi(){if(Li)return Ui;Li=1;var t=V(),i=Bi(),n=Ct();return Ui=t?function(t,e,r){return i.f(t,e,n(1,r))}:function(t,i,n){return t[i]=n,t}}var ji,Hi,qi,Ki,Wi,Xi,Yi,Qi,Ji,$i,Zi,tn,nn,en,rn,sn={exports:{}};function on(){if(Ki)return qi;Ki=1;var t=Rt(),i=Lt(),n=Ei(),e=t(Function.toString);return i(n.inspectSource)||(n.inspectSource=function(t){return e(t)}),qi=n.inspectSource}function un(){if(Qi)return Yi;Qi=1;var t=_i(),i=Ti(),n=t("keys");return Yi=function(t){return n[t]||(n[t]=i(t))}}function an(){return $i?Ji:($i=1,Ji={})}function cn(){if(tn)return Zi;tn=1;var t,i,n,e=function(){if(Xi)return Wi;Xi=1;var t=O(),i=Lt(),n=t.WeakMap;return Wi=i(n)&&/native code/.test(String(n))}(),r=O(),s=Ft(),o=zi(),u=bi(),a=Ei(),c=un(),h=an(),d="Object already initialized",f=r.TypeError,l=r.WeakMap;if(e||a.state){var v=a.state||(a.state=new l);v.get=v.get,v.has=v.has,v.set=v.set,t=function(t,i){if(v.has(t))throw new f(d);return i.facade=t,v.set(t,i),i},i=function(t){return v.get(t)||{}},n=function(t){return v.has(t)}}else{var m=c("state");h[m]=!0,t=function(t,i){if(u(t,m))throw new f(d);return i.facade=t,o(t,m,i),i},i=function(t){return u(t,m)?t[m]:{}},n=function(t){return u(t,m)}}return Zi={set:t,get:i,has:n,enforce:function(e){return n(e)?i(e):t(e,{})},getterFor:function(t){return function(n){var e;if(!s(n)||(e=i(n)).type!==t)throw new f("Incompatible receiver, "+t+" required");return e}}}}function hn(){if(nn)return sn.exports;nn=1;var t=Rt(),i=G(),n=Lt(),e=bi(),r=V(),s=function(){if(Hi)return ji;Hi=1;var t=V(),i=bi(),n=Function.prototype,e=t&&Object.getOwnPropertyDescriptor,r=i(n,"name"),s=r&&"something"===function(){}.name,o=r&&(!t||t&&e(n,"name").configurable);return ji={EXISTS:r,PROPER:s,CONFIGURABLE:o}}().CONFIGURABLE,o=on(),u=cn(),a=u.enforce,c=u.get,h=String,d=Object.defineProperty,f=t("".slice),l=t("".replace),v=t([].join),m=r&&!i(function(){return 8!==d(function(){},"length",{value:8}).length}),g=String(String).split("String"),p=sn.exports=function(t,i,n){"Symbol("===f(h(i),0,7)&&(i="["+l(h(i),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(i="get "+i),n&&n.setter&&(i="set "+i),(!e(t,"name")||s&&t.name!==i)&&(r?d(t,"name",{value:i,configurable:!0}):t.name=i),m&&n&&e(n,"arity")&&t.length!==n.arity&&d(t,"length",{value:n.arity});try{n&&e(n,"constructor")&&n.constructor?r&&d(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var o=a(t);return e(o,"source")||(o.source=v(g,"string"==typeof i?i:"")),t};return Function.prototype.toString=p(function(){return n(this)&&c(this).source||o(this)},"toString"),sn.exports}function dn(){if(rn)return en;rn=1;var t=Lt(),i=Bi(),n=hn(),e=yi();return en=function(r,s,o,u){u||(u={});var a=u.enumerable,c=void 0!==u.name?u.name:s;if(t(o)&&n(o,c,u),u.global)a?r[s]=o:e(s,o);else{try{u.unsafe?r[s]&&(a=!0):delete r[s]}catch(t){}a?r[s]=o:i.f(r,s,{value:o,enumerable:!1,configurable:!u.nonConfigurable,writable:!u.nonWritable})}return r}}var fn,ln,vn,mn,gn,pn,wn,yn,En,_n,In,bn,Tn,Sn,Nn,Dn,kn,On={};function An(){if(mn)return vn;mn=1;var t=function(){if(ln)return fn;ln=1;var t=Math.ceil,i=Math.floor;return fn=Math.trunc||function(n){var e=+n;return(e>0?i:t)(e)}}();return vn=function(i){var n=+i;return n!=n||0===n?0:t(n)}}function Cn(){if(pn)return gn;pn=1;var t=An(),i=Math.max,n=Math.min;return gn=function(e,r){var s=t(e);return s<0?i(s+r,0):n(s,r)}}function Rn(){if(yn)return wn;yn=1;var t=An(),i=Math.min;return wn=function(n){var e=t(n);return e>0?i(e,9007199254740991):0}}function xn(){if(_n)return En;_n=1;var t=Rn();return En=function(i){return t(i.length)}}function Pn(){if(bn)return In;bn=1;var t=Ut(),i=Cn(),n=xn(),e=function(e){return function(r,s,o){var u=t(r),a=n(u);if(0===a)return!e&&-1;var c,h=i(o,a);if(e&&s!=s){for(;a>h;)if((c=u[h++])!=c)return!0}else for(;a>h;h++)if((e||h in u)&&u[h]===s)return e||h||0;return!e&&-1}};return In={includes:e(!0),indexOf:e(!1)}}function Mn(){if(Sn)return Tn;Sn=1;var t=Rt(),i=bi(),n=Ut(),e=Pn().indexOf,r=an(),s=t([].push);return Tn=function(t,o){var u,a=n(t),c=0,h=[];for(u in a)!i(r,u)&&i(a,u)&&s(h,u);for(;o.length>c;)i(a,u=o[c++])&&(~e(h,u)||s(h,u));return h}}function Un(){return Dn?Nn:(Dn=1,Nn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}var Ln,Fn,Gn,Vn,Bn,zn,jn,Hn,qn,Kn={};function Wn(){if(Gn)return Fn;Gn=1;var t=Gt(),i=Rt(),n=function(){if(kn)return On;kn=1;var t=Mn(),i=Un().concat("length","prototype");return On.f=Object.getOwnPropertyNames||function(n){return t(n,i)},On}(),e=(Ln||(Ln=1,Kn.f=Object.getOwnPropertySymbols),Kn),r=Vi(),s=i([].concat);return Fn=t("Reflect","ownKeys")||function(t){var i=n.f(r(t)),o=e.f;return o?s(i,o(t)):i}}function Xn(){if(Bn)return Vn;Bn=1;var t=bi(),i=Wn(),n=Ai(),e=Bi();return Vn=function(r,s,o){for(var u=i(s),a=e.f,c=n.f,h=0;h<u.length;h++){var d=u[h];t(r,d)||o&&t(o,d)||a(r,d,c(s,d))}}}function Yn(){if(qn)return Hn;qn=1;var t=O(),i=Ai().f,n=zi(),e=dn(),r=yi(),s=Xn(),o=function(){if(jn)return zn;jn=1;var t=G(),i=Lt(),n=/#|\.prototype\./,e=function(n,e){var a=s[r(n)];return a===u||a!==o&&(i(e)?t(e):!!e)},r=e.normalize=function(t){return String(t).replace(n,".").toLowerCase()},s=e.data={},o=e.NATIVE="N",u=e.POLYFILL="P";return zn=e}();return Hn=function(u,a){var c,h,d,f,l,v=u.target,m=u.global,g=u.stat;if(c=m?t:g?t[v]||r(v,{}):t[v]&&t[v].prototype)for(h in a){if(f=a[h],d=u.dontCallGetSet?(l=i(c,h))&&l.value:c[h],!o(m?h:v+(g?".":"#")+h,u.forced)&&void 0!==d){if(typeof f==typeof d)continue;s(f,d)}(u.sham||d&&d.sham)&&n(f,"sham",!0),e(c,h,f,u)}}}var Qn,Jn,$n,Zn,te,ie,ne,ee,re,se,oe={};function ue(){if(Jn)return Qn;Jn=1;var t=Mn(),i=Un();return Qn=Object.keys||function(n){return t(n,i)}}function ae(){if(te)return Zn;te=1;var t=Gt();return Zn=t("document","documentElement")}function ce(){if(ne)return ie;ne=1;var t,i=Vi(),n=function(){if($n)return oe;$n=1;var t=V(),i=Gi(),n=Bi(),e=Vi(),r=Ut(),s=ue();return oe.f=t&&!i?Object.defineProperties:function(t,i){e(t);for(var o,u=r(i),a=s(i),c=a.length,h=0;c>h;)n.f(t,o=a[h++],u[o]);return t},oe}(),e=Un(),r=an(),s=ae(),o=ki(),u=un(),a="prototype",c="script",h=u("IE_PROTO"),d=function(){},f=function(t){return"<"+c+">"+t+"</"+c+">"},l=function(t){t.write(f("")),t.close();var i=t.parentWindow.Object;return t=null,i},v=function(){try{t=new ActiveXObject("htmlfile")}catch(t){}var i,n,r;v="undefined"!=typeof document?document.domain&&t?l(t):(n=o("iframe"),r="java"+c+":",n.style.display="none",s.appendChild(n),n.src=String(r),(i=n.contentWindow.document).open(),i.write(f("document.F=Object")),i.close(),i.F):l(t);for(var u=e.length;u--;)delete v[a][e[u]];return v()};return r[h]=!0,ie=Object.create||function(t,e){var r;return null!==t?(d[a]=i(t),r=new d,d[a]=null,r[h]=t):r=v(),void 0===e?r:n.f(r,e)}}function he(){if(re)return ee;re=1;var t=Si(),i=ce(),n=Bi().f,e=t("unscopables"),r=Array.prototype;return void 0===r[e]&&n(r,e,{configurable:!0,value:i(null)}),ee=function(t){r[e][t]=!0}}!function(){if(se)return k;se=1;var t=Yn(),i=Pn().includes,n=G(),e=he(),r=n(function(){return!Array(1).includes()}),s=n(function(){return[,1].includes(void 0,1)});t({target:"Array",proto:!0,forced:r||s},{includes:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}}),e("includes")}();var de=function(t,i){return de=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])},de(t,i)};function fe(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}de(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var le=function(){return le=Object.assign||function(t){for(var i,n=1,e=arguments.length;n<e;n++)for(var r in i=arguments[n])Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r]);return t},le.apply(this,arguments)};function ve(t,i,n,e){return new(n||(n=Promise))(function(r,s){function o(t){try{a(e.next(t))}catch(t){s(t)}}function u(t){try{a(e.throw(t))}catch(t){s(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n(function(t){t(i)})).then(o,u)}a((e=e.apply(t,i||[])).next())})}function me(t,i){var n,e,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=u(0),o.throw=u(1),o.return=u(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function ge(t){var i="function"==typeof Symbol&&Symbol.iterator,n=i&&t[i],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}function pe(t,i){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var e,r,s=n.call(t),o=[];try{for(;(void 0===i||i-- >0)&&!(e=s.next()).done;)o.push(e.value)}catch(t){r={error:t}}finally{try{e&&!e.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return o}function we(t,i,n){if(n||2===arguments.length)for(var e,r=0,s=i.length;r<s;r++)!e&&r in i||(e||(e=Array.prototype.slice.call(i,0,r)),e[r]=i[r]);return t.concat(e||Array.prototype.slice.call(i))}"function"==typeof SuppressedError&&SuppressedError;var ye="/api/v1/web/events",Ee="/api/v1/web/userEvents",_e="/sdk/v2/config",Ie="/sdk/v2/visitors",be="/sdk/v2/visitors",Te="/sdk/v2/visitors/merge",Se="/api/v1/websdk/dlr",Ne=18e5,De={STATUSES:{PENDING:"pending"},BATCH_SIZE:50,DEFAULT_RETRY_DELAYS:[6e4,12e4,24e4,48e4,9e5],RETRYABLE_HTTP_CODES:[408,429,500,502,503,504,401],GLOBAL_SUCCESS_CODE:202,PARTIAL_SUCCESS_CODE:201,DLR_SUCCESS_CODE:200},ke="/firebase-messaging-sw.js",Oe={USER_CONTEXT:"websdk_user_context",VISITOR_ID:"websdk_visitor_id",VISITOR_EXTERNAL_ID:"websdk_visitor_external_id",VISITOR_EXPIRED_AT:"websdk_visitor_expired_at",VISITOR_CONFIG:"websdk_visitor_config",FCM_TOKEN:"websdk_fcm_token",FCM_TOKEN_CREATED_AT:"websdk_fcm_token_created_at",NOTIFICATION_STATE:"websdk_notification_state",SESSION_ID:"websdk_session_id",SESSION_START_TIME:"websdk_session_start_time",LAST_EVENT_TIME:"websdk_last_event_time",LAST_AUTHENTICATED_USER:"websdk_last_authenticated_user",MERGED_USER_ID:"websdk_merged_user_id",PENDING_MERGE:"websdk_pending_merge",SESSION_NUMBER:"websdk_session_number"};function Ae(t,i,n){var e=Oe[t],r=[];return i&&r.push(i),n&&r.push(n),r.length>0?"".concat(r.join("_"),"_").concat(e):e}var Ce="websdk_storage_test",Re="test_value",xe={REQUEST_TIMEOUT_MS:15e3,SENSITIVE_LOG_KEYS:["writeKey","token","accessToken","refreshToken","password"]},Pe="INIT_ERROR",Me="AUTH_ERROR",Ue="NETWORK_ERROR",Le="EVENT_ERROR",Fe="VISITOR_CONFIG_ERROR",Ge="WebSDK initialized successfully",Ve="Failed to initialize WebSDK",Be="WebSDK destroyed successfully",ze="Failed to destroy WebSDK",je="Storage initialization failed",He="Failed to restore persisted page-path-tracking preference",qe="Failed to restore persisted gamification-suppression preference",Ke="Failed to restore persisted gamification theme",We="Session initialization failed",Xe="Visitor config initialization failed",Ye="Event tracker initialization failed",Qe="Failed to restore user context",Je="Failed to sync event tracker context",$e="DLR setup failed",Ze="EventQueue initialized successfully",tr="EventTracker initialized successfully",ir="EventTracker destroyed successfully",nr="Event added to queue",er="Failed to track event",rr="Events sent successfully",sr="Failed to send events",or="User event sent successfully",ur="Failed to send user event",ar="Failed to send batch",cr="Starting queue processing",hr="Queue processing completed",dr="Queue processing failed",fr="Queue processing already in progress, skipping",lr="No pending events to process",vr="No more pending events",mr="Failed to mark event as processing",gr="Failed to remove events from storage",pr="Failed to initialize storage:",wr="Storage test failed:",yr="Storage read/write test failed",Er="StorageManager destroyed successfully",_r="Error during storage cleanup:",Ir="New session started",br="Session continued",Tr="Session expired due to inactivity",Sr="Session ended on user switch (different user login)",Nr="Session ended on signout",Dr="Session restored from storage",kr="Failed to track user signin event",Or="Failed to track user signup event",Ar="Failed to track user update event",Cr="Failed to track user signout event",Rr="Failed to track behavioral event",xr="VisitorConfigManager initialized successfully",Pr="Visitor config fetched successfully",Mr="Failed to fetch visitor config",Ur="Visitor tracking is disabled",Lr="Visitor tracking is enabled",Fr="Visitor config retrieved from cache",Gr="AnonymousVisitorManager initialized successfully",Vr="Visitor ID generated successfully",Br="Failed to generate visitor ID",zr="Visitor ID restored from storage",jr="Using cached visitor ID",Hr="Visitor updated successfully",qr="Failed to update visitor",Kr="Visitor merged with user successfully",Wr="Failed to merge visitor with user",Xr="Visitor merge skipped",Yr="Notification permission denied by user",Qr="Notification manager initialized successfully",Jr="Failed to initialize notification manager",$r="Notification initialization skipped (disabled or not supported)",Zr="Firebase initialized successfully",ts="Failed to initialize Firebase",is="FCM token received successfully",ns="FCM token refreshed",es="Failed to retrieve FCM token",rs="Service worker registered successfully",ss="Failed to register service worker",os="Service worker not supported in this browser",us="FirebaseManager already initialized",as="FirebaseManager not initialized",cs="No service worker found in registration",hs="Service worker registration required for FCM - no token obtained",ds="getToken() returned no token despite notifications being enabled - permission may have been revoked externally, VAPID key may be invalid, or this may be transient",fs="Failed to setup message listener",ls="FCM message payload has neither notification nor data",vs="onMessageReceived callback threw",ms="Notifications not supported in this browser",gs="Firebase Messaging instance not provided - notifications disabled",ps="Failed to restore notification state",ws="Failed to save notification state",ys="Failed to initialize Firebase for messaging",Es="Failed to store FCM token",_s="Failed to retrieve FCM token creation date",Is="Cannot refresh token - notifications not enabled",bs="Failed to refresh FCM token",Ts="Failed to clear notification state",Ss="Permission revoked - clearing FCM token",Ns="Failed to destroy NotificationManager",Ds="DLR events sent successfully",ks="Failed to send DLR events",Os="web",As="user_signin",Cs="user_update",Rs="user_signout",xs="scroll_depth",Ps=[25,50,75,90],Ms=30,Us=3e3,Ls={WEBPUSH:"WEBPUSH"},Fs={WEB:"web"},Gs={ACCOUNT_NOT_EXISTS:2432,ACCOUNT_ID_NOT_PASSED:9999},Vs={ALREADY_MERGED:"1429",VISITOR_NOT_FOUND:"1428"},Bs={NOTIFICATION_RECEIVED:"push_notification_received",NOTIFICATION_CLICKED:"push_notification_click",NOTIFICATION_DISMISSED:"push_notification_close"},zs="fcm",js="push",Hs="1.10.5",qs="GamificationManager initialized successfully",Ks="Failed to initialize GamificationManager",Ws="GamificationManager destroyed successfully",Xs="GamificationManager state cleared",Ys="Gamification disabled — gamificationWriteKey not configured",Qs="GamificationManager refresh triggered",Js="GamificationManager data resync triggered",$s="GamificationManager data resync failed",Zs="GamificationManager loaded from cache — API call skipped",to="GamificationManager cache miss — fetching from API",io="GamificationManager reused cached token — token API call skipped",no="GamificationManager token cache miss — fetching new token",eo="GamificationManager got an auth error on campaigns/entry points — invalidating cached token and retrying once",ro="GamificationManager token refetch is in backoff after repeated failures — skipping network call",so="GamificationManager token refetch failed, entering backoff",oo="GamificationManager failed to handle an ACTION_EVENT trigger",uo="Failed to persist gamification-suppression preference",ao="Content-initiated open skipped — gamification is suppressed",co="Failed to persist gamification theme preference",ho="Failed to read session-dismissal record",fo="Failed to persist session-dismissal record",lo="Failed to persist pending ACTION_EVENT queue",vo="Failed to restore pending ACTION_EVENT queue",mo="Entry point with unresolvable _id present in entryPointMap",go="Failed to construct entry point instance",po="Expected a string field in analytics payload",wo="Failed to persist gamification token cache",yo="Gamification token cache miss: failed to read/parse cached entry",Eo="Gamification cache miss: no cached entry",_o="Gamification cache miss: entry expired",Io="Gamification cache miss: failed to read/parse cached entry",bo="Failed to persist gamification cache",To="Failed to read entry point count state",So="Failed to persist entry point count state",No="Failed to reconcile stale entry point state against refreshed server config",Do="GAME_PLAYED",ko="CAMPAIGN_PLAY",Oo="NO_GAME_CONFIGURED",Ao="game_open",Co="game_viewed",Ro="game_played",xo="game_completed",Po="reward_seen",Mo="content_open",Uo="content_viewed",Lo="LOYALTY",Fo="COMPLETED",Go="ACTION_EVENT",Vo="https://api.customerglu.com",Bo=function(t){return"https://api-".concat(t,".customerglu.com")},zo=3e5,jo=18e5,Ho="__GLU__CACHE__",qo="__GLU__TOKEN__",Ko="__GLU__COUNT_DATE_",Wo="__GLU__QUEUE__",Xo="__GLU__SESSION_DISMISSED_",Yo=16,Qo={LOGGED_IN:"loggedIn"},Jo={EVENT_NAME:"event_name",REWARD_TYPE:"reward_type",CAMPAIGN_ID:"campaign_id",CAMPAIGN_DETAILS:"campaign_details",REWARD_STATUS:"reward_status",REWARD_USER_ID:"reward_user_id"},$o=1e3,Zo=16e3,tu=2e3,iu=3e5,nu="glu_cap_token",eu="glu_page_path_tracking_enabled",ru="glu_gamification_suppressed",su="glu_gamification_theme",ou="/preload/",uu=5e3,au="__GLU__ORIGIN__",cu=new Set(xe.SENSITIVE_LOG_KEYS.map(function(t){return t.toLowerCase()}));function hu(t){return Array.isArray(t)?t.map(hu):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).map(function(t){var i=pe(t,2),n=i[0],e=i[1];return[n,cu.has(n.toLowerCase())?"[REDACTED]":hu(e)]})):t}var du=function(){function t(t,i){this.baseUrl=t.baseUrl.replace(/\/$/,""),this.logger=i}return t.prototype.request=function(t){return ve(this,arguments,void 0,function(t,i){var n,e,r,s,o,u,a,c,h,d,f,l,v,m,g,p,w;return void 0===i&&(i={}),me(this,function(y){switch(y.label){case 0:n=i.method,e=void 0===n?"GET":n,r=i.headers,s=void 0===r?{}:r,o=i.body,u=!t||t.startsWith("/")?t:"/".concat(t),a="".concat(this.baseUrl).concat(u),c=Date.now(),h=!1,d=hu(o),this.logger.debug("HTTP request started",{method:e,url:a,requestBody:d}),f=new AbortController,l=setTimeout(function(){return f.abort()},xe.REQUEST_TIMEOUT_MS),y.label=1;case 1:return y.trys.push([1,6,7,8]),v={method:e,headers:le({"Content-Type":"application/json"},s),body:o?JSON.stringify(o):null,signal:f.signal},[4,fetch(a,v)];case 2:return(m=y.sent()).ok?[3,4]:[4,m.text()];case 3:throw g=y.sent(),h=!0,this.logger.error("HTTP request failed",{method:e,url:a,status:m.status,durationMs:Date.now()-c,requestBody:d,responseBody:g}),new Error("HTTP ".concat(m.status,": ").concat(m.statusText," - ").concat(g));case 4:return[4,m.json()];case 5:return p=y.sent(),this.logger.debug("HTTP request succeeded",{method:e,url:a,status:m.status,durationMs:Date.now()-c,requestBody:d,responseBody:hu(p)}),[2,p];case 6:throw w=y.sent(),h||this.logger.error("HTTP request failed",{method:e,url:a,durationMs:Date.now()-c,requestBody:d,error:w}),this.handleError(w);case 7:return clearTimeout(l),[7];case 8:return[2]}})})},t.prototype.handleError=function(t){return t instanceof Error?"AbortError"===t.name?{code:Ue,message:"Request timeout",details:t}:t.message.includes("HTTP 401")||t.message.includes("HTTP 403")?{code:Me,message:"Authentication failed",details:t}:(t.message.includes("HTTP"),{code:Ue,message:t.message,details:t}):{code:Ue,message:"Unknown error: ".concat(String(t)),details:t}},t.prototype.get=function(t){return ve(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),me(this,function(n){return[2,this.request(t,le(le({},i),{method:"GET"}))]})})},t.prototype.post=function(t,i){return ve(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),me(this,function(e){return[2,this.request(t,le(le({},n),{method:"POST",body:i}))]})})},t.prototype.put=function(t,i){return ve(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),me(this,function(e){return[2,this.request(t,le(le({},n),{method:"PUT",body:i}))]})})},t.prototype.delete=function(t){return ve(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),me(this,function(n){return[2,this.request(t,le(le({},i),{method:"DELETE"}))]})})},t}(),fu="/user/v1/user/sdk",lu="/reward/v1.1/user",vu="/entrypoints/v1/list",mu=function(){function t(t,i){this.http=new du({baseUrl:t},i),this.logger=i}return t.prototype.getToken=function(t,i,n,e,r){return ve(this,void 0,void 0,function(){var s,o=this;return me(this,function(u){return s=le(le(le(le(le(le({writeKey:t,userId:i,userState:n,appType:"WEB",sdkVersion:Hs},e&&{anonymousId:e}),(null==r?void 0:r.name)&&{name:r.name}),(null==r?void 0:r.email)&&{email:r.email}),(null==r?void 0:r.mobile)&&{mobile:r.mobile}),(null==r?void 0:r.country)&&{country:r.country}),(null==r?void 0:r.customAttributes)&&{customAttributes:r.customAttributes}),this.logger.info("Fetching gamification token",{userId:i,userState:n}),[2,this.withRetry(function(){return ve(o,void 0,void 0,function(){var t;return me(this,function(e){switch(e.label){case 0:return[4,this.http.post("".concat(fu,"?token=true"),s)];case 1:return t=e.sent(),this.logger.info("Gamification token fetched successfully",{userId:i,userState:n}),[2,t.data.token]}})})},"getToken")]})})},t.prototype.getCampaigns=function(t){return ve(this,void 0,void 0,function(){var i=this;return me(this,function(n){return this.logger.info("Fetching gamification campaigns"),[2,this.withRetry(function(){return ve(i,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return[4,this.http.get(lu,{headers:{Authorization:"Bearer ".concat(t)}})];case 1:return i=e.sent(),n=this.normalizeCampaigns(i),this.logger.info("Gamification campaigns fetched successfully",{campaignCount:n.allIds.length,loyaltyUrlCount:n.loyaltyUrls.length}),[2,n]}})})},"getCampaigns")]})})},t.prototype.getEntryPoints=function(t){return ve(this,void 0,void 0,function(){var i=this;return me(this,function(n){return this.logger.info("Fetching gamification entry points"),[2,this.withRetry(function(){return ve(i,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return[4,this.http.get("".concat(vu,"?consumer=WEB"),{headers:{Authorization:"Bearer ".concat(t)}})];case 1:return i=n.sent(),this.logger.info("Gamification entry points fetched successfully",{entryPointCount:i.data.length}),[2,i.data]}})})},"getEntryPoints")]})})},t.prototype.normalizeCampaigns=function(t){var i,n,e,r=[],s={};0===t.campaigns.length&&this.logger.warn("Campaigns response returned zero campaigns",{defaultUrl:t.defaultUrl});try{for(var o=ge(t.campaigns),u=o.next();!u.done;u=o.next()){var a=u.value;r.push(a.campaignId),s[a.campaignId]=a}}catch(t){i={error:t}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return{allIds:r,byId:s,defaultUrl:t.defaultUrl,base:this.extractBase(t.defaultUrl),loyaltyUrls:null!==(e=t.loyaltyUrls)&&void 0!==e?e:[]}},t.prototype.extractBase=function(t){try{var i=new URL(t);return"".concat(i.protocol,"//").concat(i.host)}catch(i){return this.logger.error("Failed to parse defaultUrl from campaigns response",{url:t,error:i}),""}},t.prototype.isAuthError=function(t){return"object"==typeof t&&null!==t&&t.code===Me},t.prototype.withRetry=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:e=function(e){var s,o,u;return me(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,5]),s={},[4,t()];case 1:return[2,(s.value=a.sent(),s)];case 2:if(o=a.sent(),n=o,r.logger.error("GamificationManager API call failed: ".concat(i),{attempt:e,maxRetries:5,error:o}),r.isAuthError(o))throw o;return e<5?(u=Math.min($o*Math.pow(2,e-1),Zo),[4,new Promise(function(t){return setTimeout(t,u)})]):[3,4];case 3:a.sent(),a.label=4;case 4:return[3,5];case 5:return[2]}})},r=this,s=1,u.label=1;case 1:return s<=5?[5,e(s)]:[3,4];case 2:if("object"==typeof(o=u.sent()))return[2,o.value];u.label=3;case 3:return s++,[3,1];case 4:throw n}})})},t}(),gu={EMBEDDED:"EMBED",POP_UP:"POP_UP",BOTTOM_SHEET:"BOTTOM_SHEET",ICON_BUTTON:"FLOATING",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"BANNER"};function pu(t){var i,n=(i=t.container.typeId,gu[i]);return"EMBED"===n&&"STATIC"===t.content.typeId?"BANNER":n}function wu(t){return"CAMPAIGN"===t.typeId||"NUDGE"===t.typeId&&!!t.campaignId}function yu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId?"content":wu(t.content)?"game":"ICON_BUTTON"===t.container.typeId?"content":null}function Eu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId}function _u(t){return t.toFixed(2)}function Iu(t){var i,n;return null!==(n=null!==(i=null==t?void 0:t.data)&&void 0!==i?i:t)&&void 0!==n?n:{}}function bu(t){var i=null==t?void 0:t.campaignId;if("string"==typeof i)return i;if(Array.isArray(i)){var n=i[0];if("string"==typeof n)return n}return null}function Tu(t){return t.triggerType===Go}var Su=new Set(["EMBEDDED","NATIVE_BANNER"]);function Nu(t){var i;if(!Tu(t))return null;if(Su.has(t.container.typeId))return null;var n=null===(i=t.actionEventConfig)||void 0===i?void 0:i.eventName;return"string"==typeof n&&""!==n.trim()?n:null}var Du=new Set(["POP_UP","BOTTOM_SHEET","CHAT_BOX"]);function ku(t){return Du.has(t.container.typeId)}var Ou=new Set(["http:","https:"]);function Au(t){if(!t||"undefined"==typeof window)return!1;try{return Ou.has(new URL(t,window.location.href).protocol)}catch(t){return!1}}function Cu(t){var i,n,e=t.content;if("CAMPAIGN"===e.typeId)return null!==(i=e.campaignId)&&void 0!==i?i:bu(e.conditions);if("NUDGE"===e.typeId||"PROGRAM"===e.typeId)return null!==(n=e.campaignId)&&void 0!==n?n:null;if("STATIC"===e.typeId&&e.action){var r=e.action;if("TOGGLE_CONTAINER_CONTENT"===r.type||"OPEN_CONTAINER_CONTENT"===r.type)return bu(r.content.conditions)}return null}var Ru={LAUNCHER_ICON:"ICON_BUTTON",BOTTOM_SHEET:"BOTTOM_SHEET",POP_UP:"POP_UP",EMBEDDED:"EMBEDDED",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"NATIVE_BANNER"};function xu(t){var i,n;if("string"==typeof t.m&&t.m.length>0)return t.m;try{for(var e=ge(Object.entries(t)),r=e.next();!r.done;r=e.next()){var s=pe(r.value,2),o=s[0],u=s[1];if("_id"===o&&"string"==typeof u&&u.length>0)return u}}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=e.return)&&n.call(e)}finally{if(i)throw i.error}}}function Pu(t,i){var n;return le(le(le(le(le(le(le(le(le(le({typeId:null!==(n=null==t?void 0:t.typeId)&&void 0!==n?n:""},void 0!==i&&{campaignId:i}),void 0!==(null==t?void 0:t.src)&&{src:t.src}),void 0!==(null==t?void 0:t.state)&&{state:t.state}),void 0!==(null==t?void 0:t.action)&&{action:t.action}),void 0!==(null==t?void 0:t.conditions)&&{conditions:t.conditions}),void 0!==(null==t?void 0:t.IWidgetState)&&{IWidgetState:t.IWidgetState}),void 0!==(null==t?void 0:t.widgetCss)&&{widgetCss:t.widgetCss}),void 0!==(null==t?void 0:t.progressBarIcon)&&{progressBarIcon:t.progressBarIcon}),void 0!==(null==t?void 0:t.progressMeterIcon)&&{progressMeterIcon:t.progressMeterIcon}),void 0!==(null==t?void 0:t.rootId)&&{rootId:t.rootId})}function Mu(t){var i,n,e,r,s=t.web,o=s.container,u=s.content,a=s.conditions,c=u[0],h=null==a?void 0:a.backgroundOpacity,d=null!=h?o.css.replace("{{backgroundOpacity}}",String(h)):o.css,f=null!==(n=null!==(i=null==c?void 0:c.campaignId)&&void 0!==i?i:bu(null==c?void 0:c.conditions))&&void 0!==n?n:void 0;return le(le(le(le(le(le({id:null!==(e=xu(t))&&void 0!==e?e:""},void 0!==t.name&&{name:t.name}),{container:{typeId:null!==(r=Ru[o.typeId])&&void 0!==r?r:o.typeId,css:d,height:o.height,elementHookId:o.elementId},content:Pu(c,f)}),void 0!==a&&{conditions:a}),void 0!==t.triggerType&&{triggerType:t.triggerType}),void 0!==t.actionEventConfig&&{actionEventConfig:t.actionEventConfig}),void 0!==t.createdAt&&{createdAt:t.createdAt})}function Uu(t){var i,n,e=[],r={};try{for(var s=ge(t),o=s.next();!o.done;o=s.next()){var u=Mu(o.value);e.push(u.id),r[u.id]=u}}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return{allIds:e,byId:r}}var Lu="/*";function Fu(t){return t.startsWith("#/")||t.startsWith("#!/")}function Gu(t){try{return decodeURIComponent(t)}catch(i){return t}}function Vu(t){return t.replace(/(?:^\/+)|(?:\/+$)/g,"").split("/").filter(Boolean).map(Gu)}function Bu(t){try{return new URL(t)}catch(t){return null}}function zu(t,i,n){for(var e=0;e<i.length;e++)if(t[n+e]!==i[e])return!1;return!0}function ju(t,i){if(i.length>t.length)return-1;for(var n=0;n<=t.length-i.length;n++)if(zu(t,i,n))return n;return-1}function Hu(t,i){var n=i.endsWith(Lu),e=n?i.slice(0,-2):i;if(""===e)return!1;if("/"===e)return!n&&0===t.length;var r=Vu(e),s=ju(t,r);return-1!==s&&(!n||s+r.length<t.length)}function qu(t,i){var n=function(t){var i=t.trim();if("*"===i||i===Lu)return"*";if(""===i)return"";var n=i.replace(/(?:^\/+)|(?:\/+$)/g,"");return""===n?"/":n}(i);if("*"===n)return!0;var e=t.indexOf("#"),r=-1===e?t:t.slice(0,e),s=-1===e?"":t.slice(e),o=r.replace(/\?.*$/,""),u=function(t){if(!t.startsWith("/"))return null;var i=t.lastIndexOf("/");if(i<=1)return null;var n=t.slice(1,i),e=t.slice(i+1);if(!/[*+?^${}()|[\]\\]/.test(n))return null;try{return new RegExp(n,e)}catch(t){return null}}(i.trim());if(u){var a=Fu(s)?o+s:o;return u.test(a)}var c=function(t,i){if(!/^https?:\/\//i.test(t))return null;var n=Bu(i);if(!n)return!1;var e=t.endsWith(Lu),r=Bu(e?t.slice(0,-2):t);if(!r)return!1;if(n.origin!==r.origin)return!1;if(!e)return n.pathname.replace(/\/+$/,"")===r.pathname.replace(/\/+$/,"");var s=Vu(n.pathname),o=Vu(r.pathname),u=ju(s,o);return 0===u&&u+o.length<s.length}(n,o);if(null!==c)return c;var h=Bu(t);return!!Hu(Vu(h?h.pathname:o),n)||!!Fu(s)&&Hu(Vu(s.replace(/^#!?\//,"").replace(/\?.*$/,"")),n)}function Ku(t,i){var n,e;try{for(var r=ge(i),s=r.next();!s.done;s=r.next()){if(qu(t,s.value))return!0}}catch(t){n={error:t}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(n)throw n.error}}return!1}function Wu(t,i){return"".concat(Ko).concat(null!=i?i:"anonymous","_").concat(t)}function Xu(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,n.get(Wu(t,i))];case 1:return(r=u.sent())?(s=JSON.parse(r),[2,(a=s,"object"==typeof a&&null!==a&&"number"==typeof a.count&&"string"==typeof a.date?s:null)]):[2,null];case 2:return o=u.sent(),e.error(To,{entryPointId:t,error:o}),[2,null];case 3:return[2]}var a})})}function Yu(t,i){return t.getFullYear()===i.getFullYear()&&t.getMonth()===i.getMonth()&&t.getDate()===i.getDate()}function Qu(t,i){var n,e;if(!t)return!0;var r=null!==(n=t.excludePaths)&&void 0!==n?n:[],s=null!==(e=t.includePaths)&&void 0!==e?e:[];return(!r.length||!Ku(i,r))&&!(s.length&&!Ku(i,s))}function Ju(t,i,n,e,r){return!n||!Yu(e,new Date(n.date))||(!(n.count>=i)||(r.info("Rule engine: daily refresh cap exhausted",{entryPointId:t,count:n.count,cap:i}),!1))}function $u(t,i,n,e){return!(n&&n.count>=i)||(e.info("Rule engine: lifetime cap exhausted",{entryPointId:t,count:n.count,cap:i}),!1)}function Zu(t,i,n,e,r){return ve(this,void 0,void 0,function(){var s,o,u,a,c,h,d,f,l,v,m;return me(this,function(g){switch(g.label){case 0:return null===(s=t.conditions)?(e.info("Rule engine: conditions explicitly null - never show",{entryPointId:t.id}),[2,!1]):s?(o=s.paths,u=s.showCount,a=s.timeWindow,c=s.isLoggedIn,h=s.backendValidations,d=new Date,f=null!=r?r:"undefined"!=typeof window?window.location.href:"",c&&!i?(e.info("Rule engine: requires login, no userId",{entryPointId:t.id}),[2,!1]):function(t,i){if(!t)return!0;var n=i.valueOf();return n>=new Date(t.start).valueOf()&&n<=new Date(t.end).valueOf()}(a,d)?Tu(t)||Qu(o,f)?"INVALID"===h?(e.info("Rule engine: backend validation invalid",{entryPointId:t.id}),[2,!1]):Tu(t)?(e.info("Rule engine: frequency cap skipped for ACTION_EVENT entry",{entryPointId:t.id}),[2,!0]):u?(l=u.count,v=u.dailyRefresh,[4,Xu(t.id,i,n,e)]):(e.info("Rule engine: no frequency cap configured - show",{entryPointId:t.id}),[2,!0]):(e.info("Rule engine: path not allowed",{entryPointId:t.id,currentHref:f,paths:o}),[2,!1]):(e.info("Rule engine: outside time window",{entryPointId:t.id,timeWindow:a}),[2,!1])):(e.info("Rule engine: no conditions - always show",{entryPointId:t.id}),[2,!0]);case 1:return m=g.sent(),[2,v?Ju(t.id,l,m,d,e):$u(t.id,l,m,e)]}})})}var ta=function(){function t(){this.queue=[]}return t.prototype.enqueue=function(t){var i,n,e=function(t){var i=r.queue.findIndex(function(i){return i.id===t.id});-1===i?r.queue.push(t):r.queue[i]=t},r=this;try{for(var s=ge(t),o=s.next();!o.done;o=s.next()){e(o.value)}}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}this.queue.sort(function(t,i){var n,e,r,s,o,u,a=(null!==(e=null===(n=i.conditions)||void 0===n?void 0:n.priority)&&void 0!==e?e:0)-(null!==(s=null===(r=t.conditions)||void 0===r?void 0:r.priority)&&void 0!==s?s:0);return 0!==a?a:(null!==(o=i.createdAt)&&void 0!==o?o:"").localeCompare(null!==(u=t.createdAt)&&void 0!==u?u:"")})},t.prototype.peek=function(){return this.queue[0]},t.prototype.dequeue=function(){return this.queue.shift()},t.prototype.remove=function(t){this.queue=this.queue.filter(function(i){return i.id!==t})},t.prototype.hasNext=function(){return this.queue.length>0},t.prototype.clear=function(){this.queue=[]},t.prototype.clearScreenTriggered=function(){this.queue=this.queue.filter(function(t){return Tu(t)})},t.prototype.size=function(){return this.queue.length},t.prototype.entries=function(){return this.queue},t}(),ia={iframe:{className:"__GLU__IFRAME",css:".__GLU__IFRAME{ height: 100%; width: 100%; border: none !important; outline: none; }"},hideScroll:{className:"__GLU_HIDE_SCROLL",css:".__GLU_HIDE_SCROLL::-moz-focus-inner {border: 0;} .__GLU_HIDE_SCROLL::-webkit-scrollbar {width: 0px !important;background: transparent !important;display: none !important;} .__GLU_HIDE_SCROLL {scrollbar-width: none !important;-ms-overflow-style: -ms-autohiding-scrollbar !important;}"},slideUp:{className:"__GLU__SLIDE_UP",css:".__GLU__SLIDE_UP { animation: GLU_SLIDE_UP 300ms ease-out; } @keyframes GLU_SLIDE_UP { from { opacity: 0; transform: translateY(100px); }to { opacity: 1; transform: translateY(0px); }}"},slideDown:{className:"__GLU__SLIDE_DOWN",css:".__GLU__SLIDE_DOWN { animation: GLU_SLIDE_DOWN 300ms ease-out; } @keyframes GLU_SLIDE_DOWN { from { opacity: 1; transform: translateY(0px); }to { opacity: 0; transform: translateY(100px); }}"},slideUpSheet:{className:"__GLU__SLIDE_UP_SHEET",css:".__GLU__SLIDE_UP_SHEET { animation: GLU_SLIDE_UP_SHEET 300ms ease-out; } @keyframes GLU_SLIDE_UP_SHEET { from { transform: translateY(100%); } to { transform: translateY(0px); }}"},slideDownSheet:{className:"__GLU__SLIDE_DOWN_SHEET",css:".__GLU__SLIDE_DOWN_SHEET { animation: GLU_SLIDE_DOWN_SHEET 300ms ease-out forwards; } @keyframes GLU_SLIDE_DOWN_SHEET { from { transform: translateY(0px); } to { transform: translateY(100%); }}"},iconButton:{className:"__GLU__ICON_BUTTON",css:".__GLU__ICON_BUTTON { position: fixed; bottom: 40px; left: 40px; height: 160px; width: 160px; overflow: hidden; z-index: 999;}"},chatBox:{className:"__GLU__CHAT_BOX",css:function(t){return".__GLU__CHAT_BOX { position: fixed; bottom: 130px; left: 40px; height: 580px; max-height: 580px; width: 360px; background-color: ".concat(t," !important; border-radius: 24px; overflow-x: hidden; z-index: 9999; }")}},popUp:{className:"__GLU__POP_UP",css:function(t){return".__GLU__POP_UP { position: relative; max-height: 740px; max-width: 1000px; width: 100%; height:90%; background-color: ".concat(t," !important; border-radius: 12px; z-index: 999999; overflow: hidden;}")}},popUpStatic:{className:"__GLU__POP_UP_STATIC",css:function(t){return".__GLU__POP_UP_STATIC { position: relative; max-height: 100%; max-width: 100%; background-color: ".concat(t," !important; border-radius: 12px; z-index: 999999; overflow: hidden;}")}},backDrop:{className:"__GLU__BACK_DROP",css:".__GLU__BACK_DROP { position: fixed; bottom: 0px; left: 0px; height: 100%; width: 100vw; background-color: rgba(0,0,0,0.2); display: flex; justify-content: center; align-items: center; z-index: 99999;}"},bottomSheet:{className:"__GLU__BOTTOM_SHEET",css:function(t){return".__GLU__BOTTOM_SHEET { position: relative; height: 880px; width: 600px; max-width: 100%; max-height: 100%; background-color: ".concat(t," !important; border-radius: 20px 20px 0px 0px; overflow-x: hidden; z-index: 999999; align-self: flex-end}")}},bottomSheetStatic:{className:"__GLU__BOTTOM_SHEET_STATIC",css:function(t){return".__GLU__BOTTOM_SHEET_STATIC { position: relative; max-width: 100%; max-height: 100%; background-color: ".concat(t," !important; border-radius: 20px 20px 0px 0px; overflow-x: hidden; z-index: 999999; align-self: flex-end}")}},embeddedStatic:{className:"__GLU__EMBEDDED_STATIC",css:".__GLU__EMBEDDED_STATIC { width: 100%; overflow-x: hidden; }"},embedded:{className:"__GLU__EMBEDDED",css:".__GLU__EMBEDDED { width: 100%; height: 100%; overflow-x: hidden; }"},loader:{className:"__GLU__LOADER",css:'.__GLU__LOADER { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 5; } .__GLU__LOADER::after { content: ""; width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgba(0,0,0,0.15); border-top-color: rgba(0,0,0,0.55); animation: GLU_SPIN 800ms linear infinite; } @keyframes GLU_SPIN { to { transform: rotate(360deg); } }'},closeIcon:{className:"__GLU__CLOSE_ICON",css:".__GLU__CLOSE_ICON { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; padding: 0; border: none; border-radius: 50%; background-color: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10; }"}};function na(t){var i=t?"#1E1E1E":"#fff";return Object.values(ia).map(function(t){return"function"==typeof t.css?t.css(i):t.css}).join("")}function ea(){if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();var t="undefined"!=typeof crypto?crypto:null;if(null==t?void 0:t.getRandomValues){var i=new Uint8Array(16);t.getRandomValues(i);var n=new DataView(i.buffer);return n.setUint8(6,15&n.getUint8(6)|64),n.setUint8(8,63&n.getUint8(8)|128),Array.from(i).map(function(t,i){return[4,6,8,10].includes(i)?"-".concat(t.toString(16).padStart(2,"0")):t.toString(16).padStart(2,"0")}).join("")}throw new Error("No cryptographically secure random number generator available")}function ra(t,i){var n;if("undefined"!=typeof URLSearchParams)return new URLSearchParams(t).get(i);var e=new RegExp("[?&]"+i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"=([^&#]*)"),r=t.match(e);return r?decodeURIComponent(null!==(n=r[1])&&void 0!==n?n:""):null}function sa(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){return"UTC"}}function oa(t,i){var n,e={campaignName:ra(n=window.location.search,"utm_campaign")||"",campaignSource:ra(n,"utm_source")||"",campaignMedium:ra(n,"utm_medium")||""};return{libraryName:"cap-hydra-web-sdk",libraryVersion:Hs,locale:navigator.language||navigator.languages&&navigator.languages[0]||"en-US",userAgent:navigator.userAgent||"",timezone:sa(),ip:"",campaignName:e.campaignName,campaignSource:e.campaignSource,campaignMedium:e.campaignMedium,pageUrl:window.location.href||"",pagePath:window.location.pathname||"",pageReferrer:document.referrer||"",pageTitle:document.title||"",sessionId:t,lat:i?String(i.latitude):"",long:i?String(i.longitude):""}}function ua(){try{var t=function(){var t,i;if("undefined"!=typeof navigator&&"userAgentData"in navigator){var n=navigator.userAgentData;if(n&&n.brands)try{for(var e=ge(n.brands),r=e.next();!r.done;r=e.next()){var s=r.value;if(s.brand&&"Chromium"!==s.brand&&!s.brand.startsWith("Not"))return s.brand}}catch(i){t={error:i}}finally{try{r&&!r.done&&(i=e.return)&&i.call(e)}finally{if(t)throw t.error}}}return null}();return t||("undefined"!=typeof navigator&&navigator.userAgent?(i=navigator.userAgent).includes("Firefox/")?"Firefox":i.includes("Edg/")?"Edge":i.includes("Chrome/")?"Chrome":i.includes("Safari/")&&!i.includes("Chrome")?"Safari":i.includes("Opera/")||i.includes("OPR/")?"Opera":null:null)}catch(t){return null}var i}function aa(){try{var t=function(){if("undefined"!=typeof navigator&&"userAgentData"in navigator){var t=navigator.userAgentData;if(t&&t.platform)return t.platform}return null}();return t||("undefined"!=typeof navigator&&navigator.userAgent?(i=navigator.userAgent,null!==(e=null!==(n=function(t){if(!t.includes("Mac OS X"))return null;var i=t.match(/Mac OS X ([\d_]+)/);return(null==i?void 0:i[1])?"macOS ".concat(i[1].replace(/_/g,".")):"macOS"}(i))&&void 0!==n?n:function(t){var i;if(!t.includes("Windows NT"))return null;var n=t.match(/Windows NT ([\d.]+)/);return(null==n?void 0:n[1])?"Windows ".concat(null!==(i={"10.0":"10/11",6.3:"8.1",6.2:"8",6.1:"7"}[n[1]])&&void 0!==i?i:n[1]):"Windows"}(i))&&void 0!==e?e:function(t){var i;return t.includes("iPhone")||t.includes("iPad")?(null==(i=t.match(/OS ([\d_]+)/))?void 0:i[1])?"iOS ".concat(i[1].replace(/_/g,".")):"iOS":t.includes("Android")?(i=t.match(/Android ([\d.]+)/))?"Android ".concat(i[1]):"Android":t.includes("Linux")?"Linux":null}(i)):null)}catch(n){return null}var i,n,e}function ca(){try{if("undefined"!=typeof document&&document.referrer)return function(t){var i;if("undefined"!=typeof URL)try{return new URL(t).hostname}catch(t){return"direct"}var n=t.match(/^https?:\/\/([^/?#]+)/);return n&&null!==(i=n[1])&&void 0!==i?i:"direct"}(document.referrer)}catch(t){}return"direct"}function ha(t){var i=ua(),n=aa(),e=function(){var t;try{if("undefined"!=typeof navigator)return navigator.language||(null===(t=navigator.languages)||void 0===t?void 0:t[0])||"en-US"}catch(t){}return"en-US"}(),r=function(){try{if("undefined"!=typeof Intl)return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(t){}return"UTC"}(),s=function(){try{if("undefined"!=typeof window&&window.screen)return"".concat(window.screen.width,"x").concat(window.screen.height)}catch(t){}return"0x0"}(),o=function(){try{if("undefined"!=typeof window&&window.location){var t=window.location.search;return{utmSource:ra(t,"utm_source"),utmMedium:ra(t,"utm_medium"),utmCampaign:ra(t,"utm_campaign"),utmTerm:ra(t,"utm_term"),utmContent:ra(t,"utm_content"),adsId:ra(t,"gclid")||ra(t,"fbclid")||ra(t,"msclkid")||ra(t,"ttclid")}}}catch(t){}return{utmSource:null,utmMedium:null,utmCampaign:null,utmTerm:null,utmContent:null,adsId:null}}(),u=ca(),a={sdk_version:Hs,consent:(null==t?void 0:t.notificationPermissionGranted)?"yes":"no"};return function(t,i,n,e,r,s){i&&(t.browser=i),n&&(t.os_version=n),e&&"en-US"!==e&&(t.locale=e),r&&"UTC"!==r&&(t.timezone=r),s&&"0x0"!==s&&(t.screen_resolution=s)}(a,i,n,e,r,s),function(t,i,n,e){(null==i?void 0:i.appVersion)&&(t.app_version=i.appVersion),(null==i?void 0:i.fcmTokenCreatedAt)&&(t.token_creation_date=i.fcmTokenCreatedAt),n.utmSource&&(t.utm_source=n.utmSource),n.utmMedium&&(t.utm_medium=n.utmMedium),n.utmCampaign&&(t.utm_campaign=n.utmCampaign),n.utmTerm&&(t.utm_term=n.utmTerm),n.utmContent&&(t.utm_content=n.utmContent),n.adsId&&(t.ads_id=n.adsId),e&&"direct"!==e&&(t.initial_referrer=e)}(a,t,o,u),a}var da=3e5,fa=null,la=0;function va(){return ve(this,void 0,void 0,function(){return me(this,function(t){return null!==fa&&Date.now()-la<da?[2,fa]:"undefined"!=typeof navigator&&navigator.geolocation?[2,new Promise(function(t){navigator.geolocation.getCurrentPosition(function(i){fa={latitude:i.coords.latitude,longitude:i.coords.longitude},la=Date.now(),t(fa)},function(){return t(null)},{maximumAge:da,timeout:2e3,enableHighAccuracy:!1})})]:[2,null]})})}var ma="__glu_container",ga="__glu_backdrop";function pa(){return"__GLU__"+ea().replace(/-/g,"")}function wa(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ya(t,i){var n=Math.max(0,Math.round(i)),e=parseInt(t.style.height,10)||0;Math.abs(e-n)<=1||(t.style.transition||(t.style.transition="height 300ms ease"),t.style.height="".concat(n,"px"))}var Ea=function(){function t(t,i){var n;this.rootElement=null,this.closeListener=null,this.isShown=!1,this.supportsPreload=!0,this.preloaded=!1,this.preloadStyleSnapshot=null,this.boundListeners=[],this.customStyles=[],this.destroyed=!1,this.loaderElement=null,this.config=t,this.contentElement=i,this.mountDefaultStyleOnce(null!==(n=t.darkMode)&&void 0!==n&&n)}return t.prototype.isVisible=function(){var t,i;return this.isShown&&null!==(i=null===(t=this.rootElement)||void 0===t?void 0:t.isConnected)&&void 0!==i&&i},t.prototype.mountDefaultStyleOnce=function(i){if("undefined"!=typeof document){var n=document.getElementById(t.DEFAULT_STYLE_ID);if(n)n.dataset.gluDark!==String(i)&&(n.textContent=na(i),n.dataset.gluDark=String(i));else{var e=this.mountStyle(na(i));e&&(e.setAttribute("id",t.DEFAULT_STYLE_ID),e.dataset.gluDark=String(i))}}},t.prototype.bindEvent=function(t,i,n){t.addEventListener(i,n),this.boundListeners.push({target:t,type:i,handler:n})},t.prototype.mountStyle=function(t){if("undefined"==typeof document)return null;var i=document.createElement("style");return i.textContent=t,document.head.appendChild(i),i},t.prototype.addCustomStyle=function(t){if(this.config.css){var i=function(t,i){var n,e,r=t;try{for(var s=ge(Object.entries(i)),o=s.next();!o.done;o=s.next()){var u=pe(o.value,2),a=u[0],c=u[1];r.includes(a)&&(r=r.replace(new RegExp(wa(a),"g"),c))}}catch(t){n={error:t}}finally{try{o&&!o.done&&(e=s.return)&&e.call(s)}finally{if(n)throw n.error}}return r}(this.config.css,t),n=this.mountStyle(i);n&&this.customStyles.push(n)}},t.prototype.addCloseButton=function(t){var i=this;if("undefined"!=typeof document){var n=document.createElement("button");n.type="button",n.setAttribute("aria-label","Close"),n.classList.add(ia.closeIcon.className),n.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L13 13M13 1L1 13" stroke="white" stroke-width="2" stroke-linecap="round"/></svg>',this.bindEvent(n,"click",function(t){var n;t.stopPropagation(),t.preventDefault(),null===(n=i.closeListener)||void 0===n||n.call(i)}),t.appendChild(n)}},t.prototype.preload=function(){var i,n;if(this.supportsPreload&&!this.preloaded&&!this.isShown&&this.rootElement&&"undefined"!=typeof document){this.preloaded=!0;var e={};try{for(var r=ge(t.PRELOAD_STYLE_KEYS),s=r.next();!s.done;s=r.next()){var o=s.value;e[o]=this.rootElement.style[o]}}catch(t){i={error:t}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}this.preloadStyleSnapshot=e,Object.assign(this.rootElement.style,t.HIDDEN_STYLE),document.body.appendChild(this.rootElement)}},t.prototype.clearPreloadStyles=function(){var i;this.preloaded&&this.rootElement&&(this.preloaded=!1,Object.assign(this.rootElement.style,null!==(i=this.preloadStyleSnapshot)&&void 0!==i?i:t.CLEARED_STYLE),this.preloadStyleSnapshot=null)},t.prototype.show=function(){var t,i;this.rootElement&&"undefined"!=typeof document&&(this.clearPreloadStyles(),this.rootElement.parentNode||document.body.appendChild(this.rootElement),this.isShown=!0,null===(i=(t=this.config).onShown)||void 0===i||i.call(t))},t.prototype.hide=function(){this.isShown=!1,this.rootElement&&this.rootElement.parentNode&&this.rootElement.parentNode.removeChild(this.rootElement)},t.prototype.addCloseListener=function(t){this.closeListener=t},Object.defineProperty(t.prototype,"resizableElement",{get:function(){return this.rootElement},enumerable:!1,configurable:!0}),t.prototype.setHeight=function(t){var i=this.resizableElement;i&&ya(i,t)},t.prototype.showLoader=function(){var t=this.resizableElement;if(t&&!this.loaderElement&&"undefined"!=typeof document){var i=document.createElement("div");i.classList.add(ia.loader.className),t.appendChild(i),this.loaderElement=i}},t.prototype.hideLoader=function(){var t;null===(t=this.loaderElement)||void 0===t||t.remove(),this.loaderElement=null},t.prototype.destroy=function(){var t,i,n,e,r;if(!this.destroyed){this.destroyed=!0,this.isShown=!1;try{for(var s=ge(this.boundListeners),o=s.next();!o.done;o=s.next()){var u=o.value,a=u.target,c=u.type,h=u.handler;a.removeEventListener(c,h)}}catch(i){t={error:i}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}this.boundListeners.length=0,(null===(r=this.rootElement)||void 0===r?void 0:r.parentNode)&&this.rootElement.parentNode.removeChild(this.rootElement);try{for(var d=ge(this.customStyles),f=d.next();!f.done;f=d.next()){f.value.remove()}}catch(t){n={error:t}}finally{try{f&&!f.done&&(e=d.return)&&e.call(d)}finally{if(n)throw n.error}}this.customStyles.length=0,this.closeListener=null,this.onDestroy()}},t.prototype.onDestroy=function(){},t.DEFAULT_STYLE_ID="__glu_default_style",t.PRELOAD_STYLE_KEYS=["position","left","top","visibility","pointerEvents"],t.HIDDEN_STYLE={position:"fixed",left:"-9999px",top:"-9999px",visibility:"hidden",pointerEvents:"none"},t.CLEARED_STYLE={position:"",left:"",top:"",visibility:"",pointerEvents:""},t}(),_a=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.sheetClass=pa(),r.backdropClass=pa(),r.sheetElement=null,r.height=i.height,r.createElement(),r.addCustomStyle(((e={})[ma]=r.sheetClass,e[ga]=r.backdropClass,e)),r}return fe(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.classList.add(this.backdropClass,ia.backDrop.className);var e=document.createElement("div"),r="IMG"===this.contentElement.tagName;e.classList.add(this.sheetClass,r?ia.bottomSheetStatic.className:ia.bottomSheet.className,ia.hideScroll.className),e.style.height=this.height,e.appendChild(this.contentElement),this.addCloseButton(e),this.bindEvent(e,"click",function(t){return t.stopPropagation()}),n.appendChild(e),this.bindEvent(n,"click",function(t){var n;t.stopPropagation(),t.preventDefault(),null===(n=i.closeListener)||void 0===n||n.call(i)}),this.bindEvent(n,"animationend",function(){i.isShown||t.prototype.hide.call(i)}),this.rootElement=n,this.sheetElement=e}else this.config.logger.warn("BottomSheetContainer.createElement() skipped - no document (SSR), container will not render")},Object.defineProperty(i.prototype,"resizableElement",{get:function(){return this.sheetElement},enumerable:!1,configurable:!0}),i.prototype.show=function(){this.sheetElement&&(this.sheetElement.classList.remove(ia.slideDownSheet.className),this.sheetElement.classList.add(ia.slideUpSheet.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.sheetElement&&(this.sheetElement.classList.remove(ia.slideUpSheet.className),this.sheetElement.classList.add(ia.slideDownSheet.className),this.isShown=!1)},i}(Ea),Ia=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.instanceClass=pa(),r.createElement(),r.addCustomStyle(((e={})[ma]=r.instanceClass,e)),r}return fe(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.appendChild(this.contentElement),n.classList.add(ia.chatBox.className,this.instanceClass),this.addCloseButton(n),this.bindEvent(n,"animationend",function(){i.isShown||t.prototype.hide.call(i)}),this.rootElement=n}else this.config.logger.warn("ChatBoxContainer.createElement() skipped - no document (SSR), container will not render")},i.prototype.show=function(){this.rootElement&&(this.rootElement.classList.remove(ia.slideDown.className),this.rootElement.classList.add(ia.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.rootElement&&(this.rootElement.classList.remove(ia.slideUp.className),this.rootElement.classList.add(ia.slideDown.className),this.isShown=!1)},i}(Ea),ba=[],Ta=!1,Sa=null,Na=null;function Da(t,i){Na=i,"undefined"!=typeof document&&(Ta||((Sa||(Sa=new MutationObserver(function(){var t,i;try{for(var n=ge(we([],pe(ba),!1)),e=n.next();!e.done;e=n.next()){var r=e.value;try{r()}catch(t){null==Na||Na.error("DOM observer callback failed",{error:t})}}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}})),Sa).observe(document.body,{childList:!0,subtree:!0}),Ta=!0),ba.includes(t)||ba.push(t))}function ka(t){0===(ba=ba.filter(function(i){return i!==t})).length&&Ta&&Sa&&(Sa.disconnect(),Sa=null,Ta=!1)}var Oa=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.supportsPreload=!1,r.instanceClass=pa(),r.isObserverRunning=!1,r.showOnceHookPresent=function(){var t,i;if(r.isObserverRunning&&"undefined"!=typeof document&&r.rootElement){var n=document.querySelector("#".concat(r.hookId));n&&(n.innerHTML="",n.append(r.rootElement),r.isShown=!0,null===(i=(t=r.config).onShown)||void 0===i||i.call(t),ka(r.showOnceHookPresent),r.isObserverRunning=!1)}},r.hookId=i.elementHookId,r.createElement(),r.addCustomStyle(((e={})[ma]=r.instanceClass,e)),r}return fe(i,t),i.prototype.createElement=function(){if("undefined"!=typeof document){var t=document.createElement("div");t.appendChild(this.contentElement);var i="IMG"===this.contentElement.tagName;t.classList.add(this.instanceClass,i?ia.embeddedStatic.className:ia.embedded.className),this.rootElement=t}},i.prototype.show=function(){var t,i;if("undefined"!=typeof document&&this.rootElement){var n=document.querySelector("#".concat(this.hookId));if(n)return n.innerHTML="",n.append(this.rootElement),this.isShown=!0,void(null===(i=(t=this.config).onShown)||void 0===i||i.call(t));this.isObserverRunning||(this.config.logger.info("EmbeddedContainer hook not found, waiting for it to appear",{hookId:this.hookId}),Da(this.showOnceHookPresent,this.config.logger),this.isObserverRunning=!0)}},i.prototype.hide=function(){var t;null===(t=this.rootElement)||void 0===t||t.remove(),this.isShown=!1,this.isObserverRunning&&(ka(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.onDestroy=function(){this.isObserverRunning&&(ka(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.showLoader=function(){},i.prototype.hideLoader=function(){},i}(Ea),Aa=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.instanceClass=pa(),r.createElement(),r.addCustomStyle(((e={})[ma]=r.instanceClass,e)),r}return fe(i,t),i.prototype.createElement=function(){if("undefined"!=typeof document){var t=document.createElement("div");t.appendChild(this.contentElement),t.classList.add(ia.iconButton.className,this.instanceClass),this.rootElement=t}else this.config.logger.warn("IconButtonContainer.createElement() skipped - no document (SSR), container will not render")},i.prototype.show=function(){this.rootElement&&(this.rootElement.classList.remove(ia.slideDown.className),this.rootElement.classList.add(ia.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.rootElement&&(this.rootElement.classList.remove(ia.slideUp.className),this.rootElement.classList.add(ia.slideDown.className),t.prototype.hide.call(this))},i}(Ea),Ca=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.supportsPreload=!1,r.instanceClass=pa(),r.isObserverRunning=!1,r.showOnceHookPresent=function(){var t,i;if(r.isObserverRunning&&"undefined"!=typeof document&&r.rootElement){var n=document.querySelector("#".concat(r.hookId));n&&(n.innerHTML="",n.append(r.rootElement),r.isShown=!0,null===(i=(t=r.config).onShown)||void 0===i||i.call(t),ka(r.showOnceHookPresent),r.isObserverRunning=!1)}},r.hookId=i.elementHookId,r.contentElement.classList.add(r.instanceClass),r.rootElement=r.contentElement,r.addCustomStyle(((e={})[ma]=r.instanceClass,e)),r}return fe(i,t),i.prototype.show=function(){var t,i;if("undefined"!=typeof document&&this.rootElement){var n=document.querySelector("#".concat(this.hookId));if(n)return n.innerHTML="",n.append(this.rootElement),this.isShown=!0,void(null===(i=(t=this.config).onShown)||void 0===i||i.call(t));this.isObserverRunning||(this.config.logger.info("NativeBannerContainer hook not found, waiting for it to appear",{hookId:this.hookId}),Da(this.showOnceHookPresent,this.config.logger),this.isObserverRunning=!0)}},i.prototype.hide=function(){var t;null===(t=this.rootElement)||void 0===t||t.remove(),this.isShown=!1,this.isObserverRunning&&(ka(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.onDestroy=function(){this.isObserverRunning&&(ka(this.showOnceHookPresent),this.isObserverRunning=!1)},i}(Ea),Ra=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.popupClass=pa(),r.backdropClass=pa(),r.popupElement=null,r.height=i.height,r.createElement(),r.addCustomStyle(((e={})[ma]=r.popupClass,e[ga]=r.backdropClass,e)),r}return fe(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.classList.add(this.backdropClass,ia.backDrop.className);var e=document.createElement("div"),r="IMG"===this.contentElement.tagName;e.classList.add(this.popupClass,r?ia.popUpStatic.className:ia.popUp.className,ia.hideScroll.className),e.style.height=this.height,e.appendChild(this.contentElement),this.addCloseButton(e),this.bindEvent(e,"click",function(t){return t.stopPropagation()}),n.appendChild(e),this.bindEvent(n,"click",function(t){var n;t.stopPropagation(),t.preventDefault(),null===(n=i.closeListener)||void 0===n||n.call(i)}),this.bindEvent(n,"animationend",function(){i.isShown||t.prototype.hide.call(i)}),this.rootElement=n,this.popupElement=e}else this.config.logger.warn("PopupContainer.createElement() skipped - no document (SSR), container will not render")},Object.defineProperty(i.prototype,"resizableElement",{get:function(){return this.popupElement},enumerable:!1,configurable:!0}),i.prototype.show=function(){this.popupElement&&(this.popupElement.classList.remove(ia.slideDown.className),this.popupElement.classList.add(ia.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.popupElement&&(this.popupElement.classList.remove(ia.slideUp.className),this.popupElement.classList.add(ia.slideDown.className),this.isShown=!1)},i}(Ea);function xa(t){var i=t;if("string"==typeof i)try{i=JSON.parse(i)}catch(t){return null}var n=function(t){if(!t||"object"!=typeof t)return null;var i=t.eventName;if("string"!=typeof i)return null;return{target:"GLU_SDK",action:{type:i,data:t.data}}}(i);return n||(i&&"object"==typeof i&&"GLU_SDK"===i.target?i:null)}var Pa=function(){function t(i){var n=this;this.sdkEventListener=null,this.boundListeners=[],this.headStyles=[],this.destroyed=!1,this.messageListener=function(t,i,e){var r,s,o="CLOSE_FRAME_CONTENT"===i.action.type?{target:"GLU_SDK",action:{type:"CLOSE_CONTAINER_CONTENT"}}:i;n.element instanceof HTMLIFrameElement&&t===n.element.contentWindow&&e===n.contentOrigin()?null===(r=n.sdkEventListener)||void 0===r||r.call(n,o):"UPDATE_CONTENT_STATE"===o.action.type?n.sendMessageToContent(o.action):"CLOSE_CONTAINER_CONTENT"===o.action.type&&n.sendMessageToContent({type:"UPDATE_CONTENT_STATE",data:null!==(s=o.action.data)&&void 0!==s?s:{}})},this.config=i,t.lastLogger=i.logger,t.listeners.push(this.messageListener),t.isListening||t.installWindowListener()}return t.prototype.bindEvent=function(t,i,n,e){t.addEventListener(i,n,e),this.boundListeners.push({target:t,type:i,handler:n})},t.prototype.addHeadStyle=function(t){if("undefined"!=typeof document){var i=document.createElement("style");i.textContent=t,document.head.appendChild(i),this.headStyles.push(i)}},t.prototype.destroy=function(){var i,n,e,r;if(!this.destroyed){this.destroyed=!0,t.removeListener(this.messageListener);try{for(var s=ge(this.boundListeners),o=s.next();!o.done;o=s.next()){var u=o.value,a=u.target,c=u.type,h=u.handler;a.removeEventListener(c,h)}}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}this.boundListeners.length=0;try{for(var d=ge(this.headStyles),f=d.next();!f.done;f=d.next()){f.value.remove()}}catch(t){e={error:t}}finally{try{f&&!f.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}this.headStyles.length=0,this.sdkEventListener=null,this.onDestroy()}},t.prototype.onDestroy=function(){},t.removeListener=function(i){t.listeners=t.listeners.filter(function(t){return t!==i}),0===t.listeners.length&&t.windowListener&&"undefined"!=typeof window&&(window.removeEventListener("message",t.windowListener),t.windowListener=null,t.isListening=!1)},t.parseSdkEvent=function(t){return xa(t)},t.dispatchToListeners=function(i,n,e){var r,s,o;try{for(var u=ge(t.listeners),a=u.next();!a.done;a=u.next()){var c=a.value;try{c(i,n,e)}catch(i){null===(o=t.lastLogger)||void 0===o||o.error("Content message listener threw",{error:i})}}}catch(t){r={error:t}}finally{try{a&&!a.done&&(s=u.return)&&s.call(u)}finally{if(r)throw r.error}}},t.installWindowListener=function(){if("undefined"!=typeof window){var i=function(i){var n=t.parseSdkEvent(i.data);n&&(t.dispatchToListeners(i.source,n,i.origin),i.stopPropagation())};window.addEventListener("message",i),t.windowListener=i,t.isListening=!0}},t.prototype.urlModifier=function(t,i){var n=function(t){return encodeURIComponent(String(t))},e=t.includes("?")?"&":"?";return e+="source=JS_SDK",(null==i?void 0:i.token)&&(e+="&token=".concat(n(this.config.token))),this.config.isEmbedded&&(this.config.rootId&&(e+="&rootId=".concat(n(this.config.rootId))),e+="&isEmbedded=true"),this.config.userId||(e+="¬LoggedIn=true"),void 0!==this.config.darkMode&&(e+="&darkMode=".concat(n(this.config.darkMode))),t+e},t.prototype.listen=function(t){this.sdkEventListener=t},t.prototype.reveal=function(){this.element instanceof HTMLIFrameElement&&(this.element.style.opacity="1")},t.prototype.sendMessageToContent=function(t){this.postToContentWindow({target:"GLU_SDK",action:t})},t.prototype.sendRawMessage=function(t){this.postToContentWindow(t)},t.prototype.postToContentWindow=function(t){if(this.element instanceof HTMLIFrameElement){var i=this.element.contentWindow;if(i&&"function"==typeof i.postMessage){var n=this.contentOrigin();n&&i.postMessage(t,n)}}},t.prototype.contentOrigin=function(){if(!(this.element instanceof HTMLIFrameElement&&this.element.src))return null;try{return new URL(this.element.src).origin}catch(t){return this.config.logger.warn("Could not resolve content iframe origin for postMessage",{src:this.element.src}),null}},t.listeners=[],t.isListening=!1,t.windowListener=null,t.lastLogger=null,t}(),Ma="https://api.customerglu.com/reward/v1.1/user/program/accept",Ua=["https://img.icons8.com/ios-filled/24/000000/rocket.png","https://img.icons8.com/ios-filled/24/000000/gift.png","https://img.icons8.com/ios-filled/24/000000/money.png"],La={card:"#1E1E1E",iconContainer:"#164048",heading:"#F5F5F5",notNow:"#AAAAAA"},Fa={card:"#fff",iconContainer:"#e0f7fa",heading:"#333",notNow:"#888"},Ga=function(t){function i(i,n){var e=t.call(this,n)||this;if(e.data=i,e.campaignId=e.extractCampaignId(),!e.campaignId)throw new Error("ACCEPT_GUARD content missing conditions.campaignId");if(!e.config.allCampaignsMap.byId[e.campaignId])throw new Error("ACCEPT_GUARD: campaign ".concat(e.campaignId," not present in campaign map"));return e.createElement(),e}return fe(i,t),i.prototype.extractCampaignId=function(){var t,i=null===(t=this.data.conditions)||void 0===t?void 0:t.campaignId;return"string"==typeof i?i:Array.isArray(i)&&void 0!==i[0]?String(i[0]):""},i.prototype.createElement=function(){var t,i,n,e,r,s,o=this,u=null!==(n=this.config.darkMode)&&void 0!==n&&n?La:Fa,a={container:"display: flex; justify-content: center; align-items: center;",card:"background-color: ".concat(u.card,"; text-align: center; padding: 30px 20px; max-width: 400px; width: 100%; margin: 10px;"),iconContainer:"background-color: ".concat(u.iconContainer,"; border-radius: 50%; padding: 15px; margin: 0 auto 20px; width: 100px; height: 100px; display: flex; justify-content: center; align-items: center;"),flameIcon:"width: 60px; height: 60px;",heading:"font-size: 22px; font-weight: bold; color: ".concat(u.heading,"; margin: 20px 0;"),instructions:"list-style: none; padding: 0; margin: 0 0 20px; text-align: left;",listItem:"display: flex; align-items: center; margin-bottom: 15px; font-size: 16px; color: ".concat(u.heading,";"),icon:"margin-right: 10px;",startStreakButton:"background-color: #6c63ff; color: #fff; border: none; border-radius: 25px; padding: 12px 25px; font-size: 16px; cursor: pointer; width: 80%; margin: 0 auto 10px;",notNowButton:"background: none; border: none; color: ".concat(u.notNow,"; font-size: 14px; cursor: pointer; margin-top: 5px;")},c=document.createElement("div");c.style.cssText=a.container;var h=document.createElement("div");h.style.cssText=a.card;var d=document.createElement("div");d.style.cssText=a.iconContainer;var f=document.createElement("img");f.src="https://img.icons8.com/color/96/000000/fire-element.png",f.style.cssText=a.flameIcon,d.appendChild(f);var l=document.createElement("h1");l.innerText="Can you complete a 7-day earning streak?",l.style.cssText=a.heading;var v=document.createElement("ul");v.style.cssText=a.instructions;var m=[{icon:null!==(e=Ua[0])&&void 0!==e?e:"",text:"Start a streak anytime until [DATE HERE] by earning at least $1"},{icon:null!==(r=Ua[1])&&void 0!==r?r:"",text:"Claim a bonus reward for each streak day"},{icon:null!==(s=Ua[2])&&void 0!==s?s:"",text:"Complete a 7-day streak and earn an additional up to $50 reward"}];try{for(var g=ge(m),p=g.next();!p.done;p=g.next()){var w=p.value,y=document.createElement("li");y.style.cssText=a.listItem;var E=document.createElement("img");E.src=w.icon,E.style.cssText=a.icon;var _=document.createElement("span");_.innerText=w.text,y.appendChild(E),y.appendChild(_),v.appendChild(y)}}catch(i){t={error:i}}finally{try{p&&!p.done&&(i=g.return)&&i.call(g)}finally{if(t)throw t.error}}var I=document.createElement("button");I.innerText="Earn to start your streak",I.style.cssText=a.startStreakButton,this.bindEvent(I,"click",function(){o.accept()});var b=document.createElement("button");b.innerText="Not now",b.style.cssText=a.notNowButton,this.bindEvent(b,"click",function(){var t;null===(t=o.sdkEventListener)||void 0===t||t.call(o,{target:"GLU_SDK",action:{type:"CLOSE_CONTAINER_CONTENT"}})}),h.appendChild(d),h.appendChild(l),h.appendChild(v),h.appendChild(I),h.appendChild(b),c.appendChild(h),this.element=c},i.prototype.accept=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:t={campaignId:this.campaignId,choice:"accept"},i=!1,this.config.logger.debug("ACCEPT_GUARD accept request started",{url:Ma,requestBody:t}),u.label=1;case 1:return u.trys.push([1,5,,6]),[4,fetch(Ma,{method:"POST",headers:{authorization:"Bearer ".concat(this.config.token),"content-type":"application/json"},body:JSON.stringify(t)})];case 2:return(n=u.sent()).ok?[3,4]:[4,n.text()];case 3:throw e=u.sent(),i=!0,this.config.logger.error("ACCEPT_GUARD accept request failed",{url:Ma,requestBody:t,status:n.status,responseBody:e}),new Error("Accept failed with status ".concat(n.status));case 4:return this.config.logger.info("ACCEPT_GUARD accept request succeeded",{campaignId:this.campaignId}),r={target:"GLU_SDK",action:{type:"TOGGLE_CONTAINER_CONTENT",id:pa(),content:{typeId:"CAMPAIGN",conditions:{campaignId:[this.campaignId]}},container:{typeId:"POP_UP",css:".__glu_container { \n background-color: #000; \n border-radius: 0px;\n max-width: none;\n max-height: none;\n height: 100vh;\n width: 100vw;\n } \n .__glu_backdrop { background-color: rgba(0,0,0,0.5); \n background-color: rgba(0,0,0,0.5); \n }",height:"",elementHookId:""}}},null===(o=this.sdkEventListener)||void 0===o||o.call(this,r),[3,6];case 5:return s=u.sent(),i||this.config.logger.error("ACCEPT_GUARD accept request failed",{url:Ma,requestBody:t,error:s}),[3,6];case 6:return[2]}})})},i}(Pa);function Va(t,i,n){var e=document.createElement("iframe");e.classList.add(ia.iframe.className),e.style.height="100%",e.style.width="100%",e.style.display="block",e.setAttribute("fetchpriority","high"),e.style.opacity="0",e.style.transition="opacity 150ms ease";var r=function(){e.style.opacity="1"},s=performance.now();return e.addEventListener("load",function(){r(),null==i||i(performance.now()-s)},{once:!0}),e.addEventListener("error",function(){r(),null==n||n()},{once:!0}),e.src=t,e}var Ba=function(t){function i(i,n){var e=t.call(this,n)||this,r=e.resolveUrl(i);return e.element=Va(e.urlModifier(r),n.onLoad,function(){return n.logger.error("Campaign iframe failed to load",{src:r})}),e}return fe(i,t),i.prototype.resolveUrl=function(t){var i,n,e,r=null!==(e=t.conditions)&&void 0!==e?e:{};if(0===Object.keys(r).length){if(t.campaignId)if(h=this.config.allCampaignsMap.byId[t.campaignId])return h.url;throw new Error("CAMPAIGN content has no conditions")}var s=this.config.allCampaignsMap,o=s.allIds,u=s.byId;try{for(var a=ge(o),c=a.next();!c.done;c=a.next()){var h;if((h=u[c.value])&&this.campaignMatches(h,r))return h.url}}catch(t){i={error:t}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}throw new Error("CAMPAIGN_NOT_FOUND")},i.prototype.campaignMatches=function(t,i){var n,e,r;try{for(var s=ge(Object.keys(i)),o=s.next();!o.done;o=s.next()){var u=o.value,a=i[u],c=t[u],h=null===(r=t.banner)||void 0===r?void 0:r[u];if("string"==typeof a){if(a!==c&&a!==h)return!1}else{if(!Array.isArray(a))return!1;if(!a.includes(c)&&!a.includes(h))return!1}}}catch(t){n={error:t}}finally{try{o&&!o.done&&(e=s.return)&&e.call(s)}finally{if(n)throw n.error}}return!0},i}(Pa);var za=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=pa(),e.data=i;var r=e.lookupCampaign();if(!(null==r?void 0:r.banner))throw new Error("DYNAMIC content requires a campaign with banner state");return e.bannerData=r.banner,e.createElement(),e}return fe(i,t),i.prototype.bindImageErrorLog=function(t,i){var n=this;this.bindEvent(t,"error",function(){return n.config.logger.error("".concat(i," failed to load"),{src:t.src})},{once:!0})},i.prototype.lookupCampaign=function(){var t,i=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==i?void 0:i.type)){var n=null===(t=i.content.conditions)||void 0===t?void 0:t.campaignId,e="";if("string"==typeof n?e=n:Array.isArray(n)&&void 0!==n[0]&&(e=String(n[0])),e)return this.config.allCampaignsMap.byId[e]}},i.prototype.createElement=function(){var t,i,n=this,e=this.bannerData,r=null!==(t=this.data.state)&&void 0!==t?t:{},s=e.userCampaignStatus,o=null!==(i=r[s])&&void 0!==i?i:{title:"",body:""},u=e.stepCompleted,a=e.activityCount,c=e.totalCampaignParticipants,h=e.activityExpiry,d=Math.floor(Date.now()/1e3),f=Math.max(0,h-d),l=Math.floor(f/3600),v=Math.floor(f%3600/60),m="".concat(l,"h").concat(v.toString().padStart(2,"0"),"m"),g=document.createElement("div");g.className="element";var p=document.createElement("div");p.className="progress-text-container";var w=document.createElement("div");w.setAttribute("class","progress-container");var y="http://www.w3.org/2000/svg",E=document.createElementNS(y,"svg");E.setAttribute("class","progress-circle"),E.setAttribute("viewBox","0 0 36 36");var _=document.createElementNS(y,"path");_.setAttribute("class","progress-bg"),_.setAttribute("d","M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831");var I=document.createElementNS(y,"path");I.setAttribute("class","progress"),I.setAttribute("d","M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831");var b=a>0?u/a*100:0;I.setAttribute("stroke-dasharray","".concat(b,", 100")),I.setAttribute("stroke-linecap",0===u?"butt":"round"),E.appendChild(_),E.appendChild(I);var T=document.createElement("div");T.setAttribute("class","inner-content");var S=document.createElement("div");S.setAttribute("class","primary-icon-container");var N=document.createElement("img");N.setAttribute("class","icon-image"),N.setAttribute("src","https://assets.customerglu.com/d051269a-05d7-4722-9e25-7e031655b4d0/b4194687-57e6-4272-83d5-b7867053408d.svg"),this.bindImageErrorLog(N,"Dynamic content primary icon"),S.appendChild(N),T.appendChild(S),w.appendChild(E),w.appendChild(T);var D=document.createElement("p");D.setAttribute("class","progress-text"),D.innerText="".concat(u,"/").concat(a),p.appendChild(w),p.appendChild(D),g.appendChild(p);var k=document.createElement("img");k.setAttribute("class","smaller-icon"),k.setAttribute("src","https://assets.customerglu.com/d051269a-05d7-4722-9e25-7e031655b4d0/c7d4d74e-c9ef-4ba1-8646-277c2ba2e91d.svg"),this.bindImageErrorLog(k,"Dynamic content smaller icon"),w.appendChild(k);var O=document.createElement("div");if(O.className="time-title-body-container",g.appendChild(O),"completed"!==s){var A=document.createElement("div");A.className="icon-text-container";var C=document.createElement("img");C.className="icon-container",C.src="pristine"===s?"https://assets.customerglu.com/d051269a-05d7-4722-9e25-7e031655b4d0/2ca387f9-60b5-40bb-af78-272d81a73021.svg":"https://assets.customerglu.com/d051269a-05d7-4722-9e25-7e031655b4d0/9406d009-5604-4e13-a03b-4e24a7ca4264.svg",this.bindImageErrorLog(C,"Dynamic content timer icon"),A.appendChild(C);var R=document.createElement("p");R.className="timer-text",R.innerText="pristine"===s?"".concat(c," users currently streaking"):m,A.appendChild(R),O.appendChild(A)}var x=document.createElement("div");x.className="title-body-container";var P=document.createElement("p");P.className="title-text",P.innerText=o.title,x.appendChild(P);var M=document.createElement("p");M.className="body-text",M.innerText=o.body,x.appendChild(M),O.appendChild(x);var U=document.createElement("div");U.className="right-icon-container";var L=document.createElement("img");L.className="right-icon",L.src="https://assets.customerglu.com/d051269a-05d7-4722-9e25-7e031655b4d0/5ca637bd-2b75-4996-a3aa-14e58b60c07e.svg",this.bindImageErrorLog(L,"Dynamic content right arrow icon"),U.appendChild(L),g.appendChild(U),this.addHeadStyle(this.buildStylesheet(u===a)),this.bindEvent(g,"click",function(t){t.stopPropagation(),t.preventDefault(),n.handleClick()}),this.element=g},i.prototype.handleClick=function(){var t,i=this.data.action;if(i&&"TOGGLE_CONTAINER_CONTENT"===i.type&&this.sdkEventListener)if(this.bannerData.checkAccepted&&this.bannerData.accepted){var n=le(le({},i),{id:this.actionId});this.sdkEventListener({target:"GLU_SDK",action:n})}else{var e,r={target:"GLU_SDK",action:le(le({},i),{id:this.actionId,content:le(le({},i.content),{typeId:"ACCEPT_GUARD"}),container:le(le({},i.container),{typeId:"BOTTOM_SHEET",css:(e=null!==(t=this.config.darkMode)&&void 0!==t&&t,".__glu_container {\n background-color: ".concat(e?"#1E1E1E":"#fff",";\n height: 57vh\n }\n .__glu_backdrop {\n background-color: rgba(0,0,0,0.5);\n }"))})})};this.sdkEventListener(r)}},i.prototype.buildStylesheet=function(t){var i,n=t?"block":"none",e=null!==(i=this.config.darkMode)&&void 0!==i&&i,r=e?"#1E1E1E":"white",s=e?"#444444":"#d3d3d3",o=e?"#22303A":"#E9F2F9",u=e?"#B0B0B0":"#757575",a=e?"#444444":"#D8D8D8",c=e?"#F5F5F5":"inherit";return"\n *{ margin: 0; padding: 0; box-sizing: border-box; }\n body{ font-family: 'Poppins', sans-serif; }\n .element { border-radius: 8px; width: 100%; padding: 8px 0; align-items: stretch; background-color: ".concat(r,"; display: flex; }\n .progress-text-container{ display: flex; flex-direction: column; align-items: center; width: 20%; }\n .progress-container { align-items: center; display: flex; flex-direction: column; width: 80%; position: relative; }\n .progress-bg { fill: none; stroke: ").concat(s,"; stroke-width: 3; }\n .progress { fill: none; stroke: #FF0099; stroke-width: 3; transition: stroke-dasharray 0.3s ease; }\n .inner-content { height: 63%; width: 63%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; background-color: ").concat(o,"; border-radius: 50%; }\n .primary-icon-container { height: 100%; width: 100%; display: flex; align-items: center; justify-content: center; }\n .icon-image{ height: 70%; width: 70%; }\n .smaller-icon { display: ").concat(n,"; position: absolute; bottom: 9%; width: 31%; right: 0%; border-radius: 50%; background-color: ").concat(r,"; padding: 1px; }\n .progress-text { margin: 0; font-size: 12px; font-weight: 400; color: ").concat(u,"; }\n .time-title-body-container { max-height: 100%; display: flex; gap: 8px; flex-direction: column; justify-content: center; width: 65%; }\n .icon-text-container { display: flex; border: 1px solid ").concat(a,"; border-radius: 4px; gap: 4px; padding: 2px 4px; width: fit-content; align-items: center; }\n .icon-container { width: 12px; height: 12px; }\n .timer-text { margin: 0px; font-size: 12px; font-weight: 600; color: ").concat(c,"; }\n .title-body-container { display: flex; gap: 8px; flex-direction: column; }\n .title-text { margin: 0; font-size: 16px; font-weight: 600; color: ").concat(c,"; }\n .body-text { margin: 0; font-size: 12px; font-weight: 400; color: ").concat(u,"; }\n .right-icon-container { display: flex; justify-content: center; align-items: center; width: 15%; }\n .right-icon { width: 20px; height: 20px; }\n ")},i}(Pa),ja=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=pa(),e.data=i;var r=e.lookupCampaign();return(null==r?void 0:r.banner)?(e.createElement(r),e):(n.logger.warn("DynamicMultistep1Content: campaign/banner lookup failed — hiding",{campaignId:e.data.campaignId}),e.createEmptyElement(),e)}return fe(i,t),i.prototype.createEmptyElement=function(){var t=document.createElement("div");t.style.display="none",this.element=t},i.prototype.lookupCampaign=function(){var t,i=this.data.campaignId;if(i)return this.config.allCampaignsMap.byId[i];var n=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==n?void 0:n.type)){var e=null===(t=n.content.conditions)||void 0===t?void 0:t.campaignId,r="";return"string"==typeof e?r=e:Array.isArray(e)&&void 0!==e[0]&&(r=String(e[0])),r?this.config.allCampaignsMap.byId[r]:void 0}},i.prototype.createElement=function(t){var i,n,e,r,s,o,u,a,c,h=this,d=null==t?void 0:t.banner,f=null!==(i=null==d?void 0:d.stepCompleted)&&void 0!==i?i:0,l=null!==(n=null==d?void 0:d.activityCount)&&void 0!==n?n:0,v=null!==(e=null==d?void 0:d.userCampaignStatus)&&void 0!==e?e:"pristine",m=this.findWidgetState(f,v),g=null!==(r=null==m?void 0:m.title)&&void 0!==r?r:"",p=null!==(s=null==m?void 0:m.body)&&void 0!==s?s:"",w=null!==(u=null===(o=null==m?void 0:m.progressBar)||void 0===o?void 0:o.progressRewardText)&&void 0!==u?u:"",y=null!==(c=null!==(a=this.data.progressBarIcon)&&void 0!==a?a:this.data.src)&&void 0!==c?c:"",E=l>0?Math.round(f/l*100):0;this.data.widgetCss&&this.addHeadStyle(this.data.widgetCss);var _=document.createElement("div");_.className="banner-container";var I=document.createElement("div");I.className="header-progressbar-container";var b=document.createElement("div");b.className="header-container";var T=document.createElement("p");T.className="heading-text",T.innerHTML=g;var S=document.createElement("p");S.className="body-text",S.textContent=p,b.appendChild(T),b.appendChild(S);var N=document.createElement("div");N.className="progressbar-parent-container";var D=document.createElement("span");D.className="progressbar-text",D.textContent=w;var k=document.createElement("div");k.className="progressbar-container";var O=document.createElement("div");O.className="total-progress";var A=document.createElement("div");A.className="completed-progress",A.style.width="".concat(E,"%"),k.appendChild(O),k.appendChild(A),N.appendChild(D),N.appendChild(k),I.appendChild(b),I.appendChild(N);var C=document.createElement("div");if(C.className="right-icon-container",y){var R=document.createElement("img");R.src=y,R.style.width="48px",R.style.height="48px",this.bindEvent(R,"error",function(){return h.config.logger.error("DynamicMultistep1 icon failed to load",{src:y})},{once:!0}),C.appendChild(R)}_.appendChild(I),_.appendChild(C),this.bindEvent(_,"click",function(t){t.stopPropagation(),t.preventDefault(),h.handleClick()}),this.element=_},i.prototype.findWidgetState=function(t,i){var n,e,r=this.data.IWidgetState;if(null==r?void 0:r.length)return null!==(e=null!==(n=r.find(function(n){return n.step===t&&n.state===i}))&&void 0!==n?n:r.find(function(i){return i.step===t}))&&void 0!==e?e:r[0]},i.prototype.handleClick=function(){var t=this.data.action;if(t&&"TOGGLE_CONTAINER_CONTENT"===t.type&&this.sdkEventListener){var i={target:"GLU_SDK",action:le(le({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(Pa),Ha=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=pa(),e.data=i;var r=e.lookupCampaign();return(null==r?void 0:r.banner)?(e.createElement(r),e):(n.logger.warn("DynamicMultistep2Content: campaign/banner lookup failed — hiding",{campaignId:e.data.campaignId}),e.createEmptyElement(),e)}return fe(i,t),i.prototype.createEmptyElement=function(){var t=document.createElement("div");t.style.display="none",this.element=t},i.prototype.lookupCampaign=function(){var t,i=this.data.campaignId;if(i)return this.config.allCampaignsMap.byId[i];var n=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==n?void 0:n.type)){var e=null===(t=n.content.conditions)||void 0===t?void 0:t.campaignId,r="";return"string"==typeof e?r=e:Array.isArray(e)&&void 0!==e[0]&&(r=String(e[0])),r?this.config.allCampaignsMap.byId[r]:void 0}},i.prototype.buildHeaderImage=function(t){var i=this;if(!t)return null;var n=document.createElement("div");n.className="image-container-ms2";var e=document.createElement("img");return e.className="header-image",e.src=t,this.bindEvent(e,"error",function(){return i.config.logger.error("DynamicMultistep2 header image failed to load",{src:t})},{once:!0}),n.appendChild(e),n},i.prototype.buildProgressBar=function(t,i){var n=document.createElement("div");n.className="progressbar-wrapper-ms2";var e=document.createElement("div");e.className="progressbar-container-ms2";var r=document.createElement("div");r.className="total-progress-ms2";var s=document.createElement("div");s.className="completed-progress-ms2",s.style.width="".concat(t,"%"),e.appendChild(r),e.appendChild(s);var o=document.createElement("div");o.className="progressbar-text-container-ms2";var u=document.createElement("span");return u.className="progressbar-text-ms2",u.textContent=i,o.appendChild(u),n.appendChild(e),n.appendChild(o),n},i.prototype.buildStepCircle=function(t,i){var n=document.createElement("div");n.className="step";var e=document.createElement("div");e.className=i?"circle completed":"circle";var r=document.createElement("span");return r.className=i?"amount completed":"amount",r.textContent=t,e.appendChild(r),n.appendChild(e),n},i.prototype.buildStepLabel=function(t,i,n){var e=document.createElement("div"),r="label inactive";return i?r="label completed":n&&(r="label current"),e.className=r,e.textContent=t,e},i.prototype.buildStepRows=function(t,i,n){var e=this,r=document.createElement("div");r.className="steps-container";var s=document.createElement("div");return s.className="labels-container",i.forEach(function(o,u){var a,c,h,d,f,l=null!==(a=t.find(function(t){return t.step===o&&"pristine"===t.state}))&&void 0!==a?a:t.find(function(t){return t.step===o}),v=null!==(h=null===(c=null==l?void 0:l.progressBar)||void 0===c?void 0:c.progressRewardText)&&void 0!==h?h:"",m=null!==(f=null===(d=null==l?void 0:l.progressBar)||void 0===d?void 0:d.progressLabel)&&void 0!==f?f:"",g=o<n,p=o===n;if(r.appendChild(e.buildStepCircle(v,g||p)),u<i.length-1){var w=document.createElement("div");w.className=g?"connector completed":"connector",r.appendChild(w)}s.appendChild(e.buildStepLabel(m,g,p))}),[r,s]},i.prototype.buildCtaButton=function(t){var i=this,n=document.createElement("div");n.className="button-container";var e=document.createElement("button");return e.className="view-rewards-button",e.textContent=t,this.bindEvent(e,"click",function(t){t.stopPropagation(),t.preventDefault(),i.handleClick()}),n.appendChild(e),n},i.prototype.createElement=function(t){var i,n,e,r,s,o,u,a,c,h,d=this,f=null==t?void 0:t.banner,l=null!==(i=null==f?void 0:f.stepCompleted)&&void 0!==i?i:0,v=null!==(n=null==f?void 0:f.activityCount)&&void 0!==n?n:0,m=null!==(e=null==f?void 0:f.userCampaignStatus)&&void 0!==e?e:"pristine",g=null!==(r=this.data.IWidgetState)&&void 0!==r?r:[],p=this.findWidgetState(l,m,g),w=v>0?Math.round(l/v*100):0;this.data.widgetCss&&this.addHeadStyle(this.data.widgetCss);var y=document.createElement("div");y.className="card-container-ms2";var E=document.createElement("div");E.className="banner-container-ms2";var _=null!==(u=null!==(o=null!==(s=null==p?void 0:p.headerImage)&&void 0!==s?s:this.data.progressMeterIcon)&&void 0!==o?o:this.data.src)&&void 0!==u?u:"",I=this.buildHeaderImage(_);I&&E.appendChild(I);var b=document.createElement("div");b.className="header-progressbar-container-ms2";var T=document.createElement("div");T.className="heading-container-ms2";var S=document.createElement("p");S.className="heading-text-ms2",S.innerHTML=null!==(a=null==p?void 0:p.title)&&void 0!==a?a:"",T.appendChild(S),b.appendChild(T),b.appendChild(this.buildProgressBar(w,null!==(h=null===(c=null==p?void 0:p.progressMeter)||void 0===c?void 0:c.completedText)&&void 0!==h?h:""));var N=we([],pe(new Set(g.map(function(t){return t.step}))),!1).sort(function(t,i){return t-i});if(N.length>0){var D=pe(this.buildStepRows(g,N,l),2),k=D[0],O=D[1];b.appendChild(k),b.appendChild(O)}(null==p?void 0:p.ctaText)&&b.appendChild(this.buildCtaButton(p.ctaText)),E.appendChild(b),y.appendChild(E),this.bindEvent(y,"click",function(t){t.stopPropagation(),t.preventDefault(),d.handleClick()}),this.element=y},i.prototype.findWidgetState=function(t,i,n){var e,r;return null!==(r=null!==(e=n.find(function(n){return n.step===t&&n.state===i}))&&void 0!==e?e:n.find(function(i){return i.step===t}))&&void 0!==r?r:n[0]},i.prototype.handleClick=function(){var t=this.data.action;if(t&&"TOGGLE_CONTAINER_CONTENT"===t.type&&this.sdkEventListener){var i={target:"GLU_SDK",action:le(le({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(Pa),qa=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=pa(),e.isExpanded=!0,e.data=i;var r=e.lookupCampaign();return(null==r?void 0:r.banner)?(e.createElement(r),e):(n.logger.warn("DynamicMultistep3Content: campaign/banner lookup failed — hiding",{campaignId:e.data.campaignId}),e.createEmptyElement(),e)}return fe(i,t),i.prototype.createEmptyElement=function(){var t=document.createElement("div");t.style.display="none",this.element=t},i.prototype.lookupCampaign=function(){var t,i=this.data.campaignId;if(i)return this.config.allCampaignsMap.byId[i];var n=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==n?void 0:n.type)){var e=null===(t=n.content.conditions)||void 0===t?void 0:t.campaignId,r="";return"string"==typeof e?r=e:Array.isArray(e)&&void 0!==e[0]&&(r=String(e[0])),r?this.config.allCampaignsMap.byId[r]:void 0}},i.prototype.buildHeader=function(t,i){var n=this,e=document.createElement("div");e.className="header-container-ms3";var r=document.createElement("div");if(r.className="header-content-ms3",i){var s=document.createElement("span");s.className="progress-badge-ms3",s.textContent=i,r.appendChild(s)}var o=document.createElement("p");if(o.className="heading-ms3",o.innerHTML=t,r.appendChild(o),e.appendChild(r),this.data.progressBarIcon){var u=document.createElement("img");u.className="dropdown-icon-ms3",u.src=this.data.progressBarIcon;var a=this.data.progressBarIcon;this.bindEvent(u,"error",function(){return n.config.logger.error("DynamicMultistep3 dropdown icon failed to load",{src:a})},{once:!0}),e.appendChild(u)}return e},i.prototype.buildStepDiv=function(t,i,n,e){var r=document.createElement("div");r.className="step-ms3";var s=document.createElement("div"),o="circle-ms3";i?o+=" completed":n&&(o+=" current"),s.className=o;var u=document.createElement("span");if(u.className=n?"amount-ms3 current":"amount-ms3",u.textContent=t,s.appendChild(u),r.appendChild(s),e){var a=document.createElement("div");a.className=i?"connector-ms3 completed":"connector-ms3";var c=document.createElement("div");c.className="connector-progress-ms3",a.appendChild(c),r.appendChild(a)}return r},i.prototype.buildStepsContainer=function(t,i,n){var e=this,r=document.createElement("div");return r.className="steps-container-ms3",i.forEach(function(s,o){var u,a,c,h=null!==(u=t.find(function(t){return t.step===s&&"pristine"===t.state}))&&void 0!==u?u:t.find(function(t){return t.step===s}),d=null!==(c=null===(a=null==h?void 0:h.progressBar)||void 0===a?void 0:a.progressRewardText)&&void 0!==c?c:"",f=s<n,l=s===n;r.appendChild(e.buildStepDiv(d,f,l,o<i.length-1))}),r},i.prototype.buildCtaButton=function(t){var i=this,n=document.createElement("div");n.className="button-container-ms3";var e=document.createElement("button");e.className="action-button-ms3",e.textContent=t,this.bindEvent(e,"click",function(t){t.stopPropagation(),t.preventDefault(),i.handleClick()});var r=document.createElement("div");return r.className="shine-effect",n.appendChild(e),n.appendChild(r),n},i.prototype.createElement=function(t){var i,n,e,r,s=this,o=null==t?void 0:t.banner,u=null!==(i=null==o?void 0:o.stepCompleted)&&void 0!==i?i:0,a=null!==(n=null==o?void 0:o.userCampaignStatus)&&void 0!==n?n:"pristine",c=null!==(e=this.data.IWidgetState)&&void 0!==e?e:[],h=this.findWidgetState(u,a,c);this.data.widgetCss&&this.addHeadStyle(this.data.widgetCss);var d=document.createElement("div");d.className="content-container-ms3";var f=document.createElement("div");f.className="main-content-ms3";var l=we([],pe(new Set(c.map(function(t){return t.step}))),!1).sort(function(t,i){return t-i});if(l.length>0&&f.appendChild(this.buildStepsContainer(c,l,u)),null==h?void 0:h.body){var v=document.createElement("p");v.className="description-ms3",v.textContent=h.body,f.appendChild(v)}(null==h?void 0:h.ctaText)&&f.appendChild(this.buildCtaButton(h.ctaText)),d.appendChild(f);var m=this.buildHeader(null!==(r=null==h?void 0:h.title)&&void 0!==r?r:"",null==h?void 0:h.badgeTag);this.bindEvent(m,"click",function(t){t.stopPropagation(),s.isExpanded=!s.isExpanded,d.classList.toggle("hidden",!s.isExpanded)});var g=document.createElement("div");g.className="banner-container-ms3",g.appendChild(m),g.appendChild(d);var p=document.createElement("div");p.className="card-container-ms3",p.appendChild(g),this.element=p},i.prototype.findWidgetState=function(t,i,n){var e,r;return null!==(r=null!==(e=n.find(function(n){return n.step===t&&n.state===i}))&&void 0!==e?e:n.find(function(i){return i.step===t}))&&void 0!==r?r:n[0]},i.prototype.handleClick=function(){var t=this.data.action;if(t&&"TOGGLE_CONTAINER_CONTENT"===t.type&&this.sdkEventListener){var i={target:"GLU_SDK",action:le(le({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(Pa),Ka=function(t){function i(i,n){var e=t.call(this,n)||this;if(!i.url)throw new Error("NUDGE content missing `url`");return e.element=Va(e.urlModifier(i.url),n.onLoad,function(){return n.logger.error("Nudge iframe failed to load",{src:i.url})}),e}return fe(i,t),i}(Pa),Wa=function(t){function i(i,n){var e=t.call(this,n)||this;if(!i.campaignId)throw new Error("PROGRAM content missing `campaignId`");var r="".concat(e.config.allCampaignsMap.base,"/program/?campaignId=").concat(i.campaignId);return e.element=Va(e.urlModifier(r,{token:!0}),n.onLoad,function(){return n.logger.error("Program iframe failed to load",{src:r})}),e}return fe(i,t),i}(Pa),Xa=function(t){function i(i,n){var e=t.call(this,n)||this;if(!i.rewardUserId)throw new Error("REWARD content missing `rewardUserId`");var r="".concat(e.config.allCampaignsMap.base,"/reward/?rewardUserId=").concat(i.rewardUserId);return e.element=Va(e.urlModifier(r,{token:!0}),n.onLoad,function(){return n.logger.error("Reward iframe failed to load",{src:r})}),e}return fe(i,t),i}(Pa),Ya=function(t){function i(i,n){var e=t.call(this,n)||this;if(e.actionId=pa(),e.data=i,e.shouldGateOnCampaign()){var r=e.extractGatedCampaignId();return r&&e.config.allCampaignsMap.byId[r]&&e.createElement(),e}return e.createElement(),e}return fe(i,t),i.prototype.shouldGateOnCampaign=function(){var t,i,n,e=this.data.action;return!(!e||"TOGGLE_CONTAINER_CONTENT"!==e.type)&&("CAMPAIGN"===(null===(t=e.content)||void 0===t?void 0:t.typeId)&&void 0!==(null===(n=null===(i=e.content)||void 0===i?void 0:i.conditions)||void 0===n?void 0:n.campaignId))},i.prototype.extractGatedCampaignId=function(){var t,i;if("TOGGLE_CONTAINER_CONTENT"!==(null===(t=this.data.action)||void 0===t?void 0:t.type))return null;var n=null===(i=this.data.action.content.conditions)||void 0===i?void 0:i.campaignId;return"string"==typeof n?n:Array.isArray(n)&&void 0!==n[0]?String(n[0]):null},i.prototype.createElement=function(){var t=this;if(!this.data.src)throw new Error("STATIC content missing `src`");var i=document.createElement("img");i.style.maxWidth="100%",i.style.maxHeight="100%",i.style.display="block",i.style.cursor="pointer";var n=this.config.onLoad;if(n){var e=performance.now();this.bindEvent(i,"load",function(){return n(performance.now()-e)},{once:!0})}this.bindEvent(i,"error",function(){return t.config.logger.error("Static image failed to load",{src:t.data.src})},{once:!0}),i.src=this.data.src,this.bindEvent(i,"click",function(i){i.stopPropagation(),i.preventDefault();var n=t.data.action;if(n&&t.sdkEventListener){var e={target:"GLU_SDK",action:"TOGGLE_CONTAINER_CONTENT"===n.type?le(le({},n),{id:t.actionId}):n};t.sdkEventListener(e)}}),this.element=i},i}(Pa),Qa=function(t){function i(i,n){var e=t.call(this,n)||this;return e.element=Va(e.urlModifier(e.config.allCampaignsMap.defaultUrl),n.onLoad,function(){return n.logger.error("Wallet iframe failed to load",{src:e.config.allCampaignsMap.defaultUrl})}),e}return fe(i,t),i}(Pa);var Ja=function(){function t(t,i){var n=this;this.sdkEventListener=null,this.closeListener=null,this.loaderTimeout=null,this.contentReady=!1,this.entryPoint=t,this.onOpen=i.onOpen;var e=le(le(le(le({},i),{isEmbedded:"EMBEDDED"===t.container.typeId}),void 0!==t.content.rootId&&{rootId:t.content.rootId}),{onLoad:function(t){var e;n.hideLoader(),null===(e=i.onLoad)||void 0===e||e.call(i,t)}});if(this.content=function(t,i){var n=t.content;switch(n.typeId){case"CAMPAIGN":return new Ba(n,i);case"WALLET":return new Qa(n,i);case"NUDGE":return new Ka(n,i);case"PROGRAM":return new Wa(n,i);case"REWARD":return new Xa(n,i);case"STATIC":return new Ya(n,i);case"DYNAMIC":return new za(n,i);case"DYNAMIC_MULTISTEP_1":return new ja(n,i);case"DYNAMIC_MULTISTEP_2":return new Ha(n,i);case"DYNAMIC_MULTISTEP_3":return new qa(n,i);case"ACCEPT_GUARD":return new Ga(n,i);default:var e=n.typeId;throw new Error("Unknown content typeId: ".concat(String(e)))}}(t,e),!this.content.element)throw new Error("Content ".concat(t.content.typeId," did not produce an element"));this.container=function(t,i,n,e,r){var s=t.container,o=le({typeId:s.typeId,css:s.css,logger:n,darkMode:e},void 0!==r&&{onShown:r});switch(s.typeId){case"ICON_BUTTON":return new Aa(o,i);case"CHAT_BOX":return new Ia(o,i);case"POP_UP":return new Ra(le(le({},o),{height:s.height}),i);case"BOTTOM_SHEET":return new _a(le(le({},o),{height:s.height}),i);case"NATIVE_BANNER":return new Ca(le(le({},o),{elementHookId:s.elementHookId}),i);case"EMBEDDED":return new Oa(le(le({},o),{elementHookId:s.elementHookId}),i);default:var u=s.typeId;throw new Error("Unknown container typeId: ".concat(String(u)))}}(t,this.content.element,i.logger,i.darkMode,function(){var t;return null===(t=n.onOpen)||void 0===t?void 0:t.call(n,n.entryPoint)}),this.content.listen(function(t){var i;return null===(i=n.sdkEventListener)||void 0===i?void 0:i.call(n,t)}),this.container.addCloseListener(function(){var t;return null===(t=n.closeListener)||void 0===t?void 0:t.call(n)})}return Object.defineProperty(t.prototype,"containerTypeId",{get:function(){return this.entryPoint.container.typeId},enumerable:!1,configurable:!0}),t.prototype.addEventListener=function(t){this.sdkEventListener=t},t.prototype.addCloseEventListener=function(t){this.closeListener=t},t.prototype.open=function(){var t=this;this.container.show(),this.contentReady||(this.container.showLoader(),this.clearLoaderTimeout(),this.loaderTimeout=setTimeout(function(){return t.hideLoader()},8e3))},t.prototype.preload=function(){this.container.preload()},t.prototype.close=function(){this.container.hide(),this.clearLoaderTimeout()},t.prototype.toggle=function(){this.isOpen()?this.close():this.open()},t.prototype.isOpen=function(){return this.container.isVisible()},t.prototype.sendMessage=function(t){this.content.sendMessageToContent(t)},t.prototype.sendRawMessage=function(t){this.content.sendRawMessage(t)},t.prototype.setHeight=function(t){this.container.setHeight(t)},t.prototype.hideLoader=function(){this.contentReady=!0,this.container.hideLoader(),this.content.reveal(),this.clearLoaderTimeout()},t.prototype.clearLoaderTimeout=function(){null!==this.loaderTimeout&&(clearTimeout(this.loaderTimeout),this.loaderTimeout=null)},t.prototype.destroy=function(){this.clearLoaderTimeout(),this.container.destroy(),this.content.destroy(),this.sdkEventListener=null,this.closeListener=null,this.onOpen=void 0},t}(),$a=function(){function t(){var t=this;this.windowToEmbed=new Map,this.listenerInstalled=!1,this.handleMessage=function(i){var n,e,r,s,o,u,a,c,h=i.source?t.windowToEmbed.get(i.source):void 0;if(h){var d=xa(i.data);if(d)switch(d.action.type){case"DIMENSIONS_UPDATE":var f=null!==(e=null===(n=d.action.data.data)||void 0===n?void 0:n.height)&&void 0!==e?e:d.action.data.height;"number"==typeof f&&ya(h.host,f);break;case"CLOSE":case"CLOSE_CONTAINER_CONTENT":t.removeEmbed(i.source,h);break;case"OPEN_DEEPLINK":t.handleOpenDeepLink(d.action.data,i.source,h);break;case"REQUEST_API_DATA":t.replyToEmbed(h.iframe,{eventName:"REQUEST_API_RESULT",data:{requestId:null!==(s=null===(r=d.action.data)||void 0===r?void 0:r.requestId)&&void 0!==s?s:""}});break;case"OPEN_WALLET":null===(u=null===(o=t.callbacks)||void 0===o?void 0:o.onOpenWallet)||void 0===u||u.call(o);break;case"OPEN_CG_WEBVIEW":null===(c=null===(a=t.callbacks)||void 0===a?void 0:a.onOpenCgWebView)||void 0===c||c.call(a,d.action.data)}}}}return t.prototype.render=function(t,i,n,e){var r,s;if("undefined"!=typeof document){this.callbacks=n,this.windowToEmbed.clear(),document.querySelectorAll("[data-glu-loyalty]").forEach(function(t){t.remove()});try{for(var o=ge(t),u=o.next();!u.done;u=o.next()){var a=u.value,c=document.getElementById(a.embedId);c&&this.injectIframe(c,this.buildUrl(a.url,i,e),a.embedId,n)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(s=o.return)&&s.call(o)}finally{if(r)throw r.error}}this.installMessageListener()}},t.prototype.buildUrl=function(t,i,n){var e=t,r=t.includes("?");return i&&(e+="".concat(r?"&":"?","capToken=").concat(encodeURIComponent(i)),r=!0),void 0!==n&&(e+="".concat(r?"&":"?","darkMode=").concat(n),r=!0),this.hasQueryParam(t,"isEmbedded")||(e+="".concat(r?"&":"?","isEmbedded=true")),e},t.prototype.hasQueryParam=function(t,i){var n,e;return(null!==(e=null===(n=t.split("?")[1])||void 0===n?void 0:n.split("#")[0])&&void 0!==e?e:"").split("&").some(function(t){var n;return(null===(n=t.split("=")[0])||void 0===n?void 0:n.toLowerCase())===i.toLowerCase()})},t.prototype.injectIframe=function(t,i,n,e){var r,s=document.createElement("iframe");s.src=i,s.setAttribute("data-glu-loyalty",n),s.style.cssText="border:none;width:100%;height:100%;opacity:0;transition:opacity 150ms ease;";var o=function(){s.style.opacity="1"},u=null==e?void 0:e.onLoad,a=performance.now();s.addEventListener("load",function(){o(),null==u||u(n,performance.now()-a)},{once:!0}),s.addEventListener("error",o,{once:!0}),t.appendChild(s),s.contentWindow&&this.windowToEmbed.set(s.contentWindow,{host:t,iframe:s,embedId:n}),null===(r=null==e?void 0:e.onOpen)||void 0===r||r.call(e,n)},t.prototype.installMessageListener=function(){this.listenerInstalled||"undefined"==typeof window||(this.listenerInstalled=!0,window.addEventListener("message",this.handleMessage))},t.prototype.handleOpenDeepLink=function(t,i,n){var e,r,s=Iu(t),o=s.deepLink,u=s.isHandledByCG,a=s.closeOnDeepLink;null===(r=null===(e=this.callbacks)||void 0===e?void 0:e.onDeepLinkEvent)||void 0===r||r.call(e,s),"true"===String(u).toLowerCase()&&"undefined"!=typeof window&&Au(o)&&(window.location.href=o),"true"===String(a).toLowerCase()&&this.removeEmbed(i,n)},t.prototype.removeEmbed=function(t,i){i.iframe.remove(),this.windowToEmbed.delete(t)},t.prototype.replyToEmbed=function(t,i){var n=t.contentWindow;if(n&&"function"==typeof n.postMessage&&t.src)try{n.postMessage(i,new URL(t.src).origin)}catch(t){}},t}(),Za=function(){function t(t,i,n,e,r,s){this.initialized=!1,this.userId=null,this.userAttributes=void 0,this.token=null,this.allCampaignsMap=null,this.entryPointMap=null,this.instances=new Map,this.dataDump=null,this.callback=null,this.lastSyncTimestamp=0,this.spaListenerCleanup=null,this.visibilityListenerCleanup=null,this.capToken=null,this.loyaltyRenderer=new $a,this.pagePathTrackingEnabled=!0,this.manualScreenName=null,this.pagePathTrackingExplicitlySet=!1,this.suppressed=!1,this.suppressedExplicitlySet=!1,this.theme="NONE",this.themeExplicitlySet=!1,this.tokenRefetchInFlight=null,this.authFailureCount=0,this.authBackoffUntil=0,this.pendingTimers=new Set,this.delayedOpenTimers=new Map,this.pendingShownRecordIds=new Set,this.openedCampaignIds=new Set,this.initGeneration=0,this.syncGeneration=0,this.preconnectedOrigins=new Set,this.swPreloaded=!1,this.trackingState=new Map,this.eventEntryPointMap=new Map,this.campaignQueue=new ta,this.openOverlayEntryPointId=null,this.openOverlayIds=new Set,this.ephemeralEntryPointIds=new Set,this.adHocEntryPointIds=new Set,this.adHocToggleSourceEmbedId=new Map,this.writeKey=t,this.logger=n,this.storageManager=e,this.apiClient=new mu(i,n),this.trackEvent=r,this.getSessionId=s}return t.prototype.initialize=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h,d,f,l,v,m,g,p,w,y,E;return me(this,function(_){switch(_.label){case 0:this.initialized&&(this.logger.info("GamificationManager re-initializing for new user",{userId:t}),this.clean()),this.logger.info("GamificationManager initializing",{userId:t}),n=++this.initGeneration,_.label=1;case 1:return _.trys.push([1,8,,9]),this.userId=t,this.userAttributes=i,this.preconnectFromCachedOrigin(),[4,Promise.all([this.storageManager.get(nu),this.loadFromCache(t)])];case 2:return e=pe.apply(void 0,[_.sent(),2]),r=e[0],s=e[1],n!==this.initGeneration?[2]:(r&&(this.capToken=r),s?(this.logger.info(Zs,{campaigns:null!==(a=null===(u=this.allCampaignsMap)||void 0===u?void 0:u.allIds.length)&&void 0!==a?a:0,entryPoints:null!==(h=null===(c=this.entryPointMap)||void 0===c?void 0:c.allIds.length)&&void 0!==h?h:0}),[3,5]):[3,3]);case 3:return this.logger.info(to),[4,this.fetchAndCache(t,i,n)];case 4:if(!_.sent())return[2];_.label=5;case 5:return this.entryPointMap&&(null===(f=null===(d=this.callback)||void 0===d?void 0:d.onEntryPointsLoaded)||void 0===f||f.call(d,Object.values(this.entryPointMap.byId))),this.preloadEntryPoints(),this.initialized=!0,this.logger.info(qs,{campaigns:null!==(v=null===(l=this.allCampaignsMap)||void 0===l?void 0:l.allIds.length)&&void 0!==v?v:0,entryPoints:null!==(g=null===(m=this.entryPointMap)||void 0===m?void 0:m.allIds.length)&&void 0!==g?g:0}),null===(w=null===(p=this.callback)||void 0===p?void 0:p.onInitSuccess)||void 0===w||w.call(p),[4,this.restorePersistedActionEventQueue(t)];case 6:return _.sent(),n!==this.initGeneration?[2]:[4,this.refresh()];case 7:return _.sent(),n!==this.initGeneration?[2]:(this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode()),this.registerSpaListener(),this.registerVisibilityListener(),[3,9]);case 8:return o=_.sent(),this.logger.error(Ks,o),null===(E=null===(y=this.callback)||void 0===y?void 0:y.onInitFailure)||void 0===E||E.call(y,{code:Pe,message:Ks,cause:o}),[3,9];case 9:return[2]}})})},t.prototype.getCampaignsMap=function(){return this.allCampaignsMap},t.prototype.getEntryPointMap=function(){return this.entryPointMap},t.prototype.getToken=function(){return this.token},t.prototype.setCapToken=function(t){this.capToken=t,this.storageManager.set(nu,t).catch(function(){}),this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode())},t.prototype.getCapToken=function(){return this.capToken},t.prototype.enablePagePathTracking=function(t){this.logger.info("Page path tracking mode changed",{enabled:t}),this.pagePathTrackingEnabled=t,this.pagePathTrackingExplicitlySet=!0,this.storageManager.set(eu,String(t)).catch(function(){}),this.refresh()},t.prototype.restorePersistedPagePathTracking=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(eu)];case 1:return null===(t=i.sent())||this.pagePathTrackingExplicitlySet||(this.pagePathTrackingEnabled="true"===t),[2]}})})},t.prototype.onScreenChanged=function(t){this.manualScreenName=t,this.pagePathTrackingEnabled||this.handleScreenChange()},t.prototype.setGamificationCallback=function(t){this.callback=t},t.prototype.setGamificationSuppressed=function(t){var i=this,n=this.suppressed;this.logger.info("Gamification suppression changed",{suppressed:t}),this.suppressed=t,this.suppressedExplicitlySet=!0,this.storageManager.set(ru,String(t)).catch(function(t){i.logger.error(uo,{error:t})}),n&&!t?this.refresh():!n&&t&&this.closeSuppressedInstances()},t.prototype.closeSuppressedInstances=function(){var t,i;try{for(var n=ge(this.instances.values()),e=n.next();!e.done;e=n.next()){var r=e.value;r.isOpen()&&this.isEffectivelySuppressed(r.entryPoint)&&this.closeIfOpen(r.entryPoint)}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}this.closeAdHocEntryPoints()},t.prototype.isContentOpenSuppressed=function(t){return!!this.isEffectivelySuppressed(t)&&(this.logger.debug(ao,{entryPointId:t.id,containerTypeId:t.container.typeId}),!0)},t.prototype.isGamificationSuppressed=function(){return this.suppressed},t.prototype.restorePersistedGamificationSuppressed=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(ru)];case 1:return null===(t=i.sent())||this.suppressedExplicitlySet||(this.suppressed="true"===t),[2]}})})},t.prototype.setTheme=function(i){var n=this;t.VALID_THEMES.includes(i)?(this.logger.info("Gamification theme changed",{theme:i}),this.theme=i,this.themeExplicitlySet=!0,this.storageManager.set(su,i).catch(function(t){n.logger.error(co,{error:t})}),this.invalidateUnopenedInstances(),this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode())):this.logger.warn("Invalid theme value, ignoring",{theme:i})},t.prototype.invalidateUnopenedInstances=function(){var t,i,n,e,r,s=[];try{for(var o=ge(this.instances),u=o.next();!u.done;u=o.next()){var a=pe(u.value,2),c=a[0],h=a[1],d=!!(v=null===(r=this.entryPointMap)||void 0===r?void 0:r.byId[c])&&Eu(v);h.isOpen()&&!d||(d&&h.isOpen()&&v&&!this.isCampaignCompleted(v)&&s.push(v),h.destroy(),this.instances.delete(c))}}catch(i){t={error:i}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}this.preloadEntryPoints();try{for(var f=ge(s),l=f.next();!l.done;l=f.next()){var v=l.value;this.openInstance(v)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(e=f.return)&&e.call(f)}finally{if(n)throw n.error}}},t.prototype.restorePersistedTheme=function(){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return[4,this.storageManager.get(su)];case 1:return null!==(i=n.sent())&&!this.themeExplicitlySet&&t.VALID_THEMES.includes(i)&&(this.theme=i),[2]}})})},t.prototype.resolveDarkMode=function(){switch(this.theme){case"LIGHT":return!1;case"DARK":return!0;case"AUTO":return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches;default:return}},t.prototype.openEntryPoint=function(t){if(this.initialized){var i=this.getOrCreateInstance(t);i?(ku(i.entryPoint)&&this.openOverlayIds.add(t),i.open()):this.logger.error("openEntryPoint() could not resolve an entry point instance",{entryPointId:t})}else this.logger.error("openEntryPoint() called before GamificationManager is initialized",{entryPointId:t})},t.prototype.closeEntryPoint=function(t){if(this.initialized){var i=this.instances.get(t);i||this.logger.warn("closeEntryPoint() found no open instance for this entry point",{entryPointId:t}),null==i||i.close(),this.onCampaignClosed(t)}else this.logger.warn("closeEntryPoint() called before GamificationManager is initialized",{entryPointId:t})},t.prototype.forceSync=function(){var t=this;return this.initialized?this.resyncData().then(function(){t.refresh()}):(this.logger.error("forceSync() called before GamificationManager is initialized"),Promise.resolve())},t.prototype.clean=function(){var t,i,n,e,r,s;this.logger.info(Xs),this.initGeneration++,this.syncGeneration++,null===(r=this.spaListenerCleanup)||void 0===r||r.call(this),this.spaListenerCleanup=null,null===(s=this.visibilityListenerCleanup)||void 0===s||s.call(this),this.visibilityListenerCleanup=null,this.lastSyncTimestamp=0;try{for(var o=ge(this.pendingTimers),u=o.next();!u.done;u=o.next()){var a=u.value;clearTimeout(a)}}catch(i){t={error:i}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}this.pendingTimers.clear(),this.delayedOpenTimers.clear(),this.pendingShownRecordIds.clear(),this.openedCampaignIds.clear();try{for(var c=ge(this.instances.values()),h=c.next();!h.done;h=c.next()){var d=h.value;d.isOpen()&&d.close(),d.destroy()}}catch(t){n={error:t}}finally{try{h&&!h.done&&(e=c.return)&&e.call(c)}finally{if(n)throw n.error}}this.instances.clear(),this.trackingState.clear(),this.eventEntryPointMap.clear(),this.campaignQueue.clear(),this.openOverlayEntryPointId=null,this.openOverlayIds.clear(),this.ephemeralEntryPointIds.clear(),this.adHocEntryPointIds.clear(),this.adHocToggleSourceEmbedId.clear(),this.userId&&(this.storageManager.remove(this.cacheKey(this.userId)).catch(function(){}),this.storageManager.remove(this.tokenCacheKey(this.userId)).catch(function(){}),this.storageManager.remove(this.queueStorageKey(this.userId)).catch(function(){})),this.userId=null,this.userAttributes=void 0,this.token=null,this.tokenRefetchInFlight=null,this.authFailureCount=0,this.authBackoffUntil=0,this.allCampaignsMap=null,this.entryPointMap=null,this.dataDump=null,this.capToken=null,this.storageManager.remove(nu).catch(function(){}),this.initialized=!1},t.prototype.destroy=function(){this.clean(),this.logger.info(Ws)},Object.defineProperty(t.prototype,"loyaltyUrls",{get:function(){var t,i;return null!==(i=null===(t=this.allCampaignsMap)||void 0===t?void 0:t.loyaltyUrls)&&void 0!==i?i:[]},enumerable:!1,configurable:!0}),t.prototype.resolveCurrentPath=function(){var t;return this.pagePathTrackingEnabled?"undefined"!=typeof window?window.location.href:"":null!==(t=this.manualScreenName)&&void 0!==t?t:""},t.prototype.refresh=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:if(!this.entryPointMap)return[2];t=this.resolveCurrentPath(),this.logger.info(Qs,{entryPoints:this.entryPointMap.allIds.length,url:t}),this.campaignQueue.clearScreenTriggered(),i={},n={},e=this.entryPointMap,r=this.initGeneration,f.label=1;case 1:f.trys.push([1,6,7,8]),s=ge(this.orderedEntryPointIds(e)),o=s.next(),f.label=2;case 2:return o.done?[3,5]:(u=o.value,r!==this.initGeneration?[2]:!(a=e.byId[u])||Tu(a)?[3,4]:[4,this.refreshEntryPoint(a,i,n)]);case 3:f.sent(),f.label=4;case 4:return o=s.next(),[3,2];case 5:return[3,8];case 6:return c=f.sent(),h={error:c},[3,8];case 7:try{o&&!o.done&&(d=s.return)&&d.call(s)}finally{if(h)throw h.error}return[7];case 8:return this.showNextFromQueue(),[2]}})})},t.prototype.orderedEntryPointIds=function(t){var i=function(i){var n=t.byId[i];return n&&Eu(n)?n.container.elementHookId:null};return we([],pe(t.allIds),!1).sort(function(n,e){var r,s,o,u,a,c,h=i(n),d=i(e);if(!h||!d||h!==d)return 0;var f=t.byId[n],l=t.byId[e],v=(null!==(s=null===(r=null==l?void 0:l.conditions)||void 0===r?void 0:r.priority)&&void 0!==s?s:0)-(null!==(u=null===(o=null==f?void 0:f.conditions)||void 0===o?void 0:o.priority)&&void 0!==u?u:0);return 0!==v?v:(null!==(a=null==l?void 0:l.createdAt)&&void 0!==a?a:"").localeCompare(null!==(c=null==f?void 0:f.createdAt)&&void 0!==c?c:"")})},t.prototype.refreshEntryPoint=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:return e=ku(t),r=null===(u=t.conditions)||void 0===u?void 0:u.singleOpenName,!e&&r&&i[r]?[2]:(s=Eu(t)?t.container.elementHookId:null)&&n[s]?[2]:!Tu(t)&&this.isCampaignCompleted(t)?(this.closeIfOpen(t),[2]):[4,this.isDismissedThisSession(t)];case 1:return a.sent()?(this.cancelDelayedOpen(t.id),[2]):(o=this.isEffectivelySuppressed(t),[4,Zu(t,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())]);case 2:return a.sent()?(o||(!e&&r&&(i[r]=!0),s&&(n[s]=!0),this.scheduleOpenOrEnqueue(t,e)),[2]):(this.closeIfOpen(t),[2])}})})},t.prototype.isEffectivelySuppressed=function(t){return this.suppressed&&!Eu(t)},t.prototype.scheduleOpenOrEnqueue=function(t,i){var n,e=this,r=null===(n=t.conditions)||void 0===n?void 0:n.delay;if(r){this.cancelDelayedOpen(t.id);var s=setTimeout(function(){e.pendingTimers.delete(s),e.delayedOpenTimers.delete(t.id),e.fireDelayedOpen(t.id)},1e3*r);this.pendingTimers.add(s),this.delayedOpenTimers.set(t.id,s)}else this.openOrEnqueue(t,i)},t.prototype.cancelDelayedOpen=function(t){var i=this.delayedOpenTimers.get(t);void 0!==i&&(clearTimeout(i),this.pendingTimers.delete(i),this.delayedOpenTimers.delete(t))},t.prototype.fireDelayedOpen=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:return(i=null===(e=this.entryPointMap)||void 0===e?void 0:e.byId[t])?!Tu(i)&&this.isCampaignCompleted(i)?[2]:[4,this.isDismissedThisSession(i)]:[2];case 1:return r.sent()||this.isEffectivelySuppressed(i)?[2]:[4,Zu(i,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())];case 2:return r.sent()?(n=ku(i),this.openOrEnqueue(i,n),n&&this.showNextFromQueue(),[2]):[2]}})})},t.prototype.openOrEnqueue=function(t,i){if(!i){if(this.isEffectivelySuppressed(t))return;var n=this.instances.get(t.id);if(null==n?void 0:n.isOpen())return;var e=this.getOrCreateInstance(t.id);if(!e)return;return this.recordEntryPointShownIfEligible(t),void e.open()}this.openOverlayEntryPointId!==t.id&&this.enqueueCampaign(t)},t.prototype.closeIfOpen=function(t){this.cancelDelayedOpen(t.id);var i=this.instances.get(t.id);(null==i?void 0:i.isOpen())&&i.close(),this.onCampaignClosed(t.id)},t.prototype.openInstance=function(t){var i=this.getOrCreateInstance(t.id);i&&(ku(t)&&this.openOverlayIds.add(t.id),i.open())},t.prototype.notifyCampaignOpened=function(t){var i,n,e=Cu(t);!e&&this.ephemeralEntryPointIds.has(t.id)||(this.openedCampaignIds.add(t.id),null===(n=null===(i=this.callback)||void 0===i?void 0:i.onCampaignOpened)||void 0===n||n.call(i,null!=e?e:t.id))},t.prototype.enqueueCampaign=function(t){this.campaignQueue.enqueue([t]),this.persistActionEventQueue()},t.prototype.showNextFromQueue=function(){var t,i;if(!(this.openOverlayIds.size>0||this.suppressed))try{for(var n=ge(this.campaignQueue.entries()),e=n.next();!e.done;e=n.next()){var r=e.value,s=this.getOrCreateInstance(r.id);if(s)return this.campaignQueue.remove(r.id),this.openOverlayEntryPointId=r.id,this.openOverlayIds.add(r.id),this.persistActionEventQueue(),this.recordEntryPointShownIfEligible(r),void s.open()}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}},t.prototype.recordEntryPointShownIfEligible=function(t){this.isEffectivelySuppressed(t)||(!Eu(t)||function(t){return"undefined"!=typeof document&&null!==document.querySelector("#".concat(t.container.elementHookId))}(t)?this.persistEntryPointShown(t):this.pendingShownRecordIds.add(t.id))},t.prototype.recordPendingShownIfAny=function(t){this.pendingShownRecordIds.delete(t.id)&&this.persistEntryPointShown(t)},t.prototype.persistEntryPointShown=function(t){var i=this;(function(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:return Tu(t)?[2]:(r=null===(c=t.conditions)||void 0===c?void 0:c.showCount)?(s=new Date,[4,Xu(t.id,i,n,e)]):[2];case 1:o=h.sent(),u=!r.dailyRefresh||o&&Yu(s,new Date(o.date))?{count:o?o.count+1:1,date:s.toISOString()}:{count:1,date:s.toISOString()},h.label=2;case 2:return h.trys.push([2,4,,5]),[4,n.set(Wu(t.id,i),JSON.stringify(u))];case 3:return h.sent(),[3,5];case 4:return a=h.sent(),e.error(So,{entryPointId:t.id,error:a}),[3,5];case 5:return[2]}})})})(t,this.userId,this.storageManager,this.logger).catch(function(n){i.logger.error(So,{entryPointId:t.id,error:n})})},t.prototype.onCampaignClosed=function(t){var i,n,e,r;if(this.openOverlayIds.delete(t),this.openedCampaignIds.delete(t)){var s=null===(i=this.entryPointMap)||void 0===i?void 0:i.byId[t];null===(e=null===(n=this.callback)||void 0===n?void 0:n.onCampaignClosed)||void 0===e||e.call(n,s&&null!==(r=Cu(s))&&void 0!==r?r:t)}this.openOverlayEntryPointId===t&&(this.openOverlayEntryPointId=null),0===this.openOverlayIds.size&&this.showNextFromQueue()},t.prototype.sessionDismissedKeyPrefix=function(t,i){return"".concat(Xo).concat(t,"_").concat(i,"_")},t.prototype.sessionDismissedKey=function(t,i,n){return"".concat(this.sessionDismissedKeyPrefix(t,i)).concat(n)},t.prototype.isDismissedThisSession=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(Eu(t)||Tu(t))return[2,!1];if(!(i=this.getSessionId())||!this.userId)return[2,!1];o.label=1;case 1:return o.trys.push([1,3,,4]),n=this.sessionDismissedKey(this.userId,t.id,this.resolveCurrentPath()),[4,this.storageManager.get(n)];case 2:return(e=o.sent())?[2,"object"==typeof(r=JSON.parse(e))&&null!==r&&r.sessionId===i]:[2,!1];case 3:return s=o.sent(),this.logger.error(ho,{entryPointId:t.id,error:s}),[2,!1];case 4:return[2]}})})},t.prototype.recordSessionDismissal=function(t){var i,n=this,e=null===(i=this.entryPointMap)||void 0===i?void 0:i.byId[t];if(e&&!Eu(e)&&!Tu(e)){var r=this.getSessionId();if(r&&this.userId){var s=this.sessionDismissedKey(this.userId,t,this.resolveCurrentPath());this.storageManager.set(s,JSON.stringify({sessionId:r})).catch(function(i){n.logger.error(fo,{entryPointId:t,error:i})})}}},t.prototype.queueStorageKey=function(t){return Wo+t},t.prototype.persistActionEventQueue=function(){var t=this;if(this.userId){var i=this.campaignQueue.entries().filter(function(t){return Tu(t)}).map(function(t){return t.id}),n=this.queueStorageKey(this.userId);0!==i.length?this.storageManager.set(n,JSON.stringify(i)).catch(function(i){t.logger.error(lo,{error:i})}):this.storageManager.remove(n).catch(function(){})}},t.prototype.restorePersistedActionEventQueue=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h;return me(this,function(d){switch(d.label){case 0:if(!this.entryPointMap)return[2];d.label=1;case 1:return d.trys.push([1,11,,12]),[4,this.storageManager.get(this.queueStorageKey(t))];case 2:if(!(i=d.sent()))return[2];if(n=JSON.parse(i),!Array.isArray(n))return[2];d.label=3;case 3:d.trys.push([3,8,9,10]),e=ge(n),r=e.next(),d.label=4;case 4:return r.done?[3,7]:"string"!=typeof(s=r.value)?[3,6]:(o=this.entryPointMap.byId[s])&&Tu(o)?[4,Zu(o,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())]:[3,6];case 5:d.sent()&&this.campaignQueue.enqueue([o]),d.label=6;case 6:return r=e.next(),[3,4];case 7:return[3,10];case 8:return u=d.sent(),c={error:u},[3,10];case 9:try{r&&!r.done&&(h=e.return)&&h.call(e)}finally{if(c)throw c.error}return[7];case 10:return this.persistActionEventQueue(),[3,12];case 11:return a=d.sent(),this.logger.error(vo,{error:a}),[3,12];case 12:return[2]}})})},t.prototype.buildEventIndex=function(){var t,i,n;if(this.eventEntryPointMap.clear(),this.entryPointMap){this.entryPointMap.allIds.includes("")&&this.logger.error(mo,{totalEntryPoints:this.entryPointMap.allIds.length});try{for(var e=ge(this.entryPointMap.allIds),r=e.next();!r.done;r=e.next()){var s=r.value,o=this.entryPointMap.byId[s],u=o?Nu(o):null;if(u){var a=null!==(n=this.eventEntryPointMap.get(u))&&void 0!==n?n:new Set;a.add(s),this.eventEntryPointMap.set(u,a)}}}catch(i){t={error:i}}finally{try{r&&!r.done&&(i=e.return)&&i.call(e)}finally{if(t)throw t.error}}}},t.prototype.handleActionEvent=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l;return me(this,function(v){switch(v.label){case 0:if(!this.initialized||!t||!this.entryPointMap)return[2];if(!(i=this.eventEntryPointMap.get(t))||0===i.size)return null===(l=null===(f=this.callback)||void 0===f?void 0:f.onGameEventTrigger)||void 0===l||l.call(f,t,{reason:Oo}),[2];v.label=1;case 1:v.trys.push([1,10,,11]),n={},e={},v.label=2;case 2:v.trys.push([2,7,8,9]),r=ge(i),s=r.next(),v.label=3;case 3:return s.done?[3,6]:(o=s.value,(u=this.entryPointMap.byId[o])?[4,this.refreshEntryPoint(u,n,e)]:[3,5]);case 4:v.sent(),v.label=5;case 5:return s=r.next(),[3,3];case 6:return[3,9];case 7:return a=v.sent(),h={error:a},[3,9];case 8:try{s&&!s.done&&(d=r.return)&&d.call(r)}finally{if(h)throw h.error}return[7];case 9:return this.showNextFromQueue(),[3,11];case 10:return c=v.sent(),this.logger.error(oo,{eventName:t,error:c}),[3,11];case 11:return[2]}})})},t.prototype.preloadEntryPoints=function(){var t,i,n;if(this.entryPointMap){this.preconnectToCampaignOrigin(),this.preloadServiceWorker();var e=this.resolveCurrentPath();try{for(var r=ge(this.entryPointMap.allIds),s=r.next();!s.done;s=r.next()){var o=s.value;if(!this.instances.has(o)){var u=this.entryPointMap.byId[o];if(u&&(Tu(u)||!this.isCampaignCompleted(u))&&(Tu(u)||Qu(null===(n=u.conditions)||void 0===n?void 0:n.paths,e))){var a=this.getOrCreateInstance(o);null==a||a.preload()}}}}catch(i){t={error:i}}finally{try{s&&!s.done&&(i=r.return)&&i.call(r)}finally{if(t)throw t.error}}}},t.prototype.preconnectToCampaignOrigin=function(t){var i,n=null!=t?t:null===(i=this.allCampaignsMap)||void 0===i?void 0:i.base;if("undefined"!=typeof document&&n&&!this.preconnectedOrigins.has(n)){this.preconnectedOrigins.add(n);var e=document.createElement("link");e.rel="preconnect",e.href=n,document.head.appendChild(e)}},t.prototype.preconnectFromCachedOrigin=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.storageManager.get(au)];case 1:return(t=i.sent())&&this.preconnectToCampaignOrigin(t),[3,3];case 2:return i.sent(),[3,3];case 3:return[2]}})})},t.prototype.preloadServiceWorker=function(){var t,i=this;if("undefined"!=typeof document&&(null===(t=this.allCampaignsMap)||void 0===t?void 0:t.base)&&!this.swPreloaded){this.swPreloaded=!0;var n="".concat(this.allCampaignsMap.base).concat(ou),e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.style.cssText="position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;border:0;",e.setAttribute("fetchpriority","low");var r=function(){e.remove(),clearTimeout(s),i.pendingTimers.delete(s)};e.addEventListener("load",function(){return r()},{once:!0});var s=setTimeout(function(){return r()},uu);this.pendingTimers.add(s),e.src=n,document.body.appendChild(e)}},t.prototype.getOrCreateInstance=function(t){var i,n=this,e=this.instances.get(t);if(e)return e;var r=null===(i=this.entryPointMap)||void 0===i?void 0:i.byId[t];if(!(r&&this.token&&this.allCampaignsMap&&this.userId))return this.logger.error("getOrCreateInstance() precondition not met, cannot open entry point",{entryPointId:t,hasEntryPoint:!!r,hasToken:!!this.token,hasAllCampaignsMap:!!this.allCampaignsMap,hasUserId:!!this.userId}),null;var s=this.token,o=this.userId;try{var u=function(){var i,e;return null!==(e=null===(i=n.entryPointMap)||void 0===i?void 0:i.byId[t])&&void 0!==e?e:r};this.resetDisplayTracking(t);var a=new Ja(r,{userId:o,token:s,darkMode:this.resolveDarkMode(),allCampaignsMap:this.allCampaignsMap,logger:this.logger,onOpen:function(){var t=u();n.recordPendingShownIfAny(t),n.trackEntryPointOpen(t),n.notifyCampaignOpened(t)},onLoad:function(t){return n.trackEntryPointLoaded(u(),t)}});return a.addEventListener(function(i){return n.handleSdkEvent(i,t)}),a.addCloseEventListener(function(){a.close(),n.recordSessionDismissal(t),n.onCampaignClosed(t)}),this.instances.set(t,a),a}catch(i){return this.logger.error(go,{entryPointId:t,error:i}),null}},t.prototype.trackEntryPointOpen=function(t){var i,n,e,r=this,s=yu(t);if(s&&this.userId){if(this.markOpened(t.id),"game"===s){this.getOrCreateTrackingState(t.id).completionFired=!1;var o=Cu(t),u={campaign_id:o,game_type:this.lookupGameType(o),entry_surface:null!==(i=pu(t))&&void 0!==i?i:"",embed_id:null!==(n=this.adHocToggleSourceEmbedId.get(t.id))&&void 0!==n?n:t.container.elementHookId,entry_point_id:this.resolveTrackingEntryPointId(t,o),entry_point_location:"undefined"!=typeof window?window.location.href:""};this.trackEvent(Ao,u)}else{u={page_id:t.container.elementHookId,content_surface:null!==(e=pu(t))&&void 0!==e?e:""};this.trackEvent(Mo,u)}this.fireViewedIfReady(t.id,function(i){return r.buildViewedAttributes(t,s,i)},s)}},t.prototype.trackEntryPointLoaded=function(t,i){var n=this;this.logger.debug("Campaign iframe loaded in ".concat(i.toFixed(2),"ms"),{entryPointId:t.id,campaignId:Cu(t)});var e=yu(t);e&&(this.markLoaded(t.id,i),this.fireViewedIfReady(t.id,function(i){return n.buildViewedAttributes(t,e,i)},e))},t.prototype.buildViewedAttributes=function(t,i,n){var e;if("game"===i){var r=Cu(t);return{campaign_id:r,game_type:this.lookupGameType(r),load_time_ms:_u(n)}}return{page_id:t.container.elementHookId,content_surface:null!==(e=pu(t))&&void 0!==e?e:"",load_time_ms:_u(n)}},t.prototype.lookupGameType=function(t){var i,n,e;return t&&null!==(e=null===(n=null===(i=this.allCampaignsMap)||void 0===i?void 0:i.byId[t])||void 0===n?void 0:n.type)&&void 0!==e?e:null},t.prototype.resolveTrackingEntryPointId=function(t,i){var n;if(!this.ephemeralEntryPointIds.has(t.id)||!i||!this.entryPointMap)return t.id;var e=this.entryPointMap,r=e.allIds.map(function(t){return e.byId[t]}).find(function(n){return void 0!==n&&n.id!==t.id&&Cu(n)===i});return null!==(n=null==r?void 0:r.id)&&void 0!==n?n:t.id},t.prototype.handleInboundAnalyticsEvent=function(t,i){if(this.matchesAnalyticsEventName(t,ko))return this.trackGamePlayed(i),void this.trackRewardSeenIfPresent(t,i);if(this.matchesAnalyticsEventName(t,Do)){var n=this.getOrCreateTrackingState(i),e=n.completionFired;return n.completionFired=!0,e||this.trackGameCompleted(i),void this.trackRewardSeenIfPresent(t,i)}this.trackRewardSeenIfPresent(t,i)},t.prototype.matchesAnalyticsEventName=function(t,i){return"object"==typeof t&&null!==t&&t[Jo.EVENT_NAME]===i},t.prototype.trackGamePlayed=function(t){var i,n=null===(i=this.instances.get(t))||void 0===i?void 0:i.entryPoint;if(n&&wu(n.content)&&this.userId){var e=this.getOrCreateTrackingState(t);e.playedAt=Date.now(),e.completionFired=!1;var r=Cu(n),s={campaign_id:r,game_type:this.lookupGameType(r)};this.trackEvent(Ro,s)}},t.prototype.trackGameCompleted=function(t){var i,n,e=null===(i=this.instances.get(t))||void 0===i?void 0:i.entryPoint;if(e&&wu(e.content)&&this.userId){var r=null===(n=this.trackingState.get(t))||void 0===n?void 0:n.playedAt,s=void 0!==r?Date.now()-r:0,o=Cu(e),u={campaign_id:o,game_type:this.lookupGameType(o),total_time_ms:_u(s)};this.trackEvent(xo,u)}},t.prototype.trackRewardSeenIfPresent=function(t,i){if("object"==typeof t&&null!==t){var n=t[Jo.CAMPAIGN_DETAILS];if("object"==typeof n&&null!==n){var e=n,r=e[Jo.REWARD_STATUS];"string"==typeof r&&r.split("-").includes("SEEN")&&this.trackRewardSeen(e,i)}}},t.prototype.trackRewardSeen=function(t,i){if(this.userId){var n=this.readStringField(t,Jo.REWARD_USER_ID),e=this.getOrCreateTrackingState(i);if(null===n||n!==e.lastRewardUserId){e.lastRewardUserId=n;var r={reward_id:n,campaign_id:this.readStringField(t,Jo.CAMPAIGN_ID),reward_type:this.readStringField(t,Jo.REWARD_TYPE)};this.trackEvent(Po,r)}}},t.prototype.readStringField=function(t,i){var n=t[i];return void 0===n?null:"string"==typeof n?n:(this.logger.warn(po,{field:i,value:n}),null)},t.prototype.trackLoyaltyOpen=function(t){var i=this;if(this.userId){var n=this.loyaltyStateKey(t);this.trackingState.set(n,{opened:!0,viewedFired:!1});var e={page_id:t,content_surface:Lo};this.trackEvent(Mo,e),this.fireViewedIfReady(n,function(n){return i.buildLoyaltyViewedAttributes(t,n)},"content")}},t.prototype.trackLoyaltyLoaded=function(t,i){var n=this,e=this.loyaltyStateKey(t);this.markLoaded(e,i),this.fireViewedIfReady(e,function(i){return n.buildLoyaltyViewedAttributes(t,i)},"content")},t.prototype.buildLoyaltyViewedAttributes=function(t,i){return{page_id:t,content_surface:Lo,load_time_ms:_u(i)}},t.prototype.loyaltyStateKey=function(t){return"loyalty:".concat(t)},t.prototype.loyaltyCallbacks=function(){var i=this;return{onOpen:function(t){return i.trackLoyaltyOpen(t)},onLoad:function(t,n){return i.trackLoyaltyLoaded(t,n)},onDeepLinkEvent:function(t){var n,e;return null===(e=null===(n=i.callback)||void 0===n?void 0:n.onDeepLinkEvent)||void 0===e?void 0:e.call(n,t)},onOpenWallet:function(){return i.handleOpenWallet()},onOpenCgWebView:function(n){return i.handleOpenCgWebView(n,t.LOYALTY_SOURCE_ID)}}},t.prototype.markOpened=function(t){var i=this.getOrCreateTrackingState(t);i.opened=!0,i.viewedFired=!1},t.prototype.resetDisplayTracking=function(t){var i=this.trackingState.get(t);i&&(i.opened=!1,i.viewedFired=!1,delete i.loadTimeMs)},t.prototype.markLoaded=function(t,i){this.getOrCreateTrackingState(t).loadTimeMs=i},t.prototype.getOrCreateTrackingState=function(t){var i=this.trackingState.get(t);return i||(i={opened:!1,viewedFired:!1},this.trackingState.set(t,i)),i},t.prototype.fireViewedIfReady=function(t,i,n){var e=this.trackingState.get(t);e&&!e.viewedFired&&e.opened&&void 0!==e.loadTimeMs&&this.userId&&(e.viewedFired=!0,this.trackEvent("game"===n?Co:Uo,i(e.loadTimeMs)))},t.prototype.handleSdkEvent=function(t,i){var n,e,r,s,o,u,a,c,h,d,f,l,v,m,g,p;if(this.initialized&&t&&"GLU_SDK"===t.target&&t.action){var w=t.action;switch(w.type){case"TOGGLE_CONTAINER_CONTENT":this.handleToggle(w,i);break;case"OPEN_CONTAINER_CONTENT":this.handleOpen(w);break;case"CLOSE_CONTAINER_CONTENT":case"CLOSE":this.handleClose(w,i);break;case"REQUEST_STATE":null===(e=this.instances.get(i))||void 0===e||e.sendMessage({type:"UPDATE_CONTENT_STATE",data:null!==(r=this.dataDump)&&void 0!==r?r:{}});break;case"LOGIN":this.handleLogin(w);break;case"REDIRECT":this.handleRedirect(w);break;case"ANALYTICS":null===(o=null===(s=this.callback)||void 0===s?void 0:s.onAnalyticsEvent)||void 0===o||o.call(s,w.data),this.handleInboundAnalyticsEvent(w.data,i);break;case"REFRESH":this.refresh();break;case"UPDATE_CONTENT_STATE":break;case"OPEN_DEEPLINK":this.handleOpenDeepLink(w,i);break;case"DIMENSIONS_UPDATE":null===(u=this.instances.get(i))||void 0===u||u.setHeight(null!==(c=null===(a=w.data.data)||void 0===a?void 0:a.height)&&void 0!==c?c:w.data.height);break;case"HIDE_LOADER":null===(h=this.instances.get(i))||void 0===h||h.hideLoader();break;case"REQUEST_API_DATA":null===(d=this.instances.get(i))||void 0===d||d.sendRawMessage({eventName:"REQUEST_API_RESULT",data:{requestId:null!==(l=null===(f=w.data)||void 0===f?void 0:f.requestId)&&void 0!==l?l:""}});break;case"REFRESH_API_DATA":null===(v=this.instances.get(i))||void 0===v||v.sendRawMessage({eventName:"REFRESH_API_DATA_RESULT",data:{requestId:null!==(g=null===(m=w.data)||void 0===m?void 0:m.requestId)&&void 0!==g?g:""}});break;case"OPEN_WALLET":this.handleOpenWallet();break;case"OPEN_WEBLINK":this.handleOpenWebLink(w.data);break;case"SHARE":this.handleShare(w.data);break;case"GAME_PLAYED":this.handleInboundAnalyticsEvent(le(le({},null!==(p=w.data)&&void 0!==p?p:{}),((n={})[Jo.EVENT_NAME]=Do,n)),i);break;case"OPEN_CG_WEBVIEW":this.handleOpenCgWebView(w.data,i)}}},t.prototype.handleClose=function(t,i){var n;null===(n=this.instances.get(i))||void 0===n||n.close(),this.recordSessionDismissal(i),this.onCampaignClosed(i),this.ephemeralEntryPointIds.delete(i)&&this.trackingState.delete(i),t.data&&(this.dataDump=t.data)},t.prototype.handleLogin=function(t){"undefined"!=typeof window&&Au(t.data.url)&&(window.location.href=t.data.url)},t.prototype.handleToggle=function(t,i){var n=this.instances.get(t.id);n?n.isOpen()?(n.close(),this.recordSessionDismissal(t.id),this.onCampaignClosed(t.id)):this.isContentOpenSuppressed(n.entryPoint)||(ku(n.entryPoint)&&this.openOverlayIds.add(t.id),n.open()):this.openNewToggleTarget({id:t.id,container:t.container,content:t.content},i),t.data&&(this.dataDump=t.data)},t.prototype.openNewToggleTarget=function(t,i){var n;if(!this.isContentOpenSuppressed(t)){var e=null===(n=this.instances.get(i))||void 0===n?void 0:n.entryPoint;e&&this.adHocToggleSourceEmbedId.set(t.id,e.container.elementHookId||e.id),this.registerAdHocEntryPoint(t),this.openInstance(t)}},t.prototype.handleOpen=function(t){var i={id:pa(),container:t.container,content:t.content};this.isContentOpenSuppressed(i)||(this.ephemeralEntryPointIds.add(i.id),this.registerAdHocEntryPoint(i),this.openInstance(i),t.data&&(this.dataDump=t.data))},t.prototype.handleRedirect=function(t){if("undefined"!=typeof window&&Au(t.data.url)){var i=t.data.url;this.userId&&(i+=i.includes("?")?"&":"?",i+="userId=".concat(this.userId)),t.data.openInNewTab?window.open(i,"_blank","noopener,noreferrer"):window.location.href=i}},t.prototype.handleOpenDeepLink=function(t,i){var n,e,r,s=Iu(t.data),o=s.deepLink,u=s.isHandledByCG,a=s.closeOnDeepLink;null===(e=null===(n=this.callback)||void 0===n?void 0:n.onDeepLinkEvent)||void 0===e||e.call(n,s),"true"===String(u).toLowerCase()&&"undefined"!=typeof window&&Au(o)&&(window.location.href=o),"true"===String(a).toLowerCase()&&(null===(r=this.instances.get(i))||void 0===r||r.close(),this.onCampaignClosed(i))},t.prototype.handleOpenWallet=function(){var t,i=null===(t=this.allCampaignsMap)||void 0===t?void 0:t.defaultUrl;i&&this.openAdHocContent(i)},t.prototype.handleOpenWebLink=function(t){"undefined"!=typeof window&&Au(null==t?void 0:t.url)&&window.open(t.url,"_blank","noopener,noreferrer")},t.prototype.handleShare=function(t){var i,n=null==t?void 0:t.text,e=null==t?void 0:t.image,r=null!==(i=null==t?void 0:t.channelName)&&void 0!==i?i:"OTHERS";e?"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("CUSTOMERGLU_SHARE_EVENT",{detail:t})):n&&"undefined"!=typeof window&&("WHATSAPP"===r.toUpperCase()?window.open("https://wa.me/?text=".concat(encodeURIComponent(n)),"_blank"):"undefined"!=typeof navigator&&"function"==typeof navigator.share&&navigator.share({text:n}).catch(function(){}))},t.prototype.handleOpenCgWebView=function(t,i){var n,e,r,s=null!==(n=null==t?void 0:t.data)&&void 0!==n?n:t,o=null==s?void 0:s.content,u=null==o?void 0:o.campaignId,a=this.resolveOpenCgWebViewUrl(o);a&&this.openAdHocContent(a,u,this.resolveOpenCgWebViewContainer(null==s?void 0:s.container))&&"true"===String(null!==(e=null==s?void 0:s.hidePrevious)&&void 0!==e?e:"false").toLowerCase()&&(null===(r=this.instances.get(i))||void 0===r||r.close(),this.onCampaignClosed(i))},t.prototype.resolveOpenCgWebViewUrl=function(t){var i,n,e,r,s=(null!==(i=null==t?void 0:t.type)&&void 0!==i?i:"").toUpperCase();return"WALLET"===s?null===(n=this.allCampaignsMap)||void 0===n?void 0:n.defaultUrl:"CAMPAIGN"===s&&(null==t?void 0:t.campaignId)?null===(r=null===(e=this.allCampaignsMap)||void 0===e?void 0:e.byId[t.campaignId])||void 0===r?void 0:r.url:null==t?void 0:t.url},t.prototype.resolveOpenCgWebViewContainer=function(i){var n,e=(null!==(n=null==i?void 0:i.type)&&void 0!==n?n:"").toLowerCase(),r=t.BOTTOM_SHEET_LAYOUTS.has(e)?"BOTTOM_SHEET":"POP_UP",s=Number(null==i?void 0:i.relativeHeight),o=Number(null==i?void 0:i.absoluteHeight);return s>0?{typeId:r,height:"".concat(s,"%")}:o>0?{typeId:r,height:"".concat(o,"px")}:{typeId:r,height:"".concat(t.DEFAULT_NUDGE_HEIGHT_PERCENT,"%")}},t.prototype.openAdHocContent=function(i,n,e){void 0===e&&(e={typeId:"POP_UP",height:"".concat(t.DEFAULT_NUDGE_HEIGHT_PERCENT,"%")});var r={id:pa(),container:{typeId:e.typeId,css:"",height:e.height,elementHookId:""},content:le({typeId:"NUDGE",url:i},n?{campaignId:n}:{})};return!this.isContentOpenSuppressed(r)&&(this.ephemeralEntryPointIds.add(r.id),this.registerAdHocEntryPoint(r),this.openInstance(r),!0)},t.prototype.registerAdHocEntryPoint=function(t){this.entryPointMap?(this.adHocEntryPointIds.add(t.id),this.entryPointMap.byId[t.id]||(this.entryPointMap.allIds.push(t.id),this.entryPointMap.byId[t.id]=t)):this.logger.error("registerAdHocEntryPoint() called before entryPointMap is loaded",{entryPointId:t.id})},t.prototype.closeAdHocEntryPoints=function(){var t,i;if(0!==this.adHocEntryPointIds.size){try{for(var n=ge(this.adHocEntryPointIds),e=n.next();!e.done;e=n.next()){var r=e.value,s=this.instances.get(r);if(s&&(s.isOpen()&&s.close(),s.destroy(),this.instances.delete(r)),this.trackingState.delete(r),this.ephemeralEntryPointIds.delete(r),this.adHocToggleSourceEmbedId.delete(r),this.openOverlayIds.delete(r),this.entryPointMap){delete this.entryPointMap.byId[r];var o=this.entryPointMap.allIds.indexOf(r);-1!==o&&this.entryPointMap.allIds.splice(o,1)}}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}this.adHocEntryPointIds.clear()}},t.prototype.cacheKey=function(t){return Ho+t},t.prototype.tokenCacheKey=function(t){return qo+t},t.prototype.loadTokenFromCache=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.storageManager.get(this.tokenCacheKey(t))];case 1:return(i=r.sent())?(n=JSON.parse(i),Date.now()-n.timestamp>=jo?[2,null]:[2,n.token]):[2,null];case 2:return e=r.sent(),this.logger.error(yo,{userId:t,error:e}),[2,null];case 3:return[2]}})})},t.prototype.saveTokenToCache=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:n={token:i,timestamp:Date.now()},r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.storageManager.set(this.tokenCacheKey(t),JSON.stringify(n))];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.logger.error(wo,{error:e}),[3,4];case 4:return[2]}})})},t.prototype.getOrFetchToken=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:return[4,this.loadTokenFromCache(t)];case 1:return(n=r.sent())?(this.logger.info(io),[2,n]):(this.logger.info(no),[4,this.apiClient.getToken(this.writeKey,t,Qo.LOGGED_IN,void 0,i)]);case 2:return e=r.sent(),[4,this.saveTokenToCache(t,e)];case 3:return r.sent(),[2,e]}})})},t.prototype.isAuthError=function(t){return"object"==typeof t&&null!==t&&t.code===Me},t.prototype.ensureFreshToken=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r;return me(this,function(s){switch(s.label){case 0:if(this.tokenRefetchInFlight)return[2,this.tokenRefetchInFlight];if(Date.now()<this.authBackoffUntil)throw this.logger.warn(ro,{retryInMs:this.authBackoffUntil-Date.now()}),new Error("Gamification token refetch is in backoff after repeated failures");i=this.refetchToken(t,this.userAttributes),this.tokenRefetchInFlight=i,s.label=1;case 1:return s.trys.push([1,3,4,5]),[4,i];case 2:return n=s.sent(),this.authFailureCount=0,this.authBackoffUntil=0,[2,n];case 3:throw e=s.sent(),this.authFailureCount+=1,r=Math.min(tu*Math.pow(2,this.authFailureCount-1),iu),this.authBackoffUntil=Date.now()+r,this.logger.error(so,{userId:t,authFailureCount:this.authFailureCount,backoffMs:r,error:e}),e;case 4:return this.tokenRefetchInFlight=null,[7];case 5:return[2]}})})},t.prototype.refetchToken=function(t,i){return ve(this,void 0,void 0,function(){var n;return me(this,function(e){switch(e.label){case 0:return[4,this.storageManager.remove(this.tokenCacheKey(t)).catch(function(){})];case 1:return e.sent(),[4,this.apiClient.getToken(this.writeKey,t,Qo.LOGGED_IN,void 0,i)];case 2:return n=e.sent(),this.userId!==t?[3,4]:[4,this.saveTokenToCache(t,n)];case 3:e.sent(),this.token=n,e.label=4;case 4:return[2,n]}})})},t.prototype.fetchCampaignsAndEntryPoints=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,4]),[4,Promise.all([this.apiClient.getCampaigns(i),this.apiClient.getEntryPoints(i)])];case 1:return[2,r.sent()];case 2:if(n=r.sent(),!this.isAuthError(n))throw n;return this.logger.error(eo,{userId:t}),[4,this.ensureFreshToken(t)];case 3:return e=r.sent(),[2,Promise.all([this.apiClient.getCampaigns(e),this.apiClient.getEntryPoints(e)])];case 4:return[2]}})})},t.prototype.loadFromCache=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.storageManager.get(this.cacheKey(t))];case 1:return(i=r.sent())?(n=JSON.parse(i),Date.now()-n.timestamp>=zo?(this.logger.debug(_o,{userId:t,ageMs:Date.now()-n.timestamp}),[2,!1]):(this.token=n.token,this.allCampaignsMap=n.allCampaignsMap,this.entryPointMap=n.entryPointMap,this.buildEventIndex(),this.lastSyncTimestamp=n.timestamp,[2,!0])):(this.logger.debug(Eo,{userId:t}),[2,!1]);case 2:return e=r.sent(),this.logger.error(Io,{userId:t,error:e}),[2,!1];case 3:return[2]}})})},t.prototype.saveToCache=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:if(!(this.userId&&this.token&&this.allCampaignsMap&&this.entryPointMap))return[2];t={token:this.token,allCampaignsMap:this.allCampaignsMap,entryPointMap:this.entryPointMap,timestamp:this.lastSyncTimestamp},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.storageManager.set(this.cacheKey(this.userId),JSON.stringify(t))];case 2:return n.sent(),[3,4];case 3:return i=n.sent(),this.logger.error(bo,{error:i}),[3,4];case 4:return this.allCampaignsMap.base&&this.storageManager.set(au,this.allCampaignsMap.base).catch(function(){}),[2]}})})},t.prototype.handleScreenChange=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.closeAdHocEntryPoints(),this.isDataStale()?[4,this.resyncData()]:[3,2];case 1:return t.sent(),[3,3];case 2:this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode()),t.label=3;case 3:return this.refresh(),[2]}})})},t.prototype.isDataStale=function(){return Date.now()-this.lastSyncTimestamp>=zo},t.prototype.resyncData=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:if(t=this.token,i=this.userId,!t||!i)return[2];n=++this.syncGeneration,this.logger.info(Js),h.label=1;case 1:return h.trys.push([1,4,,5]),[4,this.fetchCampaignsAndEntryPoints(i,t)];case 2:return e=pe.apply(void 0,[h.sent(),2]),r=e[0],s=e[1],n!==this.syncGeneration?[2]:(o=this.entryPointMap,this.allCampaignsMap=r,this.entryPointMap=Uu(s),this.buildEventIndex(),this.lastSyncTimestamp=Date.now(),null===(c=null===(a=this.callback)||void 0===a?void 0:a.onEntryPointsLoaded)||void 0===c||c.call(a,Object.values(this.entryPointMap.byId)),this.preloadEntryPoints(),[4,this.saveToCache()]);case 3:return h.sent(),this.reconcileEntryPointState(o,this.entryPointMap,i),this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode()),[3,5];case 4:return u=h.sent(),this.logger.error($s,u),[3,5];case 5:return[2]}})})},t.prototype.reconcileEntryPointState=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f,l=this;return me(this,function(v){switch(v.label){case 0:if(!t)return[2];e=this.classifyReconciledEntryPoints(t,i),r=e.removedIds,s=e.dailyRefreshChangedIds,o=function(t){u.storageManager.remove(Wu(t,n)).catch(function(i){l.logger.error(No,{entryPointId:t,error:i})})},u=this;try{for(a=ge(we(we([],pe(r),!1),pe(s),!1)),c=a.next();!c.done;c=a.next())h=c.value,o(h)}catch(t){d={error:t}}finally{try{c&&!c.done&&(f=a.return)&&f.call(a)}finally{if(d)throw d.error}}return r.length>0?[4,this.pruneSessionDismissalRecords(r,n)]:[3,2];case 1:v.sent(),v.label=2;case 2:return[2]}})})},t.prototype.classifyReconciledEntryPoints=function(t,i){var n,e,r,s,o,u,a,c,h=[],d=[];try{for(var f=ge(t.allIds),l=f.next();!l.done;l=f.next()){var v=l.value,m=t.byId[v],g=i.byId[v];if(m)if(g)(null!==(o=null===(s=null===(r=m.conditions)||void 0===r?void 0:r.showCount)||void 0===s?void 0:s.dailyRefresh)&&void 0!==o&&o)!==(null!==(c=null===(a=null===(u=g.conditions)||void 0===u?void 0:u.showCount)||void 0===a?void 0:a.dailyRefresh)&&void 0!==c&&c)&&d.push(v);else h.push(v)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(e=f.return)&&e.call(f)}finally{if(n)throw n.error}}return{removedIds:h,dailyRefreshChangedIds:d}},t.prototype.pruneSessionDismissalRecords=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h,d=this;return me(this,function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),[4,this.storageManager.keys("".concat(Xo).concat(i,"_"))];case 1:n=f.sent(),e=function(t){var e,s,o=r.sessionDismissedKeyPrefix(i,t);try{for(var u=(e=void 0,ge(n.filter(function(t){return t.startsWith(o)}))),a=u.next();!a.done;a=u.next()){var c=a.value;r.storageManager.remove(c).catch(function(i){d.logger.error(No,{entryPointId:t,error:i})})}}catch(t){e={error:t}}finally{try{a&&!a.done&&(s=u.return)&&s.call(u)}finally{if(e)throw e.error}}},r=this;try{for(s=ge(t),o=s.next();!o.done;o=s.next())u=o.value,e(u)}catch(t){c={error:t}}finally{try{o&&!o.done&&(h=s.return)&&h.call(s)}finally{if(c)throw c.error}}return[3,3];case 2:return a=f.sent(),this.logger.error(No,{entryPointId:"all",error:a}),[3,3];case 3:return[2]}})})},t.prototype.fetchAndCache=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o;return me(this,function(u){switch(u.label){case 0:return[4,this.getOrFetchToken(t,i)];case 1:return e=u.sent(),n!==this.initGeneration?[2,!1]:(this.token=e,[4,this.fetchCampaignsAndEntryPoints(t,e)]);case 2:return r=pe.apply(void 0,[u.sent(),2]),s=r[0],o=r[1],n!==this.initGeneration?[2,!1]:(this.allCampaignsMap=s,this.entryPointMap=Uu(o),this.buildEventIndex(),this.lastSyncTimestamp=Date.now(),this.saveToCache(),[2,n===this.initGeneration])}})})},t.prototype.isCampaignCompleted=function(t){var i,n,e,r=Cu(t);if(!r||!this.allCampaignsMap)return!1;var s=this.allCampaignsMap.byId[r];if(!s)return!1;var o=Fo;return(null===(i=s.status)||void 0===i?void 0:i.toUpperCase())===o||(null===(e=null===(n=s.banner)||void 0===n?void 0:n.userCampaignStatus)||void 0===e?void 0:e.toUpperCase())===o},t.prototype.registerSpaListener=function(){var t=this;if("undefined"!=typeof window&&"undefined"!=typeof document){var i=window.location.href,n=null,e=new MutationObserver(function(){var e=window.location.href;if(e!==i){if(i=e,!t.pagePathTrackingEnabled)return;n&&clearTimeout(n),n=setTimeout(function(){t.handleScreenChange()},Yo)}});e.observe(document.body,{childList:!0,subtree:!0}),this.spaListenerCleanup=function(){e.disconnect(),n&&clearTimeout(n)}}},t.prototype.registerVisibilityListener=function(){var t=this;if("undefined"!=typeof document){var i=function(){return ve(t,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return"visible"!==document.visibilityState?[2]:this.isDataStale()?[4,this.resyncData()]:[3,2];case 1:return t.sent(),this.refresh(),[2];case 2:return this.showNextFromQueue(),[2]}})})};document.addEventListener("visibilitychange",i),this.visibilityListenerCleanup=function(){document.removeEventListener("visibilitychange",i)}}},t.VALID_THEMES=["NONE","AUTO","DARK","LIGHT"],t.LOYALTY_SOURCE_ID="__GLU__LOYALTY__",t.BOTTOM_SHEET_LAYOUTS=new Set(["bottom-popup","bottom-default","bottom-slider"]),t.DEFAULT_NUDGE_HEIGHT_PERCENT=100/1.4,t}(),tc=function(){function t(t,i,n,e,r){this.httpClient=new du(t,i),this.logger=i,this.accountId=n,this.orgId=e,this.source=r}return t.prototype.sendEvents=function(t,i,n,e,r,s){return ve(this,void 0,void 0,function(){var o,u,a,c,h,d,f,l;return me(this,function(v){switch(v.label){case 0:if(!i&&!n&&!e)throw new Error("Either visitorId, visitorExternalId, or userId must be provided for event tracking");if(!s)throw new Error("Session ID is required for event tracking");return u=(o=!!i||!!n)&&e?"identified":o?"anonymous":"user-only",this.logger.info("Sending events",{eventCount:t.length,trackingMode:u,hasVisitor:o,hasUser:!!e,sessionId:s}),[4,va()];case 1:a=v.sent(),c=oa(s,a),h={request_id:ea(),context:c,events:t},i?h.visitor={identifierName:"id",identifierValue:i}:n&&(h.visitor={identifierName:"externalId",identifierValue:n}),e&&r&&(h.user={identifierName:r,identifierValue:e}),v.label=2;case 2:return v.trys.push([2,4,,5]),d={"X-CAP-API-AUTH-ORG-ID":this.orgId,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":this.source,"X-CAP-API-AUTH-ENTITY-ID":this.orgId},[4,this.httpClient.post(ye,h,{headers:d})];case 3:return f=v.sent(),this.logger.info(rr,{requestId:h.request_id,eventCount:t.length,trackingMode:u,success:f.status.success}),[2,f];case 4:throw l=v.sent(),this.logger.error(sr,{requestId:h.request_id,eventCount:t.length,trackingMode:u,error:l}),l;case 5:return[2]}})})},t.prototype.getVisitorConfig=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s;return me(this,function(o){switch(o.label){case 0:this.logger.info("Fetching visitor config",{orgId:t}),o.label=1;case 1:return o.trys.push([1,3,,4]),i={"X-CAP-API-AUTH-ORG-ID":t,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":Ls.WEBPUSH},[4,this.httpClient.get(_e,{headers:i})];case 2:return n=o.sent(),this.logger.info(Pr,{isEnabled:null===(r=n.data)||void 0===r?void 0:r.visitorTrackingEnabled,warningCount:(null===(s=n.warnings)||void 0===s?void 0:s.length)||0}),[2,n];case 3:throw e=o.sent(),this.logger.error(Mr,{orgId:t,error:e}),e;case 4:return[2]}})})},t.prototype.createVisitor=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:this.logger.info("Creating anonymous visitor",{orgId:t,profileCount:i.profiles.length,hasExtendedFields:!!i.extendedFields}),u.label=1;case 1:if(u.trys.push([1,3,,4]),!i.profiles||0===i.profiles.length)throw new Error("At least one profile is required");return n={"X-CAP-API-AUTH-ORG-ID":t,"X-CAP-SOURCE-NAME":this.source,"X-CAP-ORG-ACCOUNT-ID":this.accountId},[4,this.httpClient.post(Ie,i,{headers:n})];case 2:return e=u.sent(),this.logger.info(Vr,{visitorId:null===(s=e.data)||void 0===s?void 0:s.id,warningCount:(null===(o=e.warnings)||void 0===o?void 0:o.length)||0}),[2,e];case 3:throw r=u.sent(),this.logger.error(Br,{error:r,accountId:this.accountId}),r;case 4:return[2]}})})},t.prototype.updateVisitor=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a;return me(this,function(c){switch(c.label){case 0:this.logger.info("Updating visitor",{orgId:t,visitorId:i,profileCount:n.profiles.length,hasExtendedFields:!!n.extendedFields}),c.label=1;case 1:if(c.trys.push([1,3,,4]),!n.profiles||0===n.profiles.length)throw new Error("At least one profile is required");if(!i||""===i.trim())throw new Error("Visitor ID is required for update");return e={"X-CAP-API-AUTH-ORG-ID":t,"X-CAP-SOURCE-NAME":this.source,"X-CAP-ORG-ACCOUNT-ID":this.accountId},r="".concat(be,"?identifierType=visitorId&identifierValue=").concat(encodeURIComponent(i)),[4,this.httpClient.put(r,n,{headers:e})];case 2:return s=c.sent(),this.logger.info(Hr,{visitorId:null===(u=s.data)||void 0===u?void 0:u.id,warningCount:(null===(a=s.warnings)||void 0===a?void 0:a.length)||0}),[2,s];case 3:throw o=c.sent(),this.logger.error(qr,{error:o,visitorId:i,accountId:this.accountId}),o;case 4:return[2]}})})},t.prototype.buildMergeIdentifiers=function(t,i,n,e){var r,s={email:i,mobile:n,externalId:e},o=t&&s[t]?t:void 0;r=i?"email":n?"mobile":"externalId";var u=null!=o?o:r;return[{type:u,value:s[u]}]},t.prototype.handleMergeResponse=function(t,i){var n,e=this;if(t.warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){e.logger.warn("Visitor merge warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0){var r=t.errors[0],s=r.code,o=r.message,u=String(s);if(u===Vs.ALREADY_MERGED)return void this.logger.info("Visitor already merged, treating as success",{visitorId:i});if(u===Vs.VISITOR_NOT_FOUND)throw this.logger.warn("Visitor not found, merge cannot proceed",{visitorId:i}),new ic(u,o);throw new Error("Merge API error: [".concat(u,"] ").concat(o))}if(202!==(null===(n=t.status)||void 0===n?void 0:n.code))throw new Error("Unexpected merge API response");this.logger.info(Kr,{visitorId:i,statusCode:t.status.code,message:t.status.message})},t.prototype.mergeVisitor=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f,l,v,m,g,p,w,y,E,_,I,b,T,S,N,D,k;return me(this,function(O){switch(O.label){case 0:if(e=n.firstName,r=n.lastName,s=n.email,o=n.mobile,u=n.fcmToken,a=n.channelType,c=n.subscribed,h=void 0===c||c,d=n.fields,f=n.extendedFields,l=n.externalId,v=n.sessionId,m=void 0===v?"":v,g=n.cuid,p=void 0===g?"":g,w=n.identifierType,!s&&!o&&!l)throw new Error("At least one identifier (email, mobile, or externalId) is required for visitor merge");if(!t&&!i)throw new Error("Either visitorId or visitorExternalId is required for visitor merge");return this.logger.info("Merging visitor with user",{visitorId:t,visitorExternalId:i,hasEmail:!!s,hasMobile:!!o,hasExternalId:!!l,hasFcmToken:!!u}),y=this.buildMergeIdentifiers(w,s,o,l),E=a||Fs.WEB,_=[],u&&_.push({type:E,value:u,primary:!0,verified:!0,subscribed:h,accountId:this.accountId,attributes:{gateway:zs,cuid:p,luid:p,lastSeen:(new Date).toISOString(),deleted:!1,pushReachable:h}}),s&&_.push({type:"email",value:s,primary:!0,subscribed:!1,accountId:this.accountId,attributes:{cuid:p}}),o&&_.push({type:"mobile",value:o,primary:!0,subscribed:!1,accountId:this.accountId,attributes:{cuid:p}}),k={visitor:t?{identifierName:"id",identifierValue:t}:{identifierName:"externalId",identifierValue:i},user:{profiles:[{firstName:e,lastName:r,identifiers:y,commChannels:_,fields:d||{}}],extendedFields:f||{}}},b=oa,T=[m],[4,va()];case 1:k.context=b.apply(void 0,T.concat([O.sent()])),I=k,O.label=2;case 2:return O.trys.push([2,4,,5]),S={"X-CAP-API-AUTH-ORG-ID":this.orgId,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":this.source},[4,this.httpClient.post(Te,I,{headers:S})];case 3:return N=O.sent(),this.handleMergeResponse(N,t),[3,5];case 4:if((D=O.sent())instanceof ic)throw D;throw this.logger.error(Wr,{visitorId:t,error:D}),D;case 5:return[2]}})})},t.prototype.buildUserEventsRequest=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r;return me(this,function(s){switch(s.label){case 0:return[4,va()];case 1:return e=s.sent(),r=oa(n,e),[2,{request_id:ea(),context:le(le({},r),{os_name:Os}),events:[{name:t,eventExternalId:ea(),eventDateTime:(new Date).toISOString(),attributes:i}]}]}})})},t.prototype.sendUserEvents=function(t,i,n,e,r){return ve(this,void 0,void 0,function(){var s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:i?t.visitor={identifierName:"id",identifierValue:i}:n&&(t.visitor={identifierName:"externalId",identifierValue:n}),e&&r&&(t.user={identifierName:r,identifierValue:e}),this.logger.info("Sending user event",{eventName:null===(u=t.events[0])||void 0===u?void 0:u.name,requestId:t.request_id,hasVisitor:!!t.visitor,hasUser:!!t.user}),h.label=1;case 1:return h.trys.push([1,3,,4]),s={"X-CAP-API-AUTH-ORG-ID":this.orgId,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":this.source,"X-CAP-API-AUTH-ENTITY-ID":this.orgId},[4,this.httpClient.post(Ee,t,{headers:s})];case 2:return h.sent(),this.logger.info(or,{eventName:null===(a=t.events[0])||void 0===a?void 0:a.name,requestId:t.request_id}),[3,4];case 3:throw o=h.sent(),this.logger.error(ur,{eventName:null===(c=t.events[0])||void 0===c?void 0:c.name,requestId:t.request_id,error:o}),o;case 4:return[2]}})})},t.prototype.sendDLR=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s;return me(this,function(o){switch(o.label){case 0:this.logger.info("Sending DLR events",{eventCount:t.events.length,requestId:t.request_id,cuid:null===(r=t.user)||void 0===r?void 0:r.identifierValue,visitorId:null===(s=t.visitor)||void 0===s?void 0:s.identifierValue}),o.label=1;case 1:return o.trys.push([1,3,,4]),i={"x-cap-api-auth-org-id":this.orgId,"x-cap-request-id":t.request_id},[4,this.httpClient.post(Se,t,{headers:i})];case 2:return n=o.sent(),this.logger.info(Ds,{requestId:t.request_id,eventCount:t.events.length,success:n.status.success}),[2,n];case 3:throw e=o.sent(),this.logger.error(ks,{requestId:t.request_id,eventCount:t.events.length,error:e}),e;case 4:return[2]}})})},t}(),ic=function(t){function i(i,n){var e=t.call(this,n)||this;return e.name="MergeNonRetryableError",e.code=i,e}return fe(i,t),i}(Error);var nc,ec=function(){function t(t,i,n,e){void 0===i&&(i="WebSDK"),void 0===n&&(n=2),void 0===e&&(e="data"),this.db=null,this.logger=t,this.dbName=i,this.version=n,this.storeName=e,this.eventsStoreName="events"}return t.prototype.logAndReject=function(t,i,n){this.logger.error("IndexedDB request failed",{operation:i,error:n}),t(n)},t.prototype.attachTransactionSafety=function(t,i,n){var e=this;t.onabort=function(){return e.logAndReject(i,"".concat(n,":transaction"),t.error)},t.onerror=function(){return e.logAndReject(i,"".concat(n,":transaction"),t.error)}},t.prototype.openDB=function(){return ve(this,void 0,void 0,function(){var t=this;return me(this,function(i){return this.db?[2,this.db]:[2,new Promise(function(i,n){var e=indexedDB.open(t.dbName,t.version);e.onerror=function(){return t.logAndReject(n,"openDB",e.error)},e.onblocked=function(){return t.logAndReject(n,"openDB",new Error("IndexedDB open request blocked by another open connection"))},e.onsuccess=function(){t.db=e.result,t.db.onversionchange=function(){var i;t.logger.info("IndexedDB version change detected by another connection, closing"),null===(i=t.db)||void 0===i||i.close(),t.db=null},i(t.db)},e.onupgradeneeded=function(i){var n=i.target.result;if(t.logger.info("IndexedDB schema upgrade",{dbName:t.dbName,oldVersion:i.oldVersion,newVersion:i.newVersion}),n.objectStoreNames.contains(t.storeName)||n.createObjectStore(t.storeName),!n.objectStoreNames.contains(t.eventsStoreName)){var e=n.createObjectStore(t.eventsStoreName,{keyPath:"id"});e.createIndex("timestamp","timestamp",{unique:!1}),e.createIndex("status","status",{unique:!1})}}})]})})},t.prototype.getItem=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.storeName],"readonly");n.attachTransactionSafety(s,r,"getItem");var o=s.objectStore(n.storeName).get(t);o.onerror=function(){return n.logAndReject(r,"getItem",o.error)},o.onsuccess=function(){var t=o.result;e(null==t?null:"string"==typeof t?t:"object"==typeof t?JSON.stringify(t):String(t))}})]}})})},t.prototype.setItem=function(t,i){return ve(this,void 0,void 0,function(){var n,e=this;return me(this,function(r){switch(r.label){case 0:return[4,this.openDB()];case 1:return n=r.sent(),[2,new Promise(function(r,s){var o=n.transaction([e.storeName],"readwrite");e.attachTransactionSafety(o,s,"setItem");var u=o.objectStore(e.storeName).put(i,t);u.onerror=function(){return e.logAndReject(s,"setItem",u.error)},u.onsuccess=function(){return r()}})]}})})},t.prototype.removeItem=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.storeName],"readwrite");n.attachTransactionSafety(s,r,"removeItem");var o=s.objectStore(n.storeName).delete(t);o.onerror=function(){return n.logAndReject(r,"removeItem",o.error)},o.onsuccess=function(){return e()}})]}})})},t.prototype.clear=function(){return ve(this,void 0,void 0,function(){var t,i=this;return me(this,function(n){switch(n.label){case 0:return[4,this.openDB()];case 1:return t=n.sent(),[2,new Promise(function(n,e){var r=t.transaction([i.storeName],"readwrite");i.attachTransactionSafety(r,e,"clear");var s=r.objectStore(i.storeName).clear();s.onerror=function(){return i.logAndReject(e,"clear",s.error)},s.onsuccess=function(){return n()}})]}})})},t.prototype.getAllKeys=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.storeName],"readonly");n.attachTransactionSafety(s,r,"getAllKeys");var o=s.objectStore(n.storeName).getAllKeys();o.onerror=function(){return n.logAndReject(r,"getAllKeys",o.error)},o.onsuccess=function(){var i=o.result.map(function(t){return String(t)});e(t?i.filter(function(i){return i.startsWith(t)}):i)}})]}})})},t.prototype.close=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.db&&(this.db.close(),this.db=null),[2]})})},t.prototype.addEvent=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readwrite");n.attachTransactionSafety(s,r,"addEvent");var o=s.objectStore(n.eventsStoreName).add(t);o.onerror=function(){return n.logAndReject(r,"addEvent",o.error)},o.onsuccess=function(){return e()}})]}})})},t.prototype.getOldestPendingEvents=function(t){return ve(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=50),me(this,function(r){switch(r.label){case 0:return[4,this.openDB()];case 1:return n=r.sent(),[2,new Promise(function(r,s){var o=n.transaction([e.eventsStoreName],"readonly");e.attachTransactionSafety(o,s,"getOldestPendingEvents");var u=o.objectStore(e.eventsStoreName).index("timestamp").openCursor(),a=[],c=0;u.onerror=function(){return e.logAndReject(s,"getOldestPendingEvents",u.error)},u.onsuccess=function(n){var e=n.target.result;if(e&&c<i){var s=e.value;"pending"===s.status&&s.accountId===t&&(a.push(s),c++),e.continue()}else r(a)}})]}})})},t.prototype.updateEventStatus=function(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s=this;return me(this,function(o){switch(o.label){case 0:return[4,this.openDB()];case 1:return r=o.sent(),[2,new Promise(function(o,u){var a=r.transaction([s.eventsStoreName],"readwrite");s.attachTransactionSafety(a,u,"updateEventStatus");var c=a.objectStore(s.eventsStoreName),h=c.get(t);h.onerror=function(){return s.logAndReject(u,"updateEventStatus:get",h.error)},h.onsuccess=function(){var r=h.result;if(r){r.status=i,r.lastAttempt=Date.now(),n&&(r.error=n),void 0!==e&&(r.attempts=e);var a=c.put(r);a.onerror=function(){return s.logAndReject(u,"updateEventStatus:put",a.error)},a.onsuccess=function(){return o()}}else s.logAndReject(u,"updateEventStatus",new Error("Event with id ".concat(t," not found")))}})]}})})},t.prototype.removeEvents=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readwrite");n.attachTransactionSafety(s,r,"removeEvents");var o=s.objectStore(n.eventsStoreName),u=0,a=t.length;0!==a?t.forEach(function(t){var i=o.delete(t);i.onerror=function(){return n.logAndReject(r,"removeEvents",i.error)},i.onsuccess=function(){++u===a&&e()}}):e()})]}})})},t.prototype.recoverOrphanedEvents=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readwrite");n.attachTransactionSafety(s,r,"recoverOrphanedEvents");var o=s.objectStore(n.eventsStoreName).openCursor(),u=0;o.onerror=function(){return n.logAndReject(r,"recoverOrphanedEvents",o.error)},o.onsuccess=function(i){var s=i.target.result;if(s){var o=s.value;if("processing"===o.status&&o.accountId===t){o.status="failed",o.lastAttempt=Date.now(),o.error="Recovered from orphaned processing state";var a=s.update(o);a.onerror=function(){return n.logAndReject(r,"recoverOrphanedEvents:update",a.error)},a.onsuccess=function(){u++}}s.continue()}else e(u)}})]}})})},t.prototype.getPendingEventCount=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readonly");n.attachTransactionSafety(s,r,"getPendingEventCount");var o=s.objectStore(n.eventsStoreName).openCursor(),u=0;o.onerror=function(){return n.logAndReject(r,"getPendingEventCount",o.error)},o.onsuccess=function(i){var n=i.target.result;if(n){var r=n.value;"pending"===r.status&&r.accountId===t&&u++,n.continue()}else e(u)}})]}})})},t.prototype.getRetryableEvents=function(t){return ve(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=5),me(this,function(r){switch(r.label){case 0:return[4,this.openDB()];case 1:return n=r.sent(),[2,new Promise(function(r,s){var o=n.transaction([e.eventsStoreName],"readonly");e.attachTransactionSafety(o,s,"getRetryableEvents");var u=o.objectStore(e.eventsStoreName).openCursor(),a=[];u.onerror=function(){return e.logAndReject(s,"getRetryableEvents",u.error)},u.onsuccess=function(n){var e=n.target.result;if(e){var s=e.value;"failed"===s.status&&s.attempts<=i&&s.accountId===t&&a.push(s),e.continue()}else r(a)}})]}})})},t}(),rc=function(){function t(t,i,n,e,r){if(this.currentAccountId=null,this.currentCuid=null,this.currentUserIdentifierType=null,this.currentVisitorId=null,this.currentVisitorExternalId=null,this.getSessionInfo=null,this.isProcessing=!1,this.processingPromise=null,this.paused=!1,this.apiClient=t,this.logger=i,this.BATCH_SIZE=r||De.BATCH_SIZE,this.RETRY_DELAYS=e||De.DEFAULT_RETRY_DELAYS,n&&"getIndexedDBAdapter"in n){var s=n.getIndexedDBAdapter();s?(i.info("EventQueue: Reusing existing IndexedDB adapter from StorageManager"),this.storage=s):(i.warn("EventQueue: StorageManager has no IndexedDB adapter, creating new one"),this.storage=new ec(i))}else n?(i.info("EventQueue: Using provided IndexedDBStorage"),this.storage=n):(i.warn("EventQueue: No storage provided, creating new IndexedDBStorage"),this.storage=new ec(i))}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Initializing EventQueue"),[4,this.processQueueIfIdle()];case 1:return t.sent(),this.logger.info(Ze),[2]}})})},t.prototype.setUserContext=function(t,i,n){return ve(this,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return this.currentAccountId=t,this.currentCuid=i||null,this.currentUserIdentifierType=n||null,this.logger.debug("EventQueue user context set",{accountId:t,cuid:i,userIdentifierType:n}),[4,this.storage.recoverOrphanedEvents(t)];case 1:return(e=r.sent())>0&&this.logger.info("Recovered ".concat(e," orphaned processing events for account ").concat(t)),[2]}})})},t.prototype.setVisitorContext=function(t,i){this.currentVisitorId=t,this.currentVisitorExternalId=null!=i?i:null,this.logger.debug("EventQueue visitor context set",{visitorId:t,visitorExternalId:i})},t.prototype.setSessionInfoCallback=function(t){this.getSessionInfo=t,this.logger.debug("EventQueue session info callback set")},t.prototype.getCurrentAccountId=function(){return this.currentAccountId},t.prototype.getCurrentCuid=function(){return this.currentCuid},t.prototype.getCurrentVisitorId=function(){return this.currentVisitorId},t.prototype.clearUserContext=function(){this.currentCuid=null,this.currentUserIdentifierType=null,this.logger.debug("EventQueue user context cleared (cuid removed)")},t.prototype.enqueue=function(t){return ve(this,arguments,void 0,function(t,i){var n,e,r;return void 0===i&&(i=!1),me(this,function(s){switch(s.label){case 0:if(!this.currentAccountId)throw new Error("Cannot enqueue event: No account context set");if(n=null,!this.getSessionInfo)return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.getSessionInfo()];case 2:return n=s.sent(),[3,4];case 3:return e=s.sent(),this.logger.error("Failed to resolve session ID at enqueue time",{error:e}),[3,4];case 4:return r={id:ea(),event:t,accountId:this.currentAccountId,timestamp:(new Date).toISOString(),attempts:0,status:De.STATUSES.PENDING,visitorId:this.currentVisitorId,visitorExternalId:this.currentVisitorExternalId,cuid:this.currentCuid,userIdentifierType:this.currentUserIdentifierType,sessionId:n,isDLR:i},[4,this.storage.addEvent(r)];case 5:return s.sent(),this.logger.debug(nr,{eventId:r.id,eventName:t.name,visitorId:r.visitorId,cuid:r.cuid,sessionId:r.sessionId,isDLR:i}),[4,this.processQueueIfIdle()];case 6:return s.sent(),[2]}})})},t.prototype.processQueueIfIdle=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.paused?(this.logger.debug("Queue processing paused, skipping"),[2]):this.isProcessing?(this.logger.debug(fr),[2]):(this.processingPromise||(this.processingPromise=this.processQueue()),[2,this.processingPromise])})})},t.prototype.getIdentityKey=function(t){var i,n,e,r,s,o=null!==(i=t.visitorId)&&void 0!==i?i:"_none_",u=null!==(n=t.visitorExternalId)&&void 0!==n?n:"_none_",a=null!==(e=t.cuid)&&void 0!==e?e:"_none_",c=null!==(r=t.userIdentifierType)&&void 0!==r?r:"_none_",h=null!==(s=t.sessionId)&&void 0!==s?s:"_none_";return"".concat(o,"|").concat(u,"|").concat(a,"|").concat(c,"|").concat(h)},t.prototype.groupEventsByIdentity=function(t){var i,n,e=new Map;try{for(var r=ge(t),s=r.next();!s.done;s=r.next()){var o=s.value,u=this.getIdentityKey(o),a=e.get(u);a?a.push(o):e.set(u,[o])}}catch(t){i={error:t}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return Array.from(e.values())},t.prototype.processQueue=function(){return ve(this,void 0,void 0,function(){var i=this;return me(this,function(n){switch(n.label){case 0:return this.isProcessing?[2]:"undefined"!=typeof navigator&&"locks"in navigator?[4,navigator.locks.request(t.QUEUE_LOCK_NAME,{ifAvailable:!0},function(t){return ve(i,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return t?[4,this.executeProcessQueue()]:(this.logger.debug("Queue lock held by another tab, skipping"),[2]);case 1:return i.sent(),[2]}})})})]:[3,2];case 1:return n.sent(),[3,4];case 2:return[4,this.executeProcessQueue()];case 3:n.sent(),n.label=4;case 4:return[2]}})})},t.prototype.executeProcessQueue=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:this.isProcessing=!0,this.logger.debug(cr),h.label=1;case 1:h.trys.push([1,16,17,18]),h.label=2;case 2:return this.paused?(this.logger.debug("Queue processing paused mid-cycle, stopping"),[3,15]):[4,this.checkAndPromoteRetryEvents()];case 3:return h.sent(),this.currentAccountId?[4,this.storage.getOldestPendingEvents(this.currentAccountId,this.BATCH_SIZE)]:(this.logger.debug("No account context, skipping event processing"),[3,15]);case 4:if(0===(t=h.sent()).length)return this.logger.debug(lr),[3,15];i=this.groupEventsByIdentity(t),this.logger.info("Processing events",{totalEvents:t.length,identityGroups:i.length}),h.label=5;case 5:h.trys.push([5,11,12,13]),a=void 0,n=ge(i),e=n.next(),h.label=6;case 6:return e.done?[3,10]:(r=e.value,s=r[0],this.logger.debug("Processing identity group",{batchSize:r.length,visitorId:null==s?void 0:s.visitorId,cuid:null==s?void 0:s.cuid,sessionId:null==s?void 0:s.sessionId}),[4,this.markEventsAsProcessing(r)]);case 7:return h.sent(),[4,this.sendBatch(r)];case 8:h.sent(),h.label=9;case 9:return e=n.next(),[3,6];case 10:return[3,13];case 11:return o=h.sent(),a={error:o},[3,13];case 12:try{e&&!e.done&&(c=n.return)&&c.call(n)}finally{if(a)throw a.error}return[7];case 13:return[4,this.storage.getPendingEventCount(this.currentAccountId)];case 14:return 0===h.sent()?(this.logger.debug(vr),[3,15]):[3,2];case 15:return[3,18];case 16:return u=h.sent(),this.logger.error(dr,{error:u}),[3,18];case 17:return this.isProcessing=!1,this.processingPromise=null,this.logger.debug(hr),[7];case 18:return[2]}})})},t.prototype.markEventsAsProcessing=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=ge(t),n=i.next(),a.label=1;case 1:if(n.done)return[3,6];e=n.value,a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.storage.updateEventStatus(e.id,"processing")];case 3:return a.sent(),[3,5];case 4:return r=a.sent(),this.logger.error(mr,{eventId:e.id,error:r}),[3,5];case 5:return n=i.next(),[3,1];case 6:return[3,9];case 7:return s=a.sent(),o={error:s},[3,9];case 8:try{n&&!n.done&&(u=i.return)&&u.call(i)}finally{if(o)throw o.error}return[7];case 9:return[2]}})})},t.prototype.sendBatch=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:if(h.trys.push([0,5,,10]),!this.currentAccountId)throw new Error("Missing account context for batch sending");return i=t[0],n=!!(null!==(c=i.visitorId)&&void 0!==c?c:i.visitorExternalId),e=!!i.cuid,r=void 0,r=n&&e?"identified":n?"anonymous":"user-only",this.logger.debug("Sending event batch",{batchSize:t.length,trackingMode:r,hasVisitor:n,hasUser:e}),s=t.filter(function(t){return!0===t.isDLR}),(o=t.filter(function(t){return!0!==t.isDLR})).length>0?[4,this.sendRegularEvents(o)]:[3,2];case 1:h.sent(),h.label=2;case 2:return s.length>0?[4,this.sendDLREvents(s)]:[3,4];case 3:h.sent(),h.label=4;case 4:return[2,!0];case 5:return u=h.sent(),a=this.isRetryableHttpError(u),this.logger.error(ar,{batchSize:t.length,hasDLREvents:t.some(function(t){return!0===t.isDLR}),error:u,isRetryable:a}),a?[4,this.handleFailedBatch(t)]:[3,7];case 6:return h.sent(),[3,9];case 7:return[4,this.removeNonRetryableEvents(t)];case 8:h.sent(),h.label=9;case 9:return[2,!1];case 10:return[2]}})})},t.prototype.sendRegularEvents=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l,v;return me(this,function(m){switch(m.label){case 0:if(i=t[0],n=null!==(h=i.visitorId)&&void 0!==h?h:null,e=null!==(d=i.visitorExternalId)&&void 0!==d?d:null,r=null!==(f=i.cuid)&&void 0!==f?f:null,s=null!==(l=i.userIdentifierType)&&void 0!==l?l:null,o=null!==(v=i.sessionId)&&void 0!==v?v:null,u=this.apiClient,a=t.map(function(t){return t.event}),!o)throw new Error("Session ID is required for event tracking");return[4,u.sendEvents(a,n||void 0,e||void 0,r||void 0,s||void 0,o)];case 1:return c=m.sent(),[4,this.handleBatchResponse(t,c)];case 2:return m.sent(),[2]}})})},t.prototype.sendDLREvents=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a;return me(this,function(c){switch(c.label){case 0:return i=t[0],n=this.apiClient,e=null!==(a=i.sessionId)&&void 0!==a?a:"",[4,va()];case 1:return r=c.sent(),s=oa(e,r),o={events:t.map(function(t){var i=t.event,n=i.eventExternalId,e=function(t,i){var n={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&i.indexOf(e)<0&&(n[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(e=Object.getOwnPropertySymbols(t);r<e.length;r++)i.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(t,e[r])&&(n[e[r]]=t[e[r]])}return n}(i,["eventExternalId"]);return le(le({},e),{eventRefId:n})}),request_id:ea(),system_data:s},i.cuid?o.user={identifierName:"id",identifierValue:i.cuid}:i.visitorId&&(o.visitor={identifierName:"id",identifierValue:i.visitorId}),[4,n.sendDLR(o)];case 2:return u=c.sent(),[4,this.handleBatchResponse(t,u,De.DLR_SUCCESS_CODE)];case 3:return c.sent(),[2]}})})},t.prototype.removeSuccessfulEvents=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:i=t.map(function(t){return t.id}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.storage.removeEvents(i)];case 2:return e.sent(),this.logger.debug("Successfully removed events from storage",{count:i.length}),[3,4];case 3:return n=e.sent(),this.logger.error(gr,{eventIds:i,error:n}),[3,4];case 4:return[2]}})})},t.prototype.handleBatchResponse=function(t,i){return ve(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=De.GLOBAL_SUCCESS_CODE),me(this,function(s){switch(s.label){case 0:return e=parseInt(i.status.code,10),r=t.some(function(t){return!0===t.isDLR}),e!==n?[3,2]:[4,this.removeSuccessfulEvents(t)];case 1:return s.sent(),this.logger.info("All events processed successfully",{count:t.length,hasDLREvents:r}),[3,8];case 2:return e!==De.PARTIAL_SUCCESS_CODE?[3,4]:[4,this.handlePartialSuccess(t,i.events)];case 3:return s.sent(),[3,8];case 4:return De.RETRYABLE_HTTP_CODES.includes(e)?[4,this.handleFailedBatch(t)]:[3,6];case 5:return s.sent(),this.logger.warn("Batch failed with retryable error",{code:e,message:i.status.message,hasDLREvents:r}),[3,8];case 6:return[4,this.removeNonRetryableEvents(t)];case 7:s.sent(),this.logger.error("Batch failed with non-retryable error",{code:e,message:i.status.message,hasDLREvents:r}),s.label=8;case 8:return[2]}})})},t.prototype.handlePartialSuccess=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h;return me(this,function(d){switch(d.label){case 0:n=new Map,i.forEach(function(t){n.set(t.eventExternalId,t)}),d.label=1;case 1:d.trys.push([1,12,13,14]),e=ge(t),r=e.next(),d.label=2;case 2:return r.done?[3,11]:(s=r.value,(o=n.get(s.event.eventExternalId))?[3,4]:[4,this.markEventForRetry(s,"No response received")]);case 3:return d.sent(),[3,10];case 4:return o.status.success?[4,this.storage.removeEvents([s.id])]:[3,6];case 5:return d.sent(),this.logger.debug("Event processed successfully",{eventId:s.id}),[3,10];case 6:return u=parseInt(o.status.code,10),De.RETRYABLE_HTTP_CODES.includes(u)?[4,this.markEventForRetry(s,o.status.message)]:[3,8];case 7:return d.sent(),[3,10];case 8:return[4,this.storage.removeEvents([s.id])];case 9:d.sent(),this.logger.warn("Event permanently failed - removed",{eventId:s.id,isDLR:s.isDLR,code:u,message:o.status.message}),d.label=10;case 10:return r=e.next(),[3,2];case 11:return[3,14];case 12:return a=d.sent(),c={error:a},[3,14];case 13:try{r&&!r.done&&(h=e.return)&&h.call(e)}finally{if(c)throw c.error}return[7];case 14:return[2]}})})},t.prototype.markEventForRetry=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r;return me(this,function(s){switch(s.label){case 0:return n=(t.attempts||0)+1,[4,this.storage.updateEventStatus(t.id,"failed","Attempt ".concat(n," failed: ").concat(i),n)];case 1:return s.sent(),e=Math.min(Math.max(n-1,0),this.RETRY_DELAYS.length-1),r=this.RETRY_DELAYS[e],this.logger.warn("Event marked for retry",{eventId:t.id,isDLR:t.isDLR,attempts:n,delay:r,isInfiniteRetry:n>this.RETRY_DELAYS.length,errorMessage:i}),[2]}})})},t.prototype.checkAndPromoteRetryEvents=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:return f.trys.push([0,10,,11]),this.currentAccountId?[4,this.storage.getRetryableEvents(this.currentAccountId,Number.MAX_SAFE_INTEGER)]:(this.logger.debug("No account context, skipping retry check"),[2]);case 1:if(0===(t=f.sent()).length)return[2];i=0,f.label=2;case 2:f.trys.push([2,7,8,9]),n=ge(t),e=n.next(),f.label=3;case 3:return e.done?[3,6]:(r=e.value,s=Math.min(Math.max(r.attempts-1,0),this.RETRY_DELAYS.length-1),o=this.RETRY_DELAYS[s],(u=Date.now()-(r.lastAttempt||0))>=(o||0)?[4,this.storage.updateEventStatus(r.id,"pending")]:[3,5]);case 4:f.sent(),i++,this.logger.debug("Failed event promoted to pending",{eventId:r.id,attempt:r.attempts+1,delay:o,timeSinceLastAttempt:u}),f.label=5;case 5:return e=n.next(),[3,3];case 6:return[3,9];case 7:return a=f.sent(),h={error:a},[3,9];case 8:try{e&&!e.done&&(d=n.return)&&d.call(n)}finally{if(h)throw h.error}return[7];case 9:return i>0&&this.logger.debug("Promoted ".concat(i," failed events for retry")),[3,11];case 10:return c=f.sent(),this.logger.error("Failed to check retry events",{error:c}),[3,11];case 11:return[2]}})})},t.prototype.isRetryableHttpError=function(t){var i,n,e,r,s=t;if(s.code){var o=parseInt(s.code,10);return De.RETRYABLE_HTTP_CODES.includes(o)}return null!==(r=(null===(i=s.message)||void 0===i?void 0:i.includes("network"))||(null===(n=s.message)||void 0===n?void 0:n.includes("timeout"))||(null===(e=s.message)||void 0===e?void 0:e.includes("fetch")))&&void 0!==r&&r},t.prototype.removeNonRetryableEvents=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:i=t.map(function(t){return t.id}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.storage.removeEvents(i)];case 2:return e.sent(),this.logger.error("Non-retryable events removed permanently",{eventIds:i}),[3,4];case 3:return n=e.sent(),this.logger.error("Failed to remove non-retryable events",{eventIds:i,error:n}),[3,4];case 4:return[2]}})})},t.prototype.handleFailedBatch=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=ge(t),n=i.next(),a.label=1;case 1:if(n.done)return[3,6];e=n.value,a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.markEventForRetry(e,"Batch failed")];case 3:return a.sent(),[3,5];case 4:return r=a.sent(),this.logger.error("Failed to mark event for retry",{eventId:e.id,error:r}),[3,5];case 5:return n=i.next(),[3,1];case 6:return[3,9];case 7:return s=a.sent(),o={error:s},[3,9];case 8:try{n&&!n.done&&(u=i.return)&&u.call(i)}finally{if(o)throw o.error}return[7];case 9:return[2]}})})},t.prototype.pause=function(){this.paused=!0,this.logger.info("EventQueue paused")},t.prototype.resume=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.paused=!1,this.logger.info("EventQueue resumed"),[4,this.processQueueIfIdle()];case 1:return t.sent(),[2]}})})},t.prototype.flush=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return[4,this.processQueueIfIdle()];case 1:return t.sent(),[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Destroying EventQueue"),this.processingPromise?[4,this.processingPromise]:[3,2];case 1:t.sent(),t.label=2;case 2:return[4,this.storage.close()];case 3:return t.sent(),this.logger.info("EventQueue destroyed"),[2]}})})},t.QUEUE_LOCK_NAME="websdk-event-queue-lock",t}(),sc=function(){function t(t,i,n,e){this.eventQueue=null,this.initialized=!1,this.visitorId=null,this.visitorTrackingEnabled=null,this.config=t,this.logger=e,this.apiClient=i,this.storageManager=n}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized?(this.logger.warn("EventTracker already initialized"),[2]):(this.logger.info("Initializing EventTracker with IndexedDB queue"),this.eventQueue=new rc(this.apiClient,this.logger,this.storageManager,this.config.retryDelays,this.config.batchSize),[4,this.eventQueue.init()]);case 1:return t.sent(),this.initialized=!0,this.logger.info(tr),[2]}})})},t.prototype.setUserContext=function(t,i,n){return ve(this,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:if(!this.eventQueue)throw new Error("EventTracker not initialized");return[4,this.eventQueue.setUserContext(t,i,n)];case 1:return e.sent(),this.logger.info("User context set",{accountId:t,cuid:i,userIdentifierType:n}),[2]}})})},t.prototype.setVisitorTrackingState=function(t,i,n){this.visitorId=t,this.visitorTrackingEnabled=i,this.eventQueue&&this.eventQueue.setVisitorContext(t,n),this.logger.debug("Visitor tracking state updated",{visitorId:t,visitorExternalId:n,isEnabled:i,trackingMode:t?"anonymous":"not-configured"})},t.prototype.setSessionInfoCallback=function(t){if(!this.eventQueue)throw new Error("EventTracker not initialized");this.eventQueue.setSessionInfoCallback(t),this.logger.debug("Session info callback set in EventTracker")},t.prototype.clearUserContext=function(){this.eventQueue?(this.eventQueue.clearUserContext(),this.logger.info("User context cleared from EventTracker")):this.logger.warn("Cannot clear user context - EventTracker not initialized")},t.prototype.track=function(t){return ve(this,arguments,void 0,function(t,i){var n,e;return void 0===i&&(i=!1),me(this,function(r){switch(r.label){case 0:if(!this.initialized||!this.eventQueue)throw new Error("EventTracker not initialized");if(!1===this.visitorTrackingEnabled&&!i)throw this.logger.warn("Event tracking is disabled - visitor tracking is not enabled"),new Error("Event tracking is disabled");this.logger.debug("Tracking event",{event:t}),r.label=1;case 1:return r.trys.push([1,3,,4]),n=this.convertToApiEvent(t),[4,this.eventQueue.enqueue(n)];case 2:return r.sent(),[3,4];case 3:throw e=r.sent(),this.logger.error(er,{event:t,error:e}),new Error("".concat(Le,": ").concat(e));case 4:return[2]}})})},t.prototype.convertToApiEvent=function(t){if(!t.name||""===t.name.trim())throw new Error("Event name is required");var i=le({},t.data);if(!this.eventQueue)throw new Error("EventTracker not initialized");var n,e=this.eventQueue.getCurrentCuid();if(!e&&!this.visitorId){var r=null===this.visitorTrackingEnabled?"Cannot track event: User must be identified (cuid) or visitor tracking must be configured":"Cannot track event: Either visitor tracking must be enabled or user must be identified";throw this.logger.error(r,{hasVisitorId:!!this.visitorId,hasCuid:!1,visitorTrackingEnabled:this.visitorTrackingEnabled}),new Error(r)}return n=this.visitorId&&e?"identified":this.visitorId?"anonymous":"user-only",this.logger.debug("Creating event payload",{eventName:t.name,hasCuid:!!e,hasVisitorId:!!this.visitorId,trackingMode:n,visitorTrackingEnabled:this.visitorTrackingEnabled}),function(t,i){if(!t||""===t.trim())throw new Error("Event name is required");return{name:t.trim(),eventExternalId:ea(),eventDateTime:(new Date).toISOString(),attributes:i||{}}}(t.name,i)},t.prototype.pause=function(){this.eventQueue&&this.eventQueue.pause(),this.logger.info("EventTracker paused")},t.prototype.resume=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.eventQueue?[4,this.eventQueue.resume()]:[3,2];case 1:t.sent(),t.label=2;case 2:return this.logger.info("EventTracker resumed"),[2]}})})},t.prototype.flush=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized&&this.eventQueue?(this.logger.info("Manual flush requested"),[4,this.eventQueue.flush()]):(this.logger.warn("Cannot flush events - EventTracker not initialized"),[2]);case 1:return t.sent(),[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Destroying EventTracker"),this.eventQueue?[4,this.eventQueue.destroy()]:[3,2];case 1:t.sent(),t.label=2;case 2:return this.initialized=!1,this.logger.info(ir),[2]}})})},t.prototype.trackNotificationReceived=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return[4,this.trackDLREvent("received",t)];case 1:return i.sent(),[2]}})})},t.prototype.trackNotificationClicked=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return[4,this.trackDLREvent("clicked",t)];case 1:return i.sent(),[2]}})})},t.prototype.trackNotificationDismissed=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return[4,this.trackDLREvent("dismissed",t)];case 1:return i.sent(),[2]}})})},t.prototype.trackDLREvent=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:if(!this.initialized||!this.eventQueue)return this.logger.error("EventTracker not initialized, skipping DLR event",{eventType:t}),[2];r.label=1;case 1:return r.trys.push([1,3,,4]),n=this.createDLREvent(t,i),[4,this.eventQueue.enqueue(n,!0)];case 2:return r.sent(),this.logger.info("DLR event tracked: ".concat(t),{eventType:t,eventName:n.name,messageId:i.messageId}),[3,4];case 3:return e=r.sent(),this.logger.error("Failed to track DLR event",{eventType:t,notificationData:i,error:e}),[3,4];case 4:return[2]}})})},t.prototype.createDLREvent=function(t,i){var n,e={received:Bs.NOTIFICATION_RECEIVED,clicked:Bs.NOTIFICATION_CLICKED,dismissed:Bs.NOTIFICATION_DISMISSED},r=null===(n=this.eventQueue)||void 0===n?void 0:n.getCurrentCuid(),s={messageId:i.messageId,gateway:zs,result:{received:"SUCCESS",clicked:"CLICKED",dismissed:"DISMISSED"}[t],notification_route:js,cuid:r||null,visitor_id:r?null:this.visitorId||null,scope:i.scope||null};return"received"===t&&(s.notification_id=i.messageId,s.campaign_id=i.campaignId||null,s.channel=js,s.title=i.title||null),"clicked"===t&&(s.notification_id=i.messageId,s.campaign_id=i.campaignId||null,s.channel=js,s.action="open_app"),i.senderId&&(s.senderId=i.senderId),{attributes:s,name:e[t],eventDateTime:(new Date).toISOString(),eventExternalId:ea()}},t.prototype.dispatchDLREvent=function(t){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:switch(i=le(le(le(le(le(le({messageId:t.messageId},void 0!==t.scope?{scope:t.scope}:{}),void 0!==t.campaignId?{campaignId:t.campaignId}:{}),void 0!==t.variationId?{variationId:t.variationId}:{}),void 0!==t.senderId?{senderId:t.senderId}:{}),void 0!==t.cuid?{cuid:t.cuid}:{}),void 0!==t.accountId?{accountId:t.accountId}:{}),t.type){case"received":return[3,1];case"clicked":return[3,3];case"dismissed":return[3,5]}return[3,7];case 1:return[4,this.trackNotificationReceived(i)];case 2:case 4:case 6:return n.sent(),[3,7];case 3:return[4,this.trackNotificationClicked(i)];case 5:return[4,this.trackNotificationDismissed(i)];case 7:return[2]}})})},t.prototype.processPendingServiceWorkerDLREvents=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:if(!this.initialized)return this.logger.error("EventTracker not initialized, skipping pending DLR event processing"),[2];a.label=1;case 1:return a.trys.push([1,12,,13]),[4,this.getServiceWorkerPendingDLREvents()];case 2:if(0===(t=a.sent()).length)return[2];this.logger.info("Processing pending service worker DLR events",{count:t.length}),a.label=3;case 3:a.trys.push([3,8,9,10]),i=ge(t),n=i.next(),a.label=4;case 4:return n.done?[3,7]:(e=n.value,[4,this.dispatchDLREvent(e)]);case 5:a.sent(),a.label=6;case 6:return n=i.next(),[3,4];case 7:return[3,10];case 8:return r=a.sent(),o={error:r},[3,10];case 9:try{n&&!n.done&&(u=i.return)&&u.call(i)}finally{if(o)throw o.error}return[7];case 10:return[4,this.clearServiceWorkerPendingDLREvents()];case 11:return a.sent(),this.logger.info("Processed pending service worker DLR events",{count:t.length}),[3,13];case 12:return s=a.sent(),this.logger.error("Failed to process pending service worker DLR events",{error:s}),[3,13];case 13:return[2]}})})},t.prototype.getServiceWorkerPendingDLREvents=function(){return ve(this,void 0,void 0,function(){var t=this;return me(this,function(i){return[2,new Promise(function(i){var n=indexedDB.open("WebSDK_DLR_SW",1);n.onerror=function(){t.logger.error("Failed to open WebSDK_DLR_SW database",n.error),i([])},n.onsuccess=function(){var e=n.result;if(!e.objectStoreNames.contains("pending_dlr_events"))return e.close(),void i([]);var r=e.transaction(["pending_dlr_events"],"readonly").objectStore("pending_dlr_events").getAll();r.onerror=function(){t.logger.error("Failed to read pending service worker DLR events",r.error),e.close(),i([])},r.onsuccess=function(){e.close(),i(r.result||[])}},n.onupgradeneeded=function(t){var i=t.target.result;i.objectStoreNames.contains("pending_dlr_events")||i.createObjectStore("pending_dlr_events",{keyPath:"id",autoIncrement:!0})}})]})})},t.prototype.clearServiceWorkerPendingDLREvents=function(){return ve(this,void 0,void 0,function(){var t=this;return me(this,function(i){return[2,new Promise(function(i){var n=indexedDB.open("WebSDK_DLR_SW",1);n.onerror=function(){t.logger.error("Failed to open WebSDK_DLR_SW database",n.error),i()},n.onsuccess=function(){var e=n.result;if(!e.objectStoreNames.contains("pending_dlr_events"))return e.close(),void i();var r=e.transaction(["pending_dlr_events"],"readwrite").objectStore("pending_dlr_events").clear();r.onerror=function(){t.logger.error("Failed to clear pending service worker DLR events",r.error),e.close(),i()},r.onsuccess=function(){e.close(),i()}},n.onupgradeneeded=function(t){var i=t.target.result;i.objectStoreNames.contains("pending_dlr_events")||i.createObjectStore("pending_dlr_events",{keyPath:"id",autoIncrement:!0})}})]})})},t}(),oc=function(){function t(t,i,n){this.initialized=!1,this.logger=t,this.brandId=i,this.applicationId=n,this.adapter=new uc(t)}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:if(this.initialized)return this.logger.warn("StorageManager already initialized"),[2];this.logger.info("Initializing StorageManager"),t=["WebSDK"],this.brandId&&t.push(this.brandId),this.applicationId&&t.push(this.applicationId),i=t.join("_"),r.label=1;case 1:return r.trys.push([1,6,,7]),this.isIndexedDBSupported()?(n=new ec(this.logger,i),[4,this.testStorageAdapter(n)]):[3,3];case 2:return r.sent(),this.adapter=n,this.logger.info("StorageManager initialized with IndexedDB",{dbName:i,brandId:this.brandId,applicationId:this.applicationId}),[3,5];case 3:return[4,this.testStorageAdapter(this.adapter)];case 4:r.sent(),this.logger.info("StorageManager initialized with localStorage"),r.label=5;case 5:return this.initialized=!0,[3,7];case 6:throw e=r.sent(),this.logger.error(pr,{brandId:this.brandId,applicationId:this.applicationId,dbName:i,error:e}),new Error("Storage initialization failed: ".concat(e));case 7:return[2]}})})},t.prototype.isIndexedDBSupported=function(){return"undefined"!=typeof window&&"indexedDB"in window&&null!==indexedDB},t.prototype.testStorageAdapter=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:i=Ce,n=Re,r.label=1;case 1:return r.trys.push([1,5,,6]),[4,t.setItem(i,n)];case 2:return r.sent(),[4,t.getItem(i)];case 3:if(r.sent()!==n)throw new Error(yr);return[4,t.removeItem(i)];case 4:return r.sent(),[3,6];case 5:throw e=r.sent(),new Error("".concat(wr," ").concat(e));case 6:return[2]}})})},t.prototype.get=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.getItem(t)]})})},t.prototype.set=function(t,i){return ve(this,void 0,void 0,function(){return me(this,function(n){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.setItem(t,i)]})})},t.prototype.remove=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.removeItem(t)]})})},t.prototype.clear=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.clear()]})})},t.prototype.keys=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.getAllKeys(t)]})})},t.prototype.getIndexedDBAdapter=function(){return this.adapter instanceof ec?this.adapter:null},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:this.logger.info("Destroying StorageManager"),i.label=1;case 1:return i.trys.push([1,4,,5]),this.adapter instanceof ec?[4,this.adapter.close()]:[3,3];case 2:i.sent(),i.label=3;case 3:return this.initialized=!1,this.logger.info(Er),[3,5];case 4:return t=i.sent(),this.logger.error(_r,t),this.initialized=!1,[3,5];case 5:return[2]}})})},t}(),uc=function(){function t(t){this.logger=t}return t.prototype.getItem=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){try{return[2,localStorage.getItem(t)]}catch(i){throw this.logger.error("LocalStorage getItem failed",{key:t,error:i}),new Error("LocalStorage getItem failed: ".concat(i))}return[2]})})},t.prototype.setItem=function(t,i){return ve(this,void 0,void 0,function(){return me(this,function(n){try{localStorage.setItem(t,i)}catch(i){if(i instanceof DOMException&&(22===i.code||1014===i.code||"QuotaExceededError"===i.name||"NS_ERROR_DOM_QUOTA_REACHED"===i.name))throw this.logger.error("LocalStorage quota exceeded",{key:t,error:i}),new Error("LocalStorage quota exceeded");throw this.logger.error("LocalStorage setItem failed",{key:t,error:i}),new Error("LocalStorage setItem failed: ".concat(i))}return[2]})})},t.prototype.removeItem=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){try{localStorage.removeItem(t)}catch(i){throw this.logger.error("LocalStorage removeItem failed",{key:t,error:i}),new Error("LocalStorage removeItem failed: ".concat(i))}return[2]})})},t.prototype.clear=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){try{localStorage.clear()}catch(t){throw this.logger.error("LocalStorage clear failed",{error:t}),new Error("LocalStorage clear failed: ".concat(t))}return[2]})})},t.prototype.getAllKeys=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){try{for(i=[],n=0;n<localStorage.length;n++)null!==(e=localStorage.key(n))&&i.push(e);return[2,t?i.filter(function(i){return i.startsWith(t)}):i]}catch(t){throw this.logger.error("LocalStorage getAllKeys failed",{error:t}),new Error("LocalStorage getAllKeys failed: ".concat(t))}return[2]})})},t}();!function(t){t[t.VERBOSE=0]="VERBOSE",t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.NONE=5]="NONE"}(nc||(nc={}));var ac=function(){function t(t,i){void 0===t&&(t=!1),void 0===i&&(i=nc.INFO),this.logs=[],this.maxLogs=1e3,this.context={orgId:"",accountId:"",visitorId:"",cuid:""},this.enabled=t,this.level=i}return t.prototype.setContext=function(t){this.context=le(le({},this.context),t)},Object.defineProperty(t.prototype,"contextPrefix",{get:function(){var t=this.context.cuid||this.context.visitorId,i=[this.context.orgId,this.context.accountId,t].filter(Boolean);return i.length>0?"[".concat(i.join(" -> "),"]"):""},enumerable:!1,configurable:!0}),t.prototype.formatMessage=function(t,i){var n=(new Date).toISOString(),e=nc[t];return"[".concat(n,"] [WebSDK:").concat(e,"] ").concat(i)},t.prototype.log=function(t,i,n){if(this.enabled&&!(t<this.level)){var e={level:t,message:i,timestamp:Date.now(),data:n};this.logs.push(e),this.logs.length>this.maxLogs&&this.logs.shift();var r=t===nc.INFO||t===nc.ERROR?this.contextPrefix:"",s=r?"".concat(r," ").concat(i):i,o=this.formatMessage(t,s),u=n?[o,n]:[o];switch(t){case nc.VERBOSE:case nc.DEBUG:console.debug.apply(console,we([],pe(u),!1));break;case nc.INFO:console.info.apply(console,we([],pe(u),!1));break;case nc.WARN:console.warn.apply(console,we([],pe(u),!1));break;case nc.ERROR:console.error.apply(console,we([],pe(u),!1))}}},t.prototype.verbose=function(t,i){this.log(nc.VERBOSE,t,i)},t.prototype.debug=function(t,i){this.log(nc.DEBUG,t,i)},t.prototype.info=function(t,i){this.log(nc.INFO,t,i)},t.prototype.warn=function(t,i){this.log(nc.WARN,t,i)},t.prototype.error=function(t,i){this.log(nc.ERROR,t,i)},t.prototype.setLevel=function(t){this.level=t},t.prototype.setEnabled=function(t){this.enabled=t},t.prototype.getLogs=function(){return we([],pe(this.logs),!1)},t.prototype.clearLogs=function(){this.logs=[]},t}(),cc=function(){function t(t,i,n,e,r,s){this.initialized=!1,this.cachedConfig=null,this.orgId=t,this.apiClient=i,this.logger=n,this.storageManager=e,void 0!==r&&(this.brandId=r),void 0!==s&&(this.applicationId=s)}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized?(this.logger.warn("VisitorConfigManager already initialized"),[2]):(this.logger.info("Initializing VisitorConfigManager",{orgId:this.orgId}),[4,this.restoreCachedConfig()]);case 1:return t.sent(),this.initialized=!0,this.logger.info(xr),[2]}})})},t.prototype.fetchConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n=this;return me(this,function(e){switch(e.label){case 0:if(!this.initialized)throw new Error("VisitorConfigManager not initialized");if(this.cachedConfig)return this.logger.info(Fr),[2,this.cachedConfig];e.label=1;case 1:return e.trys.push([1,4,,5]),this.logger.info("Fetching visitor config from API",{orgId:this.orgId}),[4,this.apiClient.getVisitorConfig(this.orgId)];case 2:return(t=e.sent()).warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){n.logger.warn("Visitor config warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0&&t.errors.forEach(function(t){n.logger.error("Visitor config error from response",{code:t.code,message:t.message})}),this.cachedConfig=t,[4,this.storeCachedConfig(t)];case 3:return e.sent(),[2,t];case 4:throw i=e.sent(),new Error("".concat(Fe,": ").concat(i));case 5:return[2]}})})},t.prototype.isVisitorTrackingEnabled=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.fetchConfig()];case 1:return t=r.sent(),(i=!0===(null===(e=t.data)||void 0===e?void 0:e.visitorTrackingEnabled))?this.logger.info(Lr):this.logger.info(Ur),[2,i];case 2:return n=r.sent(),this.logger.error("Failed to check visitor tracking status",{error:n}),[2,!1];case 3:return[2]}})})},t.prototype.refreshConfig=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){if(!this.initialized)throw new Error("VisitorConfigManager not initialized");return this.logger.info("Force refreshing visitor config from API"),this.cachedConfig=null,[2,this.fetchConfig()]})})},t.prototype.getCachedConfig=function(){return this.cachedConfig},t.prototype.storeCachedConfig=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Ae("VISITOR_CONFIG",this.brandId,this.applicationId),[4,this.storageManager.set(i,JSON.stringify(t))];case 1:return e.sent(),this.logger.debug("Visitor config cached to storage",{key:i}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store visitor config to cache",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.restoreCachedConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r;return me(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=Ae("VISITOR_CONFIG",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=s.sent())&&(n=JSON.parse(i),this.cachedConfig=n,this.logger.info("Visitor config restored from cache",{isEnabled:null===(r=n.data)||void 0===r?void 0:r.visitorTrackingEnabled})),[3,3];case 2:return e=s.sent(),this.logger.error("Failed to restore visitor config from cache",{error:e}),this.cachedConfig=null,[3,3];case 3:return[2]}})})},t.prototype.clearCachedConfig=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:this.cachedConfig=null,n.label=1;case 1:return n.trys.push([1,3,,4]),t=Ae("VISITOR_CONFIG",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 2:return n.sent(),this.logger.debug("Visitor config cache cleared"),[3,4];case 3:return i=n.sent(),this.logger.error("Failed to clear visitor config cache",{error:i}),[3,4];case 4:return[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Destroying VisitorConfigManager"),[4,this.clearCachedConfig()];case 1:return t.sent(),this.initialized=!1,this.logger.info("VisitorConfigManager destroyed successfully"),[2]}})})},t}(),hc=function(){function t(t,i,n,e,r,s){this.initialized=!1,this.visitorId=null,this.visitorExternalId=null,this.expiredAt=null,this.getFcmToken=null,this.getChannelType=null,this.getExtendedFields=null,this.getPermissionGranted=null,this.getSessionId=null,this.mergeRetryTimeoutId=null,this.accountId=t,this.orgId=i,this.apiClient=n,this.logger=e,this.storageManager=r,void 0!==(null==s?void 0:s.brandId)&&(this.brandId=s.brandId),void 0!==(null==s?void 0:s.applicationId)&&(this.applicationId=s.applicationId)}return t.prototype.setMergeDataProviders=function(t,i,n,e,r){this.getFcmToken=t,this.getChannelType=i,this.getExtendedFields=n,this.getPermissionGranted=e,this.getSessionId=r},t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized?(this.logger.warn("AnonymousVisitorManager already initialized"),[2]):(this.logger.info("Initializing AnonymousVisitorManager",{accountId:this.accountId,orgId:this.orgId}),[4,this.restoreVisitorId()]);case 1:return t.sent(),this.initialized=!0,this.logger.info(Gr),[2]}})})},t.prototype.getOrCreateVisitorId=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(!this.initialized)throw this.logger.error("getOrCreateVisitorId() called before AnonymousVisitorManager is initialized"),new Error("AnonymousVisitorManager not initialized");if(this.visitorId&&!this.isVisitorExpired())return this.logger.info(jr,{visitorId:this.visitorId}),[2,this.visitorId];if(this.visitorId&&this.isVisitorExpired()&&this.logger.info("Visitor session expired, creating new visitor via API",{visitorId:this.visitorId,expiredAt:this.expiredAt}),!this.accountId||""===this.accountId.trim())throw n=new Error("AccountId is required for visitor creation"),this.logger.error("Visitor creation validation failed",n),n;return this.logger.info("Creating new visitor ID",{accountId:this.accountId,hasCommChannels:!!t&&t.length>0,hasExtendedFields:!!i}),[4,this.createVisitor(t,i)];case 1:return e=o.sent(),r=e.visitorId,s=e.expiredAt,this.visitorId=r,[4,this.storeVisitorId(r)];case 2:return o.sent(),[4,this.storeExpiredAt(s)];case 3:return o.sent(),this.logger.info(Vr,{visitorId:r}),[2,r]}})})},t.prototype.createVisitor=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,3,,4]),[4,this.getOrGenerateVisitorExternalId()];case 1:return n=u.sent(),e=t&&t.length>0?t:[],r=le({visitorExternalId:n,profiles:[{commChannels:e}]},i&&{extendedFields:i}),this.logger.debug("Visitor creation request payload",{request:r}),[4,this.apiClient.createVisitor(this.orgId,r)];case 2:return s=u.sent(),[2,this.handleCreateVisitorResponse(s)];case 3:throw o=u.sent(),this.handleCreateVisitorError(o),o;case 4:return[2]}})})},t.prototype.handleCreateVisitorResponse=function(t){var i,n,e=this;t.warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){e.logger.warn("Visitor creation warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0&&t.errors.forEach(function(t){e.logger.error("Visitor creation error from response",{code:t.code,message:t.message})});var r=null===(i=t.data)||void 0===i?void 0:i.id;if(!r||""===r.trim())throw this.logger.error("Invalid visitor ID received from API",{response:t}),new Error("Invalid visitor ID received from API");var s=null===(n=t.data)||void 0===n?void 0:n.expiredAt;if(!s)throw this.logger.error("Missing expiredAt in visitor creation response",{response:t}),new Error("Missing expiredAt in visitor creation response");return{visitorId:r,expiredAt:s}},t.prototype.logCreateVisitorWarnings=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){t.code===Gs.ACCOUNT_NOT_EXISTS?i.logger.error("Account does not exist",{code:t.code,message:t.message,accountId:i.accountId}):i.logger.warn("Visitor creation warning",{code:t.code,message:t.message})}),!0)},t.prototype.logCreateVisitorErrors=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){t.code===Gs.ACCOUNT_ID_NOT_PASSED?i.logger.error("AccountId not passed",{code:t.code,message:t.message}):i.logger.error("Visitor creation error",{code:t.code,message:t.message})}),!0)},t.prototype.handleCreateVisitorError=function(t){var i;try{var n=(null===(i=t.response)||void 0===i?void 0:i.data)||t,e=this.logCreateVisitorWarnings(n.warnings),r=this.logCreateVisitorErrors(n.errors);e||r||this.logger.error("Visitor creation failed with an unrecognized error shape",{accountId:this.accountId,error:t})}catch(t){this.logger.error("Failed to parse visitor creation error",{parseError:t})}},t.prototype.updateVisitor=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(!this.initialized)throw new Error("AnonymousVisitorManager not initialized");if(!this.visitorId)throw new Error("No visitor ID exists. Create a visitor first.");o.label=1;case 1:return o.trys.push([1,3,,4]),n=t&&t.length>0?t:[],e=le({profiles:[{commChannels:n}]},i&&{extendedFields:i}),this.logger.debug("Visitor update request payload",{request:e}),[4,this.apiClient.updateVisitor(this.orgId,this.visitorId,e)];case 2:return r=o.sent(),[2,this.handleUpdateVisitorResponse(r)];case 3:throw s=o.sent(),this.handleUpdateVisitorError(s),s;case 4:return[2]}})})},t.prototype.handleUpdateVisitorResponse=function(t){var i,n=this;t.warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){n.logger.warn("Visitor update warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0&&t.errors.forEach(function(t){n.logger.error("Visitor update error from response",{code:t.code,message:t.message})});var e=null===(i=t.data)||void 0===i?void 0:i.id;if(!e||""===e.trim())throw this.logger.error("Invalid visitor ID received from update API",{response:t}),new Error("Invalid visitor ID received from update API");return e},t.prototype.logUpdateVisitorWarnings=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){t.code===Gs.ACCOUNT_NOT_EXISTS?i.logger.error("Account does not exist",{code:t.code,message:t.message,accountId:i.accountId}):i.logger.warn("Visitor update warning",{code:t.code,message:t.message})}),!0)},t.prototype.logUpdateVisitorErrors=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){i.logger.error("Visitor update error",{code:t.code,message:t.message})}),!0)},t.prototype.handleUpdateVisitorError=function(t){var i;try{var n=(null===(i=t.response)||void 0===i?void 0:i.data)||t,e=this.logUpdateVisitorWarnings(n.warnings),r=this.logUpdateVisitorErrors(n.errors);e||r||this.logger.error("Visitor update failed with an unrecognized error shape",{visitorId:this.visitorId,error:t})}catch(t){this.logger.error("Failed to parse visitor update error",{parseError:t})}},t.prototype.mergeVisitorWithUser=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:if(i=t.firstName,n=t.lastName,e=t.email,r=t.mobile,s=t.externalId,o=t.customData,u=t.cuid,a=t.identifierType,!this.initialized)return this.logger.warn(Xr,{reason:"Not initialized"}),[2,!1];if(!this.visitorId)return this.logger.warn(Xr,{reason:"No visitor ID"}),[2,!1];if(!e&&!r&&!s)return this.logger.warn(Xr,{reason:"No email, mobile, or externalId"}),[2,!1];c=this.visitorId,h=this.visitorExternalId,f.label=1;case 1:return f.trys.push([1,5,,6]),[4,this.isMerged()];case 2:return f.sent()?(this.logger.info(Xr,{reason:"Visitor already merged",visitorId:c}),[2,!0]):[4,this.persistPendingMerge(c,h,le(le(le(le(le(le({firstName:i,lastName:n},void 0!==e&&{email:e}),void 0!==r&&{mobile:r}),void 0!==s&&{externalId:s}),void 0!==o&&{customData:o}),void 0!==u&&{cuid:u}),void 0!==a&&{identifierType:a}))];case 3:return f.sent(),[4,this.attemptPendingMerge()];case 4:return f.sent(),[2,this.isMerged()];case 5:return d=f.sent(),this.logger.error("Merge background task failed unexpectedly",{error:d}),[2,!1];case 6:return[2]}})})},t.prototype.retryPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,7,,8]),[4,this.getPendingMerge()];case 1:return(t=n.sent())?[4,this.isMerged()]:[2];case 2:return n.sent()?[4,this.clearPendingMerge()]:[3,4];case 3:return n.sent(),this.logger.info(Xr,{reason:"Already merged"}),[2];case 4:return t.attempts>=Ms?(this.logger.error(Wr,{visitorId:t.visitorId,attempts:t.attempts,message:"Max retries exhausted"}),[4,this.clearPendingMerge()]):[3,6];case 5:return n.sent(),[2];case 6:return this.scheduleMergeRetry(),[3,8];case 7:return i=n.sent(),this.logger.error("Failed to retry pending merge",{error:i}),[3,8];case 8:return[2]}})})},t.prototype.cancelMergeRetryTimer=function(){null!==this.mergeRetryTimeoutId&&(globalThis.clearTimeout(this.mergeRetryTimeoutId),this.mergeRetryTimeoutId=null)},t.prototype.scheduleMergeRetry=function(){var t=this;this.cancelMergeRetryTimer(),this.mergeRetryTimeoutId=globalThis.setTimeout(function(){t.mergeRetryTimeoutId=null,t.attemptPendingMerge().catch(function(i){t.logger.error("Scheduled merge retry failed unexpectedly",{error:i})})},Us)},t.prototype.collectMergeContext=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:t=this.getFcmToken?this.getFcmToken():null,i=this.getChannelType?this.getChannelType():void 0,n=!this.getPermissionGranted||this.getPermissionGranted(),e=this.getSessionId?this.getSessionId():"",u.label=1;case 1:return u.trys.push([1,5,,6]),this.getExtendedFields?[4,this.getExtendedFields()]:[3,3];case 2:return s=u.sent(),[3,4];case 3:s=void 0,u.label=4;case 4:return r=s,[3,6];case 5:return o=u.sent(),this.logger.error("Failed to collect extended fields for merge, proceeding without them",{error:o}),r=void 0,[3,6];case 6:return[2,{fcmToken:t,channelType:i,subscribed:n,sessionId:e,extendedFields:r}]}})})},t.prototype.attemptPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:return[4,this.getPendingMerge()];case 1:return(t=a.sent())?[4,this.collectMergeContext()]:(this.logger.debug("attemptPendingMerge() found no pending merge to attempt"),[2]);case 2:i=a.sent(),n=i.fcmToken,e=i.channelType,r=i.subscribed,s=i.sessionId,o=i.extendedFields,a.label=3;case 3:return a.trys.push([3,7,,9]),[4,this.apiClient.mergeVisitor(t.visitorId,t.visitorExternalId||null,le(le(le(le(le(le(le(le(le(le({firstName:t.firstName,lastName:t.lastName},void 0!==t.email&&{email:t.email}),void 0!==t.mobile&&{mobile:t.mobile}),n?{fcmToken:n,subscribed:r}:{}),void 0!==e&&{channelType:e}),{fields:t.customData||{}}),void 0!==o&&{extendedFields:o}),void 0!==t.externalId&&{externalId:t.externalId}),void 0!==t.cuid&&{cuid:t.cuid}),void 0!==t.identifierType&&{identifierType:t.identifierType}),{sessionId:s}))];case 4:return a.sent(),[4,this.markAsMerged(t.visitorId)];case 5:return a.sent(),[4,this.clearPendingMerge()];case 6:return a.sent(),this.logger.info(Kr,{visitorId:t.visitorId,attempts:t.attempts+1}),[3,9];case 7:return u=a.sent(),[4,this.handleMergeRetryOrAbort(u,t)];case 8:return a.sent(),[3,9];case 9:return[2]}})})},t.prototype.handleMergeRetryOrAbort=function(t,i){return ve(this,void 0,void 0,function(){var n;return me(this,function(e){switch(e.label){case 0:return t instanceof ic?[4,this.clearPendingMerge()]:[3,2];case 1:return e.sent(),this.logger.error("Visitor merge failed permanently, will not retry",{code:t.code,message:t.message,visitorId:i.visitorId}),[2];case 2:return n=le(le({},i),{attempts:i.attempts+1}),[4,this.savePendingMerge(n)];case 3:return e.sent(),n.attempts>=Ms?(this.logger.error(Wr,{visitorId:i.visitorId,attempts:n.attempts,message:"Max retries exhausted"}),[4,this.clearPendingMerge()]):[3,5];case 4:return e.sent(),[2];case 5:return this.logger.warn("Visitor merge attempt failed, scheduling retry",{attempt:n.attempts,maxRetries:Ms,nextRetryMs:Us,visitorId:i.visitorId,error:t}),this.scheduleMergeRetry(),[2]}})})},t.prototype.persistPendingMerge=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:return e=n.firstName,r=n.lastName,s=n.email,o=n.mobile,u=n.externalId,a=n.customData,c=n.cuid,h=n.identifierType,d=le(le(le(le(le(le(le(le(le({visitorId:t},i&&{visitorExternalId:i}),{firstName:e,lastName:r}),void 0!==s&&{email:s}),void 0!==o&&{mobile:o}),void 0!==u&&{externalId:u}),void 0!==a&&{customData:a}),void 0!==c&&{cuid:c}),void 0!==h&&{identifierType:h}),{attempts:0}),[4,this.savePendingMerge(d)];case 1:return f.sent(),this.logger.debug("Pending merge request persisted to storage",{visitorId:t}),[2]}})})},t.prototype.getPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Ae("PENDING_MERGE",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=e.sent())?[2,JSON.parse(i)]:[2,null];case 2:return n=e.sent(),this.logger.error("Failed to read pending merge from storage",{error:n}),[2,null];case 3:return[2]}})})},t.prototype.savePendingMerge=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Ae("PENDING_MERGE",this.brandId,this.applicationId),[4,this.storageManager.set(i,JSON.stringify(t))];case 1:return e.sent(),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to save pending merge to storage",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.clearPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:this.cancelMergeRetryTimer(),n.label=1;case 1:return n.trys.push([1,3,,4]),t=Ae("PENDING_MERGE",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 2:return n.sent(),this.logger.debug("Pending merge cleared from storage"),[3,4];case 3:return i=n.sent(),this.logger.error("Failed to clear pending merge from storage",{error:i}),[3,4];case 4:return[2]}})})},t.prototype.isMerged=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Ae("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return[2,null!=n.sent()];case 2:return i=n.sent(),this.logger.error("Failed to check merge status",{error:i}),[2,!1];case 3:return[2]}})})},t.prototype.getMergedUserId=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Ae("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return[2,null!=(i=e.sent())?i:null];case 2:return n=e.sent(),this.logger.error("Failed to get merge status",{error:n}),[2,null];case 3:return[2]}})})},t.prototype.clearMergedUserId=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Ae("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 1:return n.sent(),this.logger.info("Merge status cleared from storage"),[3,3];case 2:return i=n.sent(),this.logger.error("Failed to clear merge status",{error:i}),[3,3];case 3:return[2]}})})},t.prototype.markAsMerged=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Ae("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 1:return e.sent(),this.logger.debug("Visitor marked as merged",{visitorId:t,key:i}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store merge status",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.getVisitorId=function(){return this.visitorId},t.prototype.getVisitorExternalId=function(){return this.visitorExternalId},t.prototype.hasVisitorId=function(){return null!==this.visitorId},t.prototype.storeVisitorId=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Ae("VISITOR_ID",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 1:return e.sent(),this.logger.debug("Visitor ID stored to storage",{visitorId:t,key:i}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store visitor ID",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.storeExpiredAt=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.expiredAt=t,i=Ae("VISITOR_EXPIRED_AT",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 1:return e.sent(),this.logger.debug("Visitor expiredAt stored to storage",{expiredAt:t}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store visitor expiredAt",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.isVisitorExpired=function(){if(!this.expiredAt)return!0;try{return new Date(this.expiredAt).getTime()<=Date.now()}catch(t){return this.logger.error("Invalid expiredAt format, treating as expired",{expiredAt:this.expiredAt}),!0}},t.prototype.getOrGenerateVisitorExternalId=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:if(this.visitorExternalId)return[2,this.visitorExternalId];t=ea(),this.visitorExternalId=t,e.label=1;case 1:return e.trys.push([1,3,,4]),i=Ae("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 2:return e.sent(),this.logger.debug("visitorExternalId generated and stored",{visitorExternalId:t}),[3,4];case 3:return n=e.sent(),this.logger.error("Failed to store visitorExternalId",{error:n}),[3,4];case 4:return[2,t]}})})},t.prototype.restoreVisitorId=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),t=Ae("VISITOR_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=u.sent())&&(this.visitorId=i,this.logger.info(zr,{visitorId:i})),n=Ae("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),[4,this.storageManager.get(n)];case 2:return(e=u.sent())&&(this.visitorExternalId=e),r=Ae("VISITOR_EXPIRED_AT",this.brandId,this.applicationId),[4,this.storageManager.get(r)];case 3:return(s=u.sent())&&(this.expiredAt=s),[3,5];case 4:return o=u.sent(),this.logger.error("Failed to restore visitor ID from storage",{accountId:this.accountId,error:o}),this.visitorId=null,[3,5];case 5:return[2]}})})},t.prototype.clearVisitorId=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),t=Ae("VISITOR_ID",this.brandId,this.applicationId),i=Ae("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),n=Ae("VISITOR_EXPIRED_AT",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 1:return r.sent(),[4,this.storageManager.remove(i)];case 2:return r.sent(),[4,this.storageManager.remove(n)];case 3:return r.sent(),this.visitorId=null,this.visitorExternalId=null,this.expiredAt=null,this.logger.info("Visitor ID cleared from storage"),[3,5];case 4:return e=r.sent(),this.logger.error("Failed to clear visitor ID",{error:e}),this.visitorId=null,this.visitorExternalId=null,this.expiredAt=null,[3,5];case 5:return[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.logger.info("Destroying AnonymousVisitorManager"),this.cancelMergeRetryTimer(),this.initialized=!1,this.logger.info("AnonymousVisitorManager destroyed successfully"),[2]})})},t}();function dc(){return"undefined"!=typeof window&&window.firebase?window.firebase:null}function fc(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){return(t=dc())?[2,t]:[2,import("firebase/app")]})})}function lc(){return ve(this,void 0,void 0,function(){return me(this,function(t){return[2,import("firebase/messaging")]})})}function vc(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){return(t=dc())&&t.remoteConfig?[2,t]:[2,import("firebase/remote-config")]})})}var mc=function(){function t(t,i,n,e,r,s){this.isInitialized=!1,this.currentToken=null,this.swRegistration=null,this.messaging=t,this.logger=i,this.vapidKey=n,this.serviceWorkerPath=e||ke,this.onTokenReceivedCallback=r,this.onMessageReceivedCallback=s}return t.prototype.initialize=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.isInitialized?(this.logger.warn(us),[2,!0]):this.messaging?(this.isInitialized=!0,this.logger.info(Zr),[2,!0]):(this.logger.error(ts,new Error("Messaging instance missing")),[2,!1])})})},t.prototype.ensureServiceWorkerRegistered=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return this.swRegistration?[2,this.swRegistration]:this.isInitialized&&this.messaging?(t=this,[4,this.registerServiceWorker()]):(this.logger.warn("ensureServiceWorkerRegistered() called before Firebase is initialized",{isInitialized:this.isInitialized,hasMessaging:!!this.messaging}),[2,null]);case 1:return t.swRegistration=i.sent(),[2,this.swRegistration]}})})},t.prototype.registerServiceWorker=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:if(!("serviceWorker"in navigator))return this.logger.warn(os),[2,null];e.label=1;case 1:return e.trys.push([1,7,,8]),[4,navigator.serviceWorker.getRegistration(this.serviceWorkerPath)];case 2:return(t=e.sent())?(this.logger.info("Service worker already registered",{scope:t.scope}),[4,this.ensureServiceWorkerActive(t)]):[3,4];case 3:return e.sent(),[2,t];case 4:return this.logger.info("Registering service worker",{path:this.serviceWorkerPath}),[4,navigator.serviceWorker.register(this.serviceWorkerPath)];case 5:return i=e.sent(),this.logger.info(rs,{scope:i.scope}),[4,this.ensureServiceWorkerActive(i)];case 6:return e.sent(),[2,i];case 7:return n=e.sent(),this.logger.error(ss,n),[2,null];case 8:return[2]}})})},t.prototype.ensureServiceWorkerActive=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){return t.active?(this.logger.debug("Service worker is already active"),[2]):(i=t.installing||t.waiting)?(this.logger.info("Waiting for service worker to activate...",{state:i.state}),[2,new Promise(function(t,e){if("activated"!==i.state){var r=function(){"activated"===i.state?(i.removeEventListener("statechange",r),n.logger.info("Service worker activated"),t()):"redundant"===i.state&&(i.removeEventListener("statechange",r),e(new Error("Service worker became redundant")))};i.addEventListener("statechange",r)}else t()})]):(this.logger.warn(cs),[2])})})},t.prototype.requestToken=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(as),[2,null];r.label=1;case 1:return r.trys.push([1,5,,6]),(i=this.swRegistration)?[3,3]:[4,this.registerServiceWorker()];case 2:i=r.sent(),r.label=3;case 3:return(t=i)?(this.swRegistration=t,[4,this.fetchFCMToken(t)]):(this.logger.error(hs),[2,null]);case 4:return(n=r.sent())?(this.currentToken=n,this.logger.info(is,{token:n}),this.onTokenReceivedCallback&&this.onTokenReceivedCallback(n),[2,n]):(this.logger.error(ds),[2,null]);case 5:return e=r.sent(),this.logger.error(es,{error:e}),[2,null];case 6:return[2]}})})},t.prototype.fetchFCMToken=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return[4,lc()];case 1:return i=e.sent().getToken,n={serviceWorkerRegistration:t},this.vapidKey&&(n.vapidKey=this.vapidKey),[2,i(this.messaging,n)]}})})},t.prototype.setupMessageListener=function(){return ve(this,void 0,void 0,function(){var t,i=this;return me(this,function(n){switch(n.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(as),[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,lc()];case 2:return(0,n.sent().onMessage)(this.messaging,function(t){i.handleMessage(t)}),this.logger.info("Message listener setup successfully"),[3,4];case 3:return t=n.sent(),this.logger.error(fs,{error:t}),[3,4];case 4:return[2]}})})},t.prototype.handleMessage=function(t){if(this.logger.info("FCM message received",t),t&&(t.notification||t.data)||this.logger.warn(ls,t),this.onMessageReceivedCallback)try{this.onMessageReceivedCallback(t)}catch(t){this.logger.error(vs,{error:t})}},t.prototype.getCurrentToken=function(){return this.currentToken},t.prototype.isFirebaseInitialized=function(){return this.isInitialized},t.prototype.destroy=function(){this.isInitialized=!1,this.messaging=null,this.currentToken=null,this.swRegistration=null,this.logger.info("FirebaseManager destroyed successfully")},t}(),gc=function(){function t(t,i,n,e,r){this.firebaseManager=null,this.tokenUpdateCallback=null,this.config=t,this.logger=i,this.storageManager=n,this.brandId=e,this.applicationId=r,this.config.onTokenRefresh&&this.logger.warn("notifications.onTokenRefresh has no effect — the modular Firebase SDK has no token-refresh event to fire it from. Call NotificationManager.refreshToken() to manually re-request a token instead."),this.state={isNotificationEnabled:!1,firebaseInitialized:!1,permissionStatus:"default"}}return t.prototype.isNotificationSupported=function(){return"undefined"!=typeof window&&"undefined"!=typeof Notification&&"undefined"!=typeof navigator&&"serviceWorker"in navigator},t.prototype.getPermissionStatus=function(){return this.isNotificationSupported()?Notification.permission:"denied"},t.prototype.shouldInitializeNotifications=function(){return this.isNotificationSupported()?!!this.config.messaging||(this.logger.info(gs),!1):(this.logger.info(ms),!1)},t.prototype.restoreState=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r;return me(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=Ae("NOTIFICATION_STATE",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=s.sent())&&(n=JSON.parse(i),e=this.getPermissionStatus(),this.state=le(le(le({},this.state),n),{permissionStatus:e}),this.logger.info("Notification state restored from storage",{storedPermission:n.permissionStatus,currentPermission:e,hasToken:!!n.fcmToken})),[3,3];case 2:return r=s.sent(),this.logger.error(ps,{error:r}),[3,3];case 3:return[2]}})})},t.prototype.saveState=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Ae("NOTIFICATION_STATE",this.brandId,this.applicationId),[4,this.storageManager.set(t,JSON.stringify(this.state))];case 1:return n.sent(),this.logger.debug("Notification state saved to storage",this.state),[3,3];case 2:return i=n.sent(),this.logger.error(ws,{error:i}),[3,3];case 3:return[2]}})})},t.prototype.init=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,15,,17]),[4,this.restoreState()];case 1:return n.sent(),this.shouldInitializeNotifications()?[3,3]:(this.logger.info($r),this.state.isNotificationEnabled=!1,[4,this.saveState()]);case 2:return n.sent(),[2,this.state];case 3:return t=this.getPermissionStatus(),this.state.permissionStatus=t,this.logger.info("Current notification permission",{permission:t,hasStoredToken:!!this.state.fcmToken,isNotificationEnabled:this.state.isNotificationEnabled}),"denied"!==t?[3,5]:(this.logger.info(Yr),this.state.isNotificationEnabled=!1,this.state.fcmToken&&(this.logger.info("Clearing stored FCM token because notification permission is denied"),delete this.state.fcmToken),[4,this.saveState()]);case 4:return n.sent(),[2,this.state];case 5:return"default"!==t?[3,7]:(this.logger.info("Permission not yet granted - notifications will not be shown until user grants permission"),this.state.isNotificationEnabled=!1,[4,this.saveState()]);case 6:return n.sent(),[2,this.state];case 7:return"granted"!==t?[3,14]:this.state.fcmToken?(this.logger.info("Using existing FCM token from storage",{token:this.state.fcmToken.substring(0,20)+"..."}),this.state.isNotificationEnabled=!0,this.firebaseManager?[3,9]:(this.logger.info("Initializing Firebase for message listening"),[4,this.initializeFirebaseForMessaging()])):[3,11];case 8:n.sent(),n.label=9;case 9:return[4,this.saveState()];case 10:return n.sent(),[2,this.state];case 11:return this.logger.info("Permission granted - initializing Firebase to generate FCM token"),[4,this.initializeFirebase()];case 12:return n.sent(),[4,this.saveState()];case 13:n.sent(),n.label=14;case 14:return this.logger.info(Qr,this.state),[2,this.state];case 15:return i=n.sent(),this.logger.error(Jr,i),this.state.isNotificationEnabled=!1,[4,this.saveState()];case 16:return n.sent(),[2,this.state];case 17:return[2]}})})},t.prototype.initializeFirebaseForMessaging=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:if(!this.config.messaging)throw new Error("Firebase Messaging instance is required");i.label=1;case 1:return i.trys.push([1,5,,6]),this.firebaseManager=new mc(this.config.messaging,this.logger,this.config.vapidKey,this.config.serviceWorkerPath,this.config.onTokenReceived,this.config.onMessageReceived),[4,this.firebaseManager.initialize()];case 2:if(!i.sent())throw new Error("Firebase initialization failed");return this.state.firebaseInitialized=!0,[4,this.firebaseManager.ensureServiceWorkerRegistered()];case 3:return i.sent(),[4,this.firebaseManager.setupMessageListener()];case 4:return i.sent(),this.logger.info("Firebase initialized for message listening"),[3,6];case 5:throw t=i.sent(),this.logger.error(ys,t),t;case 6:return[2]}})})},t.prototype.initializeFirebase=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:if(!this.config.messaging)throw new Error("Firebase Messaging instance is required");n.label=1;case 1:return n.trys.push([1,7,,8]),this.firebaseManager=new mc(this.config.messaging,this.logger,this.config.vapidKey,this.config.serviceWorkerPath,this.config.onTokenReceived,this.config.onMessageReceived),[4,this.firebaseManager.initialize()];case 2:if(!n.sent())throw new Error("Firebase initialization failed");return this.state.firebaseInitialized=!0,this.state.isNotificationEnabled=!0,[4,this.firebaseManager.requestToken()];case 3:return(t=n.sent())?(this.state.fcmToken=t,[4,this.storeFCMToken(t)]):[3,5];case 4:n.sent(),n.label=5;case 5:return[4,this.firebaseManager.setupMessageListener()];case 6:return n.sent(),this.logger.info("Firebase initialized and FCM token retrieved",{hasToken:!!t}),[3,8];case 7:throw i=n.sent(),this.logger.error(ts,i),this.state.firebaseInitialized=!1,this.state.isNotificationEnabled=!1,i;case 8:return[2]}})})},t.prototype.storeFCMToken=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,6,,7]),i=Ae("FCM_TOKEN",this.brandId,this.applicationId),n=Ae("FCM_TOKEN_CREATED_AT",this.brandId,this.applicationId),[4,this.storageManager.get(i)];case 1:return e=u.sent(),r=!e||e!==t,[4,this.storageManager.set(i,t)];case 2:return u.sent(),r?(s=(new Date).toISOString(),[4,this.storageManager.set(n,s)]):[3,4];case 3:return u.sent(),this.logger.debug("FCM token and creation date stored successfully",{createdAt:s}),[3,5];case 4:this.logger.debug("FCM token stored (creation date unchanged)"),u.label=5;case 5:return this.tokenUpdateCallback&&(this.logger.info("Notifying token update callback",{isNewToken:r,tokenPreview:t.substring(0,20)+"..."}),this.tokenUpdateCallback(t,r)),[3,7];case 6:return o=u.sent(),this.logger.error(Es,{error:o}),[3,7];case 7:return[2]}})})},t.prototype.setTokenUpdateCallback=function(t){this.tokenUpdateCallback=t,this.logger.debug("Token update callback registered")},t.prototype.clearTokenUpdateCallback=function(){this.tokenUpdateCallback=null,this.logger.debug("Token update callback cleared")},t.prototype.getState=function(){return le({},this.state)},t.prototype.getFCMToken=function(){return this.state.fcmToken||null},t.prototype.getTokenCreationDate=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Ae("FCM_TOKEN_CREATED_AT",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return[2,n.sent()||null];case 2:return i=n.sent(),this.logger.error(_s,i),[2,null];case 3:return[2]}})})},t.prototype.isEnabled=function(){return this.state.isNotificationEnabled},t.prototype.getFirebaseManager=function(){return this.firebaseManager},t.prototype.refreshToken=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:if(!this.firebaseManager||!this.state.isNotificationEnabled)return this.logger.info(Is),[2,null];n.label=1;case 1:return n.trys.push([1,6,,7]),[4,this.firebaseManager.requestToken()];case 2:return(t=n.sent())?(this.state.fcmToken=t,[4,this.storeFCMToken(t)]):[3,5];case 3:return n.sent(),[4,this.saveState()];case 4:n.sent(),this.logger.info(ns,{token:t}),n.label=5;case 5:return[2,t];case 6:return i=n.sent(),this.logger.error(bs,i),[2,null];case 7:return[2]}})})},t.prototype.clearToken=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.logger.info("Clearing notification state (permission revoked)"),t=this.state.fcmToken,this.state.isNotificationEnabled=!1,this.state.firebaseInitialized=!1,this.firebaseManager&&(this.firebaseManager.destroy(),this.firebaseManager=null),[4,this.saveState()];case 1:return n.sent(),this.tokenUpdateCallback&&t&&(this.logger.info("Notifying permission revoked to sync push_opted:false with backend"),this.tokenUpdateCallback(t,!0)),this.logger.info("Notification state cleared"),[3,3];case 2:throw i=n.sent(),this.logger.error(Ts,i),i;case 3:return[2]}})})},t.prototype.hasPermissionChanged=function(){return this.getPermissionStatus()!==this.state.permissionStatus},t.prototype.handlePermissionChange=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return t=this.getPermissionStatus(),i=this.state.permissionStatus,this.logger.info("Permission status changed",{from:i,to:t}),this.state.permissionStatus=t,"denied"!==t&&"default"!==t?[3,5]:"granted"!==i?[3,2]:(this.logger.warn(Ss),[4,this.clearToken()]);case 1:return n.sent(),[3,4];case 2:return this.state.isNotificationEnabled=!1,[4,this.saveState()];case 3:n.sent(),n.label=4;case 4:return[3,10];case 5:return"granted"!==t||"granted"===i?[3,10]:this.config.messaging?[3,6]:(this.logger.warn(gs),this.state.isNotificationEnabled=!1,[3,8]);case 6:return this.logger.info("Permission granted - initializing Firebase"),[4,this.initializeFirebase()];case 7:n.sent(),n.label=8;case 8:return[4,this.saveState()];case 9:n.sent(),n.label=10;case 10:return[2,this.state]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.firebaseManager&&(this.firebaseManager.destroy(),this.firebaseManager=null),t=Ae("NOTIFICATION_STATE",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 1:return n.sent(),this.logger.info("NotificationManager destroyed successfully"),[3,3];case 2:return i=n.sent(),this.logger.error(Ns,i),[3,3];case 3:return[2]}})})},t}(),pc=function(){function t(t,i,n,e,r){this.currentSession=null,this.sessionNumber=0,this.storageManager=t,this.logger=i,this.brandId=n,this.applicationId=e;var s=Ne/6e4;this.inactivityTimeoutMs=60*(r||s)*1e3,this.logger.info("SessionManager configured with timeout:",{timeoutMinutes:r||s,timeoutMs:this.inactivityTimeoutMs,source:r?"Remote Config":"Default"})}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Initializing SessionManager"),[4,this.restoreSessionNumber()];case 1:return t.sent(),[4,this.restoreSession()];case 2:return t.sent(),this.logger.info("SessionManager initialized successfully"),[2]}})})},t.prototype.getOrCreateSession=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return t=Date.now(),this.currentSession?(i=t-this.currentSession.lastEventTime)<this.inactivityTimeoutMs?(this.currentSession.lastEventTime=t,[4,this.persistSession()]):[3,2]:[3,3];case 1:return n.sent(),this.logger.debug(br,{sessionId:this.currentSession.sessionId,inactivityDuration:i}),[2,this.currentSession.sessionId];case 2:this.logger.info(Tr,{sessionId:this.currentSession.sessionId,inactivityDuration:i,timeoutMs:this.inactivityTimeoutMs}),n.label=3;case 3:return[2,this.startNewSession()]}})})},t.prototype.getSessionStartTime=function(){var t;return(null===(t=this.currentSession)||void 0===t?void 0:t.sessionStartTime)||null},t.prototype.getCurrentSessionId=function(){var t,i;return null!==(i=null===(t=this.currentSession)||void 0===t?void 0:t.sessionId)&&void 0!==i?i:null},t.prototype.getSessionNumber=function(){return this.sessionNumber},t.prototype.resetSessionNumber=function(){return ve(this,arguments,void 0,function(t){return void 0===t&&(t=0),me(this,function(i){switch(i.label){case 0:return this.sessionNumber=t,[4,this.persistSessionNumber()];case 1:return i.sent(),this.logger.info("Session number reset",{sessionNumber:this.sessionNumber}),[2]}})})},t.prototype.endSession=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return this.currentSession?(this.logger.info("user_switch"===t?Sr:Nr,{sessionId:this.currentSession.sessionId,reason:t}),this.currentSession=null,[4,this.clearSessionStorage()]):[3,3];case 1:return i.sent(),[4,this.resetSessionNumber(0)];case 2:i.sent(),i.label=3;case 3:return[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.logger.info("Destroying SessionManager (session persists in storage)"),this.currentSession=null,[2]})})},t.prototype.startNewSession=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return t=Date.now(),i=ea(),this.currentSession={sessionId:i,sessionStartTime:t,lastEventTime:t},this.sessionNumber+=1,[4,this.persistSession()];case 1:return n.sent(),[4,this.persistSessionNumber()];case 2:return n.sent(),this.logger.info(Ir,{sessionId:i,sessionStartTime:t,sessionNumber:this.sessionNumber}),[2,i]}})})},t.prototype.restoreSession=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a;return me(this,function(c){switch(c.label){case 0:return c.trys.push([0,7,,9]),t=Ae("SESSION_ID",this.brandId,this.applicationId),i=Ae("SESSION_START_TIME",this.brandId,this.applicationId),n=Ae("LAST_EVENT_TIME",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return e=c.sent(),[4,this.storageManager.get(i)];case 2:return r=c.sent(),[4,this.storageManager.get(n)];case 3:return s=c.sent(),e&&r&&s?(o=Date.now(),(u=o-parseInt(s))<this.inactivityTimeoutMs?(this.currentSession={sessionId:e,sessionStartTime:parseInt(r),lastEventTime:parseInt(s)},this.logger.info(Dr,{sessionId:e,timeSinceLastEvent:u}),[3,6]):[3,4]):[3,6];case 4:return this.logger.debug("Stored session expired, will create new session",{timeSinceLastEvent:u,timeoutMs:this.inactivityTimeoutMs}),[4,this.clearSessionStorage()];case 5:c.sent(),c.label=6;case 6:return[3,9];case 7:return a=c.sent(),this.logger.error("Failed to restore session from storage",{error:a}),[4,this.clearSessionStorage()];case 8:return c.sent(),[3,9];case 9:return[2]}})})},t.prototype.persistSession=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:if(!this.currentSession)return[2];r.label=1;case 1:return r.trys.push([1,3,,4]),t=Ae("SESSION_ID",this.brandId,this.applicationId),i=Ae("SESSION_START_TIME",this.brandId,this.applicationId),n=Ae("LAST_EVENT_TIME",this.brandId,this.applicationId),[4,Promise.all([this.storageManager.set(t,this.currentSession.sessionId),this.storageManager.set(i,this.currentSession.sessionStartTime.toString()),this.storageManager.set(n,this.currentSession.lastEventTime.toString())])];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.logger.error("Failed to persist session to storage",{error:e}),[3,4];case 4:return[2]}})})},t.prototype.clearSessionStorage=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),t=Ae("SESSION_ID",this.brandId,this.applicationId),i=Ae("SESSION_START_TIME",this.brandId,this.applicationId),n=Ae("LAST_EVENT_TIME",this.brandId,this.applicationId),[4,Promise.all([this.storageManager.remove(t),this.storageManager.remove(i),this.storageManager.remove(n)])];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error("Failed to clear session storage",{error:e}),[3,3];case 3:return[2]}})})},t.prototype.restoreSessionNumber=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Ae("SESSION_NUMBER",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=e.sent())&&(this.sessionNumber=parseInt(i,10)||0,this.logger.debug("Session number restored",{sessionNumber:this.sessionNumber})),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to restore session number",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.persistSessionNumber=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Ae("SESSION_NUMBER",this.brandId,this.applicationId),[4,this.storageManager.set(t,this.sessionNumber.toString())];case 1:return n.sent(),[3,3];case 2:return i=n.sent(),this.logger.error("Failed to persist session number",{error:i}),[3,3];case 3:return[2]}})})},t}(),wc=function(){function t(t,i){this.firedThresholds=new Set,this.pageStartTime=0,this.currentUrl="",this.scrollHandler=null,this.initialized=!1,this.logger=t,this.onDepthReached=i,this.thresholds=Ps}return t.prototype.init=function(){var t=this;"undefined"!=typeof window&&"undefined"!=typeof document?this.initialized?this.logger.debug("ScrollDepthTracker already initialized, skipping"):(this.pageStartTime=Date.now(),this.currentUrl=window.location.href,this.scrollHandler=function(){return t.handleScroll()},window.addEventListener("scroll",this.scrollHandler,{passive:!0}),this.checkScrollDepth(),this.initialized=!0,this.logger.debug("ScrollDepthTracker initialized")):this.logger.debug("ScrollDepthTracker.init() skipped - no window/document (SSR)")},t.prototype.handleScroll=function(){this.checkSPANavigation(),this.checkScrollDepth()},t.prototype.checkSPANavigation=function(){var t=window.location.href;t!==this.currentUrl&&(this.firedThresholds.clear(),this.pageStartTime=Date.now(),this.currentUrl=t,this.logger.debug("ScrollDepthTracker reset for new page",{url:t}))},t.prototype.checkScrollDepth=function(){var t,i,n=window.scrollY,e=document.documentElement.scrollHeight-document.documentElement.clientHeight;if(!(e<=0)){var r=Math.min(100,Math.floor(n/e*100));try{for(var s=ge(this.thresholds),o=s.next();!o.done;o=s.next()){var u=o.value;if(!this.firedThresholds.has(u)&&r>=u){this.firedThresholds.add(u);var a=Math.floor((Date.now()-this.pageStartTime)/1e3);this.logger.debug("Scroll depth threshold reached",{threshold:u,timeToDepth:a,url:this.currentUrl}),this.onDepthReached({depth_percentage:u,page_url:this.currentUrl,time_to_depth:a})}}}catch(i){t={error:i}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}}},t.prototype.destroy=function(){this.scrollHandler&&"undefined"!=typeof window&&window.removeEventListener("scroll",this.scrollHandler),this.scrollHandler=null,this.firedThresholds.clear(),this.initialized=!1,this.logger.debug("ScrollDepthTracker destroyed")},t}(),yc=function(){function t(t){this.userContextSet=!1,this.initialized=!1,this.initializationPromise=null,this.visitorTrackingEnabled=!1,this.visitorId=null,this.currentUserIdentifierType=null,this.notificationManager=null,this.permissionChangeCleanup=null,this.dlrMessageCleanup=null,this.lastAuthenticatedUser=null,this.lastUserAttributes=null,this.scrollDepthTracker=null,this.sdkDisabled=!1,this.userIdentified=!1,this.userOperationChain=Promise.resolve(),this.gamificationManager=null,this.gamificationBaseUrl=Vo,this.pendingGamificationCallback=null,this.pendingGamificationSettings={},this.config=t,this.logger=new ac(!1),this.validateRequiredConfig(t),t.remoteConfigKey?(this.logger.info("🔧 SDK initializing in Remote Config bootstrap mode"),this.logger.info("Will fetch configuration from Remote Config key:",t.remoteConfigKey)):this.logger.info("🔧 SDK initializing in direct-config bootstrap mode (no Firebase)")}return t.initialize=function(i){return t.p?(new ac(!0).warn("WebSDK is already initialized. Returning existing instance."),t.p):(t.p=new t(i),t.p.init(),t.p)},t.getInstance=function(){return t.p},t.isInitialized=function(){return null!==t.p},t.requireInstance=function(){if(!t.p)throw new Error("WebSDK is not initialized. Call WebSDK.initialize(config) first.");return t.p},t.track=function(i,n){t.requireInstance().track(i,n)},t.pageView=function(i){t.requireInstance().pageView(i)},t.identify=function(i){t.requireInstance().identify(i)},t.getUser=function(){return t.requireInstance().getUser()},t.getAnonymousId=function(){return t.requireInstance().getAnonymousId()},t.reset=function(){t.requireInstance().reset()},t.setCapToken=function(i){t.requireInstance().setCapToken(i)},t.getCapToken=function(){return t.requireInstance().getCapToken()},t.enablePagePathTracking=function(i){t.requireInstance().enablePagePathTracking(i)},t.onScreenChanged=function(i){t.requireInstance().onScreenChanged(i)},t.setGamificationSuppressed=function(i){t.requireInstance().setGamificationSuppressed(i)},t.setTheme=function(i){t.requireInstance().setTheme(i)},t.forceSyncGamification=function(){t.requireInstance().forceSyncGamification()},t.setGamificationCallback=function(i){t.requireInstance().setGamificationCallback(i)},t.isGamificationSuppressed=function(){return t.requireInstance().isGamificationSuppressed()},t.disableSDK=function(){t.requireInstance().disableSDK()},t.enableSDK=function(){t.requireInstance().enableSDK()},t.destroy=function(){if(!t.p)return Promise.resolve();var i=t.p.destroy();return t.p=null,i},t.prototype.shouldEnableLogging=function(t){return!(!t||"NONE"===t)&&["ERROR","WARN","INFO","DEBUG","VERBOSE"].includes(t)},t.prototype.resolveLogLevel=function(t){return{NONE:nc.NONE,ERROR:nc.ERROR,WARN:nc.WARN,INFO:nc.INFO,DEBUG:nc.DEBUG,VERBOSE:nc.VERBOSE}[null!=t?t:"NONE"]},t.prototype.restoreUserContext=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a=this;return me(this,function(c){switch(c.label){case 0:return c.trys.push([0,5,,6]),t=Ae("USER_CONTEXT",this.config.brandId,this.config.applicationId),[4,this.storageManager.get(t)];case 1:return(i=c.sent())?(n=JSON.parse(i),e=n.cuid,r=n.userIdentifierType,this.currentUserIdentifierType=null!=r?r:null,s=this.config.accountId||"",[4,this.eventTracker.setUserContext(s,e,r)]):[3,3];case 2:c.sent(),this.userContextSet=!0,this.userIdentified=!0,this.logger.setContext({cuid:e}),n.attributes&&(this.lastUserAttributes=n.attributes),this.logger.info("User context restored from storage",{cuid:e,accountId:this.config.accountId}),this.gamificationManager&&this.gamificationManager.initialize(e).catch(function(t){a.logger.error("Failed to restore gamification on page refresh",t)}),c.label=3;case 3:return[4,this.storageManager.get(this.lastAuthenticatedUserKey())];case 4:return(o=c.sent())&&(this.lastAuthenticatedUser=o,this.logger.info("Last authenticated user restored from storage",{lastAuthenticatedUser:this.lastAuthenticatedUser})),[3,6];case 5:return u=c.sent(),this.logger.error("Failed to restore user context from storage",{error:u}),[3,6];case 6:return[2]}})})},t.prototype.validateAndClearDifferentUserContext=function(t){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,5,,7]),this.lastAuthenticatedUser&&this.lastAuthenticatedUser!==t?(this.logger.info("Different user detected, ending session and clearing context",{previousCuid:this.lastAuthenticatedUser,newCuid:t}),[4,this.sessionManager.endSession("user_switch")]):[3,3];case 1:return n.sent(),[4,this.clearUserContext({resetIdentified:!1})];case 2:n.sent(),this.userContextSet=!1,n.label=3;case 3:return this.lastAuthenticatedUser=t,[4,this.persistLastAuthenticatedUser(t)];case 4:return n.sent(),[3,7];case 5:return i=n.sent(),this.logger.error("Error validating different user context",{previousCuid:this.lastAuthenticatedUser,newCuid:t,error:i}),[4,this.clearUserContext()];case 6:return n.sent(),this.userContextSet=!1,[3,7];case 7:return[2]}})})},t.prototype.lastAuthenticatedUserKey=function(){return Ae("LAST_AUTHENTICATED_USER",this.config.brandId,this.config.applicationId)},t.prototype.persistLastAuthenticatedUser=function(t){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.storageManager.set(this.lastAuthenticatedUserKey(),t)];case 1:return n.sent(),[3,3];case 2:return i=n.sent(),this.logger.error("Failed to persist lastAuthenticatedUser",{error:i}),[3,3];case 3:return[2]}})})},t.prototype.storeUserContext=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),e=null!=i?i:this.currentUserIdentifierType,r={cuid:t,timestamp:Date.now()},e&&(r.userIdentifierType=e),n&&(r.attributes=n),s=Ae("USER_CONTEXT",this.config.brandId,this.config.applicationId),[4,this.storageManager.set(s,JSON.stringify(r))];case 1:return u.sent(),[3,3];case 2:return o=u.sent(),this.logger.error("Failed to store user context",{error:o}),[3,3];case 3:return[2]}})})},t.prototype.init=function(){var t=this;this.initialized?this.logger.warn("WebSDK already initialized"):this.initializationPromise?this.logger.warn("WebSDK initialization already in progress"):(va(),this.initializationPromise=this.initializeAsync().catch(function(i){t.logger.error(Ve,i),t.initializationPromise=null}))},t.prototype.tryStep=function(t,i){return ve(this,void 0,void 0,function(){var n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,i()];case 1:return e.sent(),[3,3];case 2:return n=e.sent(),this.logger.error(t,n),[3,3];case 3:return[2]}})})},t.prototype.initializeAsync=function(){return ve(this,void 0,void 0,function(){var t,i,n=this;return me(this,function(e){switch(e.label){case 0:this.logger.info("Initializing WebSDK",{version:Hs,config:this.config}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.bootstrapConfig()];case 2:return e.sent(),[3,4];case 3:throw t=e.sent(),new Error("".concat(Pe,": ").concat(t));case 4:return[4,this.tryStep(je,function(){return n.storageManager.init()})];case 5:return e.sent(),[4,this.tryStep(He,function(){var t;return Promise.resolve(null===(t=n.gamificationManager)||void 0===t?void 0:t.restorePersistedPagePathTracking())})];case 6:return e.sent(),[4,this.tryStep(qe,function(){var t;return Promise.resolve(null===(t=n.gamificationManager)||void 0===t?void 0:t.restorePersistedGamificationSuppressed())})];case 7:return e.sent(),[4,this.tryStep(Ke,function(){var t;return Promise.resolve(null===(t=n.gamificationManager)||void 0===t?void 0:t.restorePersistedTheme())})];case 8:return e.sent(),[4,this.tryStep(We,function(){return n.sessionManager.init()})];case 9:if(e.sent(),!this.config.notifications)return[3,13];e.label=10;case 10:return e.trys.push([10,12,,13]),this.notificationManager=new gc(this.config.notifications,this.logger,this.storageManager,this.config.brandId,this.config.applicationId),this.setupTokenUpdateCallback(),[4,this.notificationManager.init()];case 11:return e.sent(),this.logger.info("Notifications initialized early for FCM token availability"),[3,13];case 12:return i=e.sent(),this.logger.error("Failed to construct or configure NotificationManager",{error:i}),this.notificationManager=null,[3,13];case 13:return[4,this.tryStep(Xe,function(){return n.initializeVisitorConfig()})];case 14:return e.sent(),[4,this.tryStep(Ye,function(){return ve(n,void 0,void 0,function(){var t=this;return me(this,function(i){switch(i.label){case 0:return[4,this.eventTracker.init()];case 1:return i.sent(),this.eventTracker.setSessionInfoCallback(function(){return ve(t,void 0,void 0,function(){return me(this,function(t){return[2,this.sessionManager.getOrCreateSession()]})})}),[2]}})})})];case 15:return e.sent(),[4,this.tryStep(Qe,function(){return n.restoreUserContext()})];case 16:return e.sent(),[4,this.tryStep(Je,function(){return n.syncEventTrackerContext()})];case 17:return e.sent(),this.initialized=!0,this.notificationManager&&this.setupPermissionChangeDetection(),this.scrollDepthTracker=new wc(this.logger,function(t){n.pushEvent(xs,n.buildInternalEventAttributes(le({},t)))}),this.scrollDepthTracker.init(),this.config.notifications?[4,this.tryStep($e,function(){return ve(n,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.setupDLRServiceWorkerListener(),[4,this.eventTracker.processPendingServiceWorkerDLREvents()];case 1:return t.sent(),[2]}})})})]:[3,19];case 18:e.sent(),e.label=19;case 19:return this.logger.info(Ge),[2]}})})},t.prototype.handleVisibilityChange=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:if("visible"!==document.visibilityState||!this.notificationManager)return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),this.notificationManager.hasPermissionChanged()?(t="Notification"in window?Notification.permission:"denied",this.logger.info("Notification permission changed detected",{currentPermission:t}),[4,this.notificationManager.handlePermissionChange()]):[2];case 2:return(i=e.sent())&&this.logger.info("Notification state updated after permission change",i),[3,4];case 3:return n=e.sent(),this.logger.error("Error handling permission change",{error:n}),[3,4];case 4:return[2]}})})},t.prototype.setupPermissionChangeDetection=function(){var t=this;if("undefined"!=typeof document&&"undefined"!=typeof window){var i=function(){return t.handleVisibilityChange()};document.addEventListener("visibilitychange",i),window.addEventListener("focus",i),this.permissionChangeCleanup=function(){document.removeEventListener("visibilitychange",i),window.removeEventListener("focus",i)},this.logger.debug("Permission change detection setup complete")}},t.prototype.setupDLRServiceWorkerListener=function(){var t=this;if("undefined"!=typeof navigator&&"serviceWorker"in navigator){var i=function(i){return ve(t,void 0,void 0,function(){var t;return me(this,function(n){switch(n.label){case 0:if(!i.data||"HYDRA_DLR_EVENTS_PENDING"!==i.data.type)return[3,4];this.logger.info("Received DLR events pending notification from service worker",{serviceWorkerTimestamp:i.data.timestamp,dlrEventType:i.data.dlrEventType,messageId:i.data.messageId,campaignId:i.data.campaignId}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.eventTracker.processPendingServiceWorkerDLREvents()];case 2:return n.sent(),[3,4];case 3:return t=n.sent(),this.logger.error("Failed to process pending DLR events",t),[3,4];case 4:return[2]}})})};navigator.serviceWorker.addEventListener("message",i),this.dlrMessageCleanup=function(){navigator.serviceWorker.removeEventListener("message",i)},this.logger.debug("DLR service worker message listener setup complete")}},t.prototype.initializeVisitorConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n=this;return me(this,function(e){switch(e.label){case 0:return this.logger.info("Initializing visitor configuration"),[4,this.visitorConfigManager.init()];case 1:return e.sent(),t=this,[4,this.visitorConfigManager.isVisitorTrackingEnabled()];case 2:return t.visitorTrackingEnabled=e.sent(),this.visitorTrackingEnabled?[4,this.anonymousVisitorManager.init()]:[3,5];case 3:return e.sent(),[4,this.getOrCreateVisitorId()];case 4:e.sent(),this.anonymousVisitorManager.retryPendingMerge().catch(function(t){n.logger.error("Failed to retry pending merge on init",{error:t})}),e.label=5;case 5:return(i=this.visitorConfigManager.getCachedConfig())&&i.warnings&&i.warnings.length>0&&i.warnings.forEach(function(t){n.logger.warn("Visitor config warning",{code:t.code,message:t.message})}),[2]}})})},t.prototype.syncEventTrackerContext=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return t=null!==(e=null===(n=this.anonymousVisitorManager)||void 0===n?void 0:n.getVisitorExternalId())&&void 0!==e?e:null,this.eventTracker.setVisitorTrackingState(this.visitorId,this.visitorTrackingEnabled,t),this.visitorTrackingEnabled?(i=this.config.accountId||"",this.userContextSet?[3,2]:[4,this.eventTracker.setUserContext(i)]):(this.logger.warn("Event tracking disabled: Visitor tracking is off"),[2]);case 1:return r.sent(),this.logger.info("Account context set for visitor tracking"),[3,3];case 2:this.logger.debug("Skipping account context set - user context already set"),r.label=3;case 3:return[2]}})})},t.prototype.getOrCreateVisitorId=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h;return me(this,function(d){switch(d.label){case 0:t=[],(i=null===(a=this.notificationManager)||void 0===a?void 0:a.getFCMToken())?(n="granted"===(null===(c=this.notificationManager)||void 0===c?void 0:c.getState().permissionStatus),t.push({type:this.getChannelType(),value:i,primary:!0,verified:!0,subscribed:n}),this.logger.info("Including FCM token in visitor creation",{tokenPreview:i.substring(0,20)+"...",subscribed:n})):this.logger.info("No FCM token available, creating visitor without commChannels"),d.label=1;case 1:return d.trys.push([1,5,,6]),this.notificationManager?[4,this.notificationManager.getTokenCreationDate()]:[3,3];case 2:return s=d.sent(),[3,4];case 3:s=null,d.label=4;case 4:return r=s,e=ha(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:"granted"===(null===(h=this.notificationManager)||void 0===h?void 0:h.getState().permissionStatus),fcmTokenCreatedAt:r})),this.logger.debug("Extended fields collected",{extendedFields:e}),[3,6];case 5:return o=d.sent(),this.logger.error("Failed to collect extended fields, proceeding without them",{error:o}),e=void 0,[3,6];case 6:return u=this,[4,this.anonymousVisitorManager.getOrCreateVisitorId(t.length>0?t:void 0,e)];case 7:return u.visitorId=d.sent(),this.logger.setContext({visitorId:this.visitorId}),this.logger.info("Visitor ID ready",{visitorId:this.visitorId}),[2,this.visitorId]}})})},t.prototype.setupTokenUpdateCallback=function(){var t=this;this.notificationManager&&(this.notificationManager.setTokenUpdateCallback(function(i,n){return ve(t,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return[4,this.handleTokenUpdate(i,n)];case 1:return t.sent(),[2]}})})}),this.logger.debug("Token update callback configured for backend sync"))},t.prototype.handleTokenUpdate=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r;return me(this,function(s){switch(s.label){case 0:if(!this.visitorId)return this.logger.info("Skipping token sync - no visitor ID yet (will be included in create)",{isNewToken:i}),[2];if(!i)return this.logger.info("Skipping token sync - token unchanged"),[2];n="granted"!==(null===(r=this.notificationManager)||void 0===r?void 0:r.getState().permissionStatus),this.logTokenSyncStart(t,n),s.label=1;case 1:return s.trys.push([1,6,,7]),this.userIdentified&&this.lastAuthenticatedUser?[4,this.syncTokenForIdentifiedUser(n)]:[3,3];case 2:return s.sent(),[3,5];case 3:return[4,this.syncTokenForAnonymousUser(t,n)];case 4:s.sent(),s.label=5;case 5:return[3,7];case 6:return e=s.sent(),this.logger.error("Failed to sync FCM token with backend",e),[3,7];case 7:return[2]}})})},t.prototype.logTokenSyncStart=function(t,i){i?this.logger.info("Permission revoked, syncing push_opted:false with backend",{visitorId:this.visitorId}):this.logger.info("FCM token updated, syncing with backend",{visitorId:this.visitorId,tokenPreview:t.substring(0,20)+"..."})},t.prototype.syncTokenForIdentifiedUser=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return this.lastAuthenticatedUser?[4,this.sendUserEventToApi(Cs,this.lastAuthenticatedUser,this.lastUserAttributes)]:[2];case 1:return i.sent(),this.logger.info("Token state synced via User Events API (user_update)",{permissionRevoked:t}),[2]}})})},t.prototype.syncTokenForAnonymousUser=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:n=t?[{type:this.getChannelType(),value:t,primary:!0,verified:!0,subscribed:!i}]:[],u.label=1;case 1:return u.trys.push([1,5,,6]),i||!this.notificationManager?[3,3]:[4,this.notificationManager.getTokenCreationDate()];case 2:return s=u.sent(),[3,4];case 3:s=null,u.label=4;case 4:return r=s,e=ha(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:!i,fcmTokenCreatedAt:r})),[3,6];case 5:return o=u.sent(),this.logger.error("Failed to collect extended fields for token update",{error:o}),e=void 0,[3,6];case 6:return[4,this.anonymousVisitorManager.updateVisitor(n,e)];case 7:return u.sent(),i?this.logger.info("Token synced with subscribed:false (permission revoked)",{visitorId:this.visitorId}):this.logger.info("FCM token synced with backend successfully",{visitorId:this.visitorId}),[2]}})})},t.prototype.getAnonymousId=function(){return this.visitorId},t.prototype.getUser=function(){var t,i,n,e,r;if(this.userIdentified)throw this.logger.error("getUser() called while a user is identified - data not exposed"),new Error("This data is not exposed");var s=null!==(i=null===(t=this.sessionManager)||void 0===t?void 0:t.getCurrentSessionId())&&void 0!==i?i:"",o=null!==(e=null===(n=this.sessionManager)||void 0===n?void 0:n.getSessionNumber())&&void 0!==e?e:0;return{visitorId:null!==(r=this.visitorId)&&void 0!==r?r:"",userId:null,sessionId:s,isIdentified:!1,isAnonymous:!0,profileTier:"anonymous",attributes:null,sessionNumber:o,isFirstSession:1===o,isReturningVisitor:o>1}},t.prototype.setUserContext=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(!this.initialized)throw this.logger.error("setUserContext() called before WebSDK is initialized"),new Error("WebSDK must be initialized before setting user context");o.label=1;case 1:return o.trys.push([1,5,,6]),[4,this.validateAndClearDifferentUserContext(t)];case 2:return o.sent(),this.logger.setContext({cuid:t}),n=null!==(s=null!=i?i:this.currentUserIdentifierType)&&void 0!==s?s:void 0,e=this.config.accountId||"",[4,this.eventTracker.setUserContext(e,t,n)];case 3:return o.sent(),this.userContextSet=!0,i&&(this.currentUserIdentifierType=i),this.visitorId&&this.logger.info("User identified - transitioning from anonymous to identified tracking",{visitorId:this.visitorId,cuid:t,trackingMode:"identified"}),[4,this.storeUserContext(t,n)];case 4:return o.sent(),this.logger.info("User context set and persisted",{cuid:t,accountId:this.config.accountId}),[3,6];case 5:throw r=o.sent(),this.logger.error("Failed to set user context",{cuid:t,error:r}),r;case 6:return[2]}})})},t.prototype.clearUserContext=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r;return me(this,function(s){switch(s.label){case 0:i=null===(r=null==t?void 0:t.resetIdentified)||void 0===r||r,s.label=1;case 1:return s.trys.push([1,5,,6]),n=Ae("USER_CONTEXT",this.config.brandId,this.config.applicationId),[4,this.storageManager.remove(n)];case 2:return s.sent(),i?[4,this.storageManager.remove(this.lastAuthenticatedUserKey())]:[3,4];case 3:s.sent(),s.label=4;case 4:return this.eventTracker&&this.eventTracker.clearUserContext(),this.currentUserIdentifierType=null,this.userContextSet=!1,i&&(this.userIdentified=!1,this.lastAuthenticatedUser=null),this.logger.setContext({cuid:""}),this.logger.info("User context cleared"),[3,6];case 5:return e=s.sent(),this.logger.error("Failed to clear user context",{error:e}),this.currentUserIdentifierType=null,this.userContextSet=!1,i&&(this.userIdentified=!1,this.lastAuthenticatedUser=null),this.logger.setContext({cuid:""}),[3,6];case 6:return[2]}})})},t.prototype.track=function(t,i){var n;this.pushEvent(t,i),null===(n=this.gamificationManager)||void 0===n||n.handleActionEvent(t)},t.prototype.pageView=function(t){var i,n,e,r=null!==(i=null==t?void 0:t.page_url)&&void 0!==i?i:"undefined"!=typeof window?window.location.href:void 0,s=null!==(n=null==t?void 0:t.page_title)&&void 0!==n?n:"undefined"!=typeof document?document.title:void 0,o=null!==(e=null==t?void 0:t.referrer)&&void 0!==e?e:"undefined"!=typeof document?document.referrer:void 0,u=le(le(le(le(le({},r&&{page_url:r}),s&&{page_title:s}),o&&{referrer:o}),(null==t?void 0:t.page_category)&&{page_category:t.page_category}),null==t?void 0:t.properties);this.pushEvent("page_view",u)},t.prototype.pickTraitFields=function(t){var i={},n=t.gender,e=t.birthday,r=t.city,s=t.country,o=t.timezone;return n&&(i.gender=n),e&&(i.birthday=e),r&&(i.city=r),s&&(i.country=s),o&&(i.timezone=o),i},t.prototype.identify=function(t){var i,n,e,r,s,o,u,a=t.identifier,c=t.actionType,h=t.traits,d=void 0===h?{}:h;if(!a||!a.cuid)throw this.logger.error("Invalid identify call: missing identifier or cuid",{identifier:a}),new Error("identifier with a non-empty cuid is required for identify");var f=["email","mobile","externalId"],l=null===(s=null===(r=null===(e=null===(n=this.visitorConfigManager)||void 0===n?void 0:n.getCachedConfig())||void 0===e?void 0:e.data)||void 0===r?void 0:r.configs)||void 0===s?void 0:s.loginIdentifierType,v=l&&f.includes(l)?l:a.type;if(!f.includes(v))throw this.logger.error("Invalid identify call: unsupported identifier type",{type:v,cuid:a.cuid}),new Error("Invalid identifier type: ".concat(v,". Must be 'email', 'mobile', or 'externalId'."));var m=a.cuid;this.currentUserIdentifierType=v;var g=le(le(le(le(le({firstName:null!==(o=d.firstName)&&void 0!==o?o:"",lastName:null!==(u=d.lastName)&&void 0!==u?u:""},d.email&&{email:d.email}),d.mobile&&{mobile:d.mobile}),d.externalId&&{externalId:d.externalId}),((i={})[v]=m,i)),void 0!==d.custom&&{customData:d.custom}),p=this.pickTraitFields(d);g.customData=le(le({},p),g.customData),this.userIdentified=!0;var w=v;switch(c){case"USER_REGISTER":this.pushUserSignin(m,g,w);break;case"USER_UPDATE":this.pushUserUpdate(m,g,w);break;default:throw this.logger.error("Invalid identify actionType",{actionType:c,cuid:m}),new Error("Invalid identify actionType: ".concat(c,". Must be 'USER_REGISTER' or 'USER_UPDATE'."))}},t.prototype.trackEvent=function(t){return ve(this,arguments,void 0,function(t,i){return void 0===i&&(i=!1),me(this,function(n){switch(n.label){case 0:if(!this.initialized)throw new Error("WebSDK must be initialized before tracking events");return[4,this.eventTracker.track(t,i)];case 1:return n.sent(),[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:this.logger.info("Destroying WebSDK instance"),i.label=1;case 1:return i.trys.push([1,16,,17]),this.eventTracker?[4,this.eventTracker.flush()]:[3,4];case 2:return i.sent(),[4,this.eventTracker.destroy()];case 3:i.sent(),i.label=4;case 4:return this.scrollDepthTracker&&(this.scrollDepthTracker.destroy(),this.scrollDepthTracker=null),this.visitorConfigManager?[4,this.visitorConfigManager.destroy()]:[3,6];case 5:i.sent(),i.label=6;case 6:return this.anonymousVisitorManager?[4,this.anonymousVisitorManager.destroy()]:[3,8];case 7:i.sent(),i.label=8;case 8:return this.permissionChangeCleanup&&(this.permissionChangeCleanup(),this.permissionChangeCleanup=null),this.dlrMessageCleanup&&(this.dlrMessageCleanup(),this.dlrMessageCleanup=null),this.notificationManager?(this.notificationManager.clearTokenUpdateCallback(),[4,this.notificationManager.destroy()]):[3,10];case 9:i.sent(),this.notificationManager=null,i.label=10;case 10:return this.gamificationManager&&(this.gamificationManager.destroy(),this.gamificationManager=null),this.sessionManager?[4,this.sessionManager.destroy()]:[3,12];case 11:i.sent(),i.label=12;case 12:return this.storageManager?[4,this.clearUserContext()]:[3,15];case 13:return i.sent(),[4,this.storageManager.destroy()];case 14:i.sent(),i.label=15;case 15:return this.initialized=!1,this.logger.info(Be),[3,17];case 16:throw t=i.sent(),this.logger.error(ze,{error:t}),t;case 17:return[2]}})})},t.prototype.validateUserAttributes=function(t){if(!t.email&&!t.mobile&&!t.externalId)throw new Error("At least one of email, mobile, or externalId is required")},t.prototype.attemptVisitorMerge=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s;return me(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),this.visitorTrackingEnabled&&this.visitorId?t.email||t.mobile||t.externalId?(e="email"===n||"mobile"===n||"externalId"===n?n:void 0,[4,this.anonymousVisitorManager.mergeVisitorWithUser(le(le(le(le(le(le({firstName:t.firstName,lastName:t.lastName},void 0!==t.email&&{email:t.email}),void 0!==t.mobile&&{mobile:t.mobile}),void 0!==t.externalId&&{externalId:t.externalId}),void 0!==t.customData&&{customData:t.customData}),{cuid:i}),void 0!==e&&{identifierType:e}))]):(this.logger.debug(Xr,{reason:"No email, mobile, or externalId"}),[2,!1]):(this.logger.debug(Xr,{reason:this.visitorTrackingEnabled?"No visitorId":"Visitor tracking disabled"}),[2,!1]);case 1:return r=o.sent(),this.logger.info("Visitor merge attempt completed",{visitorId:this.visitorId,success:r}),[2,r];case 2:return s=o.sent(),this.logger.error(Wr,{visitorId:this.visitorId,error:s}),[2,!1];case 3:return[2]}})})},t.prototype.buildPushData=function(){var t,i,n,e="granted"===(null===(t=this.notificationManager)||void 0===t?void 0:t.getState().permissionStatus),r=null!==(n=null===(i=this.notificationManager)||void 0===i?void 0:i.getFCMToken())&&void 0!==n?n:null;return{pushOpted:e&&!!r,tokens:r?[{interface_id:r,gateway:Fs.WEB}]:[]}},t.prototype.buildUserAttributePayload=function(t){if(!t)return{};var i={};return t.firstName&&(i.firstName=t.firstName),t.lastName&&(i.lastName=t.lastName),t.email&&(i.email=t.email),t.mobile&&(i.phone=t.mobile),i},t.prototype.sendUserEventToApi=function(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s,o,u,a,c,h,d,f,l,v,m;return me(this,function(g){switch(g.label){case 0:return r=this.buildPushData(),s=r.pushOpted,o=r.tokens,u=null!==(d=null===(h=this.sessionManager)||void 0===h?void 0:h.getCurrentSessionId())&&void 0!==d?d:"",[4,this.apiClient.buildUserEventsRequest(t,le(le(le({cuid:i,push_opted:s,tokens:o},this.visitorId&&{visitorId:this.visitorId}),this.buildUserAttributePayload(n)),e),u)];case 1:return a=g.sent(),c=null!==(l=null===(f=this.anonymousVisitorManager)||void 0===f?void 0:f.getVisitorExternalId())&&void 0!==l?l:void 0,[4,this.apiClient.sendUserEvents(a,null!==(v=this.visitorId)&&void 0!==v?v:void 0,c,i,null!==(m=this.currentUserIdentifierType)&&void 0!==m?m:void 0)];case 2:return g.sent(),this.logger.info("User event sent to User Events API",{eventName:t,cuid:i}),[2]}})})},t.prototype.pushUserSignin=function(t,i,n){var e=this;this.userIdentified=!0,this.queueUserOperation(function(){return ve(e,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.pushUserSigninAsync(t,i,n)];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error(kr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSigninAsync=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f=this;return me(this,function(l){switch(l.label){case 0:return[4,this.ensureInitialized()];case 1:return l.sent(),this.validateUserAttributes(i),e=(null!==(h=null===(c=this.sessionManager)||void 0===c?void 0:c.getSessionNumber())&&void 0!==h?h:0)>1,r=e?"returning":"new_session",[4,this.setUserContextIfNeeded(t,n)];case 2:return l.sent(),[4,this.attemptVisitorMerge(i,t,n)];case 3:return s=l.sent(),this.lastUserAttributes=i,[4,this.storeUserContext(t,n,i)];case 4:l.sent(),l.label=5;case 5:return l.trys.push([5,7,,8]),[4,this.sendUserEventToApi(As,t,i,le(le({},void 0!==n&&{method:n}),{success:s,login_type:r}))];case 6:return l.sent(),this.logger.info("User signin event tracked",{cuid:t,firstName:i.firstName,lastName:i.lastName,email:i.email,loginType:r,mergeSuccess:s}),[3,8];case 7:return o=l.sent(),this.logger.error("Failed to send signin event to User Events API",{cuid:t,error:o}),[3,8];case 8:return u=le(le(le({},i.email&&{email:i.email}),i.mobile&&{mobile:i.mobile}),i.customData&&{customAttributes:i.customData}),(a=[i.firstName,i.lastName].filter(Boolean).join(" "))&&Object.assign(u,{name:a}),null===(d=this.gamificationManager)||void 0===d||d.initialize(t,u).catch(function(i){f.logger.error("Failed to initialize gamification on signin",{cuid:t,error:i})}),[2]}})})},t.prototype.pushUserSignup=function(t,i,n){var e=this;this.userIdentified=!0,this.queueUserOperation(function(){return ve(e,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.pushUserSignupAsync(t,i,n)];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error(Or,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSignupAsync=function(t,i,n){return ve(this,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:return[4,this.ensureInitialized()];case 1:return e.sent(),this.validateUserAttributes(i),[4,this.setUserContextIfNeeded(t,n)];case 2:return e.sent(),this.attemptVisitorMerge(i,t,n),this.lastUserAttributes=i,[4,this.storeUserContext(t,n,i)];case 3:return e.sent(),[4,this.sendUserEventToApi(As,t,i)];case 4:return e.sent(),this.logger.info("User signup event tracked (routed as user_signin)",{cuid:t,firstName:i.firstName,lastName:i.lastName,email:i.email}),[2]}})})},t.prototype.pushUserUpdate=function(t,i,n){var e=this;this.queueUserOperation(function(){return ve(e,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.pushUserUpdateAsync(t,i,n)];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error(Ar,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserUpdateAsync=function(t,i,n){return ve(this,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:return[4,this.ensureInitialized()];case 1:return e.sent(),this.validateUserAttributes(i),[4,this.setUserContextIfNeeded(t,n)];case 2:return e.sent(),this.lastUserAttributes=i,[4,this.storeUserContext(t,n,i)];case 3:return e.sent(),[4,this.sendUserEventToApi(Cs,t,i)];case 4:return e.sent(),this.logger.info("User update event tracked",{cuid:t}),[2]}})})},t.prototype.reset=function(){var t=this.lastAuthenticatedUser;t?this.pushUserSignOut(t):this.logger.warn("reset() called but no authenticated user to sign out")},t.prototype.setCapToken=function(t){var i;this.pendingGamificationSettings.capToken=t,null===(i=this.gamificationManager)||void 0===i||i.setCapToken(t)},t.prototype.getCapToken=function(){var t,i;return null!==(i=null===(t=this.gamificationManager)||void 0===t?void 0:t.getCapToken())&&void 0!==i?i:null},t.prototype.enablePagePathTracking=function(t){var i;this.pendingGamificationSettings.pagePathTrackingEnabled=t,null===(i=this.gamificationManager)||void 0===i||i.enablePagePathTracking(t)},t.prototype.onScreenChanged=function(t){var i;this.pendingGamificationSettings.screenName=t,null===(i=this.gamificationManager)||void 0===i||i.onScreenChanged(t)},t.prototype.setGamificationSuppressed=function(t){var i;this.pendingGamificationSettings.suppressed=t,null===(i=this.gamificationManager)||void 0===i||i.setGamificationSuppressed(t)},t.prototype.isGamificationSuppressed=function(){var t,i;return null!==(i=null===(t=this.gamificationManager)||void 0===t?void 0:t.isGamificationSuppressed())&&void 0!==i&&i},t.prototype.setTheme=function(t){var i;this.pendingGamificationSettings.theme=t,null===(i=this.gamificationManager)||void 0===i||i.setTheme(t)},t.prototype.forceSyncGamification=function(){var t,i=this;null===(t=this.gamificationManager)||void 0===t||t.forceSync().catch(function(t){i.logger.error("forceSyncGamification() failed",{error:t})})},t.prototype.setGamificationCallback=function(t){var i;this.pendingGamificationCallback=t,null===(i=this.gamificationManager)||void 0===i||i.setGamificationCallback(t)},t.prototype.pushUserSignOut=function(t){var i=this;this.queueUserOperation(function(){return ve(i,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.pushUserSignOutAsync(t)];case 1:return n.sent(),[3,3];case 2:return i=n.sent(),this.logger.error(Cr,{cuid:t,error:i}),[3,3];case 3:return[2]}})})})},t.prototype.resetToAnonymousMode=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d,f,l;return me(this,function(v){switch(v.label){case 0:return null===(h=this.gamificationManager)||void 0===h||h.clean(),[4,this.sessionManager.endSession("signout")];case 1:if(v.sent(),!this.visitorTrackingEnabled)return this.logger.info("Visitor tracking disabled per latest config, skipping anonymous mode"),this.visitorId=null,this.logger.setContext({visitorId:""}),this.eventTracker.setVisitorTrackingState(null,!1),[2];v.label=2;case 2:return v.trys.push([2,11,,12]),[4,this.anonymousVisitorManager.clearVisitorId()];case 3:v.sent(),this.logger.info("Visitor ID cleared on user signout"),t=[],(i=null===(d=this.notificationManager)||void 0===d?void 0:d.getFCMToken())&&(n="granted"===(null===(f=this.notificationManager)||void 0===f?void 0:f.getState().permissionStatus),t.push({type:this.getChannelType(),value:i,primary:!0,verified:!0,subscribed:n})),e=void 0,v.label=4;case 4:return v.trys.push([4,8,,9]),this.notificationManager?[4,this.notificationManager.getTokenCreationDate()]:[3,6];case 5:return s=v.sent(),[3,7];case 6:s=null,v.label=7;case 7:return r=s,e=ha(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:"granted"===(null===(l=this.notificationManager)||void 0===l?void 0:l.getState().permissionStatus),fcmTokenCreatedAt:r})),[3,9];case 8:return o=v.sent(),this.logger.error("Failed to collect extended fields on signout, proceeding without them",{error:o}),e=void 0,[3,9];case 9:return u=this,[4,this.anonymousVisitorManager.getOrCreateVisitorId(t.length>0?t:void 0,e)];case 10:return u.visitorId=v.sent(),this.logger.setContext({visitorId:this.visitorId}),this.logger.info("New anonymous visitor ID generated after signout",{visitorId:this.visitorId,hasFCMToken:!!i}),a=this.anonymousVisitorManager.getVisitorExternalId(),this.eventTracker.setVisitorTrackingState(this.visitorId,!0,a),[3,12];case 11:return c=v.sent(),this.logger.error("Failed to regenerate visitor ID on signout",{error:c}),this.visitorId=null,this.logger.setContext({visitorId:""}),this.eventTracker.setVisitorTrackingState(null,!0),[3,12];case 12:return[2]}})})},t.prototype.pushUserSignOutAsync=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:return[4,this.ensureInitialized()];case 1:return h.sent(),[4,this.setUserContextIfNeeded(t)];case 2:h.sent(),h.label=3;case 3:return h.trys.push([3,5,,6]),i=null!==(a=null===(u=this.sessionManager)||void 0===u?void 0:u.getSessionStartTime())&&void 0!==a?a:null,n=null!==i?Math.floor((Date.now()-i)/1e3):void 0,[4,this.sendUserEventToApi(Rs,t,this.lastUserAttributes,le(le({},void 0!==n&&{session_duration:n}),{logout_trigger:"user_initiated"}))];case 4:return h.sent(),this.logger.info("User signout event tracked",{cuid:t}),[3,6];case 5:return e=h.sent(),this.logger.error("Failed to send signout event to User Events API",{cuid:t,error:e}),[3,6];case 6:return h.trys.push([6,15,,16]),[4,this.anonymousVisitorManager.clearMergedUserId()];case 7:return h.sent(),[4,this.anonymousVisitorManager.clearPendingMerge()];case 8:return h.sent(),[4,this.clearUserContext()];case 9:h.sent(),this.logger.info("User context cleared, returning to anonymous mode (session continues)"),h.label=10;case 10:return h.trys.push([10,12,,13]),[4,this.visitorConfigManager.refreshConfig()];case 11:return r=h.sent(),this.visitorTrackingEnabled=!0===(null===(c=r.data)||void 0===c?void 0:c.visitorTrackingEnabled),this.logger.info("Visitor config refreshed on signout",{visitorTrackingEnabled:this.visitorTrackingEnabled}),[3,13];case 12:return s=h.sent(),this.logger.error("Failed to refresh visitor config on signout, using existing value",{visitorTrackingEnabled:this.visitorTrackingEnabled,error:s}),[3,13];case 13:return[4,this.resetToAnonymousMode()];case 14:return h.sent(),this.logger.info("SDK remains active for anonymous tracking"),[3,16];case 15:throw o=h.sent(),this.logger.error("Failed to clear user context on signout",{error:o}),o;case 16:return[2]}})})},t.prototype.buildInternalEventAttributes=function(t){return le(le(le({},this.userIdentified&&this.lastAuthenticatedUser&&{cuid:this.lastAuthenticatedUser}),this.visitorId&&{visitorId:this.visitorId}),t)},t.prototype.pushEvent=function(t,i){var n=this;this.pushEventAsync(t,i).catch(function(i){n.logger.error(Rr,{eventName:t,error:i})})},t.prototype.pushGamificationEvent=function(t,i){var n=this,e=le(le({},this.userIdentified&&this.lastAuthenticatedUser&&{cuid:this.lastAuthenticatedUser}),i);this.pushEventAsync(t,e,!0).catch(function(i){n.logger.error(Rr,{eventName:t,error:i})})},t.prototype.pushEventAsync=function(t,i){return ve(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=!1),me(this,function(s){switch(s.label){case 0:return[4,this.ensureInitialized()];case 1:return s.sent(),this.visitorTrackingEnabled||n?this.sdkDisabled&&!n?(this.logger.debug("SDK disabled, dropping event",{eventName:t}),[2]):this.userContextSet||this.visitorId?(e=le({},null!=i?i:{}),r={type:"behavioral",name:t,timestamp:Date.now(),data:e},[4,this.trackEvent(r,n)]):(this.logger.warn("Event tracking skipped: No visitor ID available and no user context set",{eventName:t}),[2]):(this.logger.warn("Event tracking skipped: Visitor tracking is disabled",{eventName:t}),[2]);case 2:return s.sent(),this.logger.info("Behavioral event tracked",{eventName:t,attributes:i}),[2]}})})},t.prototype.disableSDK=function(){this.sdkDisabled?this.logger.warn("SDK is already disabled"):(this.sdkDisabled=!0,this.eventTracker&&this.eventTracker.pause(),this.logger.info("SDK disabled — event tracking stopped"))},t.prototype.enableSDK=function(){var t=this;this.sdkDisabled?(this.sdkDisabled=!1,this.eventTracker&&this.eventTracker.resume().catch(function(i){t.logger.error("Failed to resume event tracker",i)}),this.logger.info("SDK enabled — event tracking resumed")):this.logger.warn("SDK is already enabled")},t.prototype.getChannelType=function(){return this.config.channelType||Fs.WEB},t.prototype.resolveGamificationBaseUrl=function(t){return t.gamificationBaseUrl?t.gamificationBaseUrl:t.gamificationRegion?Bo(t.gamificationRegion):Vo},t.prototype.applyConfigDefaults=function(){this.config.source=this.config.source||Ls.WEBPUSH,this.config.channelType=this.config.channelType||Fs.WEB;var t=Ne/6e4;this.config.sessionTimeoutMinutes=this.config.sessionTimeoutMinutes||t,this.config.batchSize=this.config.batchSize||De.BATCH_SIZE,this.config.debugLevel=this.config.debugLevel||"NONE",this.gamificationBaseUrl=this.resolveGamificationBaseUrl(this.config),this.logger.setEnabled(this.shouldEnableLogging(this.config.debugLevel)),this.logger.setLevel(this.resolveLogLevel(this.config.debugLevel))},t.prototype.applyRemoteConfigValues=function(t){this.config.accountId=t.accountId,this.config.baseURL=t.baseURL,this.config.orgId=t.orgId,this.config.source=t.source,this.config.channelType=t.channelType,this.config.brandId=this.config.brandId||t.brandId,this.config.applicationId=this.config.applicationId||t.applicationId,this.config.sessionTimeoutMinutes=t.sessionTimeoutMinutes,this.config.batchSize=t.batchSize,this.config.debugLevel=t.debugLevel,this.config.gamificationWriteKey=t.gamificationWriteKey||void 0,this.config.gamificationRegion=t.gamificationRegion||void 0,this.config.gamificationBaseUrl=t.gamificationBaseUrl||void 0,this.applyConfigDefaults(),this.logger.info("Session timeout configured:",{timeoutMinutes:this.config.sessionTimeoutMinutes,source:t.sessionTimeoutMinutes?"Remote Config":"Default"}),this.logger.info("Batch size configured:",{batchSize:this.config.batchSize,source:t.batchSize?"Remote Config":"Default"}),this.logger.info("Debug level configured:",{debugLevel:this.config.debugLevel,source:t.debugLevel?"Remote Config":"Default"})},t.prototype.applyDirectConfigValues=function(){this.applyConfigDefaults(),this.logger.info("✅ SDK configuration applied directly (no Remote Config)"),this.logger.debug("Final SDK config:",this.config)},t.prototype.bootstrapConfig=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.config.remoteConfigKey?[4,this.fetchAndApplyRemoteConfig()]:[3,2];case 1:return t.sent(),[3,3];case 2:this.applyDirectConfigValues(),this.initializeManagersFromConfig(),t.label=3;case 3:return[2]}})})},t.prototype.getExtendedFieldsForMerge=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),this.notificationManager?[4,this.notificationManager.getTokenCreationDate()]:[3,2];case 1:return i=r.sent(),[3,3];case 2:i=null,r.label=3;case 3:return t=i,[2,ha(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:"granted"===(null===(e=this.notificationManager)||void 0===e?void 0:e.getState().permissionStatus),fcmTokenCreatedAt:t}))];case 4:return n=r.sent(),this.logger.error("Failed to collect extended fields for merge, proceeding without them",{error:n}),[2,void 0];case 5:return[2]}})})},t.prototype.initializeManagersFromConfig=function(){var t=this;this.storageManager=new oc(this.logger,this.config.brandId,this.config.applicationId),this.sessionManager=new pc(this.storageManager,this.logger,this.config.brandId,this.config.applicationId,this.config.sessionTimeoutMinutes),this.apiClient=new tc({baseUrl:this.config.baseURL||""},this.logger,this.config.accountId||"",this.config.orgId||"",this.config.source||Ls.WEBPUSH);var i=this.apiClient;this.eventTracker=new sc(this.config,i,this.storageManager,this.logger);var n=this.config.orgId||"",e=this.config.accountId||"";this.logger.setContext({orgId:n,accountId:e}),this.visitorConfigManager=new cc(n,i,this.logger,this.storageManager,this.config.brandId,this.config.applicationId),this.anonymousVisitorManager=new hc(e,n,i,this.logger,this.storageManager,le(le({},void 0!==this.config.brandId?{brandId:this.config.brandId}:{}),void 0!==this.config.applicationId?{applicationId:this.config.applicationId}:{})),this.anonymousVisitorManager.setMergeDataProviders(function(){var i;return(null===(i=t.notificationManager)||void 0===i?void 0:i.getFCMToken())||null},function(){return t.getChannelType()},function(){return t.getExtendedFieldsForMerge()},function(){var i;return"granted"===(null===(i=t.notificationManager)||void 0===i?void 0:i.getState().permissionStatus)},function(){var i,n;return null!==(n=null===(i=t.sessionManager)||void 0===i?void 0:i.getCurrentSessionId())&&void 0!==n?n:""}),this.initializeGamificationManager()},t.prototype.initializeGamificationManager=function(){var t=this;this.config.gamificationWriteKey&&this.gamificationBaseUrl?(this.gamificationManager=new Za(this.config.gamificationWriteKey,this.gamificationBaseUrl,this.logger,this.storageManager,function(i,n){return t.pushGamificationEvent(i,n)},function(){var i,n;return null!==(n=null===(i=t.sessionManager)||void 0===i?void 0:i.getCurrentSessionId())&&void 0!==n?n:null}),this.pendingGamificationCallback&&this.gamificationManager.setGamificationCallback(this.pendingGamificationCallback),this.applyPendingGamificationSettings()):this.logger.info(Ys)},t.prototype.applyPendingGamificationSettings=function(){var t,i,n,e,r,s=this.pendingGamificationSettings;void 0!==s.capToken&&(null===(t=this.gamificationManager)||void 0===t||t.setCapToken(s.capToken)),void 0!==s.pagePathTrackingEnabled&&(null===(i=this.gamificationManager)||void 0===i||i.enablePagePathTracking(s.pagePathTrackingEnabled)),void 0!==s.screenName&&(null===(n=this.gamificationManager)||void 0===n||n.onScreenChanged(s.screenName)),void 0!==s.suppressed&&(null===(e=this.gamificationManager)||void 0===e||e.setGamificationSuppressed(s.suppressed)),void 0!==s.theme&&(null===(r=this.gamificationManager)||void 0===r||r.setTheme(s.theme))},t.prototype.fetchAndApplyRemoteConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:this.logger.info("📡 Fetching configuration from Firebase Remote Config..."),f.label=1;case 1:return f.trys.push([1,5,,6]),[4,fc()];case 2:return t=f.sent(),[4,vc()];case 3:return i=f.sent(),n=t.initializeApp||t,e=i.getRemoteConfig||i,r=i.fetchAndActivate,s=i.getValue,o=n(this.config.firebaseConfig),(u=e(o)).settings.minimumFetchIntervalMillis=36e5,this.logger.info("🔄 Fetching Remote Config from Firebase..."),[4,r(u)];case 4:if(f.sent()||this.logger.error("⚠️ Remote Config fetched but not activated (using cached values)"),a=s(u,this.config.remoteConfigKey),!(c=a.asString()))throw new Error('Remote Config key "'.concat(this.config.remoteConfigKey,'" is empty or not found'));h=void 0;try{h=JSON.parse(c)}catch(t){throw new Error("Failed to parse Remote Config JSON: ".concat(t))}return this.logger.info("✅ Remote Config fetched successfully:",h),this.applyRemoteConfigValues(h),this.initializeManagersFromConfig(),this.logger.info("✅ SDK configuration applied from Remote Config"),this.logger.debug("Final SDK config:",this.config),[3,6];case 5:throw d=f.sent(),this.logger.error("❌ Failed to fetch Remote Config:",{remoteConfigKey:this.config.remoteConfigKey,error:d}),new Error("Remote Config bootstrap failed: ".concat(d));case 6:return[2]}})})},t.prototype.validateRequiredConfig=function(t){var i=[];if(t.remoteConfigKey?t.firebaseConfig||i.push("firebaseConfig"):(t.accountId||i.push("accountId"),t.baseURL||i.push("baseURL"),t.orgId||i.push("orgId")),i.length>0)throw this.logger.error("WebSDK initialization failed: missing required configuration fields",{missingFields:i}),new Error("WebSDK initialization failed: Missing required configuration fields: ".concat(i.join(", "),". ")+'Provide either "remoteConfigKey" + "firebaseConfig" (Remote Config bootstrap) or "accountId" + "baseURL" + "orgId" directly (direct-config bootstrap).')},t.prototype.ensureInitialized=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:if(!this.initializationPromise)return[3,4];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.initializationPromise];case 2:return i.sent(),[3,4];case 3:throw t=i.sent(),new Error("SDK initialization failed: ".concat(t));case 4:if(!this.initialized)throw new Error("WebSDK must be initialized before tracking events. Call init() first.");return[2]}})})},t.prototype.setUserContextIfNeeded=function(t,i){return ve(this,void 0,void 0,function(){return me(this,function(n){switch(n.label){case 0:return this.userContextSet&&this.lastAuthenticatedUser===t?[3,2]:[4,this.setUserContext(t,i)];case 1:n.sent(),this.logger.debug("User context set automatically",{cuid:t}),n.label=2;case 2:return[2]}})})},t.prototype.queueUserOperation=function(t){var i=this;this.userOperationChain=this.userOperationChain.then(t).catch(function(t){i.logger.error("User operation failed",t)})},t.p=null,t}();t.HydraSDK=yc,t.default=yc,Object.defineProperty(t,"_",{value:!0})});
|
|
1
|
+
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).WebSDK={})}(this,function(t){"use strict";var i="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},n="URLSearchParams"in i,e="Symbol"in i&&"iterator"in Symbol,r="FileReader"in i&&"Blob"in i&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in i,o="ArrayBuffer"in i;if(o)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],a=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||""===t)throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var i={next:function(){var i=t.shift();return{done:void 0===i,value:i}}};return e&&(i[Symbol.iterator]=function(){return i}),i}function f(t){this.map={},t instanceof f?t.forEach(function(t,i){this.append(i,t)},this):Array.isArray(t)?t.forEach(function(t){if(2!=t.length)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+t.length);this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(i){this.append(i,t[i])},this)}function l(t){if(!t.t)return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function v(t){return new Promise(function(i,n){t.onload=function(){i(t.result)},t.onerror=function(){n(t.error)}})}function m(t){var i=new FileReader,n=v(i);return i.readAsArrayBuffer(t),n}function g(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}function p(){return this.bodyUsed=!1,this.i=function(t){var i;this.bodyUsed=this.bodyUsed,this.o=t,t?"string"==typeof t?this.u=t:r&&Blob.prototype.isPrototypeOf(t)?this.h=t:s&&FormData.prototype.isPrototypeOf(t)?this.l=t:n&&URLSearchParams.prototype.isPrototypeOf(t)?this.u=t.toString():o&&r&&((i=t)&&DataView.prototype.isPrototypeOf(i))?(this.v=g(t.buffer),this.o=new Blob([this.v])):o&&(ArrayBuffer.prototype.isPrototypeOf(t)||a(t))?this.v=g(t):this.u=t=Object.prototype.toString.call(t):(this.t=!0,this.u=""),this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this.h&&this.h.type?this.headers.set("content-type",this.h.type):n&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var t=l(this);if(t)return t;if(this.h)return Promise.resolve(this.h);if(this.v)return Promise.resolve(new Blob([this.v]));if(this.l)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this.u]))}),this.arrayBuffer=function(){if(this.v){var t=l(this);return t||(ArrayBuffer.isView(this.v)?Promise.resolve(this.v.buffer.slice(this.v.byteOffset,this.v.byteOffset+this.v.byteLength)):Promise.resolve(this.v))}if(r)return this.blob().then(m);throw new Error("could not read as ArrayBuffer")},this.text=function(){var t,i,n,e,r,s=l(this);if(s)return s;if(this.h)return t=this.h,i=new FileReader,n=v(i),e=/charset=([A-Za-z0-9_-]+)/.exec(t.type),r=e?e[1]:"utf-8",i.readAsText(t,r),n;if(this.v)return Promise.resolve(function(t){for(var i=new Uint8Array(t),n=new Array(i.length),e=0;e<i.length;e++)n[e]=String.fromCharCode(i[e]);return n.join("")}(this.v));if(this.l)throw new Error("could not read FormData body as text");return Promise.resolve(this.u)},s&&(this.formData=function(){return this.text().then(E)}),this.json=function(){return this.text().then(JSON.parse)},this}f.prototype.append=function(t,i){t=c(t),i=h(i);var n=this.map[t];this.map[t]=n?n+", "+i:i},f.prototype.delete=function(t){delete this.map[c(t)]},f.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},f.prototype.set=function(t,i){this.map[c(t)]=h(i)},f.prototype.forEach=function(t,i){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(i,this.map[n],n,this)},f.prototype.keys=function(){var t=[];return this.forEach(function(i,n){t.push(n)}),d(t)},f.prototype.values=function(){var t=[];return this.forEach(function(i){t.push(i)}),d(t)},f.prototype.entries=function(){var t=[];return this.forEach(function(i,n){t.push([n,i])}),d(t)},e&&(f.prototype[Symbol.iterator]=f.prototype.entries);var w=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function y(t,n){if(!(this instanceof y))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');var e,r,s=(n=n||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,n.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,s||null==t.o||(s=t.o,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=n.credentials||this.credentials||"same-origin",!n.headers&&this.headers||(this.headers=new f(n.headers)),this.method=(e=n.method||this.method||"GET",r=e.toUpperCase(),w.indexOf(r)>-1?r:e),this.mode=n.mode||this.mode||null,this.signal=n.signal||this.signal||function(){if("AbortController"in i)return(new AbortController).signal}(),this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");if(this.i(s),!("GET"!==this.method&&"HEAD"!==this.method||"no-store"!==n.cache&&"no-cache"!==n.cache)){var o=/([?&])_=[^&]*/;if(o.test(this.url))this.url=this.url.replace(o,"$1_="+(new Date).getTime());else{this.url+=(/\?/.test(this.url)?"&":"?")+"_="+(new Date).getTime()}}}function E(t){var i=new FormData;return t.trim().split("&").forEach(function(t){if(t){var n=t.split("="),e=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");i.append(decodeURIComponent(e),decodeURIComponent(r))}}),i}function _(t,i){if(!(this instanceof _))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(i||(i={}),this.type="default",this.status=void 0===i.status?200:i.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=void 0===i.statusText?"":""+i.statusText,this.headers=new f(i.headers),this.url=i.url||"",this.i(t)}y.prototype.clone=function(){return new y(this,{body:this.o})},p.call(y.prototype),p.call(_.prototype),_.prototype.clone=function(){return new _(this.o,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},_.error=function(){var t=new _(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var I=[301,302,303,307,308];_.redirect=function(t,i){if(-1===I.indexOf(i))throw new RangeError("Invalid status code");return new _(null,{status:i,headers:{location:t}})};var b=i.DOMException;try{new b}catch(t){(b=function(t,i){this.message=t,this.name=i;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),b.prototype.constructor=b}function T(t,n){return new Promise(function(e,s){var u=new y(t,n);if(u.signal&&u.signal.aborted)return s(new b("Aborted","AbortError"));var a=new XMLHttpRequest;function d(){a.abort()}if(a.onload=function(){var t,i,n={statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",i=new f,t.replace(/\r?\n[\t ]+/g," ").split("\r").map(function(t){return 0===t.indexOf("\n")?t.substr(1,t.length):t}).forEach(function(t){var n=t.split(":"),e=n.shift().trim();if(e){var r=n.join(":").trim();try{i.append(e,r)}catch(t){console.warn("Response "+t.message)}}}),i)};0===u.url.indexOf("file://")&&(a.status<200||a.status>599)?n.status=200:n.status=a.status,n.url="responseURL"in a?a.responseURL:n.headers.get("X-Request-URL");var r="response"in a?a.response:a.responseText;setTimeout(function(){e(new _(r,n))},0)},a.onerror=function(){setTimeout(function(){s(new TypeError("Network request failed"))},0)},a.ontimeout=function(){setTimeout(function(){s(new TypeError("Network request timed out"))},0)},a.onabort=function(){setTimeout(function(){s(new b("Aborted","AbortError"))},0)},a.open(u.method,function(t){try{return""===t&&i.location.href?i.location.href:t}catch(i){return t}}(u.url),!0),"include"===u.credentials?a.withCredentials=!0:"omit"===u.credentials&&(a.withCredentials=!1),"responseType"in a&&(r?a.responseType="blob":o&&(a.responseType="arraybuffer")),n&&"object"==typeof n.headers&&!(n.headers instanceof f||i.Headers&&n.headers instanceof i.Headers)){var l=[];Object.getOwnPropertyNames(n.headers).forEach(function(t){l.push(c(t)),a.setRequestHeader(t,h(n.headers[t]))}),u.headers.forEach(function(t,i){-1===l.indexOf(i)&&a.setRequestHeader(i,t)})}else u.headers.forEach(function(t,i){a.setRequestHeader(i,t)});u.signal&&(u.signal.addEventListener("abort",d),a.onreadystatechange=function(){4===a.readyState&&u.signal.removeEventListener("abort",d)}),a.send(void 0===u.o?null:u.o)})}T.polyfill=!0,i.fetch||(i.fetch=T,i.Headers=f,i.Request=y,i.Response=_);var S,C,N="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},D={};function O(){if(C)return S;C=1;var t=function(t){return t&&t.Math===Math&&t};return S=t("object"==typeof globalThis&&globalThis)||t("object"==typeof window&&window)||t("object"==typeof self&&self)||t("object"==typeof N&&N)||t("object"==typeof S&&S)||function(){return this}()||Function("return this")()}var k,A,x,R,P,M,U,L,F={};function G(){return A?k:(A=1,k=function(t){try{return!!t()}catch(t){return!0}})}function V(){if(R)return x;R=1;var t=G();return x=!t(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})}function B(){if(M)return P;M=1;var t=G();return P=!t(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})}function z(){if(L)return U;L=1;var t=B(),i=Function.prototype.call;return U=t?i.bind(i):function(){return i.apply(i,arguments)},U}var j,H,q,K,W,X,Y,J,Q,$,Z,tt,it,nt,et,rt,st,ot,ut,at,ct,ht,dt,ft,lt,vt,mt,gt,pt,wt,yt,Et,_t,It,bt,Tt,St,Ct,Nt,Dt,Ot,kt={};function At(){return q?H:(q=1,H=function(t,i){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:i}})}function xt(){if(W)return K;W=1;var t=B(),i=Function.prototype,n=i.call,e=t&&i.bind.bind(n,n);return K=t?e:function(t){return function(){return n.apply(t,arguments)}},K}function Rt(){if(Q)return J;Q=1;var t=xt(),i=G(),n=function(){if(Y)return X;Y=1;var t=xt(),i=t({}.toString),n=t("".slice);return X=function(t){return n(i(t),8,-1)}}(),e=Object,r=t("".split);return J=i(function(){return!e("z").propertyIsEnumerable(0)})?function(t){return"String"===n(t)?r(t,""):e(t)}:e}function Pt(){return Z?$:(Z=1,$=function(t){return null==t})}function Mt(){if(it)return tt;it=1;var t=Pt(),i=TypeError;return tt=function(n){if(t(n))throw new i("Can't call method on "+n);return n}}function Ut(){if(et)return nt;et=1;var t=Rt(),i=Mt();return nt=function(n){return t(i(n))}}function Lt(){if(st)return rt;st=1;var t="object"==typeof document&&document.all;return rt=void 0===t&&void 0!==t?function(i){return"function"==typeof i||i===t}:function(t){return"function"==typeof t}}function Ft(){if(ut)return ot;ut=1;var t=Lt();return ot=function(i){return"object"==typeof i?null!==i:t(i)}}function Gt(){if(ct)return at;ct=1;var t=O(),i=Lt();return at=function(n,e){return arguments.length<2?(r=t[n],i(r)?r:void 0):t[n]&&t[n][e];var r},at}function Vt(){if(mt)return vt;mt=1;var t,i,n=O(),e=function(){if(lt)return ft;lt=1;var t=O().navigator,i=t&&t.userAgent;return ft=i?String(i):""}(),r=n.process,s=n.Deno,o=r&&r.versions||s&&s.version,u=o&&o.v8;return u&&(i=(t=u.split("."))[0]>0&&t[0]<4?1:+(t[0]+t[1])),!i&&e&&(!(t=e.match(/Edge\/(\d+)/))||t[1]>=74)&&(t=e.match(/Chrome\/(\d+)/))&&(i=+t[1]),vt=i}function Bt(){if(pt)return gt;pt=1;var t=Vt(),i=G(),n=O().String;return gt=!!Object.getOwnPropertySymbols&&!i(function(){var i=Symbol("symbol detection");return!n(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&t&&t<41})}function zt(){if(yt)return wt;yt=1;var t=Bt();return wt=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function jt(){if(_t)return Et;_t=1;var t=Gt(),i=Lt(),n=function(){if(dt)return ht;dt=1;var t=xt();return ht=t({}.isPrototypeOf)}(),e=zt(),r=Object;return Et=e?function(t){return"symbol"==typeof t}:function(e){var s=t("Symbol");return i(s)&&n(s.prototype,r(e))}}function Ht(){if(bt)return It;bt=1;var t=String;return It=function(i){try{return t(i)}catch(t){return"Object"}}}function qt(){if(St)return Tt;St=1;var t=Lt(),i=Ht(),n=TypeError;return Tt=function(e){if(t(e))return e;throw new n(i(e)+" is not a function")}}function Kt(){if(Nt)return Ct;Nt=1;var t=qt(),i=Pt();return Ct=function(n,e){var r=n[e];return i(r)?void 0:t(r)}}function Wt(){if(Ot)return Dt;Ot=1;var t=z(),i=Lt(),n=Ft(),e=TypeError;return Dt=function(r,s){var o,u;if("string"===s&&i(o=r.toString)&&!n(u=t(o,r)))return u;if(i(o=r.valueOf)&&!n(u=t(o,r)))return u;if("string"!==s&&i(o=r.toString)&&!n(u=t(o,r)))return u;throw new e("Can't convert object to primitive value")}}var Xt,Yt,Jt,Qt,$t,Zt,ti,ii,ni,ei,ri,si,oi,ui,ai,ci,hi,di,fi,li,vi,mi,gi,pi,wi={exports:{}};function yi(){if(Qt)return Jt;Qt=1;var t=O(),i=Object.defineProperty;return Jt=function(n,e){try{i(t,n,{value:e,configurable:!0,writable:!0})}catch(i){t[n]=e}return e}}function Ei(){if($t)return wi.exports;$t=1;var t=Yt?Xt:(Yt=1,Xt=!1),i=O(),n=yi(),e="__core-js_shared__",r=wi.exports=i[e]||n(e,{});return(r.versions||(r.versions=[])).push({version:"3.50.0",mode:t?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.50.0/LICENSE",source:"https://github.com/zloirock/core-js"}),wi.exports}function _i(){if(ti)return Zt;ti=1;var t=Ei(),i=Object.create||Object;return Zt=function(n,e){return t[n]||(t[n]=e||i(null))}}function Ii(){if(ni)return ii;ni=1;var t=Mt(),i=Object;return ii=function(n){return i(t(n))}}function bi(){if(ri)return ei;ri=1;var t=xt(),i=Ii(),n=t({}.hasOwnProperty);return ei=Object.hasOwn||function(t,e){return n(i(t),e)}}function Ti(){if(oi)return si;oi=1;var t=xt(),i=0,n=Math.random(),e=t(1.1.toString);return si=function(t){return"Symbol("+(void 0===t?"":t)+")_"+e(++i+n,36)}}function Si(){if(ai)return ui;ai=1;var t=O(),i=_i(),n=bi(),e=Ti(),r=Bt(),s=zt(),o=t.Symbol,u=i("wks"),a=s?o.for||o:o&&o.withoutSetter||e;return ui=function(t){return n(u,t)||(u[t]=r&&n(o,t)?o[t]:a("Symbol."+t)),u[t]}}function Ci(){if(hi)return ci;hi=1;var t=z(),i=Ft(),n=jt(),e=Kt(),r=Wt(),s=Si(),o=TypeError,u=s("toPrimitive");return ci=function(s,a){if(!i(s)||n(s))return s;var c,h=e(s,u);if(h){if(void 0===a&&(a="default"),c=t(h,s,a),!i(c)||n(c))return c;throw new o("Can't convert object to primitive value")}return void 0===a&&(a="number"),r(s,a)}}function Ni(){if(fi)return di;fi=1;var t=Ci(),i=jt();return di=function(n){var e=t(n,"string");return i(e)?e:e+""}}function Di(){if(vi)return li;vi=1;var t=O(),i=Ft(),n=t.document,e=i(n)&&i(n.createElement);return li=function(t){return e?n.createElement(t):{}}}function Oi(){if(gi)return mi;gi=1;var t=V(),i=G(),n=Di();return mi=!t&&!i(function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a})}function ki(){if(pi)return F;pi=1;var t=V(),i=z(),n=function(){if(j)return kt;j=1;var t={}.propertyIsEnumerable,i=Object.getOwnPropertyDescriptor,n=i&&!t.call({1:2},1);return kt.f=n?function(t){var n=i(this,t);return!!n&&n.enumerable}:t,kt}(),e=At(),r=Ut(),s=Ni(),o=bi(),u=Oi(),a=Object.getOwnPropertyDescriptor;return F.f=t?a:function(t,c){if(t=r(t),c=s(c),u)try{return a(t,c)}catch(t){}if(o(t,c))return e(!i(n.f,t,c),t[c])},F}var Ai,xi,Ri,Pi,Mi,Ui,Li,Fi={};function Gi(){if(xi)return Ai;xi=1;var t=V(),i=G();return Ai=t&&i(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})}function Vi(){if(Pi)return Ri;Pi=1;var t=Ft(),i=String,n=TypeError;return Ri=function(e){if(t(e))return e;throw new n(i(e)+" is not an object")}}function Bi(){if(Mi)return Fi;Mi=1;var t=V(),i=Oi(),n=Gi(),e=Vi(),r=Ni(),s=TypeError,o=Object.defineProperty,u=Object.getOwnPropertyDescriptor,a="enumerable",c="configurable",h="writable";return Fi.f=t?n?function(t,i,n){if(e(t),i=r(i),e(n),"function"==typeof t&&"prototype"===i&&"value"in n&&h in n&&!n[h]){var s=u(t,i);s&&s[h]&&(t[i]=n.value,n={configurable:c in n?n[c]:s[c],enumerable:a in n?n[a]:s[a],writable:!1})}return o(t,i,n)}:o:function(t,n,u){if(e(t),n=r(n),e(u),i)try{return o(t,n,u)}catch(t){}if("get"in u||"set"in u)throw new s("Accessors not supported");return"value"in u&&(t[n]=u.value),t},Fi}function zi(){if(Li)return Ui;Li=1;var t=V(),i=Bi(),n=At();return Ui=t?function(t,e,r){return i.f(t,e,n(1,r))}:function(t,i,n){return t[i]=n,t}}var ji,Hi,qi,Ki,Wi,Xi,Yi,Ji,Qi,$i,Zi,tn,nn,en,rn,sn={exports:{}};function on(){if(Ki)return qi;Ki=1;var t=xt(),i=Lt(),n=Ei(),e=t(Function.toString);return i(n.inspectSource)||(n.inspectSource=function(t){return e(t)}),qi=n.inspectSource}function un(){if(Ji)return Yi;Ji=1;var t=_i(),i=Ti(),n=t("keys");return Yi=function(t){return n[t]||(n[t]=i(t))}}function an(){return $i?Qi:($i=1,Qi={})}function cn(){if(tn)return Zi;tn=1;var t,i,n,e=function(){if(Xi)return Wi;Xi=1;var t=O(),i=Lt(),n=t.WeakMap;return Wi=i(n)&&/native code/.test(String(n))}(),r=O(),s=Ft(),o=zi(),u=bi(),a=Ei(),c=un(),h=an(),d="Object already initialized",f=r.TypeError,l=r.WeakMap;if(e||a.state){var v=a.state||(a.state=new l);v.get=v.get,v.has=v.has,v.set=v.set,t=function(t,i){if(v.has(t))throw new f(d);return i.facade=t,v.set(t,i),i},i=function(t){return v.get(t)||{}},n=function(t){return v.has(t)}}else{var m=c("state");h[m]=!0,t=function(t,i){if(u(t,m))throw new f(d);return i.facade=t,o(t,m,i),i},i=function(t){return u(t,m)?t[m]:{}},n=function(t){return u(t,m)}}return Zi={set:t,get:i,has:n,enforce:function(e){return n(e)?i(e):t(e,{})},getterFor:function(t){return function(n){var e;if(!s(n)||(e=i(n)).type!==t)throw new f("Incompatible receiver, "+t+" required");return e}}}}function hn(){if(nn)return sn.exports;nn=1;var t=xt(),i=G(),n=Lt(),e=bi(),r=V(),s=function(){if(Hi)return ji;Hi=1;var t=V(),i=bi(),n=Function.prototype,e=t&&Object.getOwnPropertyDescriptor,r=i(n,"name"),s=r&&"something"===function(){}.name,o=r&&(!t||t&&e(n,"name").configurable);return ji={EXISTS:r,PROPER:s,CONFIGURABLE:o}}().CONFIGURABLE,o=on(),u=cn(),a=u.enforce,c=u.get,h=String,d=Object.defineProperty,f=t("".slice),l=t("".replace),v=t([].join),m=r&&!i(function(){return 8!==d(function(){},"length",{value:8}).length}),g=String(String).split("String"),p=sn.exports=function(t,i,n){"Symbol("===f(h(i),0,7)&&(i="["+l(h(i),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(i="get "+i),n&&n.setter&&(i="set "+i),(!e(t,"name")||s&&t.name!==i)&&(r?d(t,"name",{value:i,configurable:!0}):t.name=i),m&&n&&e(n,"arity")&&t.length!==n.arity&&d(t,"length",{value:n.arity});try{n&&e(n,"constructor")&&n.constructor?r&&d(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var o=a(t);return e(o,"source")||(o.source=v(g,"string"==typeof i?i:"")),t};return Function.prototype.toString=p(function(){return n(this)&&c(this).source||o(this)},"toString"),sn.exports}function dn(){if(rn)return en;rn=1;var t=Lt(),i=Bi(),n=hn(),e=yi();return en=function(r,s,o,u){u||(u={});var a=u.enumerable,c=void 0!==u.name?u.name:s;if(t(o)&&n(o,c,u),u.global)a?r[s]=o:e(s,o);else{try{u.unsafe?r[s]&&(a=!0):delete r[s]}catch(t){}a?r[s]=o:i.f(r,s,{value:o,enumerable:!1,configurable:!u.nonConfigurable,writable:!u.nonWritable})}return r}}var fn,ln,vn,mn,gn,pn,wn,yn,En,_n,In,bn,Tn,Sn,Cn,Nn,Dn,On={};function kn(){if(mn)return vn;mn=1;var t=function(){if(ln)return fn;ln=1;var t=Math.ceil,i=Math.floor;return fn=Math.trunc||function(n){var e=+n;return(e>0?i:t)(e)}}();return vn=function(i){var n=+i;return n!=n||0===n?0:t(n)}}function An(){if(pn)return gn;pn=1;var t=kn(),i=Math.max,n=Math.min;return gn=function(e,r){var s=t(e);return s<0?i(s+r,0):n(s,r)}}function xn(){if(yn)return wn;yn=1;var t=kn(),i=Math.min;return wn=function(n){var e=t(n);return e>0?i(e,9007199254740991):0}}function Rn(){if(_n)return En;_n=1;var t=xn();return En=function(i){return t(i.length)}}function Pn(){if(bn)return In;bn=1;var t=Ut(),i=An(),n=Rn(),e=function(e){return function(r,s,o){var u=t(r),a=n(u);if(0===a)return!e&&-1;var c,h=i(o,a);if(e&&s!=s){for(;a>h;)if((c=u[h++])!=c)return!0}else for(;a>h;h++)if((e||h in u)&&u[h]===s)return e||h||0;return!e&&-1}};return In={includes:e(!0),indexOf:e(!1)}}function Mn(){if(Sn)return Tn;Sn=1;var t=xt(),i=bi(),n=Ut(),e=Pn().indexOf,r=an(),s=t([].push);return Tn=function(t,o){var u,a=n(t),c=0,h=[];for(u in a)!i(r,u)&&i(a,u)&&s(h,u);for(;o.length>c;)i(a,u=o[c++])&&(~e(h,u)||s(h,u));return h}}function Un(){return Nn?Cn:(Nn=1,Cn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}var Ln,Fn,Gn,Vn,Bn,zn,jn,Hn,qn,Kn={};function Wn(){if(Gn)return Fn;Gn=1;var t=Gt(),i=xt(),n=function(){if(Dn)return On;Dn=1;var t=Mn(),i=Un().concat("length","prototype");return On.f=Object.getOwnPropertyNames||function(n){return t(n,i)},On}(),e=(Ln||(Ln=1,Kn.f=Object.getOwnPropertySymbols),Kn),r=Vi(),s=i([].concat);return Fn=t("Reflect","ownKeys")||function(t){var i=n.f(r(t)),o=e.f;return o?s(i,o(t)):i}}function Xn(){if(Bn)return Vn;Bn=1;var t=bi(),i=Wn(),n=ki(),e=Bi();return Vn=function(r,s,o){for(var u=i(s),a=e.f,c=n.f,h=0;h<u.length;h++){var d=u[h];t(r,d)||o&&t(o,d)||a(r,d,c(s,d))}}}function Yn(){if(qn)return Hn;qn=1;var t=O(),i=ki().f,n=zi(),e=dn(),r=yi(),s=Xn(),o=function(){if(jn)return zn;jn=1;var t=G(),i=Lt(),n=/#|\.prototype\./,e=function(n,e){var a=s[r(n)];return a===u||a!==o&&(i(e)?t(e):!!e)},r=e.normalize=function(t){return String(t).replace(n,".").toLowerCase()},s=e.data={},o=e.NATIVE="N",u=e.POLYFILL="P";return zn=e}();return Hn=function(u,a){var c,h,d,f,l,v=u.target,m=u.global,g=u.stat;if(c=m?t:g?t[v]||r(v,{}):t[v]&&t[v].prototype)for(h in a){if(f=a[h],d=u.dontCallGetSet?(l=i(c,h))&&l.value:c[h],!o(m?h:v+(g?".":"#")+h,u.forced)&&void 0!==d){if(typeof f==typeof d)continue;s(f,d)}(u.sham||d&&d.sham)&&n(f,"sham",!0),e(c,h,f,u)}}}var Jn,Qn,$n,Zn,te,ie,ne,ee,re,se,oe={};function ue(){if(Qn)return Jn;Qn=1;var t=Mn(),i=Un();return Jn=Object.keys||function(n){return t(n,i)}}function ae(){if(te)return Zn;te=1;var t=Gt();return Zn=t("document","documentElement")}function ce(){if(ne)return ie;ne=1;var t,i=Vi(),n=function(){if($n)return oe;$n=1;var t=V(),i=Gi(),n=Bi(),e=Vi(),r=Ut(),s=ue();return oe.f=t&&!i?Object.defineProperties:function(t,i){e(t);for(var o,u=r(i),a=s(i),c=a.length,h=0;c>h;)n.f(t,o=a[h++],u[o]);return t},oe}(),e=Un(),r=an(),s=ae(),o=Di(),u=un(),a="prototype",c="script",h=u("IE_PROTO"),d=function(){},f=function(t){return"<"+c+">"+t+"</"+c+">"},l=function(t){t.write(f("")),t.close();var i=t.parentWindow.Object;return t=null,i},v=function(){try{t=new ActiveXObject("htmlfile")}catch(t){}var i,n,r;v="undefined"!=typeof document?document.domain&&t?l(t):(n=o("iframe"),r="java"+c+":",n.style.display="none",s.appendChild(n),n.src=String(r),(i=n.contentWindow.document).open(),i.write(f("document.F=Object")),i.close(),i.F):l(t);for(var u=e.length;u--;)delete v[a][e[u]];return v()};return r[h]=!0,ie=Object.create||function(t,e){var r;return null!==t?(d[a]=i(t),r=new d,d[a]=null,r[h]=t):r=v(),void 0===e?r:n.f(r,e)}}function he(){if(re)return ee;re=1;var t=Si(),i=ce(),n=Bi().f,e=t("unscopables"),r=Array.prototype;return void 0===r[e]&&n(r,e,{configurable:!0,value:i(null)}),ee=function(t){r[e][t]=!0}}!function(){if(se)return D;se=1;var t=Yn(),i=Pn().includes,n=G(),e=he(),r=n(function(){return!Array(1).includes()}),s=n(function(){return[,1].includes(void 0,1)});t({target:"Array",proto:!0,forced:r||s},{includes:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}}),e("includes")}();var de=function(t,i){return de=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])},de(t,i)};function fe(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}de(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var le=function(){return le=Object.assign||function(t){for(var i,n=1,e=arguments.length;n<e;n++)for(var r in i=arguments[n])Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r]);return t},le.apply(this,arguments)};function ve(t,i,n,e){return new(n||(n=Promise))(function(r,s){function o(t){try{a(e.next(t))}catch(t){s(t)}}function u(t){try{a(e.throw(t))}catch(t){s(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n(function(t){t(i)})).then(o,u)}a((e=e.apply(t,i||[])).next())})}function me(t,i){var n,e,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=u(0),o.throw=u(1),o.return=u(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(a){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(n=1,e&&(r=2&u[0]?e.return:u[0]?e.throw||((r=e.return)&&r.call(e),0):e.next)&&!(r=r.call(e,u[1])).done)return r;switch(e=0,r&&(u=[2&u[0],r.value]),u[0]){case 0:case 1:r=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,e=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!r||u[1]>r[0]&&u[1]<r[3])){s.label=u[1];break}if(6===u[0]&&s.label<r[1]){s.label=r[1],r=u;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(u);break}r[2]&&s.ops.pop(),s.trys.pop();continue}u=i.call(t,s)}catch(t){u=[6,t],e=0}finally{n=r=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}function ge(t){var i="function"==typeof Symbol&&Symbol.iterator,n=i&&t[i],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}function pe(t,i){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var e,r,s=n.call(t),o=[];try{for(;(void 0===i||i-- >0)&&!(e=s.next()).done;)o.push(e.value)}catch(t){r={error:t}}finally{try{e&&!e.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return o}function we(t,i,n){if(n||2===arguments.length)for(var e,r=0,s=i.length;r<s;r++)!e&&r in i||(e||(e=Array.prototype.slice.call(i,0,r)),e[r]=i[r]);return t.concat(e||Array.prototype.slice.call(i))}"function"==typeof SuppressedError&&SuppressedError;var ye="/api/v1/web/events",Ee="/api/v1/web/userEvents",_e="/sdk/v2/config",Ie="/sdk/v2/visitors",be="/sdk/v2/visitors",Te="/sdk/v2/visitors/merge",Se="/api/v1/websdk/dlr",Ce=18e5,Ne={STATUSES:{PENDING:"pending"},BATCH_SIZE:50,DEFAULT_RETRY_DELAYS:[6e4,12e4,24e4,48e4,9e5],RETRYABLE_HTTP_CODES:[408,429,500,502,503,504,401],GLOBAL_SUCCESS_CODE:202,PARTIAL_SUCCESS_CODE:201,DLR_SUCCESS_CODE:200},De="/firebase-messaging-sw.js",Oe={USER_CONTEXT:"websdk_user_context",VISITOR_ID:"websdk_visitor_id",VISITOR_EXTERNAL_ID:"websdk_visitor_external_id",VISITOR_EXPIRED_AT:"websdk_visitor_expired_at",VISITOR_CONFIG:"websdk_visitor_config",FCM_TOKEN:"websdk_fcm_token",FCM_TOKEN_CREATED_AT:"websdk_fcm_token_created_at",NOTIFICATION_STATE:"websdk_notification_state",SESSION_ID:"websdk_session_id",SESSION_START_TIME:"websdk_session_start_time",LAST_EVENT_TIME:"websdk_last_event_time",LAST_AUTHENTICATED_USER:"websdk_last_authenticated_user",MERGED_USER_ID:"websdk_merged_user_id",PENDING_MERGE:"websdk_pending_merge",SESSION_NUMBER:"websdk_session_number"};function ke(t,i,n){var e=Oe[t],r=[];return i&&r.push(i),n&&r.push(n),r.length>0?"".concat(r.join("_"),"_").concat(e):e}var Ae="websdk_storage_test",xe="test_value",Re={REQUEST_TIMEOUT_MS:15e3,SENSITIVE_LOG_KEYS:["writeKey","token","accessToken","refreshToken","password"]},Pe="INIT_ERROR",Me="AUTH_ERROR",Ue="NETWORK_ERROR",Le="EVENT_ERROR",Fe="VISITOR_CONFIG_ERROR",Ge="WebSDK initialized successfully",Ve="Failed to initialize WebSDK",Be="WebSDK destroyed successfully",ze="Failed to destroy WebSDK",je="Storage initialization failed",He="Failed to restore persisted page-path-tracking preference",qe="Failed to restore persisted gamification-suppression preference",Ke="Failed to restore persisted gamification theme",We="Session initialization failed",Xe="Visitor config initialization failed",Ye="Event tracker initialization failed",Je="Failed to restore user context",Qe="Failed to sync event tracker context",$e="DLR setup failed",Ze="EventQueue initialized successfully",tr="EventTracker initialized successfully",ir="EventTracker destroyed successfully",nr="Event added to queue",er="Failed to track event",rr="Events sent successfully",sr="Failed to send events",or="User event sent successfully",ur="Failed to send user event",ar="Failed to send batch",cr="Starting queue processing",hr="Queue processing completed",dr="Queue processing failed",fr="Queue processing already in progress, skipping",lr="No pending events to process",vr="No more pending events",mr="Failed to mark event as processing",gr="Failed to remove events from storage",pr="Failed to initialize storage:",wr="Storage test failed:",yr="Storage read/write test failed",Er="StorageManager destroyed successfully",_r="Error during storage cleanup:",Ir="New session started",br="Session continued",Tr="Session expired due to inactivity",Sr="Session ended on user switch (different user login)",Cr="Session ended on signout",Nr="Session restored from storage",Dr="Failed to track user signin event",Or="Failed to track user signup event",kr="Failed to track user update event",Ar="Failed to track user signout event",xr="Failed to track behavioral event",Rr="VisitorConfigManager initialized successfully",Pr="Visitor config fetched successfully",Mr="Failed to fetch visitor config",Ur="Visitor tracking is disabled",Lr="Visitor tracking is enabled",Fr="Visitor config retrieved from cache",Gr="AnonymousVisitorManager initialized successfully",Vr="Visitor ID generated successfully",Br="Failed to generate visitor ID",zr="Visitor ID restored from storage",jr="Using cached visitor ID",Hr="Visitor updated successfully",qr="Failed to update visitor",Kr="Visitor merged with user successfully",Wr="Failed to merge visitor with user",Xr="Visitor merge skipped",Yr="Notification permission denied by user",Jr="Notification manager initialized successfully",Qr="Failed to initialize notification manager",$r="Notification initialization skipped (disabled or not supported)",Zr="Firebase initialized successfully",ts="Failed to initialize Firebase",is="FCM token received successfully",ns="FCM token refreshed",es="Failed to retrieve FCM token",rs="Service worker registered successfully",ss="Failed to register service worker",os="Service worker not supported in this browser",us="FirebaseManager already initialized",as="FirebaseManager not initialized",cs="No service worker found in registration",hs="Service worker registration required for FCM - no token obtained",ds="getToken() returned no token despite notifications being enabled - permission may have been revoked externally, VAPID key may be invalid, or this may be transient",fs="Failed to setup message listener",ls="FCM message payload has neither notification nor data",vs="onMessageReceived callback threw",ms="Notifications not supported in this browser",gs="Firebase Messaging instance not provided - notifications disabled",ps="Failed to restore notification state",ws="Failed to save notification state",ys="Failed to initialize Firebase for messaging",Es="Failed to store FCM token",_s="Failed to retrieve FCM token creation date",Is="Cannot refresh token - notifications not enabled",bs="Failed to refresh FCM token",Ts="Failed to clear notification state",Ss="Permission revoked - clearing FCM token",Cs="Failed to destroy NotificationManager",Ns="DLR events sent successfully",Ds="Failed to send DLR events",Os="web",ks="user_signin",As="user_update",xs="user_signout",Rs="scroll_depth",Ps=[25,50,75,90],Ms=30,Us=3e3,Ls={WEBPUSH:"WEBPUSH"},Fs={WEB:"web"},Gs={ACCOUNT_NOT_EXISTS:2432,ACCOUNT_ID_NOT_PASSED:9999},Vs={ALREADY_MERGED:"1429",VISITOR_NOT_FOUND:"1428"},Bs={NOTIFICATION_RECEIVED:"push_notification_received",NOTIFICATION_CLICKED:"push_notification_click",NOTIFICATION_DISMISSED:"push_notification_close"},zs="fcm",js="push",Hs="1.10.6",qs="GamificationManager initialized successfully",Ks="Failed to initialize GamificationManager",Ws="GamificationManager destroyed successfully",Xs="GamificationManager state cleared",Ys="Gamification disabled — gamificationWriteKey not configured",Js="GamificationManager refresh triggered",Qs="GamificationManager data resync triggered",$s="GamificationManager data resync failed",Zs="GamificationManager loaded from cache — API call skipped",to="GamificationManager cache miss — fetching from API",io="GamificationManager reused cached token — token API call skipped",no="GamificationManager token cache miss — fetching new token",eo="GamificationManager got an auth error on campaigns/entry points — invalidating cached token and retrying once",ro="GamificationManager token refetch is in backoff after repeated failures — skipping network call",so="GamificationManager token refetch failed, entering backoff",oo="GamificationManager failed to handle an ACTION_EVENT trigger",uo="Failed to persist gamification-suppression preference",ao="Content-initiated open skipped — gamification is suppressed",co="Failed to persist gamification theme preference",ho="Failed to read session-dismissal record",fo="Failed to persist session-dismissal record",lo="Failed to persist pending ACTION_EVENT queue",vo="Failed to restore pending ACTION_EVENT queue",mo="Entry point with unresolvable _id present in entryPointMap",go="Failed to construct entry point instance",po="Expected a string field in analytics payload",wo="Failed to persist gamification token cache",yo="Gamification token cache miss: failed to read/parse cached entry",Eo="Gamification cache miss: no cached entry",_o="Gamification cache miss: entry expired",Io="Gamification cache miss: failed to read/parse cached entry",bo="Failed to persist gamification cache",To="Failed to read entry point count state",So="Failed to persist entry point count state",Co="Failed to reconcile stale entry point state against refreshed server config",No="GAME_PLAYED",Do="CAMPAIGN_PLAY",Oo="NO_GAME_CONFIGURED",ko="game_open",Ao="game_viewed",xo="game_played",Ro="game_completed",Po="reward_seen",Mo="content_open",Uo="content_viewed",Lo="LOYALTY",Fo="COMPLETED",Go="ACTION_EVENT",Vo=3e5,Bo=18e5,zo="__GLU__CACHE__",jo="__GLU__TOKEN__",Ho="__GLU__COUNT_DATE_",qo="__GLU__QUEUE__",Ko="__GLU__SESSION_DISMISSED_",Wo=16,Xo={LOGGED_IN:"loggedIn"},Yo={EVENT_NAME:"event_name",REWARD_TYPE:"reward_type",CAMPAIGN_ID:"campaign_id",CAMPAIGN_DETAILS:"campaign_details",REWARD_STATUS:"reward_status",REWARD_USER_ID:"reward_user_id"},Jo=1e3,Qo=16e3,$o=2e3,Zo=3e5,tu="glu_cap_token",iu="glu_page_path_tracking_enabled",nu="glu_gamification_suppressed",eu="glu_gamification_theme",ru="/preload/",su=5e3,ou="__GLU__ORIGIN__",uu=new Set(Re.SENSITIVE_LOG_KEYS.map(function(t){return t.toLowerCase()}));function au(t){return Array.isArray(t)?t.map(au):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).map(function(t){var i=pe(t,2),n=i[0],e=i[1];return[n,uu.has(n.toLowerCase())?"[REDACTED]":au(e)]})):t}var cu=function(){function t(t,i){this.baseUrl=t.baseUrl.replace(/\/$/,""),this.logger=i}return t.prototype.request=function(t){return ve(this,arguments,void 0,function(t,i){var n,e,r,s,o,u,a,c,h,d,f,l,v,m,g,p,w;return void 0===i&&(i={}),me(this,function(y){switch(y.label){case 0:n=i.method,e=void 0===n?"GET":n,r=i.headers,s=void 0===r?{}:r,o=i.body,u=!t||t.startsWith("/")?t:"/".concat(t),a="".concat(this.baseUrl).concat(u),c=Date.now(),h=!1,d=au(o),this.logger.debug("HTTP request started",{method:e,url:a,requestBody:d}),f=new AbortController,l=setTimeout(function(){return f.abort()},Re.REQUEST_TIMEOUT_MS),y.label=1;case 1:return y.trys.push([1,6,7,8]),v={method:e,headers:le({"Content-Type":"application/json"},s),body:o?JSON.stringify(o):null,signal:f.signal},[4,fetch(a,v)];case 2:return(m=y.sent()).ok?[3,4]:[4,m.text()];case 3:throw g=y.sent(),h=!0,this.logger.error("HTTP request failed",{method:e,url:a,status:m.status,durationMs:Date.now()-c,requestBody:d,responseBody:g}),new Error("HTTP ".concat(m.status,": ").concat(m.statusText," - ").concat(g));case 4:return[4,m.json()];case 5:return p=y.sent(),this.logger.debug("HTTP request succeeded",{method:e,url:a,status:m.status,durationMs:Date.now()-c,requestBody:d,responseBody:au(p)}),[2,p];case 6:throw w=y.sent(),h||this.logger.error("HTTP request failed",{method:e,url:a,durationMs:Date.now()-c,requestBody:d,error:w}),this.handleError(w);case 7:return clearTimeout(l),[7];case 8:return[2]}})})},t.prototype.handleError=function(t){return t instanceof Error?"AbortError"===t.name?{code:Ue,message:"Request timeout",details:t}:t.message.includes("HTTP 401")||t.message.includes("HTTP 403")?{code:Me,message:"Authentication failed",details:t}:(t.message.includes("HTTP"),{code:Ue,message:t.message,details:t}):{code:Ue,message:"Unknown error: ".concat(String(t)),details:t}},t.prototype.get=function(t){return ve(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),me(this,function(n){return[2,this.request(t,le(le({},i),{method:"GET"}))]})})},t.prototype.post=function(t,i){return ve(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),me(this,function(e){return[2,this.request(t,le(le({},n),{method:"POST",body:i}))]})})},t.prototype.put=function(t,i){return ve(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),me(this,function(e){return[2,this.request(t,le(le({},n),{method:"PUT",body:i}))]})})},t.prototype.delete=function(t){return ve(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),me(this,function(n){return[2,this.request(t,le(le({},i),{method:"DELETE"}))]})})},t}(),hu="/user/v1/user/sdk",du="/reward/v1.1/user",fu="/entrypoints/v1/list",lu=function(){function t(t,i){this.http=new cu({baseUrl:t},i),this.logger=i}return t.prototype.getToken=function(t,i,n,e,r){return ve(this,void 0,void 0,function(){var s,o=this;return me(this,function(u){return s=le(le(le(le(le(le({writeKey:t,userId:i,userState:n,appType:"WEB",sdkVersion:Hs},e&&{anonymousId:e}),(null==r?void 0:r.name)&&{name:r.name}),(null==r?void 0:r.email)&&{email:r.email}),(null==r?void 0:r.mobile)&&{mobile:r.mobile}),(null==r?void 0:r.country)&&{country:r.country}),(null==r?void 0:r.customAttributes)&&{customAttributes:r.customAttributes}),this.logger.info("Fetching gamification token",{userId:i,userState:n}),[2,this.withRetry(function(){return ve(o,void 0,void 0,function(){var t;return me(this,function(e){switch(e.label){case 0:return[4,this.http.post("".concat(hu,"?token=true"),s)];case 1:return t=e.sent(),this.logger.info("Gamification token fetched successfully",{userId:i,userState:n}),[2,t.data.token]}})})},"getToken")]})})},t.prototype.getCampaigns=function(t){return ve(this,void 0,void 0,function(){var i=this;return me(this,function(n){return this.logger.info("Fetching gamification campaigns"),[2,this.withRetry(function(){return ve(i,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return[4,this.http.get(du,{headers:{Authorization:"Bearer ".concat(t)}})];case 1:return i=e.sent(),n=this.normalizeCampaigns(i),this.logger.info("Gamification campaigns fetched successfully",{campaignCount:n.allIds.length,loyaltyUrlCount:n.loyaltyUrls.length}),[2,n]}})})},"getCampaigns")]})})},t.prototype.getEntryPoints=function(t){return ve(this,void 0,void 0,function(){var i=this;return me(this,function(n){return this.logger.info("Fetching gamification entry points"),[2,this.withRetry(function(){return ve(i,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return[4,this.http.get("".concat(fu,"?consumer=WEB"),{headers:{Authorization:"Bearer ".concat(t)}})];case 1:return i=n.sent(),this.logger.info("Gamification entry points fetched successfully",{entryPointCount:i.data.length}),[2,i.data]}})})},"getEntryPoints")]})})},t.prototype.normalizeCampaigns=function(t){var i,n,e,r=[],s={};0===t.campaigns.length&&this.logger.warn("Campaigns response returned zero campaigns",{defaultUrl:t.defaultUrl});try{for(var o=ge(t.campaigns),u=o.next();!u.done;u=o.next()){var a=u.value;r.push(a.campaignId),s[a.campaignId]=a}}catch(t){i={error:t}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return{allIds:r,byId:s,defaultUrl:t.defaultUrl,base:this.extractBase(t.defaultUrl),loyaltyUrls:null!==(e=t.loyaltyUrls)&&void 0!==e?e:[]}},t.prototype.extractBase=function(t){try{var i=new URL(t);return"".concat(i.protocol,"//").concat(i.host)}catch(i){return this.logger.error("Failed to parse defaultUrl from campaigns response",{url:t,error:i}),""}},t.prototype.isAuthError=function(t){return"object"==typeof t&&null!==t&&t.code===Me},t.prototype.withRetry=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:e=function(e){var s,o,u;return me(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,5]),s={},[4,t()];case 1:return[2,(s.value=a.sent(),s)];case 2:if(o=a.sent(),n=o,r.logger.error("GamificationManager API call failed: ".concat(i),{attempt:e,maxRetries:5,error:o}),r.isAuthError(o))throw o;return e<5?(u=Math.min(Jo*Math.pow(2,e-1),Qo),[4,new Promise(function(t){return setTimeout(t,u)})]):[3,4];case 3:a.sent(),a.label=4;case 4:return[3,5];case 5:return[2]}})},r=this,s=1,u.label=1;case 1:return s<=5?[5,e(s)]:[3,4];case 2:if("object"==typeof(o=u.sent()))return[2,o.value];u.label=3;case 3:return s++,[3,1];case 4:throw n}})})},t}(),vu={EMBEDDED:"EMBED",POP_UP:"POP_UP",BOTTOM_SHEET:"BOTTOM_SHEET",ICON_BUTTON:"FLOATING",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"BANNER"};function mu(t){var i,n=(i=t.container.typeId,vu[i]);return"EMBED"===n&&"STATIC"===t.content.typeId?"BANNER":n}function gu(t){return"CAMPAIGN"===t.typeId||"NUDGE"===t.typeId&&!!t.campaignId}function pu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId?"content":gu(t.content)?"game":"ICON_BUTTON"===t.container.typeId?"content":null}function wu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId}function yu(t){return t.toFixed(2)}function Eu(t){var i,n;return null!==(n=null!==(i=null==t?void 0:t.data)&&void 0!==i?i:t)&&void 0!==n?n:{}}function _u(t){var i=null==t?void 0:t.campaignId;if("string"==typeof i)return i;if(Array.isArray(i)){var n=i[0];if("string"==typeof n)return n}return null}function Iu(t){return t.triggerType===Go}var bu=new Set(["EMBEDDED","NATIVE_BANNER"]);function Tu(t){var i;if(!Iu(t))return null;if(bu.has(t.container.typeId))return null;var n=null===(i=t.actionEventConfig)||void 0===i?void 0:i.eventName;return"string"==typeof n&&""!==n.trim()?n:null}var Su=new Set(["POP_UP","BOTTOM_SHEET","CHAT_BOX"]);function Cu(t){return Su.has(t.container.typeId)}var Nu=new Set(["http:","https:"]);function Du(t){if(!t||"undefined"==typeof window)return!1;try{return Nu.has(new URL(t,window.location.href).protocol)}catch(t){return!1}}function Ou(t){var i,n,e=t.content;if("CAMPAIGN"===e.typeId)return null!==(i=e.campaignId)&&void 0!==i?i:_u(e.conditions);if("NUDGE"===e.typeId||"PROGRAM"===e.typeId)return null!==(n=e.campaignId)&&void 0!==n?n:null;if("STATIC"===e.typeId&&e.action){var r=e.action;if("TOGGLE_CONTAINER_CONTENT"===r.type||"OPEN_CONTAINER_CONTENT"===r.type)return _u(r.content.conditions)}return null}var ku={LAUNCHER_ICON:"ICON_BUTTON",BOTTOM_SHEET:"BOTTOM_SHEET",POP_UP:"POP_UP",EMBEDDED:"EMBEDDED",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"NATIVE_BANNER"};function Au(t){var i,n;if("string"==typeof t.m&&t.m.length>0)return t.m;try{for(var e=ge(Object.entries(t)),r=e.next();!r.done;r=e.next()){var s=pe(r.value,2),o=s[0],u=s[1];if("_id"===o&&"string"==typeof u&&u.length>0)return u}}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=e.return)&&n.call(e)}finally{if(i)throw i.error}}}function xu(t,i){var n;return le(le(le(le(le(le(le(le(le(le({typeId:null!==(n=null==t?void 0:t.typeId)&&void 0!==n?n:""},void 0!==i&&{campaignId:i}),void 0!==(null==t?void 0:t.src)&&{src:t.src}),void 0!==(null==t?void 0:t.state)&&{state:t.state}),void 0!==(null==t?void 0:t.action)&&{action:t.action}),void 0!==(null==t?void 0:t.conditions)&&{conditions:t.conditions}),void 0!==(null==t?void 0:t.IWidgetState)&&{IWidgetState:t.IWidgetState}),void 0!==(null==t?void 0:t.widgetCss)&&{widgetCss:t.widgetCss}),void 0!==(null==t?void 0:t.progressBarIcon)&&{progressBarIcon:t.progressBarIcon}),void 0!==(null==t?void 0:t.progressMeterIcon)&&{progressMeterIcon:t.progressMeterIcon}),void 0!==(null==t?void 0:t.rootId)&&{rootId:t.rootId})}function Ru(t){var i,n,e,r,s=t.web,o=s.container,u=s.content,a=s.conditions,c=u[0],h=null==a?void 0:a.backgroundOpacity,d=null!=h?o.css.replace("{{backgroundOpacity}}",String(h)):o.css,f=null!==(n=null!==(i=null==c?void 0:c.campaignId)&&void 0!==i?i:_u(null==c?void 0:c.conditions))&&void 0!==n?n:void 0;return le(le(le(le(le(le({id:null!==(e=Au(t))&&void 0!==e?e:""},void 0!==t.name&&{name:t.name}),{container:{typeId:null!==(r=ku[o.typeId])&&void 0!==r?r:o.typeId,css:d,height:o.height,elementHookId:o.elementId},content:xu(c,f)}),void 0!==a&&{conditions:a}),void 0!==t.triggerType&&{triggerType:t.triggerType}),void 0!==t.actionEventConfig&&{actionEventConfig:t.actionEventConfig}),void 0!==t.createdAt&&{createdAt:t.createdAt})}function Pu(t){var i,n,e=[],r={};try{for(var s=ge(t),o=s.next();!o.done;o=s.next()){var u=Ru(o.value);e.push(u.id),r[u.id]=u}}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return{allIds:e,byId:r}}var Mu="/*";function Uu(t){return t.startsWith("#/")||t.startsWith("#!/")}function Lu(t){try{return decodeURIComponent(t)}catch(i){return t}}function Fu(t){return t.replace(/(?:^\/+)|(?:\/+$)/g,"").split("/").filter(Boolean).map(Lu)}function Gu(t){try{return new URL(t)}catch(t){return null}}function Vu(t,i,n){for(var e=0;e<i.length;e++)if(t[n+e]!==i[e])return!1;return!0}function Bu(t,i){if(i.length>t.length)return-1;for(var n=0;n<=t.length-i.length;n++)if(Vu(t,i,n))return n;return-1}function zu(t,i){var n=i.endsWith(Mu),e=n?i.slice(0,-2):i;if(""===e)return!1;if("/"===e)return!n&&0===t.length;var r=Fu(e),s=Bu(t,r);return-1!==s&&(!n||s+r.length<t.length)}function ju(t,i){var n=function(t){var i=t.trim();if("*"===i||i===Mu)return"*";if(""===i)return"";var n=i.replace(/(?:^\/+)|(?:\/+$)/g,"");return""===n?"/":n}(i);if("*"===n)return!0;var e=t.indexOf("#"),r=-1===e?t:t.slice(0,e),s=-1===e?"":t.slice(e),o=r.replace(/\?.*$/,""),u=function(t){if(!t.startsWith("/"))return null;var i=t.lastIndexOf("/");if(i<=1)return null;var n=t.slice(1,i),e=t.slice(i+1);if(!/[*+?^${}()|[\]\\]/.test(n))return null;try{return new RegExp(n,e)}catch(t){return null}}(i.trim());if(u){var a=Uu(s)?o+s:o;return u.test(a)}var c=function(t,i){if(!/^https?:\/\//i.test(t))return null;var n=Gu(i);if(!n)return!1;var e=t.endsWith(Mu),r=Gu(e?t.slice(0,-2):t);if(!r)return!1;if(n.origin!==r.origin)return!1;if(!e)return n.pathname.replace(/\/+$/,"")===r.pathname.replace(/\/+$/,"");var s=Fu(n.pathname),o=Fu(r.pathname),u=Bu(s,o);return 0===u&&u+o.length<s.length}(n,o);if(null!==c)return c;var h=Gu(t);return!!zu(Fu(h?h.pathname:o),n)||!!Uu(s)&&zu(Fu(s.replace(/^#!?\//,"").replace(/\?.*$/,"")),n)}function Hu(t,i){var n,e;try{for(var r=ge(i),s=r.next();!s.done;s=r.next()){if(ju(t,s.value))return!0}}catch(t){n={error:t}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(n)throw n.error}}return!1}function qu(t,i){return"".concat(Ho).concat(null!=i?i:"anonymous","_").concat(t)}function Ku(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,n.get(qu(t,i))];case 1:return(r=u.sent())?(s=JSON.parse(r),[2,(a=s,"object"==typeof a&&null!==a&&"number"==typeof a.count&&"string"==typeof a.date?s:null)]):[2,null];case 2:return o=u.sent(),e.error(To,{entryPointId:t,error:o}),[2,null];case 3:return[2]}var a})})}function Wu(t,i){return t.getFullYear()===i.getFullYear()&&t.getMonth()===i.getMonth()&&t.getDate()===i.getDate()}function Xu(t,i){var n,e;if(!t)return!0;var r=null!==(n=t.excludePaths)&&void 0!==n?n:[],s=null!==(e=t.includePaths)&&void 0!==e?e:[];return(!r.length||!Hu(i,r))&&!(s.length&&!Hu(i,s))}function Yu(t,i,n,e,r){return!n||!Wu(e,new Date(n.date))||(!(n.count>=i)||(r.info("Rule engine: daily refresh cap exhausted",{entryPointId:t,count:n.count,cap:i}),!1))}function Ju(t,i,n,e){return!(n&&n.count>=i)||(e.info("Rule engine: lifetime cap exhausted",{entryPointId:t,count:n.count,cap:i}),!1)}function Qu(t,i,n,e,r){return ve(this,void 0,void 0,function(){var s,o,u,a,c,h,d,f,l,v,m;return me(this,function(g){switch(g.label){case 0:return null===(s=t.conditions)?(e.info("Rule engine: conditions explicitly null - never show",{entryPointId:t.id}),[2,!1]):s?(o=s.paths,u=s.showCount,a=s.timeWindow,c=s.isLoggedIn,h=s.backendValidations,d=new Date,f=null!=r?r:"undefined"!=typeof window?window.location.href:"",c&&!i?(e.info("Rule engine: requires login, no userId",{entryPointId:t.id}),[2,!1]):function(t,i){if(!t)return!0;var n=i.valueOf();return n>=new Date(t.start).valueOf()&&n<=new Date(t.end).valueOf()}(a,d)?Iu(t)||Xu(o,f)?"INVALID"===h?(e.info("Rule engine: backend validation invalid",{entryPointId:t.id}),[2,!1]):Iu(t)?(e.info("Rule engine: frequency cap skipped for ACTION_EVENT entry",{entryPointId:t.id}),[2,!0]):u?(l=u.count,v=u.dailyRefresh,[4,Ku(t.id,i,n,e)]):(e.info("Rule engine: no frequency cap configured - show",{entryPointId:t.id}),[2,!0]):(e.info("Rule engine: path not allowed",{entryPointId:t.id,currentHref:f,paths:o}),[2,!1]):(e.info("Rule engine: outside time window",{entryPointId:t.id,timeWindow:a}),[2,!1])):(e.info("Rule engine: no conditions - always show",{entryPointId:t.id}),[2,!0]);case 1:return m=g.sent(),[2,v?Yu(t.id,l,m,d,e):Ju(t.id,l,m,e)]}})})}var $u=function(){function t(){this.queue=[]}return t.prototype.enqueue=function(t){var i,n,e=function(t){var i=r.queue.findIndex(function(i){return i.id===t.id});-1===i?r.queue.push(t):r.queue[i]=t},r=this;try{for(var s=ge(t),o=s.next();!o.done;o=s.next()){e(o.value)}}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}this.queue.sort(function(t,i){var n,e,r,s,o,u,a=(null!==(e=null===(n=i.conditions)||void 0===n?void 0:n.priority)&&void 0!==e?e:0)-(null!==(s=null===(r=t.conditions)||void 0===r?void 0:r.priority)&&void 0!==s?s:0);return 0!==a?a:(null!==(o=i.createdAt)&&void 0!==o?o:"").localeCompare(null!==(u=t.createdAt)&&void 0!==u?u:"")})},t.prototype.peek=function(){return this.queue[0]},t.prototype.dequeue=function(){return this.queue.shift()},t.prototype.remove=function(t){this.queue=this.queue.filter(function(i){return i.id!==t})},t.prototype.hasNext=function(){return this.queue.length>0},t.prototype.clear=function(){this.queue=[]},t.prototype.clearScreenTriggered=function(){this.queue=this.queue.filter(function(t){return Iu(t)})},t.prototype.size=function(){return this.queue.length},t.prototype.entries=function(){return this.queue},t}(),Zu={iframe:{className:"__GLU__IFRAME",css:".__GLU__IFRAME{ height: 100%; width: 100%; border: none !important; outline: none; }"},hideScroll:{className:"__GLU_HIDE_SCROLL",css:".__GLU_HIDE_SCROLL::-moz-focus-inner {border: 0;} .__GLU_HIDE_SCROLL::-webkit-scrollbar {width: 0px !important;background: transparent !important;display: none !important;} .__GLU_HIDE_SCROLL {scrollbar-width: none !important;-ms-overflow-style: -ms-autohiding-scrollbar !important;}"},slideUp:{className:"__GLU__SLIDE_UP",css:".__GLU__SLIDE_UP { animation: GLU_SLIDE_UP 300ms ease-out; } @keyframes GLU_SLIDE_UP { from { opacity: 0; transform: translateY(100px); }to { opacity: 1; transform: translateY(0px); }}"},slideDown:{className:"__GLU__SLIDE_DOWN",css:".__GLU__SLIDE_DOWN { animation: GLU_SLIDE_DOWN 300ms ease-out; } @keyframes GLU_SLIDE_DOWN { from { opacity: 1; transform: translateY(0px); }to { opacity: 0; transform: translateY(100px); }}"},slideUpSheet:{className:"__GLU__SLIDE_UP_SHEET",css:".__GLU__SLIDE_UP_SHEET { animation: GLU_SLIDE_UP_SHEET 300ms ease-out; } @keyframes GLU_SLIDE_UP_SHEET { from { transform: translateY(100%); } to { transform: translateY(0px); }}"},slideDownSheet:{className:"__GLU__SLIDE_DOWN_SHEET",css:".__GLU__SLIDE_DOWN_SHEET { animation: GLU_SLIDE_DOWN_SHEET 300ms ease-out forwards; } @keyframes GLU_SLIDE_DOWN_SHEET { from { transform: translateY(0px); } to { transform: translateY(100%); }}"},iconButton:{className:"__GLU__ICON_BUTTON",css:".__GLU__ICON_BUTTON { position: fixed; bottom: 40px; left: 40px; height: 160px; width: 160px; overflow: hidden; z-index: 999;}"},chatBox:{className:"__GLU__CHAT_BOX",css:function(t){return".__GLU__CHAT_BOX { position: fixed; bottom: 130px; left: 40px; height: 580px; max-height: 580px; width: 360px; background-color: ".concat(t," !important; border-radius: 24px; overflow-x: hidden; z-index: 9999; }")}},popUp:{className:"__GLU__POP_UP",css:function(t){return".__GLU__POP_UP { position: relative; max-height: 740px; max-width: 1000px; width: 100%; height:90%; background-color: ".concat(t," !important; border-radius: 12px; z-index: 999999; overflow: hidden;}")}},popUpStatic:{className:"__GLU__POP_UP_STATIC",css:function(t){return".__GLU__POP_UP_STATIC { position: relative; max-height: 100%; max-width: 100%; background-color: ".concat(t," !important; border-radius: 12px; z-index: 999999; overflow: hidden;}")}},backDrop:{className:"__GLU__BACK_DROP",css:".__GLU__BACK_DROP { position: fixed; bottom: 0px; left: 0px; height: 100%; width: 100vw; background-color: rgba(0,0,0,0.2); display: flex; justify-content: center; align-items: center; z-index: 99999;}"},bottomSheet:{className:"__GLU__BOTTOM_SHEET",css:function(t){return".__GLU__BOTTOM_SHEET { position: relative; height: 880px; width: 600px; max-width: 100%; max-height: 100%; background-color: ".concat(t," !important; border-radius: 20px 20px 0px 0px; overflow-x: hidden; z-index: 999999; align-self: flex-end}")}},bottomSheetStatic:{className:"__GLU__BOTTOM_SHEET_STATIC",css:function(t){return".__GLU__BOTTOM_SHEET_STATIC { position: relative; max-width: 100%; max-height: 100%; background-color: ".concat(t," !important; border-radius: 20px 20px 0px 0px; overflow-x: hidden; z-index: 999999; align-self: flex-end}")}},embeddedStatic:{className:"__GLU__EMBEDDED_STATIC",css:".__GLU__EMBEDDED_STATIC { width: 100%; overflow-x: hidden; }"},embedded:{className:"__GLU__EMBEDDED",css:".__GLU__EMBEDDED { width: 100%; height: 100%; overflow-x: hidden; }"},loader:{className:"__GLU__LOADER",css:'.__GLU__LOADER { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 5; } .__GLU__LOADER::after { content: ""; width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgba(0,0,0,0.15); border-top-color: rgba(0,0,0,0.55); animation: GLU_SPIN 800ms linear infinite; } @keyframes GLU_SPIN { to { transform: rotate(360deg); } }'},closeIcon:{className:"__GLU__CLOSE_ICON",css:".__GLU__CLOSE_ICON { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; padding: 0; border: none; border-radius: 50%; background-color: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10; }"}};function ta(t){var i=t?"#1E1E1E":"#fff";return Object.values(Zu).map(function(t){return"function"==typeof t.css?t.css(i):t.css}).join("")}function ia(){if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();var t="undefined"!=typeof crypto?crypto:null;if(null==t?void 0:t.getRandomValues){var i=new Uint8Array(16);t.getRandomValues(i);var n=new DataView(i.buffer);return n.setUint8(6,15&n.getUint8(6)|64),n.setUint8(8,63&n.getUint8(8)|128),Array.from(i).map(function(t,i){return[4,6,8,10].includes(i)?"-".concat(t.toString(16).padStart(2,"0")):t.toString(16).padStart(2,"0")}).join("")}throw new Error("No cryptographically secure random number generator available")}function na(t,i){var n;if("undefined"!=typeof URLSearchParams)return new URLSearchParams(t).get(i);var e=new RegExp("[?&]"+i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"=([^&#]*)"),r=t.match(e);return r?decodeURIComponent(null!==(n=r[1])&&void 0!==n?n:""):null}function ea(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){return"UTC"}}function ra(t,i){var n,e={campaignName:na(n=window.location.search,"utm_campaign")||"",campaignSource:na(n,"utm_source")||"",campaignMedium:na(n,"utm_medium")||""};return{libraryName:"cap-hydra-web-sdk",libraryVersion:Hs,locale:navigator.language||navigator.languages&&navigator.languages[0]||"en-US",userAgent:navigator.userAgent||"",timezone:ea(),ip:"",campaignName:e.campaignName,campaignSource:e.campaignSource,campaignMedium:e.campaignMedium,pageUrl:window.location.href||"",pagePath:window.location.pathname||"",pageReferrer:document.referrer||"",pageTitle:document.title||"",sessionId:t,lat:i?String(i.latitude):"",long:i?String(i.longitude):""}}function sa(){try{var t=function(){var t,i;if("undefined"!=typeof navigator&&"userAgentData"in navigator){var n=navigator.userAgentData;if(n&&n.brands)try{for(var e=ge(n.brands),r=e.next();!r.done;r=e.next()){var s=r.value;if(s.brand&&"Chromium"!==s.brand&&!s.brand.startsWith("Not"))return s.brand}}catch(i){t={error:i}}finally{try{r&&!r.done&&(i=e.return)&&i.call(e)}finally{if(t)throw t.error}}}return null}();return t||("undefined"!=typeof navigator&&navigator.userAgent?(i=navigator.userAgent).includes("Firefox/")?"Firefox":i.includes("Edg/")?"Edge":i.includes("Chrome/")?"Chrome":i.includes("Safari/")&&!i.includes("Chrome")?"Safari":i.includes("Opera/")||i.includes("OPR/")?"Opera":null:null)}catch(t){return null}var i}function oa(){try{var t=function(){if("undefined"!=typeof navigator&&"userAgentData"in navigator){var t=navigator.userAgentData;if(t&&t.platform)return t.platform}return null}();return t||("undefined"!=typeof navigator&&navigator.userAgent?(i=navigator.userAgent,null!==(e=null!==(n=function(t){if(!t.includes("Mac OS X"))return null;var i=t.match(/Mac OS X ([\d_]+)/);return(null==i?void 0:i[1])?"macOS ".concat(i[1].replace(/_/g,".")):"macOS"}(i))&&void 0!==n?n:function(t){var i;if(!t.includes("Windows NT"))return null;var n=t.match(/Windows NT ([\d.]+)/);return(null==n?void 0:n[1])?"Windows ".concat(null!==(i={"10.0":"10/11",6.3:"8.1",6.2:"8",6.1:"7"}[n[1]])&&void 0!==i?i:n[1]):"Windows"}(i))&&void 0!==e?e:function(t){var i;return t.includes("iPhone")||t.includes("iPad")?(null==(i=t.match(/OS ([\d_]+)/))?void 0:i[1])?"iOS ".concat(i[1].replace(/_/g,".")):"iOS":t.includes("Android")?(i=t.match(/Android ([\d.]+)/))?"Android ".concat(i[1]):"Android":t.includes("Linux")?"Linux":null}(i)):null)}catch(n){return null}var i,n,e}function ua(){try{if("undefined"!=typeof document&&document.referrer)return function(t){var i;if("undefined"!=typeof URL)try{return new URL(t).hostname}catch(t){return"direct"}var n=t.match(/^https?:\/\/([^/?#]+)/);return n&&null!==(i=n[1])&&void 0!==i?i:"direct"}(document.referrer)}catch(t){}return"direct"}function aa(t){var i=sa(),n=oa(),e=function(){var t;try{if("undefined"!=typeof navigator)return navigator.language||(null===(t=navigator.languages)||void 0===t?void 0:t[0])||"en-US"}catch(t){}return"en-US"}(),r=function(){try{if("undefined"!=typeof Intl)return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(t){}return"UTC"}(),s=function(){try{if("undefined"!=typeof window&&window.screen)return"".concat(window.screen.width,"x").concat(window.screen.height)}catch(t){}return"0x0"}(),o=function(){try{if("undefined"!=typeof window&&window.location){var t=window.location.search;return{utmSource:na(t,"utm_source"),utmMedium:na(t,"utm_medium"),utmCampaign:na(t,"utm_campaign"),utmTerm:na(t,"utm_term"),utmContent:na(t,"utm_content"),adsId:na(t,"gclid")||na(t,"fbclid")||na(t,"msclkid")||na(t,"ttclid")}}}catch(t){}return{utmSource:null,utmMedium:null,utmCampaign:null,utmTerm:null,utmContent:null,adsId:null}}(),u=ua(),a={sdk_version:Hs,consent:(null==t?void 0:t.notificationPermissionGranted)?"yes":"no"};return function(t,i,n,e,r,s){i&&(t.browser=i),n&&(t.os_version=n),e&&"en-US"!==e&&(t.locale=e),r&&"UTC"!==r&&(t.timezone=r),s&&"0x0"!==s&&(t.screen_resolution=s)}(a,i,n,e,r,s),function(t,i,n,e){(null==i?void 0:i.appVersion)&&(t.app_version=i.appVersion),(null==i?void 0:i.fcmTokenCreatedAt)&&(t.token_creation_date=i.fcmTokenCreatedAt),n.utmSource&&(t.utm_source=n.utmSource),n.utmMedium&&(t.utm_medium=n.utmMedium),n.utmCampaign&&(t.utm_campaign=n.utmCampaign),n.utmTerm&&(t.utm_term=n.utmTerm),n.utmContent&&(t.utm_content=n.utmContent),n.adsId&&(t.ads_id=n.adsId),e&&"direct"!==e&&(t.initial_referrer=e)}(a,t,o,u),a}var ca=3e5,ha=null,da=0;function fa(){return ve(this,void 0,void 0,function(){return me(this,function(t){return null!==ha&&Date.now()-da<ca?[2,ha]:"undefined"!=typeof navigator&&navigator.geolocation?[2,new Promise(function(t){navigator.geolocation.getCurrentPosition(function(i){ha={latitude:i.coords.latitude,longitude:i.coords.longitude},da=Date.now(),t(ha)},function(){return t(null)},{maximumAge:ca,timeout:2e3,enableHighAccuracy:!1})})]:[2,null]})})}var la="__glu_container",va="__glu_backdrop";function ma(){return"__GLU__"+ia().replace(/-/g,"")}function ga(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function pa(t,i){var n=Math.max(0,Math.round(i)),e=parseInt(t.style.height,10)||0;Math.abs(e-n)<=1||(t.style.transition||(t.style.transition="height 300ms ease"),t.style.height="".concat(n,"px"))}var wa=function(){function t(t,i){var n;this.rootElement=null,this.closeListener=null,this.isShown=!1,this.supportsPreload=!0,this.preloaded=!1,this.preloadStyleSnapshot=null,this.boundListeners=[],this.customStyles=[],this.destroyed=!1,this.loaderElement=null,this.config=t,this.contentElement=i,this.mountDefaultStyleOnce(null!==(n=t.darkMode)&&void 0!==n&&n)}return t.prototype.isVisible=function(){var t,i;return this.isShown&&null!==(i=null===(t=this.rootElement)||void 0===t?void 0:t.isConnected)&&void 0!==i&&i},t.prototype.mountDefaultStyleOnce=function(i){if("undefined"!=typeof document){var n=document.getElementById(t.DEFAULT_STYLE_ID);if(n)n.dataset.gluDark!==String(i)&&(n.textContent=ta(i),n.dataset.gluDark=String(i));else{var e=this.mountStyle(ta(i));e&&(e.setAttribute("id",t.DEFAULT_STYLE_ID),e.dataset.gluDark=String(i))}}},t.prototype.bindEvent=function(t,i,n){t.addEventListener(i,n),this.boundListeners.push({target:t,type:i,handler:n})},t.prototype.mountStyle=function(t){if("undefined"==typeof document)return null;var i=document.createElement("style");return i.textContent=t,document.head.appendChild(i),i},t.prototype.addCustomStyle=function(t){if(this.config.css){var i=function(t,i){var n,e,r=t;try{for(var s=ge(Object.entries(i)),o=s.next();!o.done;o=s.next()){var u=pe(o.value,2),a=u[0],c=u[1];r.includes(a)&&(r=r.replace(new RegExp(ga(a),"g"),c))}}catch(t){n={error:t}}finally{try{o&&!o.done&&(e=s.return)&&e.call(s)}finally{if(n)throw n.error}}return r}(this.config.css,t),n=this.mountStyle(i);n&&this.customStyles.push(n)}},t.prototype.addCloseButton=function(t){var i=this;if("undefined"!=typeof document){var n=document.createElement("button");n.type="button",n.setAttribute("aria-label","Close"),n.classList.add(Zu.closeIcon.className),n.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L13 13M13 1L1 13" stroke="white" stroke-width="2" stroke-linecap="round"/></svg>',this.bindEvent(n,"click",function(t){var n;t.stopPropagation(),t.preventDefault(),null===(n=i.closeListener)||void 0===n||n.call(i)}),t.appendChild(n)}},t.prototype.preload=function(){var i,n;if(this.supportsPreload&&!this.preloaded&&!this.isShown&&this.rootElement&&"undefined"!=typeof document){this.preloaded=!0;var e={};try{for(var r=ge(t.PRELOAD_STYLE_KEYS),s=r.next();!s.done;s=r.next()){var o=s.value;e[o]=this.rootElement.style[o]}}catch(t){i={error:t}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}this.preloadStyleSnapshot=e,Object.assign(this.rootElement.style,t.HIDDEN_STYLE),document.body.appendChild(this.rootElement)}},t.prototype.clearPreloadStyles=function(){var i;this.preloaded&&this.rootElement&&(this.preloaded=!1,Object.assign(this.rootElement.style,null!==(i=this.preloadStyleSnapshot)&&void 0!==i?i:t.CLEARED_STYLE),this.preloadStyleSnapshot=null)},t.prototype.show=function(){var t,i;this.rootElement&&"undefined"!=typeof document&&(this.clearPreloadStyles(),this.rootElement.parentNode||document.body.appendChild(this.rootElement),this.isShown=!0,null===(i=(t=this.config).onShown)||void 0===i||i.call(t))},t.prototype.hide=function(){this.isShown=!1,this.rootElement&&this.rootElement.parentNode&&this.rootElement.parentNode.removeChild(this.rootElement)},t.prototype.addCloseListener=function(t){this.closeListener=t},Object.defineProperty(t.prototype,"resizableElement",{get:function(){return this.rootElement},enumerable:!1,configurable:!0}),t.prototype.setHeight=function(t){var i=this.resizableElement;i&&pa(i,t)},t.prototype.showLoader=function(){var t=this.resizableElement;if(t&&!this.loaderElement&&"undefined"!=typeof document){var i=document.createElement("div");i.classList.add(Zu.loader.className),t.appendChild(i),this.loaderElement=i}},t.prototype.hideLoader=function(){var t;null===(t=this.loaderElement)||void 0===t||t.remove(),this.loaderElement=null},t.prototype.destroy=function(){var t,i,n,e,r;if(!this.destroyed){this.destroyed=!0,this.isShown=!1;try{for(var s=ge(this.boundListeners),o=s.next();!o.done;o=s.next()){var u=o.value,a=u.target,c=u.type,h=u.handler;a.removeEventListener(c,h)}}catch(i){t={error:i}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}this.boundListeners.length=0,(null===(r=this.rootElement)||void 0===r?void 0:r.parentNode)&&this.rootElement.parentNode.removeChild(this.rootElement);try{for(var d=ge(this.customStyles),f=d.next();!f.done;f=d.next()){f.value.remove()}}catch(t){n={error:t}}finally{try{f&&!f.done&&(e=d.return)&&e.call(d)}finally{if(n)throw n.error}}this.customStyles.length=0,this.closeListener=null,this.onDestroy()}},t.prototype.onDestroy=function(){},t.DEFAULT_STYLE_ID="__glu_default_style",t.PRELOAD_STYLE_KEYS=["position","left","top","visibility","pointerEvents"],t.HIDDEN_STYLE={position:"fixed",left:"-9999px",top:"-9999px",visibility:"hidden",pointerEvents:"none"},t.CLEARED_STYLE={position:"",left:"",top:"",visibility:"",pointerEvents:""},t}(),ya=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.sheetClass=ma(),r.backdropClass=ma(),r.sheetElement=null,r.height=i.height,r.createElement(),r.addCustomStyle(((e={})[la]=r.sheetClass,e[va]=r.backdropClass,e)),r}return fe(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.classList.add(this.backdropClass,Zu.backDrop.className);var e=document.createElement("div"),r="IMG"===this.contentElement.tagName;e.classList.add(this.sheetClass,r?Zu.bottomSheetStatic.className:Zu.bottomSheet.className,Zu.hideScroll.className),e.style.height=this.height,e.appendChild(this.contentElement),this.addCloseButton(e),this.bindEvent(e,"click",function(t){return t.stopPropagation()}),n.appendChild(e),this.bindEvent(n,"click",function(t){var n;t.stopPropagation(),t.preventDefault(),null===(n=i.closeListener)||void 0===n||n.call(i)}),this.bindEvent(n,"animationend",function(){i.isShown||t.prototype.hide.call(i)}),this.rootElement=n,this.sheetElement=e}else this.config.logger.warn("BottomSheetContainer.createElement() skipped - no document (SSR), container will not render")},Object.defineProperty(i.prototype,"resizableElement",{get:function(){return this.sheetElement},enumerable:!1,configurable:!0}),i.prototype.show=function(){this.sheetElement&&(this.sheetElement.classList.remove(Zu.slideDownSheet.className),this.sheetElement.classList.add(Zu.slideUpSheet.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.sheetElement&&(this.sheetElement.classList.remove(Zu.slideUpSheet.className),this.sheetElement.classList.add(Zu.slideDownSheet.className),this.isShown=!1)},i}(wa),Ea=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.instanceClass=ma(),r.createElement(),r.addCustomStyle(((e={})[la]=r.instanceClass,e)),r}return fe(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.appendChild(this.contentElement),n.classList.add(Zu.chatBox.className,this.instanceClass),this.addCloseButton(n),this.bindEvent(n,"animationend",function(){i.isShown||t.prototype.hide.call(i)}),this.rootElement=n}else this.config.logger.warn("ChatBoxContainer.createElement() skipped - no document (SSR), container will not render")},i.prototype.show=function(){this.rootElement&&(this.rootElement.classList.remove(Zu.slideDown.className),this.rootElement.classList.add(Zu.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.rootElement&&(this.rootElement.classList.remove(Zu.slideUp.className),this.rootElement.classList.add(Zu.slideDown.className),this.isShown=!1)},i}(wa),_a=[],Ia=!1,ba=null,Ta=null;function Sa(t,i){Ta=i,"undefined"!=typeof document&&(Ia||((ba||(ba=new MutationObserver(function(){var t,i;try{for(var n=ge(we([],pe(_a),!1)),e=n.next();!e.done;e=n.next()){var r=e.value;try{r()}catch(t){null==Ta||Ta.error("DOM observer callback failed",{error:t})}}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}})),ba).observe(document.body,{childList:!0,subtree:!0}),Ia=!0),_a.includes(t)||_a.push(t))}function Ca(t){0===(_a=_a.filter(function(i){return i!==t})).length&&Ia&&ba&&(ba.disconnect(),ba=null,Ia=!1)}var Na=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.supportsPreload=!1,r.instanceClass=ma(),r.isObserverRunning=!1,r.showOnceHookPresent=function(){var t,i;if(r.isObserverRunning&&"undefined"!=typeof document&&r.rootElement){var n=document.querySelector("#".concat(r.hookId));n&&(n.innerHTML="",n.append(r.rootElement),r.isShown=!0,null===(i=(t=r.config).onShown)||void 0===i||i.call(t),Ca(r.showOnceHookPresent),r.isObserverRunning=!1)}},r.hookId=i.elementHookId,r.createElement(),r.addCustomStyle(((e={})[la]=r.instanceClass,e)),r}return fe(i,t),i.prototype.createElement=function(){if("undefined"!=typeof document){var t=document.createElement("div");t.appendChild(this.contentElement);var i="IMG"===this.contentElement.tagName;t.classList.add(this.instanceClass,i?Zu.embeddedStatic.className:Zu.embedded.className),this.rootElement=t}},i.prototype.show=function(){var t,i;if("undefined"!=typeof document&&this.rootElement){var n=document.querySelector("#".concat(this.hookId));if(n)return n.innerHTML="",n.append(this.rootElement),this.isShown=!0,void(null===(i=(t=this.config).onShown)||void 0===i||i.call(t));this.isObserverRunning||(this.config.logger.info("EmbeddedContainer hook not found, waiting for it to appear",{hookId:this.hookId}),Sa(this.showOnceHookPresent,this.config.logger),this.isObserverRunning=!0)}},i.prototype.hide=function(){var t;null===(t=this.rootElement)||void 0===t||t.remove(),this.isShown=!1,this.isObserverRunning&&(Ca(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.onDestroy=function(){this.isObserverRunning&&(Ca(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.showLoader=function(){},i.prototype.hideLoader=function(){},i}(wa),Da=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.instanceClass=ma(),r.createElement(),r.addCustomStyle(((e={})[la]=r.instanceClass,e)),r}return fe(i,t),i.prototype.createElement=function(){if("undefined"!=typeof document){var t=document.createElement("div");t.appendChild(this.contentElement),t.classList.add(Zu.iconButton.className,this.instanceClass),this.rootElement=t}else this.config.logger.warn("IconButtonContainer.createElement() skipped - no document (SSR), container will not render")},i.prototype.show=function(){this.rootElement&&(this.rootElement.classList.remove(Zu.slideDown.className),this.rootElement.classList.add(Zu.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.rootElement&&(this.rootElement.classList.remove(Zu.slideUp.className),this.rootElement.classList.add(Zu.slideDown.className),t.prototype.hide.call(this))},i}(wa),Oa=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.supportsPreload=!1,r.instanceClass=ma(),r.isObserverRunning=!1,r.showOnceHookPresent=function(){var t,i;if(r.isObserverRunning&&"undefined"!=typeof document&&r.rootElement){var n=document.querySelector("#".concat(r.hookId));n&&(n.innerHTML="",n.append(r.rootElement),r.isShown=!0,null===(i=(t=r.config).onShown)||void 0===i||i.call(t),Ca(r.showOnceHookPresent),r.isObserverRunning=!1)}},r.hookId=i.elementHookId,r.contentElement.classList.add(r.instanceClass),r.rootElement=r.contentElement,r.addCustomStyle(((e={})[la]=r.instanceClass,e)),r}return fe(i,t),i.prototype.show=function(){var t,i;if("undefined"!=typeof document&&this.rootElement){var n=document.querySelector("#".concat(this.hookId));if(n)return n.innerHTML="",n.append(this.rootElement),this.isShown=!0,void(null===(i=(t=this.config).onShown)||void 0===i||i.call(t));this.isObserverRunning||(this.config.logger.info("NativeBannerContainer hook not found, waiting for it to appear",{hookId:this.hookId}),Sa(this.showOnceHookPresent,this.config.logger),this.isObserverRunning=!0)}},i.prototype.hide=function(){var t;null===(t=this.rootElement)||void 0===t||t.remove(),this.isShown=!1,this.isObserverRunning&&(Ca(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.onDestroy=function(){this.isObserverRunning&&(Ca(this.showOnceHookPresent),this.isObserverRunning=!1)},i}(wa),ka=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.popupClass=ma(),r.backdropClass=ma(),r.popupElement=null,r.height=i.height,r.createElement(),r.addCustomStyle(((e={})[la]=r.popupClass,e[va]=r.backdropClass,e)),r}return fe(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.classList.add(this.backdropClass,Zu.backDrop.className);var e=document.createElement("div"),r="IMG"===this.contentElement.tagName;e.classList.add(this.popupClass,r?Zu.popUpStatic.className:Zu.popUp.className,Zu.hideScroll.className),e.style.height=this.height,e.appendChild(this.contentElement),this.addCloseButton(e),this.bindEvent(e,"click",function(t){return t.stopPropagation()}),n.appendChild(e),this.bindEvent(n,"click",function(t){var n;t.stopPropagation(),t.preventDefault(),null===(n=i.closeListener)||void 0===n||n.call(i)}),this.bindEvent(n,"animationend",function(){i.isShown||t.prototype.hide.call(i)}),this.rootElement=n,this.popupElement=e}else this.config.logger.warn("PopupContainer.createElement() skipped - no document (SSR), container will not render")},Object.defineProperty(i.prototype,"resizableElement",{get:function(){return this.popupElement},enumerable:!1,configurable:!0}),i.prototype.show=function(){this.popupElement&&(this.popupElement.classList.remove(Zu.slideDown.className),this.popupElement.classList.add(Zu.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.popupElement&&(this.popupElement.classList.remove(Zu.slideUp.className),this.popupElement.classList.add(Zu.slideDown.className),this.isShown=!1)},i}(wa);function Aa(t){var i=t;if("string"==typeof i)try{i=JSON.parse(i)}catch(t){return null}var n=function(t){if(!t||"object"!=typeof t)return null;var i=t.eventName;if("string"!=typeof i)return null;return{target:"GLU_SDK",action:{type:i,data:t.data}}}(i);return n||(i&&"object"==typeof i&&"GLU_SDK"===i.target?i:null)}var xa=function(){function t(i){var n=this;this.sdkEventListener=null,this.boundListeners=[],this.headStyles=[],this.destroyed=!1,this.messageListener=function(t,i,e){var r,s,o="CLOSE_FRAME_CONTENT"===i.action.type?{target:"GLU_SDK",action:{type:"CLOSE_CONTAINER_CONTENT"}}:i;n.element instanceof HTMLIFrameElement&&t===n.element.contentWindow&&e===n.contentOrigin()?null===(r=n.sdkEventListener)||void 0===r||r.call(n,o):"UPDATE_CONTENT_STATE"===o.action.type?n.sendMessageToContent(o.action):"CLOSE_CONTAINER_CONTENT"===o.action.type&&n.sendMessageToContent({type:"UPDATE_CONTENT_STATE",data:null!==(s=o.action.data)&&void 0!==s?s:{}})},this.config=i,t.lastLogger=i.logger,t.listeners.push(this.messageListener),t.isListening||t.installWindowListener()}return t.prototype.bindEvent=function(t,i,n,e){t.addEventListener(i,n,e),this.boundListeners.push({target:t,type:i,handler:n})},t.prototype.addHeadStyle=function(t){if("undefined"!=typeof document){var i=document.createElement("style");i.textContent=t,document.head.appendChild(i),this.headStyles.push(i)}},t.prototype.destroy=function(){var i,n,e,r;if(!this.destroyed){this.destroyed=!0,t.removeListener(this.messageListener);try{for(var s=ge(this.boundListeners),o=s.next();!o.done;o=s.next()){var u=o.value,a=u.target,c=u.type,h=u.handler;a.removeEventListener(c,h)}}catch(t){i={error:t}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}this.boundListeners.length=0;try{for(var d=ge(this.headStyles),f=d.next();!f.done;f=d.next()){f.value.remove()}}catch(t){e={error:t}}finally{try{f&&!f.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}this.headStyles.length=0,this.sdkEventListener=null,this.onDestroy()}},t.prototype.onDestroy=function(){},t.removeListener=function(i){t.listeners=t.listeners.filter(function(t){return t!==i}),0===t.listeners.length&&t.windowListener&&"undefined"!=typeof window&&(window.removeEventListener("message",t.windowListener),t.windowListener=null,t.isListening=!1)},t.parseSdkEvent=function(t){return Aa(t)},t.dispatchToListeners=function(i,n,e){var r,s,o;try{for(var u=ge(t.listeners),a=u.next();!a.done;a=u.next()){var c=a.value;try{c(i,n,e)}catch(i){null===(o=t.lastLogger)||void 0===o||o.error("Content message listener threw",{error:i})}}}catch(t){r={error:t}}finally{try{a&&!a.done&&(s=u.return)&&s.call(u)}finally{if(r)throw r.error}}},t.installWindowListener=function(){if("undefined"!=typeof window){var i=function(i){var n=t.parseSdkEvent(i.data);n&&(t.dispatchToListeners(i.source,n,i.origin),i.stopPropagation())};window.addEventListener("message",i),t.windowListener=i,t.isListening=!0}},t.prototype.urlModifier=function(t,i){var n=function(t){return encodeURIComponent(String(t))},e=t.includes("?")?"&":"?";return e+="source=JS_SDK",(null==i?void 0:i.token)&&(e+="&token=".concat(n(this.config.token))),this.config.isEmbedded&&(this.config.rootId&&(e+="&rootId=".concat(n(this.config.rootId))),e+="&isEmbedded=true"),this.config.userId||(e+="¬LoggedIn=true"),void 0!==this.config.darkMode&&(e+="&darkMode=".concat(n(this.config.darkMode))),t+e},t.prototype.listen=function(t){this.sdkEventListener=t},t.prototype.reveal=function(){this.element instanceof HTMLIFrameElement&&(this.element.style.opacity="1")},t.prototype.sendMessageToContent=function(t){this.postToContentWindow({target:"GLU_SDK",action:t})},t.prototype.sendRawMessage=function(t){this.postToContentWindow(t)},t.prototype.postToContentWindow=function(t){if(this.element instanceof HTMLIFrameElement){var i=this.element.contentWindow;if(i&&"function"==typeof i.postMessage){var n=this.contentOrigin();n&&i.postMessage(t,n)}}},t.prototype.contentOrigin=function(){if(!(this.element instanceof HTMLIFrameElement&&this.element.src))return null;try{return new URL(this.element.src).origin}catch(t){return this.config.logger.warn("Could not resolve content iframe origin for postMessage",{src:this.element.src}),null}},t.listeners=[],t.isListening=!1,t.windowListener=null,t.lastLogger=null,t}(),Ra="http://www.w3.org/2000/svg",Pa={viewBox:"0 0 20 20",paths:[{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M15.4677 8.63654C15.381 8.49733 15.3021 8.38154 15.2387 8.30868C14.1364 9.89462 12.1607 9.28835 12.9409 6.93871C13.963 3.8579 12.2875 1.56551 9.20043 0.666504C10.2678 2.99272 7.53657 3.66405 6.06808 5.45945C5.24909 6.46124 4.47797 8.75233 5.39917 10.3122C5.7485 10.9042 5.10935 11.6536 4.38222 11.1475C4.1778 11.0044 3.9061 10.5725 3.74825 10.2589C3.4662 10.968 3.29541 11.7356 3.29541 12.5786C3.29541 16.3021 6.29709 19.3192 9.99872 19.3192C13.7004 19.3192 16.702 16.3008 16.702 12.5786C16.702 11.9632 16.6205 11.3674 16.4666 10.8001C16.4174 10.9549 16.3695 11.1293 16.2492 11.2698C15.8339 11.7538 15.0123 11.3739 15.2504 10.7195C15.3914 10.3292 15.9749 9.66304 15.469 8.63524L15.4677 8.63654Z",fill:"#FF0099"},{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M6.01376 11.5492C6.07693 11.4477 6.13444 11.3634 6.18063 11.3103C6.98387 12.4659 8.42347 12.0241 7.85498 10.312C7.1102 8.06716 8.33108 6.39677 10.5805 5.7417C9.80274 7.43673 11.7929 7.92591 12.863 9.23415C13.4597 9.96412 14.0216 11.6336 13.3504 12.7702C13.0958 13.2016 13.5615 13.7476 14.0914 13.3788C14.2403 13.2746 14.4383 12.9598 14.5533 12.7313C14.7589 13.248 14.8833 13.8073 14.8833 14.4216C14.8833 17.1348 12.6961 19.3333 9.99883 19.3333C7.30158 19.3333 5.11436 17.1339 5.11436 14.4216C5.11436 13.9732 5.17376 13.5391 5.28595 13.1257C5.32177 13.2385 5.35666 13.3656 5.44433 13.4679C5.74696 13.8206 6.34562 13.5438 6.17215 13.0669C6.06939 12.7825 5.6442 12.2972 6.01282 11.5482L6.01376 11.5492Z",fill:"#FF7BC9"},{d:"M9.66252 13.0464C9.66252 13.0464 10.0316 14.1917 9.59153 14.8957C9.54547 14.9694 9.49707 15.0354 9.44719 15.0949C9.26032 15.3179 8.89714 15.2454 8.81735 14.9659C8.7575 14.7564 8.73638 14.4924 8.82879 14.192C8.82879 14.192 7.76301 15.9527 8.3952 17.2115L8.39667 17.2145C8.39667 17.2145 8.39725 17.2153 8.39725 17.2159C8.39755 17.2168 8.39813 17.2174 8.39843 17.2183C8.6912 17.8206 9.30726 18.2371 10.021 18.2415C10.9982 18.2477 11.7935 17.4621 11.8454 16.486C11.9716 14.1239 9.66252 13.0464 9.66252 13.0464Z",fill:"white"}]},Ma={viewBox:"0 0 16 16",paths:[{d:"M15 7.99999C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 7.99999C1 4.134 4.13401 1 8 1C11.866 1 15 4.134 15 7.99999Z",fill:"#FF0099",stroke:"white","stroke-width":"2"},{d:"M10.6796 6.75249C10.8413 6.75249 10.9179 6.95334 10.7953 7.06058L5.16639 11.9525C5.0217 12.0784 4.80724 11.9116 4.89575 11.7414L6.58085 8.43249H5.59362C5.46256 8.43249 5.37745 8.29462 5.43702 8.17717L7.4966 4.13292C7.52553 4.07334 7.58681 4.0376 7.65319 4.0376H10.9485C11.0966 4.0376 11.1783 4.21292 11.083 4.32526L9.04724 6.75079H10.6796V6.75249Z",fill:"white"}]},Ua={viewBox:"0 0 10 10",paths:[{d:"M5 0C2.24 0 0 2.24 0 5C0 7.76 2.24 10 5 10C7.76 10 10 7.76 10 5C10 2.24 7.76 0 5 0ZM2.535 8.14C2.75 7.69 4.06 7.25 5 7.25C5.94 7.25 7.255 7.69 7.465 8.14C6.785 8.68 5.93 9 5 9C4.07 9 3.215 8.68 2.535 8.14ZM8.18 7.415C7.465 6.545 5.73 6.25 5 6.25C4.27 6.25 2.535 6.545 1.82 7.415C1.31 6.745 1 5.91 1 5C1 2.795 2.795 1 5 1C7.205 1 9 2.795 9 5C9 5.91 8.69 6.745 8.18 7.415ZM5 2C4.03 2 3.25 2.78 3.25 3.75C3.25 4.72 4.03 5.5 5 5.5C5.97 5.5 6.75 4.72 6.75 3.75C6.75 2.78 5.97 2 5 2ZM5 4.5C4.585 4.5 4.25 4.165 4.25 3.75C4.25 3.335 4.585 3 5 3C5.415 3 5.75 3.335 5.75 3.75C5.75 4.165 5.415 4.5 5 4.5Z",fill:"#242220"}]},La={viewBox:"0 0 12 12",paths:[{d:"M7.5 0.5H4.5V1.5H7.5V0.5ZM5.5 7H6.5V4H5.5V7ZM9.515 3.695L10.225 2.985C10.01 2.73 9.775 2.49 9.52 2.28L8.81 2.99C8.035 2.37 7.06 2 6 2C3.515 2 1.5 4.015 1.5 6.5C1.5 8.985 3.51 11 6 11C8.49 11 10.5 8.985 10.5 6.5C10.5 5.44 10.13 4.465 9.515 3.695ZM6 10C4.065 10 2.5 8.435 2.5 6.5C2.5 4.565 4.065 3 6 3C7.935 3 9.5 4.565 9.5 6.5C9.5 8.435 7.935 10 6 10Z",fill:"#242220"}]},Fa={viewBox:"0 0 24 24",paths:[{d:"M8.29492 16.59L12.8749 12L8.29492 7.41L9.70492 6L15.7049 12L9.70492 18L8.29492 16.59Z",fill:"#4F4DF8"}]};function Ga(t){var i,n,e,r,s=document.createElementNS(Ra,"svg");s.setAttribute("viewBox",t.viewBox),s.setAttribute("fill","none"),s.setAttribute("aria-hidden","true");try{for(var o=ge(t.paths),u=o.next();!u.done;u=o.next()){var a=u.value,c=document.createElementNS(Ra,"path");try{for(var h=(e=void 0,ge(Object.entries(a))),d=h.next();!d.done;d=h.next()){var f=pe(d.value,2),l=f[0],v=f[1];c.setAttribute(l,v)}}catch(t){e={error:t}}finally{try{d&&!d.done&&(r=h.return)&&r.call(h)}finally{if(e)throw e.error}}s.appendChild(c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}var Va={card:"#1E1E1E",iconContainer:"#164048",heading:"#F5F5F5",notNow:"#AAAAAA"},Ba={card:"#fff",iconContainer:"#e0f7fa",heading:"#333",notNow:"#888"},za=function(t){function i(i,n){var e=t.call(this,n)||this;if(e.data=i,e.campaignId=e.extractCampaignId(),!e.campaignId)throw new Error("ACCEPT_GUARD content missing conditions.campaignId");if(!e.config.allCampaignsMap.byId[e.campaignId])throw new Error("ACCEPT_GUARD: campaign ".concat(e.campaignId," not present in campaign map"));return e.createElement(),e}return fe(i,t),i.prototype.extractCampaignId=function(){var t,i=null===(t=this.data.conditions)||void 0===t?void 0:t.campaignId;return"string"==typeof i?i:Array.isArray(i)&&void 0!==i[0]?String(i[0]):""},i.prototype.createElement=function(){var t,i,n,e=this,r=null!==(n=this.config.darkMode)&&void 0!==n&&n?Va:Ba,s={container:"display: flex; justify-content: center; align-items: center;",card:"background-color: ".concat(r.card,"; text-align: center; padding: 30px 20px; max-width: 400px; width: 100%; margin: 10px;"),iconContainer:"background-color: ".concat(r.iconContainer,"; border-radius: 50%; padding: 15px; margin: 0 auto 20px; width: 100px; height: 100px; display: flex; justify-content: center; align-items: center;"),flameIcon:"width: 60px; height: 60px;",heading:"font-size: 22px; font-weight: bold; color: ".concat(r.heading,"; margin: 20px 0;"),instructions:"list-style: none; padding: 0; margin: 0 0 20px; text-align: left;",listItem:"display: flex; align-items: center; margin-bottom: 15px; font-size: 16px; color: ".concat(r.heading,";"),icon:"margin-right: 10px; width: 24px; height: 24px; flex-shrink: 0;",startStreakButton:"background-color: #6c63ff; color: #fff; border: none; border-radius: 25px; padding: 12px 25px; font-size: 16px; cursor: pointer; width: 80%; margin: 0 auto 10px;",notNowButton:"background: none; border: none; color: ".concat(r.notNow,"; font-size: 14px; cursor: pointer; margin-top: 5px;")},o=document.createElement("div");o.style.cssText=s.container;var u=document.createElement("div");u.style.cssText=s.card;var a=document.createElement("div");a.style.cssText=s.iconContainer;var c=Ga(Pa);c.style.cssText=s.flameIcon,a.appendChild(c);var h=document.createElement("h1");h.innerText="Can you complete a 7-day earning streak?",h.style.cssText=s.heading;var d=document.createElement("ul");d.style.cssText=s.instructions;var f=[{icon:La,text:"Start a streak anytime until [DATE HERE] by earning at least $1"},{icon:Ma,text:"Claim a bonus reward for each streak day"},{icon:Pa,text:"Complete a 7-day streak and earn an additional up to $50 reward"}];try{for(var l=ge(f),v=l.next();!v.done;v=l.next()){var m=v.value,g=document.createElement("li");g.style.cssText=s.listItem;var p=Ga(m.icon);p.style.cssText=s.icon;var w=document.createElement("span");w.innerText=m.text,g.appendChild(p),g.appendChild(w),d.appendChild(g)}}catch(i){t={error:i}}finally{try{v&&!v.done&&(i=l.return)&&i.call(l)}finally{if(t)throw t.error}}var y=document.createElement("button");y.innerText="Earn to start your streak",y.style.cssText=s.startStreakButton,this.bindEvent(y,"click",function(){e.accept()});var E=document.createElement("button");E.innerText="Not now",E.style.cssText=s.notNowButton,this.bindEvent(E,"click",function(){var t;null===(t=e.sdkEventListener)||void 0===t||t.call(e,{target:"GLU_SDK",action:{type:"CLOSE_CONTAINER_CONTENT"}})}),u.appendChild(a),u.appendChild(h),u.appendChild(d),u.appendChild(y),u.appendChild(E),o.appendChild(u),this.element=o},i.prototype.accept=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:t="".concat(this.config.baseUrl).concat("/reward/v1.1/user/program/accept"),i={campaignId:this.campaignId,choice:"accept"},n=!1,this.config.logger.debug("ACCEPT_GUARD accept request started",{url:t,requestBody:i}),a.label=1;case 1:return a.trys.push([1,5,,6]),[4,fetch(t,{method:"POST",headers:{authorization:"Bearer ".concat(this.config.token),"content-type":"application/json"},body:JSON.stringify(i)})];case 2:return(e=a.sent()).ok?[3,4]:[4,e.text()];case 3:throw r=a.sent(),n=!0,this.config.logger.error("ACCEPT_GUARD accept request failed",{url:t,requestBody:i,status:e.status,responseBody:r}),new Error("Accept failed with status ".concat(e.status));case 4:return this.config.logger.info("ACCEPT_GUARD accept request succeeded",{campaignId:this.campaignId}),s={target:"GLU_SDK",action:{type:"TOGGLE_CONTAINER_CONTENT",id:ma(),content:{typeId:"CAMPAIGN",conditions:{campaignId:[this.campaignId]}},container:{typeId:"POP_UP",css:".__glu_container { \n background-color: #000; \n border-radius: 0px;\n max-width: none;\n max-height: none;\n height: 100vh;\n width: 100vw;\n } \n .__glu_backdrop { background-color: rgba(0,0,0,0.5); \n background-color: rgba(0,0,0,0.5); \n }",height:"",elementHookId:""}}},null===(u=this.sdkEventListener)||void 0===u||u.call(this,s),[3,6];case 5:return o=a.sent(),n||this.config.logger.error("ACCEPT_GUARD accept request failed",{url:t,requestBody:i,error:o}),[3,6];case 6:return[2]}})})},i}(xa);function ja(t,i,n){var e=document.createElement("iframe");e.classList.add(Zu.iframe.className),e.style.height="100%",e.style.width="100%",e.style.display="block",e.setAttribute("fetchpriority","high"),e.style.opacity="0",e.style.transition="opacity 150ms ease";var r=function(){e.style.opacity="1"},s=performance.now();return e.addEventListener("load",function(){r(),null==i||i(performance.now()-s)},{once:!0}),e.addEventListener("error",function(){r(),null==n||n()},{once:!0}),e.src=t,e}var Ha=function(t){function i(i,n){var e=t.call(this,n)||this,r=e.resolveUrl(i);return e.element=ja(e.urlModifier(r),n.onLoad,function(){return n.logger.error("Campaign iframe failed to load",{src:r})}),e}return fe(i,t),i.prototype.resolveUrl=function(t){var i,n,e,r=null!==(e=t.conditions)&&void 0!==e?e:{};if(0===Object.keys(r).length){if(t.campaignId)if(h=this.config.allCampaignsMap.byId[t.campaignId])return h.url;throw new Error("CAMPAIGN content has no conditions")}var s=this.config.allCampaignsMap,o=s.allIds,u=s.byId;try{for(var a=ge(o),c=a.next();!c.done;c=a.next()){var h;if((h=u[c.value])&&this.campaignMatches(h,r))return h.url}}catch(t){i={error:t}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}throw new Error("CAMPAIGN_NOT_FOUND")},i.prototype.campaignMatches=function(t,i){var n,e,r;try{for(var s=ge(Object.keys(i)),o=s.next();!o.done;o=s.next()){var u=o.value,a=i[u],c=t[u],h=null===(r=t.banner)||void 0===r?void 0:r[u];if("string"==typeof a){if(a!==c&&a!==h)return!1}else{if(!Array.isArray(a))return!1;if(!a.includes(c)&&!a.includes(h))return!1}}}catch(t){n={error:t}}finally{try{o&&!o.done&&(e=s.return)&&e.call(s)}finally{if(n)throw n.error}}return!0},i}(xa);var qa=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=ma(),e.data=i;var r=e.lookupCampaign();if(!(null==r?void 0:r.banner))throw new Error("DYNAMIC content requires a campaign with banner state");return e.bannerData=r.banner,e.createElement(),e}return fe(i,t),i.prototype.lookupCampaign=function(){var t,i=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==i?void 0:i.type)){var n=null===(t=i.content.conditions)||void 0===t?void 0:t.campaignId,e="";if("string"==typeof n?e=n:Array.isArray(n)&&void 0!==n[0]&&(e=String(n[0])),e)return this.config.allCampaignsMap.byId[e]}},i.prototype.createElement=function(){var t,i,n=this,e=this.bannerData,r=null!==(t=this.data.state)&&void 0!==t?t:{},s=e.userCampaignStatus,o=null!==(i=r[s])&&void 0!==i?i:{title:"",body:""},u=e.stepCompleted,a=e.activityCount,c=e.totalCampaignParticipants,h=e.activityExpiry,d=Math.floor(Date.now()/1e3),f=Math.max(0,h-d),l=Math.floor(f/3600),v=Math.floor(f%3600/60),m="".concat(l,"h").concat(v.toString().padStart(2,"0"),"m"),g=document.createElement("div");g.className="element";var p=document.createElement("div");p.className="progress-text-container";var w=document.createElement("div");w.setAttribute("class","progress-container");var y="http://www.w3.org/2000/svg",E=document.createElementNS(y,"svg");E.setAttribute("class","progress-circle"),E.setAttribute("viewBox","0 0 36 36");var _=document.createElementNS(y,"path");_.setAttribute("class","progress-bg"),_.setAttribute("d","M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831");var I=document.createElementNS(y,"path");I.setAttribute("class","progress"),I.setAttribute("d","M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831");var b=a>0?u/a*100:0;I.setAttribute("stroke-dasharray","".concat(b,", 100")),I.setAttribute("stroke-linecap",0===u?"butt":"round"),E.appendChild(_),E.appendChild(I);var T=document.createElement("div");T.setAttribute("class","inner-content");var S=document.createElement("div");S.setAttribute("class","primary-icon-container");var C=Ga(Pa);C.setAttribute("class","icon-image"),S.appendChild(C),T.appendChild(S),w.appendChild(E),w.appendChild(T);var N=document.createElement("p");N.setAttribute("class","progress-text"),N.innerText="".concat(u,"/").concat(a),p.appendChild(w),p.appendChild(N),g.appendChild(p);var D=Ga(Ma);D.setAttribute("class","smaller-icon"),w.appendChild(D);var O=document.createElement("div");if(O.className="time-title-body-container",g.appendChild(O),"completed"!==s){var k=document.createElement("div");k.className="icon-text-container";var A=Ga("pristine"===s?Ua:La);A.setAttribute("class","icon-container"),k.appendChild(A);var x=document.createElement("p");x.className="timer-text",x.innerText="pristine"===s?"".concat(c," users currently streaking"):m,k.appendChild(x),O.appendChild(k)}var R=document.createElement("div");R.className="title-body-container";var P=document.createElement("p");P.className="title-text",P.innerText=o.title,R.appendChild(P);var M=document.createElement("p");M.className="body-text",M.innerText=o.body,R.appendChild(M),O.appendChild(R);var U=document.createElement("div");U.className="right-icon-container";var L=Ga(Fa);L.setAttribute("class","right-icon"),U.appendChild(L),g.appendChild(U),this.addHeadStyle(this.buildStylesheet(u===a)),this.bindEvent(g,"click",function(t){t.stopPropagation(),t.preventDefault(),n.handleClick()}),this.element=g},i.prototype.handleClick=function(){var t,i=this.data.action;if(i&&"TOGGLE_CONTAINER_CONTENT"===i.type&&this.sdkEventListener)if(this.bannerData.checkAccepted&&this.bannerData.accepted){var n=le(le({},i),{id:this.actionId});this.sdkEventListener({target:"GLU_SDK",action:n})}else{var e,r={target:"GLU_SDK",action:le(le({},i),{id:this.actionId,content:le(le({},i.content),{typeId:"ACCEPT_GUARD"}),container:le(le({},i.container),{typeId:"BOTTOM_SHEET",css:(e=null!==(t=this.config.darkMode)&&void 0!==t&&t,".__glu_container {\n background-color: ".concat(e?"#1E1E1E":"#fff",";\n height: 57vh\n }\n .__glu_backdrop {\n background-color: rgba(0,0,0,0.5);\n }"))})})};this.sdkEventListener(r)}},i.prototype.buildStylesheet=function(t){var i,n=t?"block":"none",e=null!==(i=this.config.darkMode)&&void 0!==i&&i,r=e?"#1E1E1E":"white",s=e?"#444444":"#d3d3d3",o=e?"#22303A":"#E9F2F9",u=e?"#B0B0B0":"#757575",a=e?"#444444":"#D8D8D8",c=e?"#F5F5F5":"inherit";return"\n *{ margin: 0; padding: 0; box-sizing: border-box; }\n body{ font-family: 'Poppins', sans-serif; }\n .element { border-radius: 8px; width: 100%; padding: 8px 0; align-items: stretch; background-color: ".concat(r,"; display: flex; }\n .progress-text-container{ display: flex; flex-direction: column; align-items: center; width: 20%; }\n .progress-container { align-items: center; display: flex; flex-direction: column; width: 80%; position: relative; }\n .progress-bg { fill: none; stroke: ").concat(s,"; stroke-width: 3; }\n .progress { fill: none; stroke: #FF0099; stroke-width: 3; transition: stroke-dasharray 0.3s ease; }\n .inner-content { height: 63%; width: 63%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; background-color: ").concat(o,"; border-radius: 50%; }\n .primary-icon-container { height: 100%; width: 100%; display: flex; align-items: center; justify-content: center; }\n .icon-image{ height: 70%; width: 70%; }\n .smaller-icon { display: ").concat(n,"; position: absolute; bottom: 9%; width: 31%; right: 0%; border-radius: 50%; background-color: ").concat(r,"; padding: 1px; }\n .progress-text { margin: 0; font-size: 12px; font-weight: 400; color: ").concat(u,"; }\n .time-title-body-container { max-height: 100%; display: flex; gap: 8px; flex-direction: column; justify-content: center; width: 65%; }\n .icon-text-container { display: flex; border: 1px solid ").concat(a,"; border-radius: 4px; gap: 4px; padding: 2px 4px; width: fit-content; align-items: center; }\n .icon-container { width: 12px; height: 12px; }\n .timer-text { margin: 0px; font-size: 12px; font-weight: 600; color: ").concat(c,"; }\n .title-body-container { display: flex; gap: 8px; flex-direction: column; }\n .title-text { margin: 0; font-size: 16px; font-weight: 600; color: ").concat(c,"; }\n .body-text { margin: 0; font-size: 12px; font-weight: 400; color: ").concat(u,"; }\n .right-icon-container { display: flex; justify-content: center; align-items: center; width: 15%; }\n .right-icon { width: 20px; height: 20px; }\n ")},i}(xa),Ka=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=ma(),e.data=i;var r=e.lookupCampaign();return(null==r?void 0:r.banner)?(e.createElement(r),e):(n.logger.warn("DynamicMultistep1Content: campaign/banner lookup failed — hiding",{campaignId:e.data.campaignId}),e.createEmptyElement(),e)}return fe(i,t),i.prototype.createEmptyElement=function(){var t=document.createElement("div");t.style.display="none",this.element=t},i.prototype.lookupCampaign=function(){var t,i=this.data.campaignId;if(i)return this.config.allCampaignsMap.byId[i];var n=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==n?void 0:n.type)){var e=null===(t=n.content.conditions)||void 0===t?void 0:t.campaignId,r="";return"string"==typeof e?r=e:Array.isArray(e)&&void 0!==e[0]&&(r=String(e[0])),r?this.config.allCampaignsMap.byId[r]:void 0}},i.prototype.createElement=function(t){var i,n,e,r,s,o,u,a,c,h=this,d=null==t?void 0:t.banner,f=null!==(i=null==d?void 0:d.stepCompleted)&&void 0!==i?i:0,l=null!==(n=null==d?void 0:d.activityCount)&&void 0!==n?n:0,v=null!==(e=null==d?void 0:d.userCampaignStatus)&&void 0!==e?e:"pristine",m=this.findWidgetState(f,v),g=null!==(r=null==m?void 0:m.title)&&void 0!==r?r:"",p=null!==(s=null==m?void 0:m.body)&&void 0!==s?s:"",w=null!==(u=null===(o=null==m?void 0:m.progressBar)||void 0===o?void 0:o.progressRewardText)&&void 0!==u?u:"",y=null!==(c=null!==(a=this.data.progressBarIcon)&&void 0!==a?a:this.data.src)&&void 0!==c?c:"",E=l>0?Math.round(f/l*100):0;this.data.widgetCss&&this.addHeadStyle(this.data.widgetCss);var _=document.createElement("div");_.className="banner-container";var I=document.createElement("div");I.className="header-progressbar-container";var b=document.createElement("div");b.className="header-container";var T=document.createElement("p");T.className="heading-text",T.innerHTML=g;var S=document.createElement("p");S.className="body-text",S.textContent=p,b.appendChild(T),b.appendChild(S);var C=document.createElement("div");C.className="progressbar-parent-container";var N=document.createElement("span");N.className="progressbar-text",N.textContent=w;var D=document.createElement("div");D.className="progressbar-container";var O=document.createElement("div");O.className="total-progress";var k=document.createElement("div");k.className="completed-progress",k.style.width="".concat(E,"%"),D.appendChild(O),D.appendChild(k),C.appendChild(N),C.appendChild(D),I.appendChild(b),I.appendChild(C);var A=document.createElement("div");if(A.className="right-icon-container",y){var x=document.createElement("img");x.src=y,x.style.width="48px",x.style.height="48px",this.bindEvent(x,"error",function(){return h.config.logger.error("DynamicMultistep1 icon failed to load",{src:y})},{once:!0}),A.appendChild(x)}_.appendChild(I),_.appendChild(A),this.bindEvent(_,"click",function(t){t.stopPropagation(),t.preventDefault(),h.handleClick()}),this.element=_},i.prototype.findWidgetState=function(t,i){var n,e,r=this.data.IWidgetState;if(null==r?void 0:r.length)return null!==(e=null!==(n=r.find(function(n){return n.step===t&&n.state===i}))&&void 0!==n?n:r.find(function(i){return i.step===t}))&&void 0!==e?e:r[0]},i.prototype.handleClick=function(){var t=this.data.action;if(t&&"TOGGLE_CONTAINER_CONTENT"===t.type&&this.sdkEventListener){var i={target:"GLU_SDK",action:le(le({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(xa),Wa=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=ma(),e.data=i;var r=e.lookupCampaign();return(null==r?void 0:r.banner)?(e.createElement(r),e):(n.logger.warn("DynamicMultistep2Content: campaign/banner lookup failed — hiding",{campaignId:e.data.campaignId}),e.createEmptyElement(),e)}return fe(i,t),i.prototype.createEmptyElement=function(){var t=document.createElement("div");t.style.display="none",this.element=t},i.prototype.lookupCampaign=function(){var t,i=this.data.campaignId;if(i)return this.config.allCampaignsMap.byId[i];var n=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==n?void 0:n.type)){var e=null===(t=n.content.conditions)||void 0===t?void 0:t.campaignId,r="";return"string"==typeof e?r=e:Array.isArray(e)&&void 0!==e[0]&&(r=String(e[0])),r?this.config.allCampaignsMap.byId[r]:void 0}},i.prototype.buildHeaderImage=function(t){var i=this;if(!t)return null;var n=document.createElement("div");n.className="image-container-ms2";var e=document.createElement("img");return e.className="header-image",e.src=t,this.bindEvent(e,"error",function(){return i.config.logger.error("DynamicMultistep2 header image failed to load",{src:t})},{once:!0}),n.appendChild(e),n},i.prototype.buildProgressBar=function(t,i){var n=document.createElement("div");n.className="progressbar-wrapper-ms2";var e=document.createElement("div");e.className="progressbar-container-ms2";var r=document.createElement("div");r.className="total-progress-ms2";var s=document.createElement("div");s.className="completed-progress-ms2",s.style.width="".concat(t,"%"),e.appendChild(r),e.appendChild(s);var o=document.createElement("div");o.className="progressbar-text-container-ms2";var u=document.createElement("span");return u.className="progressbar-text-ms2",u.textContent=i,o.appendChild(u),n.appendChild(e),n.appendChild(o),n},i.prototype.buildStepCircle=function(t,i){var n=document.createElement("div");n.className="step";var e=document.createElement("div");e.className=i?"circle completed":"circle";var r=document.createElement("span");return r.className=i?"amount completed":"amount",r.textContent=t,e.appendChild(r),n.appendChild(e),n},i.prototype.buildStepLabel=function(t,i,n){var e=document.createElement("div"),r="label inactive";return i?r="label completed":n&&(r="label current"),e.className=r,e.textContent=t,e},i.prototype.buildStepRows=function(t,i,n){var e=this,r=document.createElement("div");r.className="steps-container";var s=document.createElement("div");return s.className="labels-container",i.forEach(function(o,u){var a,c,h,d,f,l=null!==(a=t.find(function(t){return t.step===o&&"pristine"===t.state}))&&void 0!==a?a:t.find(function(t){return t.step===o}),v=null!==(h=null===(c=null==l?void 0:l.progressBar)||void 0===c?void 0:c.progressRewardText)&&void 0!==h?h:"",m=null!==(f=null===(d=null==l?void 0:l.progressBar)||void 0===d?void 0:d.progressLabel)&&void 0!==f?f:"",g=o<n,p=o===n;if(r.appendChild(e.buildStepCircle(v,g||p)),u<i.length-1){var w=document.createElement("div");w.className=g?"connector completed":"connector",r.appendChild(w)}s.appendChild(e.buildStepLabel(m,g,p))}),[r,s]},i.prototype.buildCtaButton=function(t){var i=this,n=document.createElement("div");n.className="button-container";var e=document.createElement("button");return e.className="view-rewards-button",e.textContent=t,this.bindEvent(e,"click",function(t){t.stopPropagation(),t.preventDefault(),i.handleClick()}),n.appendChild(e),n},i.prototype.createElement=function(t){var i,n,e,r,s,o,u,a,c,h,d=this,f=null==t?void 0:t.banner,l=null!==(i=null==f?void 0:f.stepCompleted)&&void 0!==i?i:0,v=null!==(n=null==f?void 0:f.activityCount)&&void 0!==n?n:0,m=null!==(e=null==f?void 0:f.userCampaignStatus)&&void 0!==e?e:"pristine",g=null!==(r=this.data.IWidgetState)&&void 0!==r?r:[],p=this.findWidgetState(l,m,g),w=v>0?Math.round(l/v*100):0;this.data.widgetCss&&this.addHeadStyle(this.data.widgetCss);var y=document.createElement("div");y.className="card-container-ms2";var E=document.createElement("div");E.className="banner-container-ms2";var _=null!==(u=null!==(o=null!==(s=null==p?void 0:p.headerImage)&&void 0!==s?s:this.data.progressMeterIcon)&&void 0!==o?o:this.data.src)&&void 0!==u?u:"",I=this.buildHeaderImage(_);I&&E.appendChild(I);var b=document.createElement("div");b.className="header-progressbar-container-ms2";var T=document.createElement("div");T.className="heading-container-ms2";var S=document.createElement("p");S.className="heading-text-ms2",S.innerHTML=null!==(a=null==p?void 0:p.title)&&void 0!==a?a:"",T.appendChild(S),b.appendChild(T),b.appendChild(this.buildProgressBar(w,null!==(h=null===(c=null==p?void 0:p.progressMeter)||void 0===c?void 0:c.completedText)&&void 0!==h?h:""));var C=we([],pe(new Set(g.map(function(t){return t.step}))),!1).sort(function(t,i){return t-i});if(C.length>0){var N=pe(this.buildStepRows(g,C,l),2),D=N[0],O=N[1];b.appendChild(D),b.appendChild(O)}(null==p?void 0:p.ctaText)&&b.appendChild(this.buildCtaButton(p.ctaText)),E.appendChild(b),y.appendChild(E),this.bindEvent(y,"click",function(t){t.stopPropagation(),t.preventDefault(),d.handleClick()}),this.element=y},i.prototype.findWidgetState=function(t,i,n){var e,r;return null!==(r=null!==(e=n.find(function(n){return n.step===t&&n.state===i}))&&void 0!==e?e:n.find(function(i){return i.step===t}))&&void 0!==r?r:n[0]},i.prototype.handleClick=function(){var t=this.data.action;if(t&&"TOGGLE_CONTAINER_CONTENT"===t.type&&this.sdkEventListener){var i={target:"GLU_SDK",action:le(le({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(xa),Xa=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=ma(),e.isExpanded=!0,e.data=i;var r=e.lookupCampaign();return(null==r?void 0:r.banner)?(e.createElement(r),e):(n.logger.warn("DynamicMultistep3Content: campaign/banner lookup failed — hiding",{campaignId:e.data.campaignId}),e.createEmptyElement(),e)}return fe(i,t),i.prototype.createEmptyElement=function(){var t=document.createElement("div");t.style.display="none",this.element=t},i.prototype.lookupCampaign=function(){var t,i=this.data.campaignId;if(i)return this.config.allCampaignsMap.byId[i];var n=this.data.action;if("TOGGLE_CONTAINER_CONTENT"===(null==n?void 0:n.type)){var e=null===(t=n.content.conditions)||void 0===t?void 0:t.campaignId,r="";return"string"==typeof e?r=e:Array.isArray(e)&&void 0!==e[0]&&(r=String(e[0])),r?this.config.allCampaignsMap.byId[r]:void 0}},i.prototype.buildHeader=function(t,i){var n=this,e=document.createElement("div");e.className="header-container-ms3";var r=document.createElement("div");if(r.className="header-content-ms3",i){var s=document.createElement("span");s.className="progress-badge-ms3",s.textContent=i,r.appendChild(s)}var o=document.createElement("p");if(o.className="heading-ms3",o.innerHTML=t,r.appendChild(o),e.appendChild(r),this.data.progressBarIcon){var u=document.createElement("img");u.className="dropdown-icon-ms3",u.src=this.data.progressBarIcon;var a=this.data.progressBarIcon;this.bindEvent(u,"error",function(){return n.config.logger.error("DynamicMultistep3 dropdown icon failed to load",{src:a})},{once:!0}),e.appendChild(u)}return e},i.prototype.buildStepDiv=function(t,i,n,e){var r=document.createElement("div");r.className="step-ms3";var s=document.createElement("div"),o="circle-ms3";i?o+=" completed":n&&(o+=" current"),s.className=o;var u=document.createElement("span");if(u.className=n?"amount-ms3 current":"amount-ms3",u.textContent=t,s.appendChild(u),r.appendChild(s),e){var a=document.createElement("div");a.className=i?"connector-ms3 completed":"connector-ms3";var c=document.createElement("div");c.className="connector-progress-ms3",a.appendChild(c),r.appendChild(a)}return r},i.prototype.buildStepsContainer=function(t,i,n){var e=this,r=document.createElement("div");return r.className="steps-container-ms3",i.forEach(function(s,o){var u,a,c,h=null!==(u=t.find(function(t){return t.step===s&&"pristine"===t.state}))&&void 0!==u?u:t.find(function(t){return t.step===s}),d=null!==(c=null===(a=null==h?void 0:h.progressBar)||void 0===a?void 0:a.progressRewardText)&&void 0!==c?c:"",f=s<n,l=s===n;r.appendChild(e.buildStepDiv(d,f,l,o<i.length-1))}),r},i.prototype.buildCtaButton=function(t){var i=this,n=document.createElement("div");n.className="button-container-ms3";var e=document.createElement("button");e.className="action-button-ms3",e.textContent=t,this.bindEvent(e,"click",function(t){t.stopPropagation(),t.preventDefault(),i.handleClick()});var r=document.createElement("div");return r.className="shine-effect",n.appendChild(e),n.appendChild(r),n},i.prototype.createElement=function(t){var i,n,e,r,s=this,o=null==t?void 0:t.banner,u=null!==(i=null==o?void 0:o.stepCompleted)&&void 0!==i?i:0,a=null!==(n=null==o?void 0:o.userCampaignStatus)&&void 0!==n?n:"pristine",c=null!==(e=this.data.IWidgetState)&&void 0!==e?e:[],h=this.findWidgetState(u,a,c);this.data.widgetCss&&this.addHeadStyle(this.data.widgetCss);var d=document.createElement("div");d.className="content-container-ms3";var f=document.createElement("div");f.className="main-content-ms3";var l=we([],pe(new Set(c.map(function(t){return t.step}))),!1).sort(function(t,i){return t-i});if(l.length>0&&f.appendChild(this.buildStepsContainer(c,l,u)),null==h?void 0:h.body){var v=document.createElement("p");v.className="description-ms3",v.textContent=h.body,f.appendChild(v)}(null==h?void 0:h.ctaText)&&f.appendChild(this.buildCtaButton(h.ctaText)),d.appendChild(f);var m=this.buildHeader(null!==(r=null==h?void 0:h.title)&&void 0!==r?r:"",null==h?void 0:h.badgeTag);this.bindEvent(m,"click",function(t){t.stopPropagation(),s.isExpanded=!s.isExpanded,d.classList.toggle("hidden",!s.isExpanded)});var g=document.createElement("div");g.className="banner-container-ms3",g.appendChild(m),g.appendChild(d);var p=document.createElement("div");p.className="card-container-ms3",p.appendChild(g),this.element=p},i.prototype.findWidgetState=function(t,i,n){var e,r;return null!==(r=null!==(e=n.find(function(n){return n.step===t&&n.state===i}))&&void 0!==e?e:n.find(function(i){return i.step===t}))&&void 0!==r?r:n[0]},i.prototype.handleClick=function(){var t=this.data.action;if(t&&"TOGGLE_CONTAINER_CONTENT"===t.type&&this.sdkEventListener){var i={target:"GLU_SDK",action:le(le({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(xa),Ya=function(t){function i(i,n){var e=t.call(this,n)||this;if(!i.url)throw new Error("NUDGE content missing `url`");return e.element=ja(e.urlModifier(i.url),n.onLoad,function(){return n.logger.error("Nudge iframe failed to load",{src:i.url})}),e}return fe(i,t),i}(xa),Ja=function(t){function i(i,n){var e=t.call(this,n)||this;if(!i.campaignId)throw new Error("PROGRAM content missing `campaignId`");var r="".concat(e.config.allCampaignsMap.base,"/program/?campaignId=").concat(i.campaignId);return e.element=ja(e.urlModifier(r,{token:!0}),n.onLoad,function(){return n.logger.error("Program iframe failed to load",{src:r})}),e}return fe(i,t),i}(xa),Qa=function(t){function i(i,n){var e=t.call(this,n)||this;if(!i.rewardUserId)throw new Error("REWARD content missing `rewardUserId`");var r="".concat(e.config.allCampaignsMap.base,"/reward/?rewardUserId=").concat(i.rewardUserId);return e.element=ja(e.urlModifier(r,{token:!0}),n.onLoad,function(){return n.logger.error("Reward iframe failed to load",{src:r})}),e}return fe(i,t),i}(xa),$a=function(t){function i(i,n){var e=t.call(this,n)||this;if(e.actionId=ma(),e.data=i,e.shouldGateOnCampaign()){var r=e.extractGatedCampaignId();return r&&e.config.allCampaignsMap.byId[r]&&e.createElement(),e}return e.createElement(),e}return fe(i,t),i.prototype.shouldGateOnCampaign=function(){var t,i,n,e=this.data.action;return!(!e||"TOGGLE_CONTAINER_CONTENT"!==e.type)&&("CAMPAIGN"===(null===(t=e.content)||void 0===t?void 0:t.typeId)&&void 0!==(null===(n=null===(i=e.content)||void 0===i?void 0:i.conditions)||void 0===n?void 0:n.campaignId))},i.prototype.extractGatedCampaignId=function(){var t,i;if("TOGGLE_CONTAINER_CONTENT"!==(null===(t=this.data.action)||void 0===t?void 0:t.type))return null;var n=null===(i=this.data.action.content.conditions)||void 0===i?void 0:i.campaignId;return"string"==typeof n?n:Array.isArray(n)&&void 0!==n[0]?String(n[0]):null},i.prototype.createElement=function(){var t=this;if(!this.data.src)throw new Error("STATIC content missing `src`");var i=document.createElement("img");i.style.maxWidth="100%",i.style.maxHeight="100%",i.style.display="block",i.style.cursor="pointer";var n=this.config.onLoad;if(n){var e=performance.now();this.bindEvent(i,"load",function(){return n(performance.now()-e)},{once:!0})}this.bindEvent(i,"error",function(){return t.config.logger.error("Static image failed to load",{src:t.data.src})},{once:!0}),i.src=this.data.src,this.bindEvent(i,"click",function(i){i.stopPropagation(),i.preventDefault();var n=t.data.action;if(n&&t.sdkEventListener){var e={target:"GLU_SDK",action:"TOGGLE_CONTAINER_CONTENT"===n.type?le(le({},n),{id:t.actionId}):n};t.sdkEventListener(e)}}),this.element=i},i}(xa),Za=function(t){function i(i,n){var e=t.call(this,n)||this;return e.element=ja(e.urlModifier(e.config.allCampaignsMap.defaultUrl),n.onLoad,function(){return n.logger.error("Wallet iframe failed to load",{src:e.config.allCampaignsMap.defaultUrl})}),e}return fe(i,t),i}(xa);var tc=function(){function t(t,i){var n=this;this.sdkEventListener=null,this.closeListener=null,this.loaderTimeout=null,this.contentReady=!1,this.entryPoint=t,this.onOpen=i.onOpen;var e=le(le(le(le({},i),{isEmbedded:"EMBEDDED"===t.container.typeId}),void 0!==t.content.rootId&&{rootId:t.content.rootId}),{onLoad:function(t){var e;n.hideLoader(),null===(e=i.onLoad)||void 0===e||e.call(i,t)}});if(this.content=function(t,i){var n=t.content;switch(n.typeId){case"CAMPAIGN":return new Ha(n,i);case"WALLET":return new Za(n,i);case"NUDGE":return new Ya(n,i);case"PROGRAM":return new Ja(n,i);case"REWARD":return new Qa(n,i);case"STATIC":return new $a(n,i);case"DYNAMIC":return new qa(n,i);case"DYNAMIC_MULTISTEP_1":return new Ka(n,i);case"DYNAMIC_MULTISTEP_2":return new Wa(n,i);case"DYNAMIC_MULTISTEP_3":return new Xa(n,i);case"ACCEPT_GUARD":return new za(n,i);default:var e=n.typeId;throw new Error("Unknown content typeId: ".concat(String(e)))}}(t,e),!this.content.element)throw new Error("Content ".concat(t.content.typeId," did not produce an element"));this.container=function(t,i,n,e,r){var s=t.container,o=le({typeId:s.typeId,css:s.css,logger:n,darkMode:e},void 0!==r&&{onShown:r});switch(s.typeId){case"ICON_BUTTON":return new Da(o,i);case"CHAT_BOX":return new Ea(o,i);case"POP_UP":return new ka(le(le({},o),{height:s.height}),i);case"BOTTOM_SHEET":return new ya(le(le({},o),{height:s.height}),i);case"NATIVE_BANNER":return new Oa(le(le({},o),{elementHookId:s.elementHookId}),i);case"EMBEDDED":return new Na(le(le({},o),{elementHookId:s.elementHookId}),i);default:var u=s.typeId;throw new Error("Unknown container typeId: ".concat(String(u)))}}(t,this.content.element,i.logger,i.darkMode,function(){var t;return null===(t=n.onOpen)||void 0===t?void 0:t.call(n,n.entryPoint)}),this.content.listen(function(t){var i;return null===(i=n.sdkEventListener)||void 0===i?void 0:i.call(n,t)}),this.container.addCloseListener(function(){var t;return null===(t=n.closeListener)||void 0===t?void 0:t.call(n)})}return Object.defineProperty(t.prototype,"containerTypeId",{get:function(){return this.entryPoint.container.typeId},enumerable:!1,configurable:!0}),t.prototype.addEventListener=function(t){this.sdkEventListener=t},t.prototype.addCloseEventListener=function(t){this.closeListener=t},t.prototype.open=function(){var t=this;this.container.show(),this.contentReady||(this.container.showLoader(),this.clearLoaderTimeout(),this.loaderTimeout=setTimeout(function(){return t.hideLoader()},8e3))},t.prototype.preload=function(){this.container.preload()},t.prototype.close=function(){this.container.hide(),this.clearLoaderTimeout()},t.prototype.toggle=function(){this.isOpen()?this.close():this.open()},t.prototype.isOpen=function(){return this.container.isVisible()},t.prototype.sendMessage=function(t){this.content.sendMessageToContent(t)},t.prototype.sendRawMessage=function(t){this.content.sendRawMessage(t)},t.prototype.setHeight=function(t){this.container.setHeight(t)},t.prototype.hideLoader=function(){this.contentReady=!0,this.container.hideLoader(),this.content.reveal(),this.clearLoaderTimeout()},t.prototype.clearLoaderTimeout=function(){null!==this.loaderTimeout&&(clearTimeout(this.loaderTimeout),this.loaderTimeout=null)},t.prototype.destroy=function(){this.clearLoaderTimeout(),this.container.destroy(),this.content.destroy(),this.sdkEventListener=null,this.closeListener=null,this.onOpen=void 0},t}(),ic=function(){function t(){var t=this;this.windowToEmbed=new Map,this.listenerInstalled=!1,this.handleMessage=function(i){var n,e,r,s,o,u,a,c,h=i.source?t.windowToEmbed.get(i.source):void 0;if(h){var d=Aa(i.data);if(d)switch(d.action.type){case"DIMENSIONS_UPDATE":var f=null!==(e=null===(n=d.action.data.data)||void 0===n?void 0:n.height)&&void 0!==e?e:d.action.data.height;"number"==typeof f&&pa(h.host,f);break;case"CLOSE":case"CLOSE_CONTAINER_CONTENT":t.removeEmbed(i.source,h);break;case"OPEN_DEEPLINK":t.handleOpenDeepLink(d.action.data,i.source,h);break;case"REQUEST_API_DATA":t.replyToEmbed(h.iframe,{eventName:"REQUEST_API_RESULT",data:{requestId:null!==(s=null===(r=d.action.data)||void 0===r?void 0:r.requestId)&&void 0!==s?s:""}});break;case"OPEN_WALLET":null===(u=null===(o=t.callbacks)||void 0===o?void 0:o.onOpenWallet)||void 0===u||u.call(o);break;case"OPEN_CG_WEBVIEW":null===(c=null===(a=t.callbacks)||void 0===a?void 0:a.onOpenCgWebView)||void 0===c||c.call(a,d.action.data)}}}}return t.prototype.render=function(t,i,n,e){var r,s;if("undefined"!=typeof document){this.callbacks=n,this.windowToEmbed.clear(),document.querySelectorAll("[data-glu-loyalty]").forEach(function(t){t.remove()});try{for(var o=ge(t),u=o.next();!u.done;u=o.next()){var a=u.value,c=document.getElementById(a.embedId);c&&this.injectIframe(c,this.buildUrl(a.url,i,e),a.embedId,n)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(s=o.return)&&s.call(o)}finally{if(r)throw r.error}}this.installMessageListener()}},t.prototype.buildUrl=function(t,i,n){var e=t,r=t.includes("?");return i&&(e+="".concat(r?"&":"?","capToken=").concat(encodeURIComponent(i)),r=!0),void 0!==n&&(e+="".concat(r?"&":"?","darkMode=").concat(n),r=!0),this.hasQueryParam(t,"isEmbedded")||(e+="".concat(r?"&":"?","isEmbedded=true")),e},t.prototype.hasQueryParam=function(t,i){var n,e;return(null!==(e=null===(n=t.split("?")[1])||void 0===n?void 0:n.split("#")[0])&&void 0!==e?e:"").split("&").some(function(t){var n;return(null===(n=t.split("=")[0])||void 0===n?void 0:n.toLowerCase())===i.toLowerCase()})},t.prototype.injectIframe=function(t,i,n,e){var r,s=document.createElement("iframe");s.src=i,s.setAttribute("data-glu-loyalty",n),s.style.cssText="border:none;width:100%;height:100%;opacity:0;transition:opacity 150ms ease;";var o=function(){s.style.opacity="1"},u=null==e?void 0:e.onLoad,a=performance.now();s.addEventListener("load",function(){o(),null==u||u(n,performance.now()-a)},{once:!0}),s.addEventListener("error",o,{once:!0}),t.appendChild(s),s.contentWindow&&this.windowToEmbed.set(s.contentWindow,{host:t,iframe:s,embedId:n}),null===(r=null==e?void 0:e.onOpen)||void 0===r||r.call(e,n)},t.prototype.installMessageListener=function(){this.listenerInstalled||"undefined"==typeof window||(this.listenerInstalled=!0,window.addEventListener("message",this.handleMessage))},t.prototype.handleOpenDeepLink=function(t,i,n){var e,r,s=Eu(t),o=s.deepLink,u=s.isHandledByCG,a=s.closeOnDeepLink;null===(r=null===(e=this.callbacks)||void 0===e?void 0:e.onDeepLinkEvent)||void 0===r||r.call(e,s),"true"===String(u).toLowerCase()&&"undefined"!=typeof window&&Du(o)&&(window.location.href=o),"true"===String(a).toLowerCase()&&this.removeEmbed(i,n)},t.prototype.removeEmbed=function(t,i){i.iframe.remove(),this.windowToEmbed.delete(t)},t.prototype.replyToEmbed=function(t,i){var n=t.contentWindow;if(n&&"function"==typeof n.postMessage&&t.src)try{n.postMessage(i,new URL(t.src).origin)}catch(t){}},t}(),nc=function(){function t(t,i,n,e,r,s){this.initialized=!1,this.userId=null,this.userAttributes=void 0,this.token=null,this.allCampaignsMap=null,this.entryPointMap=null,this.instances=new Map,this.dataDump=null,this.callback=null,this.lastSyncTimestamp=0,this.spaListenerCleanup=null,this.visibilityListenerCleanup=null,this.capToken=null,this.loyaltyRenderer=new ic,this.pagePathTrackingEnabled=!0,this.manualScreenName=null,this.pagePathTrackingExplicitlySet=!1,this.suppressed=!1,this.suppressedExplicitlySet=!1,this.theme="NONE",this.themeExplicitlySet=!1,this.tokenRefetchInFlight=null,this.authFailureCount=0,this.authBackoffUntil=0,this.pendingTimers=new Set,this.delayedOpenTimers=new Map,this.pendingShownRecordIds=new Set,this.openedCampaignIds=new Set,this.initGeneration=0,this.syncGeneration=0,this.preconnectedOrigins=new Set,this.swPreloaded=!1,this.trackingState=new Map,this.eventEntryPointMap=new Map,this.campaignQueue=new $u,this.openOverlayEntryPointId=null,this.openOverlayIds=new Set,this.ephemeralEntryPointIds=new Set,this.adHocEntryPointIds=new Set,this.adHocToggleSourceEmbedId=new Map,this.writeKey=t,this.baseUrl=i,this.logger=n,this.storageManager=e,this.apiClient=new lu(i,n),this.trackEvent=r,this.getSessionId=s}return t.prototype.initialize=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h,d,f,l,v,m,g,p,w,y,E;return me(this,function(_){switch(_.label){case 0:this.initialized&&(this.logger.info("GamificationManager re-initializing for new user",{userId:t}),this.clean()),this.logger.info("GamificationManager initializing",{userId:t}),n=++this.initGeneration,_.label=1;case 1:return _.trys.push([1,8,,9]),this.userId=t,this.userAttributes=i,this.preconnectFromCachedOrigin(),[4,Promise.all([this.storageManager.get(tu),this.loadFromCache(t)])];case 2:return e=pe.apply(void 0,[_.sent(),2]),r=e[0],s=e[1],n!==this.initGeneration?[2]:(r&&(this.capToken=r),s?(this.logger.info(Zs,{campaigns:null!==(a=null===(u=this.allCampaignsMap)||void 0===u?void 0:u.allIds.length)&&void 0!==a?a:0,entryPoints:null!==(h=null===(c=this.entryPointMap)||void 0===c?void 0:c.allIds.length)&&void 0!==h?h:0}),[3,5]):[3,3]);case 3:return this.logger.info(to),[4,this.fetchAndCache(t,i,n)];case 4:if(!_.sent())return[2];_.label=5;case 5:return this.entryPointMap&&(null===(f=null===(d=this.callback)||void 0===d?void 0:d.onEntryPointsLoaded)||void 0===f||f.call(d,Object.values(this.entryPointMap.byId))),this.preloadEntryPoints(),this.initialized=!0,this.logger.info(qs,{campaigns:null!==(v=null===(l=this.allCampaignsMap)||void 0===l?void 0:l.allIds.length)&&void 0!==v?v:0,entryPoints:null!==(g=null===(m=this.entryPointMap)||void 0===m?void 0:m.allIds.length)&&void 0!==g?g:0}),null===(w=null===(p=this.callback)||void 0===p?void 0:p.onInitSuccess)||void 0===w||w.call(p),[4,this.restorePersistedActionEventQueue(t)];case 6:return _.sent(),n!==this.initGeneration?[2]:[4,this.refresh()];case 7:return _.sent(),n!==this.initGeneration?[2]:(this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode()),this.registerSpaListener(),this.registerVisibilityListener(),[3,9]);case 8:return o=_.sent(),this.logger.error(Ks,o),null===(E=null===(y=this.callback)||void 0===y?void 0:y.onInitFailure)||void 0===E||E.call(y,{code:Pe,message:Ks,cause:o}),[3,9];case 9:return[2]}})})},t.prototype.getCampaignsMap=function(){return this.allCampaignsMap},t.prototype.getEntryPointMap=function(){return this.entryPointMap},t.prototype.getToken=function(){return this.token},t.prototype.setCapToken=function(t){this.capToken=t,this.storageManager.set(tu,t).catch(function(){}),this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode())},t.prototype.getCapToken=function(){return this.capToken},t.prototype.enablePagePathTracking=function(t){this.logger.info("Page path tracking mode changed",{enabled:t}),this.pagePathTrackingEnabled=t,this.pagePathTrackingExplicitlySet=!0,this.storageManager.set(iu,String(t)).catch(function(){}),this.refresh()},t.prototype.restorePersistedPagePathTracking=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(iu)];case 1:return null===(t=i.sent())||this.pagePathTrackingExplicitlySet||(this.pagePathTrackingEnabled="true"===t),[2]}})})},t.prototype.onScreenChanged=function(t){this.manualScreenName=t,this.pagePathTrackingEnabled||this.handleScreenChange()},t.prototype.setGamificationCallback=function(t){this.callback=t},t.prototype.setGamificationSuppressed=function(t){var i=this,n=this.suppressed;this.logger.info("Gamification suppression changed",{suppressed:t}),this.suppressed=t,this.suppressedExplicitlySet=!0,this.storageManager.set(nu,String(t)).catch(function(t){i.logger.error(uo,{error:t})}),n&&!t?this.refresh():!n&&t&&this.closeSuppressedInstances()},t.prototype.closeSuppressedInstances=function(){var t,i;try{for(var n=ge(this.instances.values()),e=n.next();!e.done;e=n.next()){var r=e.value;r.isOpen()&&this.isEffectivelySuppressed(r.entryPoint)&&this.closeIfOpen(r.entryPoint)}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}this.closeAdHocEntryPoints()},t.prototype.isContentOpenSuppressed=function(t){return!!this.isEffectivelySuppressed(t)&&(this.logger.debug(ao,{entryPointId:t.id,containerTypeId:t.container.typeId}),!0)},t.prototype.isGamificationSuppressed=function(){return this.suppressed},t.prototype.restorePersistedGamificationSuppressed=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(nu)];case 1:return null===(t=i.sent())||this.suppressedExplicitlySet||(this.suppressed="true"===t),[2]}})})},t.prototype.setTheme=function(i){var n=this;t.VALID_THEMES.includes(i)?(this.logger.info("Gamification theme changed",{theme:i}),this.theme=i,this.themeExplicitlySet=!0,this.storageManager.set(eu,i).catch(function(t){n.logger.error(co,{error:t})}),this.invalidateUnopenedInstances(),this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode())):this.logger.warn("Invalid theme value, ignoring",{theme:i})},t.prototype.invalidateUnopenedInstances=function(){var t,i,n,e,r,s=[];try{for(var o=ge(this.instances),u=o.next();!u.done;u=o.next()){var a=pe(u.value,2),c=a[0],h=a[1],d=!!(v=null===(r=this.entryPointMap)||void 0===r?void 0:r.byId[c])&&wu(v);h.isOpen()&&!d||(d&&h.isOpen()&&v&&!this.isCampaignCompleted(v)&&s.push(v),h.destroy(),this.instances.delete(c))}}catch(i){t={error:i}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}this.preloadEntryPoints();try{for(var f=ge(s),l=f.next();!l.done;l=f.next()){var v=l.value;this.openInstance(v)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(e=f.return)&&e.call(f)}finally{if(n)throw n.error}}},t.prototype.restorePersistedTheme=function(){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return[4,this.storageManager.get(eu)];case 1:return null!==(i=n.sent())&&!this.themeExplicitlySet&&t.VALID_THEMES.includes(i)&&(this.theme=i),[2]}})})},t.prototype.resolveDarkMode=function(){switch(this.theme){case"LIGHT":return!1;case"DARK":return!0;case"AUTO":return"undefined"!=typeof window&&"function"==typeof window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches;default:return}},t.prototype.openEntryPoint=function(t){if(this.initialized){var i=this.getOrCreateInstance(t);i?(Cu(i.entryPoint)&&this.openOverlayIds.add(t),i.open()):this.logger.error("openEntryPoint() could not resolve an entry point instance",{entryPointId:t})}else this.logger.error("openEntryPoint() called before GamificationManager is initialized",{entryPointId:t})},t.prototype.closeEntryPoint=function(t){if(this.initialized){var i=this.instances.get(t);i||this.logger.warn("closeEntryPoint() found no open instance for this entry point",{entryPointId:t}),null==i||i.close(),this.onCampaignClosed(t)}else this.logger.warn("closeEntryPoint() called before GamificationManager is initialized",{entryPointId:t})},t.prototype.forceSync=function(){var t=this;return this.initialized?this.resyncData().then(function(){t.refresh()}):(this.logger.error("forceSync() called before GamificationManager is initialized"),Promise.resolve())},t.prototype.clean=function(){var t,i,n,e,r,s;this.logger.info(Xs),this.initGeneration++,this.syncGeneration++,null===(r=this.spaListenerCleanup)||void 0===r||r.call(this),this.spaListenerCleanup=null,null===(s=this.visibilityListenerCleanup)||void 0===s||s.call(this),this.visibilityListenerCleanup=null,this.lastSyncTimestamp=0;try{for(var o=ge(this.pendingTimers),u=o.next();!u.done;u=o.next()){var a=u.value;clearTimeout(a)}}catch(i){t={error:i}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}this.pendingTimers.clear(),this.delayedOpenTimers.clear(),this.pendingShownRecordIds.clear(),this.openedCampaignIds.clear();try{for(var c=ge(this.instances.values()),h=c.next();!h.done;h=c.next()){var d=h.value;d.isOpen()&&d.close(),d.destroy()}}catch(t){n={error:t}}finally{try{h&&!h.done&&(e=c.return)&&e.call(c)}finally{if(n)throw n.error}}this.instances.clear(),this.trackingState.clear(),this.eventEntryPointMap.clear(),this.campaignQueue.clear(),this.openOverlayEntryPointId=null,this.openOverlayIds.clear(),this.ephemeralEntryPointIds.clear(),this.adHocEntryPointIds.clear(),this.adHocToggleSourceEmbedId.clear(),this.userId&&(this.storageManager.remove(this.cacheKey(this.userId)).catch(function(){}),this.storageManager.remove(this.tokenCacheKey(this.userId)).catch(function(){}),this.storageManager.remove(this.queueStorageKey(this.userId)).catch(function(){})),this.userId=null,this.userAttributes=void 0,this.token=null,this.tokenRefetchInFlight=null,this.authFailureCount=0,this.authBackoffUntil=0,this.allCampaignsMap=null,this.entryPointMap=null,this.dataDump=null,this.capToken=null,this.storageManager.remove(tu).catch(function(){}),this.initialized=!1},t.prototype.destroy=function(){this.clean(),this.logger.info(Ws)},Object.defineProperty(t.prototype,"loyaltyUrls",{get:function(){var t,i;return null!==(i=null===(t=this.allCampaignsMap)||void 0===t?void 0:t.loyaltyUrls)&&void 0!==i?i:[]},enumerable:!1,configurable:!0}),t.prototype.resolveCurrentPath=function(){var t;return this.pagePathTrackingEnabled?"undefined"!=typeof window?window.location.href:"":null!==(t=this.manualScreenName)&&void 0!==t?t:""},t.prototype.refresh=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:if(!this.entryPointMap)return[2];t=this.resolveCurrentPath(),this.logger.info(Js,{entryPoints:this.entryPointMap.allIds.length,url:t}),this.campaignQueue.clearScreenTriggered(),i={},n={},e=this.entryPointMap,r=this.initGeneration,f.label=1;case 1:f.trys.push([1,6,7,8]),s=ge(this.orderedEntryPointIds(e)),o=s.next(),f.label=2;case 2:return o.done?[3,5]:(u=o.value,r!==this.initGeneration?[2]:!(a=e.byId[u])||Iu(a)?[3,4]:[4,this.refreshEntryPoint(a,i,n)]);case 3:f.sent(),f.label=4;case 4:return o=s.next(),[3,2];case 5:return[3,8];case 6:return c=f.sent(),h={error:c},[3,8];case 7:try{o&&!o.done&&(d=s.return)&&d.call(s)}finally{if(h)throw h.error}return[7];case 8:return this.showNextFromQueue(),[2]}})})},t.prototype.orderedEntryPointIds=function(t){var i=function(i){var n=t.byId[i];return n&&wu(n)?n.container.elementHookId:null};return we([],pe(t.allIds),!1).sort(function(n,e){var r,s,o,u,a,c,h=i(n),d=i(e);if(!h||!d||h!==d)return 0;var f=t.byId[n],l=t.byId[e],v=(null!==(s=null===(r=null==l?void 0:l.conditions)||void 0===r?void 0:r.priority)&&void 0!==s?s:0)-(null!==(u=null===(o=null==f?void 0:f.conditions)||void 0===o?void 0:o.priority)&&void 0!==u?u:0);return 0!==v?v:(null!==(a=null==l?void 0:l.createdAt)&&void 0!==a?a:"").localeCompare(null!==(c=null==f?void 0:f.createdAt)&&void 0!==c?c:"")})},t.prototype.refreshEntryPoint=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:return e=Cu(t),r=null===(u=t.conditions)||void 0===u?void 0:u.singleOpenName,!e&&r&&i[r]?[2]:(s=wu(t)?t.container.elementHookId:null)&&n[s]?[2]:!Iu(t)&&this.isCampaignCompleted(t)?(this.closeIfOpen(t),[2]):[4,this.isDismissedThisSession(t)];case 1:return a.sent()?(this.cancelDelayedOpen(t.id),[2]):(o=this.isEffectivelySuppressed(t),[4,Qu(t,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())]);case 2:return a.sent()?(o||(!e&&r&&(i[r]=!0),s&&(n[s]=!0),this.scheduleOpenOrEnqueue(t,e)),[2]):(this.closeIfOpen(t),[2])}})})},t.prototype.isEffectivelySuppressed=function(t){return this.suppressed&&!wu(t)},t.prototype.scheduleOpenOrEnqueue=function(t,i){var n,e=this,r=null===(n=t.conditions)||void 0===n?void 0:n.delay;if(r){this.cancelDelayedOpen(t.id);var s=setTimeout(function(){e.pendingTimers.delete(s),e.delayedOpenTimers.delete(t.id),e.fireDelayedOpen(t.id)},1e3*r);this.pendingTimers.add(s),this.delayedOpenTimers.set(t.id,s)}else this.openOrEnqueue(t,i)},t.prototype.cancelDelayedOpen=function(t){var i=this.delayedOpenTimers.get(t);void 0!==i&&(clearTimeout(i),this.pendingTimers.delete(i),this.delayedOpenTimers.delete(t))},t.prototype.fireDelayedOpen=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:return(i=null===(e=this.entryPointMap)||void 0===e?void 0:e.byId[t])?!Iu(i)&&this.isCampaignCompleted(i)?[2]:[4,this.isDismissedThisSession(i)]:[2];case 1:return r.sent()||this.isEffectivelySuppressed(i)?[2]:[4,Qu(i,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())];case 2:return r.sent()?(n=Cu(i),this.openOrEnqueue(i,n),n&&this.showNextFromQueue(),[2]):[2]}})})},t.prototype.openOrEnqueue=function(t,i){if(!i){if(this.isEffectivelySuppressed(t))return;var n=this.instances.get(t.id);if(null==n?void 0:n.isOpen())return;var e=this.getOrCreateInstance(t.id);if(!e)return;return this.recordEntryPointShownIfEligible(t),void e.open()}this.openOverlayEntryPointId!==t.id&&this.enqueueCampaign(t)},t.prototype.closeIfOpen=function(t){this.cancelDelayedOpen(t.id);var i=this.instances.get(t.id);(null==i?void 0:i.isOpen())&&i.close(),this.onCampaignClosed(t.id)},t.prototype.openInstance=function(t){var i=this.getOrCreateInstance(t.id);i&&(Cu(t)&&this.openOverlayIds.add(t.id),i.open())},t.prototype.notifyCampaignOpened=function(t){var i,n,e=Ou(t);!e&&this.ephemeralEntryPointIds.has(t.id)||(this.openedCampaignIds.add(t.id),null===(n=null===(i=this.callback)||void 0===i?void 0:i.onCampaignOpened)||void 0===n||n.call(i,null!=e?e:t.id))},t.prototype.enqueueCampaign=function(t){this.campaignQueue.enqueue([t]),this.persistActionEventQueue()},t.prototype.showNextFromQueue=function(){var t,i;if(!(this.openOverlayIds.size>0||this.suppressed))try{for(var n=ge(this.campaignQueue.entries()),e=n.next();!e.done;e=n.next()){var r=e.value,s=this.getOrCreateInstance(r.id);if(s)return this.campaignQueue.remove(r.id),this.openOverlayEntryPointId=r.id,this.openOverlayIds.add(r.id),this.persistActionEventQueue(),this.recordEntryPointShownIfEligible(r),void s.open()}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}},t.prototype.recordEntryPointShownIfEligible=function(t){this.isEffectivelySuppressed(t)||(!wu(t)||function(t){return"undefined"!=typeof document&&null!==document.querySelector("#".concat(t.container.elementHookId))}(t)?this.persistEntryPointShown(t):this.pendingShownRecordIds.add(t.id))},t.prototype.recordPendingShownIfAny=function(t){this.pendingShownRecordIds.delete(t.id)&&this.persistEntryPointShown(t)},t.prototype.persistEntryPointShown=function(t){var i=this;(function(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:return Iu(t)?[2]:(r=null===(c=t.conditions)||void 0===c?void 0:c.showCount)?(s=new Date,[4,Ku(t.id,i,n,e)]):[2];case 1:o=h.sent(),u=!r.dailyRefresh||o&&Wu(s,new Date(o.date))?{count:o?o.count+1:1,date:s.toISOString()}:{count:1,date:s.toISOString()},h.label=2;case 2:return h.trys.push([2,4,,5]),[4,n.set(qu(t.id,i),JSON.stringify(u))];case 3:return h.sent(),[3,5];case 4:return a=h.sent(),e.error(So,{entryPointId:t.id,error:a}),[3,5];case 5:return[2]}})})})(t,this.userId,this.storageManager,this.logger).catch(function(n){i.logger.error(So,{entryPointId:t.id,error:n})})},t.prototype.onCampaignClosed=function(t){var i,n,e,r;if(this.openOverlayIds.delete(t),this.openedCampaignIds.delete(t)){var s=null===(i=this.entryPointMap)||void 0===i?void 0:i.byId[t];null===(e=null===(n=this.callback)||void 0===n?void 0:n.onCampaignClosed)||void 0===e||e.call(n,s&&null!==(r=Ou(s))&&void 0!==r?r:t)}this.openOverlayEntryPointId===t&&(this.openOverlayEntryPointId=null),0===this.openOverlayIds.size&&this.showNextFromQueue()},t.prototype.sessionDismissedKeyPrefix=function(t,i){return"".concat(Ko).concat(t,"_").concat(i,"_")},t.prototype.sessionDismissedKey=function(t,i,n){return"".concat(this.sessionDismissedKeyPrefix(t,i)).concat(n)},t.prototype.isDismissedThisSession=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(wu(t)||Iu(t))return[2,!1];if(!(i=this.getSessionId())||!this.userId)return[2,!1];o.label=1;case 1:return o.trys.push([1,3,,4]),n=this.sessionDismissedKey(this.userId,t.id,this.resolveCurrentPath()),[4,this.storageManager.get(n)];case 2:return(e=o.sent())?[2,"object"==typeof(r=JSON.parse(e))&&null!==r&&r.sessionId===i]:[2,!1];case 3:return s=o.sent(),this.logger.error(ho,{entryPointId:t.id,error:s}),[2,!1];case 4:return[2]}})})},t.prototype.recordSessionDismissal=function(t){var i,n=this,e=null===(i=this.entryPointMap)||void 0===i?void 0:i.byId[t];if(e&&!wu(e)&&!Iu(e)){var r=this.getSessionId();if(r&&this.userId){var s=this.sessionDismissedKey(this.userId,t,this.resolveCurrentPath());this.storageManager.set(s,JSON.stringify({sessionId:r})).catch(function(i){n.logger.error(fo,{entryPointId:t,error:i})})}}},t.prototype.queueStorageKey=function(t){return qo+t},t.prototype.persistActionEventQueue=function(){var t=this;if(this.userId){var i=this.campaignQueue.entries().filter(function(t){return Iu(t)}).map(function(t){return t.id}),n=this.queueStorageKey(this.userId);0!==i.length?this.storageManager.set(n,JSON.stringify(i)).catch(function(i){t.logger.error(lo,{error:i})}):this.storageManager.remove(n).catch(function(){})}},t.prototype.restorePersistedActionEventQueue=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h;return me(this,function(d){switch(d.label){case 0:if(!this.entryPointMap)return[2];d.label=1;case 1:return d.trys.push([1,11,,12]),[4,this.storageManager.get(this.queueStorageKey(t))];case 2:if(!(i=d.sent()))return[2];if(n=JSON.parse(i),!Array.isArray(n))return[2];d.label=3;case 3:d.trys.push([3,8,9,10]),e=ge(n),r=e.next(),d.label=4;case 4:return r.done?[3,7]:"string"!=typeof(s=r.value)?[3,6]:(o=this.entryPointMap.byId[s])&&Iu(o)?[4,Qu(o,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())]:[3,6];case 5:d.sent()&&this.campaignQueue.enqueue([o]),d.label=6;case 6:return r=e.next(),[3,4];case 7:return[3,10];case 8:return u=d.sent(),c={error:u},[3,10];case 9:try{r&&!r.done&&(h=e.return)&&h.call(e)}finally{if(c)throw c.error}return[7];case 10:return this.persistActionEventQueue(),[3,12];case 11:return a=d.sent(),this.logger.error(vo,{error:a}),[3,12];case 12:return[2]}})})},t.prototype.buildEventIndex=function(){var t,i,n;if(this.eventEntryPointMap.clear(),this.entryPointMap){this.entryPointMap.allIds.includes("")&&this.logger.error(mo,{totalEntryPoints:this.entryPointMap.allIds.length});try{for(var e=ge(this.entryPointMap.allIds),r=e.next();!r.done;r=e.next()){var s=r.value,o=this.entryPointMap.byId[s],u=o?Tu(o):null;if(u){var a=null!==(n=this.eventEntryPointMap.get(u))&&void 0!==n?n:new Set;a.add(s),this.eventEntryPointMap.set(u,a)}}}catch(i){t={error:i}}finally{try{r&&!r.done&&(i=e.return)&&i.call(e)}finally{if(t)throw t.error}}}},t.prototype.handleActionEvent=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l;return me(this,function(v){switch(v.label){case 0:if(!this.initialized||!t||!this.entryPointMap)return[2];if(!(i=this.eventEntryPointMap.get(t))||0===i.size)return null===(l=null===(f=this.callback)||void 0===f?void 0:f.onGameEventTrigger)||void 0===l||l.call(f,t,{reason:Oo}),[2];v.label=1;case 1:v.trys.push([1,10,,11]),n={},e={},v.label=2;case 2:v.trys.push([2,7,8,9]),r=ge(i),s=r.next(),v.label=3;case 3:return s.done?[3,6]:(o=s.value,(u=this.entryPointMap.byId[o])?[4,this.refreshEntryPoint(u,n,e)]:[3,5]);case 4:v.sent(),v.label=5;case 5:return s=r.next(),[3,3];case 6:return[3,9];case 7:return a=v.sent(),h={error:a},[3,9];case 8:try{s&&!s.done&&(d=r.return)&&d.call(r)}finally{if(h)throw h.error}return[7];case 9:return this.showNextFromQueue(),[3,11];case 10:return c=v.sent(),this.logger.error(oo,{eventName:t,error:c}),[3,11];case 11:return[2]}})})},t.prototype.preloadEntryPoints=function(){var t,i,n;if(this.entryPointMap){this.preconnectToCampaignOrigin(),this.preloadServiceWorker();var e=this.resolveCurrentPath();try{for(var r=ge(this.entryPointMap.allIds),s=r.next();!s.done;s=r.next()){var o=s.value;if(!this.instances.has(o)){var u=this.entryPointMap.byId[o];if(u&&(Iu(u)||!this.isCampaignCompleted(u))&&(Iu(u)||Xu(null===(n=u.conditions)||void 0===n?void 0:n.paths,e))){var a=this.getOrCreateInstance(o);null==a||a.preload()}}}}catch(i){t={error:i}}finally{try{s&&!s.done&&(i=r.return)&&i.call(r)}finally{if(t)throw t.error}}}},t.prototype.preconnectToCampaignOrigin=function(t){var i,n=null!=t?t:null===(i=this.allCampaignsMap)||void 0===i?void 0:i.base;if("undefined"!=typeof document&&n&&!this.preconnectedOrigins.has(n)){this.preconnectedOrigins.add(n);var e=document.createElement("link");e.rel="preconnect",e.href=n,document.head.appendChild(e)}},t.prototype.preconnectFromCachedOrigin=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.storageManager.get(ou)];case 1:return(t=i.sent())&&this.preconnectToCampaignOrigin(t),[3,3];case 2:return i.sent(),[3,3];case 3:return[2]}})})},t.prototype.preloadServiceWorker=function(){var t,i=this;if("undefined"!=typeof document&&(null===(t=this.allCampaignsMap)||void 0===t?void 0:t.base)&&!this.swPreloaded){this.swPreloaded=!0;var n="".concat(this.allCampaignsMap.base).concat(ru),e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.style.cssText="position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;border:0;",e.setAttribute("fetchpriority","low");var r=function(){e.remove(),clearTimeout(s),i.pendingTimers.delete(s)};e.addEventListener("load",function(){return r()},{once:!0});var s=setTimeout(function(){return r()},su);this.pendingTimers.add(s),e.src=n,document.body.appendChild(e)}},t.prototype.getOrCreateInstance=function(t){var i,n=this,e=this.instances.get(t);if(e)return e;var r=null===(i=this.entryPointMap)||void 0===i?void 0:i.byId[t];if(!(r&&this.token&&this.allCampaignsMap&&this.userId))return this.logger.error("getOrCreateInstance() precondition not met, cannot open entry point",{entryPointId:t,hasEntryPoint:!!r,hasToken:!!this.token,hasAllCampaignsMap:!!this.allCampaignsMap,hasUserId:!!this.userId}),null;var s=this.token,o=this.userId;try{var u=function(){var i,e;return null!==(e=null===(i=n.entryPointMap)||void 0===i?void 0:i.byId[t])&&void 0!==e?e:r};this.resetDisplayTracking(t);var a=new tc(r,{userId:o,token:s,baseUrl:this.baseUrl,darkMode:this.resolveDarkMode(),allCampaignsMap:this.allCampaignsMap,logger:this.logger,onOpen:function(){var t=u();n.recordPendingShownIfAny(t),n.trackEntryPointOpen(t),n.notifyCampaignOpened(t)},onLoad:function(t){return n.trackEntryPointLoaded(u(),t)}});return a.addEventListener(function(i){return n.handleSdkEvent(i,t)}),a.addCloseEventListener(function(){a.close(),n.recordSessionDismissal(t),n.onCampaignClosed(t)}),this.instances.set(t,a),a}catch(i){return this.logger.error(go,{entryPointId:t,error:i}),null}},t.prototype.trackEntryPointOpen=function(t){var i,n,e,r=this,s=pu(t);if(s&&this.userId){if(this.markOpened(t.id),"game"===s){this.getOrCreateTrackingState(t.id).completionFired=!1;var o=Ou(t),u={campaign_id:o,game_type:this.lookupGameType(o),entry_surface:null!==(i=mu(t))&&void 0!==i?i:"",embed_id:null!==(n=this.adHocToggleSourceEmbedId.get(t.id))&&void 0!==n?n:t.container.elementHookId,entry_point_id:this.resolveTrackingEntryPointId(t,o),entry_point_location:"undefined"!=typeof window?window.location.href:""};this.trackEvent(ko,u)}else{u={page_id:t.container.elementHookId,content_surface:null!==(e=mu(t))&&void 0!==e?e:""};this.trackEvent(Mo,u)}this.fireViewedIfReady(t.id,function(i){return r.buildViewedAttributes(t,s,i)},s)}},t.prototype.trackEntryPointLoaded=function(t,i){var n=this;this.logger.debug("Campaign iframe loaded in ".concat(i.toFixed(2),"ms"),{entryPointId:t.id,campaignId:Ou(t)});var e=pu(t);e&&(this.markLoaded(t.id,i),this.fireViewedIfReady(t.id,function(i){return n.buildViewedAttributes(t,e,i)},e))},t.prototype.buildViewedAttributes=function(t,i,n){var e;if("game"===i){var r=Ou(t);return{campaign_id:r,game_type:this.lookupGameType(r),load_time_ms:yu(n)}}return{page_id:t.container.elementHookId,content_surface:null!==(e=mu(t))&&void 0!==e?e:"",load_time_ms:yu(n)}},t.prototype.lookupGameType=function(t){var i,n,e;return t&&null!==(e=null===(n=null===(i=this.allCampaignsMap)||void 0===i?void 0:i.byId[t])||void 0===n?void 0:n.type)&&void 0!==e?e:null},t.prototype.resolveTrackingEntryPointId=function(t,i){var n;if(!this.ephemeralEntryPointIds.has(t.id)||!i||!this.entryPointMap)return t.id;var e=this.entryPointMap,r=e.allIds.map(function(t){return e.byId[t]}).find(function(n){return void 0!==n&&n.id!==t.id&&Ou(n)===i});return null!==(n=null==r?void 0:r.id)&&void 0!==n?n:t.id},t.prototype.handleInboundAnalyticsEvent=function(t,i){if(this.matchesAnalyticsEventName(t,Do))return this.trackGamePlayed(i),void this.trackRewardSeenIfPresent(t,i);if(this.matchesAnalyticsEventName(t,No)){var n=this.getOrCreateTrackingState(i),e=n.completionFired;return n.completionFired=!0,e||this.trackGameCompleted(i),void this.trackRewardSeenIfPresent(t,i)}this.trackRewardSeenIfPresent(t,i)},t.prototype.matchesAnalyticsEventName=function(t,i){return"object"==typeof t&&null!==t&&t[Yo.EVENT_NAME]===i},t.prototype.trackGamePlayed=function(t){var i,n=null===(i=this.instances.get(t))||void 0===i?void 0:i.entryPoint;if(n&&gu(n.content)&&this.userId){var e=this.getOrCreateTrackingState(t);e.playedAt=Date.now(),e.completionFired=!1;var r=Ou(n),s={campaign_id:r,game_type:this.lookupGameType(r)};this.trackEvent(xo,s)}},t.prototype.trackGameCompleted=function(t){var i,n,e=null===(i=this.instances.get(t))||void 0===i?void 0:i.entryPoint;if(e&&gu(e.content)&&this.userId){var r=null===(n=this.trackingState.get(t))||void 0===n?void 0:n.playedAt,s=void 0!==r?Date.now()-r:0,o=Ou(e),u={campaign_id:o,game_type:this.lookupGameType(o),total_time_ms:yu(s)};this.trackEvent(Ro,u)}},t.prototype.trackRewardSeenIfPresent=function(t,i){if("object"==typeof t&&null!==t){var n=t[Yo.CAMPAIGN_DETAILS];if("object"==typeof n&&null!==n){var e=n,r=e[Yo.REWARD_STATUS];"string"==typeof r&&r.split("-").includes("SEEN")&&this.trackRewardSeen(e,i)}}},t.prototype.trackRewardSeen=function(t,i){if(this.userId){var n=this.readStringField(t,Yo.REWARD_USER_ID),e=this.getOrCreateTrackingState(i);if(null===n||n!==e.lastRewardUserId){e.lastRewardUserId=n;var r={reward_id:n,campaign_id:this.readStringField(t,Yo.CAMPAIGN_ID),reward_type:this.readStringField(t,Yo.REWARD_TYPE)};this.trackEvent(Po,r)}}},t.prototype.readStringField=function(t,i){var n=t[i];return void 0===n?null:"string"==typeof n?n:(this.logger.warn(po,{field:i,value:n}),null)},t.prototype.trackLoyaltyOpen=function(t){var i=this;if(this.userId){var n=this.loyaltyStateKey(t);this.trackingState.set(n,{opened:!0,viewedFired:!1});var e={page_id:t,content_surface:Lo};this.trackEvent(Mo,e),this.fireViewedIfReady(n,function(n){return i.buildLoyaltyViewedAttributes(t,n)},"content")}},t.prototype.trackLoyaltyLoaded=function(t,i){var n=this,e=this.loyaltyStateKey(t);this.markLoaded(e,i),this.fireViewedIfReady(e,function(i){return n.buildLoyaltyViewedAttributes(t,i)},"content")},t.prototype.buildLoyaltyViewedAttributes=function(t,i){return{page_id:t,content_surface:Lo,load_time_ms:yu(i)}},t.prototype.loyaltyStateKey=function(t){return"loyalty:".concat(t)},t.prototype.loyaltyCallbacks=function(){var i=this;return{onOpen:function(t){return i.trackLoyaltyOpen(t)},onLoad:function(t,n){return i.trackLoyaltyLoaded(t,n)},onDeepLinkEvent:function(t){var n,e;return null===(e=null===(n=i.callback)||void 0===n?void 0:n.onDeepLinkEvent)||void 0===e?void 0:e.call(n,t)},onOpenWallet:function(){return i.handleOpenWallet()},onOpenCgWebView:function(n){return i.handleOpenCgWebView(n,t.LOYALTY_SOURCE_ID)}}},t.prototype.markOpened=function(t){var i=this.getOrCreateTrackingState(t);i.opened=!0,i.viewedFired=!1},t.prototype.resetDisplayTracking=function(t){var i=this.trackingState.get(t);i&&(i.opened=!1,i.viewedFired=!1,delete i.loadTimeMs)},t.prototype.markLoaded=function(t,i){this.getOrCreateTrackingState(t).loadTimeMs=i},t.prototype.getOrCreateTrackingState=function(t){var i=this.trackingState.get(t);return i||(i={opened:!1,viewedFired:!1},this.trackingState.set(t,i)),i},t.prototype.fireViewedIfReady=function(t,i,n){var e=this.trackingState.get(t);e&&!e.viewedFired&&e.opened&&void 0!==e.loadTimeMs&&this.userId&&(e.viewedFired=!0,this.trackEvent("game"===n?Ao:Uo,i(e.loadTimeMs)))},t.prototype.handleSdkEvent=function(t,i){var n,e,r,s,o,u,a,c,h,d,f,l,v,m,g,p;if(this.initialized&&t&&"GLU_SDK"===t.target&&t.action){var w=t.action;switch(w.type){case"TOGGLE_CONTAINER_CONTENT":this.handleToggle(w,i);break;case"OPEN_CONTAINER_CONTENT":this.handleOpen(w);break;case"CLOSE_CONTAINER_CONTENT":case"CLOSE":this.handleClose(w,i);break;case"REQUEST_STATE":null===(e=this.instances.get(i))||void 0===e||e.sendMessage({type:"UPDATE_CONTENT_STATE",data:null!==(r=this.dataDump)&&void 0!==r?r:{}});break;case"LOGIN":this.handleLogin(w);break;case"REDIRECT":this.handleRedirect(w);break;case"ANALYTICS":null===(o=null===(s=this.callback)||void 0===s?void 0:s.onAnalyticsEvent)||void 0===o||o.call(s,w.data),this.handleInboundAnalyticsEvent(w.data,i);break;case"REFRESH":this.refresh();break;case"UPDATE_CONTENT_STATE":break;case"OPEN_DEEPLINK":this.handleOpenDeepLink(w,i);break;case"DIMENSIONS_UPDATE":null===(u=this.instances.get(i))||void 0===u||u.setHeight(null!==(c=null===(a=w.data.data)||void 0===a?void 0:a.height)&&void 0!==c?c:w.data.height);break;case"HIDE_LOADER":null===(h=this.instances.get(i))||void 0===h||h.hideLoader();break;case"REQUEST_API_DATA":null===(d=this.instances.get(i))||void 0===d||d.sendRawMessage({eventName:"REQUEST_API_RESULT",data:{requestId:null!==(l=null===(f=w.data)||void 0===f?void 0:f.requestId)&&void 0!==l?l:""}});break;case"REFRESH_API_DATA":null===(v=this.instances.get(i))||void 0===v||v.sendRawMessage({eventName:"REFRESH_API_DATA_RESULT",data:{requestId:null!==(g=null===(m=w.data)||void 0===m?void 0:m.requestId)&&void 0!==g?g:""}});break;case"OPEN_WALLET":this.handleOpenWallet();break;case"OPEN_WEBLINK":this.handleOpenWebLink(w.data);break;case"SHARE":this.handleShare(w.data);break;case"GAME_PLAYED":this.handleInboundAnalyticsEvent(le(le({},null!==(p=w.data)&&void 0!==p?p:{}),((n={})[Yo.EVENT_NAME]=No,n)),i);break;case"OPEN_CG_WEBVIEW":this.handleOpenCgWebView(w.data,i)}}},t.prototype.handleClose=function(t,i){var n;null===(n=this.instances.get(i))||void 0===n||n.close(),this.recordSessionDismissal(i),this.onCampaignClosed(i),this.ephemeralEntryPointIds.delete(i)&&this.trackingState.delete(i),t.data&&(this.dataDump=t.data)},t.prototype.handleLogin=function(t){"undefined"!=typeof window&&Du(t.data.url)&&(window.location.href=t.data.url)},t.prototype.handleToggle=function(t,i){var n=this.instances.get(t.id);n?n.isOpen()?(n.close(),this.recordSessionDismissal(t.id),this.onCampaignClosed(t.id)):this.isContentOpenSuppressed(n.entryPoint)||(Cu(n.entryPoint)&&this.openOverlayIds.add(t.id),n.open()):this.openNewToggleTarget({id:t.id,container:t.container,content:t.content},i),t.data&&(this.dataDump=t.data)},t.prototype.openNewToggleTarget=function(t,i){var n;if(!this.isContentOpenSuppressed(t)){var e=null===(n=this.instances.get(i))||void 0===n?void 0:n.entryPoint;e&&this.adHocToggleSourceEmbedId.set(t.id,e.container.elementHookId||e.id),this.registerAdHocEntryPoint(t),this.openInstance(t)}},t.prototype.handleOpen=function(t){var i={id:ma(),container:t.container,content:t.content};this.isContentOpenSuppressed(i)||(this.ephemeralEntryPointIds.add(i.id),this.registerAdHocEntryPoint(i),this.openInstance(i),t.data&&(this.dataDump=t.data))},t.prototype.handleRedirect=function(t){if("undefined"!=typeof window&&Du(t.data.url)){var i=t.data.url;this.userId&&(i+=i.includes("?")?"&":"?",i+="userId=".concat(this.userId)),t.data.openInNewTab?window.open(i,"_blank","noopener,noreferrer"):window.location.href=i}},t.prototype.handleOpenDeepLink=function(t,i){var n,e,r,s=Eu(t.data),o=s.deepLink,u=s.isHandledByCG,a=s.closeOnDeepLink;null===(e=null===(n=this.callback)||void 0===n?void 0:n.onDeepLinkEvent)||void 0===e||e.call(n,s),"true"===String(u).toLowerCase()&&"undefined"!=typeof window&&Du(o)&&(window.location.href=o),"true"===String(a).toLowerCase()&&(null===(r=this.instances.get(i))||void 0===r||r.close(),this.onCampaignClosed(i))},t.prototype.handleOpenWallet=function(){var t,i=null===(t=this.allCampaignsMap)||void 0===t?void 0:t.defaultUrl;i&&this.openAdHocContent(i)},t.prototype.handleOpenWebLink=function(t){"undefined"!=typeof window&&Du(null==t?void 0:t.url)&&window.open(t.url,"_blank","noopener,noreferrer")},t.prototype.handleShare=function(t){var i,n=null==t?void 0:t.text,e=null==t?void 0:t.image,r=null!==(i=null==t?void 0:t.channelName)&&void 0!==i?i:"OTHERS";e?"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("CUSTOMERGLU_SHARE_EVENT",{detail:t})):n&&"undefined"!=typeof window&&("WHATSAPP"===r.toUpperCase()?window.open("https://wa.me/?text=".concat(encodeURIComponent(n)),"_blank"):"undefined"!=typeof navigator&&"function"==typeof navigator.share&&navigator.share({text:n}).catch(function(){}))},t.prototype.handleOpenCgWebView=function(t,i){var n,e,r,s=null!==(n=null==t?void 0:t.data)&&void 0!==n?n:t,o=null==s?void 0:s.content,u=null==o?void 0:o.campaignId,a=this.resolveOpenCgWebViewUrl(o);a&&this.openAdHocContent(a,u,this.resolveOpenCgWebViewContainer(null==s?void 0:s.container))&&"true"===String(null!==(e=null==s?void 0:s.hidePrevious)&&void 0!==e?e:"false").toLowerCase()&&(null===(r=this.instances.get(i))||void 0===r||r.close(),this.onCampaignClosed(i))},t.prototype.resolveOpenCgWebViewUrl=function(t){var i,n,e,r,s=(null!==(i=null==t?void 0:t.type)&&void 0!==i?i:"").toUpperCase();return"WALLET"===s?null===(n=this.allCampaignsMap)||void 0===n?void 0:n.defaultUrl:"CAMPAIGN"===s&&(null==t?void 0:t.campaignId)?null===(r=null===(e=this.allCampaignsMap)||void 0===e?void 0:e.byId[t.campaignId])||void 0===r?void 0:r.url:null==t?void 0:t.url},t.prototype.resolveOpenCgWebViewContainer=function(i){var n,e=(null!==(n=null==i?void 0:i.type)&&void 0!==n?n:"").toLowerCase(),r=t.BOTTOM_SHEET_LAYOUTS.has(e)?"BOTTOM_SHEET":"POP_UP",s=Number(null==i?void 0:i.relativeHeight),o=Number(null==i?void 0:i.absoluteHeight);return s>0?{typeId:r,height:"".concat(s,"%")}:o>0?{typeId:r,height:"".concat(o,"px")}:{typeId:r,height:"".concat(t.DEFAULT_NUDGE_HEIGHT_PERCENT,"%")}},t.prototype.openAdHocContent=function(i,n,e){void 0===e&&(e={typeId:"POP_UP",height:"".concat(t.DEFAULT_NUDGE_HEIGHT_PERCENT,"%")});var r={id:ma(),container:{typeId:e.typeId,css:"",height:e.height,elementHookId:""},content:le({typeId:"NUDGE",url:i},n?{campaignId:n}:{})};return!this.isContentOpenSuppressed(r)&&(this.ephemeralEntryPointIds.add(r.id),this.registerAdHocEntryPoint(r),this.openInstance(r),!0)},t.prototype.registerAdHocEntryPoint=function(t){this.entryPointMap?(this.adHocEntryPointIds.add(t.id),this.entryPointMap.byId[t.id]||(this.entryPointMap.allIds.push(t.id),this.entryPointMap.byId[t.id]=t)):this.logger.error("registerAdHocEntryPoint() called before entryPointMap is loaded",{entryPointId:t.id})},t.prototype.closeAdHocEntryPoints=function(){var t,i;if(0!==this.adHocEntryPointIds.size){try{for(var n=ge(this.adHocEntryPointIds),e=n.next();!e.done;e=n.next()){var r=e.value,s=this.instances.get(r);if(s&&(s.isOpen()&&s.close(),s.destroy(),this.instances.delete(r)),this.trackingState.delete(r),this.ephemeralEntryPointIds.delete(r),this.adHocToggleSourceEmbedId.delete(r),this.openOverlayIds.delete(r),this.entryPointMap){delete this.entryPointMap.byId[r];var o=this.entryPointMap.allIds.indexOf(r);-1!==o&&this.entryPointMap.allIds.splice(o,1)}}}catch(i){t={error:i}}finally{try{e&&!e.done&&(i=n.return)&&i.call(n)}finally{if(t)throw t.error}}this.adHocEntryPointIds.clear()}},t.prototype.cacheKey=function(t){return zo+t},t.prototype.tokenCacheKey=function(t){return jo+t},t.prototype.loadTokenFromCache=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.storageManager.get(this.tokenCacheKey(t))];case 1:return(i=r.sent())?(n=JSON.parse(i),Date.now()-n.timestamp>=Bo?[2,null]:[2,n.token]):[2,null];case 2:return e=r.sent(),this.logger.error(yo,{userId:t,error:e}),[2,null];case 3:return[2]}})})},t.prototype.saveTokenToCache=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:n={token:i,timestamp:Date.now()},r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.storageManager.set(this.tokenCacheKey(t),JSON.stringify(n))];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.logger.error(wo,{error:e}),[3,4];case 4:return[2]}})})},t.prototype.getOrFetchToken=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:return[4,this.loadTokenFromCache(t)];case 1:return(n=r.sent())?(this.logger.info(io),[2,n]):(this.logger.info(no),[4,this.apiClient.getToken(this.writeKey,t,Xo.LOGGED_IN,void 0,i)]);case 2:return e=r.sent(),[4,this.saveTokenToCache(t,e)];case 3:return r.sent(),[2,e]}})})},t.prototype.isAuthError=function(t){return"object"==typeof t&&null!==t&&t.code===Me},t.prototype.ensureFreshToken=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r;return me(this,function(s){switch(s.label){case 0:if(this.tokenRefetchInFlight)return[2,this.tokenRefetchInFlight];if(Date.now()<this.authBackoffUntil)throw this.logger.warn(ro,{retryInMs:this.authBackoffUntil-Date.now()}),new Error("Gamification token refetch is in backoff after repeated failures");i=this.refetchToken(t,this.userAttributes),this.tokenRefetchInFlight=i,s.label=1;case 1:return s.trys.push([1,3,4,5]),[4,i];case 2:return n=s.sent(),this.authFailureCount=0,this.authBackoffUntil=0,[2,n];case 3:throw e=s.sent(),this.authFailureCount+=1,r=Math.min($o*Math.pow(2,this.authFailureCount-1),Zo),this.authBackoffUntil=Date.now()+r,this.logger.error(so,{userId:t,authFailureCount:this.authFailureCount,backoffMs:r,error:e}),e;case 4:return this.tokenRefetchInFlight=null,[7];case 5:return[2]}})})},t.prototype.refetchToken=function(t,i){return ve(this,void 0,void 0,function(){var n;return me(this,function(e){switch(e.label){case 0:return[4,this.storageManager.remove(this.tokenCacheKey(t)).catch(function(){})];case 1:return e.sent(),[4,this.apiClient.getToken(this.writeKey,t,Xo.LOGGED_IN,void 0,i)];case 2:return n=e.sent(),this.userId!==t?[3,4]:[4,this.saveTokenToCache(t,n)];case 3:e.sent(),this.token=n,e.label=4;case 4:return[2,n]}})})},t.prototype.fetchCampaignsAndEntryPoints=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,4]),[4,Promise.all([this.apiClient.getCampaigns(i),this.apiClient.getEntryPoints(i)])];case 1:return[2,r.sent()];case 2:if(n=r.sent(),!this.isAuthError(n))throw n;return this.logger.error(eo,{userId:t}),[4,this.ensureFreshToken(t)];case 3:return e=r.sent(),[2,Promise.all([this.apiClient.getCampaigns(e),this.apiClient.getEntryPoints(e)])];case 4:return[2]}})})},t.prototype.loadFromCache=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.storageManager.get(this.cacheKey(t))];case 1:return(i=r.sent())?(n=JSON.parse(i),Date.now()-n.timestamp>=Vo?(this.logger.debug(_o,{userId:t,ageMs:Date.now()-n.timestamp}),[2,!1]):(this.token=n.token,this.allCampaignsMap=n.allCampaignsMap,this.entryPointMap=n.entryPointMap,this.buildEventIndex(),this.lastSyncTimestamp=n.timestamp,[2,!0])):(this.logger.debug(Eo,{userId:t}),[2,!1]);case 2:return e=r.sent(),this.logger.error(Io,{userId:t,error:e}),[2,!1];case 3:return[2]}})})},t.prototype.saveToCache=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:if(!(this.userId&&this.token&&this.allCampaignsMap&&this.entryPointMap))return[2];t={token:this.token,allCampaignsMap:this.allCampaignsMap,entryPointMap:this.entryPointMap,timestamp:this.lastSyncTimestamp},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.storageManager.set(this.cacheKey(this.userId),JSON.stringify(t))];case 2:return n.sent(),[3,4];case 3:return i=n.sent(),this.logger.error(bo,{error:i}),[3,4];case 4:return this.allCampaignsMap.base&&this.storageManager.set(ou,this.allCampaignsMap.base).catch(function(){}),[2]}})})},t.prototype.handleScreenChange=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.closeAdHocEntryPoints(),this.isDataStale()?[4,this.resyncData()]:[3,2];case 1:return t.sent(),[3,3];case 2:this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode()),t.label=3;case 3:return this.refresh(),[2]}})})},t.prototype.isDataStale=function(){return Date.now()-this.lastSyncTimestamp>=Vo},t.prototype.resyncData=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:if(t=this.token,i=this.userId,!t||!i)return[2];n=++this.syncGeneration,this.logger.info(Qs),h.label=1;case 1:return h.trys.push([1,4,,5]),[4,this.fetchCampaignsAndEntryPoints(i,t)];case 2:return e=pe.apply(void 0,[h.sent(),2]),r=e[0],s=e[1],n!==this.syncGeneration?[2]:(o=this.entryPointMap,this.allCampaignsMap=r,this.entryPointMap=Pu(s),this.buildEventIndex(),this.lastSyncTimestamp=Date.now(),null===(c=null===(a=this.callback)||void 0===a?void 0:a.onEntryPointsLoaded)||void 0===c||c.call(a,Object.values(this.entryPointMap.byId)),this.preloadEntryPoints(),[4,this.saveToCache()]);case 3:return h.sent(),this.reconcileEntryPointState(o,this.entryPointMap,i),this.loyaltyRenderer.render(this.loyaltyUrls,this.capToken,this.loyaltyCallbacks(),this.resolveDarkMode()),[3,5];case 4:return u=h.sent(),this.logger.error($s,u),[3,5];case 5:return[2]}})})},t.prototype.reconcileEntryPointState=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f,l=this;return me(this,function(v){switch(v.label){case 0:if(!t)return[2];e=this.classifyReconciledEntryPoints(t,i),r=e.removedIds,s=e.dailyRefreshChangedIds,o=function(t){u.storageManager.remove(qu(t,n)).catch(function(i){l.logger.error(Co,{entryPointId:t,error:i})})},u=this;try{for(a=ge(we(we([],pe(r),!1),pe(s),!1)),c=a.next();!c.done;c=a.next())h=c.value,o(h)}catch(t){d={error:t}}finally{try{c&&!c.done&&(f=a.return)&&f.call(a)}finally{if(d)throw d.error}}return r.length>0?[4,this.pruneSessionDismissalRecords(r,n)]:[3,2];case 1:v.sent(),v.label=2;case 2:return[2]}})})},t.prototype.classifyReconciledEntryPoints=function(t,i){var n,e,r,s,o,u,a,c,h=[],d=[];try{for(var f=ge(t.allIds),l=f.next();!l.done;l=f.next()){var v=l.value,m=t.byId[v],g=i.byId[v];if(m)if(g)(null!==(o=null===(s=null===(r=m.conditions)||void 0===r?void 0:r.showCount)||void 0===s?void 0:s.dailyRefresh)&&void 0!==o&&o)!==(null!==(c=null===(a=null===(u=g.conditions)||void 0===u?void 0:u.showCount)||void 0===a?void 0:a.dailyRefresh)&&void 0!==c&&c)&&d.push(v);else h.push(v)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(e=f.return)&&e.call(f)}finally{if(n)throw n.error}}return{removedIds:h,dailyRefreshChangedIds:d}},t.prototype.pruneSessionDismissalRecords=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h,d=this;return me(this,function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),[4,this.storageManager.keys("".concat(Ko).concat(i,"_"))];case 1:n=f.sent(),e=function(t){var e,s,o=r.sessionDismissedKeyPrefix(i,t);try{for(var u=(e=void 0,ge(n.filter(function(t){return t.startsWith(o)}))),a=u.next();!a.done;a=u.next()){var c=a.value;r.storageManager.remove(c).catch(function(i){d.logger.error(Co,{entryPointId:t,error:i})})}}catch(t){e={error:t}}finally{try{a&&!a.done&&(s=u.return)&&s.call(u)}finally{if(e)throw e.error}}},r=this;try{for(s=ge(t),o=s.next();!o.done;o=s.next())u=o.value,e(u)}catch(t){c={error:t}}finally{try{o&&!o.done&&(h=s.return)&&h.call(s)}finally{if(c)throw c.error}}return[3,3];case 2:return a=f.sent(),this.logger.error(Co,{entryPointId:"all",error:a}),[3,3];case 3:return[2]}})})},t.prototype.fetchAndCache=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o;return me(this,function(u){switch(u.label){case 0:return[4,this.getOrFetchToken(t,i)];case 1:return e=u.sent(),n!==this.initGeneration?[2,!1]:(this.token=e,[4,this.fetchCampaignsAndEntryPoints(t,e)]);case 2:return r=pe.apply(void 0,[u.sent(),2]),s=r[0],o=r[1],n!==this.initGeneration?[2,!1]:(this.allCampaignsMap=s,this.entryPointMap=Pu(o),this.buildEventIndex(),this.lastSyncTimestamp=Date.now(),this.saveToCache(),[2,n===this.initGeneration])}})})},t.prototype.isCampaignCompleted=function(t){var i,n,e,r=Ou(t);if(!r||!this.allCampaignsMap)return!1;var s=this.allCampaignsMap.byId[r];if(!s)return!1;var o=Fo;return(null===(i=s.status)||void 0===i?void 0:i.toUpperCase())===o||(null===(e=null===(n=s.banner)||void 0===n?void 0:n.userCampaignStatus)||void 0===e?void 0:e.toUpperCase())===o},t.prototype.registerSpaListener=function(){var t=this;if("undefined"!=typeof window&&"undefined"!=typeof document){var i=window.location.href,n=null,e=new MutationObserver(function(){var e=window.location.href;if(e!==i){if(i=e,!t.pagePathTrackingEnabled)return;n&&clearTimeout(n),n=setTimeout(function(){t.handleScreenChange()},Wo)}});e.observe(document.body,{childList:!0,subtree:!0}),this.spaListenerCleanup=function(){e.disconnect(),n&&clearTimeout(n)}}},t.prototype.registerVisibilityListener=function(){var t=this;if("undefined"!=typeof document){var i=function(){return ve(t,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return"visible"!==document.visibilityState?[2]:this.isDataStale()?[4,this.resyncData()]:[3,2];case 1:return t.sent(),this.refresh(),[2];case 2:return this.showNextFromQueue(),[2]}})})};document.addEventListener("visibilitychange",i),this.visibilityListenerCleanup=function(){document.removeEventListener("visibilitychange",i)}}},t.VALID_THEMES=["NONE","AUTO","DARK","LIGHT"],t.LOYALTY_SOURCE_ID="__GLU__LOYALTY__",t.BOTTOM_SHEET_LAYOUTS=new Set(["bottom-popup","bottom-default","bottom-slider"]),t.DEFAULT_NUDGE_HEIGHT_PERCENT=100/1.4,t}(),ec=function(){function t(t,i,n,e,r){this.httpClient=new cu(t,i),this.logger=i,this.accountId=n,this.orgId=e,this.source=r}return t.prototype.sendEvents=function(t,i,n,e,r,s){return ve(this,void 0,void 0,function(){var o,u,a,c,h,d,f,l;return me(this,function(v){switch(v.label){case 0:if(!i&&!n&&!e)throw new Error("Either visitorId, visitorExternalId, or userId must be provided for event tracking");if(!s)throw new Error("Session ID is required for event tracking");return u=(o=!!i||!!n)&&e?"identified":o?"anonymous":"user-only",this.logger.info("Sending events",{eventCount:t.length,trackingMode:u,hasVisitor:o,hasUser:!!e,sessionId:s}),[4,fa()];case 1:a=v.sent(),c=ra(s,a),h={request_id:ia(),context:c,events:t},i?h.visitor={identifierName:"id",identifierValue:i}:n&&(h.visitor={identifierName:"externalId",identifierValue:n}),e&&r&&(h.user={identifierName:r,identifierValue:e}),v.label=2;case 2:return v.trys.push([2,4,,5]),d={"X-CAP-API-AUTH-ORG-ID":this.orgId,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":this.source,"X-CAP-API-AUTH-ENTITY-ID":this.orgId},[4,this.httpClient.post(ye,h,{headers:d})];case 3:return f=v.sent(),this.logger.info(rr,{requestId:h.request_id,eventCount:t.length,trackingMode:u,success:f.status.success}),[2,f];case 4:throw l=v.sent(),this.logger.error(sr,{requestId:h.request_id,eventCount:t.length,trackingMode:u,error:l}),l;case 5:return[2]}})})},t.prototype.getVisitorConfig=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s;return me(this,function(o){switch(o.label){case 0:this.logger.info("Fetching visitor config",{orgId:t}),o.label=1;case 1:return o.trys.push([1,3,,4]),i={"X-CAP-API-AUTH-ORG-ID":t,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":Ls.WEBPUSH},[4,this.httpClient.get(_e,{headers:i})];case 2:return n=o.sent(),this.logger.info(Pr,{isEnabled:null===(r=n.data)||void 0===r?void 0:r.visitorTrackingEnabled,warningCount:(null===(s=n.warnings)||void 0===s?void 0:s.length)||0}),[2,n];case 3:throw e=o.sent(),this.logger.error(Mr,{orgId:t,error:e}),e;case 4:return[2]}})})},t.prototype.createVisitor=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:this.logger.info("Creating anonymous visitor",{orgId:t,profileCount:i.profiles.length,hasExtendedFields:!!i.extendedFields}),u.label=1;case 1:if(u.trys.push([1,3,,4]),!i.profiles||0===i.profiles.length)throw new Error("At least one profile is required");return n={"X-CAP-API-AUTH-ORG-ID":t,"X-CAP-SOURCE-NAME":this.source,"X-CAP-ORG-ACCOUNT-ID":this.accountId},[4,this.httpClient.post(Ie,i,{headers:n})];case 2:return e=u.sent(),this.logger.info(Vr,{visitorId:null===(s=e.data)||void 0===s?void 0:s.id,warningCount:(null===(o=e.warnings)||void 0===o?void 0:o.length)||0}),[2,e];case 3:throw r=u.sent(),this.logger.error(Br,{error:r,accountId:this.accountId}),r;case 4:return[2]}})})},t.prototype.updateVisitor=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a;return me(this,function(c){switch(c.label){case 0:this.logger.info("Updating visitor",{orgId:t,visitorId:i,profileCount:n.profiles.length,hasExtendedFields:!!n.extendedFields}),c.label=1;case 1:if(c.trys.push([1,3,,4]),!n.profiles||0===n.profiles.length)throw new Error("At least one profile is required");if(!i||""===i.trim())throw new Error("Visitor ID is required for update");return e={"X-CAP-API-AUTH-ORG-ID":t,"X-CAP-SOURCE-NAME":this.source,"X-CAP-ORG-ACCOUNT-ID":this.accountId},r="".concat(be,"?identifierType=visitorId&identifierValue=").concat(encodeURIComponent(i)),[4,this.httpClient.put(r,n,{headers:e})];case 2:return s=c.sent(),this.logger.info(Hr,{visitorId:null===(u=s.data)||void 0===u?void 0:u.id,warningCount:(null===(a=s.warnings)||void 0===a?void 0:a.length)||0}),[2,s];case 3:throw o=c.sent(),this.logger.error(qr,{error:o,visitorId:i,accountId:this.accountId}),o;case 4:return[2]}})})},t.prototype.buildMergeIdentifiers=function(t,i,n,e){var r,s={email:i,mobile:n,externalId:e},o=t&&s[t]?t:void 0;r=i?"email":n?"mobile":"externalId";var u=null!=o?o:r;return[{type:u,value:s[u]}]},t.prototype.handleMergeResponse=function(t,i){var n,e=this;if(t.warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){e.logger.warn("Visitor merge warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0){var r=t.errors[0],s=r.code,o=r.message,u=String(s);if(u===Vs.ALREADY_MERGED)return void this.logger.info("Visitor already merged, treating as success",{visitorId:i});if(u===Vs.VISITOR_NOT_FOUND)throw this.logger.warn("Visitor not found, merge cannot proceed",{visitorId:i}),new rc(u,o);throw new Error("Merge API error: [".concat(u,"] ").concat(o))}if(202!==(null===(n=t.status)||void 0===n?void 0:n.code))throw new Error("Unexpected merge API response");this.logger.info(Kr,{visitorId:i,statusCode:t.status.code,message:t.status.message})},t.prototype.mergeVisitor=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f,l,v,m,g,p,w,y,E,_,I,b,T,S,C,N,D;return me(this,function(O){switch(O.label){case 0:if(e=n.firstName,r=n.lastName,s=n.email,o=n.mobile,u=n.fcmToken,a=n.channelType,c=n.subscribed,h=void 0===c||c,d=n.fields,f=n.extendedFields,l=n.externalId,v=n.sessionId,m=void 0===v?"":v,g=n.cuid,p=void 0===g?"":g,w=n.identifierType,!s&&!o&&!l)throw new Error("At least one identifier (email, mobile, or externalId) is required for visitor merge");if(!t&&!i)throw new Error("Either visitorId or visitorExternalId is required for visitor merge");return this.logger.info("Merging visitor with user",{visitorId:t,visitorExternalId:i,hasEmail:!!s,hasMobile:!!o,hasExternalId:!!l,hasFcmToken:!!u}),y=this.buildMergeIdentifiers(w,s,o,l),E=a||Fs.WEB,_=[],u&&_.push({type:E,value:u,primary:!0,verified:!0,subscribed:h,accountId:this.accountId,attributes:{gateway:zs,cuid:p,luid:p,lastSeen:(new Date).toISOString(),deleted:!1,pushReachable:h}}),s&&_.push({type:"email",value:s,primary:!0,subscribed:!1,accountId:this.accountId,attributes:{cuid:p}}),o&&_.push({type:"mobile",value:o,primary:!0,subscribed:!1,accountId:this.accountId,attributes:{cuid:p}}),D={visitor:t?{identifierName:"id",identifierValue:t}:{identifierName:"externalId",identifierValue:i},user:{profiles:[{firstName:e,lastName:r,identifiers:y,commChannels:_,fields:d||{}}],extendedFields:f||{}}},b=ra,T=[m],[4,fa()];case 1:D.context=b.apply(void 0,T.concat([O.sent()])),I=D,O.label=2;case 2:return O.trys.push([2,4,,5]),S={"X-CAP-API-AUTH-ORG-ID":this.orgId,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":this.source},[4,this.httpClient.post(Te,I,{headers:S})];case 3:return C=O.sent(),this.handleMergeResponse(C,t),[3,5];case 4:if((N=O.sent())instanceof rc)throw N;throw this.logger.error(Wr,{visitorId:t,error:N}),N;case 5:return[2]}})})},t.prototype.buildUserEventsRequest=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r;return me(this,function(s){switch(s.label){case 0:return[4,fa()];case 1:return e=s.sent(),r=ra(n,e),[2,{request_id:ia(),context:le(le({},r),{os_name:Os}),events:[{name:t,eventExternalId:ia(),eventDateTime:(new Date).toISOString(),attributes:i}]}]}})})},t.prototype.sendUserEvents=function(t,i,n,e,r){return ve(this,void 0,void 0,function(){var s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:i?t.visitor={identifierName:"id",identifierValue:i}:n&&(t.visitor={identifierName:"externalId",identifierValue:n}),e&&r&&(t.user={identifierName:r,identifierValue:e}),this.logger.info("Sending user event",{eventName:null===(u=t.events[0])||void 0===u?void 0:u.name,requestId:t.request_id,hasVisitor:!!t.visitor,hasUser:!!t.user}),h.label=1;case 1:return h.trys.push([1,3,,4]),s={"X-CAP-API-AUTH-ORG-ID":this.orgId,"X-CAP-ORG-ACCOUNT-ID":this.accountId,"X-CAP-SOURCE-NAME":this.source,"X-CAP-API-AUTH-ENTITY-ID":this.orgId},[4,this.httpClient.post(Ee,t,{headers:s})];case 2:return h.sent(),this.logger.info(or,{eventName:null===(a=t.events[0])||void 0===a?void 0:a.name,requestId:t.request_id}),[3,4];case 3:throw o=h.sent(),this.logger.error(ur,{eventName:null===(c=t.events[0])||void 0===c?void 0:c.name,requestId:t.request_id,error:o}),o;case 4:return[2]}})})},t.prototype.sendDLR=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s;return me(this,function(o){switch(o.label){case 0:this.logger.info("Sending DLR events",{eventCount:t.events.length,requestId:t.request_id,cuid:null===(r=t.user)||void 0===r?void 0:r.identifierValue,visitorId:null===(s=t.visitor)||void 0===s?void 0:s.identifierValue}),o.label=1;case 1:return o.trys.push([1,3,,4]),i={"x-cap-api-auth-org-id":this.orgId,"x-cap-request-id":t.request_id},[4,this.httpClient.post(Se,t,{headers:i})];case 2:return n=o.sent(),this.logger.info(Ns,{requestId:t.request_id,eventCount:t.events.length,success:n.status.success}),[2,n];case 3:throw e=o.sent(),this.logger.error(Ds,{requestId:t.request_id,eventCount:t.events.length,error:e}),e;case 4:return[2]}})})},t}(),rc=function(t){function i(i,n){var e=t.call(this,n)||this;return e.name="MergeNonRetryableError",e.code=i,e}return fe(i,t),i}(Error);var sc,oc=function(){function t(t,i,n,e){void 0===i&&(i="WebSDK"),void 0===n&&(n=2),void 0===e&&(e="data"),this.db=null,this.logger=t,this.dbName=i,this.version=n,this.storeName=e,this.eventsStoreName="events"}return t.prototype.logAndReject=function(t,i,n){this.logger.error("IndexedDB request failed",{operation:i,error:n}),t(n)},t.prototype.attachTransactionSafety=function(t,i,n){var e=this;t.onabort=function(){return e.logAndReject(i,"".concat(n,":transaction"),t.error)},t.onerror=function(){return e.logAndReject(i,"".concat(n,":transaction"),t.error)}},t.prototype.openDB=function(){return ve(this,void 0,void 0,function(){var t=this;return me(this,function(i){return this.db?[2,this.db]:[2,new Promise(function(i,n){var e=indexedDB.open(t.dbName,t.version);e.onerror=function(){return t.logAndReject(n,"openDB",e.error)},e.onblocked=function(){return t.logAndReject(n,"openDB",new Error("IndexedDB open request blocked by another open connection"))},e.onsuccess=function(){t.db=e.result,t.db.onversionchange=function(){var i;t.logger.info("IndexedDB version change detected by another connection, closing"),null===(i=t.db)||void 0===i||i.close(),t.db=null},i(t.db)},e.onupgradeneeded=function(i){var n=i.target.result;if(t.logger.info("IndexedDB schema upgrade",{dbName:t.dbName,oldVersion:i.oldVersion,newVersion:i.newVersion}),n.objectStoreNames.contains(t.storeName)||n.createObjectStore(t.storeName),!n.objectStoreNames.contains(t.eventsStoreName)){var e=n.createObjectStore(t.eventsStoreName,{keyPath:"id"});e.createIndex("timestamp","timestamp",{unique:!1}),e.createIndex("status","status",{unique:!1})}}})]})})},t.prototype.getItem=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.storeName],"readonly");n.attachTransactionSafety(s,r,"getItem");var o=s.objectStore(n.storeName).get(t);o.onerror=function(){return n.logAndReject(r,"getItem",o.error)},o.onsuccess=function(){var t=o.result;e(null==t?null:"string"==typeof t?t:"object"==typeof t?JSON.stringify(t):String(t))}})]}})})},t.prototype.setItem=function(t,i){return ve(this,void 0,void 0,function(){var n,e=this;return me(this,function(r){switch(r.label){case 0:return[4,this.openDB()];case 1:return n=r.sent(),[2,new Promise(function(r,s){var o=n.transaction([e.storeName],"readwrite");e.attachTransactionSafety(o,s,"setItem");var u=o.objectStore(e.storeName).put(i,t);u.onerror=function(){return e.logAndReject(s,"setItem",u.error)},u.onsuccess=function(){return r()}})]}})})},t.prototype.removeItem=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.storeName],"readwrite");n.attachTransactionSafety(s,r,"removeItem");var o=s.objectStore(n.storeName).delete(t);o.onerror=function(){return n.logAndReject(r,"removeItem",o.error)},o.onsuccess=function(){return e()}})]}})})},t.prototype.clear=function(){return ve(this,void 0,void 0,function(){var t,i=this;return me(this,function(n){switch(n.label){case 0:return[4,this.openDB()];case 1:return t=n.sent(),[2,new Promise(function(n,e){var r=t.transaction([i.storeName],"readwrite");i.attachTransactionSafety(r,e,"clear");var s=r.objectStore(i.storeName).clear();s.onerror=function(){return i.logAndReject(e,"clear",s.error)},s.onsuccess=function(){return n()}})]}})})},t.prototype.getAllKeys=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.storeName],"readonly");n.attachTransactionSafety(s,r,"getAllKeys");var o=s.objectStore(n.storeName).getAllKeys();o.onerror=function(){return n.logAndReject(r,"getAllKeys",o.error)},o.onsuccess=function(){var i=o.result.map(function(t){return String(t)});e(t?i.filter(function(i){return i.startsWith(t)}):i)}})]}})})},t.prototype.close=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.db&&(this.db.close(),this.db=null),[2]})})},t.prototype.addEvent=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readwrite");n.attachTransactionSafety(s,r,"addEvent");var o=s.objectStore(n.eventsStoreName).add(t);o.onerror=function(){return n.logAndReject(r,"addEvent",o.error)},o.onsuccess=function(){return e()}})]}})})},t.prototype.getOldestPendingEvents=function(t){return ve(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=50),me(this,function(r){switch(r.label){case 0:return[4,this.openDB()];case 1:return n=r.sent(),[2,new Promise(function(r,s){var o=n.transaction([e.eventsStoreName],"readonly");e.attachTransactionSafety(o,s,"getOldestPendingEvents");var u=o.objectStore(e.eventsStoreName).index("timestamp").openCursor(),a=[],c=0;u.onerror=function(){return e.logAndReject(s,"getOldestPendingEvents",u.error)},u.onsuccess=function(n){var e=n.target.result;if(e&&c<i){var s=e.value;"pending"===s.status&&s.accountId===t&&(a.push(s),c++),e.continue()}else r(a)}})]}})})},t.prototype.updateEventStatus=function(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s=this;return me(this,function(o){switch(o.label){case 0:return[4,this.openDB()];case 1:return r=o.sent(),[2,new Promise(function(o,u){var a=r.transaction([s.eventsStoreName],"readwrite");s.attachTransactionSafety(a,u,"updateEventStatus");var c=a.objectStore(s.eventsStoreName),h=c.get(t);h.onerror=function(){return s.logAndReject(u,"updateEventStatus:get",h.error)},h.onsuccess=function(){var r=h.result;if(r){r.status=i,r.lastAttempt=Date.now(),n&&(r.error=n),void 0!==e&&(r.attempts=e);var a=c.put(r);a.onerror=function(){return s.logAndReject(u,"updateEventStatus:put",a.error)},a.onsuccess=function(){return o()}}else s.logAndReject(u,"updateEventStatus",new Error("Event with id ".concat(t," not found")))}})]}})})},t.prototype.removeEvents=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readwrite");n.attachTransactionSafety(s,r,"removeEvents");var o=s.objectStore(n.eventsStoreName),u=0,a=t.length;0!==a?t.forEach(function(t){var i=o.delete(t);i.onerror=function(){return n.logAndReject(r,"removeEvents",i.error)},i.onsuccess=function(){++u===a&&e()}}):e()})]}})})},t.prototype.recoverOrphanedEvents=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readwrite");n.attachTransactionSafety(s,r,"recoverOrphanedEvents");var o=s.objectStore(n.eventsStoreName).openCursor(),u=0;o.onerror=function(){return n.logAndReject(r,"recoverOrphanedEvents",o.error)},o.onsuccess=function(i){var s=i.target.result;if(s){var o=s.value;if("processing"===o.status&&o.accountId===t){o.status="failed",o.lastAttempt=Date.now(),o.error="Recovered from orphaned processing state";var a=s.update(o);a.onerror=function(){return n.logAndReject(r,"recoverOrphanedEvents:update",a.error)},a.onsuccess=function(){u++}}s.continue()}else e(u)}})]}})})},t.prototype.getPendingEventCount=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){switch(e.label){case 0:return[4,this.openDB()];case 1:return i=e.sent(),[2,new Promise(function(e,r){var s=i.transaction([n.eventsStoreName],"readonly");n.attachTransactionSafety(s,r,"getPendingEventCount");var o=s.objectStore(n.eventsStoreName).openCursor(),u=0;o.onerror=function(){return n.logAndReject(r,"getPendingEventCount",o.error)},o.onsuccess=function(i){var n=i.target.result;if(n){var r=n.value;"pending"===r.status&&r.accountId===t&&u++,n.continue()}else e(u)}})]}})})},t.prototype.getRetryableEvents=function(t){return ve(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=5),me(this,function(r){switch(r.label){case 0:return[4,this.openDB()];case 1:return n=r.sent(),[2,new Promise(function(r,s){var o=n.transaction([e.eventsStoreName],"readonly");e.attachTransactionSafety(o,s,"getRetryableEvents");var u=o.objectStore(e.eventsStoreName).openCursor(),a=[];u.onerror=function(){return e.logAndReject(s,"getRetryableEvents",u.error)},u.onsuccess=function(n){var e=n.target.result;if(e){var s=e.value;"failed"===s.status&&s.attempts<=i&&s.accountId===t&&a.push(s),e.continue()}else r(a)}})]}})})},t}(),uc=function(){function t(t,i,n,e,r){if(this.currentAccountId=null,this.currentCuid=null,this.currentUserIdentifierType=null,this.currentVisitorId=null,this.currentVisitorExternalId=null,this.getSessionInfo=null,this.isProcessing=!1,this.processingPromise=null,this.apiClient=t,this.logger=i,this.BATCH_SIZE=r||Ne.BATCH_SIZE,this.RETRY_DELAYS=e||Ne.DEFAULT_RETRY_DELAYS,n&&"getIndexedDBAdapter"in n){var s=n.getIndexedDBAdapter();s?(i.info("EventQueue: Reusing existing IndexedDB adapter from StorageManager"),this.storage=s):(i.warn("EventQueue: StorageManager has no IndexedDB adapter, creating new one"),this.storage=new oc(i))}else n?(i.info("EventQueue: Using provided IndexedDBStorage"),this.storage=n):(i.warn("EventQueue: No storage provided, creating new IndexedDBStorage"),this.storage=new oc(i))}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Initializing EventQueue"),[4,this.processQueueIfIdle()];case 1:return t.sent(),this.logger.info(Ze),[2]}})})},t.prototype.setUserContext=function(t,i,n){return ve(this,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return this.currentAccountId=t,this.currentCuid=i||null,this.currentUserIdentifierType=n||null,this.logger.debug("EventQueue user context set",{accountId:t,cuid:i,userIdentifierType:n}),[4,this.storage.recoverOrphanedEvents(t)];case 1:return(e=r.sent())>0&&this.logger.info("Recovered ".concat(e," orphaned processing events for account ").concat(t)),[2]}})})},t.prototype.setVisitorContext=function(t,i){this.currentVisitorId=t,this.currentVisitorExternalId=null!=i?i:null,this.logger.debug("EventQueue visitor context set",{visitorId:t,visitorExternalId:i})},t.prototype.setSessionInfoCallback=function(t){this.getSessionInfo=t,this.logger.debug("EventQueue session info callback set")},t.prototype.getCurrentAccountId=function(){return this.currentAccountId},t.prototype.getCurrentCuid=function(){return this.currentCuid},t.prototype.getCurrentVisitorId=function(){return this.currentVisitorId},t.prototype.clearUserContext=function(){this.currentCuid=null,this.currentUserIdentifierType=null,this.logger.debug("EventQueue user context cleared (cuid removed)")},t.prototype.enqueue=function(t){return ve(this,arguments,void 0,function(t,i){var n,e,r;return void 0===i&&(i=!1),me(this,function(s){switch(s.label){case 0:if(!this.currentAccountId)throw new Error("Cannot enqueue event: No account context set");if(n=null,!this.getSessionInfo)return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.getSessionInfo()];case 2:return n=s.sent(),[3,4];case 3:return e=s.sent(),this.logger.error("Failed to resolve session ID at enqueue time",{error:e}),[3,4];case 4:return r={id:ia(),event:t,accountId:this.currentAccountId,timestamp:(new Date).toISOString(),attempts:0,status:Ne.STATUSES.PENDING,visitorId:this.currentVisitorId,visitorExternalId:this.currentVisitorExternalId,cuid:this.currentCuid,userIdentifierType:this.currentUserIdentifierType,sessionId:n,isDLR:i},[4,this.storage.addEvent(r)];case 5:return s.sent(),this.logger.debug(nr,{eventId:r.id,eventName:t.name,visitorId:r.visitorId,cuid:r.cuid,sessionId:r.sessionId,isDLR:i}),[4,this.processQueueIfIdle()];case 6:return s.sent(),[2]}})})},t.prototype.processQueueIfIdle=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.isProcessing?(this.logger.debug(fr),[2]):(this.processingPromise||(this.processingPromise=this.processQueue()),[2,this.processingPromise])})})},t.prototype.getIdentityKey=function(t){var i,n,e,r,s,o=null!==(i=t.visitorId)&&void 0!==i?i:"_none_",u=null!==(n=t.visitorExternalId)&&void 0!==n?n:"_none_",a=null!==(e=t.cuid)&&void 0!==e?e:"_none_",c=null!==(r=t.userIdentifierType)&&void 0!==r?r:"_none_",h=null!==(s=t.sessionId)&&void 0!==s?s:"_none_";return"".concat(o,"|").concat(u,"|").concat(a,"|").concat(c,"|").concat(h)},t.prototype.groupEventsByIdentity=function(t){var i,n,e=new Map;try{for(var r=ge(t),s=r.next();!s.done;s=r.next()){var o=s.value,u=this.getIdentityKey(o),a=e.get(u);a?a.push(o):e.set(u,[o])}}catch(t){i={error:t}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return Array.from(e.values())},t.prototype.processQueue=function(){return ve(this,void 0,void 0,function(){var i=this;return me(this,function(n){switch(n.label){case 0:return this.isProcessing?[2]:"undefined"!=typeof navigator&&"locks"in navigator?[4,navigator.locks.request(t.QUEUE_LOCK_NAME,{ifAvailable:!0},function(t){return ve(i,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return t?[4,this.executeProcessQueue()]:(this.logger.debug("Queue lock held by another tab, skipping"),[2]);case 1:return i.sent(),[2]}})})})]:[3,2];case 1:return n.sent(),[3,4];case 2:return[4,this.executeProcessQueue()];case 3:n.sent(),n.label=4;case 4:return[2]}})})},t.prototype.executeProcessQueue=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:this.isProcessing=!0,this.logger.debug(cr),h.label=1;case 1:h.trys.push([1,16,17,18]),h.label=2;case 2:return[4,this.checkAndPromoteRetryEvents()];case 3:return h.sent(),this.currentAccountId?[4,this.storage.getOldestPendingEvents(this.currentAccountId,this.BATCH_SIZE)]:(this.logger.debug("No account context, skipping event processing"),[3,15]);case 4:if(0===(t=h.sent()).length)return this.logger.debug(lr),[3,15];i=this.groupEventsByIdentity(t),this.logger.info("Processing events",{totalEvents:t.length,identityGroups:i.length}),h.label=5;case 5:h.trys.push([5,11,12,13]),a=void 0,n=ge(i),e=n.next(),h.label=6;case 6:return e.done?[3,10]:(r=e.value,s=r[0],this.logger.debug("Processing identity group",{batchSize:r.length,visitorId:null==s?void 0:s.visitorId,cuid:null==s?void 0:s.cuid,sessionId:null==s?void 0:s.sessionId}),[4,this.markEventsAsProcessing(r)]);case 7:return h.sent(),[4,this.sendBatch(r)];case 8:h.sent(),h.label=9;case 9:return e=n.next(),[3,6];case 10:return[3,13];case 11:return o=h.sent(),a={error:o},[3,13];case 12:try{e&&!e.done&&(c=n.return)&&c.call(n)}finally{if(a)throw a.error}return[7];case 13:return[4,this.storage.getPendingEventCount(this.currentAccountId)];case 14:return 0===h.sent()?(this.logger.debug(vr),[3,15]):[3,2];case 15:return[3,18];case 16:return u=h.sent(),this.logger.error(dr,{error:u}),[3,18];case 17:return this.isProcessing=!1,this.processingPromise=null,this.logger.debug(hr),[7];case 18:return[2]}})})},t.prototype.markEventsAsProcessing=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=ge(t),n=i.next(),a.label=1;case 1:if(n.done)return[3,6];e=n.value,a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.storage.updateEventStatus(e.id,"processing")];case 3:return a.sent(),[3,5];case 4:return r=a.sent(),this.logger.error(mr,{eventId:e.id,error:r}),[3,5];case 5:return n=i.next(),[3,1];case 6:return[3,9];case 7:return s=a.sent(),o={error:s},[3,9];case 8:try{n&&!n.done&&(u=i.return)&&u.call(i)}finally{if(o)throw o.error}return[7];case 9:return[2]}})})},t.prototype.sendBatch=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:if(h.trys.push([0,5,,10]),!this.currentAccountId)throw new Error("Missing account context for batch sending");return i=t[0],n=!!(null!==(c=i.visitorId)&&void 0!==c?c:i.visitorExternalId),e=!!i.cuid,r=void 0,r=n&&e?"identified":n?"anonymous":"user-only",this.logger.debug("Sending event batch",{batchSize:t.length,trackingMode:r,hasVisitor:n,hasUser:e}),s=t.filter(function(t){return!0===t.isDLR}),(o=t.filter(function(t){return!0!==t.isDLR})).length>0?[4,this.sendRegularEvents(o)]:[3,2];case 1:h.sent(),h.label=2;case 2:return s.length>0?[4,this.sendDLREvents(s)]:[3,4];case 3:h.sent(),h.label=4;case 4:return[2,!0];case 5:return u=h.sent(),a=this.isRetryableHttpError(u),this.logger.error(ar,{batchSize:t.length,hasDLREvents:t.some(function(t){return!0===t.isDLR}),error:u,isRetryable:a}),a?[4,this.handleFailedBatch(t)]:[3,7];case 6:return h.sent(),[3,9];case 7:return[4,this.removeNonRetryableEvents(t)];case 8:h.sent(),h.label=9;case 9:return[2,!1];case 10:return[2]}})})},t.prototype.sendRegularEvents=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l,v;return me(this,function(m){switch(m.label){case 0:if(i=t[0],n=null!==(h=i.visitorId)&&void 0!==h?h:null,e=null!==(d=i.visitorExternalId)&&void 0!==d?d:null,r=null!==(f=i.cuid)&&void 0!==f?f:null,s=null!==(l=i.userIdentifierType)&&void 0!==l?l:null,o=null!==(v=i.sessionId)&&void 0!==v?v:null,u=this.apiClient,a=t.map(function(t){return t.event}),!o)throw new Error("Session ID is required for event tracking");return[4,u.sendEvents(a,n||void 0,e||void 0,r||void 0,s||void 0,o)];case 1:return c=m.sent(),[4,this.handleBatchResponse(t,c)];case 2:return m.sent(),[2]}})})},t.prototype.sendDLREvents=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a;return me(this,function(c){switch(c.label){case 0:return i=t[0],n=this.apiClient,e=null!==(a=i.sessionId)&&void 0!==a?a:"",[4,fa()];case 1:return r=c.sent(),s=ra(e,r),o={events:t.map(function(t){var i=t.event,n=i.eventExternalId,e=function(t,i){var n={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&i.indexOf(e)<0&&(n[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(e=Object.getOwnPropertySymbols(t);r<e.length;r++)i.indexOf(e[r])<0&&Object.prototype.propertyIsEnumerable.call(t,e[r])&&(n[e[r]]=t[e[r]])}return n}(i,["eventExternalId"]);return le(le({},e),{eventRefId:n})}),request_id:ia(),system_data:s},i.cuid?o.user={identifierName:"id",identifierValue:i.cuid}:i.visitorId&&(o.visitor={identifierName:"id",identifierValue:i.visitorId}),[4,n.sendDLR(o)];case 2:return u=c.sent(),[4,this.handleBatchResponse(t,u,Ne.DLR_SUCCESS_CODE)];case 3:return c.sent(),[2]}})})},t.prototype.removeSuccessfulEvents=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:i=t.map(function(t){return t.id}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.storage.removeEvents(i)];case 2:return e.sent(),this.logger.debug("Successfully removed events from storage",{count:i.length}),[3,4];case 3:return n=e.sent(),this.logger.error(gr,{eventIds:i,error:n}),[3,4];case 4:return[2]}})})},t.prototype.handleBatchResponse=function(t,i){return ve(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=Ne.GLOBAL_SUCCESS_CODE),me(this,function(s){switch(s.label){case 0:return e=parseInt(i.status.code,10),r=t.some(function(t){return!0===t.isDLR}),e!==n?[3,2]:[4,this.removeSuccessfulEvents(t)];case 1:return s.sent(),this.logger.info("All events processed successfully",{count:t.length,hasDLREvents:r}),[3,8];case 2:return e!==Ne.PARTIAL_SUCCESS_CODE?[3,4]:[4,this.handlePartialSuccess(t,i.events)];case 3:return s.sent(),[3,8];case 4:return Ne.RETRYABLE_HTTP_CODES.includes(e)?[4,this.handleFailedBatch(t)]:[3,6];case 5:return s.sent(),this.logger.warn("Batch failed with retryable error",{code:e,message:i.status.message,hasDLREvents:r}),[3,8];case 6:return[4,this.removeNonRetryableEvents(t)];case 7:s.sent(),this.logger.error("Batch failed with non-retryable error",{code:e,message:i.status.message,hasDLREvents:r}),s.label=8;case 8:return[2]}})})},t.prototype.handlePartialSuccess=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h;return me(this,function(d){switch(d.label){case 0:n=new Map,i.forEach(function(t){n.set(t.eventExternalId,t)}),d.label=1;case 1:d.trys.push([1,12,13,14]),e=ge(t),r=e.next(),d.label=2;case 2:return r.done?[3,11]:(s=r.value,(o=n.get(s.event.eventExternalId))?[3,4]:[4,this.markEventForRetry(s,"No response received")]);case 3:return d.sent(),[3,10];case 4:return o.status.success?[4,this.storage.removeEvents([s.id])]:[3,6];case 5:return d.sent(),this.logger.debug("Event processed successfully",{eventId:s.id}),[3,10];case 6:return u=parseInt(o.status.code,10),Ne.RETRYABLE_HTTP_CODES.includes(u)?[4,this.markEventForRetry(s,o.status.message)]:[3,8];case 7:return d.sent(),[3,10];case 8:return[4,this.storage.removeEvents([s.id])];case 9:d.sent(),this.logger.warn("Event permanently failed - removed",{eventId:s.id,isDLR:s.isDLR,code:u,message:o.status.message}),d.label=10;case 10:return r=e.next(),[3,2];case 11:return[3,14];case 12:return a=d.sent(),c={error:a},[3,14];case 13:try{r&&!r.done&&(h=e.return)&&h.call(e)}finally{if(c)throw c.error}return[7];case 14:return[2]}})})},t.prototype.markEventForRetry=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r;return me(this,function(s){switch(s.label){case 0:return n=(t.attempts||0)+1,[4,this.storage.updateEventStatus(t.id,"failed","Attempt ".concat(n," failed: ").concat(i),n)];case 1:return s.sent(),e=Math.min(Math.max(n-1,0),this.RETRY_DELAYS.length-1),r=this.RETRY_DELAYS[e],this.logger.warn("Event marked for retry",{eventId:t.id,isDLR:t.isDLR,attempts:n,delay:r,isInfiniteRetry:n>this.RETRY_DELAYS.length,errorMessage:i}),[2]}})})},t.prototype.checkAndPromoteRetryEvents=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:return f.trys.push([0,10,,11]),this.currentAccountId?[4,this.storage.getRetryableEvents(this.currentAccountId,Number.MAX_SAFE_INTEGER)]:(this.logger.debug("No account context, skipping retry check"),[2]);case 1:if(0===(t=f.sent()).length)return[2];i=0,f.label=2;case 2:f.trys.push([2,7,8,9]),n=ge(t),e=n.next(),f.label=3;case 3:return e.done?[3,6]:(r=e.value,s=Math.min(Math.max(r.attempts-1,0),this.RETRY_DELAYS.length-1),o=this.RETRY_DELAYS[s],(u=Date.now()-(r.lastAttempt||0))>=(o||0)?[4,this.storage.updateEventStatus(r.id,"pending")]:[3,5]);case 4:f.sent(),i++,this.logger.debug("Failed event promoted to pending",{eventId:r.id,attempt:r.attempts+1,delay:o,timeSinceLastAttempt:u}),f.label=5;case 5:return e=n.next(),[3,3];case 6:return[3,9];case 7:return a=f.sent(),h={error:a},[3,9];case 8:try{e&&!e.done&&(d=n.return)&&d.call(n)}finally{if(h)throw h.error}return[7];case 9:return i>0&&this.logger.debug("Promoted ".concat(i," failed events for retry")),[3,11];case 10:return c=f.sent(),this.logger.error("Failed to check retry events",{error:c}),[3,11];case 11:return[2]}})})},t.prototype.isRetryableHttpError=function(t){var i,n,e,r,s=t;if(s.code){var o=parseInt(s.code,10);return Ne.RETRYABLE_HTTP_CODES.includes(o)}return null!==(r=(null===(i=s.message)||void 0===i?void 0:i.includes("network"))||(null===(n=s.message)||void 0===n?void 0:n.includes("timeout"))||(null===(e=s.message)||void 0===e?void 0:e.includes("fetch")))&&void 0!==r&&r},t.prototype.removeNonRetryableEvents=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:i=t.map(function(t){return t.id}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.storage.removeEvents(i)];case 2:return e.sent(),this.logger.error("Non-retryable events removed permanently",{eventIds:i}),[3,4];case 3:return n=e.sent(),this.logger.error("Failed to remove non-retryable events",{eventIds:i,error:n}),[3,4];case 4:return[2]}})})},t.prototype.handleFailedBatch=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=ge(t),n=i.next(),a.label=1;case 1:if(n.done)return[3,6];e=n.value,a.label=2;case 2:return a.trys.push([2,4,,5]),[4,this.markEventForRetry(e,"Batch failed")];case 3:return a.sent(),[3,5];case 4:return r=a.sent(),this.logger.error("Failed to mark event for retry",{eventId:e.id,error:r}),[3,5];case 5:return n=i.next(),[3,1];case 6:return[3,9];case 7:return s=a.sent(),o={error:s},[3,9];case 8:try{n&&!n.done&&(u=i.return)&&u.call(i)}finally{if(o)throw o.error}return[7];case 9:return[2]}})})},t.prototype.flush=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return[4,this.processQueueIfIdle()];case 1:return t.sent(),[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Destroying EventQueue"),this.processingPromise?[4,this.processingPromise]:[3,2];case 1:t.sent(),t.label=2;case 2:return[4,this.storage.close()];case 3:return t.sent(),this.logger.info("EventQueue destroyed"),[2]}})})},t.QUEUE_LOCK_NAME="websdk-event-queue-lock",t}(),ac=function(){function t(t,i,n,e){this.eventQueue=null,this.initialized=!1,this.visitorId=null,this.visitorTrackingEnabled=null,this.config=t,this.logger=e,this.apiClient=i,this.storageManager=n}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized?(this.logger.warn("EventTracker already initialized"),[2]):(this.logger.info("Initializing EventTracker with IndexedDB queue"),this.eventQueue=new uc(this.apiClient,this.logger,this.storageManager,this.config.retryDelays,this.config.batchSize),[4,this.eventQueue.init()]);case 1:return t.sent(),this.initialized=!0,this.logger.info(tr),[2]}})})},t.prototype.setUserContext=function(t,i,n){return ve(this,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:if(!this.eventQueue)throw new Error("EventTracker not initialized");return[4,this.eventQueue.setUserContext(t,i,n)];case 1:return e.sent(),this.logger.info("User context set",{accountId:t,cuid:i,userIdentifierType:n}),[2]}})})},t.prototype.setVisitorTrackingState=function(t,i,n){this.visitorId=t,this.visitorTrackingEnabled=i,this.eventQueue&&this.eventQueue.setVisitorContext(t,n),this.logger.debug("Visitor tracking state updated",{visitorId:t,visitorExternalId:n,isEnabled:i,trackingMode:t?"anonymous":"not-configured"})},t.prototype.setSessionInfoCallback=function(t){if(!this.eventQueue)throw new Error("EventTracker not initialized");this.eventQueue.setSessionInfoCallback(t),this.logger.debug("Session info callback set in EventTracker")},t.prototype.clearUserContext=function(){this.eventQueue?(this.eventQueue.clearUserContext(),this.logger.info("User context cleared from EventTracker")):this.logger.warn("Cannot clear user context - EventTracker not initialized")},t.prototype.track=function(t){return ve(this,arguments,void 0,function(t,i){var n,e;return void 0===i&&(i=!1),me(this,function(r){switch(r.label){case 0:if(!this.initialized||!this.eventQueue)throw new Error("EventTracker not initialized");if(!1===this.visitorTrackingEnabled&&!i)throw this.logger.warn("Event tracking is disabled - visitor tracking is not enabled"),new Error("Event tracking is disabled");this.logger.debug("Tracking event",{event:t}),r.label=1;case 1:return r.trys.push([1,3,,4]),n=this.convertToApiEvent(t),[4,this.eventQueue.enqueue(n)];case 2:return r.sent(),[3,4];case 3:throw e=r.sent(),this.logger.error(er,{event:t,error:e}),new Error("".concat(Le,": ").concat(e));case 4:return[2]}})})},t.prototype.convertToApiEvent=function(t){if(!t.name||""===t.name.trim())throw new Error("Event name is required");var i=le({},t.data);if(!this.eventQueue)throw new Error("EventTracker not initialized");var n,e=this.eventQueue.getCurrentCuid();if(!e&&!this.visitorId){var r=null===this.visitorTrackingEnabled?"Cannot track event: User must be identified (cuid) or visitor tracking must be configured":"Cannot track event: Either visitor tracking must be enabled or user must be identified";throw this.logger.error(r,{hasVisitorId:!!this.visitorId,hasCuid:!1,visitorTrackingEnabled:this.visitorTrackingEnabled}),new Error(r)}return n=this.visitorId&&e?"identified":this.visitorId?"anonymous":"user-only",this.logger.debug("Creating event payload",{eventName:t.name,hasCuid:!!e,hasVisitorId:!!this.visitorId,trackingMode:n,visitorTrackingEnabled:this.visitorTrackingEnabled}),function(t,i){if(!t||""===t.trim())throw new Error("Event name is required");return{name:t.trim(),eventExternalId:ia(),eventDateTime:(new Date).toISOString(),attributes:i||{}}}(t.name,i)},t.prototype.flush=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized&&this.eventQueue?(this.logger.info("Manual flush requested"),[4,this.eventQueue.flush()]):(this.logger.warn("Cannot flush events - EventTracker not initialized"),[2]);case 1:return t.sent(),[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Destroying EventTracker"),this.eventQueue?[4,this.eventQueue.destroy()]:[3,2];case 1:t.sent(),t.label=2;case 2:return this.initialized=!1,this.logger.info(ir),[2]}})})},t.prototype.trackNotificationReceived=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return[4,this.trackDLREvent("received",t)];case 1:return i.sent(),[2]}})})},t.prototype.trackNotificationClicked=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return[4,this.trackDLREvent("clicked",t)];case 1:return i.sent(),[2]}})})},t.prototype.trackNotificationDismissed=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return[4,this.trackDLREvent("dismissed",t)];case 1:return i.sent(),[2]}})})},t.prototype.trackDLREvent=function(t,i){return ve(this,void 0,void 0,function(){var n,e;return me(this,function(r){switch(r.label){case 0:if(!this.initialized||!this.eventQueue)return this.logger.error("EventTracker not initialized, skipping DLR event",{eventType:t}),[2];r.label=1;case 1:return r.trys.push([1,3,,4]),n=this.createDLREvent(t,i),[4,this.eventQueue.enqueue(n,!0)];case 2:return r.sent(),this.logger.info("DLR event tracked: ".concat(t),{eventType:t,eventName:n.name,messageId:i.messageId}),[3,4];case 3:return e=r.sent(),this.logger.error("Failed to track DLR event",{eventType:t,notificationData:i,error:e}),[3,4];case 4:return[2]}})})},t.prototype.createDLREvent=function(t,i){var n,e={received:Bs.NOTIFICATION_RECEIVED,clicked:Bs.NOTIFICATION_CLICKED,dismissed:Bs.NOTIFICATION_DISMISSED},r=null===(n=this.eventQueue)||void 0===n?void 0:n.getCurrentCuid(),s={messageId:i.messageId,gateway:zs,result:{received:"SUCCESS",clicked:"CLICKED",dismissed:"DISMISSED"}[t],notification_route:js,cuid:r||null,visitor_id:r?null:this.visitorId||null,scope:i.scope||null};return"received"===t&&(s.notification_id=i.messageId,s.campaign_id=i.campaignId||null,s.channel=js,s.title=i.title||null),"clicked"===t&&(s.notification_id=i.messageId,s.campaign_id=i.campaignId||null,s.channel=js,s.action="open_app"),i.senderId&&(s.senderId=i.senderId),{attributes:s,name:e[t],eventDateTime:(new Date).toISOString(),eventExternalId:ia()}},t.prototype.dispatchDLREvent=function(t){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:switch(i=le(le(le(le(le(le({messageId:t.messageId},void 0!==t.scope?{scope:t.scope}:{}),void 0!==t.campaignId?{campaignId:t.campaignId}:{}),void 0!==t.variationId?{variationId:t.variationId}:{}),void 0!==t.senderId?{senderId:t.senderId}:{}),void 0!==t.cuid?{cuid:t.cuid}:{}),void 0!==t.accountId?{accountId:t.accountId}:{}),t.type){case"received":return[3,1];case"clicked":return[3,3];case"dismissed":return[3,5]}return[3,7];case 1:return[4,this.trackNotificationReceived(i)];case 2:case 4:case 6:return n.sent(),[3,7];case 3:return[4,this.trackNotificationClicked(i)];case 5:return[4,this.trackNotificationDismissed(i)];case 7:return[2]}})})},t.prototype.processPendingServiceWorkerDLREvents=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:if(!this.initialized)return this.logger.error("EventTracker not initialized, skipping pending DLR event processing"),[2];a.label=1;case 1:return a.trys.push([1,12,,13]),[4,this.getServiceWorkerPendingDLREvents()];case 2:if(0===(t=a.sent()).length)return[2];this.logger.info("Processing pending service worker DLR events",{count:t.length}),a.label=3;case 3:a.trys.push([3,8,9,10]),i=ge(t),n=i.next(),a.label=4;case 4:return n.done?[3,7]:(e=n.value,[4,this.dispatchDLREvent(e)]);case 5:a.sent(),a.label=6;case 6:return n=i.next(),[3,4];case 7:return[3,10];case 8:return r=a.sent(),o={error:r},[3,10];case 9:try{n&&!n.done&&(u=i.return)&&u.call(i)}finally{if(o)throw o.error}return[7];case 10:return[4,this.clearServiceWorkerPendingDLREvents()];case 11:return a.sent(),this.logger.info("Processed pending service worker DLR events",{count:t.length}),[3,13];case 12:return s=a.sent(),this.logger.error("Failed to process pending service worker DLR events",{error:s}),[3,13];case 13:return[2]}})})},t.prototype.getServiceWorkerPendingDLREvents=function(){return ve(this,void 0,void 0,function(){var t=this;return me(this,function(i){return[2,new Promise(function(i){var n=indexedDB.open("WebSDK_DLR_SW",1);n.onerror=function(){t.logger.error("Failed to open WebSDK_DLR_SW database",n.error),i([])},n.onsuccess=function(){var e=n.result;if(!e.objectStoreNames.contains("pending_dlr_events"))return e.close(),void i([]);var r=e.transaction(["pending_dlr_events"],"readonly").objectStore("pending_dlr_events").getAll();r.onerror=function(){t.logger.error("Failed to read pending service worker DLR events",r.error),e.close(),i([])},r.onsuccess=function(){e.close(),i(r.result||[])}},n.onupgradeneeded=function(t){var i=t.target.result;i.objectStoreNames.contains("pending_dlr_events")||i.createObjectStore("pending_dlr_events",{keyPath:"id",autoIncrement:!0})}})]})})},t.prototype.clearServiceWorkerPendingDLREvents=function(){return ve(this,void 0,void 0,function(){var t=this;return me(this,function(i){return[2,new Promise(function(i){var n=indexedDB.open("WebSDK_DLR_SW",1);n.onerror=function(){t.logger.error("Failed to open WebSDK_DLR_SW database",n.error),i()},n.onsuccess=function(){var e=n.result;if(!e.objectStoreNames.contains("pending_dlr_events"))return e.close(),void i();var r=e.transaction(["pending_dlr_events"],"readwrite").objectStore("pending_dlr_events").clear();r.onerror=function(){t.logger.error("Failed to clear pending service worker DLR events",r.error),e.close(),i()},r.onsuccess=function(){e.close(),i()}},n.onupgradeneeded=function(t){var i=t.target.result;i.objectStoreNames.contains("pending_dlr_events")||i.createObjectStore("pending_dlr_events",{keyPath:"id",autoIncrement:!0})}})]})})},t}(),cc=function(){function t(t,i,n){this.initialized=!1,this.logger=t,this.brandId=i,this.applicationId=n,this.adapter=new hc(t)}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:if(this.initialized)return this.logger.warn("StorageManager already initialized"),[2];this.logger.info("Initializing StorageManager"),t=["WebSDK"],this.brandId&&t.push(this.brandId),this.applicationId&&t.push(this.applicationId),i=t.join("_"),r.label=1;case 1:return r.trys.push([1,6,,7]),this.isIndexedDBSupported()?(n=new oc(this.logger,i),[4,this.testStorageAdapter(n)]):[3,3];case 2:return r.sent(),this.adapter=n,this.logger.info("StorageManager initialized with IndexedDB",{dbName:i,brandId:this.brandId,applicationId:this.applicationId}),[3,5];case 3:return[4,this.testStorageAdapter(this.adapter)];case 4:r.sent(),this.logger.info("StorageManager initialized with localStorage"),r.label=5;case 5:return this.initialized=!0,[3,7];case 6:throw e=r.sent(),this.logger.error(pr,{brandId:this.brandId,applicationId:this.applicationId,dbName:i,error:e}),new Error("Storage initialization failed: ".concat(e));case 7:return[2]}})})},t.prototype.isIndexedDBSupported=function(){return"undefined"!=typeof window&&"indexedDB"in window&&null!==indexedDB},t.prototype.testStorageAdapter=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){switch(r.label){case 0:i=Ae,n=xe,r.label=1;case 1:return r.trys.push([1,5,,6]),[4,t.setItem(i,n)];case 2:return r.sent(),[4,t.getItem(i)];case 3:if(r.sent()!==n)throw new Error(yr);return[4,t.removeItem(i)];case 4:return r.sent(),[3,6];case 5:throw e=r.sent(),new Error("".concat(wr," ").concat(e));case 6:return[2]}})})},t.prototype.get=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.getItem(t)]})})},t.prototype.set=function(t,i){return ve(this,void 0,void 0,function(){return me(this,function(n){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.setItem(t,i)]})})},t.prototype.remove=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.removeItem(t)]})})},t.prototype.clear=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.clear()]})})},t.prototype.keys=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.getAllKeys(t)]})})},t.prototype.getIndexedDBAdapter=function(){return this.adapter instanceof oc?this.adapter:null},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:this.logger.info("Destroying StorageManager"),i.label=1;case 1:return i.trys.push([1,4,,5]),this.adapter instanceof oc?[4,this.adapter.close()]:[3,3];case 2:i.sent(),i.label=3;case 3:return this.initialized=!1,this.logger.info(Er),[3,5];case 4:return t=i.sent(),this.logger.error(_r,t),this.initialized=!1,[3,5];case 5:return[2]}})})},t}(),hc=function(){function t(t){this.logger=t}return t.prototype.getItem=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){try{return[2,localStorage.getItem(t)]}catch(i){throw this.logger.error("LocalStorage getItem failed",{key:t,error:i}),new Error("LocalStorage getItem failed: ".concat(i))}return[2]})})},t.prototype.setItem=function(t,i){return ve(this,void 0,void 0,function(){return me(this,function(n){try{localStorage.setItem(t,i)}catch(i){if(i instanceof DOMException&&(22===i.code||1014===i.code||"QuotaExceededError"===i.name||"NS_ERROR_DOM_QUOTA_REACHED"===i.name))throw this.logger.error("LocalStorage quota exceeded",{key:t,error:i}),new Error("LocalStorage quota exceeded");throw this.logger.error("LocalStorage setItem failed",{key:t,error:i}),new Error("LocalStorage setItem failed: ".concat(i))}return[2]})})},t.prototype.removeItem=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){try{localStorage.removeItem(t)}catch(i){throw this.logger.error("LocalStorage removeItem failed",{key:t,error:i}),new Error("LocalStorage removeItem failed: ".concat(i))}return[2]})})},t.prototype.clear=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){try{localStorage.clear()}catch(t){throw this.logger.error("LocalStorage clear failed",{error:t}),new Error("LocalStorage clear failed: ".concat(t))}return[2]})})},t.prototype.getAllKeys=function(t){return ve(this,void 0,void 0,function(){var i,n,e;return me(this,function(r){try{for(i=[],n=0;n<localStorage.length;n++)null!==(e=localStorage.key(n))&&i.push(e);return[2,t?i.filter(function(i){return i.startsWith(t)}):i]}catch(t){throw this.logger.error("LocalStorage getAllKeys failed",{error:t}),new Error("LocalStorage getAllKeys failed: ".concat(t))}return[2]})})},t}();!function(t){t[t.VERBOSE=0]="VERBOSE",t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.NONE=5]="NONE"}(sc||(sc={}));var dc=function(){function t(t,i){void 0===t&&(t=!1),void 0===i&&(i=sc.INFO),this.logs=[],this.maxLogs=1e3,this.context={orgId:"",accountId:"",visitorId:"",cuid:""},this.enabled=t,this.level=i}return t.prototype.setContext=function(t){this.context=le(le({},this.context),t)},Object.defineProperty(t.prototype,"contextPrefix",{get:function(){var t=this.context.cuid||this.context.visitorId,i=[this.context.orgId,this.context.accountId,t].filter(Boolean);return i.length>0?"[".concat(i.join(" -> "),"]"):""},enumerable:!1,configurable:!0}),t.prototype.formatMessage=function(t,i){var n=(new Date).toISOString(),e=sc[t];return"[".concat(n,"] [WebSDK:").concat(e,"] ").concat(i)},t.prototype.log=function(t,i,n){if(this.enabled&&!(t<this.level)){var e={level:t,message:i,timestamp:Date.now(),data:n};this.logs.push(e),this.logs.length>this.maxLogs&&this.logs.shift();var r=t===sc.INFO||t===sc.ERROR?this.contextPrefix:"",s=r?"".concat(r," ").concat(i):i,o=this.formatMessage(t,s),u=n?[o,n]:[o];switch(t){case sc.VERBOSE:case sc.DEBUG:console.debug.apply(console,we([],pe(u),!1));break;case sc.INFO:console.info.apply(console,we([],pe(u),!1));break;case sc.WARN:console.warn.apply(console,we([],pe(u),!1));break;case sc.ERROR:console.error.apply(console,we([],pe(u),!1))}}},t.prototype.verbose=function(t,i){this.log(sc.VERBOSE,t,i)},t.prototype.debug=function(t,i){this.log(sc.DEBUG,t,i)},t.prototype.info=function(t,i){this.log(sc.INFO,t,i)},t.prototype.warn=function(t,i){this.log(sc.WARN,t,i)},t.prototype.error=function(t,i){this.log(sc.ERROR,t,i)},t.prototype.setLevel=function(t){this.level=t},t.prototype.setEnabled=function(t){this.enabled=t},t.prototype.getLogs=function(){return we([],pe(this.logs),!1)},t.prototype.clearLogs=function(){this.logs=[]},t}(),fc=function(){function t(t,i,n,e,r,s){this.initialized=!1,this.cachedConfig=null,this.orgId=t,this.apiClient=i,this.logger=n,this.storageManager=e,void 0!==r&&(this.brandId=r),void 0!==s&&(this.applicationId=s)}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized?(this.logger.warn("VisitorConfigManager already initialized"),[2]):(this.logger.info("Initializing VisitorConfigManager",{orgId:this.orgId}),[4,this.restoreCachedConfig()]);case 1:return t.sent(),this.initialized=!0,this.logger.info(Rr),[2]}})})},t.prototype.fetchConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n=this;return me(this,function(e){switch(e.label){case 0:if(!this.initialized)throw new Error("VisitorConfigManager not initialized");if(this.cachedConfig)return this.logger.info(Fr),[2,this.cachedConfig];e.label=1;case 1:return e.trys.push([1,4,,5]),this.logger.info("Fetching visitor config from API",{orgId:this.orgId}),[4,this.apiClient.getVisitorConfig(this.orgId)];case 2:return(t=e.sent()).warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){n.logger.warn("Visitor config warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0&&t.errors.forEach(function(t){n.logger.error("Visitor config error from response",{code:t.code,message:t.message})}),this.cachedConfig=t,[4,this.storeCachedConfig(t)];case 3:return e.sent(),[2,t];case 4:throw i=e.sent(),new Error("".concat(Fe,": ").concat(i));case 5:return[2]}})})},t.prototype.isVisitorTrackingEnabled=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.fetchConfig()];case 1:return t=r.sent(),(i=!0===(null===(e=t.data)||void 0===e?void 0:e.visitorTrackingEnabled))?this.logger.info(Lr):this.logger.info(Ur),[2,i];case 2:return n=r.sent(),this.logger.error("Failed to check visitor tracking status",{error:n}),[2,!1];case 3:return[2]}})})},t.prototype.refreshConfig=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){if(!this.initialized)throw new Error("VisitorConfigManager not initialized");return this.logger.info("Force refreshing visitor config from API"),this.cachedConfig=null,[2,this.fetchConfig()]})})},t.prototype.getCachedConfig=function(){return this.cachedConfig},t.prototype.storeCachedConfig=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=ke("VISITOR_CONFIG",this.brandId,this.applicationId),[4,this.storageManager.set(i,JSON.stringify(t))];case 1:return e.sent(),this.logger.debug("Visitor config cached to storage",{key:i}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store visitor config to cache",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.restoreCachedConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r;return me(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=ke("VISITOR_CONFIG",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=s.sent())&&(n=JSON.parse(i),this.cachedConfig=n,this.logger.info("Visitor config restored from cache",{isEnabled:null===(r=n.data)||void 0===r?void 0:r.visitorTrackingEnabled})),[3,3];case 2:return e=s.sent(),this.logger.error("Failed to restore visitor config from cache",{error:e}),this.cachedConfig=null,[3,3];case 3:return[2]}})})},t.prototype.clearCachedConfig=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:this.cachedConfig=null,n.label=1;case 1:return n.trys.push([1,3,,4]),t=ke("VISITOR_CONFIG",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 2:return n.sent(),this.logger.debug("Visitor config cache cleared"),[3,4];case 3:return i=n.sent(),this.logger.error("Failed to clear visitor config cache",{error:i}),[3,4];case 4:return[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Destroying VisitorConfigManager"),[4,this.clearCachedConfig()];case 1:return t.sent(),this.initialized=!1,this.logger.info("VisitorConfigManager destroyed successfully"),[2]}})})},t}(),lc=function(){function t(t,i,n,e,r,s){this.initialized=!1,this.visitorId=null,this.visitorExternalId=null,this.expiredAt=null,this.getFcmToken=null,this.getChannelType=null,this.getExtendedFields=null,this.getPermissionGranted=null,this.getSessionId=null,this.mergeRetryTimeoutId=null,this.accountId=t,this.orgId=i,this.apiClient=n,this.logger=e,this.storageManager=r,void 0!==(null==s?void 0:s.brandId)&&(this.brandId=s.brandId),void 0!==(null==s?void 0:s.applicationId)&&(this.applicationId=s.applicationId)}return t.prototype.setMergeDataProviders=function(t,i,n,e,r){this.getFcmToken=t,this.getChannelType=i,this.getExtendedFields=n,this.getPermissionGranted=e,this.getSessionId=r},t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.initialized?(this.logger.warn("AnonymousVisitorManager already initialized"),[2]):(this.logger.info("Initializing AnonymousVisitorManager",{accountId:this.accountId,orgId:this.orgId}),[4,this.restoreVisitorId()]);case 1:return t.sent(),this.initialized=!0,this.logger.info(Gr),[2]}})})},t.prototype.getOrCreateVisitorId=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(!this.initialized)throw this.logger.error("getOrCreateVisitorId() called before AnonymousVisitorManager is initialized"),new Error("AnonymousVisitorManager not initialized");if(this.visitorId&&!this.isVisitorExpired())return this.logger.info(jr,{visitorId:this.visitorId}),[2,this.visitorId];if(this.visitorId&&this.isVisitorExpired()&&this.logger.info("Visitor session expired, creating new visitor via API",{visitorId:this.visitorId,expiredAt:this.expiredAt}),!this.accountId||""===this.accountId.trim())throw n=new Error("AccountId is required for visitor creation"),this.logger.error("Visitor creation validation failed",n),n;return this.logger.info("Creating new visitor ID",{accountId:this.accountId,hasCommChannels:!!t&&t.length>0,hasExtendedFields:!!i}),[4,this.createVisitor(t,i)];case 1:return e=o.sent(),r=e.visitorId,s=e.expiredAt,this.visitorId=r,[4,this.storeVisitorId(r)];case 2:return o.sent(),[4,this.storeExpiredAt(s)];case 3:return o.sent(),this.logger.info(Vr,{visitorId:r}),[2,r]}})})},t.prototype.createVisitor=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,3,,4]),[4,this.getOrGenerateVisitorExternalId()];case 1:return n=u.sent(),e=t&&t.length>0?t:[],r=le({visitorExternalId:n,profiles:[{commChannels:e}]},i&&{extendedFields:i}),this.logger.debug("Visitor creation request payload",{request:r}),[4,this.apiClient.createVisitor(this.orgId,r)];case 2:return s=u.sent(),[2,this.handleCreateVisitorResponse(s)];case 3:throw o=u.sent(),this.handleCreateVisitorError(o),o;case 4:return[2]}})})},t.prototype.handleCreateVisitorResponse=function(t){var i,n,e=this;t.warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){e.logger.warn("Visitor creation warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0&&t.errors.forEach(function(t){e.logger.error("Visitor creation error from response",{code:t.code,message:t.message})});var r=null===(i=t.data)||void 0===i?void 0:i.id;if(!r||""===r.trim())throw this.logger.error("Invalid visitor ID received from API",{response:t}),new Error("Invalid visitor ID received from API");var s=null===(n=t.data)||void 0===n?void 0:n.expiredAt;if(!s)throw this.logger.error("Missing expiredAt in visitor creation response",{response:t}),new Error("Missing expiredAt in visitor creation response");return{visitorId:r,expiredAt:s}},t.prototype.logCreateVisitorWarnings=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){t.code===Gs.ACCOUNT_NOT_EXISTS?i.logger.error("Account does not exist",{code:t.code,message:t.message,accountId:i.accountId}):i.logger.warn("Visitor creation warning",{code:t.code,message:t.message})}),!0)},t.prototype.logCreateVisitorErrors=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){t.code===Gs.ACCOUNT_ID_NOT_PASSED?i.logger.error("AccountId not passed",{code:t.code,message:t.message}):i.logger.error("Visitor creation error",{code:t.code,message:t.message})}),!0)},t.prototype.handleCreateVisitorError=function(t){var i;try{var n=(null===(i=t.response)||void 0===i?void 0:i.data)||t,e=this.logCreateVisitorWarnings(n.warnings),r=this.logCreateVisitorErrors(n.errors);e||r||this.logger.error("Visitor creation failed with an unrecognized error shape",{accountId:this.accountId,error:t})}catch(t){this.logger.error("Failed to parse visitor creation error",{parseError:t})}},t.prototype.updateVisitor=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(!this.initialized)throw new Error("AnonymousVisitorManager not initialized");if(!this.visitorId)throw new Error("No visitor ID exists. Create a visitor first.");o.label=1;case 1:return o.trys.push([1,3,,4]),n=t&&t.length>0?t:[],e=le({profiles:[{commChannels:n}]},i&&{extendedFields:i}),this.logger.debug("Visitor update request payload",{request:e}),[4,this.apiClient.updateVisitor(this.orgId,this.visitorId,e)];case 2:return r=o.sent(),[2,this.handleUpdateVisitorResponse(r)];case 3:throw s=o.sent(),this.handleUpdateVisitorError(s),s;case 4:return[2]}})})},t.prototype.handleUpdateVisitorResponse=function(t){var i,n=this;t.warnings&&t.warnings.length>0&&t.warnings.forEach(function(t){n.logger.warn("Visitor update warning",{code:t.code,message:t.message})}),t.errors&&t.errors.length>0&&t.errors.forEach(function(t){n.logger.error("Visitor update error from response",{code:t.code,message:t.message})});var e=null===(i=t.data)||void 0===i?void 0:i.id;if(!e||""===e.trim())throw this.logger.error("Invalid visitor ID received from update API",{response:t}),new Error("Invalid visitor ID received from update API");return e},t.prototype.logUpdateVisitorWarnings=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){t.code===Gs.ACCOUNT_NOT_EXISTS?i.logger.error("Account does not exist",{code:t.code,message:t.message,accountId:i.accountId}):i.logger.warn("Visitor update warning",{code:t.code,message:t.message})}),!0)},t.prototype.logUpdateVisitorErrors=function(t){var i=this;return!(!t||0===t.length)&&(t.forEach(function(t){i.logger.error("Visitor update error",{code:t.code,message:t.message})}),!0)},t.prototype.handleUpdateVisitorError=function(t){var i;try{var n=(null===(i=t.response)||void 0===i?void 0:i.data)||t,e=this.logUpdateVisitorWarnings(n.warnings),r=this.logUpdateVisitorErrors(n.errors);e||r||this.logger.error("Visitor update failed with an unrecognized error shape",{visitorId:this.visitorId,error:t})}catch(t){this.logger.error("Failed to parse visitor update error",{parseError:t})}},t.prototype.mergeVisitorWithUser=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:if(i=t.firstName,n=t.lastName,e=t.email,r=t.mobile,s=t.externalId,o=t.customData,u=t.cuid,a=t.identifierType,!this.initialized)return this.logger.warn(Xr,{reason:"Not initialized"}),[2,!1];if(!this.visitorId)return this.logger.warn(Xr,{reason:"No visitor ID"}),[2,!1];if(!e&&!r&&!s)return this.logger.warn(Xr,{reason:"No email, mobile, or externalId"}),[2,!1];c=this.visitorId,h=this.visitorExternalId,f.label=1;case 1:return f.trys.push([1,5,,6]),[4,this.isMerged()];case 2:return f.sent()?(this.logger.info(Xr,{reason:"Visitor already merged",visitorId:c}),[2,!0]):[4,this.persistPendingMerge(c,h,le(le(le(le(le(le({firstName:i,lastName:n},void 0!==e&&{email:e}),void 0!==r&&{mobile:r}),void 0!==s&&{externalId:s}),void 0!==o&&{customData:o}),void 0!==u&&{cuid:u}),void 0!==a&&{identifierType:a}))];case 3:return f.sent(),[4,this.attemptPendingMerge()];case 4:return f.sent(),[2,this.isMerged()];case 5:return d=f.sent(),this.logger.error("Merge background task failed unexpectedly",{error:d}),[2,!1];case 6:return[2]}})})},t.prototype.retryPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,7,,8]),[4,this.getPendingMerge()];case 1:return(t=n.sent())?[4,this.isMerged()]:[2];case 2:return n.sent()?[4,this.clearPendingMerge()]:[3,4];case 3:return n.sent(),this.logger.info(Xr,{reason:"Already merged"}),[2];case 4:return t.attempts>=Ms?(this.logger.error(Wr,{visitorId:t.visitorId,attempts:t.attempts,message:"Max retries exhausted"}),[4,this.clearPendingMerge()]):[3,6];case 5:return n.sent(),[2];case 6:return this.scheduleMergeRetry(),[3,8];case 7:return i=n.sent(),this.logger.error("Failed to retry pending merge",{error:i}),[3,8];case 8:return[2]}})})},t.prototype.cancelMergeRetryTimer=function(){null!==this.mergeRetryTimeoutId&&(globalThis.clearTimeout(this.mergeRetryTimeoutId),this.mergeRetryTimeoutId=null)},t.prototype.scheduleMergeRetry=function(){var t=this;this.cancelMergeRetryTimer(),this.mergeRetryTimeoutId=globalThis.setTimeout(function(){t.mergeRetryTimeoutId=null,t.attemptPendingMerge().catch(function(i){t.logger.error("Scheduled merge retry failed unexpectedly",{error:i})})},Us)},t.prototype.collectMergeContext=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:t=this.getFcmToken?this.getFcmToken():null,i=this.getChannelType?this.getChannelType():void 0,n=!this.getPermissionGranted||this.getPermissionGranted(),e=this.getSessionId?this.getSessionId():"",u.label=1;case 1:return u.trys.push([1,5,,6]),this.getExtendedFields?[4,this.getExtendedFields()]:[3,3];case 2:return s=u.sent(),[3,4];case 3:s=void 0,u.label=4;case 4:return r=s,[3,6];case 5:return o=u.sent(),this.logger.error("Failed to collect extended fields for merge, proceeding without them",{error:o}),r=void 0,[3,6];case 6:return[2,{fcmToken:t,channelType:i,subscribed:n,sessionId:e,extendedFields:r}]}})})},t.prototype.attemptPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return me(this,function(a){switch(a.label){case 0:return[4,this.getPendingMerge()];case 1:return(t=a.sent())?[4,this.collectMergeContext()]:(this.logger.debug("attemptPendingMerge() found no pending merge to attempt"),[2]);case 2:i=a.sent(),n=i.fcmToken,e=i.channelType,r=i.subscribed,s=i.sessionId,o=i.extendedFields,a.label=3;case 3:return a.trys.push([3,7,,9]),[4,this.apiClient.mergeVisitor(t.visitorId,t.visitorExternalId||null,le(le(le(le(le(le(le(le(le(le({firstName:t.firstName,lastName:t.lastName},void 0!==t.email&&{email:t.email}),void 0!==t.mobile&&{mobile:t.mobile}),n?{fcmToken:n,subscribed:r}:{}),void 0!==e&&{channelType:e}),{fields:t.customData||{}}),void 0!==o&&{extendedFields:o}),void 0!==t.externalId&&{externalId:t.externalId}),void 0!==t.cuid&&{cuid:t.cuid}),void 0!==t.identifierType&&{identifierType:t.identifierType}),{sessionId:s}))];case 4:return a.sent(),[4,this.markAsMerged(t.visitorId)];case 5:return a.sent(),[4,this.clearPendingMerge()];case 6:return a.sent(),this.logger.info(Kr,{visitorId:t.visitorId,attempts:t.attempts+1}),[3,9];case 7:return u=a.sent(),[4,this.handleMergeRetryOrAbort(u,t)];case 8:return a.sent(),[3,9];case 9:return[2]}})})},t.prototype.handleMergeRetryOrAbort=function(t,i){return ve(this,void 0,void 0,function(){var n;return me(this,function(e){switch(e.label){case 0:return t instanceof rc?[4,this.clearPendingMerge()]:[3,2];case 1:return e.sent(),this.logger.error("Visitor merge failed permanently, will not retry",{code:t.code,message:t.message,visitorId:i.visitorId}),[2];case 2:return n=le(le({},i),{attempts:i.attempts+1}),[4,this.savePendingMerge(n)];case 3:return e.sent(),n.attempts>=Ms?(this.logger.error(Wr,{visitorId:i.visitorId,attempts:n.attempts,message:"Max retries exhausted"}),[4,this.clearPendingMerge()]):[3,5];case 4:return e.sent(),[2];case 5:return this.logger.warn("Visitor merge attempt failed, scheduling retry",{attempt:n.attempts,maxRetries:Ms,nextRetryMs:Us,visitorId:i.visitorId,error:t}),this.scheduleMergeRetry(),[2]}})})},t.prototype.persistPendingMerge=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:return e=n.firstName,r=n.lastName,s=n.email,o=n.mobile,u=n.externalId,a=n.customData,c=n.cuid,h=n.identifierType,d=le(le(le(le(le(le(le(le(le({visitorId:t},i&&{visitorExternalId:i}),{firstName:e,lastName:r}),void 0!==s&&{email:s}),void 0!==o&&{mobile:o}),void 0!==u&&{externalId:u}),void 0!==a&&{customData:a}),void 0!==c&&{cuid:c}),void 0!==h&&{identifierType:h}),{attempts:0}),[4,this.savePendingMerge(d)];case 1:return f.sent(),this.logger.debug("Pending merge request persisted to storage",{visitorId:t}),[2]}})})},t.prototype.getPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=ke("PENDING_MERGE",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=e.sent())?[2,JSON.parse(i)]:[2,null];case 2:return n=e.sent(),this.logger.error("Failed to read pending merge from storage",{error:n}),[2,null];case 3:return[2]}})})},t.prototype.savePendingMerge=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=ke("PENDING_MERGE",this.brandId,this.applicationId),[4,this.storageManager.set(i,JSON.stringify(t))];case 1:return e.sent(),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to save pending merge to storage",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.clearPendingMerge=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:this.cancelMergeRetryTimer(),n.label=1;case 1:return n.trys.push([1,3,,4]),t=ke("PENDING_MERGE",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 2:return n.sent(),this.logger.debug("Pending merge cleared from storage"),[3,4];case 3:return i=n.sent(),this.logger.error("Failed to clear pending merge from storage",{error:i}),[3,4];case 4:return[2]}})})},t.prototype.isMerged=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=ke("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return[2,null!=n.sent()];case 2:return i=n.sent(),this.logger.error("Failed to check merge status",{error:i}),[2,!1];case 3:return[2]}})})},t.prototype.getMergedUserId=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=ke("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return[2,null!=(i=e.sent())?i:null];case 2:return n=e.sent(),this.logger.error("Failed to get merge status",{error:n}),[2,null];case 3:return[2]}})})},t.prototype.clearMergedUserId=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=ke("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 1:return n.sent(),this.logger.info("Merge status cleared from storage"),[3,3];case 2:return i=n.sent(),this.logger.error("Failed to clear merge status",{error:i}),[3,3];case 3:return[2]}})})},t.prototype.markAsMerged=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=ke("MERGED_USER_ID",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 1:return e.sent(),this.logger.debug("Visitor marked as merged",{visitorId:t,key:i}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store merge status",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.getVisitorId=function(){return this.visitorId},t.prototype.getVisitorExternalId=function(){return this.visitorExternalId},t.prototype.hasVisitorId=function(){return null!==this.visitorId},t.prototype.storeVisitorId=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=ke("VISITOR_ID",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 1:return e.sent(),this.logger.debug("Visitor ID stored to storage",{visitorId:t,key:i}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store visitor ID",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.storeExpiredAt=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.expiredAt=t,i=ke("VISITOR_EXPIRED_AT",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 1:return e.sent(),this.logger.debug("Visitor expiredAt stored to storage",{expiredAt:t}),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to store visitor expiredAt",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.isVisitorExpired=function(){if(!this.expiredAt)return!0;try{return new Date(this.expiredAt).getTime()<=Date.now()}catch(t){return this.logger.error("Invalid expiredAt format, treating as expired",{expiredAt:this.expiredAt}),!0}},t.prototype.getOrGenerateVisitorExternalId=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:if(this.visitorExternalId)return[2,this.visitorExternalId];t=ia(),this.visitorExternalId=t,e.label=1;case 1:return e.trys.push([1,3,,4]),i=ke("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),[4,this.storageManager.set(i,t)];case 2:return e.sent(),this.logger.debug("visitorExternalId generated and stored",{visitorExternalId:t}),[3,4];case 3:return n=e.sent(),this.logger.error("Failed to store visitorExternalId",{error:n}),[3,4];case 4:return[2,t]}})})},t.prototype.restoreVisitorId=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),t=ke("VISITOR_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=u.sent())&&(this.visitorId=i,this.logger.info(zr,{visitorId:i})),n=ke("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),[4,this.storageManager.get(n)];case 2:return(e=u.sent())&&(this.visitorExternalId=e),r=ke("VISITOR_EXPIRED_AT",this.brandId,this.applicationId),[4,this.storageManager.get(r)];case 3:return(s=u.sent())&&(this.expiredAt=s),[3,5];case 4:return o=u.sent(),this.logger.error("Failed to restore visitor ID from storage",{accountId:this.accountId,error:o}),this.visitorId=null,[3,5];case 5:return[2]}})})},t.prototype.clearVisitorId=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),t=ke("VISITOR_ID",this.brandId,this.applicationId),i=ke("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),n=ke("VISITOR_EXPIRED_AT",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 1:return r.sent(),[4,this.storageManager.remove(i)];case 2:return r.sent(),[4,this.storageManager.remove(n)];case 3:return r.sent(),this.visitorId=null,this.visitorExternalId=null,this.expiredAt=null,this.logger.info("Visitor ID cleared from storage"),[3,5];case 4:return e=r.sent(),this.logger.error("Failed to clear visitor ID",{error:e}),this.visitorId=null,this.visitorExternalId=null,this.expiredAt=null,[3,5];case 5:return[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.logger.info("Destroying AnonymousVisitorManager"),this.cancelMergeRetryTimer(),this.initialized=!1,this.logger.info("AnonymousVisitorManager destroyed successfully"),[2]})})},t}();function vc(){return"undefined"!=typeof window&&window.firebase?window.firebase:null}function mc(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){return(t=vc())?[2,t]:[2,import("firebase/app")]})})}function gc(){return ve(this,void 0,void 0,function(){return me(this,function(t){return[2,import("firebase/messaging")]})})}function pc(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){return(t=vc())&&t.remoteConfig?[2,t]:[2,import("firebase/remote-config")]})})}var wc=function(){function t(t,i,n,e,r,s){this.isInitialized=!1,this.currentToken=null,this.swRegistration=null,this.messaging=t,this.logger=i,this.vapidKey=n,this.serviceWorkerPath=e||De,this.onTokenReceivedCallback=r,this.onMessageReceivedCallback=s}return t.prototype.initialize=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.isInitialized?(this.logger.warn(us),[2,!0]):this.messaging?(this.isInitialized=!0,this.logger.info(Zr),[2,!0]):(this.logger.error(ts,new Error("Messaging instance missing")),[2,!1])})})},t.prototype.ensureServiceWorkerRegistered=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:return this.swRegistration?[2,this.swRegistration]:this.isInitialized&&this.messaging?(t=this,[4,this.registerServiceWorker()]):(this.logger.warn("ensureServiceWorkerRegistered() called before Firebase is initialized",{isInitialized:this.isInitialized,hasMessaging:!!this.messaging}),[2,null]);case 1:return t.swRegistration=i.sent(),[2,this.swRegistration]}})})},t.prototype.registerServiceWorker=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:if(!("serviceWorker"in navigator))return this.logger.warn(os),[2,null];e.label=1;case 1:return e.trys.push([1,7,,8]),[4,navigator.serviceWorker.getRegistration(this.serviceWorkerPath)];case 2:return(t=e.sent())?(this.logger.info("Service worker already registered",{scope:t.scope}),[4,this.ensureServiceWorkerActive(t)]):[3,4];case 3:return e.sent(),[2,t];case 4:return this.logger.info("Registering service worker",{path:this.serviceWorkerPath}),[4,navigator.serviceWorker.register(this.serviceWorkerPath)];case 5:return i=e.sent(),this.logger.info(rs,{scope:i.scope}),[4,this.ensureServiceWorkerActive(i)];case 6:return e.sent(),[2,i];case 7:return n=e.sent(),this.logger.error(ss,n),[2,null];case 8:return[2]}})})},t.prototype.ensureServiceWorkerActive=function(t){return ve(this,void 0,void 0,function(){var i,n=this;return me(this,function(e){return t.active?(this.logger.debug("Service worker is already active"),[2]):(i=t.installing||t.waiting)?(this.logger.info("Waiting for service worker to activate...",{state:i.state}),[2,new Promise(function(t,e){if("activated"!==i.state){var r=function(){"activated"===i.state?(i.removeEventListener("statechange",r),n.logger.info("Service worker activated"),t()):"redundant"===i.state&&(i.removeEventListener("statechange",r),e(new Error("Service worker became redundant")))};i.addEventListener("statechange",r)}else t()})]):(this.logger.warn(cs),[2])})})},t.prototype.requestToken=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(as),[2,null];r.label=1;case 1:return r.trys.push([1,5,,6]),(i=this.swRegistration)?[3,3]:[4,this.registerServiceWorker()];case 2:i=r.sent(),r.label=3;case 3:return(t=i)?(this.swRegistration=t,[4,this.fetchFCMToken(t)]):(this.logger.error(hs),[2,null]);case 4:return(n=r.sent())?(this.currentToken=n,this.logger.info(is,{token:n}),this.onTokenReceivedCallback&&this.onTokenReceivedCallback(n),[2,n]):(this.logger.error(ds),[2,null]);case 5:return e=r.sent(),this.logger.error(es,{error:e}),[2,null];case 6:return[2]}})})},t.prototype.fetchFCMToken=function(t){return ve(this,void 0,void 0,function(){var i,n;return me(this,function(e){switch(e.label){case 0:return[4,gc()];case 1:return i=e.sent().getToken,n={serviceWorkerRegistration:t},this.vapidKey&&(n.vapidKey=this.vapidKey),[2,i(this.messaging,n)]}})})},t.prototype.setupMessageListener=function(){return ve(this,void 0,void 0,function(){var t,i=this;return me(this,function(n){switch(n.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(as),[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,gc()];case 2:return(0,n.sent().onMessage)(this.messaging,function(t){i.handleMessage(t)}),this.logger.info("Message listener setup successfully"),[3,4];case 3:return t=n.sent(),this.logger.error(fs,{error:t}),[3,4];case 4:return[2]}})})},t.prototype.handleMessage=function(t){if(this.logger.info("FCM message received",t),t&&(t.notification||t.data)||this.logger.warn(ls,t),this.onMessageReceivedCallback)try{this.onMessageReceivedCallback(t)}catch(t){this.logger.error(vs,{error:t})}},t.prototype.getCurrentToken=function(){return this.currentToken},t.prototype.isFirebaseInitialized=function(){return this.isInitialized},t.prototype.destroy=function(){this.isInitialized=!1,this.messaging=null,this.currentToken=null,this.swRegistration=null,this.logger.info("FirebaseManager destroyed successfully")},t}(),yc=function(){function t(t,i,n,e,r){this.firebaseManager=null,this.tokenUpdateCallback=null,this.config=t,this.logger=i,this.storageManager=n,this.brandId=e,this.applicationId=r,this.config.onTokenRefresh&&this.logger.warn("notifications.onTokenRefresh has no effect — the modular Firebase SDK has no token-refresh event to fire it from. Call NotificationManager.refreshToken() to manually re-request a token instead."),this.state={isNotificationEnabled:!1,firebaseInitialized:!1,permissionStatus:"default"}}return t.prototype.isNotificationSupported=function(){return"undefined"!=typeof window&&"undefined"!=typeof Notification&&"undefined"!=typeof navigator&&"serviceWorker"in navigator},t.prototype.getPermissionStatus=function(){return this.isNotificationSupported()?Notification.permission:"denied"},t.prototype.shouldInitializeNotifications=function(){return this.isNotificationSupported()?!!this.config.messaging||(this.logger.info(gs),!1):(this.logger.info(ms),!1)},t.prototype.restoreState=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r;return me(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=ke("NOTIFICATION_STATE",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=s.sent())&&(n=JSON.parse(i),e=this.getPermissionStatus(),this.state=le(le(le({},this.state),n),{permissionStatus:e}),this.logger.info("Notification state restored from storage",{storedPermission:n.permissionStatus,currentPermission:e,hasToken:!!n.fcmToken})),[3,3];case 2:return r=s.sent(),this.logger.error(ps,{error:r}),[3,3];case 3:return[2]}})})},t.prototype.saveState=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=ke("NOTIFICATION_STATE",this.brandId,this.applicationId),[4,this.storageManager.set(t,JSON.stringify(this.state))];case 1:return n.sent(),this.logger.debug("Notification state saved to storage",this.state),[3,3];case 2:return i=n.sent(),this.logger.error(ws,{error:i}),[3,3];case 3:return[2]}})})},t.prototype.init=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,15,,17]),[4,this.restoreState()];case 1:return n.sent(),this.shouldInitializeNotifications()?[3,3]:(this.logger.info($r),this.state.isNotificationEnabled=!1,[4,this.saveState()]);case 2:return n.sent(),[2,this.state];case 3:return t=this.getPermissionStatus(),this.state.permissionStatus=t,this.logger.info("Current notification permission",{permission:t,hasStoredToken:!!this.state.fcmToken,isNotificationEnabled:this.state.isNotificationEnabled}),"denied"!==t?[3,5]:(this.logger.info(Yr),this.state.isNotificationEnabled=!1,this.state.fcmToken&&(this.logger.info("Clearing stored FCM token because notification permission is denied"),delete this.state.fcmToken),[4,this.saveState()]);case 4:return n.sent(),[2,this.state];case 5:return"default"!==t?[3,7]:(this.logger.info("Permission not yet granted - notifications will not be shown until user grants permission"),this.state.isNotificationEnabled=!1,[4,this.saveState()]);case 6:return n.sent(),[2,this.state];case 7:return"granted"!==t?[3,14]:this.state.fcmToken?(this.logger.info("Using existing FCM token from storage",{token:this.state.fcmToken.substring(0,20)+"..."}),this.state.isNotificationEnabled=!0,this.firebaseManager?[3,9]:(this.logger.info("Initializing Firebase for message listening"),[4,this.initializeFirebaseForMessaging()])):[3,11];case 8:n.sent(),n.label=9;case 9:return[4,this.saveState()];case 10:return n.sent(),[2,this.state];case 11:return this.logger.info("Permission granted - initializing Firebase to generate FCM token"),[4,this.initializeFirebase()];case 12:return n.sent(),[4,this.saveState()];case 13:n.sent(),n.label=14;case 14:return this.logger.info(Jr,this.state),[2,this.state];case 15:return i=n.sent(),this.logger.error(Qr,i),this.state.isNotificationEnabled=!1,[4,this.saveState()];case 16:return n.sent(),[2,this.state];case 17:return[2]}})})},t.prototype.initializeFirebaseForMessaging=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:if(!this.config.messaging)throw new Error("Firebase Messaging instance is required");i.label=1;case 1:return i.trys.push([1,5,,6]),this.firebaseManager=new wc(this.config.messaging,this.logger,this.config.vapidKey,this.config.serviceWorkerPath,this.config.onTokenReceived,this.config.onMessageReceived),[4,this.firebaseManager.initialize()];case 2:if(!i.sent())throw new Error("Firebase initialization failed");return this.state.firebaseInitialized=!0,[4,this.firebaseManager.ensureServiceWorkerRegistered()];case 3:return i.sent(),[4,this.firebaseManager.setupMessageListener()];case 4:return i.sent(),this.logger.info("Firebase initialized for message listening"),[3,6];case 5:throw t=i.sent(),this.logger.error(ys,t),t;case 6:return[2]}})})},t.prototype.initializeFirebase=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:if(!this.config.messaging)throw new Error("Firebase Messaging instance is required");n.label=1;case 1:return n.trys.push([1,7,,8]),this.firebaseManager=new wc(this.config.messaging,this.logger,this.config.vapidKey,this.config.serviceWorkerPath,this.config.onTokenReceived,this.config.onMessageReceived),[4,this.firebaseManager.initialize()];case 2:if(!n.sent())throw new Error("Firebase initialization failed");return this.state.firebaseInitialized=!0,this.state.isNotificationEnabled=!0,[4,this.firebaseManager.requestToken()];case 3:return(t=n.sent())?(this.state.fcmToken=t,[4,this.storeFCMToken(t)]):[3,5];case 4:n.sent(),n.label=5;case 5:return[4,this.firebaseManager.setupMessageListener()];case 6:return n.sent(),this.logger.info("Firebase initialized and FCM token retrieved",{hasToken:!!t}),[3,8];case 7:throw i=n.sent(),this.logger.error(ts,i),this.state.firebaseInitialized=!1,this.state.isNotificationEnabled=!1,i;case 8:return[2]}})})},t.prototype.storeFCMToken=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,6,,7]),i=ke("FCM_TOKEN",this.brandId,this.applicationId),n=ke("FCM_TOKEN_CREATED_AT",this.brandId,this.applicationId),[4,this.storageManager.get(i)];case 1:return e=u.sent(),r=!e||e!==t,[4,this.storageManager.set(i,t)];case 2:return u.sent(),r?(s=(new Date).toISOString(),[4,this.storageManager.set(n,s)]):[3,4];case 3:return u.sent(),this.logger.debug("FCM token and creation date stored successfully",{createdAt:s}),[3,5];case 4:this.logger.debug("FCM token stored (creation date unchanged)"),u.label=5;case 5:return this.tokenUpdateCallback&&(this.logger.info("Notifying token update callback",{isNewToken:r,tokenPreview:t.substring(0,20)+"..."}),this.tokenUpdateCallback(t,r)),[3,7];case 6:return o=u.sent(),this.logger.error(Es,{error:o}),[3,7];case 7:return[2]}})})},t.prototype.setTokenUpdateCallback=function(t){this.tokenUpdateCallback=t,this.logger.debug("Token update callback registered")},t.prototype.clearTokenUpdateCallback=function(){this.tokenUpdateCallback=null,this.logger.debug("Token update callback cleared")},t.prototype.getState=function(){return le({},this.state)},t.prototype.getFCMToken=function(){return this.state.fcmToken||null},t.prototype.getTokenCreationDate=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=ke("FCM_TOKEN_CREATED_AT",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return[2,n.sent()||null];case 2:return i=n.sent(),this.logger.error(_s,i),[2,null];case 3:return[2]}})})},t.prototype.isEnabled=function(){return this.state.isNotificationEnabled},t.prototype.getFirebaseManager=function(){return this.firebaseManager},t.prototype.refreshToken=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:if(!this.firebaseManager||!this.state.isNotificationEnabled)return this.logger.info(Is),[2,null];n.label=1;case 1:return n.trys.push([1,6,,7]),[4,this.firebaseManager.requestToken()];case 2:return(t=n.sent())?(this.state.fcmToken=t,[4,this.storeFCMToken(t)]):[3,5];case 3:return n.sent(),[4,this.saveState()];case 4:n.sent(),this.logger.info(ns,{token:t}),n.label=5;case 5:return[2,t];case 6:return i=n.sent(),this.logger.error(bs,i),[2,null];case 7:return[2]}})})},t.prototype.clearToken=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.logger.info("Clearing notification state (permission revoked)"),t=this.state.fcmToken,this.state.isNotificationEnabled=!1,this.state.firebaseInitialized=!1,this.firebaseManager&&(this.firebaseManager.destroy(),this.firebaseManager=null),[4,this.saveState()];case 1:return n.sent(),this.tokenUpdateCallback&&t&&(this.logger.info("Notifying permission revoked to sync push_opted:false with backend"),this.tokenUpdateCallback(t,!0)),this.logger.info("Notification state cleared"),[3,3];case 2:throw i=n.sent(),this.logger.error(Ts,i),i;case 3:return[2]}})})},t.prototype.hasPermissionChanged=function(){return this.getPermissionStatus()!==this.state.permissionStatus},t.prototype.handlePermissionChange=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return t=this.getPermissionStatus(),i=this.state.permissionStatus,this.logger.info("Permission status changed",{from:i,to:t}),this.state.permissionStatus=t,"denied"!==t&&"default"!==t?[3,5]:"granted"!==i?[3,2]:(this.logger.warn(Ss),[4,this.clearToken()]);case 1:return n.sent(),[3,4];case 2:return this.state.isNotificationEnabled=!1,[4,this.saveState()];case 3:n.sent(),n.label=4;case 4:return[3,10];case 5:return"granted"!==t||"granted"===i?[3,10]:this.config.messaging?[3,6]:(this.logger.warn(gs),this.state.isNotificationEnabled=!1,[3,8]);case 6:return this.logger.info("Permission granted - initializing Firebase"),[4,this.initializeFirebase()];case 7:n.sent(),n.label=8;case 8:return[4,this.saveState()];case 9:n.sent(),n.label=10;case 10:return[2,this.state]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.firebaseManager&&(this.firebaseManager.destroy(),this.firebaseManager=null),t=ke("NOTIFICATION_STATE",this.brandId,this.applicationId),[4,this.storageManager.remove(t)];case 1:return n.sent(),this.logger.info("NotificationManager destroyed successfully"),[3,3];case 2:return i=n.sent(),this.logger.error(Cs,i),[3,3];case 3:return[2]}})})},t}(),Ec=function(){function t(t,i,n,e,r){this.currentSession=null,this.sessionNumber=0,this.storageManager=t,this.logger=i,this.brandId=n,this.applicationId=e;var s=Ce/6e4;this.inactivityTimeoutMs=60*(r||s)*1e3,this.logger.info("SessionManager configured with timeout:",{timeoutMinutes:r||s,timeoutMs:this.inactivityTimeoutMs,source:r?"Remote Config":"Default"})}return t.prototype.init=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.logger.info("Initializing SessionManager"),[4,this.restoreSessionNumber()];case 1:return t.sent(),[4,this.restoreSession()];case 2:return t.sent(),this.logger.info("SessionManager initialized successfully"),[2]}})})},t.prototype.getOrCreateSession=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return t=Date.now(),this.currentSession?(i=t-this.currentSession.lastEventTime)<this.inactivityTimeoutMs?(this.currentSession.lastEventTime=t,[4,this.persistSession()]):[3,2]:[3,3];case 1:return n.sent(),this.logger.debug(br,{sessionId:this.currentSession.sessionId,inactivityDuration:i}),[2,this.currentSession.sessionId];case 2:this.logger.info(Tr,{sessionId:this.currentSession.sessionId,inactivityDuration:i,timeoutMs:this.inactivityTimeoutMs}),n.label=3;case 3:return[2,this.startNewSession()]}})})},t.prototype.getSessionStartTime=function(){var t;return(null===(t=this.currentSession)||void 0===t?void 0:t.sessionStartTime)||null},t.prototype.getCurrentSessionId=function(){var t,i;return null!==(i=null===(t=this.currentSession)||void 0===t?void 0:t.sessionId)&&void 0!==i?i:null},t.prototype.getSessionNumber=function(){return this.sessionNumber},t.prototype.resetSessionNumber=function(){return ve(this,arguments,void 0,function(t){return void 0===t&&(t=0),me(this,function(i){switch(i.label){case 0:return this.sessionNumber=t,[4,this.persistSessionNumber()];case 1:return i.sent(),this.logger.info("Session number reset",{sessionNumber:this.sessionNumber}),[2]}})})},t.prototype.endSession=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return this.currentSession?(this.logger.info("user_switch"===t?Sr:Cr,{sessionId:this.currentSession.sessionId,reason:t}),this.currentSession=null,[4,this.clearSessionStorage()]):[3,3];case 1:return i.sent(),[4,this.resetSessionNumber(0)];case 2:i.sent(),i.label=3;case 3:return[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){return this.logger.info("Destroying SessionManager (session persists in storage)"),this.currentSession=null,[2]})})},t.prototype.startNewSession=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return t=Date.now(),i=ia(),this.currentSession={sessionId:i,sessionStartTime:t,lastEventTime:t},this.sessionNumber+=1,[4,this.persistSession()];case 1:return n.sent(),[4,this.persistSessionNumber()];case 2:return n.sent(),this.logger.info(Ir,{sessionId:i,sessionStartTime:t,sessionNumber:this.sessionNumber}),[2,i]}})})},t.prototype.restoreSession=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a;return me(this,function(c){switch(c.label){case 0:return c.trys.push([0,7,,9]),t=ke("SESSION_ID",this.brandId,this.applicationId),i=ke("SESSION_START_TIME",this.brandId,this.applicationId),n=ke("LAST_EVENT_TIME",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return e=c.sent(),[4,this.storageManager.get(i)];case 2:return r=c.sent(),[4,this.storageManager.get(n)];case 3:return s=c.sent(),e&&r&&s?(o=Date.now(),(u=o-parseInt(s))<this.inactivityTimeoutMs?(this.currentSession={sessionId:e,sessionStartTime:parseInt(r),lastEventTime:parseInt(s)},this.logger.info(Nr,{sessionId:e,timeSinceLastEvent:u}),[3,6]):[3,4]):[3,6];case 4:return this.logger.debug("Stored session expired, will create new session",{timeSinceLastEvent:u,timeoutMs:this.inactivityTimeoutMs}),[4,this.clearSessionStorage()];case 5:c.sent(),c.label=6;case 6:return[3,9];case 7:return a=c.sent(),this.logger.error("Failed to restore session from storage",{error:a}),[4,this.clearSessionStorage()];case 8:return c.sent(),[3,9];case 9:return[2]}})})},t.prototype.persistSession=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:if(!this.currentSession)return[2];r.label=1;case 1:return r.trys.push([1,3,,4]),t=ke("SESSION_ID",this.brandId,this.applicationId),i=ke("SESSION_START_TIME",this.brandId,this.applicationId),n=ke("LAST_EVENT_TIME",this.brandId,this.applicationId),[4,Promise.all([this.storageManager.set(t,this.currentSession.sessionId),this.storageManager.set(i,this.currentSession.sessionStartTime.toString()),this.storageManager.set(n,this.currentSession.lastEventTime.toString())])];case 2:return r.sent(),[3,4];case 3:return e=r.sent(),this.logger.error("Failed to persist session to storage",{error:e}),[3,4];case 4:return[2]}})})},t.prototype.clearSessionStorage=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),t=ke("SESSION_ID",this.brandId,this.applicationId),i=ke("SESSION_START_TIME",this.brandId,this.applicationId),n=ke("LAST_EVENT_TIME",this.brandId,this.applicationId),[4,Promise.all([this.storageManager.remove(t),this.storageManager.remove(i),this.storageManager.remove(n)])];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error("Failed to clear session storage",{error:e}),[3,3];case 3:return[2]}})})},t.prototype.restoreSessionNumber=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=ke("SESSION_NUMBER",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=e.sent())&&(this.sessionNumber=parseInt(i,10)||0,this.logger.debug("Session number restored",{sessionNumber:this.sessionNumber})),[3,3];case 2:return n=e.sent(),this.logger.error("Failed to restore session number",{error:n}),[3,3];case 3:return[2]}})})},t.prototype.persistSessionNumber=function(){return ve(this,void 0,void 0,function(){var t,i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=ke("SESSION_NUMBER",this.brandId,this.applicationId),[4,this.storageManager.set(t,this.sessionNumber.toString())];case 1:return n.sent(),[3,3];case 2:return i=n.sent(),this.logger.error("Failed to persist session number",{error:i}),[3,3];case 3:return[2]}})})},t}(),_c=function(){function t(t,i){this.firedThresholds=new Set,this.pageStartTime=0,this.currentUrl="",this.scrollHandler=null,this.initialized=!1,this.logger=t,this.onDepthReached=i,this.thresholds=Ps}return t.prototype.init=function(){var t=this;"undefined"!=typeof window&&"undefined"!=typeof document?this.initialized?this.logger.debug("ScrollDepthTracker already initialized, skipping"):(this.pageStartTime=Date.now(),this.currentUrl=window.location.href,this.scrollHandler=function(){return t.handleScroll()},window.addEventListener("scroll",this.scrollHandler,{passive:!0}),this.checkScrollDepth(),this.initialized=!0,this.logger.debug("ScrollDepthTracker initialized")):this.logger.debug("ScrollDepthTracker.init() skipped - no window/document (SSR)")},t.prototype.handleScroll=function(){this.checkSPANavigation(),this.checkScrollDepth()},t.prototype.checkSPANavigation=function(){var t=window.location.href;t!==this.currentUrl&&(this.firedThresholds.clear(),this.pageStartTime=Date.now(),this.currentUrl=t,this.logger.debug("ScrollDepthTracker reset for new page",{url:t}))},t.prototype.checkScrollDepth=function(){var t,i,n=window.scrollY,e=document.documentElement.scrollHeight-document.documentElement.clientHeight;if(!(e<=0)){var r=Math.min(100,Math.floor(n/e*100));try{for(var s=ge(this.thresholds),o=s.next();!o.done;o=s.next()){var u=o.value;if(!this.firedThresholds.has(u)&&r>=u){this.firedThresholds.add(u);var a=Math.floor((Date.now()-this.pageStartTime)/1e3);this.logger.debug("Scroll depth threshold reached",{threshold:u,timeToDepth:a,url:this.currentUrl}),this.onDepthReached({depth_percentage:u,page_url:this.currentUrl,time_to_depth:a})}}}catch(i){t={error:i}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}}},t.prototype.destroy=function(){this.scrollHandler&&"undefined"!=typeof window&&window.removeEventListener("scroll",this.scrollHandler),this.scrollHandler=null,this.firedThresholds.clear(),this.initialized=!1,this.logger.debug("ScrollDepthTracker destroyed")},t}(),Ic=function(){function t(t){this.userContextSet=!1,this.initialized=!1,this.initializationPromise=null,this.visitorTrackingEnabled=!1,this.visitorId=null,this.currentUserIdentifierType=null,this.notificationManager=null,this.permissionChangeCleanup=null,this.dlrMessageCleanup=null,this.lastAuthenticatedUser=null,this.lastUserAttributes=null,this.scrollDepthTracker=null,this.sdkDisabled=!1,this.userIdentified=!1,this.userOperationChain=Promise.resolve(),this.gamificationManager=null,this.pendingGamificationCallback=null,this.pendingGamificationSettings={},this.config=t,this.logger=new dc(!1),this.validateRequiredConfig(t),t.remoteConfigKey?(this.logger.info("🔧 SDK initializing in Remote Config bootstrap mode"),this.logger.info("Will fetch configuration from Remote Config key:",t.remoteConfigKey)):this.logger.info("🔧 SDK initializing in direct-config bootstrap mode (no Firebase)")}return t.initialize=function(i){return t.p?(new dc(!0).warn("WebSDK is already initialized. Returning existing instance."),t.p):(t.p=new t(i),t.p.init(),t.p)},t.getInstance=function(){return t.p},t.isInitialized=function(){return null!==t.p},t.requireInstance=function(){if(!t.p)throw new Error("WebSDK is not initialized. Call WebSDK.initialize(config) first.");return t.p},t.track=function(i,n){t.requireInstance().track(i,n)},t.pageView=function(i){t.requireInstance().pageView(i)},t.identify=function(i){t.requireInstance().identify(i)},t.getUser=function(){return t.requireInstance().getUser()},t.getAnonymousId=function(){return t.requireInstance().getAnonymousId()},t.reset=function(){t.requireInstance().reset()},t.setCapToken=function(i){t.requireInstance().setCapToken(i)},t.getCapToken=function(){return t.requireInstance().getCapToken()},t.enablePagePathTracking=function(i){t.requireInstance().enablePagePathTracking(i)},t.onScreenChanged=function(i){t.requireInstance().onScreenChanged(i)},t.setGamificationSuppressed=function(i){t.requireInstance().setGamificationSuppressed(i)},t.setTheme=function(i){t.requireInstance().setTheme(i)},t.forceSyncGamification=function(){t.requireInstance().forceSyncGamification()},t.setGamificationCallback=function(i){t.requireInstance().setGamificationCallback(i)},t.isGamificationSuppressed=function(){return t.requireInstance().isGamificationSuppressed()},t.disableSDK=function(){t.requireInstance().disableSDK()},t.enableSDK=function(){t.requireInstance().enableSDK()},t.destroy=function(){if(!t.p)return Promise.resolve();var i=t.p.destroy();return t.p=null,i},t.prototype.shouldEnableLogging=function(t){return!(!t||"NONE"===t)&&["ERROR","WARN","INFO","DEBUG","VERBOSE"].includes(t)},t.prototype.resolveLogLevel=function(t){return{NONE:sc.NONE,ERROR:sc.ERROR,WARN:sc.WARN,INFO:sc.INFO,DEBUG:sc.DEBUG,VERBOSE:sc.VERBOSE}[null!=t?t:"NONE"]},t.prototype.restoreUserContext=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a=this;return me(this,function(c){switch(c.label){case 0:return c.trys.push([0,5,,6]),t=ke("USER_CONTEXT",this.config.brandId,this.config.applicationId),[4,this.storageManager.get(t)];case 1:return(i=c.sent())?(n=JSON.parse(i),e=n.cuid,r=n.userIdentifierType,this.currentUserIdentifierType=null!=r?r:null,s=this.config.accountId||"",[4,this.eventTracker.setUserContext(s,e,r)]):[3,3];case 2:c.sent(),this.userContextSet=!0,this.userIdentified=!0,this.logger.setContext({cuid:e}),n.attributes&&(this.lastUserAttributes=n.attributes),this.logger.info("User context restored from storage",{cuid:e,accountId:this.config.accountId}),this.gamificationManager&&this.gamificationManager.initialize(e).catch(function(t){a.logger.error("Failed to restore gamification on page refresh",t)}),c.label=3;case 3:return[4,this.storageManager.get(this.lastAuthenticatedUserKey())];case 4:return(o=c.sent())&&(this.lastAuthenticatedUser=o,this.logger.info("Last authenticated user restored from storage",{lastAuthenticatedUser:this.lastAuthenticatedUser})),[3,6];case 5:return u=c.sent(),this.logger.error("Failed to restore user context from storage",{error:u}),[3,6];case 6:return[2]}})})},t.prototype.validateAndClearDifferentUserContext=function(t){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,5,,7]),this.lastAuthenticatedUser&&this.lastAuthenticatedUser!==t?(this.logger.info("Different user detected, ending session and clearing context",{previousCuid:this.lastAuthenticatedUser,newCuid:t}),[4,this.sessionManager.endSession("user_switch")]):[3,3];case 1:return n.sent(),[4,this.clearUserContext({resetIdentified:!1})];case 2:n.sent(),this.userContextSet=!1,n.label=3;case 3:return this.lastAuthenticatedUser=t,[4,this.persistLastAuthenticatedUser(t)];case 4:return n.sent(),[3,7];case 5:return i=n.sent(),this.logger.error("Error validating different user context",{previousCuid:this.lastAuthenticatedUser,newCuid:t,error:i}),[4,this.clearUserContext()];case 6:return n.sent(),this.userContextSet=!1,[3,7];case 7:return[2]}})})},t.prototype.lastAuthenticatedUserKey=function(){return ke("LAST_AUTHENTICATED_USER",this.config.brandId,this.config.applicationId)},t.prototype.persistLastAuthenticatedUser=function(t){return ve(this,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.storageManager.set(this.lastAuthenticatedUserKey(),t)];case 1:return n.sent(),[3,3];case 2:return i=n.sent(),this.logger.error("Failed to persist lastAuthenticatedUser",{error:i}),[3,3];case 3:return[2]}})})},t.prototype.storeUserContext=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o;return me(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),e=null!=i?i:this.currentUserIdentifierType,r={cuid:t,timestamp:Date.now()},e&&(r.userIdentifierType=e),n&&(r.attributes=n),s=ke("USER_CONTEXT",this.config.brandId,this.config.applicationId),[4,this.storageManager.set(s,JSON.stringify(r))];case 1:return u.sent(),[3,3];case 2:return o=u.sent(),this.logger.error("Failed to store user context",{error:o}),[3,3];case 3:return[2]}})})},t.prototype.init=function(){var t=this;this.initialized?this.logger.warn("WebSDK already initialized"):this.initializationPromise?this.logger.warn("WebSDK initialization already in progress"):(fa(),this.initializationPromise=this.initializeAsync().catch(function(i){t.logger.error(Ve,i),t.initializationPromise=null}))},t.prototype.tryStep=function(t,i){return ve(this,void 0,void 0,function(){var n;return me(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,i()];case 1:return e.sent(),[3,3];case 2:return n=e.sent(),this.logger.error(t,n),[3,3];case 3:return[2]}})})},t.prototype.initializeAsync=function(){return ve(this,void 0,void 0,function(){var t,i,n=this;return me(this,function(e){switch(e.label){case 0:this.logger.info("Initializing WebSDK",{version:Hs,config:this.config}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.bootstrapConfig()];case 2:return e.sent(),[3,4];case 3:throw t=e.sent(),new Error("".concat(Pe,": ").concat(t));case 4:return[4,this.tryStep(je,function(){return n.storageManager.init()})];case 5:return e.sent(),[4,this.tryStep(He,function(){var t;return Promise.resolve(null===(t=n.gamificationManager)||void 0===t?void 0:t.restorePersistedPagePathTracking())})];case 6:return e.sent(),[4,this.tryStep(qe,function(){var t;return Promise.resolve(null===(t=n.gamificationManager)||void 0===t?void 0:t.restorePersistedGamificationSuppressed())})];case 7:return e.sent(),[4,this.tryStep(Ke,function(){var t;return Promise.resolve(null===(t=n.gamificationManager)||void 0===t?void 0:t.restorePersistedTheme())})];case 8:return e.sent(),[4,this.tryStep(We,function(){return n.sessionManager.init()})];case 9:if(e.sent(),!this.config.notifications)return[3,13];e.label=10;case 10:return e.trys.push([10,12,,13]),this.notificationManager=new yc(this.config.notifications,this.logger,this.storageManager,this.config.brandId,this.config.applicationId),this.setupTokenUpdateCallback(),[4,this.notificationManager.init()];case 11:return e.sent(),this.logger.info("Notifications initialized early for FCM token availability"),[3,13];case 12:return i=e.sent(),this.logger.error("Failed to construct or configure NotificationManager",{error:i}),this.notificationManager=null,[3,13];case 13:return[4,this.tryStep(Xe,function(){return n.initializeVisitorConfig()})];case 14:return e.sent(),[4,this.tryStep(Ye,function(){return ve(n,void 0,void 0,function(){var t=this;return me(this,function(i){switch(i.label){case 0:return[4,this.eventTracker.init()];case 1:return i.sent(),this.eventTracker.setSessionInfoCallback(function(){return ve(t,void 0,void 0,function(){return me(this,function(t){return[2,this.sessionManager.getOrCreateSession()]})})}),[2]}})})})];case 15:return e.sent(),[4,this.tryStep(Je,function(){return n.restoreUserContext()})];case 16:return e.sent(),[4,this.tryStep(Qe,function(){return n.syncEventTrackerContext()})];case 17:return e.sent(),this.initialized=!0,this.notificationManager&&this.setupPermissionChangeDetection(),this.scrollDepthTracker=new _c(this.logger,function(t){n.pushEvent(Rs,n.buildInternalEventAttributes(le({},t)))}),this.scrollDepthTracker.init(),this.config.notifications?[4,this.tryStep($e,function(){return ve(n,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.setupDLRServiceWorkerListener(),[4,this.eventTracker.processPendingServiceWorkerDLREvents()];case 1:return t.sent(),[2]}})})})]:[3,19];case 18:e.sent(),e.label=19;case 19:return this.logger.info(Ge),[2]}})})},t.prototype.handleVisibilityChange=function(){return ve(this,void 0,void 0,function(){var t,i,n;return me(this,function(e){switch(e.label){case 0:if("visible"!==document.visibilityState||!this.notificationManager)return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),this.notificationManager.hasPermissionChanged()?(t="Notification"in window?Notification.permission:"denied",this.logger.info("Notification permission changed detected",{currentPermission:t}),[4,this.notificationManager.handlePermissionChange()]):[2];case 2:return(i=e.sent())&&this.logger.info("Notification state updated after permission change",i),[3,4];case 3:return n=e.sent(),this.logger.error("Error handling permission change",{error:n}),[3,4];case 4:return[2]}})})},t.prototype.setupPermissionChangeDetection=function(){var t=this;if("undefined"!=typeof document&&"undefined"!=typeof window){var i=function(){return t.handleVisibilityChange()};document.addEventListener("visibilitychange",i),window.addEventListener("focus",i),this.permissionChangeCleanup=function(){document.removeEventListener("visibilitychange",i),window.removeEventListener("focus",i)},this.logger.debug("Permission change detection setup complete")}},t.prototype.setupDLRServiceWorkerListener=function(){var t=this;if("undefined"!=typeof navigator&&"serviceWorker"in navigator){var i=function(i){return ve(t,void 0,void 0,function(){var t;return me(this,function(n){switch(n.label){case 0:if(!i.data||"HYDRA_DLR_EVENTS_PENDING"!==i.data.type)return[3,4];this.logger.info("Received DLR events pending notification from service worker",{serviceWorkerTimestamp:i.data.timestamp,dlrEventType:i.data.dlrEventType,messageId:i.data.messageId,campaignId:i.data.campaignId}),n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.eventTracker.processPendingServiceWorkerDLREvents()];case 2:return n.sent(),[3,4];case 3:return t=n.sent(),this.logger.error("Failed to process pending DLR events",t),[3,4];case 4:return[2]}})})};navigator.serviceWorker.addEventListener("message",i),this.dlrMessageCleanup=function(){navigator.serviceWorker.removeEventListener("message",i)},this.logger.debug("DLR service worker message listener setup complete")}},t.prototype.initializeVisitorConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n=this;return me(this,function(e){switch(e.label){case 0:return this.logger.info("Initializing visitor configuration"),[4,this.visitorConfigManager.init()];case 1:return e.sent(),t=this,[4,this.visitorConfigManager.isVisitorTrackingEnabled()];case 2:return t.visitorTrackingEnabled=e.sent(),this.visitorTrackingEnabled?[4,this.anonymousVisitorManager.init()]:[3,5];case 3:return e.sent(),[4,this.getOrCreateVisitorId()];case 4:e.sent(),this.anonymousVisitorManager.retryPendingMerge().catch(function(t){n.logger.error("Failed to retry pending merge on init",{error:t})}),e.label=5;case 5:return(i=this.visitorConfigManager.getCachedConfig())&&i.warnings&&i.warnings.length>0&&i.warnings.forEach(function(t){n.logger.warn("Visitor config warning",{code:t.code,message:t.message})}),[2]}})})},t.prototype.syncEventTrackerContext=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return t=null!==(e=null===(n=this.anonymousVisitorManager)||void 0===n?void 0:n.getVisitorExternalId())&&void 0!==e?e:null,this.eventTracker.setVisitorTrackingState(this.visitorId,this.visitorTrackingEnabled,t),this.visitorTrackingEnabled?(i=this.config.accountId||"",this.userContextSet?[3,2]:[4,this.eventTracker.setUserContext(i)]):(this.logger.warn("Event tracking disabled: Visitor tracking is off"),[2]);case 1:return r.sent(),this.logger.info("Account context set for visitor tracking"),[3,3];case 2:this.logger.debug("Skipping account context set - user context already set"),r.label=3;case 3:return[2]}})})},t.prototype.getOrCreateVisitorId=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h;return me(this,function(d){switch(d.label){case 0:t=[],(i=null===(a=this.notificationManager)||void 0===a?void 0:a.getFCMToken())?(n="granted"===(null===(c=this.notificationManager)||void 0===c?void 0:c.getState().permissionStatus),t.push({type:this.getChannelType(),value:i,primary:!0,verified:!0,subscribed:n}),this.logger.info("Including FCM token in visitor creation",{tokenPreview:i.substring(0,20)+"...",subscribed:n})):this.logger.info("No FCM token available, creating visitor without commChannels"),d.label=1;case 1:return d.trys.push([1,5,,6]),this.notificationManager?[4,this.notificationManager.getTokenCreationDate()]:[3,3];case 2:return s=d.sent(),[3,4];case 3:s=null,d.label=4;case 4:return r=s,e=aa(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:"granted"===(null===(h=this.notificationManager)||void 0===h?void 0:h.getState().permissionStatus),fcmTokenCreatedAt:r})),this.logger.debug("Extended fields collected",{extendedFields:e}),[3,6];case 5:return o=d.sent(),this.logger.error("Failed to collect extended fields, proceeding without them",{error:o}),e=void 0,[3,6];case 6:return u=this,[4,this.anonymousVisitorManager.getOrCreateVisitorId(t.length>0?t:void 0,e)];case 7:return u.visitorId=d.sent(),this.logger.setContext({visitorId:this.visitorId}),this.logger.info("Visitor ID ready",{visitorId:this.visitorId}),[2,this.visitorId]}})})},t.prototype.setupTokenUpdateCallback=function(){var t=this;this.notificationManager&&(this.notificationManager.setTokenUpdateCallback(function(i,n){return ve(t,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return[4,this.handleTokenUpdate(i,n)];case 1:return t.sent(),[2]}})})}),this.logger.debug("Token update callback configured for backend sync"))},t.prototype.handleTokenUpdate=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r;return me(this,function(s){switch(s.label){case 0:if(!this.visitorId)return this.logger.info("Skipping token sync - no visitor ID yet (will be included in create)",{isNewToken:i}),[2];if(!i)return this.logger.info("Skipping token sync - token unchanged"),[2];n="granted"!==(null===(r=this.notificationManager)||void 0===r?void 0:r.getState().permissionStatus),this.logTokenSyncStart(t,n),s.label=1;case 1:return s.trys.push([1,6,,7]),this.userIdentified&&this.lastAuthenticatedUser?[4,this.syncTokenForIdentifiedUser(n)]:[3,3];case 2:return s.sent(),[3,5];case 3:return[4,this.syncTokenForAnonymousUser(t,n)];case 4:s.sent(),s.label=5;case 5:return[3,7];case 6:return e=s.sent(),this.logger.error("Failed to sync FCM token with backend",e),[3,7];case 7:return[2]}})})},t.prototype.logTokenSyncStart=function(t,i){i?this.logger.info("Permission revoked, syncing push_opted:false with backend",{visitorId:this.visitorId}):this.logger.info("FCM token updated, syncing with backend",{visitorId:this.visitorId,tokenPreview:t.substring(0,20)+"..."})},t.prototype.syncTokenForIdentifiedUser=function(t){return ve(this,void 0,void 0,function(){return me(this,function(i){switch(i.label){case 0:return this.lastAuthenticatedUser?[4,this.sendUserEventToApi(As,this.lastAuthenticatedUser,this.lastUserAttributes)]:[2];case 1:return i.sent(),this.logger.info("Token state synced via User Events API (user_update)",{permissionRevoked:t}),[2]}})})},t.prototype.syncTokenForAnonymousUser=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s,o;return me(this,function(u){switch(u.label){case 0:n=t?[{type:this.getChannelType(),value:t,primary:!0,verified:!0,subscribed:!i}]:[],u.label=1;case 1:return u.trys.push([1,5,,6]),i||!this.notificationManager?[3,3]:[4,this.notificationManager.getTokenCreationDate()];case 2:return s=u.sent(),[3,4];case 3:s=null,u.label=4;case 4:return r=s,e=aa(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:!i,fcmTokenCreatedAt:r})),[3,6];case 5:return o=u.sent(),this.logger.error("Failed to collect extended fields for token update",{error:o}),e=void 0,[3,6];case 6:return[4,this.anonymousVisitorManager.updateVisitor(n,e)];case 7:return u.sent(),i?this.logger.info("Token synced with subscribed:false (permission revoked)",{visitorId:this.visitorId}):this.logger.info("FCM token synced with backend successfully",{visitorId:this.visitorId}),[2]}})})},t.prototype.getAnonymousId=function(){return this.visitorId},t.prototype.getUser=function(){var t,i,n,e,r;if(this.userIdentified)throw this.logger.error("getUser() called while a user is identified - data not exposed"),new Error("This data is not exposed");var s=null!==(i=null===(t=this.sessionManager)||void 0===t?void 0:t.getCurrentSessionId())&&void 0!==i?i:"",o=null!==(e=null===(n=this.sessionManager)||void 0===n?void 0:n.getSessionNumber())&&void 0!==e?e:0;return{visitorId:null!==(r=this.visitorId)&&void 0!==r?r:"",userId:null,sessionId:s,isIdentified:!1,isAnonymous:!0,profileTier:"anonymous",attributes:null,sessionNumber:o,isFirstSession:1===o,isReturningVisitor:o>1}},t.prototype.setUserContext=function(t,i){return ve(this,void 0,void 0,function(){var n,e,r,s;return me(this,function(o){switch(o.label){case 0:if(!this.initialized)throw this.logger.error("setUserContext() called before WebSDK is initialized"),new Error("WebSDK must be initialized before setting user context");o.label=1;case 1:return o.trys.push([1,5,,6]),[4,this.validateAndClearDifferentUserContext(t)];case 2:return o.sent(),this.logger.setContext({cuid:t}),n=null!==(s=null!=i?i:this.currentUserIdentifierType)&&void 0!==s?s:void 0,e=this.config.accountId||"",[4,this.eventTracker.setUserContext(e,t,n)];case 3:return o.sent(),this.userContextSet=!0,i&&(this.currentUserIdentifierType=i),this.visitorId&&this.logger.info("User identified - transitioning from anonymous to identified tracking",{visitorId:this.visitorId,cuid:t,trackingMode:"identified"}),[4,this.storeUserContext(t,n)];case 4:return o.sent(),this.logger.info("User context set and persisted",{cuid:t,accountId:this.config.accountId}),[3,6];case 5:throw r=o.sent(),this.logger.error("Failed to set user context",{cuid:t,error:r}),r;case 6:return[2]}})})},t.prototype.clearUserContext=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r;return me(this,function(s){switch(s.label){case 0:i=null===(r=null==t?void 0:t.resetIdentified)||void 0===r||r,s.label=1;case 1:return s.trys.push([1,5,,6]),n=ke("USER_CONTEXT",this.config.brandId,this.config.applicationId),[4,this.storageManager.remove(n)];case 2:return s.sent(),i?[4,this.storageManager.remove(this.lastAuthenticatedUserKey())]:[3,4];case 3:s.sent(),s.label=4;case 4:return this.eventTracker&&this.eventTracker.clearUserContext(),this.currentUserIdentifierType=null,this.userContextSet=!1,i&&(this.userIdentified=!1,this.lastAuthenticatedUser=null),this.logger.setContext({cuid:""}),this.logger.info("User context cleared"),[3,6];case 5:return e=s.sent(),this.logger.error("Failed to clear user context",{error:e}),this.currentUserIdentifierType=null,this.userContextSet=!1,i&&(this.userIdentified=!1,this.lastAuthenticatedUser=null),this.logger.setContext({cuid:""}),[3,6];case 6:return[2]}})})},t.prototype.track=function(t,i){var n;this.pushEvent(t,i),null===(n=this.gamificationManager)||void 0===n||n.handleActionEvent(t)},t.prototype.pageView=function(t){var i,n,e,r=null!==(i=null==t?void 0:t.page_url)&&void 0!==i?i:"undefined"!=typeof window?window.location.href:void 0,s=null!==(n=null==t?void 0:t.page_title)&&void 0!==n?n:"undefined"!=typeof document?document.title:void 0,o=null!==(e=null==t?void 0:t.referrer)&&void 0!==e?e:"undefined"!=typeof document?document.referrer:void 0,u=le(le(le(le(le({},r&&{page_url:r}),s&&{page_title:s}),o&&{referrer:o}),(null==t?void 0:t.page_category)&&{page_category:t.page_category}),null==t?void 0:t.properties);this.pushEvent("page_view",u)},t.prototype.pickTraitFields=function(t){var i={},n=t.gender,e=t.birthday,r=t.city,s=t.country,o=t.timezone;return n&&(i.gender=n),e&&(i.birthday=e),r&&(i.city=r),s&&(i.country=s),o&&(i.timezone=o),i},t.prototype.identify=function(t){var i,n,e,r,s,o,u,a=t.identifier,c=t.actionType,h=t.traits,d=void 0===h?{}:h;if(!a||!a.cuid)throw this.logger.error("Invalid identify call: missing identifier or cuid",{identifier:a}),new Error("identifier with a non-empty cuid is required for identify");var f=["email","mobile","externalId"],l=null===(s=null===(r=null===(e=null===(n=this.visitorConfigManager)||void 0===n?void 0:n.getCachedConfig())||void 0===e?void 0:e.data)||void 0===r?void 0:r.configs)||void 0===s?void 0:s.loginIdentifierType,v=l&&f.includes(l)?l:a.type;if(!f.includes(v))throw this.logger.error("Invalid identify call: unsupported identifier type",{type:v,cuid:a.cuid}),new Error("Invalid identifier type: ".concat(v,". Must be 'email', 'mobile', or 'externalId'."));var m=a.cuid;this.currentUserIdentifierType=v;var g=le(le(le(le(le({firstName:null!==(o=d.firstName)&&void 0!==o?o:"",lastName:null!==(u=d.lastName)&&void 0!==u?u:""},d.email&&{email:d.email}),d.mobile&&{mobile:d.mobile}),d.externalId&&{externalId:d.externalId}),((i={})[v]=m,i)),void 0!==d.custom&&{customData:d.custom}),p=this.pickTraitFields(d);g.customData=le(le({},p),g.customData),this.userIdentified=!0;var w=v;switch(c){case"USER_REGISTER":this.pushUserSignin(m,g,w);break;case"USER_UPDATE":this.pushUserUpdate(m,g,w);break;default:throw this.logger.error("Invalid identify actionType",{actionType:c,cuid:m}),new Error("Invalid identify actionType: ".concat(c,". Must be 'USER_REGISTER' or 'USER_UPDATE'."))}},t.prototype.trackEvent=function(t){return ve(this,arguments,void 0,function(t,i){return void 0===i&&(i=!1),me(this,function(n){switch(n.label){case 0:if(!this.initialized)throw new Error("WebSDK must be initialized before tracking events");return[4,this.eventTracker.track(t,i)];case 1:return n.sent(),[2]}})})},t.prototype.destroy=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:this.logger.info("Destroying WebSDK instance"),i.label=1;case 1:return i.trys.push([1,16,,17]),this.eventTracker?[4,this.eventTracker.flush()]:[3,4];case 2:return i.sent(),[4,this.eventTracker.destroy()];case 3:i.sent(),i.label=4;case 4:return this.scrollDepthTracker&&(this.scrollDepthTracker.destroy(),this.scrollDepthTracker=null),this.visitorConfigManager?[4,this.visitorConfigManager.destroy()]:[3,6];case 5:i.sent(),i.label=6;case 6:return this.anonymousVisitorManager?[4,this.anonymousVisitorManager.destroy()]:[3,8];case 7:i.sent(),i.label=8;case 8:return this.permissionChangeCleanup&&(this.permissionChangeCleanup(),this.permissionChangeCleanup=null),this.dlrMessageCleanup&&(this.dlrMessageCleanup(),this.dlrMessageCleanup=null),this.notificationManager?(this.notificationManager.clearTokenUpdateCallback(),[4,this.notificationManager.destroy()]):[3,10];case 9:i.sent(),this.notificationManager=null,i.label=10;case 10:return this.gamificationManager&&(this.gamificationManager.destroy(),this.gamificationManager=null),this.sessionManager?[4,this.sessionManager.destroy()]:[3,12];case 11:i.sent(),i.label=12;case 12:return this.storageManager?[4,this.clearUserContext()]:[3,15];case 13:return i.sent(),[4,this.storageManager.destroy()];case 14:i.sent(),i.label=15;case 15:return this.initialized=!1,this.logger.info(Be),[3,17];case 16:throw t=i.sent(),this.logger.error(ze,{error:t}),t;case 17:return[2]}})})},t.prototype.validateUserAttributes=function(t){if(!t.email&&!t.mobile&&!t.externalId)throw new Error("At least one of email, mobile, or externalId is required")},t.prototype.attemptVisitorMerge=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s;return me(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),this.visitorTrackingEnabled&&this.visitorId?t.email||t.mobile||t.externalId?(e="email"===n||"mobile"===n||"externalId"===n?n:void 0,[4,this.anonymousVisitorManager.mergeVisitorWithUser(le(le(le(le(le(le({firstName:t.firstName,lastName:t.lastName},void 0!==t.email&&{email:t.email}),void 0!==t.mobile&&{mobile:t.mobile}),void 0!==t.externalId&&{externalId:t.externalId}),void 0!==t.customData&&{customData:t.customData}),{cuid:i}),void 0!==e&&{identifierType:e}))]):(this.logger.debug(Xr,{reason:"No email, mobile, or externalId"}),[2,!1]):(this.logger.debug(Xr,{reason:this.visitorTrackingEnabled?"No visitorId":"Visitor tracking disabled"}),[2,!1]);case 1:return r=o.sent(),this.logger.info("Visitor merge attempt completed",{visitorId:this.visitorId,success:r}),[2,r];case 2:return s=o.sent(),this.logger.error(Wr,{visitorId:this.visitorId,error:s}),[2,!1];case 3:return[2]}})})},t.prototype.buildPushData=function(){var t,i,n,e="granted"===(null===(t=this.notificationManager)||void 0===t?void 0:t.getState().permissionStatus),r=null!==(n=null===(i=this.notificationManager)||void 0===i?void 0:i.getFCMToken())&&void 0!==n?n:null;return{pushOpted:e&&!!r,tokens:r?[{interface_id:r,gateway:Fs.WEB}]:[]}},t.prototype.buildUserAttributePayload=function(t){if(!t)return{};var i={};return t.firstName&&(i.firstName=t.firstName),t.lastName&&(i.lastName=t.lastName),t.email&&(i.email=t.email),t.mobile&&(i.phone=t.mobile),i},t.prototype.sendUserEventToApi=function(t,i,n,e){return ve(this,void 0,void 0,function(){var r,s,o,u,a,c,h,d,f,l,v,m;return me(this,function(g){switch(g.label){case 0:return r=this.buildPushData(),s=r.pushOpted,o=r.tokens,u=null!==(d=null===(h=this.sessionManager)||void 0===h?void 0:h.getCurrentSessionId())&&void 0!==d?d:"",[4,this.apiClient.buildUserEventsRequest(t,le(le(le({cuid:i,push_opted:s,tokens:o},this.visitorId&&{visitorId:this.visitorId}),this.buildUserAttributePayload(n)),e),u)];case 1:return a=g.sent(),c=null!==(l=null===(f=this.anonymousVisitorManager)||void 0===f?void 0:f.getVisitorExternalId())&&void 0!==l?l:void 0,[4,this.apiClient.sendUserEvents(a,null!==(v=this.visitorId)&&void 0!==v?v:void 0,c,i,null!==(m=this.currentUserIdentifierType)&&void 0!==m?m:void 0)];case 2:return g.sent(),this.logger.info("User event sent to User Events API",{eventName:t,cuid:i}),[2]}})})},t.prototype.pushUserSignin=function(t,i,n){var e=this;this.userIdentified=!0,this.queueUserOperation(function(){return ve(e,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.pushUserSigninAsync(t,i,n)];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error(Dr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSigninAsync=function(t,i,n){return ve(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f=this;return me(this,function(l){switch(l.label){case 0:return[4,this.ensureInitialized()];case 1:return l.sent(),this.validateUserAttributes(i),e=(null!==(h=null===(c=this.sessionManager)||void 0===c?void 0:c.getSessionNumber())&&void 0!==h?h:0)>1,r=e?"returning":"new_session",[4,this.setUserContextIfNeeded(t,n)];case 2:return l.sent(),[4,this.attemptVisitorMerge(i,t,n)];case 3:return s=l.sent(),this.lastUserAttributes=i,[4,this.storeUserContext(t,n,i)];case 4:l.sent(),l.label=5;case 5:return l.trys.push([5,7,,8]),[4,this.sendUserEventToApi(ks,t,i,le(le({},void 0!==n&&{method:n}),{success:s,login_type:r}))];case 6:return l.sent(),this.logger.info("User signin event tracked",{cuid:t,firstName:i.firstName,lastName:i.lastName,email:i.email,loginType:r,mergeSuccess:s}),[3,8];case 7:return o=l.sent(),this.logger.error("Failed to send signin event to User Events API",{cuid:t,error:o}),[3,8];case 8:return u=le(le(le({},i.email&&{email:i.email}),i.mobile&&{mobile:i.mobile}),i.customData&&{customAttributes:i.customData}),(a=[i.firstName,i.lastName].filter(Boolean).join(" "))&&Object.assign(u,{name:a}),null===(d=this.gamificationManager)||void 0===d||d.initialize(t,u).catch(function(i){f.logger.error("Failed to initialize gamification on signin",{cuid:t,error:i})}),[2]}})})},t.prototype.pushUserSignup=function(t,i,n){var e=this;this.userIdentified=!0,this.queueUserOperation(function(){return ve(e,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.pushUserSignupAsync(t,i,n)];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error(Or,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSignupAsync=function(t,i,n){return ve(this,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:return[4,this.ensureInitialized()];case 1:return e.sent(),this.validateUserAttributes(i),[4,this.setUserContextIfNeeded(t,n)];case 2:return e.sent(),this.attemptVisitorMerge(i,t,n),this.lastUserAttributes=i,[4,this.storeUserContext(t,n,i)];case 3:return e.sent(),[4,this.sendUserEventToApi(ks,t,i)];case 4:return e.sent(),this.logger.info("User signup event tracked (routed as user_signin)",{cuid:t,firstName:i.firstName,lastName:i.lastName,email:i.email}),[2]}})})},t.prototype.pushUserUpdate=function(t,i,n){var e=this;this.queueUserOperation(function(){return ve(e,void 0,void 0,function(){var e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.pushUserUpdateAsync(t,i,n)];case 1:return r.sent(),[3,3];case 2:return e=r.sent(),this.logger.error(kr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserUpdateAsync=function(t,i,n){return ve(this,void 0,void 0,function(){return me(this,function(e){switch(e.label){case 0:return[4,this.ensureInitialized()];case 1:return e.sent(),this.validateUserAttributes(i),[4,this.setUserContextIfNeeded(t,n)];case 2:return e.sent(),this.lastUserAttributes=i,[4,this.storeUserContext(t,n,i)];case 3:return e.sent(),[4,this.sendUserEventToApi(As,t,i)];case 4:return e.sent(),this.logger.info("User update event tracked",{cuid:t}),[2]}})})},t.prototype.reset=function(){var t=this.lastAuthenticatedUser;t?this.pushUserSignOut(t):this.logger.warn("reset() called but no authenticated user to sign out")},t.prototype.setCapToken=function(t){var i;this.pendingGamificationSettings.capToken=t,null===(i=this.gamificationManager)||void 0===i||i.setCapToken(t)},t.prototype.getCapToken=function(){var t,i;return null!==(i=null===(t=this.gamificationManager)||void 0===t?void 0:t.getCapToken())&&void 0!==i?i:null},t.prototype.enablePagePathTracking=function(t){var i;this.pendingGamificationSettings.pagePathTrackingEnabled=t,null===(i=this.gamificationManager)||void 0===i||i.enablePagePathTracking(t)},t.prototype.onScreenChanged=function(t){var i;this.pendingGamificationSettings.screenName=t,null===(i=this.gamificationManager)||void 0===i||i.onScreenChanged(t)},t.prototype.setGamificationSuppressed=function(t){var i;this.pendingGamificationSettings.suppressed=t,null===(i=this.gamificationManager)||void 0===i||i.setGamificationSuppressed(t)},t.prototype.isGamificationSuppressed=function(){var t,i;return null!==(i=null===(t=this.gamificationManager)||void 0===t?void 0:t.isGamificationSuppressed())&&void 0!==i&&i},t.prototype.setTheme=function(t){var i;this.pendingGamificationSettings.theme=t,null===(i=this.gamificationManager)||void 0===i||i.setTheme(t)},t.prototype.forceSyncGamification=function(){var t,i=this;null===(t=this.gamificationManager)||void 0===t||t.forceSync().catch(function(t){i.logger.error("forceSyncGamification() failed",{error:t})})},t.prototype.setGamificationCallback=function(t){var i;this.pendingGamificationCallback=t,null===(i=this.gamificationManager)||void 0===i||i.setGamificationCallback(t)},t.prototype.pushUserSignOut=function(t){var i=this;this.queueUserOperation(function(){return ve(i,void 0,void 0,function(){var i;return me(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.pushUserSignOutAsync(t)];case 1:return n.sent(),[3,3];case 2:return i=n.sent(),this.logger.error(Ar,{cuid:t,error:i}),[3,3];case 3:return[2]}})})})},t.prototype.resetToAnonymousMode=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d,f,l;return me(this,function(v){switch(v.label){case 0:return null===(h=this.gamificationManager)||void 0===h||h.clean(),[4,this.sessionManager.endSession("signout")];case 1:if(v.sent(),!this.visitorTrackingEnabled)return this.logger.info("Visitor tracking disabled per latest config, skipping anonymous mode"),this.visitorId=null,this.logger.setContext({visitorId:""}),this.eventTracker.setVisitorTrackingState(null,!1),[2];v.label=2;case 2:return v.trys.push([2,11,,12]),[4,this.anonymousVisitorManager.clearVisitorId()];case 3:v.sent(),this.logger.info("Visitor ID cleared on user signout"),t=[],(i=null===(d=this.notificationManager)||void 0===d?void 0:d.getFCMToken())&&(n="granted"===(null===(f=this.notificationManager)||void 0===f?void 0:f.getState().permissionStatus),t.push({type:this.getChannelType(),value:i,primary:!0,verified:!0,subscribed:n})),e=void 0,v.label=4;case 4:return v.trys.push([4,8,,9]),this.notificationManager?[4,this.notificationManager.getTokenCreationDate()]:[3,6];case 5:return s=v.sent(),[3,7];case 6:s=null,v.label=7;case 7:return r=s,e=aa(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:"granted"===(null===(l=this.notificationManager)||void 0===l?void 0:l.getState().permissionStatus),fcmTokenCreatedAt:r})),[3,9];case 8:return o=v.sent(),this.logger.error("Failed to collect extended fields on signout, proceeding without them",{error:o}),e=void 0,[3,9];case 9:return u=this,[4,this.anonymousVisitorManager.getOrCreateVisitorId(t.length>0?t:void 0,e)];case 10:return u.visitorId=v.sent(),this.logger.setContext({visitorId:this.visitorId}),this.logger.info("New anonymous visitor ID generated after signout",{visitorId:this.visitorId,hasFCMToken:!!i}),a=this.anonymousVisitorManager.getVisitorExternalId(),this.eventTracker.setVisitorTrackingState(this.visitorId,!0,a),[3,12];case 11:return c=v.sent(),this.logger.error("Failed to regenerate visitor ID on signout",{error:c}),this.visitorId=null,this.logger.setContext({visitorId:""}),this.eventTracker.setVisitorTrackingState(null,!0),[3,12];case 12:return[2]}})})},t.prototype.pushUserSignOutAsync=function(t){return ve(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return me(this,function(h){switch(h.label){case 0:return[4,this.ensureInitialized()];case 1:return h.sent(),[4,this.setUserContextIfNeeded(t)];case 2:h.sent(),h.label=3;case 3:return h.trys.push([3,5,,6]),i=null!==(a=null===(u=this.sessionManager)||void 0===u?void 0:u.getSessionStartTime())&&void 0!==a?a:null,n=null!==i?Math.floor((Date.now()-i)/1e3):void 0,[4,this.sendUserEventToApi(xs,t,this.lastUserAttributes,le(le({},void 0!==n&&{session_duration:n}),{logout_trigger:"user_initiated"}))];case 4:return h.sent(),this.logger.info("User signout event tracked",{cuid:t}),[3,6];case 5:return e=h.sent(),this.logger.error("Failed to send signout event to User Events API",{cuid:t,error:e}),[3,6];case 6:return h.trys.push([6,15,,16]),[4,this.anonymousVisitorManager.clearMergedUserId()];case 7:return h.sent(),[4,this.anonymousVisitorManager.clearPendingMerge()];case 8:return h.sent(),[4,this.clearUserContext()];case 9:h.sent(),this.logger.info("User context cleared, returning to anonymous mode (session continues)"),h.label=10;case 10:return h.trys.push([10,12,,13]),[4,this.visitorConfigManager.refreshConfig()];case 11:return r=h.sent(),this.visitorTrackingEnabled=!0===(null===(c=r.data)||void 0===c?void 0:c.visitorTrackingEnabled),this.logger.info("Visitor config refreshed on signout",{visitorTrackingEnabled:this.visitorTrackingEnabled}),[3,13];case 12:return s=h.sent(),this.logger.error("Failed to refresh visitor config on signout, using existing value",{visitorTrackingEnabled:this.visitorTrackingEnabled,error:s}),[3,13];case 13:return[4,this.resetToAnonymousMode()];case 14:return h.sent(),this.logger.info("SDK remains active for anonymous tracking"),[3,16];case 15:throw o=h.sent(),this.logger.error("Failed to clear user context on signout",{error:o}),o;case 16:return[2]}})})},t.prototype.buildInternalEventAttributes=function(t){return le(le(le({},this.userIdentified&&this.lastAuthenticatedUser&&{cuid:this.lastAuthenticatedUser}),this.visitorId&&{visitorId:this.visitorId}),t)},t.prototype.pushEvent=function(t,i){var n=this;this.pushEventAsync(t,i).catch(function(i){n.logger.error(xr,{eventName:t,error:i})})},t.prototype.pushGamificationEvent=function(t,i){var n=this,e=le(le({},this.userIdentified&&this.lastAuthenticatedUser&&{cuid:this.lastAuthenticatedUser}),i);this.pushEventAsync(t,e,!0).catch(function(i){n.logger.error(xr,{eventName:t,error:i})})},t.prototype.pushEventAsync=function(t,i){return ve(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=!1),me(this,function(s){switch(s.label){case 0:return[4,this.ensureInitialized()];case 1:return s.sent(),this.visitorTrackingEnabled||n?this.sdkDisabled&&!n?(this.logger.debug("SDK disabled, dropping event",{eventName:t}),[2]):this.userContextSet||this.visitorId?(e=le({},null!=i?i:{}),r={type:"behavioral",name:t,timestamp:Date.now(),data:e},[4,this.trackEvent(r,n)]):(this.logger.warn("Event tracking skipped: No visitor ID available and no user context set",{eventName:t}),[2]):(this.logger.warn("Event tracking skipped: Visitor tracking is disabled",{eventName:t}),[2]);case 2:return s.sent(),this.logger.info("Behavioral event tracked",{eventName:t,attributes:i}),[2]}})})},t.prototype.disableSDK=function(){this.sdkDisabled?this.logger.warn("SDK is already disabled"):(this.sdkDisabled=!0,this.logger.info("SDK disabled — event tracking stopped"))},t.prototype.enableSDK=function(){this.sdkDisabled?(this.sdkDisabled=!1,this.logger.info("SDK enabled — event tracking resumed")):this.logger.warn("SDK is already enabled")},t.prototype.getChannelType=function(){return this.config.channelType||Fs.WEB},t.prototype.applyConfigDefaults=function(){this.config.source=this.config.source||Ls.WEBPUSH,this.config.channelType=this.config.channelType||Fs.WEB;var t=Ce/6e4;this.config.sessionTimeoutMinutes=this.config.sessionTimeoutMinutes||t,this.config.batchSize=this.config.batchSize||Ne.BATCH_SIZE,this.config.debugLevel=this.config.debugLevel||"NONE",this.logger.setEnabled(this.shouldEnableLogging(this.config.debugLevel)),this.logger.setLevel(this.resolveLogLevel(this.config.debugLevel))},t.prototype.applyRemoteConfigValues=function(t){this.config.accountId=t.accountId,this.config.baseURL=t.baseURL,this.config.orgId=t.orgId,this.config.source=t.source,this.config.channelType=t.channelType,this.config.brandId=this.config.brandId||t.brandId,this.config.applicationId=this.config.applicationId||t.applicationId,this.config.sessionTimeoutMinutes=t.sessionTimeoutMinutes,this.config.batchSize=t.batchSize,this.config.debugLevel=t.debugLevel,this.config.gamificationWriteKey=t.gamificationWriteKey||void 0,this.config.gamificationBaseUrl=t.gamificationBaseUrl||void 0,this.applyConfigDefaults(),this.logger.info("Session timeout configured:",{timeoutMinutes:this.config.sessionTimeoutMinutes,source:t.sessionTimeoutMinutes?"Remote Config":"Default"}),this.logger.info("Batch size configured:",{batchSize:this.config.batchSize,source:t.batchSize?"Remote Config":"Default"}),this.logger.info("Debug level configured:",{debugLevel:this.config.debugLevel,source:t.debugLevel?"Remote Config":"Default"})},t.prototype.applyDirectConfigValues=function(){this.applyConfigDefaults(),this.logger.info("✅ SDK configuration applied directly (no Remote Config)"),this.logger.debug("Final SDK config:",this.config)},t.prototype.bootstrapConfig=function(){return ve(this,void 0,void 0,function(){return me(this,function(t){switch(t.label){case 0:return this.config.remoteConfigKey?[4,this.fetchAndApplyRemoteConfig()]:[3,2];case 1:return t.sent(),[3,3];case 2:this.applyDirectConfigValues(),this.initializeManagersFromConfig(),t.label=3;case 3:return[2]}})})},t.prototype.getExtendedFieldsForMerge=function(){return ve(this,void 0,void 0,function(){var t,i,n,e;return me(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),this.notificationManager?[4,this.notificationManager.getTokenCreationDate()]:[3,2];case 1:return i=r.sent(),[3,3];case 2:i=null,r.label=3;case 3:return t=i,[2,aa(le(le({},this.config.appVersion?{appVersion:this.config.appVersion}:{}),{notificationPermissionGranted:"granted"===(null===(e=this.notificationManager)||void 0===e?void 0:e.getState().permissionStatus),fcmTokenCreatedAt:t}))];case 4:return n=r.sent(),this.logger.error("Failed to collect extended fields for merge, proceeding without them",{error:n}),[2,void 0];case 5:return[2]}})})},t.prototype.initializeManagersFromConfig=function(){var t=this;this.storageManager=new cc(this.logger,this.config.brandId,this.config.applicationId),this.sessionManager=new Ec(this.storageManager,this.logger,this.config.brandId,this.config.applicationId,this.config.sessionTimeoutMinutes),this.apiClient=new ec({baseUrl:this.config.baseURL||""},this.logger,this.config.accountId||"",this.config.orgId||"",this.config.source||Ls.WEBPUSH);var i=this.apiClient;this.eventTracker=new ac(this.config,i,this.storageManager,this.logger);var n=this.config.orgId||"",e=this.config.accountId||"";this.logger.setContext({orgId:n,accountId:e}),this.visitorConfigManager=new fc(n,i,this.logger,this.storageManager,this.config.brandId,this.config.applicationId),this.anonymousVisitorManager=new lc(e,n,i,this.logger,this.storageManager,le(le({},void 0!==this.config.brandId?{brandId:this.config.brandId}:{}),void 0!==this.config.applicationId?{applicationId:this.config.applicationId}:{})),this.anonymousVisitorManager.setMergeDataProviders(function(){var i;return(null===(i=t.notificationManager)||void 0===i?void 0:i.getFCMToken())||null},function(){return t.getChannelType()},function(){return t.getExtendedFieldsForMerge()},function(){var i;return"granted"===(null===(i=t.notificationManager)||void 0===i?void 0:i.getState().permissionStatus)},function(){var i,n;return null!==(n=null===(i=t.sessionManager)||void 0===i?void 0:i.getCurrentSessionId())&&void 0!==n?n:""}),this.initializeGamificationManager()},t.prototype.initializeGamificationManager=function(){var t=this,i=this.config,n=i.gamificationWriteKey,e=i.gamificationBaseUrl;n&&e?(this.gamificationManager=new nc(n,e,this.logger,this.storageManager,function(i,n){return t.pushGamificationEvent(i,n)},function(){var i,n;return null!==(n=null===(i=t.sessionManager)||void 0===i?void 0:i.getCurrentSessionId())&&void 0!==n?n:null}),this.pendingGamificationCallback&&this.gamificationManager.setGamificationCallback(this.pendingGamificationCallback),this.applyPendingGamificationSettings()):this.logger.info(Ys)},t.prototype.applyPendingGamificationSettings=function(){var t,i,n,e,r,s=this.pendingGamificationSettings;void 0!==s.capToken&&(null===(t=this.gamificationManager)||void 0===t||t.setCapToken(s.capToken)),void 0!==s.pagePathTrackingEnabled&&(null===(i=this.gamificationManager)||void 0===i||i.enablePagePathTracking(s.pagePathTrackingEnabled)),void 0!==s.screenName&&(null===(n=this.gamificationManager)||void 0===n||n.onScreenChanged(s.screenName)),void 0!==s.suppressed&&(null===(e=this.gamificationManager)||void 0===e||e.setGamificationSuppressed(s.suppressed)),void 0!==s.theme&&(null===(r=this.gamificationManager)||void 0===r||r.setTheme(s.theme))},t.prototype.fetchAndApplyRemoteConfig=function(){return ve(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return me(this,function(f){switch(f.label){case 0:this.logger.info("📡 Fetching configuration from Firebase Remote Config..."),f.label=1;case 1:return f.trys.push([1,5,,6]),[4,mc()];case 2:return t=f.sent(),[4,pc()];case 3:return i=f.sent(),n=t.initializeApp||t,e=i.getRemoteConfig||i,r=i.fetchAndActivate,s=i.getValue,o=n(this.config.firebaseConfig),(u=e(o)).settings.minimumFetchIntervalMillis=36e5,this.logger.info("🔄 Fetching Remote Config from Firebase..."),[4,r(u)];case 4:if(f.sent()||this.logger.error("⚠️ Remote Config fetched but not activated (using cached values)"),a=s(u,this.config.remoteConfigKey),!(c=a.asString()))throw new Error('Remote Config key "'.concat(this.config.remoteConfigKey,'" is empty or not found'));h=void 0;try{h=JSON.parse(c)}catch(t){throw new Error("Failed to parse Remote Config JSON: ".concat(t))}return this.logger.info("✅ Remote Config fetched successfully:",h),this.applyRemoteConfigValues(h),this.initializeManagersFromConfig(),this.logger.info("✅ SDK configuration applied from Remote Config"),this.logger.debug("Final SDK config:",this.config),[3,6];case 5:throw d=f.sent(),this.logger.error("❌ Failed to fetch Remote Config:",{remoteConfigKey:this.config.remoteConfigKey,error:d}),new Error("Remote Config bootstrap failed: ".concat(d));case 6:return[2]}})})},t.prototype.validateRequiredConfig=function(t){var i=[];if(t.remoteConfigKey?t.firebaseConfig||i.push("firebaseConfig"):(t.accountId||i.push("accountId"),t.baseURL||i.push("baseURL"),t.orgId||i.push("orgId")),i.length>0)throw this.logger.error("WebSDK initialization failed: missing required configuration fields",{missingFields:i}),new Error("WebSDK initialization failed: Missing required configuration fields: ".concat(i.join(", "),". ")+'Provide either "remoteConfigKey" + "firebaseConfig" (Remote Config bootstrap) or "accountId" + "baseURL" + "orgId" directly (direct-config bootstrap).')},t.prototype.ensureInitialized=function(){return ve(this,void 0,void 0,function(){var t;return me(this,function(i){switch(i.label){case 0:if(!this.initializationPromise)return[3,4];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.initializationPromise];case 2:return i.sent(),[3,4];case 3:throw t=i.sent(),new Error("SDK initialization failed: ".concat(t));case 4:if(!this.initialized)throw new Error("WebSDK must be initialized before tracking events. Call init() first.");return[2]}})})},t.prototype.setUserContextIfNeeded=function(t,i){return ve(this,void 0,void 0,function(){return me(this,function(n){switch(n.label){case 0:return this.userContextSet&&this.lastAuthenticatedUser===t?[3,2]:[4,this.setUserContext(t,i)];case 1:n.sent(),this.logger.debug("User context set automatically",{cuid:t}),n.label=2;case 2:return[2]}})})},t.prototype.queueUserOperation=function(t){var i=this;this.userOperationChain=this.userOperationChain.then(t).catch(function(t){i.logger.error("User operation failed",t)})},t.p=null,t}();t.HydraSDK=Ic,t.default=Ic,Object.defineProperty(t,"_",{value:!0})});
|