import{aJ as q,aK as O}from"./index-BTl5Gysz.js";import{g as Xe,e as Je}from"./react-CRjHcyn1.js";import{v as B}from"./utils-CsLaO2iZ.js";import"./vendors-G61NC5D4.js";import"./analytics-e_U0oswF.js";import"./dateTime-BHGoDcSC.js";import"./ui-BcmfUO8P.js";import"./media-CbS6VBpW.js";import"./icons-Cmqfkpn_.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="ac067f10-a068-4aa6-aae3-abd10901729e",e._sentryDebugIdIdentifier="sentry-dbid-ac067f10-a068-4aa6-aae3-abd10901729e")}catch{}})();var E;(function(e){e.MessageOpened="in-app:message-opened",e.MessageDismissed="in-app:message-dismissed",e.MessageError="in-app:message-error",e.MessageAction="in-app:message-action"})(E||(E={}));var fe=Object.values(E),I;(function(e){e.Metric="Report Delivery Event",e.Content="Report Content Event",e.Opened="opened",e.Clicked="clicked",e.ViewedContent="viewed_content",e.ClickedContent="clicked_content"})(I||(I={}));var ge="in_app_content";function X(e,t){return new CustomEvent(e,{detail:t})}function Ke(e){switch(e){case"messageShown":return E.MessageOpened;case"messageDismissed":return E.MessageDismissed;case"messageError":return E.MessageError;case"messageAction":return E.MessageAction;default:return""}}class Ye{on(t,n){var i=this[t];i?i.push(n):this[t]=[n]}dispatch(t,n){var i=this[t];i&&i.forEach(o=>o(n))}}function a(e){u.config.logging&&console.log(`Gist: ${e}`)}const Ze=365,Z="gist.web.isPersistingSession";function et(e){sessionStorage.setItem(Z,e)}function v(e,t,n=null){var i=n;i||(i=new Date,i.setDate(i.getDate()+Ze));const o={value:t,expiry:i};ie().setItem(e,JSON.stringify(o))}function m(e){const t=ie().getItem(e);if(!t)return null;const n=JSON.parse(t);return new Date().getTime()>new Date(n.expiry).getTime()?(M(e),null):n.value}function M(e){ie().removeItem(e)}function Ie(){const e=sessionStorage.getItem(Z);return e===null?(sessionStorage.setItem(Z,"true"),!0):e==="true"}function ie(){return Ie()?localStorage:sessionStorage}const he="gist.web.userQueueVersion",me="gist.web.userQueueUseSSE",pe="gist.web.activeSSEConnection",g={RENDERER_HOST:"https://code.gist.build",ENGINE_API_ENDPOINT:{prod:"https://engine.api.gist.build",dev:"https://engine.api.dev.gist.build",local:"http://engine.api.local.gist.build:82"},GIST_QUEUE_API_ENDPOINT:{prod:"https://gist-queue-consumer-api.cloud.gist.build",dev:"https://gist-queue-consumer-api.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_QUEUE_V3_API_ENDPOINT:{prod:"https://consumer.cloud.gist.build",dev:"https://consumer.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_QUEUE_REALTIME_API_ENDPOINT:{prod:"https://realtime.cloud.gist.build",dev:"https://realtime.cloud.dev.gist.build",local:"http://api.local.gist.build:3000"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/3.0",dev:"https://renderer.gist.build/3.0",local:"http://app.local.gist.build:8080/web"},getQueueAPIVersion:function(){return m(he)??"2"},setQueueAPIVersion:function(e){v(he,e,new Date(new Date().getTime()+18e5)),a(`Set user queue version to "${e}"`)},useSSE:function(){return m(me)??!1},setUseSSEFlag:function(e){v(me,e,new Date(new Date().getTime()+6e4)),a(`Set user uses SSE to "${e}"`)},setActiveSSEConnection:function(){v(pe,!0,new Date(new Date().getTime()+31e3))},hasActiveSSEConnection:function(){return m(pe)??!1}};function V(){const e=g.getQueueAPIVersion()==="3"?g.GIST_QUEUE_V3_API_ENDPOINT[u.config.env]:g.GIST_QUEUE_API_ENDPOINT[u.config.env],t={"X-CIO-Site-Id":u.config.siteId,"X-CIO-Client-Platform":"web"},n=Le();n!=null&&(t["X-Gist-Encoded-User-Token"]=n);async function i(o,r={}){var L;const p=e+o,l=new AbortController,C=setTimeout(()=>l.abort(),5e3);try{const f=await fetch(p,{method:r.method||"GET",headers:{...t,...r.headers||{}},body:r.method&&r.method.toUpperCase()!=="GET"?r.body:void 0,signal:l.signal});clearTimeout(C);const d=((L=f.headers.get("content-type"))==null?void 0:L.includes("application/json"))?await f.json():await f.text(),c=Object.fromEntries(f.headers.entries());if(f.status<200||f.status>=400)throw{response:{status:f.status,data:d,headers:c}};return{status:f.status,headers:c,data:d}}catch(f){throw clearTimeout(C),f.response||(f.response={status:0,data:f.message||"Unknown error"}),f}}return i.post=(o,r={},p={})=>i(o,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json",...p.headers||{}}}),i}const ee="gist.web.userLocale";function tt(){return m(ee)!==null?m(ee):navigator.language}function nt(e){v(ee,e),a(`Set user locate to "${e}"`)}const it=600;var J=it,K=!1;const G="gist.web.userQueueNextPullCheck",ve="gist.web.sessionId";async function st(){var e;try{if(!K){K=!0;var t={"X-Gist-User-Anonymous":ae(),"Content-Language":tt()};if(g.getQueueAPIVersion()==="3")e=await V().post(`/api/v3/users?sessionId=${Ee()}`,{},{headers:t});else{var n=new Date().getTime();e=await V().post(`/api/v2/users?timestamp=${n}`,{},{headers:t})}}}catch(i){i.response?e=i.response:a(`Error getting user queue: ${i}`)}finally{K=!1,rt(e),at(e),ot(e)}return e}function at(e){if(e&&e.headers){var t=e.headers["x-cio-queue-version"];t&&g.setQueueAPIVersion(t)}}function ot(e){var n,i;const t=((i=(n=e==null?void 0:e.headers)==null?void 0:n["x-cio-use-sse"])==null?void 0:i.toLowerCase())==="true";g.setUseSSEFlag(t)}function Ee(){var e=m(ve);return e||(e=B()),v(ve,e,new Date(new Date().getTime()+18e5)),e}function rt(e){if(e&&e.headers){var t=e.headers["x-gist-queue-polling-interval"];t&&t>0&&(J=t)}var n=new Date(new Date().getTime()+J*1e3);v(G,J,n)}function ut(){var e=Le();return e===null?(a("No user token available for SSE endpoint."),null):g.GIST_QUEUE_REALTIME_API_ENDPOINT[u.config.env]+`/api/v3/sse?userToken=${e}&siteId=${u.config.siteId}&sessionId=${Ee()}`}const H="gist.web.userToken",se="gist.web.usingGuestUserToken",we="gist.web.guestUserToken",dt=30;function ae(){return m(se)!==null}function R(){return m(H)}function ct(e,t){t===void 0&&(t=new Date,t.setDate(t.getDate()+dt)),v(H,e,t),ae()&&(M(G),M(se)),a(`Set user token "${e}" with expiry date set to ${t}`)}function Se(){if(R()===null){var e=m(we);e==null&&(e=B(),v(we,e),a(`Set guest user token "${e}" with expiry date set to 1 year from today`)),v(H,e),v(se,!0),a(`Using anonymous session with token: "${e}"`)}}function lt(){return ae()}async function F(){var e=R();return e===null?null:await gt(e)}function Le(){var e=R();return e===null?null:btoa(e)}function ft(){M(H),a("Cleared user token")}async function gt(e){const n=new TextEncoder().encode(e),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(p=>p.toString(16).padStart(2,"0")).join("")}async function ht(e){try{var t=await V().post(`/api/v1/logs/queue/${e}`);return t}catch(n){return n.response}}async function mt(e){try{var t=await V().post(`/api/v1/logs/message/${e}`);return t}catch(n){return n.response}}function D(e){var i;const t={isEmbedded:!1,elementId:"",hasRouteRule:!1,routeRule:"",position:"",hasPosition:!1,shouldScale:!1,campaignId:null,messageWidth:414,overlayColor:"#00000033",persistent:!1,exitClick:!1,hasCustomWidth:!1},n=(i=e==null?void 0:e.properties)==null?void 0:i.gist;return n?{isEmbedded:!!n.elementId,elementId:n.elementId||"",hasRouteRule:!!n.routeRuleWeb,routeRule:n.routeRuleWeb||"",position:n.position||"",hasPosition:!!n.position,shouldScale:!!n.scale,campaignId:n.campaignId??null,messageWidth:n.messageWidth>0?n.messageWidth:t.messageWidth,hasCustomWidth:n.messageWidth>0,overlayColor:n.overlayColor||t.overlayColor,persistent:!!n.persistent,exitClick:!!n.exitClick}:t}function pt(e,t,n){var i=800;t.messageWidth>i&&(i=t.messageWidth);var o=` <div id="gist-embed"> <style> #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right { position: fixed; top: 0px; z-index: 1000000; } #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right { position: fixed; bottom: 0px; z-index: 1000000; } #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom { left: 50%; transform: translate(-50%, 0%); } #x-gist-floating-top-right, #x-gist-floating-bottom-right { right: 0px; } #gist-embed { position: relative; height: 100%; width: 100%; } #gist-embed-container { position: relative; height: 100%; width: 100%; } #gist-embed-container .gist-frame { height: 100%; width: 100%; border: none; } #x-gist-top.${e}, #x-gist-bottom.${e}, #x-gist-floating-top.${e}, #x-gist-floating-bottom.${e}, #x-gist-floating-top-left.${e}, #x-gist-floating-top-right.${e}, #x-gist-floating-bottom-left.${e}, #x-gist-floating-bottom-right.${e} { transition: height 0.1s ease-in-out; } @media (max-width: ${i}px) { #x-gist-top.${e}, #x-gist-bottom.${e}, #x-gist-floating-top.${e}, #x-gist-floating-bottom.${e}, #x-gist-floating-top-left.${e}, #x-gist-floating-top-right.${e}, #x-gist-floating-bottom-left.${e}, #x-gist-floating-bottom-right.${e} { width: 100% !important; } } </style> <div id="gist-embed-container"> <iframe id="${e}" class="gist-frame" src="${n}"></iframe> </div> </div>`;return o}function vt(e,t,n){var i=600;t.messageWidth>i&&(i=t.messageWidth);var o=` <div id="gist-embed-message"> <style> #gist-overlay.gist-background { position: fixed; z-index: 9999999998; left: 0; top: 0; width: 100%; height: 100%; background-color: ${t.overlayColor}; visibility: hidden; } #gist-overlay.gist-background.gist-visible { visibility: visible; } .gist-message { width: ${t.messageWidth}px; position: absolute; border: none; opacity: 0; transition: opacity 0.3s ease-in-out, height 0.1s ease-in-out; z-index: 9999999999; left: 50%; transform: translateX(-50%); } .gist-message.gist-visible { opacity: 1; pointer-events: auto; } .gist-message.gist-center { transform: translate(-50%, -50%); top: 50%; } .gist-message.gist-bottom { bottom: 0; } .gist-message.gist-top { top: 0; } @media (max-width: ${i}px) { .gist-message { width: 100%; } } </style> <div id="gist-overlay" class="gist-background"> <iframe id="${e}" class="gist-message" src="${n}"></iframe> </div> </div>`;return o}var $e=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function wt(e){const t=document.createElement("div");switch(t.id=e,e){case"x-gist-top":document.body.insertBefore(t,document.body.firstChild);break;default:document.body.insertAdjacentElement("beforeend",t);break}a("Top & bottom elements injected into page")}const St=e=>new Promise(t=>setTimeout(t,e)),yt=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function bt(e){var t=N(e);return!!(t&&t.classList.contains("gist-visible"))}function It(e,t,n,i){var o=N(e);if(o){var r=U(n.instanceId);o.classList.add(r);var p=D(n),l=p.messageWidth+"px";yt.includes(e)&&!p.hasCustomWidth&&(l="100%"),$e.includes(e)&&(o.style.width=l),Te(e)||(o.style.height="0px"),o.innerHTML=Pt(t,n,p),xe(r,i)}else a(`Message could not be embedded, elementId ${e} not found.`)}function Et(e){var t=N(e);t&&t.classList.add("gist-visible")}function Lt(e){var t=N(e);t&&(t.classList.remove("gist-visible"),t.style.removeProperty("height"),t.innerHTML="")}function Te(e){var t=N(e);if(t)return t.style&&t.style.height&&t.style.height!="0px"}function $t(e,t){var n=e.elementId?e.elementId:U(e.instanceId),i=N(n);if(i){var o=i.style;if(t.height>0)if(t.height>window.innerHeight){var r=1-(t.height/window.innerHeight-1);e.shouldScale&&r>=.4?(o.height=`${t.height}px`,o.transform=`translateX(-50%) translateY(-50%) scale(${r})`):o.height=`${window.innerHeight}px`}else o.height=`${t.height}px`}}function Tt(e,t,n){document.body.insertAdjacentHTML("afterbegin",Mt(e,t)),xe(U(t.instanceId),n)}function xe(e,t){const n=document.getElementById(e);n&&(n.onload=function(){xt(e,t)})}function xt(e,t){const n=document.getElementById(e);n&&n.contentWindow&&n.contentWindow.postMessage({options:t},"*")}function kt(e){var t=D(e),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");var i=document.querySelector(".gist-message");e.position?i.classList.add("gist-"+e.position):i.classList.add("gist-center"),setTimeout(Ct,100),t.exitClick&&setTimeout(()=>_t(e.instanceId),1e3)}else oe()}function _t(e){var t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",function(){u.dismissMessage(e)})}async function Dt(){var e=document.querySelector(".gist-message");e&&(e.classList.remove("gist-visible"),await St(300)),oe()}function oe(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function Nt(e,t){var n=N(U(e));n&&(n.title=t)}function U(e){return`gist-${e}`}function Ct(){var e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function Pt(e,t,n){var i=pt(U(t.instanceId),n,e);return i}function Mt(e,t){var n=D(t),i=vt(U(t.instanceId),n,e);return i}function N(e){try{var t=document.querySelector(`#${e}`);return t||null}catch{return null}}const Ut="gist.web.message.broadcasts",At=30;async function ke(e){const t=await z();if(!t)return;const n=new Date;n.setDate(n.getDate()+At);const i=e.filter(j);v(t,i,n)}async function qt(){const e=await z();return e?(m(e)??[]).filter(n=>{const{broadcast:i}=n.properties.gist,o=m(re(e,n.queueId))??!0,r=m(De(e,n.queueId))||0,p=i.frequency.count===0;return o&&(p||r<i.frequency.count)}):[]}async function Ot(e){a(`Marking broadcast ${e} as seen.`);const t=await z();if(!t)return;const n=await _e(t,e);if(!n)return;const{broadcast:i}=n.properties.gist,o=De(t,e),r=re(t,e);let p=m(o)||0;if(v(o,p+1),i.frequency.count===1)v(r,!1),a(`Marked broadcast ${e} as seen.`);else{let l=new Date;l.setSeconds(l.getSeconds()+i.frequency.delay),v(r,!1,l),a(`Marked broadcast ${e} as seen, broadcast was seen ${p+1} times, next show date is ${l}.`)}}async function Rt(e){a(`Marking broadcast ${e} as dismissed.`);const t=await z();if(!t)return;const n=await _e(t,e);if(!n)return;const{broadcast:i}=n.properties.gist;if(i.frequency.ignoreDismiss===!0){a(`Broadcast ${e} is set to ignore dismiss.`);return}const r=re(t,e);v(r,!1),a(`Marked broadcast ${e} as dismissed and will not show again.`)}async function _e(e,t){return m(e).find(i=>i.queueId===t)}function j(e){return e.properties&&e.properties.gist&&e.properties.gist.broadcast}function Qt(e){if(!j(e))return!1;const{broadcast:t}=e.properties.gist;return t.frequency.delay===0&&t.frequency.count===0}async function z(){const e=await F();return e?`${Ut}.${e}`:null}function De(e,t){return`${e}.${t}.numberOfTimesShown`}function re(e,t){return`${e}.${t}.shouldShow`}const ue="gist.web.message.user",Vt=6e4*60;async function Ne(e){const t=await Ce();if(!t)return;const n=e.filter(o=>!(o.properties&&o.properties.gist&&o.properties.gist.broadcast)),i=new Date(Date.now()+Vt);v(t,n,i)}async function Wt(){const e=await Ce();if(!e)return[];const t=m(e)??[],n=await jt();return t.filter(i=>!n.includes(i.queueId))}async function Bt(e){const t=await Pe();if(!t)return;const n=m(t)??[];n.push(e),v(t,n)}async function Gt(e){const t=await de(e);return t?m(t)!==null:!1}async function Ht(e){const t=await de(e);if(!t)return!1;v(t,!0,new Date(Date.now()+5e3))}async function Ft(e){const t=await de(e);if(!t)return!1;M(t)}async function jt(){const e=await Pe();return e?m(e)??[]:[]}async function Ce(){const e=await F();return e?`${ue}.${e}`:null}async function Pe(){const e=await F();return e?`${ue}.${e}.seen`:null}async function de(e){const t=await F();return t?`${ue}.${t}.message.${e}.loading`:null}async function Me(e){if(u.isDocumentVisible){if(u.overlayInstanceId)return a(`Message ${u.overlayInstanceId} already showing.`),null;var t=D(e);return e.instanceId=B(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=new Date().getTime(),u.overlayInstanceId=e.instanceId,u.currentMessages.push(e),Re(e)}else return a("Document hidden, not showing message now."),null}async function Ue(e,t){return u.isDocumentVisible?(e.instanceId=B(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!Te(t),e.renderStartTime=new Date().getTime(),u.currentMessages.push(e),Re(e,t)):(a("Document hidden, not showing message now."),null)}async function te(e){e?(u.messageDismissed(e),e.overlay?await Oe(!0,e):qe(e)):a(`Message with instance id: ${e.instanceId} not found`)}async function Ae(e){var t=D(e);e?t.persistent&&(a("Persistent message dismissed, logging view"),await Ge(e),await Qe(e)):a(`Message with instance id: ${e.instanceId} not found`)}function qe(e){ce(e.instanceId),Lt(e.elementId)}async function Oe(e,t){e?await Dt():oe(),u.currentMessages.length==0&&(window.removeEventListener("message",Be),window.removeEventListener("touchstart",We)),ce(t.instanceId),u.overlayInstanceId=null}function Re(e,t=null){if(t&&bt(t))return a(`Message ${e.messageId} already showing in element ${t}.`),null;var n={endpoint:g.ENGINE_API_ENDPOINT[u.config.env],siteId:u.config.siteId,dataCenter:u.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties},i=`${g.GIST_VIEW_ENDPOINT[u.config.env]}/index.html`;return window.addEventListener("message",Be),window.addEventListener("touchstart",We),t?($e.includes(t)&&wt(t),It(t,i,e,n)):Tt(i,e,n),e}async function Qe(e){a(`Message shown, logging view for: ${e.messageId}`);var t={};e.queueId!=null?(await Ge(e),t=await ht(e.queueId)):t=await mt(e.messageId),t.status===200?a("Message view logged"):a(`Problem logging message: ${t.status}`)}function Ve(e){return u.currentMessages.find(t=>t.instanceId===e)}function ce(e){u.currentMessages=u.currentMessages.filter(t=>t.instanceId!==e)}function ye(e,t){ce(e),u.currentMessages.push(t)}function We(){}async function Be(e){if(e.data.gist&&e.origin===g.RENDERER_HOST){var t=e.data.gist.instanceId,n=Ve(t);if(!n)return;var i=D(n);switch(e.data.gist.method){case"routeLoaded":{var o=(new Date().getTime()-n.renderStartTime)*.001;a(`Engine render for message: ${n.messageId} timer elapsed in ${o.toFixed(3)} seconds`),Ft(n.queueId),n.currentRoute=e.data.gist.parameters.route,n.firstLoad&&(n.overlay?kt(n):Et(n.elementId),u.messageShown(n),i.persistent?a("Persistent message shown, skipping logging view"):await Qe(n),n.firstLoad=!1),ye(t,n);break}case"tap":{var r=e.data.gist.parameters.action,p=e.data.gist.parameters.name;if(u.messageAction(n,r,p),e.data.gist.parameters.system&&!i.persistent){await te(n);break}try{var l=new URL(r);if(l&&l.protocol==="gist:"){var C=l.href.replace("gist://","").split("?")[0];switch(C){case"close":await te(n),await Ae(n),await He(n),await k();break;case"showMessage":var L=l.searchParams.get("messageId"),f=l.searchParams.get("properties");L&&(f&&(f=JSON.parse(atob(f))),await u.showMessage({messageId:L,properties:f}));break;case"loadPage":l=l.href.substring(l.href.indexOf("?url=")+5),l&&(l.startsWith("mailto:")||l.startsWith("https://")||l.startsWith("http://")||l.startsWith("/")?window.location.href=l:window.location.href=window.location+l);break}}}catch{}break}case"routeChanged":{n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=new Date().getTime(),ye(t,n),a(`Route changed to: ${n.currentRoute}`);break}case"sizeChanged":{a(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),(!n.elementId||n.shouldResizeHeight)&&$t(n,e.data.gist.parameters);break}case"titleChanged":{a(`Overlay title changed to: ${e.data.gist.parameters.title}`),Nt(t,e.data.gist.parameters.title);break}case"eventDispatched":{u.events.dispatch("eventDispatched",{name:e.data.gist.parameters.name,payload:e.data.gist.parameters.payload});break}case"error":case"routeError":{u.messageError(n),u.overlayInstanceId?Oe(!1,n):qe(n);break}}}}async function Ge(e){a(`Logging user message view locally for: ${e.queueId}`),j(e)?await Ot(e.queueId):await Bt(e.queueId)}async function He(e){j(e)&&(a(`Logging broadcast dismissed locally for: ${e.queueId}`),await Rt(e.queueId))}var zt=e=>new Promise(t=>setTimeout(t,e)),Fe=(e,t)=>e().then(zt(t).then(()=>Fe(e,t))),be=!1;let x=null;async function Y(){be?await k():R()?(a("Queue watcher started"),be=!0,Fe(()=>new Promise(()=>Jt()),1e3)):a("User token not setup, queue not started.")}async function k(){var e=await qt(),t=await Wt(),n=e.concat(t);a(`Messages in local queue: ${n.length}`);var i=n.sort((o,r)=>o.priority-r.priority);for(const o of i)await Xt(o)}async function Xt(e){var t=D(e);if(t.hasRouteRule){var n=u.currentRoute;n==null&&(n=new URL(window.location.href).pathname);var i=t.routeRule;a(`Verifying route ${n} against rule: ${i}`);var o=new RegExp(i);if(!o.test(n))return a(`Route ${n} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),!t.persistent&&!Qt(e)&&await Gt(e.queueId))return a(`Not showing message with queueId ${e.queueId} because its already loading.`),!1;var r=!1;return t.isEmbedded?r=await Ue(e,t.elementId):r=await Me(e),r&&Ht(e.queueId),r}async function Jt(){if(g.hasActiveSSEConnection()){await k();return}if(g.useSSE()&&!lt()){await je();return}await ne()}async function ne(){if(R())if(u.isDocumentVisible)if(m(G)===null){var e=await st(),t=[];e?(e.status===200||e.status===204?(a("200 response, updating local store."),t=e.data,Ne(t),ke(t)):e.status===304&&a("304 response, using local store."),await k()):a("There was an error while checking message queue.")}else a("Next queue pull scheduled for later.");else a("Document not visible, skipping queue check.");else a("User token reset, skipping queue check.")}async function je(){const e=ut();if(e===null){a("SSE endpoint not available, falling back to polling."),await ne();return}a(`Starting SSE queue listener on ${e}`),x=new EventSource(e),g.setActiveSSEConnection(),x.addEventListener("connected",async t=>{a("SSE connection received:"),g.setActiveSSEConnection(),g.setUseSSEFlag(!0),M(G),await ne()}),x.addEventListener("messages",async t=>{try{var n=JSON.parse(t.data);a("SSE message received:",n),await Ne(n),await ke(n),await k()}catch{a("Failed to parse SSE message"),W()}}),x.addEventListener("error",async t=>{a("SSE error received:"),W()}),x.addEventListener("heartbeat",async t=>{a("SSE heartbeat received:"),g.setActiveSSEConnection(),g.setUseSSEFlag(!0)})}function W(){x&&(a("Stopping SSE queue listener..."),x.close(),x=null,g.setUseSSEFlag(!1))}const Kt="cioPreviewId";function Yt(){const e=Zt();return e&&(et(!1),u.setUserToken(e),a(`Preview mode enabled with user token: ${e}`)),!Ie()}function Zt(){return new URLSearchParams(window.location.search).get(Kt)}class u{static async setup(t){this.events=new Ye,this.config={useAnonymousSession:t.useAnonymousSession===void 0?!1:t.useAnonymousSession,siteId:t.siteId,dataCenter:t.dataCenter,env:t.env===void 0?"prod":t.env,logging:t.logging===void 0?!1:t.logging,experiments:t.experiments===void 0?!1:t.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,this.config.isPreviewSession=Yt(),a(`Setup complete on ${this.config.env} environment.`),!this.config.isPreviewSession&&this.config.useAnonymousSession&&Se(),await Y(),document.addEventListener("visibilitychange",async()=>{document.visibilityState==="hidden"?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await k())},!1)}static async setCurrentRoute(t){this.currentRoute=t,a(`Current route set to: ${t}`),await k()}static async setUserToken(t,n){if(this.config.isPreviewSession)return;const i=g.hasActiveSSEConnection();W(),ct(t,n),i&&(g.setUseSSEFlag(!0),await je()),await Y()}static setUserLocale(t){nt(t)}static async clearUserToken(){this.config.isPreviewSession||(ft(),this.config.useAnonymousSession&&Se(),W(),await Y())}static async dismissMessage(t){var n=Ve(t);await te(n),await Ae(n),await He(n),await k()}static async embedMessage(t,n){var i=await Ue(t,n);return i?i.instanceId:null}static async showMessage(t){var n=await Me(t);return n?n.instanceId:null}static messageShown(t){a(`Message shown: ${t.messageId}`),this.events.dispatch("messageShown",t)}static messageDismissed(t){t!==null&&(a(`Message dismissed: ${t.messageId}`),this.events.dispatch("messageDismissed",t))}static messageError(t){a(`Message error: ${t.messageId}`),this.events.dispatch("messageError",t)}static messageAction(t,n,i){a(`Message action: ${t.currentRoute}, ${n} with name ${i} on ${t.instanceId}`),this.events.dispatch("messageAction",{message:t,action:n,name:i})}}const en=Object.freeze(Object.defineProperty({__proto__:null,default:u},Symbol.toStringTag,{value:"Module"})),tn=Xe(en),nn=tn.default;var sn=nn;const b=Je(sn);function mn(e){var t=this,n,i=!1,o=!1,r=new EventTarget;function p(){!i||o||(n.on("reset",C),e.events&&(fe.forEach(function(s){r.addEventListener(s,e==null?void 0:e.events)}),["messageDismissed","messageError"].forEach(function(s){b.events.on(s,function(d){var c,h;r.dispatchEvent(X(Ke(s),{messageId:d.messageId,deliveryId:(h=(c=d.properties)===null||c===void 0?void 0:c.gist)===null||h===void 0?void 0:h.campaignId}))})})),b.events.on("messageShown",function(s){var d,c,h,w,y,S,$,_,T=(c=(d=s==null?void 0:s.properties)===null||d===void 0?void 0:d.gist)===null||c===void 0?void 0:c.campaignId;if(e.events&&r.dispatchEvent(X(E.MessageOpened,{messageId:s==null?void 0:s.messageId,deliveryId:T,message:{dismiss:function(){b.dismissMessage(s==null?void 0:s.instanceId)}}})),typeof T<"u"&&T!=""){n.track(I.Metric,{deliveryId:T,metric:I.Opened});return}var P=(y=(w=(h=s==null?void 0:s.properties)===null||h===void 0?void 0:h.gist)===null||w===void 0?void 0:w.broadcast)===null||y===void 0?void 0:y.broadcastIdInt;if(P){var A=(_=($=(S=s==null?void 0:s.properties)===null||S===void 0?void 0:S.gist)===null||$===void 0?void 0:$.broadcast)===null||_===void 0?void 0:_.templateId;n.track(I.Content,{actionType:I.ViewedContent,contentId:P,templateId:A,contentType:ge})}}),b.events.on("messageAction",function(s){var d,c,h,w,y,S,$,_,T,P,A,Q=(h=(c=(d=s==null?void 0:s.message)===null||d===void 0?void 0:d.properties)===null||c===void 0?void 0:c.gist)===null||h===void 0?void 0:h.campaignId;if(e.events&&r.dispatchEvent(X(E.MessageAction,{messageId:s.message.messageId,deliveryId:Q,action:s.action,name:s.name,actionName:s.name,actionValue:s.action,message:{dismiss:function(){b.dismissMessage(s.message.instanceId)}}})),s.action!="gist://close"){if(typeof Q<"u"&&Q!=""){n.track(I.Metric,{deliveryId:Q,metric:I.Clicked,actionName:s.name,actionValue:s.action});return}var le=($=(S=(y=(w=s==null?void 0:s.message)===null||w===void 0?void 0:w.properties)===null||y===void 0?void 0:y.gist)===null||S===void 0?void 0:S.broadcast)===null||$===void 0?void 0:$.broadcastIdInt;if(le){var ze=(A=(P=(T=(_=s==null?void 0:s.message)===null||_===void 0?void 0:_.properties)===null||T===void 0?void 0:T.gist)===null||P===void 0?void 0:P.broadcast)===null||A===void 0?void 0:A.templateId;n.track(I.Content,{actionType:I.ClickedContent,contentId:le,templateId:ze,contentType:ge,actionName:s.name,actionValue:s.action})}}}),b.events.on("eventDispatched",function(s){var d,c,h;if(s.name=="analytics:track"){var w=(d=s.payload)===null||d===void 0?void 0:d.event;if(typeof w>"u"||w=="")return;n.track(w,(c=s.payload)===null||c===void 0?void 0:c.properties,(h=s.payload)===null||h===void 0?void 0:h.options)}}))}function l(s){var d,c,h,w,y;return q(this,void 0,void 0,function(){var S;return O(this,function($){return o?(S=(h=(c=(d=s.event)===null||d===void 0?void 0:d.properties)===null||c===void 0?void 0:c.name)!==null&&h!==void 0?h:(y=(w=s.event)===null||w===void 0?void 0:w.properties)===null||y===void 0?void 0:y.url,typeof S=="string"&&S.length>0&&b.setCurrentRoute(S),[2,s]):[2,s]})})}function C(s){return q(this,void 0,void 0,function(){return O(this,function(d){switch(d.label){case 0:return[4,b.clearUserToken()];case 1:return d.sent(),[2,s]}})})}function L(s){return q(this,void 0,void 0,function(){var d;return O(this,function(c){switch(c.label){case 0:return i?(d=n.user().id(),typeof d=="string"&&d.length>0?[4,b.setUserToken(d)]:[3,2]):[2,s];case 1:return c.sent(),[3,4];case 2:return[4,b.clearUserToken()];case 3:c.sent(),c.label=4;case 4:return[2,s]}})})}var f={name:"Customer.io In-App Plugin",type:"before",version:"0.0.1",isLoaded:function(){return o},load:function(s,d){return q(t,void 0,void 0,function(){return O(this,function(c){switch(c.label){case 0:return n=d,e.siteId==null||e.siteId==""?(an("siteId is required. Can't initialize."),[2,s]):[4,b.setup({siteId:e.siteId,env:e._env?e._env:"prod",logging:e._logging,useAnonymousSession:e.anonymousInApp})];case 1:return c.sent(),i=!0,[4,L(s)];case 2:return c.sent(),p(),o=!0,[2,Promise.resolve()]}})})},identify:L,page:l,unload:function(){return q(t,void 0,void 0,function(){return O(this,function(s){return e.events&&fe.forEach(function(d){r.removeEventListener(d,e==null?void 0:e.events)}),[2]})})}};return f}function an(e){console.error("[Customer.io In-App Plugin] ".concat(e))}export{E as InAppEvents,mn as InAppPlugin}; //# sourceMappingURL=index-Vy7GLZGp.js.map