cap-hydra-web-sdk 1.10.6 → 1.10.7

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/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"t",{value:!0});var t="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},i="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,e="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),r="FormData"in t,s="ArrayBuffer"in t;if(s)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&o.indexOf(Object.prototype.toString.call(t))>-1};function a(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 c(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var i={next:function(){var i=t.shift();return{done:void 0===i,value:i}}};return n&&(i[Symbol.iterator]=function(){return i}),i}function d(t){this.map={},t instanceof d?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 f(t){if(!t.i)return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function l(t){return new Promise(function(i,n){t.onload=function(){i(t.result)},t.onerror=function(){n(t.error)}})}function v(t){var i=new FileReader,n=l(i);return i.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}function g(){return this.bodyUsed=!1,this.o=function(t){var n;this.bodyUsed=this.bodyUsed,this.u=t,t?"string"==typeof t?this.h=t:e&&Blob.prototype.isPrototypeOf(t)?this.l=t:r&&FormData.prototype.isPrototypeOf(t)?this.v=t:i&&URLSearchParams.prototype.isPrototypeOf(t)?this.h=t.toString():s&&e&&((n=t)&&DataView.prototype.isPrototypeOf(n))?(this.m=m(t.buffer),this.u=new Blob([this.m])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this.m=m(t):this.h=t=Object.prototype.toString.call(t):(this.i=!0,this.h=""),this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this.l&&this.l.type?this.headers.set("content-type",this.l.type):i&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e&&(this.blob=function(){var t=f(this);if(t)return t;if(this.l)return Promise.resolve(this.l);if(this.m)return Promise.resolve(new Blob([this.m]));if(this.v)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this.h]))}),this.arrayBuffer=function(){if(this.m){var t=f(this);return t||(ArrayBuffer.isView(this.m)?Promise.resolve(this.m.buffer.slice(this.m.byteOffset,this.m.byteOffset+this.m.byteLength)):Promise.resolve(this.m))}if(e)return this.blob().then(v);throw new Error("could not read as ArrayBuffer")},this.text=function(){var t,i,n,e,r,s=f(this);if(s)return s;if(this.l)return t=this.l,i=new FileReader,n=l(i),e=/charset=([A-Za-z0-9_-]+)/.exec(t.type),r=e?e[1]:"utf-8",i.readAsText(t,r),n;if(this.m)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.m));if(this.v)throw new Error("could not read FormData body as text");return Promise.resolve(this.h)},r&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,i){t=a(t),i=c(i);var n=this.map[t];this.map[t]=n?n+", "+i:i},d.prototype.delete=function(t){delete this.map[a(t)]},d.prototype.get=function(t){return t=a(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(a(t))},d.prototype.set=function(t,i){this.map[a(t)]=c(i)},d.prototype.forEach=function(t,i){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(i,this.map[n],n,this)},d.prototype.keys=function(){var t=[];return this.forEach(function(i,n){t.push(n)}),h(t)},d.prototype.values=function(){var t=[];return this.forEach(function(i){t.push(i)}),h(t)},d.prototype.entries=function(){var t=[];return this.forEach(function(i,n){t.push([n,i])}),h(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var p=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function w(i,n){if(!(this instanceof w))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(i instanceof w){if(i.bodyUsed)throw new TypeError("Already read");this.url=i.url,this.credentials=i.credentials,n.headers||(this.headers=new d(i.headers)),this.method=i.method,this.mode=i.mode,this.signal=i.signal,s||null==i.u||(s=i.u,i.bodyUsed=!0)}else this.url=String(i);if(this.credentials=n.credentials||this.credentials||"same-origin",!n.headers&&this.headers||(this.headers=new d(n.headers)),this.method=(e=n.method||this.method||"GET",r=e.toUpperCase(),p.indexOf(r)>-1?r:e),this.mode=n.mode||this.mode||null,this.signal=n.signal||this.signal||function(){if("AbortController"in t)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.o(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 y(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 E(t,i){if(!(this instanceof E))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 d(i.headers),this.url=i.url||"",this.o(t)}w.prototype.clone=function(){return new w(this,{body:this.u})},g.call(w.prototype),g.call(E.prototype),E.prototype.clone=function(){return new E(this.u,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var _=[301,302,303,307,308];E.redirect=function(t,i){if(-1===_.indexOf(i))throw new RangeError("Invalid status code");return new E(null,{status:i,headers:{location:t}})};var I=t.DOMException;try{new I}catch(t){(I=function(t,i){this.message=t,this.name=i;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),I.prototype.constructor=I}function b(i,n){return new Promise(function(r,o){var u=new w(i,n);if(u.signal&&u.signal.aborted)return o(new I("Aborted","AbortError"));var h=new XMLHttpRequest;function f(){h.abort()}if(h.onload=function(){var t,i,n={statusText:h.statusText,headers:(t=h.getAllResponseHeaders()||"",i=new d,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://")&&(h.status<200||h.status>599)?n.status=200:n.status=h.status,n.url="responseURL"in h?h.responseURL:n.headers.get("X-Request-URL");var e="response"in h?h.response:h.responseText;setTimeout(function(){r(new E(e,n))},0)},h.onerror=function(){setTimeout(function(){o(new TypeError("Network request failed"))},0)},h.ontimeout=function(){setTimeout(function(){o(new TypeError("Network request timed out"))},0)},h.onabort=function(){setTimeout(function(){o(new I("Aborted","AbortError"))},0)},h.open(u.method,function(i){try{return""===i&&t.location.href?t.location.href:i}catch(t){return i}}(u.url),!0),"include"===u.credentials?h.withCredentials=!0:"omit"===u.credentials&&(h.withCredentials=!1),"responseType"in h&&(e?h.responseType="blob":s&&(h.responseType="arraybuffer")),n&&"object"==typeof n.headers&&!(n.headers instanceof d||t.Headers&&n.headers instanceof t.Headers)){var l=[];Object.getOwnPropertyNames(n.headers).forEach(function(t){l.push(a(t)),h.setRequestHeader(t,c(n.headers[t]))}),u.headers.forEach(function(t,i){-1===l.indexOf(i)&&h.setRequestHeader(i,t)})}else u.headers.forEach(function(t,i){h.setRequestHeader(i,t)});u.signal&&(u.signal.addEventListener("abort",f),h.onreadystatechange=function(){4===h.readyState&&u.signal.removeEventListener("abort",f)}),h.send(void 0===u.u?null:u.u)})}b.polyfill=!0,t.fetch||(t.fetch=b,t.Headers=d,t.Request=w,t.Response=E);var T,S,C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},N={};function D(){if(S)return T;S=1;var t=function(t){return t&&t.Math===Math&&t};return T=t("object"==typeof globalThis&&globalThis)||t("object"==typeof window&&window)||t("object"==typeof self&&self)||t("object"==typeof C&&C)||t("object"==typeof T&&T)||function(){return this}()||Function("return this")()}var O,k,A,x,R,P,M,U,L={};function F(){return k?O:(k=1,O=function(t){try{return!!t()}catch(t){return!0}})}function G(){if(x)return A;x=1;var t=F();return A=!t(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})}function V(){if(P)return R;P=1;var t=F();return R=!t(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})}function B(){if(U)return M;U=1;var t=V(),i=Function.prototype.call;return M=t?i.bind(i):function(){return i.apply(i,arguments)},M}var z,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={};function kt(){return H?j:(H=1,j=function(t,i){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:i}})}function At(){if(K)return q;K=1;var t=V(),i=Function.prototype,n=i.call,e=t&&i.bind.bind(n,n);return q=t?e:function(t){return function(){return n.apply(t,arguments)}},q}function xt(){if(J)return Y;J=1;var t=At(),i=F(),n=function(){if(X)return W;X=1;var t=At(),i=t({}.toString),n=t("".slice);return W=function(t){return n(i(t),8,-1)}}(),e=Object,r=t("".split);return Y=i(function(){return!e("z").propertyIsEnumerable(0)})?function(t){return"String"===n(t)?r(t,""):e(t)}:e}function Rt(){return $?Q:($=1,Q=function(t){return null==t})}function Pt(){if(tt)return Z;tt=1;var t=Rt(),i=TypeError;return Z=function(n){if(t(n))throw new i("Can't call method on "+n);return n}}function Mt(){if(nt)return it;nt=1;var t=xt(),i=Pt();return it=function(n){return t(i(n))}}function Ut(){if(rt)return et;rt=1;var t="object"==typeof document&&document.all;return et=void 0===t&&void 0!==t?function(i){return"function"==typeof i||i===t}:function(t){return"function"==typeof t}}function Lt(){if(ot)return st;ot=1;var t=Ut();return st=function(i){return"object"==typeof i?null!==i:t(i)}}function Ft(){if(at)return ut;at=1;var t=D(),i=Ut();return ut=function(n,e){return arguments.length<2?(r=t[n],i(r)?r:void 0):t[n]&&t[n][e];var r},ut}function Gt(){if(vt)return lt;vt=1;var t,i,n=D(),e=function(){if(ft)return dt;ft=1;var t=D().navigator,i=t&&t.userAgent;return dt=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]),lt=i}function Vt(){if(gt)return mt;gt=1;var t=Gt(),i=F(),n=D().String;return mt=!!Object.getOwnPropertySymbols&&!i(function(){var i=Symbol("symbol detection");return!n(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&t&&t<41})}function Bt(){if(wt)return pt;wt=1;var t=Vt();return pt=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function zt(){if(Et)return yt;Et=1;var t=Ft(),i=Ut(),n=function(){if(ht)return ct;ht=1;var t=At();return ct=t({}.isPrototypeOf)}(),e=Bt(),r=Object;return yt=e?function(t){return"symbol"==typeof t}:function(e){var s=t("Symbol");return i(s)&&n(s.prototype,r(e))}}function jt(){if(It)return _t;It=1;var t=String;return _t=function(i){try{return t(i)}catch(t){return"Object"}}}function Ht(){if(Tt)return bt;Tt=1;var t=Ut(),i=jt(),n=TypeError;return bt=function(e){if(t(e))return e;throw new n(i(e)+" is not a function")}}function qt(){if(Ct)return St;Ct=1;var t=Ht(),i=Rt();return St=function(n,e){var r=n[e];return i(r)?void 0:t(r)}}function Kt(){if(Dt)return Nt;Dt=1;var t=B(),i=Ut(),n=Lt(),e=TypeError;return Nt=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 Wt,Xt,Yt,Jt,Qt,$t,Zt,ti,ii,ni,ei,ri,si,oi,ui,ai,ci,hi,di,fi,li,vi,mi,gi,pi={exports:{}};function wi(){if(Jt)return Yt;Jt=1;var t=D(),i=Object.defineProperty;return Yt=function(n,e){try{i(t,n,{value:e,configurable:!0,writable:!0})}catch(i){t[n]=e}return e}}function yi(){if(Qt)return pi.exports;Qt=1;var t=Xt?Wt:(Xt=1,Wt=!1),i=D(),n=wi(),e="__core-js_shared__",r=pi.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"}),pi.exports}function Ei(){if(Zt)return $t;Zt=1;var t=yi(),i=Object.create||Object;return $t=function(n,e){return t[n]||(t[n]=e||i(null))}}function _i(){if(ii)return ti;ii=1;var t=Pt(),i=Object;return ti=function(n){return i(t(n))}}function Ii(){if(ei)return ni;ei=1;var t=At(),i=_i(),n=t({}.hasOwnProperty);return ni=Object.hasOwn||function(t,e){return n(i(t),e)}}function bi(){if(si)return ri;si=1;var t=At(),i=0,n=Math.random(),e=t(1.1.toString);return ri=function(t){return"Symbol("+(void 0===t?"":t)+")_"+e(++i+n,36)}}function Ti(){if(ui)return oi;ui=1;var t=D(),i=Ei(),n=Ii(),e=bi(),r=Vt(),s=Bt(),o=t.Symbol,u=i("wks"),a=s?o.for||o:o&&o.withoutSetter||e;return oi=function(t){return n(u,t)||(u[t]=r&&n(o,t)?o[t]:a("Symbol."+t)),u[t]}}function Si(){if(ci)return ai;ci=1;var t=B(),i=Lt(),n=zt(),e=qt(),r=Kt(),s=Ti(),o=TypeError,u=s("toPrimitive");return ai=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 Ci(){if(di)return hi;di=1;var t=Si(),i=zt();return hi=function(n){var e=t(n,"string");return i(e)?e:e+""}}function Ni(){if(li)return fi;li=1;var t=D(),i=Lt(),n=t.document,e=i(n)&&i(n.createElement);return fi=function(t){return e?n.createElement(t):{}}}function Di(){if(mi)return vi;mi=1;var t=G(),i=F(),n=Ni();return vi=!t&&!i(function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a})}function Oi(){if(gi)return L;gi=1;var t=G(),i=B(),n=function(){if(z)return Ot;z=1;var t={}.propertyIsEnumerable,i=Object.getOwnPropertyDescriptor,n=i&&!t.call({1:2},1);return Ot.f=n?function(t){var n=i(this,t);return!!n&&n.enumerable}:t,Ot}(),e=kt(),r=Mt(),s=Ci(),o=Ii(),u=Di(),a=Object.getOwnPropertyDescriptor;return L.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])},L}var ki,Ai,xi,Ri,Pi,Mi,Ui,Li={};function Fi(){if(Ai)return ki;Ai=1;var t=G(),i=F();return ki=t&&i(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})}function Gi(){if(Ri)return xi;Ri=1;var t=Lt(),i=String,n=TypeError;return xi=function(e){if(t(e))return e;throw new n(i(e)+" is not an object")}}function Vi(){if(Pi)return Li;Pi=1;var t=G(),i=Di(),n=Fi(),e=Gi(),r=Ci(),s=TypeError,o=Object.defineProperty,u=Object.getOwnPropertyDescriptor,a="enumerable",c="configurable",h="writable";return Li.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},Li}function Bi(){if(Ui)return Mi;Ui=1;var t=G(),i=Vi(),n=kt();return Mi=t?function(t,e,r){return i.f(t,e,n(1,r))}:function(t,i,n){return t[i]=n,t}}var zi,ji,Hi,qi,Ki,Wi,Xi,Yi,Ji,Qi,$i,Zi,tn,nn,en,rn={exports:{}};function sn(){if(qi)return Hi;qi=1;var t=At(),i=Ut(),n=yi(),e=t(Function.toString);return i(n.inspectSource)||(n.inspectSource=function(t){return e(t)}),Hi=n.inspectSource}function on(){if(Yi)return Xi;Yi=1;var t=Ei(),i=bi(),n=t("keys");return Xi=function(t){return n[t]||(n[t]=i(t))}}function un(){return Qi?Ji:(Qi=1,Ji={})}function an(){if(Zi)return $i;Zi=1;var t,i,n,e=function(){if(Wi)return Ki;Wi=1;var t=D(),i=Ut(),n=t.WeakMap;return Ki=i(n)&&/native code/.test(String(n))}(),r=D(),s=Lt(),o=Bi(),u=Ii(),a=yi(),c=on(),h=un(),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 $i={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 cn(){if(tn)return rn.exports;tn=1;var t=At(),i=F(),n=Ut(),e=Ii(),r=G(),s=function(){if(ji)return zi;ji=1;var t=G(),i=Ii(),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 zi={EXISTS:r,PROPER:s,CONFIGURABLE:o}}().CONFIGURABLE,o=sn(),u=an(),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=rn.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"),rn.exports}function hn(){if(en)return nn;en=1;var t=Ut(),i=Vi(),n=cn(),e=wi();return nn=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 dn,fn,ln,vn,mn,gn,pn,wn,yn,En,_n,In,bn,Tn,Sn,Cn,Nn,Dn={};function On(){if(vn)return ln;vn=1;var t=function(){if(fn)return dn;fn=1;var t=Math.ceil,i=Math.floor;return dn=Math.trunc||function(n){var e=+n;return(e>0?i:t)(e)}}();return ln=function(i){var n=+i;return n!=n||0===n?0:t(n)}}function kn(){if(gn)return mn;gn=1;var t=On(),i=Math.max,n=Math.min;return mn=function(e,r){var s=t(e);return s<0?i(s+r,0):n(s,r)}}function An(){if(wn)return pn;wn=1;var t=On(),i=Math.min;return pn=function(n){var e=t(n);return e>0?i(e,9007199254740991):0}}function xn(){if(En)return yn;En=1;var t=An();return yn=function(i){return t(i.length)}}function Rn(){if(In)return _n;In=1;var t=Mt(),i=kn(),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 _n={includes:e(!0),indexOf:e(!1)}}function Pn(){if(Tn)return bn;Tn=1;var t=At(),i=Ii(),n=Mt(),e=Rn().indexOf,r=un(),s=t([].push);return bn=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 Mn(){return Cn?Sn:(Cn=1,Sn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}var Un,Ln,Fn,Gn,Vn,Bn,zn,jn,Hn,qn={};function Kn(){if(Fn)return Ln;Fn=1;var t=Ft(),i=At(),n=function(){if(Nn)return Dn;Nn=1;var t=Pn(),i=Mn().concat("length","prototype");return Dn.f=Object.getOwnPropertyNames||function(n){return t(n,i)},Dn}(),e=(Un||(Un=1,qn.f=Object.getOwnPropertySymbols),qn),r=Gi(),s=i([].concat);return Ln=t("Reflect","ownKeys")||function(t){var i=n.f(r(t)),o=e.f;return o?s(i,o(t)):i}}function Wn(){if(Vn)return Gn;Vn=1;var t=Ii(),i=Kn(),n=Oi(),e=Vi();return Gn=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 Xn(){if(Hn)return jn;Hn=1;var t=D(),i=Oi().f,n=Bi(),e=hn(),r=wi(),s=Wn(),o=function(){if(zn)return Bn;zn=1;var t=F(),i=Ut(),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 Bn=e}();return jn=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 Yn,Jn,Qn,$n,Zn,te,ie,ne,ee,re,se={};function oe(){if(Jn)return Yn;Jn=1;var t=Pn(),i=Mn();return Yn=Object.keys||function(n){return t(n,i)}}function ue(){if(Zn)return $n;Zn=1;var t=Ft();return $n=t("document","documentElement")}function ae(){if(ie)return te;ie=1;var t,i=Gi(),n=function(){if(Qn)return se;Qn=1;var t=G(),i=Fi(),n=Vi(),e=Gi(),r=Mt(),s=oe();return se.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},se}(),e=Mn(),r=un(),s=ue(),o=Ni(),u=on(),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,te=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 ce(){if(ee)return ne;ee=1;var t=Ti(),i=ae(),n=Vi().f,e=t("unscopables"),r=Array.prototype;return void 0===r[e]&&n(r,e,{configurable:!0,value:i(null)}),ne=function(t){r[e][t]=!0}}!function(){if(re)return N;re=1;var t=Xn(),i=Rn().includes,n=F(),e=ce(),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 he=function(t,i){return he=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])},he(t,i)};function de(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}he(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var fe=function(){return fe=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},fe.apply(this,arguments)};function le(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 ve(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 me(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 ge(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 pe(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 we="/api/v1/web/events",ye="/api/v1/web/userEvents",Ee="/sdk/v2/config",_e="/sdk/v2/visitors",Ie="/sdk/v2/visitors",be="/sdk/v2/visitors/merge",Te="/api/v1/websdk/dlr",Se=18e5,Ce={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},Ne="/firebase-messaging-sw.js",De={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 Oe(t,i,n){var e=De[t],r=[];return i&&r.push(i),n&&r.push(n),r.length>0?"".concat(r.join("_"),"_").concat(e):e}var ke="websdk_storage_test",Ae="test_value",xe={REQUEST_TIMEOUT_MS:15e3,SENSITIVE_LOG_KEYS:["writeKey","token","accessToken","refreshToken","password"]},Re="INIT_ERROR",Pe="AUTH_ERROR",Me="NETWORK_ERROR",Ue="EVENT_ERROR",Le="VISITOR_CONFIG_ERROR",Fe="WebSDK initialized successfully",Ge="Failed to initialize WebSDK",Ve="WebSDK destroyed successfully",Be="Failed to destroy WebSDK",ze="Storage initialization failed",je="Failed to restore persisted page-path-tracking preference",He="Failed to restore persisted gamification-suppression preference",qe="Failed to restore persisted gamification theme",Ke="Session initialization failed",We="Visitor config initialization failed",Xe="Event tracker initialization failed",Ye="Failed to restore user context",Je="Failed to sync event tracker context",Qe="DLR setup failed",$e="EventQueue initialized successfully",Ze="EventTracker initialized successfully",tr="EventTracker destroyed successfully",ir="Event added to queue",nr="Failed to track event",er="Events sent successfully",rr="Failed to send events",sr="User event sent successfully",or="Failed to send user event",ur="Failed to send batch",ar="Starting queue processing",cr="Queue processing completed",hr="Queue processing failed",dr="Queue processing already in progress, skipping",fr="No pending events to process",lr="No more pending events",vr="Failed to mark event as processing",mr="Failed to remove events from storage",gr="Failed to initialize storage:",pr="Storage test failed:",wr="Storage read/write test failed",yr="StorageManager destroyed successfully",Er="Error during storage cleanup:",_r="New session started",Ir="Session continued",br="Session expired due to inactivity",Tr="Session ended on user switch (different user login)",Sr="Session ended on signout",Cr="Session restored from storage",Nr="Failed to track user signin event",Dr="Failed to track user signup event",Or="Failed to track user update event",kr="Failed to track user signout event",Ar="Failed to track behavioral event",xr="VisitorConfigManager initialized successfully",Rr="Visitor config fetched successfully",Pr="Failed to fetch visitor config",Mr="Visitor tracking is disabled",Ur="Visitor tracking is enabled",Lr="Visitor config retrieved from cache",Fr="AnonymousVisitorManager initialized successfully",Gr="Visitor ID generated successfully",Vr="Failed to generate visitor ID",Br="Visitor ID restored from storage",zr="Using cached visitor ID",jr="Visitor updated successfully",Hr="Failed to update visitor",qr="Visitor merged with user successfully",Kr="Failed to merge visitor with user",Wr="Visitor merge skipped",Xr="Notification permission denied by user",Yr="Notification manager initialized successfully",Jr="Failed to initialize notification manager",Qr="Notification initialization skipped (disabled or not supported)",$r="Firebase initialized successfully",Zr="Failed to initialize Firebase",ts="FCM token received successfully",is="FCM token refreshed",ns="Failed to retrieve FCM token",es="Service worker registered successfully",rs="Failed to register service worker",ss="Service worker not supported in this browser",os="FirebaseManager already initialized",us="FirebaseManager not initialized",as="No service worker found in registration",cs="Service worker registration required for FCM - no token obtained",hs="getToken() returned no token despite notifications being enabled - permission may have been revoked externally, VAPID key may be invalid, or this may be transient",ds="Failed to setup message listener",fs="FCM message payload has neither notification nor data",ls="onMessageReceived callback threw",vs="Notifications not supported in this browser",ms="Firebase Messaging instance not provided - notifications disabled",gs="Failed to restore notification state",ps="Failed to save notification state",ws="Failed to initialize Firebase for messaging",ys="Failed to store FCM token",Es="Failed to retrieve FCM token creation date",_s="Cannot refresh token - notifications not enabled",Is="Failed to refresh FCM token",bs="Failed to clear notification state",Ts="Permission revoked - clearing FCM token",Ss="Failed to destroy NotificationManager",Cs="DLR events sent successfully",Ns="Failed to send DLR events",Ds="web",Os="user_signin",ks="user_update",As="user_signout",xs="scroll_depth",Rs=[25,50,75,90],Ps=30,Ms=3e3,Us={WEBPUSH:"WEBPUSH"},Ls={WEB:"web"},Fs={ACCOUNT_NOT_EXISTS:2432,ACCOUNT_ID_NOT_PASSED:9999},Gs={ALREADY_MERGED:"1429",VISITOR_NOT_FOUND:"1428"},Vs={NOTIFICATION_RECEIVED:"push_notification_received",NOTIFICATION_CLICKED:"push_notification_click",NOTIFICATION_DISMISSED:"push_notification_close"},Bs="fcm",zs="push",js="1.10.6",Hs="GamificationManager initialized successfully",qs="Failed to initialize GamificationManager",Ks="GamificationManager destroyed successfully",Ws="GamificationManager state cleared",Xs="Gamification disabled — gamificationWriteKey not configured",Ys="GamificationManager refresh triggered",Js="GamificationManager data resync triggered",Qs="GamificationManager data resync failed",$s="GamificationManager loaded from cache — API call skipped",Zs="GamificationManager cache miss — fetching from API",to="GamificationManager reused cached token — token API call skipped",io="GamificationManager token cache miss — fetching new token",no="GamificationManager got an auth error on campaigns/entry points — invalidating cached token and retrying once",eo="GamificationManager token refetch is in backoff after repeated failures — skipping network call",ro="GamificationManager token refetch failed, entering backoff",so="GamificationManager failed to handle an ACTION_EVENT trigger",oo="Failed to persist gamification-suppression preference",uo="Content-initiated open skipped — gamification is suppressed",ao="Failed to persist gamification theme preference",co="Failed to read session-dismissal record",ho="Failed to persist session-dismissal record",fo="Failed to persist pending ACTION_EVENT queue",lo="Failed to restore pending ACTION_EVENT queue",vo="Entry point with unresolvable _id present in entryPointMap",mo="Failed to construct entry point instance",go="Expected a string field in analytics payload",po="Failed to persist gamification token cache",wo="Gamification token cache miss: failed to read/parse cached entry",yo="Gamification cache miss: no cached entry",Eo="Gamification cache miss: entry expired",_o="Gamification cache miss: failed to read/parse cached entry",Io="Failed to persist gamification cache",bo="Failed to read entry point count state",To="Failed to persist entry point count state",So="Failed to reconcile stale entry point state against refreshed server config",Co="GAME_PLAYED",No="CAMPAIGN_PLAY",Do="NO_GAME_CONFIGURED",Oo="game_open",ko="game_viewed",Ao="game_played",xo="game_completed",Ro="reward_seen",Po="content_open",Mo="content_viewed",Uo="LOYALTY",Lo="COMPLETED",Fo="ACTION_EVENT",Go=3e5,Vo=18e5,Bo="__GLU__CACHE__",zo="__GLU__TOKEN__",jo="__GLU__COUNT_DATE_",Ho="__GLU__QUEUE__",qo="__GLU__SESSION_DISMISSED_",Ko=16,Wo={LOGGED_IN:"loggedIn"},Xo={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"},Yo=1e3,Jo=16e3,Qo=2e3,$o=3e5,Zo="glu_cap_token",tu="glu_page_path_tracking_enabled",iu="glu_gamification_suppressed",nu="glu_gamification_theme",eu="/preload/",ru=5e3,su="__GLU__ORIGIN__",ou=new Set(xe.SENSITIVE_LOG_KEYS.map(function(t){return t.toLowerCase()}));function uu(t){return Array.isArray(t)?t.map(uu):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).map(function(t){var i=ge(t,2),n=i[0],e=i[1];return[n,ou.has(n.toLowerCase())?"[REDACTED]":uu(e)]})):t}var au=function(){function t(t,i){this.baseUrl=t.baseUrl.replace(/\/$/,""),this.logger=i}return t.prototype.request=function(t){return le(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={}),ve(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=uu(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:fe({"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:uu(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:Me,message:"Request timeout",details:t}:t.message.includes("HTTP 401")||t.message.includes("HTTP 403")?{code:Pe,message:"Authentication failed",details:t}:(t.message.includes("HTTP"),{code:Me,message:t.message,details:t}):{code:Me,message:"Unknown error: ".concat(String(t)),details:t}},t.prototype.get=function(t){return le(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),ve(this,function(n){return[2,this.request(t,fe(fe({},i),{method:"GET"}))]})})},t.prototype.post=function(t,i){return le(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),ve(this,function(e){return[2,this.request(t,fe(fe({},n),{method:"POST",body:i}))]})})},t.prototype.put=function(t,i){return le(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),ve(this,function(e){return[2,this.request(t,fe(fe({},n),{method:"PUT",body:i}))]})})},t.prototype.delete=function(t){return le(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),ve(this,function(n){return[2,this.request(t,fe(fe({},i),{method:"DELETE"}))]})})},t}(),cu="/user/v1/user/sdk",hu="/reward/v1.1/user",du="/entrypoints/v1/list",fu=function(){function t(t,i){this.http=new au({baseUrl:t},i),this.logger=i}return t.prototype.getToken=function(t,i,n,e,r){return le(this,void 0,void 0,function(){var s,o=this;return ve(this,function(u){return s=fe(fe(fe(fe(fe(fe({writeKey:t,userId:i,userState:n,appType:"WEB",sdkVersion:js},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 le(o,void 0,void 0,function(){var t;return ve(this,function(e){switch(e.label){case 0:return[4,this.http.post("".concat(cu,"?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 le(this,void 0,void 0,function(){var i=this;return ve(this,function(n){return this.logger.info("Fetching gamification campaigns"),[2,this.withRetry(function(){return le(i,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return[4,this.http.get(hu,{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 le(this,void 0,void 0,function(){var i=this;return ve(this,function(n){return this.logger.info("Fetching gamification entry points"),[2,this.withRetry(function(){return le(i,void 0,void 0,function(){var i;return ve(this,function(n){switch(n.label){case 0:return[4,this.http.get("".concat(du,"?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=me(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===Pe},t.prototype.withRetry=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(this,function(u){switch(u.label){case 0:e=function(e){var s,o,u;return ve(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(Yo*Math.pow(2,e-1),Jo),[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}(),lu={EMBEDDED:"EMBED",POP_UP:"POP_UP",BOTTOM_SHEET:"BOTTOM_SHEET",ICON_BUTTON:"FLOATING",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"BANNER"};function vu(t){var i,n=(i=t.container.typeId,lu[i]);return"EMBED"===n&&"STATIC"===t.content.typeId?"BANNER":n}function mu(t){return"CAMPAIGN"===t.typeId||"NUDGE"===t.typeId&&!!t.campaignId}function gu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId?"content":mu(t.content)?"game":"ICON_BUTTON"===t.container.typeId?"content":null}function pu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId}function wu(t){return t.toFixed(2)}function yu(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 Eu(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 _u(t){return t.triggerType===Fo}var Iu=new Set(["EMBEDDED","NATIVE_BANNER"]);function bu(t){var i;if(!_u(t))return null;if(Iu.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 Tu=new Set(["POP_UP","BOTTOM_SHEET","CHAT_BOX"]);function Su(t){return Tu.has(t.container.typeId)}var Cu=new Set(["http:","https:"]);function Nu(t){if(!t||"undefined"==typeof window)return!1;try{return Cu.has(new URL(t,window.location.href).protocol)}catch(t){return!1}}function Du(t){var i,n,e=t.content;if("CAMPAIGN"===e.typeId)return null!==(i=e.campaignId)&&void 0!==i?i:Eu(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 Eu(r.content.conditions)}return null}var Ou={LAUNCHER_ICON:"ICON_BUTTON",BOTTOM_SHEET:"BOTTOM_SHEET",POP_UP:"POP_UP",EMBEDDED:"EMBEDDED",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"NATIVE_BANNER"};function ku(t){var i,n;if("string"==typeof t.p&&t.p.length>0)return t.p;try{for(var e=me(Object.entries(t)),r=e.next();!r.done;r=e.next()){var s=ge(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 Au(t,i){var n;return fe(fe(fe(fe(fe(fe(fe(fe(fe(fe({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 xu(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:Eu(null==c?void 0:c.conditions))&&void 0!==n?n:void 0;return fe(fe(fe(fe(fe(fe({id:null!==(e=ku(t))&&void 0!==e?e:""},void 0!==t.name&&{name:t.name}),{container:{typeId:null!==(r=Ou[o.typeId])&&void 0!==r?r:o.typeId,css:d,height:o.height,elementHookId:o.elementId},content:Au(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 Ru(t){var i,n,e=[],r={};try{for(var s=me(t),o=s.next();!o.done;o=s.next()){var u=xu(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 Pu="/*";function Mu(t){return t.startsWith("#/")||t.startsWith("#!/")}function Uu(t){try{return decodeURIComponent(t)}catch(i){return t}}function Lu(t){return t.replace(/(?:^\/+)|(?:\/+$)/g,"").split("/").filter(Boolean).map(Uu)}function Fu(t){try{return new URL(t)}catch(t){return null}}function Gu(t,i,n){for(var e=0;e<i.length;e++)if(t[n+e]!==i[e])return!1;return!0}function Vu(t,i){if(i.length>t.length)return-1;for(var n=0;n<=t.length-i.length;n++)if(Gu(t,i,n))return n;return-1}function Bu(t,i){var n=i.endsWith(Pu),e=n?i.slice(0,-2):i;if(""===e)return!1;if("/"===e)return!n&&0===t.length;var r=Lu(e),s=Vu(t,r);return-1!==s&&(!n||s+r.length<t.length)}function zu(t,i){var n=function(t){var i=t.trim();if("*"===i||i===Pu)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=Mu(s)?o+s:o;return u.test(a)}var c=function(t,i){if(!/^https?:\/\//i.test(t))return null;var n=Fu(i);if(!n)return!1;var e=t.endsWith(Pu),r=Fu(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=Lu(n.pathname),o=Lu(r.pathname),u=Vu(s,o);return 0===u&&u+o.length<s.length}(n,o);if(null!==c)return c;var h=Fu(t);return!!Bu(Lu(h?h.pathname:o),n)||!!Mu(s)&&Bu(Lu(s.replace(/^#!?\//,"").replace(/\?.*$/,"")),n)}function ju(t,i){var n,e;try{for(var r=me(i),s=r.next();!s.done;s=r.next()){if(zu(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 Hu(t,i){return"".concat(jo).concat(null!=i?i:"anonymous","_").concat(t)}function qu(t,i,n,e){return le(this,void 0,void 0,function(){var r,s,o;return ve(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,n.get(Hu(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(bo,{entryPointId:t,error:o}),[2,null];case 3:return[2]}var a})})}function Ku(t,i){return t.getFullYear()===i.getFullYear()&&t.getMonth()===i.getMonth()&&t.getDate()===i.getDate()}function Wu(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||!ju(i,r))&&!(s.length&&!ju(i,s))}function Xu(t,i,n,e,r){return!n||!Ku(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 Yu(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 Ju(t,i,n,e,r){return le(this,void 0,void 0,function(){var s,o,u,a,c,h,d,f,l,v,m;return ve(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)?_u(t)||Wu(o,f)?"INVALID"===h?(e.info("Rule engine: backend validation invalid",{entryPointId:t.id}),[2,!1]):_u(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,qu(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?Xu(t.id,l,m,d,e):Yu(t.id,l,m,e)]}})})}var Qu=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=me(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 _u(t)})},t.prototype.size=function(){return this.queue.length},t.prototype.entries=function(){return this.queue},t}(),$u={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 Zu(t){var i=t?"#1E1E1E":"#fff";return Object.values($u).map(function(t){return"function"==typeof t.css?t.css(i):t.css}).join("")}function ta(){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 ia(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 na(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){return"UTC"}}function ea(t,i){var n,e={campaignName:ia(n=window.location.search,"utm_campaign")||"",campaignSource:ia(n,"utm_source")||"",campaignMedium:ia(n,"utm_medium")||""};return{libraryName:"cap-hydra-web-sdk",libraryVersion:js,locale:navigator.language||navigator.languages&&navigator.languages[0]||"en-US",userAgent:navigator.userAgent||"",timezone:na(),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 ra(){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=me(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 sa(){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 oa(){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 ua(t){var i=ra(),n=sa(),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:ia(t,"utm_source"),utmMedium:ia(t,"utm_medium"),utmCampaign:ia(t,"utm_campaign"),utmTerm:ia(t,"utm_term"),utmContent:ia(t,"utm_content"),adsId:ia(t,"gclid")||ia(t,"fbclid")||ia(t,"msclkid")||ia(t,"ttclid")}}}catch(t){}return{utmSource:null,utmMedium:null,utmCampaign:null,utmTerm:null,utmContent:null,adsId:null}}(),u=oa(),a={sdk_version:js,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 aa=3e5,ca=null,ha=0;function da(){return le(this,void 0,void 0,function(){return ve(this,function(t){return null!==ca&&Date.now()-ha<aa?[2,ca]:"undefined"!=typeof navigator&&navigator.geolocation?[2,new Promise(function(t){navigator.geolocation.getCurrentPosition(function(i){ca={latitude:i.coords.latitude,longitude:i.coords.longitude},ha=Date.now(),t(ca)},function(){return t(null)},{maximumAge:aa,timeout:2e3,enableHighAccuracy:!1})})]:[2,null]})})}var fa="__glu_container",la="__glu_backdrop";function va(){return"__GLU__"+ta().replace(/-/g,"")}function ma(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ga(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 pa=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=Zu(i),n.dataset.gluDark=String(i));else{var e=this.mountStyle(Zu(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=me(Object.entries(i)),o=s.next();!o.done;o=s.next()){var u=ge(o.value,2),a=u[0],c=u[1];r.includes(a)&&(r=r.replace(new RegExp(ma(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($u.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=me(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&&ga(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($u.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=me(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=me(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}(),wa=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.sheetClass=va(),r.backdropClass=va(),r.sheetElement=null,r.height=i.height,r.createElement(),r.addCustomStyle(((e={})[fa]=r.sheetClass,e[la]=r.backdropClass,e)),r}return de(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.classList.add(this.backdropClass,$u.backDrop.className);var e=document.createElement("div"),r="IMG"===this.contentElement.tagName;e.classList.add(this.sheetClass,r?$u.bottomSheetStatic.className:$u.bottomSheet.className,$u.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($u.slideDownSheet.className),this.sheetElement.classList.add($u.slideUpSheet.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.sheetElement&&(this.sheetElement.classList.remove($u.slideUpSheet.className),this.sheetElement.classList.add($u.slideDownSheet.className),this.isShown=!1)},i}(pa),ya=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.instanceClass=va(),r.createElement(),r.addCustomStyle(((e={})[fa]=r.instanceClass,e)),r}return de(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($u.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($u.slideDown.className),this.rootElement.classList.add($u.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.rootElement&&(this.rootElement.classList.remove($u.slideUp.className),this.rootElement.classList.add($u.slideDown.className),this.isShown=!1)},i}(pa),Ea=[],_a=!1,Ia=null,ba=null;function Ta(t,i){ba=i,"undefined"!=typeof document&&(_a||((Ia||(Ia=new MutationObserver(function(){var t,i;try{for(var n=me(pe([],ge(Ea),!1)),e=n.next();!e.done;e=n.next()){var r=e.value;try{r()}catch(t){null==ba||ba.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}}})),Ia).observe(document.body,{childList:!0,subtree:!0}),_a=!0),Ea.includes(t)||Ea.push(t))}function Sa(t){0===(Ea=Ea.filter(function(i){return i!==t})).length&&_a&&Ia&&(Ia.disconnect(),Ia=null,_a=!1)}var Ca=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.supportsPreload=!1,r.instanceClass=va(),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),Sa(r.showOnceHookPresent),r.isObserverRunning=!1)}},r.hookId=i.elementHookId,r.createElement(),r.addCustomStyle(((e={})[fa]=r.instanceClass,e)),r}return de(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?$u.embeddedStatic.className:$u.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}),Ta(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&&(Sa(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.onDestroy=function(){this.isObserverRunning&&(Sa(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.showLoader=function(){},i.prototype.hideLoader=function(){},i}(pa),Na=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.instanceClass=va(),r.createElement(),r.addCustomStyle(((e={})[fa]=r.instanceClass,e)),r}return de(i,t),i.prototype.createElement=function(){if("undefined"!=typeof document){var t=document.createElement("div");t.appendChild(this.contentElement),t.classList.add($u.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($u.slideDown.className),this.rootElement.classList.add($u.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.rootElement&&(this.rootElement.classList.remove($u.slideUp.className),this.rootElement.classList.add($u.slideDown.className),t.prototype.hide.call(this))},i}(pa),Da=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.supportsPreload=!1,r.instanceClass=va(),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),Sa(r.showOnceHookPresent),r.isObserverRunning=!1)}},r.hookId=i.elementHookId,r.contentElement.classList.add(r.instanceClass),r.rootElement=r.contentElement,r.addCustomStyle(((e={})[fa]=r.instanceClass,e)),r}return de(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}),Ta(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&&(Sa(this.showOnceHookPresent),this.isObserverRunning=!1)},i.prototype.onDestroy=function(){this.isObserverRunning&&(Sa(this.showOnceHookPresent),this.isObserverRunning=!1)},i}(pa),Oa=function(t){function i(i,n){var e,r=t.call(this,i,n)||this;return r.popupClass=va(),r.backdropClass=va(),r.popupElement=null,r.height=i.height,r.createElement(),r.addCustomStyle(((e={})[fa]=r.popupClass,e[la]=r.backdropClass,e)),r}return de(i,t),i.prototype.createElement=function(){var i=this;if("undefined"!=typeof document){var n=document.createElement("div");n.classList.add(this.backdropClass,$u.backDrop.className);var e=document.createElement("div"),r="IMG"===this.contentElement.tagName;e.classList.add(this.popupClass,r?$u.popUpStatic.className:$u.popUp.className,$u.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($u.slideDown.className),this.popupElement.classList.add($u.slideUp.className),t.prototype.show.call(this))},i.prototype.hide=function(){this.popupElement&&(this.popupElement.classList.remove($u.slideUp.className),this.popupElement.classList.add($u.slideDown.className),this.isShown=!1)},i}(pa);function ka(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 Aa=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=me(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=me(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 ka(t)},t.dispatchToListeners=function(i,n,e){var r,s,o;try{for(var u=me(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+="&notLoggedIn=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}(),xa="http://www.w3.org/2000/svg",Ra={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"}]},Pa={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"}]},Ma={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"}]},Ua={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"}]},La={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 Fa(t){var i,n,e,r,s=document.createElementNS(xa,"svg");s.setAttribute("viewBox",t.viewBox),s.setAttribute("fill","none"),s.setAttribute("aria-hidden","true");try{for(var o=me(t.paths),u=o.next();!u.done;u=o.next()){var a=u.value,c=document.createElementNS(xa,"path");try{for(var h=(e=void 0,me(Object.entries(a))),d=h.next();!d.done;d=h.next()){var f=ge(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 Ga={card:"#1E1E1E",iconContainer:"#164048",heading:"#F5F5F5",notNow:"#AAAAAA"},Va={card:"#fff",iconContainer:"#e0f7fa",heading:"#333",notNow:"#888"},Ba=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 de(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?Ga:Va,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=Fa(Ra);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:Ua,text:"Start a streak anytime until [DATE HERE] by earning at least $1"},{icon:Pa,text:"Claim a bonus reward for each streak day"},{icon:Ra,text:"Complete a 7-day streak and earn an additional up to $50 reward"}];try{for(var l=me(f),v=l.next();!v.done;v=l.next()){var m=v.value,g=document.createElement("li");g.style.cssText=s.listItem;var p=Fa(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return ve(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:va(),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}(Aa);function za(t,i,n){var e=document.createElement("iframe");e.classList.add($u.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 ja=function(t){function i(i,n){var e=t.call(this,n)||this,r=e.resolveUrl(i);return e.element=za(e.urlModifier(r),n.onLoad,function(){return n.logger.error("Campaign iframe failed to load",{src:r})}),e}return de(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=me(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=me(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}(Aa);var Ha=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=va(),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 de(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=Fa(Ra);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=Fa(Pa);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=Fa("pristine"===s?Ma:Ua);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=Fa(La);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=fe(fe({},i),{id:this.actionId});this.sdkEventListener({target:"GLU_SDK",action:n})}else{var e,r={target:"GLU_SDK",action:fe(fe({},i),{id:this.actionId,content:fe(fe({},i.content),{typeId:"ACCEPT_GUARD"}),container:fe(fe({},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}(Aa),qa=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=va(),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 de(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:fe(fe({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(Aa),Ka=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=va(),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 de(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=pe([],ge(new Set(g.map(function(t){return t.step}))),!1).sort(function(t,i){return t-i});if(C.length>0){var N=ge(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:fe(fe({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(Aa),Wa=function(t){function i(i,n){var e=t.call(this,n)||this;e.actionId=va(),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 de(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=pe([],ge(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:fe(fe({},t),{id:this.actionId})};this.sdkEventListener(i)}},i}(Aa),Xa=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=za(e.urlModifier(i.url),n.onLoad,function(){return n.logger.error("Nudge iframe failed to load",{src:i.url})}),e}return de(i,t),i}(Aa),Ya=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=za(e.urlModifier(r,{token:!0}),n.onLoad,function(){return n.logger.error("Program iframe failed to load",{src:r})}),e}return de(i,t),i}(Aa),Ja=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=za(e.urlModifier(r,{token:!0}),n.onLoad,function(){return n.logger.error("Reward iframe failed to load",{src:r})}),e}return de(i,t),i}(Aa),Qa=function(t){function i(i,n){var e=t.call(this,n)||this;if(e.actionId=va(),e.data=i,e.shouldGateOnCampaign()){var r=e.extractGatedCampaignId();return r&&e.config.allCampaignsMap.byId[r]&&e.createElement(),e}return e.createElement(),e}return de(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?fe(fe({},n),{id:t.actionId}):n};t.sdkEventListener(e)}}),this.element=i},i}(Aa),$a=function(t){function i(i,n){var e=t.call(this,n)||this;return e.element=za(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 de(i,t),i}(Aa);var Za=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=fe(fe(fe(fe({},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 ja(n,i);case"WALLET":return new $a(n,i);case"NUDGE":return new Xa(n,i);case"PROGRAM":return new Ya(n,i);case"REWARD":return new Ja(n,i);case"STATIC":return new Qa(n,i);case"DYNAMIC":return new Ha(n,i);case"DYNAMIC_MULTISTEP_1":return new qa(n,i);case"DYNAMIC_MULTISTEP_2":return new Ka(n,i);case"DYNAMIC_MULTISTEP_3":return new Wa(n,i);case"ACCEPT_GUARD":return new Ba(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=fe({typeId:s.typeId,css:s.css,logger:n,darkMode:e},void 0!==r&&{onShown:r});switch(s.typeId){case"ICON_BUTTON":return new Na(o,i);case"CHAT_BOX":return new ya(o,i);case"POP_UP":return new Oa(fe(fe({},o),{height:s.height}),i);case"BOTTOM_SHEET":return new wa(fe(fe({},o),{height:s.height}),i);case"NATIVE_BANNER":return new Da(fe(fe({},o),{elementHookId:s.elementHookId}),i);case"EMBEDDED":return new Ca(fe(fe({},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}(),tc=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=ka(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&&ga(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=me(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=yu(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&&Nu(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}(),ic=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 tc,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 Qu,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 fu(i,n),this.trackEvent=r,this.getSessionId=s}return t.prototype.initialize=function(t,i){return le(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 ve(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(Zo),this.loadFromCache(t)])];case 2:return e=ge.apply(void 0,[_.sent(),2]),r=e[0],s=e[1],n!==this.initGeneration?[2]:(r&&(this.capToken=r),s?(this.logger.info($s,{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(Zs),[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(Hs,{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(qs,o),null===(E=null===(y=this.callback)||void 0===y?void 0:y.onInitFailure)||void 0===E||E.call(y,{code:Re,message:qs,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(Zo,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(tu,String(t)).catch(function(){}),this.refresh()},t.prototype.restorePersistedPagePathTracking=function(){return le(this,void 0,void 0,function(){var t;return ve(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(tu)];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(iu,String(t)).catch(function(t){i.logger.error(oo,{error:t})}),n&&!t?this.refresh():!n&&t&&this.closeSuppressedInstances()},t.prototype.closeSuppressedInstances=function(){var t,i;try{for(var n=me(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(uo,{entryPointId:t.id,containerTypeId:t.container.typeId}),!0)},t.prototype.isGamificationSuppressed=function(){return this.suppressed},t.prototype.restorePersistedGamificationSuppressed=function(){return le(this,void 0,void 0,function(){var t;return ve(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(iu)];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(nu,i).catch(function(t){n.logger.error(ao,{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=me(this.instances),u=o.next();!u.done;u=o.next()){var a=ge(u.value,2),c=a[0],h=a[1],d=!!(v=null===(r=this.entryPointMap)||void 0===r?void 0:r.byId[c])&&pu(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=me(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 le(this,void 0,void 0,function(){var i;return ve(this,function(n){switch(n.label){case 0:return[4,this.storageManager.get(nu)];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?(Su(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(Ws),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=me(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=me(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(Zo).catch(function(){}),this.initialized=!1},t.prototype.destroy=function(){this.clean(),this.logger.info(Ks)},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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return ve(this,function(f){switch(f.label){case 0:if(!this.entryPointMap)return[2];t=this.resolveCurrentPath(),this.logger.info(Ys,{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=me(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])||_u(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&&pu(n)?n.container.elementHookId:null};return pe([],ge(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 le(this,void 0,void 0,function(){var e,r,s,o,u;return ve(this,function(a){switch(a.label){case 0:return e=Su(t),r=null===(u=t.conditions)||void 0===u?void 0:u.singleOpenName,!e&&r&&i[r]?[2]:(s=pu(t)?t.container.elementHookId:null)&&n[s]?[2]:!_u(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,Ju(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&&!pu(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 le(this,void 0,void 0,function(){var i,n,e;return ve(this,function(r){switch(r.label){case 0:return(i=null===(e=this.entryPointMap)||void 0===e?void 0:e.byId[t])?!_u(i)&&this.isCampaignCompleted(i)?[2]:[4,this.isDismissedThisSession(i)]:[2];case 1:return r.sent()||this.isEffectivelySuppressed(i)?[2]:[4,Ju(i,this.userId,this.storageManager,this.logger,this.resolveCurrentPath())];case 2:return r.sent()?(n=Su(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&&(Su(t)&&this.openOverlayIds.add(t.id),i.open())},t.prototype.notifyCampaignOpened=function(t){var i,n,e=Du(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=me(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)||(!pu(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 le(this,void 0,void 0,function(){var r,s,o,u,a,c;return ve(this,function(h){switch(h.label){case 0:return _u(t)?[2]:(r=null===(c=t.conditions)||void 0===c?void 0:c.showCount)?(s=new Date,[4,qu(t.id,i,n,e)]):[2];case 1:o=h.sent(),u=!r.dailyRefresh||o&&Ku(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(Hu(t.id,i),JSON.stringify(u))];case 3:return h.sent(),[3,5];case 4:return a=h.sent(),e.error(To,{entryPointId:t.id,error:a}),[3,5];case 5:return[2]}})})})(t,this.userId,this.storageManager,this.logger).catch(function(n){i.logger.error(To,{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=Du(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(qo).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 le(this,void 0,void 0,function(){var i,n,e,r,s;return ve(this,function(o){switch(o.label){case 0:if(pu(t)||_u(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(co,{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&&!pu(e)&&!_u(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(ho,{entryPointId:t,error:i})})}}},t.prototype.queueStorageKey=function(t){return Ho+t},t.prototype.persistActionEventQueue=function(){var t=this;if(this.userId){var i=this.campaignQueue.entries().filter(function(t){return _u(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(fo,{error:i})}):this.storageManager.remove(n).catch(function(){})}},t.prototype.restorePersistedActionEventQueue=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h;return ve(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=me(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])&&_u(o)?[4,Ju(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(lo,{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(vo,{totalEntryPoints:this.entryPointMap.allIds.length});try{for(var e=me(this.entryPointMap.allIds),r=e.next();!r.done;r=e.next()){var s=r.value,o=this.entryPointMap.byId[s],u=o?bu(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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l;return ve(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:Do}),[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=me(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(so,{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=me(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&&(_u(u)||!this.isCampaignCompleted(u))&&(_u(u)||Wu(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 le(this,void 0,void 0,function(){var t;return ve(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.storageManager.get(su)];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(eu),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()},ru);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 Za(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(mo,{entryPointId:t,error:i}),null}},t.prototype.trackEntryPointOpen=function(t){var i,n,e,r=this,s=gu(t);if(s&&this.userId){if(this.markOpened(t.id),"game"===s){this.getOrCreateTrackingState(t.id).completionFired=!1;var o=Du(t),u={campaign_id:o,game_type:this.lookupGameType(o),entry_surface:null!==(i=vu(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(Oo,u)}else{u={page_id:t.container.elementHookId,content_surface:null!==(e=vu(t))&&void 0!==e?e:""};this.trackEvent(Po,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:Du(t)});var e=gu(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=Du(t);return{campaign_id:r,game_type:this.lookupGameType(r),load_time_ms:wu(n)}}return{page_id:t.container.elementHookId,content_surface:null!==(e=vu(t))&&void 0!==e?e:"",load_time_ms:wu(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&&Du(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,No))return this.trackGamePlayed(i),void this.trackRewardSeenIfPresent(t,i);if(this.matchesAnalyticsEventName(t,Co)){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[Xo.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&&mu(n.content)&&this.userId){var e=this.getOrCreateTrackingState(t);e.playedAt=Date.now(),e.completionFired=!1;var r=Du(n),s={campaign_id:r,game_type:this.lookupGameType(r)};this.trackEvent(Ao,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&&mu(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=Du(e),u={campaign_id:o,game_type:this.lookupGameType(o),total_time_ms:wu(s)};this.trackEvent(xo,u)}},t.prototype.trackRewardSeenIfPresent=function(t,i){if("object"==typeof t&&null!==t){var n=t[Xo.CAMPAIGN_DETAILS];if("object"==typeof n&&null!==n){var e=n,r=e[Xo.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,Xo.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,Xo.CAMPAIGN_ID),reward_type:this.readStringField(t,Xo.REWARD_TYPE)};this.trackEvent(Ro,r)}}},t.prototype.readStringField=function(t,i){var n=t[i];return void 0===n?null:"string"==typeof n?n:(this.logger.warn(go,{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:Uo};this.trackEvent(Po,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:Uo,load_time_ms:wu(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?ko:Mo,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(fe(fe({},null!==(p=w.data)&&void 0!==p?p:{}),((n={})[Xo.EVENT_NAME]=Co,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&&Nu(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)||(Su(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:va(),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&&Nu(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=yu(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&&Nu(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&&Nu(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:va(),container:{typeId:e.typeId,css:"",height:e.height,elementHookId:""},content:fe({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=me(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 Bo+t},t.prototype.tokenCacheKey=function(t){return zo+t},t.prototype.loadTokenFromCache=function(t){return le(this,void 0,void 0,function(){var i,n,e;return ve(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>=Vo?[2,null]:[2,n.token]):[2,null];case 2:return e=r.sent(),this.logger.error(wo,{userId:t,error:e}),[2,null];case 3:return[2]}})})},t.prototype.saveTokenToCache=function(t,i){return le(this,void 0,void 0,function(){var n,e;return ve(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(po,{error:e}),[3,4];case 4:return[2]}})})},t.prototype.getOrFetchToken=function(t,i){return le(this,void 0,void 0,function(){var n,e;return ve(this,function(r){switch(r.label){case 0:return[4,this.loadTokenFromCache(t)];case 1:return(n=r.sent())?(this.logger.info(to),[2,n]):(this.logger.info(io),[4,this.apiClient.getToken(this.writeKey,t,Wo.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===Pe},t.prototype.ensureFreshToken=function(t){return le(this,void 0,void 0,function(){var i,n,e,r;return ve(this,function(s){switch(s.label){case 0:if(this.tokenRefetchInFlight)return[2,this.tokenRefetchInFlight];if(Date.now()<this.authBackoffUntil)throw this.logger.warn(eo,{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(Qo*Math.pow(2,this.authFailureCount-1),$o),this.authBackoffUntil=Date.now()+r,this.logger.error(ro,{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 le(this,void 0,void 0,function(){var n;return ve(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,Wo.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 le(this,void 0,void 0,function(){var n,e;return ve(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(no,{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 le(this,void 0,void 0,function(){var i,n,e;return ve(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>=Go?(this.logger.debug(Eo,{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(yo,{userId:t}),[2,!1]);case 2:return e=r.sent(),this.logger.error(_o,{userId:t,error:e}),[2,!1];case 3:return[2]}})})},t.prototype.saveToCache=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Io,{error:i}),[3,4];case 4:return this.allCampaignsMap.base&&this.storageManager.set(su,this.allCampaignsMap.base).catch(function(){}),[2]}})})},t.prototype.handleScreenChange=function(){return le(this,void 0,void 0,function(){return ve(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>=Go},t.prototype.resyncData=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return ve(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=ge.apply(void 0,[h.sent(),2]),r=e[0],s=e[1],n!==this.syncGeneration?[2]:(o=this.entryPointMap,this.allCampaignsMap=r,this.entryPointMap=Ru(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(Qs,u),[3,5];case 5:return[2]}})})},t.prototype.reconcileEntryPointState=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f,l=this;return ve(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(Hu(t,n)).catch(function(i){l.logger.error(So,{entryPointId:t,error:i})})},u=this;try{for(a=me(pe(pe([],ge(r),!1),ge(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=me(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 le(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h,d=this;return ve(this,function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),[4,this.storageManager.keys("".concat(qo).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,me(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(So,{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=me(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(So,{entryPointId:"all",error:a}),[3,3];case 3:return[2]}})})},t.prototype.fetchAndCache=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o;return ve(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=ge.apply(void 0,[u.sent(),2]),s=r[0],o=r[1],n!==this.initGeneration?[2,!1]:(this.allCampaignsMap=s,this.entryPointMap=Ru(o),this.buildEventIndex(),this.lastSyncTimestamp=Date.now(),this.saveToCache(),[2,n===this.initGeneration])}})})},t.prototype.isCampaignCompleted=function(t){var i,n,e,r=Du(t);if(!r||!this.allCampaignsMap)return!1;var s=this.allCampaignsMap.byId[r];if(!s)return!1;var o=Lo;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()},Ko)}});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 le(t,void 0,void 0,function(){return ve(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}(),nc=function(){function t(t,i,n,e,r){this.httpClient=new au(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 le(this,void 0,void 0,function(){var o,u,a,c,h,d,f,l;return ve(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,da()];case 1:a=v.sent(),c=ea(s,a),h={request_id:ta(),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(we,h,{headers:d})];case 3:return f=v.sent(),this.logger.info(er,{requestId:h.request_id,eventCount:t.length,trackingMode:u,success:f.status.success}),[2,f];case 4:throw l=v.sent(),this.logger.error(rr,{requestId:h.request_id,eventCount:t.length,trackingMode:u,error:l}),l;case 5:return[2]}})})},t.prototype.getVisitorConfig=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s;return ve(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":Us.WEBPUSH},[4,this.httpClient.get(Ee,{headers:i})];case 2:return n=o.sent(),this.logger.info(Rr,{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(Pr,{orgId:t,error:e}),e;case 4:return[2]}})})},t.prototype.createVisitor=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(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(_e,i,{headers:n})];case 2:return e=u.sent(),this.logger.info(Gr,{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(Vr,{error:r,accountId:this.accountId}),r;case 4:return[2]}})})},t.prototype.updateVisitor=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a;return ve(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(Ie,"?identifierType=visitorId&identifierValue=").concat(encodeURIComponent(i)),[4,this.httpClient.put(r,n,{headers:e})];case 2:return s=c.sent(),this.logger.info(jr,{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(Hr,{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===Gs.ALREADY_MERGED)return void this.logger.info("Visitor already merged, treating as success",{visitorId:i});if(u===Gs.VISITOR_NOT_FOUND)throw this.logger.warn("Visitor not found, merge cannot proceed",{visitorId:i}),new ec(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(qr,{visitorId:i,statusCode:t.status.code,message:t.status.message})},t.prototype.mergeVisitor=function(t,i,n){return le(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 ve(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||Ls.WEB,_=[],u&&_.push({type:E,value:u,primary:!0,verified:!0,subscribed:h,accountId:this.accountId,attributes:{gateway:Bs,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=ea,T=[m],[4,da()];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(be,I,{headers:S})];case 3:return C=O.sent(),this.handleMergeResponse(C,t),[3,5];case 4:if((N=O.sent())instanceof ec)throw N;throw this.logger.error(Kr,{visitorId:t,error:N}),N;case 5:return[2]}})})},t.prototype.buildUserEventsRequest=function(t,i,n){return le(this,void 0,void 0,function(){var e,r;return ve(this,function(s){switch(s.label){case 0:return[4,da()];case 1:return e=s.sent(),r=ea(n,e),[2,{request_id:ta(),context:fe(fe({},r),{os_name:Ds}),events:[{name:t,eventExternalId:ta(),eventDateTime:(new Date).toISOString(),attributes:i}]}]}})})},t.prototype.sendUserEvents=function(t,i,n,e,r){return le(this,void 0,void 0,function(){var s,o,u,a,c;return ve(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(ye,t,{headers:s})];case 2:return h.sent(),this.logger.info(sr,{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(or,{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 le(this,void 0,void 0,function(){var i,n,e,r,s;return ve(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(Te,t,{headers:i})];case 2:return n=o.sent(),this.logger.info(Cs,{requestId:t.request_id,eventCount:t.events.length,success:n.status.success}),[2,n];case 3:throw e=o.sent(),this.logger.error(Ns,{requestId:t.request_id,eventCount:t.events.length,error:e}),e;case 4:return[2]}})})},t}(),ec=function(t){function i(i,n){var e=t.call(this,n)||this;return e.name="MergeNonRetryableError",e.code=i,e}return de(i,t),i}(Error);var rc,sc=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 le(this,void 0,void 0,function(){var t=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var n,e=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var t,i=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.db&&(this.db.close(),this.db=null),[2]})})},t.prototype.addEvent=function(t){return le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=50),ve(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 le(this,void 0,void 0,function(){var r,s=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=5),ve(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}(),oc=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||Ce.BATCH_SIZE,this.RETRY_DELAYS=e||Ce.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 sc(i))}else n?(i.info("EventQueue: Using provided IndexedDBStorage"),this.storage=n):(i.warn("EventQueue: No storage provided, creating new IndexedDBStorage"),this.storage=new sc(i))}return t.prototype.init=function(){return le(this,void 0,void 0,function(){return ve(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($e),[2]}})})},t.prototype.setUserContext=function(t,i,n){return le(this,void 0,void 0,function(){var e;return ve(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 le(this,arguments,void 0,function(t,i){var n,e,r;return void 0===i&&(i=!1),ve(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:ta(),event:t,accountId:this.currentAccountId,timestamp:(new Date).toISOString(),attempts:0,status:Ce.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(ir,{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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.isProcessing?(this.logger.debug(dr),[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=me(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 le(this,void 0,void 0,function(){var i=this;return ve(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 le(i,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return ve(this,function(h){switch(h.label){case 0:this.isProcessing=!0,this.logger.debug(ar),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(fr),[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=me(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(lr),[3,15]):[3,2];case 15:return[3,18];case 16:return u=h.sent(),this.logger.error(hr,{error:u}),[3,18];case 17:return this.isProcessing=!1,this.processingPromise=null,this.logger.debug(cr),[7];case 18:return[2]}})})},t.prototype.markEventsAsProcessing=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return ve(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=me(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(vr,{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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return ve(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(ur,{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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l,v;return ve(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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a;return ve(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,da()];case 1:return r=c.sent(),s=ea(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 fe(fe({},e),{eventRefId:n})}),request_id:ta(),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,Ce.DLR_SUCCESS_CODE)];case 3:return c.sent(),[2]}})})},t.prototype.removeSuccessfulEvents=function(t){return le(this,void 0,void 0,function(){var i,n;return ve(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(mr,{eventIds:i,error:n}),[3,4];case 4:return[2]}})})},t.prototype.handleBatchResponse=function(t,i){return le(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=Ce.GLOBAL_SUCCESS_CODE),ve(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!==Ce.PARTIAL_SUCCESS_CODE?[3,4]:[4,this.handlePartialSuccess(t,i.events)];case 3:return s.sent(),[3,8];case 4:return Ce.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 le(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h;return ve(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=me(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),Ce.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 le(this,void 0,void 0,function(){var n,e,r;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return ve(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=me(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 Ce.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 le(this,void 0,void 0,function(){var i,n;return ve(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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return ve(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=me(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 le(this,void 0,void 0,function(){return ve(this,function(t){switch(t.label){case 0:return[4,this.processQueueIfIdle()];case 1:return t.sent(),[2]}})})},t.prototype.destroy=function(){return le(this,void 0,void 0,function(){return ve(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}(),uc=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 le(this,void 0,void 0,function(){return ve(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 oc(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(Ze),[2]}})})},t.prototype.setUserContext=function(t,i,n){return le(this,void 0,void 0,function(){return ve(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 le(this,arguments,void 0,function(t,i){var n,e;return void 0===i&&(i=!1),ve(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(nr,{event:t,error:e}),new Error("".concat(Ue,": ").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=fe({},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:ta(),eventDateTime:(new Date).toISOString(),attributes:i||{}}}(t.name,i)},t.prototype.flush=function(){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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(tr),[2]}})})},t.prototype.trackNotificationReceived=function(t){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var n,e;return ve(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:Vs.NOTIFICATION_RECEIVED,clicked:Vs.NOTIFICATION_CLICKED,dismissed:Vs.NOTIFICATION_DISMISSED},r=null===(n=this.eventQueue)||void 0===n?void 0:n.getCurrentCuid(),s={messageId:i.messageId,gateway:Bs,result:{received:"SUCCESS",clicked:"CLICKED",dismissed:"DISMISSED"}[t],notification_route:zs,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=zs,s.title=i.title||null),"clicked"===t&&(s.notification_id=i.messageId,s.campaign_id=i.campaignId||null,s.channel=zs,s.action="open_app"),i.senderId&&(s.senderId=i.senderId),{attributes:s,name:e[t],eventDateTime:(new Date).toISOString(),eventExternalId:ta()}},t.prototype.dispatchDLREvent=function(t){return le(this,void 0,void 0,function(){var i;return ve(this,function(n){switch(n.label){case 0:switch(i=fe(fe(fe(fe(fe(fe({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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return ve(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=me(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 le(this,void 0,void 0,function(){var t=this;return ve(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 le(this,void 0,void 0,function(){var t=this;return ve(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}(),ac=function(){function t(t,i,n){this.initialized=!1,this.logger=t,this.brandId=i,this.applicationId=n,this.adapter=new cc(t)}return t.prototype.init=function(){return le(this,void 0,void 0,function(){var t,i,n,e;return ve(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 sc(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(gr,{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 le(this,void 0,void 0,function(){var i,n,e;return ve(this,function(r){switch(r.label){case 0:i=ke,n=Ae,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(wr);return[4,t.removeItem(i)];case 4:return r.sent(),[3,6];case 5:throw e=r.sent(),new Error("".concat(pr," ").concat(e));case 6:return[2]}})})},t.prototype.get=function(t){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.removeItem(t)]})})},t.prototype.clear=function(){return le(this,void 0,void 0,function(){return ve(this,function(t){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.clear()]})})},t.prototype.keys=function(t){return le(this,void 0,void 0,function(){return ve(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 sc?this.adapter:null},t.prototype.destroy=function(){return le(this,void 0,void 0,function(){var t;return ve(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 sc?[4,this.adapter.close()]:[3,3];case 2:i.sent(),i.label=3;case 3:return this.initialized=!1,this.logger.info(yr),[3,5];case 4:return t=i.sent(),this.logger.error(Er,t),this.initialized=!1,[3,5];case 5:return[2]}})})},t}(),cc=function(){function t(t){this.logger=t}return t.prototype.getItem=function(t){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var i,n,e;return ve(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"}(rc||(rc={}));var hc=function(){function t(t,i){void 0===t&&(t=!1),void 0===i&&(i=rc.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=fe(fe({},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=rc[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===rc.INFO||t===rc.ERROR?this.contextPrefix:"",s=r?"".concat(r," ").concat(i):i,o=this.formatMessage(t,s),u=n?[o,n]:[o];switch(t){case rc.VERBOSE:case rc.DEBUG:console.debug.apply(console,pe([],ge(u),!1));break;case rc.INFO:console.info.apply(console,pe([],ge(u),!1));break;case rc.WARN:console.warn.apply(console,pe([],ge(u),!1));break;case rc.ERROR:console.error.apply(console,pe([],ge(u),!1))}}},t.prototype.verbose=function(t,i){this.log(rc.VERBOSE,t,i)},t.prototype.debug=function(t,i){this.log(rc.DEBUG,t,i)},t.prototype.info=function(t,i){this.log(rc.INFO,t,i)},t.prototype.warn=function(t,i){this.log(rc.WARN,t,i)},t.prototype.error=function(t,i){this.log(rc.ERROR,t,i)},t.prototype.setLevel=function(t){this.level=t},t.prototype.setEnabled=function(t){this.enabled=t},t.prototype.getLogs=function(){return pe([],ge(this.logs),!1)},t.prototype.clearLogs=function(){this.logs=[]},t}(),dc=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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i,n=this;return ve(this,function(e){switch(e.label){case 0:if(!this.initialized)throw new Error("VisitorConfigManager not initialized");if(this.cachedConfig)return this.logger.info(Lr),[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(Le,": ").concat(i));case 5:return[2]}})})},t.prototype.isVisitorTrackingEnabled=function(){return le(this,void 0,void 0,function(){var t,i,n,e;return ve(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(Ur):this.logger.info(Mr),[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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e,r;return ve(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:this.cachedConfig=null,n.label=1;case 1:return n.trys.push([1,3,,4]),t=Oe("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 le(this,void 0,void 0,function(){return ve(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}(),fc=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 le(this,void 0,void 0,function(){return ve(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(Fr),[2]}})})},t.prototype.getOrCreateVisitorId=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s;return ve(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(zr,{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(Gr,{visitorId:r}),[2,r]}})})},t.prototype.createVisitor=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(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=fe({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===Fs.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===Fs.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 le(this,void 0,void 0,function(){var n,e,r,s;return ve(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=fe({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===Fs.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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d;return ve(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(Wr,{reason:"Not initialized"}),[2,!1];if(!this.visitorId)return this.logger.warn(Wr,{reason:"No visitor ID"}),[2,!1];if(!e&&!r&&!s)return this.logger.warn(Wr,{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(Wr,{reason:"Visitor already merged",visitorId:c}),[2,!0]):[4,this.persistPendingMerge(c,h,fe(fe(fe(fe(fe(fe({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 le(this,void 0,void 0,function(){var t,i;return ve(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(Wr,{reason:"Already merged"}),[2];case 4:return t.attempts>=Ps?(this.logger.error(Kr,{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})})},Ms)},t.prototype.collectMergeContext=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return ve(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,fe(fe(fe(fe(fe(fe(fe(fe(fe(fe({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(qr,{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 le(this,void 0,void 0,function(){var n;return ve(this,function(e){switch(e.label){case 0:return t instanceof ec?[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=fe(fe({},i),{attempts:i.attempts+1}),[4,this.savePendingMerge(n)];case 3:return e.sent(),n.attempts>=Ps?(this.logger.error(Kr,{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:Ps,nextRetryMs:Ms,visitorId:i.visitorId,error:t}),this.scheduleMergeRetry(),[2]}})})},t.prototype.persistPendingMerge=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d;return ve(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=fe(fe(fe(fe(fe(fe(fe(fe(fe({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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:this.cancelMergeRetryTimer(),n.label=1;case 1:return n.trys.push([1,3,,4]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.expiredAt=t,i=Oe("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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:if(this.visitorExternalId)return[2,this.visitorExternalId];t=ta(),this.visitorExternalId=t,e.label=1;case 1:return e.trys.push([1,3,,4]),i=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return ve(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),t=Oe("VISITOR_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=u.sent())&&(this.visitorId=i,this.logger.info(Br,{visitorId:i})),n=Oe("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),[4,this.storageManager.get(n)];case 2:return(e=u.sent())&&(this.visitorExternalId=e),r=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),t=Oe("VISITOR_ID",this.brandId,this.applicationId),i=Oe("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),n=Oe("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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.logger.info("Destroying AnonymousVisitorManager"),this.cancelMergeRetryTimer(),this.initialized=!1,this.logger.info("AnonymousVisitorManager destroyed successfully"),[2]})})},t}();function lc(){return"undefined"!=typeof window&&window.firebase?window.firebase:null}function vc(){return le(this,void 0,void 0,function(){var t;return ve(this,function(i){return(t=lc())?[2,t]:[2,import("firebase/app")]})})}function mc(){return le(this,void 0,void 0,function(){return ve(this,function(t){return[2,import("firebase/messaging")]})})}function gc(){return le(this,void 0,void 0,function(){var t;return ve(this,function(i){return(t=lc())&&t.remoteConfig?[2,t]:[2,import("firebase/remote-config")]})})}var pc=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||Ne,this.onTokenReceivedCallback=r,this.onMessageReceivedCallback=s}return t.prototype.initialize=function(){return le(this,void 0,void 0,function(){return ve(this,function(t){return this.isInitialized?(this.logger.warn(os),[2,!0]):this.messaging?(this.isInitialized=!0,this.logger.info($r),[2,!0]):(this.logger.error(Zr,new Error("Messaging instance missing")),[2,!1])})})},t.prototype.ensureServiceWorkerRegistered=function(){return le(this,void 0,void 0,function(){var t;return ve(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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:if(!("serviceWorker"in navigator))return this.logger.warn(ss),[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(es,{scope:i.scope}),[4,this.ensureServiceWorkerActive(i)];case 6:return e.sent(),[2,i];case 7:return n=e.sent(),this.logger.error(rs,n),[2,null];case 8:return[2]}})})},t.prototype.ensureServiceWorkerActive=function(t){return le(this,void 0,void 0,function(){var i,n=this;return ve(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(as),[2])})})},t.prototype.requestToken=function(){return le(this,void 0,void 0,function(){var t,i,n,e;return ve(this,function(r){switch(r.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(us),[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(cs),[2,null]);case 4:return(n=r.sent())?(this.currentToken=n,this.logger.info(ts,{token:n}),this.onTokenReceivedCallback&&this.onTokenReceivedCallback(n),[2,n]):(this.logger.error(hs),[2,null]);case 5:return e=r.sent(),this.logger.error(ns,{error:e}),[2,null];case 6:return[2]}})})},t.prototype.fetchFCMToken=function(t){return le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return[4,mc()];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 le(this,void 0,void 0,function(){var t,i=this;return ve(this,function(n){switch(n.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(us),[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,mc()];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(ds,{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(fs,t),this.onMessageReceivedCallback)try{this.onMessageReceivedCallback(t)}catch(t){this.logger.error(ls,{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}(),wc=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(ms),!1):(this.logger.info(vs),!1)},t.prototype.restoreState=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r;return ve(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=Oe("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=fe(fe(fe({},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(gs,{error:r}),[3,3];case 3:return[2]}})})},t.prototype.saveState=function(){return le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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(ps,{error:i}),[3,3];case 3:return[2]}})})},t.prototype.init=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Qr),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(Xr),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(Yr,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 le(this,void 0,void 0,function(){var t;return ve(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 pc(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(ws,t),t;case 6:return[2]}})})},t.prototype.initializeFirebase=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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 pc(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(Zr,i),this.state.firebaseInitialized=!1,this.state.isNotificationEnabled=!1,i;case 8:return[2]}})})},t.prototype.storeFCMToken=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s,o;return ve(this,function(u){switch(u.label){case 0:return u.trys.push([0,6,,7]),i=Oe("FCM_TOKEN",this.brandId,this.applicationId),n=Oe("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(ys,{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 fe({},this.state)},t.prototype.getFCMToken=function(){return this.state.fcmToken||null},t.prototype.getTokenCreationDate=function(){return le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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(Es,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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:if(!this.firebaseManager||!this.state.isNotificationEnabled)return this.logger.info(_s),[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(is,{token:t}),n.label=5;case 5:return[2,t];case 6:return i=n.sent(),this.logger.error(Is,i),[2,null];case 7:return[2]}})})},t.prototype.clearToken=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(bs,i),i;case 3:return[2]}})})},t.prototype.hasPermissionChanged=function(){return this.getPermissionStatus()!==this.state.permissionStatus},t.prototype.handlePermissionChange=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Ts),[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(ms),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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.firebaseManager&&(this.firebaseManager.destroy(),this.firebaseManager=null),t=Oe("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(Ss,i),[3,3];case 3:return[2]}})})},t}(),yc=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=Se/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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i;return ve(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(Ir,{sessionId:this.currentSession.sessionId,inactivityDuration:i}),[2,this.currentSession.sessionId];case 2:this.logger.info(br,{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 le(this,arguments,void 0,function(t){return void 0===t&&(t=0),ve(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 le(this,void 0,void 0,function(){return ve(this,function(i){switch(i.label){case 0:return this.currentSession?(this.logger.info("user_switch"===t?Tr:Sr,{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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.logger.info("Destroying SessionManager (session persists in storage)"),this.currentSession=null,[2]})})},t.prototype.startNewSession=function(){return le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return t=Date.now(),i=ta(),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(_r,{sessionId:i,sessionStartTime:t,sessionNumber:this.sessionNumber}),[2,i]}})})},t.prototype.restoreSession=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a;return ve(this,function(c){switch(c.label){case 0:return c.trys.push([0,7,,9]),t=Oe("SESSION_ID",this.brandId,this.applicationId),i=Oe("SESSION_START_TIME",this.brandId,this.applicationId),n=Oe("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(Cr,{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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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=Oe("SESSION_ID",this.brandId,this.applicationId),i=Oe("SESSION_START_TIME",this.brandId,this.applicationId),n=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),t=Oe("SESSION_ID",this.brandId,this.applicationId),i=Oe("SESSION_START_TIME",this.brandId,this.applicationId),n=Oe("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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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}(),Ec=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=Rs}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=me(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}(),_c=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 hc(!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._?(new hc(!0).warn("WebSDK is already initialized. Returning existing instance."),t._):(t._=new t(i),t._.init(),t._)},t.getInstance=function(){return t._},t.isInitialized=function(){return null!==t._},t.requireInstance=function(){if(!t._)throw new Error("WebSDK is not initialized. Call WebSDK.initialize(config) first.");return t._},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._)return Promise.resolve();var i=t._.destroy();return t._=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:rc.NONE,ERROR:rc.ERROR,WARN:rc.WARN,INFO:rc.INFO,DEBUG:rc.DEBUG,VERBOSE:rc.VERBOSE}[null!=t?t:"NONE"]},t.prototype.restoreUserContext=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a=this;return ve(this,function(c){switch(c.label){case 0:return c.trys.push([0,5,,6]),t=Oe("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 le(this,void 0,void 0,function(){var i;return ve(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 Oe("LAST_AUTHENTICATED_USER",this.config.brandId,this.config.applicationId)},t.prototype.persistLastAuthenticatedUser=function(t){return le(this,void 0,void 0,function(){var i;return ve(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 le(this,void 0,void 0,function(){var e,r,s,o;return ve(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=Oe("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"):(da(),this.initializationPromise=this.initializeAsync().catch(function(i){t.logger.error(Ge,i),t.initializationPromise=null}))},t.prototype.tryStep=function(t,i){return le(this,void 0,void 0,function(){var n;return ve(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 le(this,void 0,void 0,function(){var t,i,n=this;return ve(this,function(e){switch(e.label){case 0:this.logger.info("Initializing WebSDK",{version:js,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(Re,": ").concat(t));case 4:return[4,this.tryStep(ze,function(){return n.storageManager.init()})];case 5:return e.sent(),[4,this.tryStep(je,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(He,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(qe,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(Ke,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 wc(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(We,function(){return n.initializeVisitorConfig()})];case 14:return e.sent(),[4,this.tryStep(Xe,function(){return le(n,void 0,void 0,function(){var t=this;return ve(this,function(i){switch(i.label){case 0:return[4,this.eventTracker.init()];case 1:return i.sent(),this.eventTracker.setSessionInfoCallback(function(){return le(t,void 0,void 0,function(){return ve(this,function(t){return[2,this.sessionManager.getOrCreateSession()]})})}),[2]}})})})];case 15:return e.sent(),[4,this.tryStep(Ye,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 Ec(this.logger,function(t){n.pushEvent(xs,n.buildInternalEventAttributes(fe({},t)))}),this.scrollDepthTracker.init(),this.config.notifications?[4,this.tryStep(Qe,function(){return le(n,void 0,void 0,function(){return ve(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(Fe),[2]}})})},t.prototype.handleVisibilityChange=function(){return le(this,void 0,void 0,function(){var t,i,n;return ve(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 le(t,void 0,void 0,function(){var t;return ve(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 le(this,void 0,void 0,function(){var t,i,n=this;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h;return ve(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=ua(fe(fe({},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 le(t,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var n,e,r;return ve(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 le(this,void 0,void 0,function(){return ve(this,function(i){switch(i.label){case 0:return this.lastAuthenticatedUser?[4,this.sendUserEventToApi(ks,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 le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(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=ua(fe(fe({},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 le(this,void 0,void 0,function(){var n,e,r,s;return ve(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 le(this,void 0,void 0,function(){var i,n,e,r;return ve(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=Oe("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=fe(fe(fe(fe(fe({},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=fe(fe(fe(fe(fe({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=fe(fe({},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 le(this,arguments,void 0,function(t,i){return void 0===i&&(i=!1),ve(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 le(this,void 0,void 0,function(){var t;return ve(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(Ve),[3,17];case 16:throw t=i.sent(),this.logger.error(Be,{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 le(this,void 0,void 0,function(){var e,r,s;return ve(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(fe(fe(fe(fe(fe(fe({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(Wr,{reason:"No email, mobile, or externalId"}),[2,!1]):(this.logger.debug(Wr,{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(Kr,{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:Ls.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 le(this,void 0,void 0,function(){var r,s,o,u,a,c,h,d,f,l,v,m;return ve(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,fe(fe(fe({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 le(e,void 0,void 0,function(){var e;return ve(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(Nr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSigninAsync=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f=this;return ve(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(Os,t,i,fe(fe({},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=fe(fe(fe({},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 le(e,void 0,void 0,function(){var e;return ve(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(Dr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSignupAsync=function(t,i,n){return le(this,void 0,void 0,function(){return ve(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(Os,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 le(e,void 0,void 0,function(){var e;return ve(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(Or,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserUpdateAsync=function(t,i,n){return le(this,void 0,void 0,function(){return ve(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(ks,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 le(i,void 0,void 0,function(){var i;return ve(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(kr,{cuid:t,error:i}),[3,3];case 3:return[2]}})})})},t.prototype.resetToAnonymousMode=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d,f,l;return ve(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=ua(fe(fe({},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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return ve(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(As,t,this.lastUserAttributes,fe(fe({},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 fe(fe(fe({},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(Ar,{eventName:t,error:i})})},t.prototype.pushGamificationEvent=function(t,i){var n=this,e=fe(fe({},this.userIdentified&&this.lastAuthenticatedUser&&{cuid:this.lastAuthenticatedUser}),i);this.pushEventAsync(t,e,!0).catch(function(i){n.logger.error(Ar,{eventName:t,error:i})})},t.prototype.pushEventAsync=function(t,i){return le(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=!1),ve(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=fe({},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||Ls.WEB},t.prototype.applyConfigDefaults=function(){this.config.source=this.config.source||Us.WEBPUSH,this.config.channelType=this.config.channelType||Ls.WEB;var t=Se/6e4;this.config.sessionTimeoutMinutes=this.config.sessionTimeoutMinutes||t,this.config.batchSize=this.config.batchSize||Ce.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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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,ua(fe(fe({},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 ac(this.logger,this.config.brandId,this.config.applicationId),this.sessionManager=new yc(this.storageManager,this.logger,this.config.brandId,this.config.applicationId,this.config.sessionTimeoutMinutes),this.apiClient=new nc({baseUrl:this.config.baseURL||""},this.logger,this.config.accountId||"",this.config.orgId||"",this.config.source||Us.WEBPUSH);var i=this.apiClient;this.eventTracker=new uc(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 dc(n,i,this.logger,this.storageManager,this.config.brandId,this.config.applicationId),this.anonymousVisitorManager=new fc(e,n,i,this.logger,this.storageManager,fe(fe({},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 ic(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(Xs)},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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return ve(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,vc()];case 2:return t=f.sent(),[4,gc()];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 le(this,void 0,void 0,function(){var t;return ve(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 le(this,void 0,void 0,function(){return ve(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._=null,t}();exports.HydraSDK=_c,exports.default=_c;
1
+ "use strict";Object.defineProperty(exports,"t",{value:!0});var t="undefined"!=typeof globalThis&&globalThis||"undefined"!=typeof self&&self||"undefined"!=typeof global&&global||{},i="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,e="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),r="FormData"in t,s="ArrayBuffer"in t;if(s)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&o.indexOf(Object.prototype.toString.call(t))>-1};function a(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 c(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var i={next:function(){var i=t.shift();return{done:void 0===i,value:i}}};return n&&(i[Symbol.iterator]=function(){return i}),i}function d(t){this.map={},t instanceof d?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 f(t){if(!t.i)return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function l(t){return new Promise(function(i,n){t.onload=function(){i(t.result)},t.onerror=function(){n(t.error)}})}function v(t){var i=new FileReader,n=l(i);return i.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}function g(){return this.bodyUsed=!1,this.o=function(t){var n;this.bodyUsed=this.bodyUsed,this.u=t,t?"string"==typeof t?this.h=t:e&&Blob.prototype.isPrototypeOf(t)?this.l=t:r&&FormData.prototype.isPrototypeOf(t)?this.v=t:i&&URLSearchParams.prototype.isPrototypeOf(t)?this.h=t.toString():s&&e&&((n=t)&&DataView.prototype.isPrototypeOf(n))?(this.m=m(t.buffer),this.u=new Blob([this.m])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this.m=m(t):this.h=t=Object.prototype.toString.call(t):(this.i=!0,this.h=""),this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this.l&&this.l.type?this.headers.set("content-type",this.l.type):i&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e&&(this.blob=function(){var t=f(this);if(t)return t;if(this.l)return Promise.resolve(this.l);if(this.m)return Promise.resolve(new Blob([this.m]));if(this.v)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this.h]))}),this.arrayBuffer=function(){if(this.m){var t=f(this);return t||(ArrayBuffer.isView(this.m)?Promise.resolve(this.m.buffer.slice(this.m.byteOffset,this.m.byteOffset+this.m.byteLength)):Promise.resolve(this.m))}if(e)return this.blob().then(v);throw new Error("could not read as ArrayBuffer")},this.text=function(){var t,i,n,e,r,s=f(this);if(s)return s;if(this.l)return t=this.l,i=new FileReader,n=l(i),e=/charset=([A-Za-z0-9_-]+)/.exec(t.type),r=e?e[1]:"utf-8",i.readAsText(t,r),n;if(this.m)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.m));if(this.v)throw new Error("could not read FormData body as text");return Promise.resolve(this.h)},r&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,i){t=a(t),i=c(i);var n=this.map[t];this.map[t]=n?n+", "+i:i},d.prototype.delete=function(t){delete this.map[a(t)]},d.prototype.get=function(t){return t=a(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(a(t))},d.prototype.set=function(t,i){this.map[a(t)]=c(i)},d.prototype.forEach=function(t,i){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(i,this.map[n],n,this)},d.prototype.keys=function(){var t=[];return this.forEach(function(i,n){t.push(n)}),h(t)},d.prototype.values=function(){var t=[];return this.forEach(function(i){t.push(i)}),h(t)},d.prototype.entries=function(){var t=[];return this.forEach(function(i,n){t.push([n,i])}),h(t)},n&&(d.prototype[Symbol.iterator]=d.prototype.entries);var p=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function w(i,n){if(!(this instanceof w))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(i instanceof w){if(i.bodyUsed)throw new TypeError("Already read");this.url=i.url,this.credentials=i.credentials,n.headers||(this.headers=new d(i.headers)),this.method=i.method,this.mode=i.mode,this.signal=i.signal,s||null==i.u||(s=i.u,i.bodyUsed=!0)}else this.url=String(i);if(this.credentials=n.credentials||this.credentials||"same-origin",!n.headers&&this.headers||(this.headers=new d(n.headers)),this.method=(e=n.method||this.method||"GET",r=e.toUpperCase(),p.indexOf(r)>-1?r:e),this.mode=n.mode||this.mode||null,this.signal=n.signal||this.signal||function(){if("AbortController"in t)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.o(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 y(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 E(t,i){if(!(this instanceof E))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 d(i.headers),this.url=i.url||"",this.o(t)}w.prototype.clone=function(){return new w(this,{body:this.u})},g.call(w.prototype),g.call(E.prototype),E.prototype.clone=function(){return new E(this.u,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var _=[301,302,303,307,308];E.redirect=function(t,i){if(-1===_.indexOf(i))throw new RangeError("Invalid status code");return new E(null,{status:i,headers:{location:t}})};var I=t.DOMException;try{new I}catch(t){(I=function(t,i){this.message=t,this.name=i;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),I.prototype.constructor=I}function b(i,n){return new Promise(function(r,o){var u=new w(i,n);if(u.signal&&u.signal.aborted)return o(new I("Aborted","AbortError"));var h=new XMLHttpRequest;function f(){h.abort()}if(h.onload=function(){var t,i,n={statusText:h.statusText,headers:(t=h.getAllResponseHeaders()||"",i=new d,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://")&&(h.status<200||h.status>599)?n.status=200:n.status=h.status,n.url="responseURL"in h?h.responseURL:n.headers.get("X-Request-URL");var e="response"in h?h.response:h.responseText;setTimeout(function(){r(new E(e,n))},0)},h.onerror=function(){setTimeout(function(){o(new TypeError("Network request failed"))},0)},h.ontimeout=function(){setTimeout(function(){o(new TypeError("Network request timed out"))},0)},h.onabort=function(){setTimeout(function(){o(new I("Aborted","AbortError"))},0)},h.open(u.method,function(i){try{return""===i&&t.location.href?t.location.href:i}catch(t){return i}}(u.url),!0),"include"===u.credentials?h.withCredentials=!0:"omit"===u.credentials&&(h.withCredentials=!1),"responseType"in h&&(e?h.responseType="blob":s&&(h.responseType="arraybuffer")),n&&"object"==typeof n.headers&&!(n.headers instanceof d||t.Headers&&n.headers instanceof t.Headers)){var l=[];Object.getOwnPropertyNames(n.headers).forEach(function(t){l.push(a(t)),h.setRequestHeader(t,c(n.headers[t]))}),u.headers.forEach(function(t,i){-1===l.indexOf(i)&&h.setRequestHeader(i,t)})}else u.headers.forEach(function(t,i){h.setRequestHeader(i,t)});u.signal&&(u.signal.addEventListener("abort",f),h.onreadystatechange=function(){4===h.readyState&&u.signal.removeEventListener("abort",f)}),h.send(void 0===u.u?null:u.u)})}b.polyfill=!0,t.fetch||(t.fetch=b,t.Headers=d,t.Request=w,t.Response=E);var T,S,C="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},N={};function D(){if(S)return T;S=1;var t=function(t){return t&&t.Math===Math&&t};return T=t("object"==typeof globalThis&&globalThis)||t("object"==typeof window&&window)||t("object"==typeof self&&self)||t("object"==typeof C&&C)||t("object"==typeof T&&T)||function(){return this}()||Function("return this")()}var O,k,A,x,R,P,M,U,L={};function F(){return k?O:(k=1,O=function(t){try{return!!t()}catch(t){return!0}})}function G(){if(x)return A;x=1;var t=F();return A=!t(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})}function V(){if(P)return R;P=1;var t=F();return R=!t(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})}function B(){if(U)return M;U=1;var t=V(),i=Function.prototype.call;return M=t?i.bind(i):function(){return i.apply(i,arguments)},M}var z,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={};function kt(){return H?j:(H=1,j=function(t,i){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:i}})}function At(){if(K)return q;K=1;var t=V(),i=Function.prototype,n=i.call,e=t&&i.bind.bind(n,n);return q=t?e:function(t){return function(){return n.apply(t,arguments)}},q}function xt(){if(J)return Y;J=1;var t=At(),i=F(),n=function(){if(X)return W;X=1;var t=At(),i=t({}.toString),n=t("".slice);return W=function(t){return n(i(t),8,-1)}}(),e=Object,r=t("".split);return Y=i(function(){return!e("z").propertyIsEnumerable(0)})?function(t){return"String"===n(t)?r(t,""):e(t)}:e}function Rt(){return $?Q:($=1,Q=function(t){return null==t})}function Pt(){if(tt)return Z;tt=1;var t=Rt(),i=TypeError;return Z=function(n){if(t(n))throw new i("Can't call method on "+n);return n}}function Mt(){if(nt)return it;nt=1;var t=xt(),i=Pt();return it=function(n){return t(i(n))}}function Ut(){if(rt)return et;rt=1;var t="object"==typeof document&&document.all;return et=void 0===t&&void 0!==t?function(i){return"function"==typeof i||i===t}:function(t){return"function"==typeof t}}function Lt(){if(ot)return st;ot=1;var t=Ut();return st=function(i){return"object"==typeof i?null!==i:t(i)}}function Ft(){if(at)return ut;at=1;var t=D(),i=Ut();return ut=function(n,e){return arguments.length<2?(r=t[n],i(r)?r:void 0):t[n]&&t[n][e];var r},ut}function Gt(){if(vt)return lt;vt=1;var t,i,n=D(),e=function(){if(ft)return dt;ft=1;var t=D().navigator,i=t&&t.userAgent;return dt=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]),lt=i}function Vt(){if(gt)return mt;gt=1;var t=Gt(),i=F(),n=D().String;return mt=!!Object.getOwnPropertySymbols&&!i(function(){var i=Symbol("symbol detection");return!n(i)||!(Object(i)instanceof Symbol)||!Symbol.sham&&t&&t<41})}function Bt(){if(wt)return pt;wt=1;var t=Vt();return pt=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function zt(){if(Et)return yt;Et=1;var t=Ft(),i=Ut(),n=function(){if(ht)return ct;ht=1;var t=At();return ct=t({}.isPrototypeOf)}(),e=Bt(),r=Object;return yt=e?function(t){return"symbol"==typeof t}:function(e){var s=t("Symbol");return i(s)&&n(s.prototype,r(e))}}function jt(){if(It)return _t;It=1;var t=String;return _t=function(i){try{return t(i)}catch(t){return"Object"}}}function Ht(){if(Tt)return bt;Tt=1;var t=Ut(),i=jt(),n=TypeError;return bt=function(e){if(t(e))return e;throw new n(i(e)+" is not a function")}}function qt(){if(Ct)return St;Ct=1;var t=Ht(),i=Rt();return St=function(n,e){var r=n[e];return i(r)?void 0:t(r)}}function Kt(){if(Dt)return Nt;Dt=1;var t=B(),i=Ut(),n=Lt(),e=TypeError;return Nt=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 Wt,Xt,Yt,Jt,Qt,$t,Zt,ti,ii,ni,ei,ri,si,oi,ui,ai,ci,hi,di,fi,li,vi,mi,gi,pi={exports:{}};function wi(){if(Jt)return Yt;Jt=1;var t=D(),i=Object.defineProperty;return Yt=function(n,e){try{i(t,n,{value:e,configurable:!0,writable:!0})}catch(i){t[n]=e}return e}}function yi(){if(Qt)return pi.exports;Qt=1;var t=Xt?Wt:(Xt=1,Wt=!1),i=D(),n=wi(),e="__core-js_shared__",r=pi.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"}),pi.exports}function Ei(){if(Zt)return $t;Zt=1;var t=yi(),i=Object.create||Object;return $t=function(n,e){return t[n]||(t[n]=e||i(null))}}function _i(){if(ii)return ti;ii=1;var t=Pt(),i=Object;return ti=function(n){return i(t(n))}}function Ii(){if(ei)return ni;ei=1;var t=At(),i=_i(),n=t({}.hasOwnProperty);return ni=Object.hasOwn||function(t,e){return n(i(t),e)}}function bi(){if(si)return ri;si=1;var t=At(),i=0,n=Math.random(),e=t(1.1.toString);return ri=function(t){return"Symbol("+(void 0===t?"":t)+")_"+e(++i+n,36)}}function Ti(){if(ui)return oi;ui=1;var t=D(),i=Ei(),n=Ii(),e=bi(),r=Vt(),s=Bt(),o=t.Symbol,u=i("wks"),a=s?o.for||o:o&&o.withoutSetter||e;return oi=function(t){return n(u,t)||(u[t]=r&&n(o,t)?o[t]:a("Symbol."+t)),u[t]}}function Si(){if(ci)return ai;ci=1;var t=B(),i=Lt(),n=zt(),e=qt(),r=Kt(),s=Ti(),o=TypeError,u=s("toPrimitive");return ai=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 Ci(){if(di)return hi;di=1;var t=Si(),i=zt();return hi=function(n){var e=t(n,"string");return i(e)?e:e+""}}function Ni(){if(li)return fi;li=1;var t=D(),i=Lt(),n=t.document,e=i(n)&&i(n.createElement);return fi=function(t){return e?n.createElement(t):{}}}function Di(){if(mi)return vi;mi=1;var t=G(),i=F(),n=Ni();return vi=!t&&!i(function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a})}function Oi(){if(gi)return L;gi=1;var t=G(),i=B(),n=function(){if(z)return Ot;z=1;var t={}.propertyIsEnumerable,i=Object.getOwnPropertyDescriptor,n=i&&!t.call({1:2},1);return Ot.f=n?function(t){var n=i(this,t);return!!n&&n.enumerable}:t,Ot}(),e=kt(),r=Mt(),s=Ci(),o=Ii(),u=Di(),a=Object.getOwnPropertyDescriptor;return L.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])},L}var ki,Ai,xi,Ri,Pi,Mi,Ui,Li={};function Fi(){if(Ai)return ki;Ai=1;var t=G(),i=F();return ki=t&&i(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})}function Gi(){if(Ri)return xi;Ri=1;var t=Lt(),i=String,n=TypeError;return xi=function(e){if(t(e))return e;throw new n(i(e)+" is not an object")}}function Vi(){if(Pi)return Li;Pi=1;var t=G(),i=Di(),n=Fi(),e=Gi(),r=Ci(),s=TypeError,o=Object.defineProperty,u=Object.getOwnPropertyDescriptor,a="enumerable",c="configurable",h="writable";return Li.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},Li}function Bi(){if(Ui)return Mi;Ui=1;var t=G(),i=Vi(),n=kt();return Mi=t?function(t,e,r){return i.f(t,e,n(1,r))}:function(t,i,n){return t[i]=n,t}}var zi,ji,Hi,qi,Ki,Wi,Xi,Yi,Ji,Qi,$i,Zi,tn,nn,en,rn={exports:{}};function sn(){if(qi)return Hi;qi=1;var t=At(),i=Ut(),n=yi(),e=t(Function.toString);return i(n.inspectSource)||(n.inspectSource=function(t){return e(t)}),Hi=n.inspectSource}function on(){if(Yi)return Xi;Yi=1;var t=Ei(),i=bi(),n=t("keys");return Xi=function(t){return n[t]||(n[t]=i(t))}}function un(){return Qi?Ji:(Qi=1,Ji={})}function an(){if(Zi)return $i;Zi=1;var t,i,n,e=function(){if(Wi)return Ki;Wi=1;var t=D(),i=Ut(),n=t.WeakMap;return Ki=i(n)&&/native code/.test(String(n))}(),r=D(),s=Lt(),o=Bi(),u=Ii(),a=yi(),c=on(),h=un(),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 $i={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 cn(){if(tn)return rn.exports;tn=1;var t=At(),i=F(),n=Ut(),e=Ii(),r=G(),s=function(){if(ji)return zi;ji=1;var t=G(),i=Ii(),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 zi={EXISTS:r,PROPER:s,CONFIGURABLE:o}}().CONFIGURABLE,o=sn(),u=an(),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=rn.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"),rn.exports}function hn(){if(en)return nn;en=1;var t=Ut(),i=Vi(),n=cn(),e=wi();return nn=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 dn,fn,ln,vn,mn,gn,pn,wn,yn,En,_n,In,bn,Tn,Sn,Cn,Nn,Dn={};function On(){if(vn)return ln;vn=1;var t=function(){if(fn)return dn;fn=1;var t=Math.ceil,i=Math.floor;return dn=Math.trunc||function(n){var e=+n;return(e>0?i:t)(e)}}();return ln=function(i){var n=+i;return n!=n||0===n?0:t(n)}}function kn(){if(gn)return mn;gn=1;var t=On(),i=Math.max,n=Math.min;return mn=function(e,r){var s=t(e);return s<0?i(s+r,0):n(s,r)}}function An(){if(wn)return pn;wn=1;var t=On(),i=Math.min;return pn=function(n){var e=t(n);return e>0?i(e,9007199254740991):0}}function xn(){if(En)return yn;En=1;var t=An();return yn=function(i){return t(i.length)}}function Rn(){if(In)return _n;In=1;var t=Mt(),i=kn(),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 _n={includes:e(!0),indexOf:e(!1)}}function Pn(){if(Tn)return bn;Tn=1;var t=At(),i=Ii(),n=Mt(),e=Rn().indexOf,r=un(),s=t([].push);return bn=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 Mn(){return Cn?Sn:(Cn=1,Sn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}var Un,Ln,Fn,Gn,Vn,Bn,zn,jn,Hn,qn={};function Kn(){if(Fn)return Ln;Fn=1;var t=Ft(),i=At(),n=function(){if(Nn)return Dn;Nn=1;var t=Pn(),i=Mn().concat("length","prototype");return Dn.f=Object.getOwnPropertyNames||function(n){return t(n,i)},Dn}(),e=(Un||(Un=1,qn.f=Object.getOwnPropertySymbols),qn),r=Gi(),s=i([].concat);return Ln=t("Reflect","ownKeys")||function(t){var i=n.f(r(t)),o=e.f;return o?s(i,o(t)):i}}function Wn(){if(Vn)return Gn;Vn=1;var t=Ii(),i=Kn(),n=Oi(),e=Vi();return Gn=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 Xn(){if(Hn)return jn;Hn=1;var t=D(),i=Oi().f,n=Bi(),e=hn(),r=wi(),s=Wn(),o=function(){if(zn)return Bn;zn=1;var t=F(),i=Ut(),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 Bn=e}();return jn=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 Yn,Jn,Qn,$n,Zn,te,ie,ne,ee,re,se={};function oe(){if(Jn)return Yn;Jn=1;var t=Pn(),i=Mn();return Yn=Object.keys||function(n){return t(n,i)}}function ue(){if(Zn)return $n;Zn=1;var t=Ft();return $n=t("document","documentElement")}function ae(){if(ie)return te;ie=1;var t,i=Gi(),n=function(){if(Qn)return se;Qn=1;var t=G(),i=Fi(),n=Vi(),e=Gi(),r=Mt(),s=oe();return se.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},se}(),e=Mn(),r=un(),s=ue(),o=Ni(),u=on(),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,te=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 ce(){if(ee)return ne;ee=1;var t=Ti(),i=ae(),n=Vi().f,e=t("unscopables"),r=Array.prototype;return void 0===r[e]&&n(r,e,{configurable:!0,value:i(null)}),ne=function(t){r[e][t]=!0}}!function(){if(re)return N;re=1;var t=Xn(),i=Rn().includes,n=F(),e=ce(),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 he=function(t,i){return he=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])},he(t,i)};function de(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}he(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var fe=function(){return fe=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},fe.apply(this,arguments)};function le(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 ve(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 me(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 ge(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 pe(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 we="/api/v1/web/events",ye="/api/v1/web/userEvents",Ee="/sdk/v2/config",_e="/sdk/v2/visitors",Ie="/sdk/v2/visitors",be="/sdk/v2/visitors/merge",Te="/api/v1/websdk/dlr",Se=18e5,Ce={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},Ne="/firebase-messaging-sw.js",De={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 Oe(t,i,n){var e=De[t],r=[];return i&&r.push(i),n&&r.push(n),r.length>0?"".concat(r.join("_"),"_").concat(e):e}var ke="websdk_storage_test",Ae="test_value",xe={REQUEST_TIMEOUT_MS:15e3,SENSITIVE_LOG_KEYS:["writeKey","token","accessToken","refreshToken","password"]},Re="INIT_ERROR",Pe="AUTH_ERROR",Me="NETWORK_ERROR",Ue="EVENT_ERROR",Le="VISITOR_CONFIG_ERROR",Fe="WebSDK initialized successfully",Ge="Failed to initialize WebSDK",Ve="WebSDK destroyed successfully",Be="Failed to destroy WebSDK",ze="Storage initialization failed",je="Failed to restore persisted page-path-tracking preference",He="Failed to restore persisted gamification-suppression preference",qe="Failed to restore persisted gamification theme",Ke="Session initialization failed",We="Visitor config initialization failed",Xe="Event tracker initialization failed",Ye="Failed to restore user context",Je="Failed to sync event tracker context",Qe="DLR setup failed",$e="EventQueue initialized successfully",Ze="EventTracker initialized successfully",tr="EventTracker destroyed successfully",ir="Event added to queue",nr="Failed to track event",er="Events sent successfully",rr="Failed to send events",sr="User event sent successfully",or="Failed to send user event",ur="Failed to send batch",ar="Starting queue processing",cr="Queue processing completed",hr="Queue processing failed",dr="Queue processing already in progress, skipping",fr="No pending events to process",lr="No more pending events",vr="Failed to mark event as processing",mr="Failed to remove events from storage",gr="Failed to initialize storage:",pr="Storage test failed:",wr="Storage read/write test failed",yr="StorageManager destroyed successfully",Er="Error during storage cleanup:",_r="New session started",Ir="Session continued",br="Session expired due to inactivity",Tr="Session ended on user switch (different user login)",Sr="Session ended on signout",Cr="Session restored from storage",Nr="Failed to track user signin event",Dr="Failed to track user signup event",Or="Failed to track user update event",kr="Failed to track user signout event",Ar="Failed to track behavioral event",xr="VisitorConfigManager initialized successfully",Rr="Visitor config fetched successfully",Pr="Failed to fetch visitor config",Mr="Visitor tracking is disabled",Ur="Visitor tracking is enabled",Lr="Visitor config retrieved from cache",Fr="AnonymousVisitorManager initialized successfully",Gr="Visitor ID generated successfully",Vr="Failed to generate visitor ID",Br="Visitor ID restored from storage",zr="Using cached visitor ID",jr="Visitor updated successfully",Hr="Failed to update visitor",qr="Visitor merged with user successfully",Kr="Failed to merge visitor with user",Wr="Visitor merge skipped",Xr="Notification permission denied by user",Yr="Notification manager initialized successfully",Jr="Failed to initialize notification manager",Qr="Notification initialization skipped (disabled or not supported)",$r="Firebase initialized successfully",Zr="Failed to initialize Firebase",ts="FCM token received successfully",is="FCM token refreshed",ns="Failed to retrieve FCM token",es="Service worker registered successfully",rs="Failed to register service worker",ss="Service worker not supported in this browser",os="FirebaseManager already initialized",us="FirebaseManager not initialized",as="No service worker found in registration",cs="Service worker registration required for FCM - no token obtained",hs="getToken() returned no token despite notifications being enabled - permission may have been revoked externally, VAPID key may be invalid, or this may be transient",ds="Failed to setup message listener",fs="FCM message payload has neither notification nor data",ls="onMessageReceived callback threw",vs="Notifications not supported in this browser",ms="Firebase Messaging instance not provided - notifications disabled",gs="Failed to restore notification state",ps="Failed to save notification state",ws="Failed to initialize Firebase for messaging",ys="Failed to store FCM token",Es="Failed to retrieve FCM token creation date",_s="Cannot refresh token - notifications not enabled",Is="Failed to refresh FCM token",bs="Failed to clear notification state",Ts="Permission revoked - clearing FCM token",Ss="Failed to destroy NotificationManager",Cs="DLR events sent successfully",Ns="Failed to send DLR events",Ds="web",Os="user_signin",ks="user_update",As="user_signout",xs="scroll_depth",Rs=[25,50,75,90],Ps=30,Ms=3e3,Us={WEBPUSH:"WEBPUSH"},Ls={WEB:"web"},Fs={ACCOUNT_NOT_EXISTS:2432,ACCOUNT_ID_NOT_PASSED:9999},Gs={ALREADY_MERGED:"1429",VISITOR_NOT_FOUND:"1428"},Vs={NOTIFICATION_RECEIVED:"push_notification_received",NOTIFICATION_CLICKED:"push_notification_click",NOTIFICATION_DISMISSED:"push_notification_close"},Bs="fcm",zs="push",js="1.10.7",Hs="GamificationManager initialized successfully",qs="Failed to initialize GamificationManager",Ks="GamificationManager destroyed successfully",Ws="GamificationManager state cleared",Xs="Gamification disabled — gamificationWriteKey not configured",Ys="GamificationManager refresh triggered",Js="GamificationManager data resync triggered",Qs="GamificationManager data resync failed",$s="GamificationManager loaded from cache — API call skipped",Zs="GamificationManager cache miss — fetching from API",to="GamificationManager reused cached token — token API call skipped",io="GamificationManager token cache miss — fetching new token",no="GamificationManager got an auth error on campaigns/entry points — invalidating cached token and retrying once",eo="GamificationManager token refetch is in backoff after repeated failures — skipping network call",ro="GamificationManager token refetch failed, entering backoff",so="GamificationManager failed to handle an ACTION_EVENT trigger",oo="Failed to persist gamification-suppression preference",uo="Content-initiated open skipped — gamification is suppressed",ao="Failed to persist gamification theme preference",co="Failed to read session-dismissal record",ho="Failed to persist session-dismissal record",fo="Failed to persist pending ACTION_EVENT queue",lo="Failed to restore pending ACTION_EVENT queue",vo="Entry point with unresolvable _id present in entryPointMap",mo="Failed to construct entry point instance",go="Expected a string field in analytics payload",po="Failed to persist gamification token cache",wo="Gamification token cache miss: failed to read/parse cached entry",yo="Gamification cache miss: no cached entry",Eo="Gamification cache miss: entry expired",_o="Gamification cache miss: failed to read/parse cached entry",Io="Failed to persist gamification cache",bo="Failed to read entry point count state",To="Failed to persist entry point count state",So="Failed to reconcile stale entry point state against refreshed server config",Co="GAME_PLAYED",No="CAMPAIGN_PLAY",Do="NO_GAME_CONFIGURED",Oo="game_open",ko="game_viewed",Ao="game_played",xo="game_completed",Ro="reward_seen",Po="content_open",Mo="content_viewed",Uo="LOYALTY",Lo="COMPLETED",Fo="ACTION_EVENT",Go=3e5,Vo=18e5,Bo="__GLU__CACHE__",zo="__GLU__TOKEN__",jo="__GLU__COUNT_DATE_",Ho="__GLU__QUEUE__",qo="__GLU__SESSION_DISMISSED_",Ko=16,Wo={LOGGED_IN:"loggedIn"},Xo={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"},Yo=1e3,Jo=16e3,Qo=2e3,$o=3e5,Zo="glu_cap_token",tu="glu_page_path_tracking_enabled",iu="glu_gamification_suppressed",nu="glu_gamification_theme",eu="/preload/",ru=5e3,su="__GLU__ORIGIN__",ou=new Set(xe.SENSITIVE_LOG_KEYS.map(function(t){return t.toLowerCase()}));function uu(t){return Array.isArray(t)?t.map(uu):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).map(function(t){var i=ge(t,2),n=i[0],e=i[1];return[n,ou.has(n.toLowerCase())?"[REDACTED]":uu(e)]})):t}var au=function(){function t(t,i){this.baseUrl=t.baseUrl.replace(/\/$/,""),this.logger=i}return t.prototype.request=function(t){return le(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={}),ve(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=uu(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:fe({"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:uu(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:Me,message:"Request timeout",details:t}:t.message.includes("HTTP 401")||t.message.includes("HTTP 403")?{code:Pe,message:"Authentication failed",details:t}:(t.message.includes("HTTP"),{code:Me,message:t.message,details:t}):{code:Me,message:"Unknown error: ".concat(String(t)),details:t}},t.prototype.get=function(t){return le(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),ve(this,function(n){return[2,this.request(t,fe(fe({},i),{method:"GET"}))]})})},t.prototype.post=function(t,i){return le(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),ve(this,function(e){return[2,this.request(t,fe(fe({},n),{method:"POST",body:i}))]})})},t.prototype.put=function(t,i){return le(this,arguments,void 0,function(t,i,n){return void 0===n&&(n={}),ve(this,function(e){return[2,this.request(t,fe(fe({},n),{method:"PUT",body:i}))]})})},t.prototype.delete=function(t){return le(this,arguments,void 0,function(t,i){return void 0===i&&(i={}),ve(this,function(n){return[2,this.request(t,fe(fe({},i),{method:"DELETE"}))]})})},t}(),cu="/user/v1/user/sdk",hu="/reward/v1.1/user",du="/entrypoints/v1/list",fu=function(){function t(t,i){this.http=new au({baseUrl:t},i),this.logger=i}return t.prototype.getToken=function(t,i,n,e,r){return le(this,void 0,void 0,function(){var s,o=this;return ve(this,function(u){return s=fe(fe(fe(fe(fe(fe({writeKey:t,userId:i,userState:n,appType:"WEB",sdkVersion:js},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 le(o,void 0,void 0,function(){var t;return ve(this,function(e){switch(e.label){case 0:return[4,this.http.post("".concat(cu,"?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 le(this,void 0,void 0,function(){var i=this;return ve(this,function(n){return this.logger.info("Fetching gamification campaigns"),[2,this.withRetry(function(){return le(i,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return[4,this.http.get(hu,{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 le(this,void 0,void 0,function(){var i=this;return ve(this,function(n){return this.logger.info("Fetching gamification entry points"),[2,this.withRetry(function(){return le(i,void 0,void 0,function(){var i;return ve(this,function(n){switch(n.label){case 0:return[4,this.http.get("".concat(du,"?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=me(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===Pe},t.prototype.withRetry=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(this,function(u){switch(u.label){case 0:e=function(e){var s,o,u;return ve(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(Yo*Math.pow(2,e-1),Jo),[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}(),lu={EMBEDDED:"EMBED",POP_UP:"POP_UP",BOTTOM_SHEET:"BOTTOM_SHEET",ICON_BUTTON:"FLOATING",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"BANNER"};function vu(t){var i,n=(i=t.container.typeId,lu[i]);return"EMBED"===n&&"STATIC"===t.content.typeId?"BANNER":n}function mu(t){return"CAMPAIGN"===t.typeId||"NUDGE"===t.typeId&&!!t.campaignId}function gu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId?"content":mu(t.content)?"game":"ICON_BUTTON"===t.container.typeId?"content":null}function pu(t){return"NATIVE_BANNER"===t.container.typeId||"EMBEDDED"===t.container.typeId}function wu(t){return t.toFixed(2)}function yu(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 Eu(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 _u(t){return t.triggerType===Fo}var Iu=new Set(["EMBEDDED","NATIVE_BANNER"]);function bu(t){var i;if(!_u(t))return null;if(Iu.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 Tu=new Set(["POP_UP","BOTTOM_SHEET","CHAT_BOX"]);function Su(t){return Tu.has(t.container.typeId)}var Cu=new Set(["http:","https:"]);function Nu(t){if(!t||"undefined"==typeof window)return!1;try{return Cu.has(new URL(t,window.location.href).protocol)}catch(t){return!1}}function Du(t){var i,n,e=t.content;if("CAMPAIGN"===e.typeId)return null!==(i=e.campaignId)&&void 0!==i?i:Eu(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 Eu(r.content.conditions)}return null}var Ou={LAUNCHER_ICON:"ICON_BUTTON",BOTTOM_SHEET:"BOTTOM_SHEET",POP_UP:"POP_UP",EMBEDDED:"EMBEDDED",CHAT_BOX:"CHAT_BOX",NATIVE_BANNER:"NATIVE_BANNER"};function ku(t){var i,n;if("string"==typeof t.p&&t.p.length>0)return t.p;try{for(var e=me(Object.entries(t)),r=e.next();!r.done;r=e.next()){var s=ge(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 Au(t,i){var n;return fe(fe(fe(fe(fe(fe(fe(fe(fe(fe({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 xu(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:Eu(null==c?void 0:c.conditions))&&void 0!==n?n:void 0;return fe(fe(fe(fe(fe(fe({id:null!==(e=ku(t))&&void 0!==e?e:""},void 0!==t.name&&{name:t.name}),{container:{typeId:null!==(r=Ou[o.typeId])&&void 0!==r?r:o.typeId,css:d,height:o.height,elementHookId:o.elementId},content:Au(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 Ru(t){var i,n,e=[],r={};try{for(var s=me(t),o=s.next();!o.done;o=s.next()){var u=xu(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 Pu="/*";function Mu(t){return t.startsWith("#/")||t.startsWith("#!/")}function Uu(t){try{return decodeURIComponent(t)}catch(i){return t}}function Lu(t){return t.replace(/(?:^\/+)|(?:\/+$)/g,"").split("/").filter(Boolean).map(Uu)}function Fu(t){try{return new URL(t)}catch(t){return null}}function Gu(t,i,n){for(var e=0;e<i.length;e++)if(t[n+e]!==i[e])return!1;return!0}function Vu(t,i){if(i.length>t.length)return-1;for(var n=0;n<=t.length-i.length;n++)if(Gu(t,i,n))return n;return-1}function Bu(t,i){var n=i.endsWith(Pu),e=n?i.slice(0,-2):i;if(""===e)return!1;if("/"===e)return!n&&0===t.length;var r=Lu(e),s=Vu(t,r);return-1!==s&&(!n||s+r.length<t.length)}function zu(t,i){var n=function(t){var i=t.trim();if("*"===i||i===Pu)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=Mu(s)?o+s:o;return u.test(a)}var c=function(t,i){if(!/^https?:\/\//i.test(t))return null;var n=Fu(i);if(!n)return!1;var e=t.endsWith(Pu),r=Fu(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=Lu(n.pathname),o=Lu(r.pathname),u=Vu(s,o);return 0===u&&u+o.length<s.length}(n,o);if(null!==c)return c;var h=Fu(t);return!!Bu(Lu(h?h.pathname:o),n)||!!Mu(s)&&Bu(Lu(s.replace(/^#!?\//,"").replace(/\?.*$/,"")),n)}function ju(t,i){var n,e;try{for(var r=me(i),s=r.next();!s.done;s=r.next()){if(zu(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 Hu(t,i){return"".concat(jo).concat(null!=i?i:"anonymous","_").concat(t)}function qu(t,i,n,e){return le(this,void 0,void 0,function(){var r,s,o;return ve(this,function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,n.get(Hu(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(bo,{entryPointId:t,error:o}),[2,null];case 3:return[2]}var a})})}var Ku=/^([01]\d|2[0-3]):[0-5]\d$/;function Wu(t,i,n){return i>=function(t,i){var n=ge(i&&Ku.test(i)?i.split(":").map(Number):[],2),e=n[0],r=void 0===e?0:e,s=n[1],o=void 0===s?0:s,u=new Date(t);return u.setHours(r,o,0,0),u>t&&u.setDate(u.getDate()-1),u}(t,n)}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||!ju(i,r))&&!(s.length&&!ju(i,s))}function Yu(t,i,n,e,r,s){return!n||!Wu(e,new Date(n.date),s)||(!(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 le(this,arguments,void 0,function(t,i,n,e,r,s){var o,u,a,c,h,d,f,l,v,m,g,p;return void 0===s&&(s=!0),ve(this,function(w){switch(w.label){case 0:return null===(o=t.conditions)?(e.info("Rule engine: conditions explicitly null - never show",{entryPointId:t.id}),[2,!1]):o?(u=o.paths,a=o.showCount,c=o.timeWindow,h=o.isLoggedIn,d=o.backendValidations,f=new Date,l=null!=r?r:"undefined"!=typeof window?window.location.href:"",h&&!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()}(c,f)?_u(t)||Xu(u,l)?"INVALID"===d?(e.info("Rule engine: backend validation invalid",{entryPointId:t.id}),[2,!1]):_u(t)?(e.info("Rule engine: frequency cap skipped for ACTION_EVENT entry",{entryPointId:t.id}),[2,!0]):a?s?(v=a.count,m=a.dailyRefresh,g=a.resetTime,[4,qu(t.id,i,n,e)]):(e.info("Rule engine: frequency cap skipped for already-open entry",{entryPointId:t.id}),[2,!0]):(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:l,paths:u}),[2,!1]):(e.info("Rule engine: outside time window",{entryPointId:t.id,timeWindow:c}),[2,!1])):(e.info("Rule engine: no conditions - always show",{entryPointId:t.id}),[2,!0]);case 1:return p=w.sent(),[2,m?Yu(t.id,v,p,f,e,g):Ju(t.id,v,p,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=me(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 _u(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:js,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=me(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:js,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 le(this,void 0,void 0,function(){return ve(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=me(Object.entries(i)),o=s.next();!o.done;o=s.next()){var u=ge(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=me(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=me(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=me(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 de(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 de(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=me(pe([],ge(_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 de(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 de(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 de(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 de(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=me(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=me(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=me(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+="&notLoggedIn=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=me(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,me(Object.entries(a))),d=h.next();!d.done;d=h.next()){var f=ge(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 de(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=me(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return ve(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 de(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=me(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=me(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 de(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=fe(fe({},i),{id:this.actionId});this.sdkEventListener({target:"GLU_SDK",action:n})}else{var e,r={target:"GLU_SDK",action:fe(fe({},i),{id:this.actionId,content:fe(fe({},i.content),{typeId:"ACCEPT_GUARD"}),container:fe(fe({},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 de(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:fe(fe({},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 de(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=pe([],ge(new Set(g.map(function(t){return t.step}))),!1).sort(function(t,i){return t-i});if(C.length>0){var N=ge(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:fe(fe({},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 de(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=pe([],ge(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:fe(fe({},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 de(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 de(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 de(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 de(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?fe(fe({},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 de(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=fe(fe(fe(fe({},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=fe({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(fe(fe({},o),{height:s.height}),i);case"BOTTOM_SHEET":return new ya(fe(fe({},o),{height:s.height}),i);case"NATIVE_BANNER":return new Oa(fe(fe({},o),{elementHookId:s.elementHookId}),i);case"EMBEDDED":return new Na(fe(fe({},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=me(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=yu(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&&Nu(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 fu(i,n),this.trackEvent=r,this.getSessionId=s}return t.prototype.initialize=function(t,i){return le(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 ve(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(Zo),this.loadFromCache(t)])];case 2:return e=ge.apply(void 0,[_.sent(),2]),r=e[0],s=e[1],n!==this.initGeneration?[2]:(r&&(this.capToken=r),s?(this.logger.info($s,{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(Zs),[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(Hs,{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(qs,o),null===(E=null===(y=this.callback)||void 0===y?void 0:y.onInitFailure)||void 0===E||E.call(y,{code:Re,message:qs,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(Zo,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(tu,String(t)).catch(function(){}),this.refresh()},t.prototype.restorePersistedPagePathTracking=function(){return le(this,void 0,void 0,function(){var t;return ve(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(tu)];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(iu,String(t)).catch(function(t){i.logger.error(oo,{error:t})}),n&&!t?this.refresh():!n&&t&&this.closeSuppressedInstances()},t.prototype.closeSuppressedInstances=function(){var t,i;try{for(var n=me(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(uo,{entryPointId:t.id,containerTypeId:t.container.typeId}),!0)},t.prototype.isGamificationSuppressed=function(){return this.suppressed},t.prototype.restorePersistedGamificationSuppressed=function(){return le(this,void 0,void 0,function(){var t;return ve(this,function(i){switch(i.label){case 0:return[4,this.storageManager.get(iu)];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(nu,i).catch(function(t){n.logger.error(ao,{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=me(this.instances),u=o.next();!u.done;u=o.next()){var a=ge(u.value,2),c=a[0],h=a[1],d=!!(v=null===(r=this.entryPointMap)||void 0===r?void 0:r.byId[c])&&pu(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=me(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 le(this,void 0,void 0,function(){var i;return ve(this,function(n){switch(n.label){case 0:return[4,this.storageManager.get(nu)];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?(Su(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(Ws),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=me(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=me(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(Zo).catch(function(){}),this.initialized=!1},t.prototype.destroy=function(){this.clean(),this.logger.info(Ks)},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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return ve(this,function(f){switch(f.label){case 0:if(!this.entryPointMap)return[2];t=this.resolveCurrentPath(),this.logger.info(Ys,{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=me(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])||_u(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&&pu(n)?n.container.elementHookId:null};return pe([],ge(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 le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h;return ve(this,function(d){switch(d.label){case 0:return e=Su(t),r=null===(a=t.conditions)||void 0===a?void 0:a.singleOpenName,!e&&r&&i[r]?[2]:(s=pu(t)?t.container.elementHookId:null)&&n[s]?[2]:!_u(t)&&this.isCampaignCompleted(t)?(this.closeIfOpen(t),[2]):[4,this.isDismissedThisSession(t)];case 1:return d.sent()?(this.cancelDelayedOpen(t.id),[2]):(o=this.isEffectivelySuppressed(t),u=null!==(h=null===(c=this.instances.get(t.id))||void 0===c?void 0:c.isOpen())&&void 0!==h&&h,[4,Qu(t,this.userId,this.storageManager,this.logger,this.resolveCurrentPath(),!u)]);case 2:return d.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&&!pu(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 le(this,void 0,void 0,function(){var i,n,e;return ve(this,function(r){switch(r.label){case 0:return(i=null===(e=this.entryPointMap)||void 0===e?void 0:e.byId[t])?!_u(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=Su(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&&(Su(t)&&this.openOverlayIds.add(t.id),i.open())},t.prototype.notifyCampaignOpened=function(t){var i,n,e=Du(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=me(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)||(!pu(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 le(this,void 0,void 0,function(){var r,s,o,u,a,c,h;return ve(this,function(d){switch(d.label){case 0:return _u(t)?[2]:(r=null===(c=t.conditions)||void 0===c?void 0:c.showCount)?(s=new Date,[4,qu(t.id,i,n,e)]):[2];case 1:o=d.sent(),u=!r.dailyRefresh||o&&Wu(s,new Date(o.date),r.resetTime)?{count:o?o.count+1:1,date:s.toISOString()}:{count:1,date:s.toISOString()},d.label=2;case 2:return d.trys.push([2,4,,5]),[4,n.set(Hu(t.id,i),JSON.stringify(u))];case 3:return d.sent(),e.info("Rule engine: display recorded",{entryPointId:t.id,shown:u.count,cap:r.count,remaining:Math.max(r.count-u.count,0),dailyRefresh:null!==(h=r.dailyRefresh)&&void 0!==h&&h}),[3,5];case 4:return a=d.sent(),e.error(To,{entryPointId:t.id,error:a}),[3,5];case 5:return[2]}})})})(t,this.userId,this.storageManager,this.logger).catch(function(n){i.logger.error(To,{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=Du(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(qo).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 le(this,void 0,void 0,function(){var i,n,e,r,s;return ve(this,function(o){switch(o.label){case 0:if(pu(t)||_u(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(co,{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&&!pu(e)&&!_u(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(ho,{entryPointId:t,error:i})})}}},t.prototype.queueStorageKey=function(t){return Ho+t},t.prototype.persistActionEventQueue=function(){var t=this;if(this.userId){var i=this.campaignQueue.entries().filter(function(t){return _u(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(fo,{error:i})}):this.storageManager.remove(n).catch(function(){})}},t.prototype.restorePersistedActionEventQueue=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h;return ve(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=me(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])&&_u(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(lo,{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(vo,{totalEntryPoints:this.entryPointMap.allIds.length});try{for(var e=me(this.entryPointMap.allIds),r=e.next();!r.done;r=e.next()){var s=r.value,o=this.entryPointMap.byId[s],u=o?bu(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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l;return ve(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:Do}),[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=me(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(so,{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=me(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&&(_u(u)||!this.isCampaignCompleted(u))&&(_u(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 le(this,void 0,void 0,function(){var t;return ve(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.storageManager.get(su)];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(eu),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()},ru);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(mo,{entryPointId:t,error:i}),null}},t.prototype.trackEntryPointOpen=function(t){var i,n,e,r=this,s=gu(t);if(s&&this.userId){if(this.markOpened(t.id),"game"===s){this.getOrCreateTrackingState(t.id).completionFired=!1;var o=Du(t),u={campaign_id:o,game_type:this.lookupGameType(o),entry_surface:null!==(i=vu(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(Oo,u)}else{u={page_id:t.container.elementHookId,content_surface:null!==(e=vu(t))&&void 0!==e?e:""};this.trackEvent(Po,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:Du(t)});var e=gu(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=Du(t);return{campaign_id:r,game_type:this.lookupGameType(r),load_time_ms:wu(n)}}return{page_id:t.container.elementHookId,content_surface:null!==(e=vu(t))&&void 0!==e?e:"",load_time_ms:wu(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&&Du(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,No))return this.trackGamePlayed(i),void this.trackRewardSeenIfPresent(t,i);if(this.matchesAnalyticsEventName(t,Co)){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[Xo.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&&mu(n.content)&&this.userId){var e=this.getOrCreateTrackingState(t);e.playedAt=Date.now(),e.completionFired=!1;var r=Du(n),s={campaign_id:r,game_type:this.lookupGameType(r)};this.trackEvent(Ao,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&&mu(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=Du(e),u={campaign_id:o,game_type:this.lookupGameType(o),total_time_ms:wu(s)};this.trackEvent(xo,u)}},t.prototype.trackRewardSeenIfPresent=function(t,i){if("object"==typeof t&&null!==t){var n=t[Xo.CAMPAIGN_DETAILS];if("object"==typeof n&&null!==n){var e=n,r=e[Xo.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,Xo.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,Xo.CAMPAIGN_ID),reward_type:this.readStringField(t,Xo.REWARD_TYPE)};this.trackEvent(Ro,r)}}},t.prototype.readStringField=function(t,i){var n=t[i];return void 0===n?null:"string"==typeof n?n:(this.logger.warn(go,{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:Uo};this.trackEvent(Po,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:Uo,load_time_ms:wu(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?ko:Mo,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(fe(fe({},null!==(p=w.data)&&void 0!==p?p:{}),((n={})[Xo.EVENT_NAME]=Co,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&&Nu(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)||(Su(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&&Nu(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=yu(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&&Nu(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&&Nu(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:fe({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=me(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 Bo+t},t.prototype.tokenCacheKey=function(t){return zo+t},t.prototype.loadTokenFromCache=function(t){return le(this,void 0,void 0,function(){var i,n,e;return ve(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>=Vo?[2,null]:[2,n.token]):[2,null];case 2:return e=r.sent(),this.logger.error(wo,{userId:t,error:e}),[2,null];case 3:return[2]}})})},t.prototype.saveTokenToCache=function(t,i){return le(this,void 0,void 0,function(){var n,e;return ve(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(po,{error:e}),[3,4];case 4:return[2]}})})},t.prototype.getOrFetchToken=function(t,i){return le(this,void 0,void 0,function(){var n,e;return ve(this,function(r){switch(r.label){case 0:return[4,this.loadTokenFromCache(t)];case 1:return(n=r.sent())?(this.logger.info(to),[2,n]):(this.logger.info(io),[4,this.apiClient.getToken(this.writeKey,t,Wo.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===Pe},t.prototype.ensureFreshToken=function(t){return le(this,void 0,void 0,function(){var i,n,e,r;return ve(this,function(s){switch(s.label){case 0:if(this.tokenRefetchInFlight)return[2,this.tokenRefetchInFlight];if(Date.now()<this.authBackoffUntil)throw this.logger.warn(eo,{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(Qo*Math.pow(2,this.authFailureCount-1),$o),this.authBackoffUntil=Date.now()+r,this.logger.error(ro,{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 le(this,void 0,void 0,function(){var n;return ve(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,Wo.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 le(this,void 0,void 0,function(){var n,e;return ve(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(no,{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 le(this,void 0,void 0,function(){var i,n,e;return ve(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>=Go?(this.logger.debug(Eo,{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(yo,{userId:t}),[2,!1]);case 2:return e=r.sent(),this.logger.error(_o,{userId:t,error:e}),[2,!1];case 3:return[2]}})})},t.prototype.saveToCache=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Io,{error:i}),[3,4];case 4:return this.allCampaignsMap.base&&this.storageManager.set(su,this.allCampaignsMap.base).catch(function(){}),[2]}})})},t.prototype.handleScreenChange=function(){return le(this,void 0,void 0,function(){return ve(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>=Go},t.prototype.resyncData=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return ve(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=ge.apply(void 0,[h.sent(),2]),r=e[0],s=e[1],n!==this.syncGeneration?[2]:(o=this.entryPointMap,this.allCampaignsMap=r,this.entryPointMap=Ru(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(Qs,u),[3,5];case 5:return[2]}})})},t.prototype.reconcileEntryPointState=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f,l=this;return ve(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(Hu(t,n)).catch(function(i){l.logger.error(So,{entryPointId:t,error:i})})},u=this;try{for(a=me(pe(pe([],ge(r),!1),ge(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,f,l,v,m,g=[],p=[];try{for(var w=me(t.allIds),y=w.next();!y.done;y=w.next()){var E=y.value,_=t.byId[E],I=i.byId[E];if(_)if(I){var b=null!==(o=null===(s=null===(r=_.conditions)||void 0===r?void 0:r.showCount)||void 0===s?void 0:s.dailyRefresh)&&void 0!==o&&o,T=null!==(c=null===(a=null===(u=I.conditions)||void 0===u?void 0:u.showCount)||void 0===a?void 0:a.dailyRefresh)&&void 0!==c&&c,S=null!==(f=null===(d=null===(h=_.conditions)||void 0===h?void 0:h.showCount)||void 0===d?void 0:d.resetTime)&&void 0!==f?f:"00:00",C=null!==(m=null===(v=null===(l=I.conditions)||void 0===l?void 0:l.showCount)||void 0===v?void 0:v.resetTime)&&void 0!==m?m:"00:00";(b!==T||T&&S!==C)&&p.push(E)}else g.push(E)}}catch(t){n={error:t}}finally{try{y&&!y.done&&(e=w.return)&&e.call(w)}finally{if(n)throw n.error}}return{removedIds:g,dailyRefreshChangedIds:p}},t.prototype.pruneSessionDismissalRecords=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h,d=this;return ve(this,function(f){switch(f.label){case 0:return f.trys.push([0,2,,3]),[4,this.storageManager.keys("".concat(qo).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,me(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(So,{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=me(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(So,{entryPointId:"all",error:a}),[3,3];case 3:return[2]}})})},t.prototype.fetchAndCache=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o;return ve(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=ge.apply(void 0,[u.sent(),2]),s=r[0],o=r[1],n!==this.initGeneration?[2,!1]:(this.allCampaignsMap=s,this.entryPointMap=Ru(o),this.buildEventIndex(),this.lastSyncTimestamp=Date.now(),this.saveToCache(),[2,n===this.initGeneration])}})})},t.prototype.isCampaignCompleted=function(t){var i,n,e,r=Du(t);if(!r||!this.allCampaignsMap)return!1;var s=this.allCampaignsMap.byId[r];if(!s)return!1;var o=Lo;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()},Ko)}});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 le(t,void 0,void 0,function(){return ve(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 au(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 le(this,void 0,void 0,function(){var o,u,a,c,h,d,f,l;return ve(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(we,h,{headers:d})];case 3:return f=v.sent(),this.logger.info(er,{requestId:h.request_id,eventCount:t.length,trackingMode:u,success:f.status.success}),[2,f];case 4:throw l=v.sent(),this.logger.error(rr,{requestId:h.request_id,eventCount:t.length,trackingMode:u,error:l}),l;case 5:return[2]}})})},t.prototype.getVisitorConfig=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s;return ve(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":Us.WEBPUSH},[4,this.httpClient.get(Ee,{headers:i})];case 2:return n=o.sent(),this.logger.info(Rr,{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(Pr,{orgId:t,error:e}),e;case 4:return[2]}})})},t.prototype.createVisitor=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(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(_e,i,{headers:n})];case 2:return e=u.sent(),this.logger.info(Gr,{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(Vr,{error:r,accountId:this.accountId}),r;case 4:return[2]}})})},t.prototype.updateVisitor=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a;return ve(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(Ie,"?identifierType=visitorId&identifierValue=").concat(encodeURIComponent(i)),[4,this.httpClient.put(r,n,{headers:e})];case 2:return s=c.sent(),this.logger.info(jr,{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(Hr,{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===Gs.ALREADY_MERGED)return void this.logger.info("Visitor already merged, treating as success",{visitorId:i});if(u===Gs.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(qr,{visitorId:i,statusCode:t.status.code,message:t.status.message})},t.prototype.mergeVisitor=function(t,i,n){return le(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 ve(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||Ls.WEB,_=[],u&&_.push({type:E,value:u,primary:!0,verified:!0,subscribed:h,accountId:this.accountId,attributes:{gateway:Bs,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(be,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(Kr,{visitorId:t,error:N}),N;case 5:return[2]}})})},t.prototype.buildUserEventsRequest=function(t,i,n){return le(this,void 0,void 0,function(){var e,r;return ve(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:fe(fe({},r),{os_name:Ds}),events:[{name:t,eventExternalId:ia(),eventDateTime:(new Date).toISOString(),attributes:i}]}]}})})},t.prototype.sendUserEvents=function(t,i,n,e,r){return le(this,void 0,void 0,function(){var s,o,u,a,c;return ve(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(ye,t,{headers:s})];case 2:return h.sent(),this.logger.info(sr,{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(or,{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 le(this,void 0,void 0,function(){var i,n,e,r,s;return ve(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(Te,t,{headers:i})];case 2:return n=o.sent(),this.logger.info(Cs,{requestId:t.request_id,eventCount:t.events.length,success:n.status.success}),[2,n];case 3:throw e=o.sent(),this.logger.error(Ns,{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 de(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 le(this,void 0,void 0,function(){var t=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var n,e=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var t,i=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.db&&(this.db.close(),this.db=null),[2]})})},t.prototype.addEvent=function(t){return le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=50),ve(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 le(this,void 0,void 0,function(){var r,s=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,void 0,void 0,function(){var i,n=this;return ve(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 le(this,arguments,void 0,function(t,i){var n,e=this;return void 0===i&&(i=5),ve(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||Ce.BATCH_SIZE,this.RETRY_DELAYS=e||Ce.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 le(this,void 0,void 0,function(){return ve(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($e),[2]}})})},t.prototype.setUserContext=function(t,i,n){return le(this,void 0,void 0,function(){var e;return ve(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 le(this,arguments,void 0,function(t,i){var n,e,r;return void 0===i&&(i=!1),ve(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:Ce.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(ir,{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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.isProcessing?(this.logger.debug(dr),[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=me(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 le(this,void 0,void 0,function(){var i=this;return ve(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 le(i,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c;return ve(this,function(h){switch(h.label){case 0:this.isProcessing=!0,this.logger.debug(ar),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(fr),[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=me(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(lr),[3,15]):[3,2];case 15:return[3,18];case 16:return u=h.sent(),this.logger.error(hr,{error:u}),[3,18];case 17:return this.isProcessing=!1,this.processingPromise=null,this.logger.debug(cr),[7];case 18:return[2]}})})},t.prototype.markEventsAsProcessing=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return ve(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=me(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(vr,{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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return ve(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(ur,{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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d,f,l,v;return ve(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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a;return ve(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 fe(fe({},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,Ce.DLR_SUCCESS_CODE)];case 3:return c.sent(),[2]}})})},t.prototype.removeSuccessfulEvents=function(t){return le(this,void 0,void 0,function(){var i,n;return ve(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(mr,{eventIds:i,error:n}),[3,4];case 4:return[2]}})})},t.prototype.handleBatchResponse=function(t,i){return le(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=Ce.GLOBAL_SUCCESS_CODE),ve(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!==Ce.PARTIAL_SUCCESS_CODE?[3,4]:[4,this.handlePartialSuccess(t,i.events)];case 3:return s.sent(),[3,8];case 4:return Ce.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 le(this,void 0,void 0,function(){var n,e,r,s,o,u,a,c,h;return ve(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=me(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),Ce.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 le(this,void 0,void 0,function(){var n,e,r;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return ve(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=me(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 Ce.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 le(this,void 0,void 0,function(){var i,n;return ve(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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u;return ve(this,function(a){switch(a.label){case 0:a.trys.push([0,7,8,9]),i=me(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 le(this,void 0,void 0,function(){return ve(this,function(t){switch(t.label){case 0:return[4,this.processQueueIfIdle()];case 1:return t.sent(),[2]}})})},t.prototype.destroy=function(){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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(Ze),[2]}})})},t.prototype.setUserContext=function(t,i,n){return le(this,void 0,void 0,function(){return ve(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 le(this,arguments,void 0,function(t,i){var n,e;return void 0===i&&(i=!1),ve(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(nr,{event:t,error:e}),new Error("".concat(Ue,": ").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=fe({},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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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(tr),[2]}})})},t.prototype.trackNotificationReceived=function(t){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var n,e;return ve(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:Vs.NOTIFICATION_RECEIVED,clicked:Vs.NOTIFICATION_CLICKED,dismissed:Vs.NOTIFICATION_DISMISSED},r=null===(n=this.eventQueue)||void 0===n?void 0:n.getCurrentCuid(),s={messageId:i.messageId,gateway:Bs,result:{received:"SUCCESS",clicked:"CLICKED",dismissed:"DISMISSED"}[t],notification_route:zs,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=zs,s.title=i.title||null),"clicked"===t&&(s.notification_id=i.messageId,s.campaign_id=i.campaignId||null,s.channel=zs,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 le(this,void 0,void 0,function(){var i;return ve(this,function(n){switch(n.label){case 0:switch(i=fe(fe(fe(fe(fe(fe({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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return ve(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=me(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 le(this,void 0,void 0,function(){var t=this;return ve(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 le(this,void 0,void 0,function(){var t=this;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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(gr,{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 le(this,void 0,void 0,function(){var i,n,e;return ve(this,function(r){switch(r.label){case 0:i=ke,n=Ae,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(wr);return[4,t.removeItem(i)];case 4:return r.sent(),[3,6];case 5:throw e=r.sent(),new Error("".concat(pr," ").concat(e));case 6:return[2]}})})},t.prototype.get=function(t){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(this,function(i){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.removeItem(t)]})})},t.prototype.clear=function(){return le(this,void 0,void 0,function(){return ve(this,function(t){if(!this.initialized)throw new Error("StorageManager not initialized");return[2,this.adapter.clear()]})})},t.prototype.keys=function(t){return le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t;return ve(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(yr),[3,5];case 4:return t=i.sent(),this.logger.error(Er,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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var i,n,e;return ve(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=fe(fe({},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,pe([],ge(u),!1));break;case sc.INFO:console.info.apply(console,pe([],ge(u),!1));break;case sc.WARN:console.warn.apply(console,pe([],ge(u),!1));break;case sc.ERROR:console.error.apply(console,pe([],ge(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 pe([],ge(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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i,n=this;return ve(this,function(e){switch(e.label){case 0:if(!this.initialized)throw new Error("VisitorConfigManager not initialized");if(this.cachedConfig)return this.logger.info(Lr),[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(Le,": ").concat(i));case 5:return[2]}})})},t.prototype.isVisitorTrackingEnabled=function(){return le(this,void 0,void 0,function(){var t,i,n,e;return ve(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(Ur):this.logger.info(Mr),[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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e,r;return ve(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:this.cachedConfig=null,n.label=1;case 1:return n.trys.push([1,3,,4]),t=Oe("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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){return ve(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(Fr),[2]}})})},t.prototype.getOrCreateVisitorId=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s;return ve(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(zr,{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(Gr,{visitorId:r}),[2,r]}})})},t.prototype.createVisitor=function(t,i){return le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(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=fe({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===Fs.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===Fs.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 le(this,void 0,void 0,function(){var n,e,r,s;return ve(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=fe({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===Fs.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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c,h,d;return ve(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(Wr,{reason:"Not initialized"}),[2,!1];if(!this.visitorId)return this.logger.warn(Wr,{reason:"No visitor ID"}),[2,!1];if(!e&&!r&&!s)return this.logger.warn(Wr,{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(Wr,{reason:"Visitor already merged",visitorId:c}),[2,!0]):[4,this.persistPendingMerge(c,h,fe(fe(fe(fe(fe(fe({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 le(this,void 0,void 0,function(){var t,i;return ve(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(Wr,{reason:"Already merged"}),[2];case 4:return t.attempts>=Ps?(this.logger.error(Kr,{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})})},Ms)},t.prototype.collectMergeContext=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u;return ve(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,fe(fe(fe(fe(fe(fe(fe(fe(fe(fe({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(qr,{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 le(this,void 0,void 0,function(){var n;return ve(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=fe(fe({},i),{attempts:i.attempts+1}),[4,this.savePendingMerge(n)];case 3:return e.sent(),n.attempts>=Ps?(this.logger.error(Kr,{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:Ps,nextRetryMs:Ms,visitorId:i.visitorId,error:t}),this.scheduleMergeRetry(),[2]}})})},t.prototype.persistPendingMerge=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d;return ve(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=fe(fe(fe(fe(fe(fe(fe(fe(fe({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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:this.cancelMergeRetryTimer(),n.label=1;case 1:return n.trys.push([1,3,,4]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),i=Oe("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 le(this,void 0,void 0,function(){var i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),this.expiredAt=t,i=Oe("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 le(this,void 0,void 0,function(){var t,i,n;return ve(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=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o;return ve(this,function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),t=Oe("VISITOR_ID",this.brandId,this.applicationId),[4,this.storageManager.get(t)];case 1:return(i=u.sent())&&(this.visitorId=i,this.logger.info(Br,{visitorId:i})),n=Oe("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),[4,this.storageManager.get(n)];case 2:return(e=u.sent())&&(this.visitorExternalId=e),r=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(this,function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),t=Oe("VISITOR_ID",this.brandId,this.applicationId),i=Oe("VISITOR_EXTERNAL_ID",this.brandId,this.applicationId),n=Oe("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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t;return ve(this,function(i){return(t=vc())?[2,t]:[2,import("firebase/app")]})})}function gc(){return le(this,void 0,void 0,function(){return ve(this,function(t){return[2,import("firebase/messaging")]})})}function pc(){return le(this,void 0,void 0,function(){var t;return ve(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||Ne,this.onTokenReceivedCallback=r,this.onMessageReceivedCallback=s}return t.prototype.initialize=function(){return le(this,void 0,void 0,function(){return ve(this,function(t){return this.isInitialized?(this.logger.warn(os),[2,!0]):this.messaging?(this.isInitialized=!0,this.logger.info($r),[2,!0]):(this.logger.error(Zr,new Error("Messaging instance missing")),[2,!1])})})},t.prototype.ensureServiceWorkerRegistered=function(){return le(this,void 0,void 0,function(){var t;return ve(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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:if(!("serviceWorker"in navigator))return this.logger.warn(ss),[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(es,{scope:i.scope}),[4,this.ensureServiceWorkerActive(i)];case 6:return e.sent(),[2,i];case 7:return n=e.sent(),this.logger.error(rs,n),[2,null];case 8:return[2]}})})},t.prototype.ensureServiceWorkerActive=function(t){return le(this,void 0,void 0,function(){var i,n=this;return ve(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(as),[2])})})},t.prototype.requestToken=function(){return le(this,void 0,void 0,function(){var t,i,n,e;return ve(this,function(r){switch(r.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(us),[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(cs),[2,null]);case 4:return(n=r.sent())?(this.currentToken=n,this.logger.info(ts,{token:n}),this.onTokenReceivedCallback&&this.onTokenReceivedCallback(n),[2,n]):(this.logger.error(hs),[2,null]);case 5:return e=r.sent(),this.logger.error(ns,{error:e}),[2,null];case 6:return[2]}})})},t.prototype.fetchFCMToken=function(t){return le(this,void 0,void 0,function(){var i,n;return ve(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 le(this,void 0,void 0,function(){var t,i=this;return ve(this,function(n){switch(n.label){case 0:if(!this.isInitialized||!this.messaging)return this.logger.error(us),[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(ds,{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(fs,t),this.onMessageReceivedCallback)try{this.onMessageReceivedCallback(t)}catch(t){this.logger.error(ls,{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(ms),!1):(this.logger.info(vs),!1)},t.prototype.restoreState=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r;return ve(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t=Oe("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=fe(fe(fe({},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(gs,{error:r}),[3,3];case 3:return[2]}})})},t.prototype.saveState=function(){return le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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(ps,{error:i}),[3,3];case 3:return[2]}})})},t.prototype.init=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Qr),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(Xr),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(Yr,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 le(this,void 0,void 0,function(){var t;return ve(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(ws,t),t;case 6:return[2]}})})},t.prototype.initializeFirebase=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Zr,i),this.state.firebaseInitialized=!1,this.state.isNotificationEnabled=!1,i;case 8:return[2]}})})},t.prototype.storeFCMToken=function(t){return le(this,void 0,void 0,function(){var i,n,e,r,s,o;return ve(this,function(u){switch(u.label){case 0:return u.trys.push([0,6,,7]),i=Oe("FCM_TOKEN",this.brandId,this.applicationId),n=Oe("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(ys,{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 fe({},this.state)},t.prototype.getFCMToken=function(){return this.state.fcmToken||null},t.prototype.getTokenCreationDate=function(){return le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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(Es,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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:if(!this.firebaseManager||!this.state.isNotificationEnabled)return this.logger.info(_s),[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(is,{token:t}),n.label=5;case 5:return[2,t];case 6:return i=n.sent(),this.logger.error(Is,i),[2,null];case 7:return[2]}})})},t.prototype.clearToken=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(bs,i),i;case 3:return[2]}})})},t.prototype.hasPermissionChanged=function(){return this.getPermissionStatus()!==this.state.permissionStatus},t.prototype.handlePermissionChange=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(Ts),[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(ms),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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.firebaseManager&&(this.firebaseManager.destroy(),this.firebaseManager=null),t=Oe("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(Ss,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=Se/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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i;return ve(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(Ir,{sessionId:this.currentSession.sessionId,inactivityDuration:i}),[2,this.currentSession.sessionId];case 2:this.logger.info(br,{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 le(this,arguments,void 0,function(t){return void 0===t&&(t=0),ve(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 le(this,void 0,void 0,function(){return ve(this,function(i){switch(i.label){case 0:return this.currentSession?(this.logger.info("user_switch"===t?Tr:Sr,{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 le(this,void 0,void 0,function(){return ve(this,function(t){return this.logger.info("Destroying SessionManager (session persists in storage)"),this.currentSession=null,[2]})})},t.prototype.startNewSession=function(){return le(this,void 0,void 0,function(){var t,i;return ve(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(_r,{sessionId:i,sessionStartTime:t,sessionNumber:this.sessionNumber}),[2,i]}})})},t.prototype.restoreSession=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a;return ve(this,function(c){switch(c.label){case 0:return c.trys.push([0,7,,9]),t=Oe("SESSION_ID",this.brandId,this.applicationId),i=Oe("SESSION_START_TIME",this.brandId,this.applicationId),n=Oe("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(Cr,{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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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=Oe("SESSION_ID",this.brandId,this.applicationId),i=Oe("SESSION_START_TIME",this.brandId,this.applicationId),n=Oe("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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),t=Oe("SESSION_ID",this.brandId,this.applicationId),i=Oe("SESSION_START_TIME",this.brandId,this.applicationId),n=Oe("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 le(this,void 0,void 0,function(){var t,i,n;return ve(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Oe("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 le(this,void 0,void 0,function(){var t,i;return ve(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),t=Oe("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=Rs}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=me(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._?(new dc(!0).warn("WebSDK is already initialized. Returning existing instance."),t._):(t._=new t(i),t._.init(),t._)},t.getInstance=function(){return t._},t.isInitialized=function(){return null!==t._},t.requireInstance=function(){if(!t._)throw new Error("WebSDK is not initialized. Call WebSDK.initialize(config) first.");return t._},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._)return Promise.resolve();var i=t._.destroy();return t._=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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a=this;return ve(this,function(c){switch(c.label){case 0:return c.trys.push([0,5,,6]),t=Oe("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 le(this,void 0,void 0,function(){var i;return ve(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 Oe("LAST_AUTHENTICATED_USER",this.config.brandId,this.config.applicationId)},t.prototype.persistLastAuthenticatedUser=function(t){return le(this,void 0,void 0,function(){var i;return ve(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 le(this,void 0,void 0,function(){var e,r,s,o;return ve(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=Oe("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(Ge,i),t.initializationPromise=null}))},t.prototype.tryStep=function(t,i){return le(this,void 0,void 0,function(){var n;return ve(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 le(this,void 0,void 0,function(){var t,i,n=this;return ve(this,function(e){switch(e.label){case 0:this.logger.info("Initializing WebSDK",{version:js,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(Re,": ").concat(t));case 4:return[4,this.tryStep(ze,function(){return n.storageManager.init()})];case 5:return e.sent(),[4,this.tryStep(je,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(He,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(qe,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(Ke,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(We,function(){return n.initializeVisitorConfig()})];case 14:return e.sent(),[4,this.tryStep(Xe,function(){return le(n,void 0,void 0,function(){var t=this;return ve(this,function(i){switch(i.label){case 0:return[4,this.eventTracker.init()];case 1:return i.sent(),this.eventTracker.setSessionInfoCallback(function(){return le(t,void 0,void 0,function(){return ve(this,function(t){return[2,this.sessionManager.getOrCreateSession()]})})}),[2]}})})})];case 15:return e.sent(),[4,this.tryStep(Ye,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 _c(this.logger,function(t){n.pushEvent(xs,n.buildInternalEventAttributes(fe({},t)))}),this.scrollDepthTracker.init(),this.config.notifications?[4,this.tryStep(Qe,function(){return le(n,void 0,void 0,function(){return ve(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(Fe),[2]}})})},t.prototype.handleVisibilityChange=function(){return le(this,void 0,void 0,function(){var t,i,n;return ve(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 le(t,void 0,void 0,function(){var t;return ve(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 le(this,void 0,void 0,function(){var t,i,n=this;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h;return ve(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(fe(fe({},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 le(t,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var n,e,r;return ve(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 le(this,void 0,void 0,function(){return ve(this,function(i){switch(i.label){case 0:return this.lastAuthenticatedUser?[4,this.sendUserEventToApi(ks,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 le(this,void 0,void 0,function(){var n,e,r,s,o;return ve(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(fe(fe({},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 le(this,void 0,void 0,function(){var n,e,r,s;return ve(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 le(this,void 0,void 0,function(){var i,n,e,r;return ve(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=Oe("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=fe(fe(fe(fe(fe({},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=fe(fe(fe(fe(fe({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=fe(fe({},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 le(this,arguments,void 0,function(t,i){return void 0===i&&(i=!1),ve(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 le(this,void 0,void 0,function(){var t;return ve(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(Ve),[3,17];case 16:throw t=i.sent(),this.logger.error(Be,{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 le(this,void 0,void 0,function(){var e,r,s;return ve(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(fe(fe(fe(fe(fe(fe({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(Wr,{reason:"No email, mobile, or externalId"}),[2,!1]):(this.logger.debug(Wr,{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(Kr,{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:Ls.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 le(this,void 0,void 0,function(){var r,s,o,u,a,c,h,d,f,l,v,m;return ve(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,fe(fe(fe({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 le(e,void 0,void 0,function(){var e;return ve(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(Nr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSigninAsync=function(t,i,n){return le(this,void 0,void 0,function(){var e,r,s,o,u,a,c,h,d,f=this;return ve(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(Os,t,i,fe(fe({},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=fe(fe(fe({},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 le(e,void 0,void 0,function(){var e;return ve(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(Dr,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserSignupAsync=function(t,i,n){return le(this,void 0,void 0,function(){return ve(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(Os,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 le(e,void 0,void 0,function(){var e;return ve(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(Or,{cuid:t,error:e}),[3,3];case 3:return[2]}})})})},t.prototype.pushUserUpdateAsync=function(t,i,n){return le(this,void 0,void 0,function(){return ve(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(ks,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 le(i,void 0,void 0,function(){var i;return ve(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(kr,{cuid:t,error:i}),[3,3];case 3:return[2]}})})})},t.prototype.resetToAnonymousMode=function(){return le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d,f,l;return ve(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(fe(fe({},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 le(this,void 0,void 0,function(){var i,n,e,r,s,o,u,a,c;return ve(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(As,t,this.lastUserAttributes,fe(fe({},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 fe(fe(fe({},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(Ar,{eventName:t,error:i})})},t.prototype.pushGamificationEvent=function(t,i){var n=this,e=fe(fe({},this.userIdentified&&this.lastAuthenticatedUser&&{cuid:this.lastAuthenticatedUser}),i);this.pushEventAsync(t,e,!0).catch(function(i){n.logger.error(Ar,{eventName:t,error:i})})},t.prototype.pushEventAsync=function(t,i){return le(this,arguments,void 0,function(t,i,n){var e,r;return void 0===n&&(n=!1),ve(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=fe({},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||Ls.WEB},t.prototype.applyConfigDefaults=function(){this.config.source=this.config.source||Us.WEBPUSH,this.config.channelType=this.config.channelType||Ls.WEB;var t=Se/6e4;this.config.sessionTimeoutMinutes=this.config.sessionTimeoutMinutes||t,this.config.batchSize=this.config.batchSize||Ce.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 le(this,void 0,void 0,function(){return ve(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 le(this,void 0,void 0,function(){var t,i,n,e;return ve(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(fe(fe({},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||Us.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,fe(fe({},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(Xs)},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 le(this,void 0,void 0,function(){var t,i,n,e,r,s,o,u,a,c,h,d;return ve(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 le(this,void 0,void 0,function(){var t;return ve(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 le(this,void 0,void 0,function(){return ve(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._=null,t}();exports.HydraSDK=Ic,exports.default=Ic;