!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gist=t():e.Gist=t()}(this,()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>ln});class n{constructor(){this.callbacks={}}on(e,t){const n=this.callbacks[e];n?n.push(t):this.callbacks[e]=[t]}off(e,t){const n=this.callbacks[e];if(!n)return;if(!t)return void delete this.callbacks[e];const i=n.indexOf(t);-1!==i&&n.splice(i,1),0===n.length&&delete this.callbacks[e]}dispatch(e,t){const n=this.callbacks[e];n&&n.forEach(e=>e(t))}}function i(e){ln.config&&ln.config.logging&&console.log(`Gist: ${e}`)}const o="gist.web.isPersistingSession";function s(e,t,n=null){let i=n;i||(i=new Date,i.setDate(i.getDate()+365));const o={value:t,expiry:i};c().setItem(e,JSON.stringify(o))}function a(e){return d(e)}function r(e){c().removeItem(e)}function l(){const e=sessionStorage.getItem(o);return null===e?(sessionStorage.setItem(o,"true"),!0):"true"===e}function c(){return l()?localStorage:sessionStorage}function d(e){if(!e)return null;try{const t=c().getItem(e);if(!t)return null;const n=JSON.parse(t);if(!n.expiry)return n.value;if(e.startsWith("gist.")){const t=new Date,i=new Date(n.expiry),o=e.startsWith("gist.web.message.broadcasts")&&!e.endsWith("shouldShow")&&!e.endsWith("numberOfTimesShown")||e.startsWith("gist.web.message.user")&&!e.endsWith("seen")&&!e.endsWith("state"),s=new Date(t.getTime()+366e4);if(o&&i.getTime()>s.getTime())return r(e),null;if(t.getTime()>i.getTime())return r(e),null}return n.value}catch(t){i(`Error checking key ${e} for expiry: ${t}`)}return null}var p,u=new Uint8Array(16);function g(){if(!p&&!(p="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return p(u)}const m=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var f=[],h=0;h<256;++h)f.push((h+256).toString(16).substr(1));const w=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(f[e[t+0]]+f[e[t+1]]+f[e[t+2]]+f[e[t+3]]+"-"+f[e[t+4]]+f[e[t+5]]+"-"+f[e[t+6]]+f[e[t+7]]+"-"+f[e[t+8]]+f[e[t+9]]+"-"+f[e[t+10]]+f[e[t+11]]+f[e[t+12]]+f[e[t+13]]+f[e[t+14]]+f[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&m.test(e)}(n))throw TypeError("Stringified UUID is invalid");return n},y=function(e,t,n){var i=(e=e||{}).random||(e.rng||g)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=i[o];return t}return w(i)},b="gist.web.userQueueUseSSE",v="gist.web.activeSSEConnection";let x,S=30;const I={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://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"},getSdkId:()=>(x||(x=y()),x),useSSE:()=>a(b)??!1,setUseSSEFlag(e){s(b,e,new Date((new Date).getTime()+6e4)),i(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection(){r(v)},setActiveSSEConnection(){s(v,I.getSdkId(),new Date((new Date).getTime()+I.getSSEHeartbeat()))},hasActiveSSEConnection:()=>a(v)??!1,isSSEConnectionManagedBySDK:()=>a(v)===I.getSdkId(),getSSEHeartbeat:()=>1e3*(S+5),setSSEHeartbeat(e){e&&e>0&&(S=e)}};function $(e){return null!==e&&"object"==typeof e&&"response"in e}function E(e){return $(e)?e.response:void 0}function C(){const e=I.GIST_QUEUE_API_ENDPOINT[ln.config.env??"prod"],t={"X-CIO-Site-Id":ln.config.siteId,"X-CIO-Client-Platform":"web"},n=B();async function i(n,i={}){const o=e+n,s=new AbortController,a=setTimeout(()=>s.abort(),5e3);try{const e=await fetch(o,{method:i.method||"GET",headers:{...t,...i.headers||{}},body:i.method&&"GET"!==i.method.toUpperCase()?i.body:void 0,signal:s.signal});clearTimeout(a);const n=e.headers.get("content-type")?.includes("application/json"),r=n?await e.json():await e.text(),l=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw function(e){return Object.assign(new Error,{response:e})}({status:e.status,data:r,headers:l});return{status:e.status,headers:l,data:r}}catch(e){if(clearTimeout(a),$(e))throw e;if(e instanceof Error)throw Object.assign(e,{response:{status:0,data:e.message||"Unknown error",headers:{}}});throw e}}return null!=n&&(t["X-Gist-Encoded-User-Token"]=n),i.post=(e,t={},n={})=>i(e,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...n.headers||{}}}),i}const k="gist.web.userLocale";function P(){const e=a(k);return null!==e?e:navigator.language}let L=600,T=!1;const M="gist.web.userQueueNextPullCheck",N="gist.web.sessionId";function D(){let e=a(N);return e||(e=y()),s(N,e,new Date((new Date).getTime()+18e5)),String(e)}const A="gist.web.userToken",q="gist.web.usingGuestUserToken",R="gist.web.guestUserToken";function W(){return null!==a(q)}function O(){return a(A)}function U(){if(null===O()){let e=a(R);null==e&&(e=y(),s(R,e),i(`Set guest user token "${e}" with expiry date set to 1 year from today`)),s(A,e),s(q,!0),i(`Using anonymous session with token: "${e}"`)}}async function z(){const e=O();return null===e?null:await async function(e){const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("")}(e)}function B(){const e=O();return null===e?null:btoa(e)}function F(){r(A),i("Cleared user token")}async function H(e){try{return await C().post(`/api/v1/logs/queue/${e}`)}catch(e){return E(e)}}function j(e){try{return(document.getElementById(e)??document.querySelector(e))||null}catch{return null}}const _={isEmbedded:!1,elementId:"",hasRouteRule:!1,routeRule:"",position:"",hasPosition:!1,tooltipPosition:"",hasTooltipPosition:!1,tooltipArrowColor:"#fff",shouldScale:!1,campaignId:null,messageWidth:414,overlayColor:"#00000033",persistent:!1,exitClick:!1,hasCustomWidth:!1};function G(e){let t=_.tooltipArrowColor;if((e?.properties?.gist?.tooltipArrowColor?.length??0)>0)t=e.properties.gist.tooltipArrowColor;else{if(!Array.isArray(e?.displaySettings)||0===e.displaySettings.length)return t;let n=e.displaySettings[0];if(e.savedStepName){const t=e.displaySettings.find(t=>t?.stepName===e.savedStepName&&t.displaySettings);t&&(n=t)}n?.displaySettings?.tooltipArrowColor&&(t=n.displaySettings.tooltipArrowColor)}return t}function V(e){const t=_,n=e?.properties?.gist;return n?{isEmbedded:!!n.elementId&&!n.tooltipPosition,elementId:n.elementId||"",hasRouteRule:!!n.routeRuleWeb,routeRule:n.routeRuleWeb||"",position:n.position||"",hasPosition:!!n.position,tooltipPosition:n.tooltipPosition||"",hasTooltipPosition:!!n.tooltipPosition,tooltipArrowColor:G(e),shouldScale:!!n.scale,campaignId:n.campaignId??null,messageWidth:null!=n.messageWidth&&n.messageWidth>0?n.messageWidth:t.messageWidth,hasCustomWidth:(n.messageWidth??0)>0,overlayColor:n.overlayColor||t.overlayColor,persistent:!!n.persistent,exitClick:!!n.exitClick}:t}const X=["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 J(e){if(document.getElementById(e))return;const t=document.createElement("div");t.id=e,"x-gist-top"===e?document.body.insertBefore(t,document.body.firstChild):document.body.insertAdjacentElement("beforeend",t),i("Top & bottom elements injected into page")}const Y=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function Q(e){return ln.currentMessages.find(t=>t.instanceId===e)}function K(e){return!!e&&ln.currentMessages.some(t=>t.queueId===e)}function Z(e){return e?ln.currentMessages.find(t=>t.elementId===e)??null:null}function ee(e){ln.currentMessages=ln.currentMessages.filter(t=>t.instanceId!==e)}function te(e,t){ee(e),ln.currentMessages.push(t)}function ne(e){const t={topLeft:"x-gist-floating-top-left",topCenter:"x-gist-floating-top",topRight:"x-gist-floating-top-right",bottomLeft:"x-gist-floating-bottom-left",bottomCenter:"x-gist-floating-bottom",bottomRight:"x-gist-floating-bottom-right"};return e&&t[e]?t[e]:(i(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function ie(e){return e.tooltipPosition?"tooltip":e.overlay?"modal":e.elementId&&X.includes(e.elementId)?"overlay":e.elementId?"inline":"modal"}function oe(e,t){const n=ie(e),i=t.displayType;if(void 0===i)return!1;if(n!==i)return!0;const o=V(e);switch(i){case"modal":{if((e.position||"center")!==(t.modalPosition||"center"))return!0;const n=t.dismissOutsideClick??_.exitClick;if(o.exitClick!==n)return!0;const i=t.overlayColor??_.overlayColor;if(o.overlayColor!==i)return!0;break}case"overlay":{const n=ne(t.overlayPosition);if(e.elementId!==n)return!0;break}case"inline":if(e.elementId!==t.elementSelector)return!0;break;case"tooltip":if(e.tooltipPosition!==t.tooltipPosition)return!0;if(e.elementId!==t.elementSelector)return!0;if(void 0!==t.tooltipArrowColor&&o.tooltipArrowColor!==t.tooltipArrowColor)return!0}if("overlay"!==i||!Y.includes(ne(t.overlayPosition))){const e=t.maxWidth??_.messageWidth;if(o.messageWidth!==e)return!0}return!1}function se(e,t){if(e.properties||(e.properties={}),e.properties.gist||(e.properties.gist={}),"modal"===t.displayType)e.overlay=!0,e.elementId=null,e.properties.gist.elementId=null,e.position=t.modalPosition||"center",e.properties.gist.position=t.modalPosition||"center",e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0;else if("overlay"===t.displayType){e.overlay=!1;const n=ne(t.overlayPosition);e.elementId=n,e.properties.gist.elementId=n,e.position=null,e.properties.gist.position=null,e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0}else"inline"===t.displayType?(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.position=null,e.properties.gist.position=null,e.tooltipPosition=void 0,e.properties.gist.tooltipPosition=void 0,e.properties.gist.tooltipArrowColor=void 0):"tooltip"===t.displayType&&(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.tooltipPosition=t.tooltipPosition,e.properties.gist.tooltipPosition=t.tooltipPosition,e.position=null,e.properties.gist.position=null,void 0!==t.tooltipArrowColor&&(e.properties.gist.tooltipArrowColor=t.tooltipArrowColor));e.elementId&&Y.includes(e.elementId)?delete e.properties.gist.messageWidth:void 0!==t.maxWidth&&t.maxWidth>0?e.properties.gist.messageWidth=t.maxWidth:delete e.properties.gist.messageWidth,void 0!==t.overlayColor?e.properties.gist.overlayColor=t.overlayColor:delete e.properties.gist.overlayColor,void 0!==t.dismissOutsideClick?e.properties.gist.exitClick=t.dismissOutsideClick:delete e.properties.gist.exitClick}const ae={top:["bottom","left","right"],bottom:["top","left","right"],left:["right","top","bottom"],right:["left","top","bottom"]},re=/auto|scroll/,le={top:"gist-arrow-bottom",bottom:"gist-arrow-top",left:"gist-arrow-right",right:"gist-arrow-left"};function ce(e){const t=j(e);return t||i(`Tooltip target element not found for selector: ${e}`),t}function de(e,t){if(e.bottom<=0||e.top>=window.innerHeight||e.right<=0||e.left>=window.innerWidth)return!1;for(const n of t){const t=n.getBoundingClientRect();if(e.bottom<=t.top||e.top>=t.bottom||e.right<=t.left||e.left>=t.right)return!1}return!0}function pe(e,t,n){const i=function(e,t,n){switch(n){case"top":return{top:t.top-e.height-16,left:t.left+(t.width-e.width)/2};case"bottom":return{top:t.bottom+16,left:t.left+(t.width-e.width)/2};case"left":return{top:t.top+(t.height-e.height)/2,left:t.left-e.width-16};case"right":return{top:t.top+(t.height-e.height)/2,left:t.right+16}}}(e,t,n);return function(e,t,n){return"top"===n||"bottom"===n?e.top>=0&&e.top+t.height<=window.innerHeight:e.left>=0&&e.left+t.width<=window.innerWidth}(i,e,n)&&function(e,t){return"top"===t||"bottom"===t?e.width+8<=window.innerWidth:e.height+8<=window.innerHeight}(e,n)?function(e,t,n){let{top:i,left:o}=e,s=null;if("top"===n||"bottom"===n){const e=4,n=window.innerWidth-t.width-4;n>=e&&(o<e?(s=o-e,o=e):o>n&&(s=o-n,o=n))}else{const e=4,n=window.innerHeight-t.height-4;n>=e&&(i<e?(s=i-e,i=e):i>n&&(s=i-n,i=n))}if(null!==s){const e=("top"===n||"bottom"===n?t.width/2:t.height/2)-16-4;Math.abs(s)>e&&(s=s>0?e:-e)}return{top:i,left:o,position:n,arrowOffset:s}}(i,e,n):null}function ue(e,t,n){const i=pe(e,t,n);if(i)return i;for(const i of ae[n]){const n=pe(e,t,i);if(n)return n}return null}function ge(e){const t=[];let n=e.parentElement;for(;n;){const e=getComputedStyle(n),i=e.overflow+e.overflowX+e.overflowY;re.test(i)&&t.push(n),n=n.parentElement}return t}function me(e){const t=j(e);t&&(t.classList.remove("gist-visible"),Array.from(t.classList).filter(e=>e.startsWith("gist-")).forEach(e=>t.classList.remove(e)),t.style.removeProperty("height"),t.style.removeProperty("width"),t.innerHTML="")}function fe(e){const t=j(e);if(t)return!(!t.style||!t.style.height||"0px"===t.style.height)}function he(e,t,n=null){const i=document.getElementById(e);i&&(i.onload=()=>{!function(e,t,n=null){const i=document.getElementById(e);if(i?.contentWindow){const e={options:t,capabilities:we};n&&(t.stepId=n),i.contentWindow.postMessage(e,"*")}}(e,t,n)})}const we=["MultiStepDisplayTypes"];function ye(e){if(!e.displaySettings)return;const t=Ie(e.instanceId??""),n=document.getElementById(t);n?.contentWindow&&n.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:e.displaySettings},"*")}async function be(){const e=document.querySelector(".gist-message");e&&(e.classList.remove("gist-visible"),await new Promise(e=>setTimeout(e,300))),ve()}function ve(){const e=document.querySelector("#gist-embed-message");e&&e.parentNode?.removeChild(e)}const xe=new Map;function Se(e){const t=e.instanceId??"",n=xe.get(t);n&&(n.cleanup(),xe.delete(t));const i=j(`gist-tooltip-${t}`);i&&i.parentNode?.removeChild(i)}function Ie(e){return`gist-${e}`}function $e(){const e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}const Ee="gist.web.customAttributes";let Ce=new Map;function ke(){const e=Array.from(Ce.entries()),t=new Date;t.setDate(t.getDate()+30),s(Ee,e,t),i(`Saved ${Ce.size} custom attributes to storage with TTL of 30 days`)}async function Pe(e){const t=await Ne();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(t,e.filter(Te),n)}async function Le(e,t){const n=a(e);return n?.find(e=>e.queueId===t)}function Te(e){return!(!e.properties?.gist||!e.properties.gist.broadcast)}function Me(e){if(!Te(e))return!1;const t=e.properties.gist.broadcast;return 0===t.frequency.delay&&0===t.frequency.count}async function Ne(){const e=await z();return e?`gist.web.message.broadcasts.${e}`:null}function De(e,t){return`${e}.${t}.numberOfTimesShown`}function Ae(e,t){return`${e}.${t}.shouldShow`}!function(){const e=a(Ee);if(e)try{Ce=new Map(e)}catch{Ce=new Map}else Ce=new Map}();const qe="gist.web.message.user";async function Re(e){const t=await We();if(!t)return;const n=e.filter(e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast)),i=new Date;i.setMinutes(i.getMinutes()+60),s(t,n,i)}async function We(){const e=await z();return e?`${qe}.${e}`:null}async function Oe(){const e=await z();return e?`${qe}.${e}.seen`:null}async function Ue(e){const t=await z();return t?`${qe}.${t}.message.${e}.loading`:null}async function ze(e){const t=await z();return t?`${qe}.${t}.message.${e}.state`:null}async function Be(e){const t=await ze(e);t&&(r(t),i(`Cleared message state for queueId: ${e}`))}function Fe(e){return`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.54223 5.33301L7.7089 9.33301L11.8756 5.33301L12.6121 6.04011L7.7089 10.7472L2.80566 6.04011L3.54223 5.33301Z" fill="${e}"/></svg>`}const He=`\n  #gist-preview-bar {\n    position: fixed; bottom: 0; left: 0; right: 0;\n    z-index: 99999999999;\n    font-family: system-ui, -apple-system, sans-serif;\n    pointer-events: none;\n  }\n  .gist-pb-toggle-row {\n    display: flex; justify-content: center;\n    padding: 6px 16px;\n    border-bottom: 1px solid #e5e7eb;\n  }\n  .gist-pb-toggle-row--collapsed { border-bottom: none; }\n  .gist-pb-toggle-btn {\n    background: #08272B; border: none;\n    padding: 4px 14px;\n    border-radius: 100px;\n    font-size: 12px; font-weight: 500;\n    font-family: system-ui, -apple-system, sans-serif;\n    color: white; cursor: pointer;\n    display: flex; align-items: center; gap: 6px;\n    pointer-events: auto;\n    height: auto; min-width: auto;\n    box-sizing: border-box;\n    line-height: normal;\n    -webkit-appearance: none;\n    appearance: none;\n  }\n  .gist-pb-controls-row {\n    background: #F8F9F9;\n    box-shadow: 1px 2px 2px #34344605, 3px 3px 8px #34344614;\n    display: flex; flex-wrap: wrap; align-items: center;\n    gap: 12px; padding: 10px 16px 12px;\n    pointer-events: auto;\n  }\n  .gist-pb-label-group { display: flex; flex-direction: column; gap: 4px; }\n  .gist-pb-label-group--grow { flex: 1; }\n  .gist-pb-label {\n    font-size: 10px; font-weight: 600; color: #3F4E50;\n    letter-spacing: 0.05em; text-transform: uppercase;\n    font-family: system-ui, -apple-system, sans-serif;\n  }\n  .gist-pb-select {\n    height: 32px; padding: 0 32px 0 8px;\n    border: 1px solid #d1d5db; border-radius: 6px;\n    font-size: 13px; font-family: system-ui, -apple-system, sans-serif;\n    background: white ${`url("data:image/svg+xml,${encodeURIComponent(Fe("#3F4E50"))}")`} no-repeat right 2px center;\n    color: #3F4E50; cursor: pointer; outline: none;\n    appearance: none; min-width: 120px;\n  }\n  .gist-pb-input {\n    height: 32px; padding: 0 8px;\n    border: 1px solid #d1d5db; border-radius: 6px;\n    font-size: 13px; font-family: system-ui, -apple-system, sans-serif;\n    color: #3F4E50; outline: none; box-sizing: border-box;\n  }\n  .gist-pb-checkbox-row { display: flex; align-items: center; gap: 6px; height: 32px; }\n  .gist-pb-checkbox-label {\n    font-size: 12px; font-family: system-ui, -apple-system, sans-serif;\n    color: #3F4E50; cursor: pointer; user-select: none;\n  }\n  .gist-pb-color-control {\n    display: flex; align-items: center;\n    border: 1px solid #d1d5db; border-radius: 6px;\n    overflow: hidden; height: 32px; background: white;\n  }\n  .gist-pb-color-swatch {\n    width: 28px; height: 100%;\n    cursor: pointer; flex-shrink: 0;\n    border-right: 1px solid #d1d5db; position: relative;\n  }\n  .gist-pb-color-input {\n    position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;\n  }\n  .gist-pb-color-hex {\n    flex: 1; border: none; outline: none; padding: 0 6px;\n    font-size: 13px; font-family: monospace; color: #3F4E50;\n    min-width: 0; background: transparent;\n  }\n  .gist-pb-color-opacity {\n    width: 36px; border: none; border-left: 1px solid #d1d5db;\n    outline: none; padding: 0 4px;\n    font-size: 13px; font-family: system-ui, -apple-system, sans-serif;\n    color: #3F4E50; background: transparent; text-align: right;\n  }\n  .gist-pb-color-pct {\n    font-size: 12px; color: #3F4E50; padding: 0 6px 0 2px;\n    font-family: system-ui, -apple-system, sans-serif; flex-shrink: 0;\n  }\n  .gist-pb-input--invalid { border-color: #941616; outline: 1px solid #941616; }\n  .gist-pb-inline-row { display: flex; align-items: center; gap: 6px; }\n  .gist-pb-select-elem-btn, .gist-pb-cancel-btn {\n    height: 32px; padding: 0 12px;\n    border: none; border-radius: 6px;\n    font-size: 12px; font-weight: 500; font-family: system-ui, -apple-system, sans-serif;\n    background: #08272B; color: white; cursor: pointer; white-space: nowrap; flex-shrink: 0;\n    min-width: auto; box-sizing: border-box;\n    -webkit-appearance: none; appearance: none;\n  }\n  .gist-pb-select-elem-btn:disabled {\n    opacity: 0.4; cursor: not-allowed;\n  }\n  .gist-pb-spacer { flex: 1; min-width: 0; }\n  .gist-pb-save-btn {\n    height: 36px; padding: 0 18px;\n    background: #08272B; color: white;\n    border: none; border-radius: 6px;\n    font-size: 13px; font-weight: 600;\n    font-family: system-ui, -apple-system, sans-serif;\n    cursor: pointer; white-space: nowrap; align-self: center;\n    min-width: auto; box-sizing: border-box;\n    -webkit-appearance: none; appearance: none;\n  }\n  .gist-pb-save-btn:disabled {\n    background: #CAD6D8; cursor: not-allowed;\n  }\n  .gist-pb-picker-overlay {\n    position: fixed; inset: 0; z-index: 999999999998; cursor: crosshair;\n  }\n  .gist-pb-checkbox { cursor: pointer; width: 14px; height: 14px; }\n  .gist-pb-pick-highlight { outline: 2px solid #006FF5 !important; }\n  .gist-pb-pick-error { outline: 2px solid #941616 !important; }\n  #gist-preview-bar.gist-pb-hidden { display: none; }\n  .gist-pb-ended-row {\n    justify-content: center; align-items: center; gap: 10px; padding: 12px 16px;\n    flex-wrap: nowrap;\n  }\n  .gist-pb-ended-icon {\n    display: flex; align-items: center; justify-content: center;\n    width: 22px; height: 22px; border-radius: 50%;\n    background: #08272B; color: white;\n    font-size: 13px; font-weight: 700; flex-shrink: 0;\n  }\n  .gist-pb-ended-text {\n    margin: 0; font-size: 13px; color: #3F4E50;\n    font-family: system-ui, -apple-system, sans-serif;\n    min-width: 0;\n  }\n  .gist-pb-ended-text strong { color: #08272B; }\n  @media (max-width: 1024px) {\n    .gist-pb-controls-row { gap: 8px; }\n    .gist-pb-label-group { flex: 1 1 100%; }\n    .gist-pb-label-group--grow { flex: 1 1 100%; }\n    .gist-pb-select { width: 100%; min-width: unset; box-sizing: border-box; }\n    .gist-pb-input { width: 100% !important; box-sizing: border-box; }\n    .gist-pb-color-control { width: 100%; }\n    .gist-pb-checkbox-row { width: 100%; }\n    .gist-pb-inline-row { flex-direction: row; align-items: center; }\n    .gist-pb-inline-row .gist-pb-input { flex: 1; min-width: 0; }\n    .gist-pb-save-btn { width: 100%; box-sizing: border-box; }\n    .gist-pb-label--spacer { display: none; }\n  }\n`;const je="cioPreviewId",_e="cioPreviewSettings";const Ge="gist.previewBar.collapsed",Ve="gist-pb-styles",Xe="gist-preview-bar",Je={topLeft:"Top Left",topCenter:"Top Center",topRight:"Top Right",bottomLeft:"Bottom Left",bottomCenter:"Bottom Center",bottomRight:"Bottom Right"};let Ye=null,Qe=[],Ke={},Ze=null,et=!1,tt=!1,nt=5,it=null,ot=!0,st=!1,at=!1,rt=null,lt=null,ct=null;const dt=new Map;function pt(e,t={}){const n=document.createElement(e);for(const[e,i]of Object.entries(t))n[e]=i;return n}function ut(e,t){const n=pt("div",{className:"gist-pb-label-group"});return n.appendChild(pt("span",{className:"gist-pb-label",textContent:e})),n.appendChild(t),n}function gt(e,t){const n=pt("select",{className:"gist-pb-select"});for(const i of e){const e=pt("option",{value:i.value,textContent:i.label});i.value===t&&(e.selected=!0),n.appendChild(e)}return n}function mt(e,t,n){const i=pt("input",{className:"gist-pb-input",type:e,value:String(t)});return n&&(i.style.width=n),i}function ft(e,t){const n=Math.round(Math.min(100,Math.max(0,t))/100*255);return"#"+e.replace("#","").toUpperCase()+n.toString(16).padStart(2,"0").toUpperCase()}function ht(e){return!!("inline"!==e.displayType&&"tooltip"!==e.displayType||e.elementSelector?.trim())}function wt(e){if("overlay"===e.displayType&&Y.includes(ne(e.overlayPosition))){const{maxWidth:t,...n}=e;e=n}if(Ke=e,Ze){const t=Qe.findIndex(e=>e.stepName===Ze);-1!==t&&(Qe[t]={...Qe[t],displaySettings:{...e}})}if(!Ye)return;const t=ln.currentMessages.find(e=>e.instanceId===Ye);t&&ht(e)&&(ye(t),oe(t,e)&&Gt(t,Ze,e)),function(){const e=new URLSearchParams(window.location.search).get(je);e&&async function(e,t){try{return await C()(`/api/v1/preview/${e}`,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return E(e)}}(e,Qe).then(e=>{e&&404===e.status&&Ye&&ln.dismissMessage(Ye)}).catch(()=>i("Failed to persist preview display settings"))}()}function yt(e){const t=e.value.trim();t&&!j(t)?e.classList.add("gist-pb-input--invalid"):e.classList.remove("gist-pb-input--invalid")}function bt(e,t){const n=mt("text",e.elementSelector||"","260px");n.placeholder="Element ID or selector",yt(n),n.addEventListener("change",()=>{const e=n.value.trim(),t=Ke.elementSelector;e&&vt(e),wt({...Ke,elementSelector:e}),t&&t!==e&&xt(t),yt(n)});const i=pt("button",{type:"button",className:"gist-pb-select-elem-btn",textContent:"Select Element"});at&&(i.disabled=!0),i.addEventListener("click",()=>It(n));const o=pt("div",{className:"gist-pb-inline-row"});o.appendChild(n),o.appendChild(i),t.appendChild(ut("Element Selector",o))}function vt(e){if(!e||dt.has(e))return;const t=j(e);t&&dt.set(e,t.innerHTML)}function xt(e){const t=dt.get(e);if(void 0===t)return;const n=j(e);n&&(n.innerHTML=t)}function St(){for(const e of dt.keys())xt(e);dt.clear()}function It(e){if(at)return;at=!0;const t=document.querySelector(`#${Xe} .gist-pb-select-elem-btn`);t&&(t.disabled=!0);const n={...Ke},o=ln.currentMessages.find(e=>e.instanceId===Ye)??null;o&&_t(o),Ke.elementSelector&&xt(Ke.elementSelector);const s=pt("div",{className:"gist-pb-picker-overlay"});let a=null;const r=e=>{s.style.pointerEvents="none";const t=document.elementFromPoint(e.clientX,e.clientY);s.style.pointerEvents="all",t&&t!==a&&t!==s&&(a?.classList.remove("gist-pb-pick-highlight"),a=t,a.classList.add("gist-pb-pick-highlight"))},l=e=>{if("Escape"===e.key){if(d(),Ke=n,Ze){const e=Qe.findIndex(e=>e.stepName===Ze);-1!==e&&(Qe[e]={...Qe[e],displaySettings:{...n}})}o&&ht(n)&&Gt(o,Ze,n),$t()}},c=t=>{t.preventDefault(),t.stopPropagation(),s.style.pointerEvents="none";const n=document.elementFromPoint(t.clientX,t.clientY);if(s.style.pointerEvents="all",n&&n!==s){n.classList.remove("gist-pb-pick-highlight");const t=document.getElementById(Xe),s=t?.contains(n)?null:function(e){if(e.id){const t=CSS.escape(e.id);if(1===document.querySelectorAll(`#${t}`).length)return e.id}const t=[];let n=e;for(;n&&"BODY"!==n.tagName&&"HTML"!==n.tagName;){if(n.id){const e=CSS.escape(n.id);if(1===document.querySelectorAll(`#${e}`).length){t.unshift(`#${e}`);break}}let e=n.tagName.toLowerCase();n.className&&"string"==typeof n.className&&(e+=n.className.trim().split(/\s+/).filter(Boolean).map(e=>`.${CSS.escape(e)}`).join(""));const i=n.parentElement;i&&(e+=`:nth-of-type(${Array.from(i.children).filter(e=>e.tagName===n.tagName).indexOf(n)+1})`),t.unshift(e);try{if(1===document.querySelectorAll(t.join(" > ")).length)break}catch{}n=n.parentElement}const o=t.join(" > ");try{if(1!==document.querySelectorAll(o).length)return i("buildUniqueSelector: could not produce a unique selector for element"),null}catch{return null}return o}(n);if(null===s)return n.classList.add("gist-pb-pick-error"),void setTimeout(()=>{n.classList.remove("gist-pb-pick-error"),n.classList.add("gist-pb-pick-highlight")},800);e.value=s,vt(s);const a=Ke.elementSelector,r={...Ke,elementSelector:s},l=null!=o&&ht(r)&&oe(o,r);wt(r),a&&a!==s&&xt(a),o&&!l&&Gt(o,Ze,r)}d(),$t()},d=()=>{a?.classList.remove("gist-pb-pick-highlight"),s.removeEventListener("mousemove",r),s.removeEventListener("click",c),document.removeEventListener("keydown",l),document.body.removeChild(s),at=!1,rt=null};rt=d,s.addEventListener("mousemove",r),s.addEventListener("click",c),document.addEventListener("keydown",l),document.body.appendChild(s)}function $t(){const e=document.getElementById(Xe);if(!e)return;if(e.classList.toggle("gist-pb-hidden",!Ye&&!tt),e.innerHTML="",!Ye){if(tt){const t=pt("div",{className:"gist-pb-controls-row gist-pb-ended-row"}),n=pt("span",{className:"gist-pb-ended-icon",textContent:"✓"}),i=pt("p",{className:"gist-pb-ended-text"});if(i.innerHTML=Ct(nt),t.appendChild(n),t.appendChild(i),ot){const e=pt("button",{type:"button",className:"gist-pb-cancel-btn",textContent:"Cancel"});e.addEventListener("click",kt),t.appendChild(e)}e.appendChild(t)}return}const t=pt("div",{className:"gist-pb-toggle-row"+(et?" gist-pb-toggle-row--collapsed":"")}),n=pt("button",{type:"button",className:"gist-pb-toggle-btn"}),i=et?"transform:rotate(180deg);display:inline-flex;":"display:inline-flex;";if(n.innerHTML=`${et?"Expand":"Collapse"}<span style="${i}">${Fe("white")}</span>`,n.addEventListener("click",Pt),t.appendChild(n),e.appendChild(t),et)return;const o=pt("div",{className:"gist-pb-controls-row"});if(Qe.length>0){const e=Ze??Qe[0].stepName,t=gt(Qe.map(e=>({value:e.stepName,label:e.stepName})),e);t.addEventListener("change",()=>{const e=Qe.find(e=>e.stepName===t.value);if(e){Ze=e.stepName,Ke={...e.displaySettings};const t=ln.currentMessages.find(e=>e.instanceId===Ye);t&&ht(e.displaySettings)&&Gt(t,e.stepName,e.displaySettings),$t()}}),o.appendChild(ut("Step",t))}const s=gt([{value:"modal",label:"Modal"},{value:"overlay",label:"Overlay"},{value:"inline",label:"Inline"},{value:"tooltip",label:"Tooltip"}],Ke.displayType||"modal");s.addEventListener("change",()=>{const e=s.value,t=Ke.displayType,n=Ke.elementSelector,i={...Ke,displayType:e};"modal"===e?(i.modalPosition=i.modalPosition||"center",i.maxWidth=i.maxWidth??414,delete i.overlayPosition,delete i.elementSelector,delete i.tooltipPosition):"overlay"===e?(i.overlayPosition=i.overlayPosition||"topCenter",i.maxWidth=i.maxWidth??414,delete i.modalPosition,delete i.elementSelector,delete i.tooltipPosition):"inline"===e?(delete i.modalPosition,delete i.overlayPosition,delete i.tooltipPosition):"tooltip"===e&&(i.tooltipPosition=i.tooltipPosition||"top",delete i.modalPosition,delete i.overlayPosition,delete i.overlayColor,delete i.dismissOutsideClick),Ke=i,wt(Ke),"inline"!==t&&"tooltip"!==t||!n||"inline"===e||"tooltip"===e||xt(n),$t()}),o.appendChild(ut("Display Type",s));const a=Ke.displayType||"modal";"modal"===a?function(e,t){const n=gt([{value:"top",label:"Top"},{value:"center",label:"Center"},{value:"bottom",label:"Bottom"}],e.modalPosition||"center");n.addEventListener("change",()=>wt({...Ke,modalPosition:n.value})),t.appendChild(ut("Position",n));const i=mt("number",e.maxWidth??414,"80px");i.addEventListener("change",()=>wt({...Ke,maxWidth:parseInt(i.value)||414})),t.appendChild(ut("Max Width",i)),t.appendChild(function(e){const{color:t,opacity:n}=function(e){const t=e.replace("#","");return 8===t.length?{color:"#"+t.slice(0,6).toUpperCase(),opacity:Math.round(parseInt(t.slice(6),16)/255*100)}:6===t.length?{color:"#"+t.toUpperCase(),opacity:100}:{color:"#000000",opacity:20}}(e.overlayColor||"#00000033"),i=pt("div",{className:"gist-pb-color-control"}),o=pt("input",{className:"gist-pb-color-input",type:"color",value:t}),s=pt("div",{className:"gist-pb-color-swatch"});s.style.background=t,s.appendChild(o),s.addEventListener("click",()=>o.click());const a=pt("input",{className:"gist-pb-color-hex",type:"text",maxLength:6,value:t.replace("#","")}),r=pt("input",{className:"gist-pb-color-opacity",type:"number",min:"0",max:"100",value:String(n)}),l=pt("span",{className:"gist-pb-color-pct",textContent:"%"}),c=()=>{const e="#"+a.value.replace("#",""),t=parseInt(r.value)||0;s.style.background=e,o.value=e,wt({...Ke,overlayColor:ft(e,t)})};return o.addEventListener("input",()=>{a.value=o.value.replace("#","").toUpperCase(),s.style.background=o.value}),o.addEventListener("change",c),a.addEventListener("change",c),r.addEventListener("change",c),i.appendChild(s),i.appendChild(a),i.appendChild(r),i.appendChild(l),ut("Overlay Color",i)}(e));const o=pt("div",{className:"gist-pb-checkbox-row"}),s=pt("input",{className:"gist-pb-checkbox",type:"checkbox"});s.checked=e.dismissOutsideClick??!1;const a=pt("label",{className:"gist-pb-checkbox-label",textContent:"Dismiss on click outside"});s.addEventListener("change",()=>wt({...Ke,dismissOutsideClick:s.checked})),a.addEventListener("click",()=>{s.checked=!s.checked,wt({...Ke,dismissOutsideClick:s.checked})}),o.appendChild(s),o.appendChild(a);const r=ut(" ",o);r.classList.add("gist-pb-label-group--grow"),r.firstChild.classList.add("gist-pb-label--spacer"),t.appendChild(r)}(Ke,o):"overlay"===a?function(e,t){const n=gt(Object.entries(Je).map(([e,t])=>({value:e,label:t})),e.overlayPosition||"topCenter");if(n.addEventListener("change",()=>wt({...Ke,overlayPosition:n.value})),t.appendChild(ut("Position",n)),!Y.includes(ne(e.overlayPosition))){const n=mt("number",e.maxWidth??414,"80px");n.addEventListener("change",()=>wt({...Ke,maxWidth:parseInt(n.value)||414})),t.appendChild(ut("Max Width",n))}}(Ke,o):"inline"===a?function(e,t){bt(e,t)}(Ke,o):"tooltip"===a&&function(e,t){const n=gt([{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],e.tooltipPosition||"top");n.addEventListener("change",()=>wt({...Ke,tooltipPosition:n.value})),t.appendChild(ut("Position",n)),bt(e,t)}(Ke,o),o.appendChild(pt("div",{className:"gist-pb-spacer"}));const r=pt("button",{type:"button",className:"gist-pb-save-btn",textContent:"End session"});r.addEventListener("click",async()=>{Ye&&await ln.dismissMessage(Ye)}),o.appendChild(r),e.appendChild(o)}async function Et(){if(!st)if(st=!0,F(),function(){try{sessionStorage.removeItem(o)}catch{}}(),ot){try{window.close()}catch{}try{window.location.reload()}catch{}rt&&rt(),it&&(clearInterval(it),it=null),St(),document.getElementById(Xe)?.remove(),document.getElementById(Ve)?.remove(),Ye=null,Qe=[],Ke={},Ze=null,tt=!1,nt=5,ot=!0,st=!1}else tt=!1,st=!1,$t()}function Ct(e){return ot?`<strong>Preview session ended.</strong> This tab will close in ${e}s…`:`<strong>Preview session ended.</strong> Finishing session in ${e}s… This tab will stay open.`}function kt(){tt&&it&&(ot=!1,$t())}function Pt(){et=!et;try{sessionStorage.setItem(Ge,String(et))}catch{}$t()}function Lt(e){if(tt)return;Ye=e.instanceId??null;const t=e.displaySettings;if(Array.isArray(t)&&t.length>0?(Qe=t,Ze||(Ze=Qe[0].stepName,Ke={...Qe[0].displaySettings})):t&&"object"==typeof t&&!Array.isArray(t)&&(Ke={...t}),lt||ct){const e=!!lt,t=!!ct,n=lt,o=ct;if(lt=null,ct=null,e){const e=Qe.find(e=>e.stepName===n);if(!e)return i(`Preview bar: step "${n}" not found, ignoring initial step/display override`),void $t();Ze=e.stepName,Ke={...e.displaySettings}}if(t){if(!e)return i(`Preview bar: display type "${o}" provided without a step, ignoring`),void $t();Ke={...Ke,displayType:o}}$t();const s=ln.currentMessages.find(e=>e.instanceId===Ye);return void(s&&ht(Ke)?Gt(s,Ze,Ke):function(){const e=Ke.displayType;if("inline"!==e&&"tooltip"!==e)return;const t=document.querySelector("#gist-preview-bar .gist-pb-input[type='text']");t&&It(t)}())}$t()}function Tt(){St(),Ye=null,Qe=[],Ke={},Ze=null,tt=!0,nt=5,ot=!0,st=!1;const e=new URLSearchParams(window.location.search).get(je);e&&async function(e){try{return await C()(`/api/v1/preview/${e}`,{method:"DELETE"})}catch(e){return E(e)}}(e).catch(()=>i("Failed to delete preview session")),$t(),it&&clearInterval(it),it=setInterval(async()=>{if(nt-=1,nt<=0)clearInterval(it),it=null,await Et();else{const e=document.querySelector(`#${Xe} .gist-pb-ended-text`);e?e.innerHTML=Ct(nt):$t()}},1e3)}async function Mt(e){if(!ln.isDocumentVisible)return i("Document hidden, not showing message now."),null;if(K(e.queueId))return i(`Message with queueId ${e.queueId} is already showing.`),null;const t=V(e);return!e.tooltipPosition&&t.hasTooltipPosition&&(e.tooltipPosition=t.tooltipPosition),e.tooltipPosition?function(e,t){const n=t.elementId||e.elementId;if(!n)return i(`No target selector specified for tooltip message ${e.messageId}`),ln.messageError(e),null;if(!j(n)){if(!ln.config.isPreviewSession||!e.properties?.gist?.livePreview)return i(`Tooltip target element "${n}" not found for message ${e.messageId}, skipping display`),ln.messageError(e),null;i(`Preview: tooltip target "${n}" not found, loading message for preview bar`)}const o=ln.currentMessages.find(e=>e.tooltipPosition&&e.elementId===n);o&&(i(`Tooltip already showing on target "${n}" (instance ${o.instanceId}), dismissing it first`),ln.messageDismissed(o),Se(o),o.instanceId&&ee(o.instanceId)),e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldResizeHeight=!1,e.shouldScale=!1,e.renderStartTime=(new Date).getTime(),e.elementId=n,ln.currentMessages.push(e);return zt(e,null,e.savedStepName||null)}(e,t):ln.overlayInstanceId?(i(`Message ${ln.overlayInstanceId} already showing.`),null):(e.instanceId=y(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),ln.overlayInstanceId=e.instanceId,ln.currentMessages.push(e),zt(e,null,e.savedStepName||null))}function Nt(e,t){return ln.isDocumentVisible?K(e.queueId)?(i(`Message with queueId ${e.queueId} is already showing.`),null):Z(t)?(i(`Message with elementId ${t} already has a message.`),null):(e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!fe(t),e.renderStartTime=(new Date).getTime(),ln.currentMessages.push(e),zt(e,t,e.savedStepName||null)):(i("Document hidden, not showing message now."),null)}async function Dt(e){e?(ln.messageDismissed(e),await At(e)):i("Message not found")}async function At(e){"tooltip"===ie(e)?Wt(e):e.overlay?await Ot(!0,e):Rt(e)}async function qt(e){e?V(e).persistent&&(i("Persistent message dismissed, logging view"),await Vt(e),await Bt(e),await Be(e.queueId??"")):i("Message not found")}function Rt(e){e.instanceId&&ee(e.instanceId),e.elementId&&me(e.elementId),ln.config.isPreviewSession&&(Tt(),Ut())}function Wt(e){Se(e),e.instanceId&&ee(e.instanceId),0===ln.currentMessages.length&&(window.removeEventListener("message",Ht),window.removeEventListener("touchstart",Ft)),ln.config.isPreviewSession&&(Tt(),Ut())}async function Ot(e,t){e?await be():ve(),0===ln.currentMessages.length&&(window.removeEventListener("message",Ht),window.removeEventListener("touchstart",Ft)),t.instanceId&&ee(t.instanceId),ln.overlayInstanceId=null,ln.config.isPreviewSession&&(Tt(),Ut())}function Ut(){const e=new URL(window.location.href);e.searchParams.delete(je),e.searchParams.delete(_e),history.replaceState(null,"",e.toString())}function zt(e,t=null,n=null){const o=ln.config.env,s={endpoint:I.ENGINE_API_ENDPOINT[o],siteId:ln.config.siteId,dataCenter:ln.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId??"",livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(Ce))},a=`${I.GIST_VIEW_ENDPOINT[o]}/index.html`;return window.addEventListener("message",Ht),window.addEventListener("touchstart",Ft),"tooltip"===ie(e)?function(e,t,n,i=null){const o=t.instanceId??"",s=Ie(o),a=V(t),r=xe.get(o);r&&(r.cleanup(),xe.delete(o)),document.querySelectorAll(`#gist-tooltip-${o}`).forEach(e=>{e.parentNode?.removeChild(e)});const l=`gist-tooltip-${o}`,c=document.createElement("div");c.id=l,c.innerHTML=function(e,t,n,i=""){let o=600;t.messageWidth>o&&(o=t.messageWidth);const s=t.tooltipArrowColor,a=function(e){switch(e){case"top":default:return"gist-arrow-bottom";case"bottom":return"gist-arrow-top";case"left":return"gist-arrow-right";case"right":return"gist-arrow-left"}}(t.tooltipPosition),r=i?`#${i} `:"";return`\n    <div class="gist-tooltip-outer">\n        <style>\n            ${r}.gist-tooltip-outer {\n                position: absolute;\n            }\n            ${r}.gist-tooltip-container {\n                position: relative;\n                z-index: 9999999;\n                opacity: 0;\n                transition: opacity 0.3s ease-in-out;\n            }\n            ${r}.gist-tooltip-container.gist-visible {\n                opacity: 1;\n            }\n            ${r}.gist-tooltip-frame-clip {\n                overflow: hidden;\n            }\n            ${r}.gist-tooltip-frame {\n                display: block;\n                width: ${t.messageWidth}px;\n                border: none;\n                transition: height 0.1s ease-in-out;\n            }\n            ${r}.gist-tooltip-arrow {\n                width: 0;\n                height: 0;\n                position: absolute;\n                z-index: 1;\n            }\n            ${r}.gist-tooltip-arrow.gist-arrow-bottom {\n                bottom: 0;\n                left: 50%;\n                transform: translateX(-50%) translateY(100%);\n                border-left: 10px solid transparent;\n                border-right: 10px solid transparent;\n                border-top: 10px solid ${s};\n            }\n            ${r}.gist-tooltip-arrow.gist-arrow-top {\n                top: 0;\n                left: 50%;\n                transform: translateX(-50%) translateY(-100%);\n                border-left: 10px solid transparent;\n                border-right: 10px solid transparent;\n                border-bottom: 10px solid ${s};\n            }\n            ${r}.gist-tooltip-arrow.gist-arrow-right {\n                right: 0;\n                top: 50%;\n                transform: translateY(-50%) translateX(100%);\n                border-top: 10px solid transparent;\n                border-bottom: 10px solid transparent;\n                border-left: 10px solid ${s};\n            }\n            ${r}.gist-tooltip-arrow.gist-arrow-left {\n                left: 0;\n                top: 50%;\n                transform: translateY(-50%) translateX(-100%);\n                border-top: 10px solid transparent;\n                border-bottom: 10px solid transparent;\n                border-right: 10px solid ${s};\n            }\n            @media (max-width: ${o}px) {\n                ${r}.gist-tooltip-frame {\n                    max-width: 100%;\n                }\n            }\n        </style>\n        <div class="gist-tooltip-container">\n            <div class="gist-tooltip-arrow ${a}"></div>\n            <div class="gist-tooltip-frame-clip">\n                <iframe id="${e}" class="gist-tooltip-frame" src="${n}"></iframe>\n            </div>\n        </div>\n    </div>`}(s,a,e,l),document.body.appendChild(c),he(s,n,i)}(a,e,s,n):t?(X.includes(t)&&J(t),function(e,t,n,o,s=null){const a=j(e);if(a){const i=Ie(n.instanceId??"");a.classList.add(i);const r=V(n);let l=r.messageWidth+"px";Y.includes(e)&&!r.hasCustomWidth&&(l="100%"),X.includes(e)&&(a.style.width=l),fe(e)||(a.style.height="0px"),a.innerHTML=function(e,t,n){return function(e,t,n){let i=800;return t.messageWidth>i&&(i=t.messageWidth),`\n    <div id="gist-embed">\n        <style>\n            #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n                position: fixed;\n                top: 0px;\n                z-index: 1000000;\n            }\n            #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n                position: fixed;\n                bottom: 0px;\n                z-index: 1000000;\n            }\n            #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n                left: 50%;\n                transform: translate(-50%, 0%);\n            }\n            #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n                right: 0px;\n            }\n            #gist-embed {\n                position: relative;\n                height: 100%;\n                width: 100%;\n            }\n            #gist-embed-container {\n                position: relative;\n                height: 100%;\n                width: 100%;\n            }\n            #gist-embed-container .gist-frame {\n                height: 100%;\n                width: 100%;\n                border: none;\n            }\n            #x-gist-top.${e},\n            #x-gist-bottom.${e},\n            #x-gist-floating-top.${e},\n            #x-gist-floating-bottom.${e},\n            #x-gist-floating-top-left.${e},\n            #x-gist-floating-top-right.${e},\n            #x-gist-floating-bottom-left.${e},\n            #x-gist-floating-bottom-right.${e} {\n                transition: height 0.1s ease-in-out;\n            }\n            @media (max-width: ${i}px) {\n                #x-gist-top.${e},\n                #x-gist-bottom.${e},\n                #x-gist-floating-top.${e},\n                #x-gist-floating-bottom.${e},\n                #x-gist-floating-top-left.${e},\n                #x-gist-floating-top-right.${e},\n                #x-gist-floating-bottom-left.${e},\n                #x-gist-floating-bottom-right.${e} {\n                    width: 100% !important;\n                }\n            }\n        </style>\n        <div id="gist-embed-container">\n            <iframe id="${e}" class="gist-frame" src="${n}"></iframe>\n        </div>\n    </div>`}(Ie(t.instanceId??""),n,e)}(t,n,r),he(i,o,s)}else i(`Message could not be embedded, elementId ${e} not found.`)}(t,a,e,s,n)):function(e,t,n,i=null){document.querySelectorAll("#gist-embed-message").forEach(e=>{e.parentNode?.removeChild(e)}),document.body.insertAdjacentHTML("afterbegin",function(e,t){const n=V(t);return function(e,t,n){let i=600;return t.messageWidth>i&&(i=t.messageWidth),`\n    <div id="gist-embed-message">\n        <style>\n            #gist-overlay.gist-background {\n                position: fixed;\n                z-index: 9999999998;\n                left: 0;\n                top: 0;\n                width: 100%;\n                height: 100%;\n                background-color: ${t.overlayColor};\n                visibility: hidden;\n            }\n            #gist-overlay.gist-background.gist-visible {\n                visibility: visible;\n            }\n            .gist-message {\n                width: ${t.messageWidth}px;\n                position: absolute;\n                border: none;\n                opacity: 0;\n                transition: opacity 0.3s ease-in-out, height 0.1s ease-in-out;\n                z-index: 9999999999;\n                left: 50%;\n                transform: translateX(-50%);\n            }\n            .gist-message.gist-visible {\n                opacity: 1;\n                pointer-events: auto;\n            }\n            .gist-message.gist-center {\n                transform: translate(-50%, -50%);\n                top: 50%;\n            }\n            .gist-message.gist-bottom {\n                bottom: 0;\n            }\n            .gist-message.gist-top {\n                top: 0;\n            }\n            @media (max-width: ${i}px) {\n                .gist-message {\n                    width: 100%;\n                }\n            }\n        </style>\n        <div id="gist-overlay" class="gist-background">\n            <iframe id="${e}" class="gist-message" src="${n}"></iframe>\n        </div>\n    </div>`}(Ie(t.instanceId??""),n,e)}(e,t)),he(Ie(t.instanceId??""),n,i)}(a,e,s,n),e}async function Bt(e){let t;i(`Message shown, logging view for: ${e.messageId}`),null!=e.queueId?(await Vt(e),t=await H(e.queueId)):t=await async function(e){try{return await C().post(`/api/v1/logs/message/${e}`)}catch(e){return E(e)}}(e.messageId),i(200===t?.status?"Message view logged":`Problem logging message: ${t?.status}`)}function Ft(){}async function Ht(e){const t=e.data;if(t.gist&&e.origin===I.RENDERER_HOST){const e=t.gist.instanceId,n=Q(e);if(!n)return;const o=V(n);switch(t.gist.method){case"routeLoaded":{const s=.001*((new Date).getTime()-(n.renderStartTime??0));if(i(`Engine render for message: ${n.messageId} timer elapsed in ${s.toFixed(3)} seconds`),async function(e){const t=await Ue(e);t&&r(t)}(n.queueId??""),n.currentRoute=t.gist.parameters.route,t.gist.parameters.fullDisplaySettings&&!n.displaySettings?n.displaySettings=t.gist.parameters.fullDisplaySettings:n.displaySettings&&(i("SDK already has display settings state, sending it to iframe"),ye(n)),ln.config.isPreviewSession&&n.properties?.gist?.livePreview&&Lt(n),n.firstLoad||n.isDisplayChange){if("tooltip"===ie(n)){const e=n.properties?.gist?.elementId||n.elementId||void 0;if(!e||!j(e)){if(ln.config.isPreviewSession&&n.properties?.gist?.livePreview){i(`Preview: tooltip target "${e}" not found, preview bar will show element picker`),n.firstLoad=!1,n.isDisplayChange=!1;break}i(`Tooltip target not found for "${e}", emitting error and skipping display`),ln.messageError(n),n.firstLoad=!1,n.isDisplayChange=!1,Wt(n);break}const t=await async function(e){const t=e.instanceId??"",n=V(e),o=`gist-tooltip-${t}`,s=j(o);if(!s)return i(`Tooltip wrapper not found for instance ${t}`),!1;const a=e.properties?.gist?.elementId||e.elementId||void 0;if(!a)return i(`No target selector for tooltip ${t}`),!1;const r=xe.get(t);r&&(r.cleanup(),xe.delete(t));const l=s.querySelector(".gist-tooltip-outer");if(!l)return i(`Tooltip inner element not found for instance ${t}`),!1;const c=n.tooltipPosition||"bottom";if(!await async function(e,t,n){const o=ce(t);if(!o)return!1;let s=[];try{s=ge(o)}catch{}if(de(o.getBoundingClientRect(),s))return!0;if(!function(e,t,n){const i=ce(t);if(!i)return!1;const o=i.getBoundingClientRect(),s=window.innerWidth,a=window.innerHeight,r=new DOMRect(Math.max(0,(s-o.width)/2),Math.max(0,(a-o.height)/2),o.width,o.height);return e.style.display="",null!==ue(e.getBoundingClientRect(),r,n)}(e,t,n))return i(`Preflight failed: tooltip would not fit after scrolling target "${t}" into view`),!1;o.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await function(e){return new Promise(t=>{let n=e.getBoundingClientRect(),i=0;const o=Date.now();setTimeout(function s(){const a=e.getBoundingClientRect();Math.abs(a.top-n.top)<1&&Math.abs(a.left-n.left)<1?i++:i=0,n=a,i>=2||Date.now()-o>1e3?t():setTimeout(s,50)},50)})}(o);const a=o.getBoundingClientRect();let r=[];try{r=ge(o)}catch{}return de(a,r)}(l,a,c))return i(`Tooltip for instance ${t} skipped: target "${a}" is off-screen and cannot be scrolled into a valid position`),!1;const d=function(e,t,n,o){const s=ce(t);if(!s)return null;let a=null,r=null,l=!1,c=[],d=null;try{c=ge(s)}catch{}function p(){if(l)return;if(!s||!document.contains(s)||!document.contains(e))return i("Tooltip or target element removed from DOM, cleaning up listeners"),g(),void o?.onDetach?.();const t=s.getBoundingClientRect();if(!de(t,c))return void(e.style.display="none");e.style.display="";const a=ue(e.getBoundingClientRect(),t,n);a?(function(e,t){e.style.position="absolute",e.style.top=`${t.top+window.scrollY}px`,e.style.left=`${t.left+window.scrollX}px`}(e,a),function(e,t){const n=e.querySelector(".gist-tooltip-arrow");n&&(n.classList.remove("gist-arrow-top","gist-arrow-bottom","gist-arrow-left","gist-arrow-right"),n.classList.add(le[t.position]),null!==t.arrowOffset?"top"===t.position||"bottom"===t.position?(n.style.left=`calc(50% + ${t.arrowOffset}px)`,n.style.removeProperty("top")):(n.style.top=`calc(50% + ${t.arrowOffset}px)`,n.style.removeProperty("left")):"top"===t.position||"bottom"===t.position?(n.style.left="50%",n.style.removeProperty("top")):(n.style.top="50%",n.style.removeProperty("left")))}(e,a)):e.style.display="none"}function u(){null===a&&(a=requestAnimationFrame(()=>{a=null,p()}))}function g(){if(!l){l=!0,d&&(d.disconnect(),d=null),window.removeEventListener("scroll",u),window.removeEventListener("resize",u);for(const e of c)e.removeEventListener("scroll",u);null!==a&&(cancelAnimationFrame(a),a=null),null!==r&&(cancelAnimationFrame(r),r=null)}}if(p(),l)return null;window.addEventListener("scroll",u,{passive:!0}),window.addEventListener("resize",u,{passive:!0});for(const e of c)e.addEventListener("scroll",u,{passive:!0});try{d=new MutationObserver(()=>{null===r&&(r=requestAnimationFrame(()=>{r=null,document.contains(s)||p()}))}),d.observe(document.body,{childList:!0,subtree:!0})}catch{}return{cleanup:g,reposition:p}}(l,a,c,{onDetach:()=>{xe.delete(t);const e=j(o);e&&e.parentNode?.removeChild(e)}});if(d){if("none"!==l.style.display){const e=s.querySelector(".gist-tooltip-container");return e?(xe.set(t,d),e.classList.add("gist-visible"),!0):(d.cleanup(),i(`Tooltip container not found for instance ${t}`),!1)}return d.cleanup(),i(`Tooltip for instance ${t} could not be positioned within the viewport, target "${a}" may be off-screen`),!1}return i(`Failed to position tooltip for instance ${t}, target "${a}" may not exist or no position fits the viewport`),!1}(n);if(!t){if(ln.config.isPreviewSession&&n.properties?.gist?.livePreview){i(`Preview: tooltip positioning failed for "${e}", preview bar will remain active`),n.firstLoad=!1,n.isDisplayChange=!1;break}i(`Tooltip positioning failed for "${e}", emitting error and cleaning up`),ln.messageError(n),n.firstLoad=!1,n.isDisplayChange=!1,Wt(n);break}}else n.overlay?function(e){const t=V(e),n=document.querySelector("#gist-overlay");if(n){n.classList.add("gist-visible");const i=document.querySelector(".gist-message");i&&(e.position?i.classList.add("gist-"+e.position):i.classList.add("gist-center")),setTimeout($e,100),t.exitClick&&setTimeout(()=>function(e){const t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",()=>{ln.dismissMessage(e)})}(e.instanceId??""),1e3)}else ve()}(n):function(e){const t=j(e);t&&t.classList.add("gist-visible")}(n.elementId);n.firstLoad&&!n.isDisplayChange&&(ln.messageShown(n),o.persistent?i("Persistent message shown, skipping logging view"):await Bt(n)),n.firstLoad=!1,n.isDisplayChange=!1}te(e,n);break}case"tap":{const e=t.gist.parameters.action,i=t.gist.parameters.name;if(ln.messageAction(n,e,i),t.gist.parameters.system&&!o.persistent){await Dt(n);break}try{const t=new URL(e);if(t&&"gist:"===t.protocol)switch(t.href.replace("gist://","").split("?")[0]){case"close":await qt(n),await Xt(n),await Dt(n),await on();break;case"showMessage":{const e=t.searchParams.get("messageId"),n=t.searchParams.get("properties");if(e){const t=n?JSON.parse(atob(n)):void 0;await ln.showMessage({messageId:e,properties:t})}break}case"loadPage":{const e=t.href.substring(t.href.indexOf("?url=")+5);e&&(e.startsWith("mailto:")||e.startsWith("https://")||e.startsWith("http://")||e.startsWith("/")?window.location.href=e:window.location.href=window.location+e);break}}}catch{}break}case"changeMessageStep":{const e=t.gist.parameters.displaySettings,r=t.gist.parameters.messageStepName;ln.config.isPreviewSession&&r&&n.properties?.gist?.livePreview&&function(e,t){if(tt)return;Ze=e;const n=Qe.find(t=>t.stepName===e);n?Ke={...n.displaySettings}:t&&(Ke={...t}),$t()}(r,e),(o.persistent||Me(n))&&await async function(e,t,n){const o=await ze(e);if(!o)return;const r=a(o)||{},l={stepName:void 0!==t?t:r.stepName,displaySettings:void 0!==n?n:r.displaySettings},c=new Date;c.setDate(c.getDate()+30),s(o,l,c),i(`Saved message state for queueId: ${e}`)}(n.queueId??"",r,e),e&&oe(n,e)&&(i("Display settings changed, reloading message"),await _t(n),se(n,e),await jt(n,r??null));break}case"routeChanged":n.currentRoute=t.gist.parameters.route,n.renderStartTime=(new Date).getTime(),te(e,n),i(`Route changed to: ${n.currentRoute}`);break;case"sizeChanged":i(`Size Changed Width: ${t.gist.parameters.width} - Height: ${t.gist.parameters.height}`),"tooltip"===ie(n)?function(e,t){const n=e.instanceId??"",i=Ie(n),o=document.getElementById(i);if(o&&t.height>0){o.style.height=`${t.height}px`;const e=xe.get(n);e&&e.reposition()}}(n,t.gist.parameters):n.elementId&&!n.shouldResizeHeight||function(e,t){const n=j(e.elementId?e.elementId:Ie(e.instanceId??""));if(n){const i=n.style;if(t.height>0)if(t.height>window.innerHeight){const n=1-(t.height/window.innerHeight-1);e.shouldScale&&n>=.4?(i.height=`${t.height}px`,i.transform=`translateX(-50%) translateY(-50%) scale(${n})`):i.height=`${window.innerHeight}px`}else i.height=`${t.height}px`}}(n,t.gist.parameters);break;case"titleChanged":i(`Overlay title changed to: ${t.gist.parameters.title}`),function(e,t){const n=j(Ie(e));n&&(n.title=t)}(e,t.gist.parameters.title);break;case"eventDispatched":ln.events.dispatch("eventDispatched",{name:t.gist.parameters.name,payload:t.gist.parameters.payload});break;case"error":case"routeError":ln.messageError(n),"tooltip"===ie(n)?Wt(n):ln.overlayInstanceId?await Ot(!1,n):Rt(n)}}}async function jt(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();const n=ie(e),o=e.elementId||null;if("tooltip"===n)return ln.overlayInstanceId===e.instanceId&&(ln.overlayInstanceId=null),e.shouldScale=!1,e.shouldResizeHeight=!1,void zt(e,null,t);if(o){const t=Z(o);t&&t.instanceId!==e.instanceId&&(i(`Dismissing existing message at ${o} to make room for multi-step message`),await Dt(t))}if(e.overlay){ln.overlayInstanceId=e.instanceId??null;const t=V(e);e.shouldScale=t.shouldScale,e.shouldResizeHeight=!0}else ln.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!fe(o??"");o&&X.includes(o)&&J(o),zt(e,o,t)}async function _t(e){"tooltip"===ie(e)?Se(e):e.overlay?await be():e.elementId&&me(e.elementId)}async function Gt(e,t,n){n&&oe(e,n)&&(await _t(e),se(e,n)),await jt(e,t??null)}async function Vt(e){i(`Logging user message view locally for: ${e.queueId}`),Te(e)?await async function(e){i(`Marking broadcast ${e} as seen.`);const t=await Ne();if(!t)return;const n=await Le(t,e);if(!n)return;const o=n.properties.gist.broadcast,{frequency:r}=o,l=De(t,e),c=Ae(t,e),d=a(l)||0;if(s(l,d+1),1===r.count)s(c,!1),i(`Marked broadcast ${e} as seen.`);else{const t=new Date;t.setSeconds(t.getSeconds()+r.delay),s(c,!1,t),i(`Marked broadcast ${e} as seen, broadcast was seen ${d+1} times, next show date is ${t}.`)}}(e.queueId??""):await async function(e){const t=await Oe();if(!t)return;const n=a(t)??[];n.push(e),s(t,n)}(e.queueId??"")}async function Xt(e){Te(e)&&(i(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){i(`Marking broadcast ${e} as dismissed.`);const t=await Ne();if(!t)return;const n=await Le(t,e);n&&(!0!==n.properties.gist.broadcast.frequency.ignoreDismiss?(s(Ae(t,e),!1),i(`Marked broadcast ${e} as dismissed and will not show again.`)):i(`Broadcast ${e} is set to ignore dismiss.`))}(e.queueId??""),await Be(e.queueId??""))}const Jt="messageInboxUpdated";async function Yt(e){const t=await Kt();if(!t)return;const n=new Date;n.setMinutes(n.getMinutes()+60),s(t,e,n),ln.events.dispatch(Jt,e)}async function Qt(){const e=await Kt();if(!e)return[];const t=a(e)??[],n=new Date;return t.filter(e=>!e.expiry||new Date(e.expiry)>n)}async function Kt(){const e=await z();return e?`gist.web.inbox.messages.${e}`:null}const Zt=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>Zt(e,t)));let en=!1,tn=null;async function nn(){en?await on():O()?(i("Queue watcher started"),en=!0,Zt(()=>new Promise(()=>{!async function(){if(I.hasActiveSSEConnection())return!I.isSSEConnectionManagedBySDK()&&tn&&(i("Not the main instance, closing our SSE connection."),rn()),void await on();tn&&(i("SSE connection not active, closing it."),rn()),!I.useSSE()||W()?await an():await async function(){rn();const e=function(){const e=B();return null===e?(i("No user token available for SSE endpoint."),null):I.GIST_QUEUE_REALTIME_API_ENDPOINT[ln.config.env??"prod"]+`/api/v3/sse?userToken=${e}&siteId=${ln.config.siteId}&sessionId=${D()}`}();if(null===e)return i("SSE endpoint not available, falling back to polling."),void await an();i(`Starting SSE queue listener on ${e}`),tn=new EventSource(e),I.setActiveSSEConnection(),tn.addEventListener("connected",async e=>{try{i("SSE connection received"),I.setUseSSEFlag(!0);const t=JSON.parse(e.data);t.heartbeat&&(I.setSSEHeartbeat(t.heartbeat),i(`SSE heartbeat set to ${t.heartbeat} seconds`)),I.setActiveSSEConnection()}catch(e){i(`Failed to parse SSE settings: ${e}`)}r(M),await an()}),tn.addEventListener("messages",async e=>{try{const t=JSON.parse(e.data);i("SSE message received"),await Re(t),await Pe(t),await on()}catch(e){i(`Failed to parse SSE message: ${e}`),rn()}}),tn.addEventListener("inbox_messages",async e=>{try{const t=JSON.parse(e.data);i("SSE inbox messages received"),await Yt(t)}catch(e){i(`Failed to parse SSE inbox messages: ${e}`)}}),tn.addEventListener("error",async()=>{i("SSE error received"),rn()}),tn.addEventListener("heartbeat",async()=>{i("SSE heartbeat received"),I.setActiveSSEConnection(),I.setUseSSEFlag(!0)})}()}()}),1e3)):i("User token not setup, queue not started.")}async function on(){const e=await async function(){const e=await Ne();return e?(a(e)??[]).filter(t=>{const n=t.properties.gist.broadcast,{frequency:i}=n,o=a(Ae(e,t.queueId))??!0,s=a(De(e,t.queueId))||0,r=0===i.count;return o&&(r||s<i.count)}):[]}(),t=await async function(){const e=await We();if(!e)return[];const t=a(e)??[],n=await async function(){const e=await Oe();return e?a(e)??[]:[]}();return t.filter(e=>!n.includes(e.queueId??""))}(),n=e.concat(t);i(`Messages in local queue: ${n.length}`);const o=n.sort((e,t)=>e.priority-t.priority);for(const e of o)await sn(e)}async function sn(e){let t=V(e);if(t.hasRouteRule){let e=ln.currentRoute;null==e&&(e=new URL(window.location.href).pathname);const n=t.routeRule;if(i(`Verifying route ${e} against rule: ${n}`),!new RegExp(n).test(e))return i(`Route ${e} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),t.hasTooltipPosition&&(e.tooltipPosition=t.tooltipPosition),t.persistent||Me(e)){const n=await async function(e){const t=await ze(e);return t?a(t):null}(e.queueId??"");n&&(i(`Restoring saved state for queueId ${e.queueId}`),n.displaySettings&&(se(e,n.displaySettings),t=V(e)),e.savedStepName=n.stepName??null)}if(t.persistent||Me(e)||!await async function(e){const t=await Ue(e);return!!t&&null!==a(t)}(e.queueId??"")){let n=null;return t.isEmbedded?!ln.config.isPreviewSession||!e.properties?.gist?.livePreview||j(t.elementId)||X.includes(t.elementId)?n=Nt(e,t.elementId):(i(`Preview: element "${t.elementId}" not found, showing as overlay so placement can be changed`),n=await Mt(e)):n=await Mt(e),n&&async function(e){const t=await Ue(e);t&&s(t,!0,new Date(Date.now()+5e3))}(e.queueId??""),null!==n}return i(`Not showing message with queueId ${e.queueId} because its already loading.`),!1}async function an(){if(O())if(ln.isDocumentVisible)if(null===a(M)){const e=await async function(){const e=O();let t;try{if(!T){T=!0;const e={"X-Gist-User-Anonymous":String(W()),"Content-Language":String(P())};t=await C().post(`/api/v4/users?sessionId=${D()}`,{},{headers:e})}}catch(e){const n=E(e);n?t=n:i(`Error getting user queue: ${e}`)}finally{T=!1}return e!==O()?(i("User token changed, clearing queue next pull check."),void r(M)):(function(e){if(e?.headers){const t=e.headers["x-gist-queue-polling-interval"];t&&Number(t)>0&&(L=Number(t))}const t=new Date((new Date).getTime()+1e3*L);s(M,L,t)}(t),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();I.setUseSSEFlag(t)}(t),t)}();if(e){if(200===e.status||204===e.status){i("200 response, updating local store.");const t=e.data,n=t?.inAppMessages??[],o=t?.inboxMessages??[];Re(n),Pe(n),Yt(o)}else 304===e.status&&i("304 response, using local store.");await on()}else i("No response object returned while checking message queue.")}else i("Next queue pull scheduled for later.");else i("Document not visible, skipping queue check.");else i("User token reset, skipping queue check.")}function rn(e=!1){e&&I.removeActiveSSEConnection(),(e||I.isSSEConnectionManagedBySDK())&&I.setUseSSEFlag(!1),tn&&(i("Stopping SSE queue listener..."),tn.close(),tn=null)}class ln{static async setup(e){this.initialized?i("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new n,this.config={useAnonymousSession:e.useAnonymousSession??!1,siteId:e.siteId,dataCenter:e.dataCenter,env:e.env??"prod",logging:e.logging??!1,experiments:e.experiments??!1},this.currentMessages=[],xe.forEach(e=>e.cleanup()),xe.clear(),document.querySelectorAll('[id^="gist-tooltip-"]').forEach(e=>{e.parentNode?.removeChild(e)}),this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,this.config.isPreviewSession=function(){const e=new URLSearchParams(window.location.search),t=e.get(je);if(t){sessionStorage.setItem(o,String(!1)),ln.setUserToken(t),i(`Preview mode enabled with user token: ${t}`),function(){if(document.getElementById(Xe))return;!function(){if(document.getElementById(Ve))return;const e=document.createElement("style");e.id=Ve,e.textContent=He,document.head.appendChild(e)}();try{et="true"===sessionStorage.getItem(Ge)}catch{et=!1}const e=pt("div",{id:Xe});document.body.appendChild(e),$t()}();const n=e.get(_e);if(n)try{const e=JSON.parse(atob(n)),t=e.stepName||null,i=e.displayType||null;(t||i)&&function(e,t){lt=e,ct=t}(t,i)}catch{i("Preview bar: failed to parse cioPreviewSettings")}}return!l()}(),function(){const e=c();for(let t=e.length-1;t>=0;t--){const n=e.key(t);n?.startsWith("gist.")&&d(n)}}(),i(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||U(),await nn(),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await on())},!1))}static async setCurrentRoute(e){this.currentRoute=e,i(`Current route set to: ${e}`),await async function(){if(0!==ln.currentMessages.length)for(const e of[...ln.currentMessages])null==document.querySelector(`#gist-${e.instanceId}`)&&(i(`Removing active message ${e.instanceId} that no longer exists after route change`),await At(e))}(),await on()}static async setUserToken(e,t){this.config.isPreviewSession||(function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),s(A,e,t),W()&&(r(M),r(q)),i(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),rn(!0),await nn())}static setUserLocale(e){var t;s(k,t=e),i(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(Ce.set(e,t),ke(),i(`Set custom attribute "${e}" to "${t}"`),!0):(i(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){Ce.clear(),r(Ee),i("Cleared all custom attributes")}static removeCustomAttribute(e){return function(e){if(!e||"string"!=typeof e)return i(`Invalid key for custom attribute: ${e}`),!1;const t=Ce.has(e);return Ce.delete(e),Ce.size>0?ke():r(Ee),i(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(F(),this.config.useAnonymousSession&&U(),rn(!0),await nn())}static async dismissMessage(e){const t=Q(e);t&&(await qt(t),await Xt(t),await Dt(t),await on())}static async embedMessage(e,t){const n=Nt(e,t);return n?.instanceId??null}static async showMessage(e){const t=await Mt(e);return t?.instanceId??null}static updateMessageDisplaySettings(e,t){const n=Q(e);return!!n&&(n.displaySettings=t,ye(n),!0)}static messageShown(e){i(`Message shown: ${e.messageId}`),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(i(`Message dismissed: ${e.messageId}`),this.events.dispatch("messageDismissed",e))}static messageError(e){i(`Message error: ${e.messageId}`),this.events.dispatch("messageError",e)}static messageAction(e,t,n){i(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}static async getInboxUnopenedCount(){return(await Qt()).filter(e=>!e.opened).length}static async getInboxMessages(){return await Qt()}static async updateInboxMessageOpenState(e,t){return await async function(e,t){const n=await Kt();if(!n)return;const o=await async function(e,t){try{return await C()(`/api/v1/messages/${e}`,{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return E(e)}}(e,{opened:t});if(!o||o.status<200||o.status>=300){const e=`Failed to mark inbox message opened: ${o?.status??"unknown error"}`;throw i(e),new Error(e)}const a=await Qt();let r=null;const l=a.map(n=>{if(n.queueId===e){const e={...n,opened:t};return r=e,e}return n}),c=new Date;if(c.setMinutes(c.getMinutes()+60),s(n,l,c),r){const e=t?"opened":"unopened";ln.events.dispatch("inboxMessageAction",{message:r,action:e})}ln.events.dispatch(Jt,await Qt())}(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await Kt();if(!t)return;const n=await H(e);if(!n||n.status<200||n.status>=300){const e=`Failed to remove inbox message: ${n?.status??"unknown error"}`;throw i(e),new Error(e)}const o=(await Qt()).filter(t=>t.queueId!==e),a=new Date;a.setMinutes(a.getMinutes()+60),s(t,o,a),ln.events.dispatch(Jt,await Qt())}(e)}}return t.default})());