(function(){"use strict";function j(){const e="aiden-storage-test";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch{return!1}}function A(){const e="aiden-storage-test";try{return sessionStorage.setItem(e,e),sessionStorage.removeItem(e),!0}catch{return!1}}const N=()=>A()?sessionStorage:E,K=()=>j()?localStorage:A()?sessionStorage:E,y={},E={getItem:e=>y[e]||null,setItem:(e,t)=>{y[e]=t},removeItem:e=>{delete y[e]}},w={session:N(),local:K()},u={};let p=[];function D(e,t){const n={type:"AdvisorSeen",userId:J(),path:window.location.pathname,domain:window.location.host,userAgent:navigator.userAgent,resolution:W(),screenSize:B()};fetch(`https://app.aiden.cx/webshop-api/v1/forms/website-analytics/${e}?&mode=${t}`,{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json"},body:JSON.stringify(n)})}function J(){const e=w.local.getItem("aidenUserId");if(!e){const t=window.crypto.getRandomValues(new Uint32Array(1))[0].toString();return w.local.setItem("aidenUserId",t),t}return e}function W(){return{width:screen.width||0,height:screen.height||0}}function B(){const e=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0,t=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0;return{width:e,height:t}}function $(e){p=p.filter(t=>e.indexOf(t)>=0),e.forEach(t=>{if(p.indexOf(t)>=0)return;p.push(t);const n=Y(t),o=G(t);if(!n)return;const a={rootMargin:"0px",threshold:o==="modal"?.9:.5};new IntersectionObserver(s=>{s.forEach(r=>{r.isIntersecting&&n&&!u[n]?u[n]=setTimeout(()=>{D(n,o),u[n]="sent"},3e3):!r.isIntersecting&&u[n]!=="sent"&&(clearTimeout(u[n]),u[n]=void 0)})},a).observe(t)})}function V(e){return e instanceof HTMLElement&&(k(e)||P(e))}function k(e){return e instanceof HTMLIFrameElement&&e.tagName==="IFRAME"&&e.id&&e.id.startsWith("aiden-")&&L(e.id.replace("aiden-",""))}function P(e){return e.dataset&&"advisorId"in e.dataset&&L(e.dataset.advisorId||"")}function Y(e){if(P(e))return e.dataset.advisorId;if(k(e))return e.id.replace("aiden-","")}function G(e){if(e instanceof HTMLIFrameElement){const t=new URLSearchParams(e.src);if(t.has("mode"))return t.get("mode")==="inpage"?"inpage":"banner"}return"modal"}function L(e){return RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i).test(e)}function x(){const e=Array.from(document.querySelectorAll("iframe, [data-advisor-id]")).filter(t=>V(t));$(e)}function M(){const e=(o,a)=>{a.disconnect();try{x(),M()}catch(i){console.error(i)}},t=new MutationObserver(e),n={attributes:!0,subtree:!0,childList:!0};t.observe(document.documentElement,n)}const O=w.local,T=btoa("aiden-storage"),R=e=>{const t=e.getItem(T)||"{}";return ee(t)},X=(e,t)=>{const n=e.data.sessionId,o=e.advisorId;if(n&&o&&Q.includes(e.type)){const a=R(t),i=a[o]||new Set,s=Z({...a,[o]:i.add(n)});t.setItem(T,s)}},Q=["answered-event","advised-event","completed-event","start-over-event","product-clicked-event","session-activity"];function U(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,[...n]]))}function Z(e){return btoa(JSON.stringify(U(e)))}function ee(e){try{const t=JSON.parse(atob(e));return t instanceof Object&&!(t instanceof Array)?Object.fromEntries(Object.entries(t).map(([n,o])=>o instanceof Array?[n,o.every(a=>typeof a=="string")?new Set(o):new Set]:[n,o])):{}}catch{return{}}}function te(e){const t=["debug","apiKey","orderId","currency"],n=["aidenProductId","quantity","price"],o=(e.products||[]).map(i=>{if(typeof i=="object"&&!Array.isArray(i))return n.reduce((s,r)=>({...s,[r]:i[r]}),{})}).filter(function(i){return i!=null});return t.reduce((i,s)=>({...i,[s]:e[s]}),{products:o})}const ne=".aiden-lock-screen{overflow:hidden}.aiden-lock-screen.aiden-ios-lock{position:fixed;width:100%}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}.aiden-modal{width:100%;height:100%;position:fixed;top:0;right:0;left:0;bottom:0;display:flex;pointer-events:all;z-index:2147483629;animation:fadeIn .5s ease-in;-webkit-overflow-scrolling:touch}.aiden-modal .aiden-modal-content{position:relative;z-index:2147483629;flex:1 1 auto;-webkit-overflow-scrolling:touch}.aiden-modal .aiden-modal-loading{position:absolute;left:0;top:0;height:100%;width:100%;align-items:center;display:flex;justify-content:center;background:#0000004d;color:#fff}.aiden-modal iframe{width:100%;height:100%;border:none}",v=window.navigator,b="aidenModal",I="aidenSidebar",m="aidenProductCheck";function S(e,t,n){const o="aiden-modal-"+e,a=document.querySelector(".aiden-modal"),s=(t==="sidebar"?[...n,["mode","sidebar"]]:n).map(([Re,Ue])=>Re+"="+Ue).join("&"),r=s?"&"+s:"";if(a&&a.id===o)return;a&&a.remove(),de(e,t,n);const d=document.createElement("div");d.id="aiden-modal-"+e;const c="
";d.className="aiden-modal",d.innerHTML=c.trim();const f=document.body;ie(f),f.appendChild(d),oe(f);const h=document.getElementById("aiden-modal-frame"),g=document.getElementById("aiden-modal-loading");h&&h.addEventListener("load",function(){g&&(g.style.display="none")})}function oe(e){ae()&&e.classList.add("aiden-ios-lock")}function ae(){return/iPad|iPhone|iPod/.test(v.platform)||v.platform==="MacIntel"&&v.maxTouchPoints>1}function _(e){e.preventDefault(),e.stopPropagation()}function ie(e){e.className+=" aiden-lock-screen",e.addEventListener("touchmove",_,{passive:!1})}function re(e){e.classList.remove("aiden-lock-screen"),e.removeEventListener("touchmove",_),e.classList.remove("aiden-ios-lock")}function se(){const e=document.querySelector(".aiden-modal"),t=document.body;re(t),ce(),e&&e.remove()}function q(){const e=new URLSearchParams(window.location.search),t=new URL(window.location.href.replace(window.location.search,""));return e.delete(b),e.delete(I),{url:t,params:e}}function C(e,t){t.forEach((n,o)=>{e.searchParams.set(o,n)}),history.replaceState({},"",e.href)}function de(e,t,n){const{url:o,params:a}=q();a.set(t==="sidebar"?I:b,e),n.forEach(([i,s])=>{i==="productId"&&a.set(m,s),i==="productUrl"&&a.set(m,"")}),C(o,a)}function ce(){const{url:e,params:t}=q();t.delete(m),C(e,t)}function F(e){return new URLSearchParams(window.location.search).get(e)}function le(){return F(b)}function ue(){return F(I)}function fe(e){e.type==="background-click"&&se()}const H=-100,pe=e=>!!e&&typeof e=="object"&&"type"in e&&typeof e.type=="string",me=e=>!!e&&typeof e=="object"&&"advisorId"in e&&typeof e.advisorId=="string",he=e=>!!e&&typeof e=="object"&&"data"in e&&typeof e.data=="object",ge=e=>he(e)&&"height"in e.data&&typeof e.data.height=="number";function ye(e){const t=e.data;if(t&&pe(t)&&me(t)){const n=document.querySelector("iframe#aiden-"+t.advisorId)||we(e);if(!n||n.id==="aiden-modal-frame")return;if(t.type==="viewport-dimensions"&&ge(t)&&(n.style.height=`${t.data.height+1}px`),t.type==="screen-change")try{const o=ve(n),a=n.getBoundingClientRect().top+window.pageYOffset+o;window.scrollTo({top:a,behavior:"smooth"})}catch{}}}function we(e){const t=document.querySelectorAll("iframe");return Array.from(t).find(n=>{var o;return n.contentWindow===e.source||((o=n.contentDocument)==null?void 0:o.defaultView)===e.source})||null}function ve(e){if(!e)return H;const t=e.dataset.scrolloffset||e.getAttribute("scrollOffset"),n=parseInt(t||"");return isFinite(n)?n:H}function be(){return new Promise(e=>{if(document.body)e(document.body);else{const t=new MutationObserver(()=>{document.body&&(e(document.body),t.disconnect())});t.observe(document.documentElement,{childList:!0,subtree:!0})}})}function Ie(){try{x(),M()}catch(r){console.error(r)}ke();const e=document.querySelectorAll("[data-advisor-id]"),t=r=>{const d=r.getAttribute("data-product-check");return d===null?[]:d.trim()!==""?[["productId",d]]:[["productUrl",window.location.href.split("?")[0]]]},n=function(r){const d=r==null?void 0:r.target;if(d instanceof Element){const c=d.getAttribute("data-advisor-id")?d:d.closest("[data-advisor-id]"),f=c==null?void 0:c.getAttribute("data-advisor-id"),h=c?t(c):[],g=(c==null?void 0:c.getAttribute("data-aiden-mode"))==="sidebar"?"sidebar":"modal";f&&S(f,g,h)}},o=le(),a=ue(),i=a?"sidebar":"modal",s=o||a;s&&be().then(()=>{S(s,i,Pe())}),e.forEach(function(r){r.addEventListener("click",n)}),window.addEventListener("click",n),window.addEventListener("message",r=>{if(Se(r.data)){const d=r.data;fe(d),ye(r),Ae(d)&&X(d,O)}}),Ee()}const Se=e=>e!==null&&typeof e=="object"&&!(e instanceof Array)&&"data"in e&&"advisorId"in e&&"type"in e,Ae=e=>"sessionId"in e.data&&typeof e.data.sessionId=="string",Ee=()=>{const e=document.getElementsByTagName("IFRAME");Array.from(e).forEach(t=>{t instanceof HTMLIFrameElement&&t.id.startsWith("aiden-")&&t.contentWindow&&t.contentWindow.window.postMessage({type:"init"},"*")})};function ke(){try{typeof Element<"u"&&(Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){var t=this;if(!t)return null;do{if(t.matches(e))return t;t=t.parentElement||t.parentNode}while(t!==null&&t.nodeType===1);return null}))}catch{}}window._aidenApp={openAdvisor:S};function Pe(){const t=new URLSearchParams(window.location.search).get(m);return t===null?[]:t.trim()!==""?[["productId",t]]:[["productUrl",window.location.href.split("?")[0]]]}function Le(){window.addEventListener("message",function(e){var n,o,a,i;const t=(n=e.data)==null?void 0:n.eventData;((o=e.data)==null?void 0:o.integration)==="aiden:google_tag_manager"&&typeof((a=e.data)==null?void 0:a.type)=="string"&&t&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:(i=e.data)==null?void 0:i.type,...t}))})}function xe(){window.addEventListener("message",function(e){var n,o,a,i;const t=(n=e.data)==null?void 0:n.eventData;((o=e.data)==null?void 0:o.integration)==="aiden:google_analytics"&&typeof((a=e.data)==null?void 0:a.type)=="string"&&t&&(typeof gtag=="function"?gtag("event",(i=e.data)==null?void 0:i.type,t):setTimeout(()=>{var s;typeof gtag=="function"&>ag("event",(s=e.data)==null?void 0:s.type,t)},2e3))})}function Me(){window._sqzl=window._sqzl||[],window.addEventListener("message",function(e){var n,o;const t=(n=e.data)==null?void 0:n.eventData;((o=e.data)==null?void 0:o.integration)==="aiden:squeezely"&&t&&window._sqzl.push(t)})}function Oe(){window.addEventListener("message",function(e){var n,o,a;const t=(n=e.data)==null?void 0:n.eventData;((o=e.data)==null?void 0:o.integration)==="aiden:bloomreach"&&typeof((a=e.data)==null?void 0:a.type)=="string"&&t&&(window.exponea?window.exponea.track(e.data.type,t):setTimeout(()=>{window.exponea&&window.exponea.track(e.data.type,t)},2e3))})}function l(e,t=void 0){console.group("Aiden"),t?console.error(e,t):console.error(e),console.groupEnd()}function z(e){const t=U(R(O));try{if(!(typeof e=="object"&&!Array.isArray(e))){l("purchase event provided was not a correctly formed object");return}if(typeof e=="object"&&"apiKey"in e&&typeof e.apiKey=="string"){const n=new XMLHttpRequest,o=e.apiKey;n.open("POST","https://app.aiden.cx/webshop-api/v1/purchase",!0),n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("Accept","application/json, text/plain, */*"),n.responseType="text",n.setRequestHeader("X-API-KEY",o),n.send(JSON.stringify({...te(e),sessions:t})),n.onloadend=()=>{n.status===200&&(e!=null&&e.debug)&&(console.group("Aiden"),console.info("Purchase event sent succesfully"),console.groupEnd()),(n.status===400||n.status===422)&&l("There was something wrong when sending the purchase event",JSON.parse(n.responseText)),n.status===403&&l("The API key you have provided is invalid.")}}else l("An API key was not provided for the purchase event. Include an 'apiKey' key and provide the key which starts with 'AID-'");return}catch(n){l("",n);return}}function Te(e){e._aiden||(e._aiden=[]);try{if(e._aiden.push=function(n){return typeof n=="object"&&"event"in n&&typeof n.event=="string"&&(n.event.toLowerCase()==="purchase"?z(n):l("Unknown event type: "+n.event)),1},e._aiden&&Array.isArray(e._aiden)){for(var t=0;t