!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,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=11)}([function(e,t,n){"use strict";var r=n(2),s=Object.prototype.toString;function i(e){return"[object Array]"===s.call(e)}function o(e){return void 0===e}function a(e){return null!==e&&"object"==typeof e}function u(e){if("[object Object]"!==s.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function c(e){return"[object Function]"===s.call(e)}function d(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),i(e))for(var n=0,r=e.length;n=200&&e<300}};u.headers={common:{Accept:"application/json, text/plain, */*"}},r.forEach(["delete","get","head"],(function(e){u.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){u.headers[e]=r.merge(i)})),e.exports=u}).call(this,n(17))},function(e,t,n){"use strict";var r=n(0),s=n(19),i=n(21),o=n(3),a=n(22),u=n(25),c=n(26),d=n(7);e.exports=function(e){return new Promise((function(t,n){var f=e.data,l=e.headers;r.isFormData(f)&&delete l["Content-Type"];var p=new XMLHttpRequest;if(e.auth){var g=e.auth.username||"",h=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";l.Authorization="Basic "+btoa(g+":"+h)}var m=a(e.baseURL,e.url);if(p.open(e.method.toUpperCase(),o(m,e.params,e.paramsSerializer),!0),p.timeout=e.timeout,p.onreadystatechange=function(){if(p&&4===p.readyState&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))){var r="getAllResponseHeaders"in p?u(p.getAllResponseHeaders()):null,i={data:e.responseType&&"text"!==e.responseType?p.response:p.responseText,status:p.status,statusText:p.statusText,headers:r,config:e,request:p};s(t,n,i),p=null}},p.onabort=function(){p&&(n(d("Request aborted",e,"ECONNABORTED",p)),p=null)},p.onerror=function(){n(d("Network Error",e,null,p)),p=null},p.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(d(t,e,"ECONNABORTED",p)),p=null},r.isStandardBrowserEnv()){var v=(e.withCredentials||c(m))&&e.xsrfCookieName?i.read(e.xsrfCookieName):void 0;v&&(l[e.xsrfHeaderName]=v)}if("setRequestHeader"in p&&r.forEach(l,(function(e,t){void 0===f&&"content-type"===t.toLowerCase()?delete l[t]:p.setRequestHeader(t,e)})),r.isUndefined(e.withCredentials)||(p.withCredentials=!!e.withCredentials),e.responseType)try{p.responseType=e.responseType}catch(t){if("json"!==e.responseType)throw t}"function"==typeof e.onDownloadProgress&&p.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&p.upload&&p.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then((function(e){p&&(p.abort(),n(e),p=null)})),f||(f=null),p.send(f)}))}},function(e,t,n){"use strict";var r=n(20);e.exports=function(e,t,n,s,i){var o=new Error(e);return r(o,t,n,s,i)}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){t=t||{};var n={},s=["url","method","data"],i=["headers","auth","proxy","params"],o=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],a=["validateStatus"];function u(e,t){return r.isPlainObject(e)&&r.isPlainObject(t)?r.merge(e,t):r.isPlainObject(t)?r.merge({},t):r.isArray(t)?t.slice():t}function c(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(e[s],t[s])}r.forEach(s,(function(e){r.isUndefined(t[e])||(n[e]=u(void 0,t[e]))})),r.forEach(i,c),r.forEach(o,(function(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(void 0,t[s])})),r.forEach(a,(function(r){r in t?n[r]=u(e[r],t[r]):r in e&&(n[r]=u(void 0,e[r]))}));var d=s.concat(i).concat(o).concat(a),f=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===d.indexOf(e)}));return r.forEach(f,c),n}},function(e,t,n){"use strict";function r(e){this.message=e}r.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},r.prototype.__CANCEL__=!0,e.exports=r},function(e,t,n){e.exports=n(12)},function(e,t,n){const r=n(32).default;e.exports=r},function(e,t,n){"use strict";var r=n(0),s=n(2),i=n(13),o=n(8);function a(e){var t=new i(e),n=s(i.prototype.request,t);return r.extend(n,i.prototype,t),r.extend(n,t),n}var u=a(n(5));u.Axios=i,u.create=function(e){return a(o(u.defaults,e))},u.Cancel=n(9),u.CancelToken=n(27),u.isCancel=n(4),u.all=function(e){return Promise.all(e)},u.spread=n(28),u.isAxiosError=n(29),e.exports=u,e.exports.default=u},function(e,t,n){"use strict";var r=n(0),s=n(3),i=n(14),o=n(15),a=n(8);function u(e){this.defaults=e,this.interceptors={request:new i,response:new i}}u.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=a(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=[o,void 0],n=Promise.resolve(e);for(this.interceptors.request.forEach((function(e){t.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((function(e){t.push(e.fulfilled,e.rejected)}));t.length;)n=n.then(t.shift(),t.shift());return n},u.prototype.getUri=function(e){return e=a(this.defaults,e),s(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},r.forEach(["delete","get","head","options"],(function(e){u.prototype[e]=function(t,n){return this.request(a(n||{},{method:e,url:t,data:(n||{}).data}))}})),r.forEach(["post","put","patch"],(function(e){u.prototype[e]=function(t,n,r){return this.request(a(r||{},{method:e,url:t,data:n}))}})),e.exports=u},function(e,t,n){"use strict";var r=n(0);function s(){this.handlers=[]}s.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},s.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},s.prototype.forEach=function(e){r.forEach(this.handlers,(function(t){null!==t&&e(t)}))},e.exports=s},function(e,t,n){"use strict";var r=n(0),s=n(16),i=n(4),o=n(5);function a(e){e.cancelToken&&e.cancelToken.throwIfRequested()}e.exports=function(e){return a(e),e.headers=e.headers||{},e.data=s(e.data,e.headers,e.transformRequest),e.headers=r.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),r.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||o.adapter)(e).then((function(t){return a(e),t.data=s(t.data,t.headers,e.transformResponse),t}),(function(t){return i(t)||(a(e),t&&t.response&&(t.response.data=s(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t,n){return r.forEach(n,(function(n){e=n(e,t)})),e}},function(e,t){var n,r,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(e){r=o}}();var u,c=[],d=!1,f=-1;function l(){d&&u&&(d=!1,u.length?c=u.concat(c):f=-1,c.length&&p())}function p(){if(!d){var e=a(l);d=!0;for(var t=c.length;t;){for(u=c,c=[];++f1)for(var n=1;n=0)return;o[t]="set-cookie"===t?(o[t]?o[t]:[]).concat([n]):o[t]?o[t]+", "+n:n}})),o):o}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function s(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=s(window.location.href),function(t){var n=r.isString(t)?s(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";var r=n(9);function s(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}s.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},s.source=function(){var e;return{token:new s((function(t){e=t})),cancel:e}},e.exports=s},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){"use strict";e.exports=function(e){return"object"==typeof e&&!0===e.isAxiosError}},function(e,t){e.exports='
'},function(e,t){e.exports='
'},function(e,t,n){"use strict";n.r(t);class r{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}dispatch(e,t){var n=this[e];n&&n.forEach(e=>e(t))}}function s(e){Z.config.logging&&console.log("Gist: "+e)}function i(e,t,n){const r={value:t,expiry:n};localStorage.setItem(e,JSON.stringify(r))}function o(e){const t=localStorage.getItem(e);if(!t)return null;const n=JSON.parse(t),r=new Date,s=new Date(n.expiry);return r.getTime()>s.getTime()?(localStorage.removeItem(e),null):n.value}function a(e){localStorage.removeItem(e)}var u,c=new Uint8Array(16);function d(){if(!u&&!(u="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 u(c)}var f=/^(?:[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 l=function(e){return"string"==typeof e&&f.test(e)},p=[],g=0;g<256;++g)p.push((g+256).toString(16).substr(1));var h=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(p[e[t+0]]+p[e[t+1]]+p[e[t+2]]+p[e[t+3]]+"-"+p[e[t+4]]+p[e[t+5]]+"-"+p[e[t+6]]+p[e[t+7]]+"-"+p[e[t+8]]+p[e[t+9]]+"-"+p[e[t+10]]+p[e[t+11]]+p[e[t+12]]+p[e[t+13]]+p[e[t+14]]+p[e[t+15]]).toLowerCase();if(!l(n))throw TypeError("Stringified UUID is invalid");return n};var m=function(e,t,n){var r=(e=e||{}).random||(e.rng||d)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var s=0;s<16;++s)t[n+s]=r[s];return t}return h(r)};function v(){return o("gist.web.userToken")}function y(){var e=new Date;if(e.setDate(e.getDate()+365),null===v()){var t=o("gist.web.guestUserToken");null==t&&(i("gist.web.guestUserToken",t=m(),e),s(`Set guest user token "${t}" with expiry date set to 1 year from today`)),i("gist.web.userToken",t,e),i("gist.web.usingGuestUserToken",!0,e)}}var w=n(10),b=n.n(w);const x={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_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/2.0",dev:"https://renderer.gist.build/2.0",local:"http://app.local.gist.build:8080/web"}};function I(){var e={"X-CIO-Site-Id":Z.config.siteId,"X-CIO-Datacenter":Z.config.dataCenter},t=v();return null!=t&&(e["X-Gist-Encoded-User-Token"]=btoa(t)),b.a.create({baseURL:x.GIST_QUEUE_API_ENDPOINT[Z.config.env],timeout:2e4,headers:e})}function S(e){var t="",n="",r="",s=!1,i=!1,o=!1,a=!1,u=null,c=!1,d="#00000033",f=414,l=!1;return e.properties&&e.properties.gist&&(e.properties.gist.campaignId&&(u=e.properties.gist.campaignId),e.properties.gist.elementId&&(t=e.properties.gist.elementId,s=!0),e.properties.gist.routeRuleWeb&&(n=e.properties.gist.routeRuleWeb,i=!0),e.properties.gist.position&&(r=e.properties.gist.position,o=!0),e.properties.gist.scale&&(a=e.properties.gist.scale),e.properties.gist.overlayColor&&(d=e.properties.gist.overlayColor),e.properties.gist.messageWidth&&e.properties.gist.messageWidth>0&&(f=e.properties.gist.messageWidth,l=!0),e.properties.gist.persistent&&(c=!0)),{isEmbedded:s,elementId:t,hasRouteRule:i,routeRule:n,position:r,hasPosition:o,shouldScale:a,campaignId:u,messageWidth:f,overlayColor:d,persistent:c,hasCustomWidth:l}}const T=e=>new Promise(t=>setTimeout(t,e));function E(e,t,r){var i=N(e);i?(C(e)||(i.style.height="0px"),i.innerHTML=function(e,t){var r=S(t),s=800;r.messageWidth>s&&(s=r.messageWidth);var i=r.messageWidth+"px";["x-gist-bottom","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"].includes(r.elementId)&&!r.hasCustomWidth&&(i="100%");var o=n(30);return o=(o=(o=(o=o.replace("'${topBottomMessageWidth}'",i)).replace("'${cornersMessageWidth}'",i)).replace("'${maxWidth}'",s+"px")).replace("${url}",e)}(t,r)):s(`Message could not be embedded, elementId ${e} not found.`)}function C(e){var t=N(e);if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function R(e,t,n){var r=N(e);if(r){var s=r.style;if(t.height>0)if(t.height>window.innerHeight){var i=1-(t.height/window.innerHeight-1);n&&i>=.4?(s.height=t.height+"px",s.transform=`translateX(-50%) translateY(-50%) scale(${i})`):s.height=window.innerHeight+"px"}else s.height=t.height+"px"}}function k(e,t){document.body.insertAdjacentHTML("beforeend",function(e,t){var r=S(t),s=600;r.messageWidth>s&&(s=r.messageWidth);var i=n(31);return i=(i=(i=(i=(i=i.replace("'${messageWidth}'",r.messageWidth+"px")).replace("'${maxWidth}'",s+"px")).replace("'${overlayColor}'",r.overlayColor)).replace("${url}",e)).replace("${instanceId}",t.instanceId)}(e,t))}function O(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function L(){var e=document.querySelector("#gist-message");e&&e.classList.add("visible")}function N(e){try{var t=document.querySelector("#"+e);return t||null}catch{return null}}var P=["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"];var j=[];async function D(e){if(Z.isDocumentVisible){if(Z.overlayInstanceId)return s(`Message ${Z.overlayInstanceId} already showing.`),null;var t=S(e);return e.instanceId=m(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),Z.overlayInstanceId=e.instanceId,Z.currentMessages.push(e),B(e)}return s("Document hidden, not showing message now."),null}async function U(e,t){return Z.isDocumentVisible?(e.instanceId=m(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!C(t),e.renderStartTime=(new Date).getTime(),Z.currentMessages.push(e),B(e,t)):(s("Document hidden, not showing message now."),null)}async function A(e){e?(Z.messageDismissed(e),e.overlay?await M(!0,e):q(e)):s(`Message with instance id: ${instanceId} not found`)}async function $(e){var t=S(e);e?t.persistent&&(s("Persistent message dismissed, logging view"),await W(e)):s(`Message with instance id: ${instanceId} not found`)}function q(e){var t,n;G(e.instanceId),t=e.elementId,(n=N(t))&&(n.classList.remove("gist-visible"),n.style.removeProperty("height"),n.innerHTML="")}async function M(e,t){G(t.instanceId),Z.overlayInstanceId=null,e?await async function(){var e=document.querySelector("#gist-message");e&&(e.classList.remove("visible"),await T(300)),O()}():O(),0==Z.currentMessages.length&&(window.removeEventListener("message",z),window.removeEventListener("touchstart",V))}function B(e,t=null){if(t&&function(e){var t=N(e);return!(!t||!t.classList.contains("gist-visible"))}(t))return s(`Message ${e.messageId} already showing in element ${t}.`),null;var n,r,i={endpoint:x.ENGINE_API_ENDPOINT[Z.config.env],siteId:Z.config.siteId,dataCenter:Z.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId,livePreview:!1,properties:e.properties},o=`${x.GIST_VIEW_ENDPOINT[Z.config.env]}/index.html?options=${n=JSON.stringify(i),r=btoa(encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)}))),encodeURIComponent(r)}`;return window.addEventListener("message",z),window.addEventListener("touchstart",V),t?(P.includes(t)&&function(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)}s("Top & bottom elements injected into page")}(t),E(t,o,e)):k(o,e),e}async function W(e){s("Message shown, logging view for: "+e.messageId);var t={};200===(t=null!=e.queueId?await async function(e){try{return await I().post("/api/v1/logs/queue/"+e)}catch(e){return e.response}}(e.queueId):await async function(e){try{return await I().post("/api/v1/logs/message/"+e)}catch(e){return e.response}}(e.messageId)).status?s("Message view logged"):s("Problem logging message: "+t.status)}function _(e){return Z.currentMessages.find(t=>t.instanceId===e)}function G(e){Z.currentMessages=Z.currentMessages.filter(t=>t.instanceId!==e)}function H(e,t){G(e),Z.currentMessages.push(t)}function V(e){}async function z(e){if(e.data.gist){var t=e.data.gist.instanceId,n=_(t);if(!n)return;var r=S(n);switch(e.data.gist.method){case"routeLoaded":var i=.001*((new Date).getTime()-n.renderStartTime);s(`Engine render for message: ${n.messageId} timer elapsed in ${i.toFixed(3)} seconds`),n.currentRoute=e.data.gist.parameters.route,n.firstLoad&&(j.push(n),n.overlay?function(e){var t=document.querySelector("#gist-overlay");if(t){t.classList.add("visible");var n=document.querySelector("#gist-message");e.position?n.classList.add(e.position):n.classList.add("center"),setTimeout(L,100)}else O()}(n):(f=n.elementId,(l=N(f))&&l.classList.add("gist-visible")),Z.messageShown(n),r.persistent?s("Persistent message shown, skipping logging view"):await W(n),n.firstLoad=!1),H(t,n);break;case"tap":var o=e.data.gist.parameters.action,a=e.data.gist.parameters.name;if(Z.messageAction(n,o,a),e.data.gist.parameters.system&&!r.persistent){await A(n);break}try{if((d=new URL(o))&&"gist:"===d.protocol)switch(d.href.replace("gist://","").split("?")[0]){case"close":await A(n),await $(n),await K();break;case"showMessage":var u=d.searchParams.get("messageId"),c=d.searchParams.get("properties");u&&(c&&(c=JSON.parse(atob(c))),await Z.showMessage({messageId:u,properties:c}));break;case"loadPage":var d;(d=d.href.substring(d.href.indexOf("?url=")+5))&&(d.startsWith("https://")||d.startsWith("http://")||d.startsWith("/")?window.location.href=d:window.location.href=window.location+d)}}catch(e){}break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,n.renderStartTime=(new Date).getTime(),H(t,n),s("Route changed to: "+n.currentRoute);break;case"sizeChanged":s(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),n.elementId&&n.shouldResizeHeight?R(n.elementId,e.data.gist.parameters,n.shouldScale):R("gist-message",e.data.gist.parameters,n.shouldScale);break;case"error":case"routeError":Z.messageError(n),Z.overlayInstanceId?M(!1,n):q(n)}}var f,l}var F=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>F(e,t))),X=!1,J=[];async function Q(){X?await K():(!async function(){var e="G"+m().substring(0,8),t=document.createElement("div");t.setAttribute("id",e),t.style.display="none",document.body.appendChild(t),await T(5e3),U({messageId:""},e)}(),v()?(s("Queue watcher started"),X=!0,F(()=>new Promise(()=>async function(){if(v())if(Z.isDocumentVisible){var e=await async function(){try{return await I().post("/api/v1/users",{})}catch(e){return e.response}}(),t=[];if(e){if(200===e.status||204===e.status){var n=new Date((new Date).getTime()+6e4);i("gist.web.userQueue",e.data,n),t=e.data}else 304===e.status&&(t=o("gist.web.userQueue"));t&&t.length>0?(s(`Message queue checked for user ${v()}, ${t.length} messages found.`),J=t,await K()):(J=[],s("No messages for user token."))}else s("There was an error while checking message queue.")}else s("Document not visible, skipping queue check.");else s("User token reset, skipping queue check.")}()),1e4)):s("User token not setup, queue not started."))}async function K(){s("Messages in local queue: "+J.length);var e=[],t=J.sort((e,t)=>e.priority-t.priority);for(const i of t){if(!await Y(i)){var n=e.find(e=>e.queueId===i.queueId),r=Z.currentMessages.find(e=>e.queueId===i.queueId);n||r?s(`Message with queueId: ${i.queueId} already in queue, discarding.`):e.push(i)}}J=e}async function Y(e){if(!function(e){return void 0!==j.find(t=>t.queueId===e.queueId)}(e)){var t=S(e);if(t.hasRouteRule){var n=Z.currentRoute;null==n&&(n=new URL(window.location.href).pathname);var r=t.routeRule;if(s("Verifying route against rule: "+r),!new RegExp(r).test(n))return s(`Route ${n} does not match rule.`),!1}return t.hasPosition&&(e.position=t.position),t.isEmbedded?await U(e,t.elementId):await D(e)}s(`Message with ${e.queueId} has been shown before, skipping.`)}var Z=t.default=class{static async setup(e){this.events=new r,this.config={useGuestSession:void 0!==e.useGuestSession&&e.useGuestSession,siteId:e.siteId,dataCenter:e.dataCenter,env:void 0===e.env?"prod":e.env,logging:void 0!==e.logging&&e.logging,experiments:void 0!==e.experiments&&e.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,s(`Setup complete on ${this.config.env} environment.`),this.config.useGuestSession&&y(),await Q(),document.addEventListener("visibilitychange",async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await K())},!1)}static async setCurrentRoute(e){this.currentRoute=e,s("Current route set to: "+e),await K()}static async setUserToken(e,t){!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),i("gist.web.userToken",e,t),a("gist.web.usingGuestUserToken"),s(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),await Q()}static async clearUserToken(){a("gist.web.userToken"),s("Cleared user token"),this.config.useGuestSession&&y(),await Q()}static async dismissMessage(e){var t=_(e);await A(t),await $(t),await K()}static async embedMessage(e,t){return(await U(e,t)).instanceId}static async showMessage(e){var t=await D(e);return t?t.instanceId:null}static messageShown(e){s("Message shown: "+e.messageId),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(s("Message dismissed: "+e.messageId),this.events.dispatch("messageDismissed",e))}static messageError(e){s("Message error: "+e.messageId),this.events.dispatch("messageError",e)}static messageAction(e,t,n){s(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}}}])}));