if(window.userledSettings)window.userledSettings.enableDynamicAssets=true;if(window.userledSettings)window.userledSettings.version='9ddd4f90573b1fe8d88453b89d1f4b2c3c4dc41a';var fn=Object.defineProperty;var yn=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var d=(e,t,n)=>(yn(e,typeof t!="symbol"?t+"":t,n),n);import{g as dt,s as ut,r as vn,l as a,a as mt,D as ce,b as wn,H as J,A as v,u as Y,c as le,d as bn,C as f,V as En,e as ht,S as Ce,f as In,t as I,h as de,R as qe,i as Sn,I as Ve,j as An,k as Cn,_ as Tn,p as pt,m as Pn,n as A,P as xn,o as C,q as gt,v as On,w as oe,x as Ln,y as ze,W as _n,z as Fn,B as $n,E as kn,F as Dn,G as Hn,J as Mn,K as ft,L as Un,M as Nn,N as Rn,O as Kn,Q as qn,T as Vn,U as zn,X as jn,Y as Bn,Z as yt,$ as Wn,a0 as vt,a1 as Gn}from"./assets/_commonjsHelpers-1cc6e14f.js";const wt=e=>{const t=dt(e);if(!t)return null;try{return JSON.parse(t)}catch{return null}},bt=(e,t)=>{t?ut(e,JSON.stringify(t)):vn(e)},Et=()=>`userled_matched_inbound_campaign_${window.location.href}`,Jn=e=>{bt(Et(),e)},Yn=()=>wt(Et()),It="userled_inbound_campaigns",Qn=e=>{bt(It,e)},Zn=()=>wt(It),St=e=>({...e,getValue:t=>e.vars[t.raw]}),Xn=async e=>{const t=await fetch(e.serverUrl+"/api/inbound-campaigns/match",{method:"POST",body:JSON.stringify(e)});if(!t.ok){const r=await t.text();throw new Error(`Failed to match inbound campaign - status=${t.status} error=${r}`)}const n=await t.json();return n?St(n):null},je=async e=>{try{const t=await Xn(e);return Jn(t),t}catch(t){throw new Error(`Failed to match inbound campaign: ${t}`)}},er=async e=>{const t=Yn();return t?(je(e),St(t)):je(e)};class Te{static enqueue(t){return new Promise((n,r)=>{this.queue.push({promise:t,resolve:n,reject:r}),this.dequeue()})}static async dequeue(){if(this.workingOnPromise)return;const t=this.queue.shift();if(t){this.workingOnPromise=!0;try{const n=await t.promise();t.resolve(n)}catch(n){t.reject(n)}this.workingOnPromise=!1,this.dequeue()}}}Te.queue=[];Te.workingOnPromise=!1;const we=(e,t)=>{const n=nr[e==null?void 0:e.Operation];if(!n)return console.error(`invalid operation [${e==null?void 0:e.Operation}]`),!1;const r=n(e.Value,t);return a(`Condition ${r}: [${e.Operation} - ${e.Value}] against value ${t}`),r},ue=(e,t)=>{const n=i=>{let o=i==null?void 0:i.replace(new RegExp("(^(http(s)?:\\/\\/)?(www\\.)?)|((\\/)?(\\?.*)?$)","gi"),"");return o=o.replace(/^(localhost|127.0.0.1|[::1])(:d+)?/,"localhost"),o},r=n(e),s=n(t);return r===s},tr=(e,t)=>t.includes(e),nr={"matches url":ue,contains:tr};let Pe=()=>{};function At(e){Pe({...e.data})}function rr(e){Pe=e,window.addEventListener("message",At,!1)}function sr(){Pe=()=>{},window.removeEventListener("message",At,!1)}function ir(e){if(!e||!or(e))return 0;const t=Number(e.slice(0,e.length-1))||0,n=e.slice(e.length-1),r=ar[n]??0;return t*r}function or(e){return e?new RegExp("^[0-9]+[smhdw]$").test(e):!1}const ar={s:1e3,m:6e4},cr=e=>{const t=["co.uk",".co.jp",".co.kr",".co.nf",".co.nz"],n=e.split(".");if(n.length===1||/^[0-9.]+$/.test(e))return e;for(let r=0;r{const e=Tt()??hr();return fr(e),e},Tt=()=>mt.get(Ct),fr=e=>{const t=cr(window.location.hostname);mt.set(Ct,e,{domain:`.${t}`,sameSite:"lax",expires:pr})},P=(e,t)=>{if(!ce())return wn(e,t),fetch(`${J}/api/sdk/events`,{method:"POST",headers:{"Userled-Org-Id":v()},body:JSON.stringify({id:Y(),userId:le(),requestId:bn(),sessionId:gr(),orgId:v(),name:e,body:t,happenedAt:new Date().toISOString(),userAgent:navigator.userAgent,channel:t.channel||f.None,version:En()})})},yr="2147483647";let l;const ae=new Map;let be=!1,z=!1;async function vr(e){a(e.promptId);const t=e.promptId,n=e.triggers;if(ae.set(t,n),l){a("already showing prompt");return}const r=de();if(we(n.urlCondition,r)){Pt(t);return}}const wr=()=>{z=!1;const e=de(),t=ae.get((l==null?void 0:l.id)||"");if(t&&!we(t.urlCondition,e)&&Ot(),!l){for(const[n,r]of ae)if(we(r.urlCondition,e)){Pt(n);break}}};function Pt(e){a(`Displaying prompt with id ${e}`);const t=ht(),n=Ce().app_id,r=document.createElement("iframe");r.id="userledPrompt",r.src=In+"/src/index.html",r.style.position="fixed",r.style.border="none",r.style.zIndex=yr,r.name=`${e},${n},${t}`,r.setAttribute("allowtransparency","true"),r.allowFullscreen=!0,r.style.opacity="0",r.style.bottom=I(0),r.style.right=I(0),rr(br),l={id:e,iframe:r,size:{width:0,height:0},position:{}},document.body.appendChild(r)}function br(e){if(l)switch(e.type){case qe.Resize:return Er(e);case qe.Interacted:return Cr(e)}}async function Er(e){if(l){if(!z){const t=ir(e.payload.options.delay);await Sn(t)}a(`Resizing prompt ${e.payload.width} ${e.payload.height}`),l.size={width:e.payload.width,height:e.payload.height},a("Positioning prompt",e.payload.options.position),l.position=e.payload.options.position,xt()}}function xt(){if(!l||!l.size.height||!l.size.width)return;const e=Tr(l.size);Ir(e),be=e,be&&!z&&(z=!0,Ar(l.id))}function Ir(e=!0){if(a(`Setting prompt visibility to ${e}`),!l)return;const t=l.iframe,n=l.position,r=l.size,s=n.left===0&&n.right===0,i=n.top===0&&n.bottom===0;t.style.width=s?"100%":I(r.width),t.style.height=i?"100%":I(r.height),t.style.top=I(n.top),t.style.right=I(n.right),t.style.bottom=I(n.bottom),t.style.left=I(n.left),t.style.display=e?"block":"none",t.style.opacity=e?"1":"0"}function Ot(){sr(),l&&(a(`Dismissing promptId [${l.id}]`),l.iframe.remove(),l=void 0,be=!1)}function Sr(e,t){a(`Sending prompt interaction [${t}] for promptId: [${e}]`),P("PROMPT_INTERACTION",{promptId:e,interactionId:t})}function Ar(e){a(`Sending prompt rendered for promptId: [${e}]`),P("PROMPT_RENDERED",{promptId:e})}function Cr(e){if(!l){console.error("Interaction on non-existing prompt");return}const t={...l};switch(ae.delete(l.id),z=!1,Ot(),Sr(t.id,e.id),e.interactionType){case Ve.Dismissal:break;case Ve.Redirect:{const{redirectLink:n,useNewTab:r}=e.payload;n&&An(n,r);break}}}function Tr(e){const t=Math.min(window.innerWidth,window.screen.width),n=Math.min(window.innerHeight,window.screen.height),r=e.width??0,s=e.height??0;return r<=t&&s<=n}const Pr=()=>l,xr=["display","width","height","objectFit","objectPosition"],xe=["div","li"],Oe=["h1","h2","h3","h4","h5","p","button",...xe],Lt=e=>Array.from(e.childNodes).every(t=>t.nodeName==="#text"||t.nodeName==="SPAN"&&Lt(t)||t.nodeName==="P"&&t.hasAttribute(j)||t.nodeName==="BR"),Le=["img"],Or=["picture"],Lr=["source"],_e=["a"],_t=["input"],Ft=["iframe"],_r=["svg"],Fr=["head","script"],$r=[...Oe,...Le,..._e,...xe,..._t,...Ft,..._r],_=e=>Oe.includes(e.tagName.toLowerCase()),F=e=>Le.includes(e.tagName.toLowerCase()),$t=e=>Or.includes(e.tagName.toLowerCase()),kt=e=>Lr.includes(e.tagName.toLowerCase()),$=e=>_e.includes(e.tagName.toLowerCase()),U=e=>_t.includes(e.tagName.toLowerCase()),Dt=e=>e.tagName.toLowerCase()==="head",Ht=e=>e.tagName.toLowerCase()==="script",N=e=>Ft.includes(e.tagName.toLowerCase()),R=e=>e instanceof SVGElement,We=e=>e.hasAttribute("data-hs-forms-root"),Ge=e=>e.hasAttribute(Rr),kr=e=>Oe.includes(e.tag),Dr=e=>Le.includes(e.tag),Hr=e=>_e.includes(e.tag),Je=e=>Fr.includes(e.tag),Ye=e=>{const t=e.textContent;if(!t)return null;const n=t.match(/hbspt.forms.create(([^)]+))/);return!n||!n[1]?null:JSON.parse(n[1].trim().replace(/(w+):/g,'"$1":'))},Qe=e=>{const t=e.cloneNode(!0);return t.removeAttribute("xmlns"),t.removeAttribute(j),t.removeAttribute(x),t.removeAttribute(T),new XMLSerializer().serializeToString(e)};function Mr(e){for(var t=-1,n=e==null?0:e.length,r=0,s=[];++timport("./assets/finder-c29405a7.js"),[]).then(e=>Ee=e.finder);const se=new Map,x="data-userled-id",T="parent-userled-id",j="data-userled-noselect",Mt=".hbspt-form",Rr="data-hubspot-rendered",Kr=e=>`[${T}='${e}']`,me=e=>`[${x}='${e}']`,V=class V{constructor(t,n,r){d(this,"id");d(this,"element");d(this,"style");d(this,"serialise",()=>{const n=new XMLSerializer().serializeToString(this.element);return{id:this.id,element:n,style:this.style}});d(this,"tag",()=>this.element.tagName.toLowerCase());d(this,"userledTag",()=>this.element.getAttribute(x)||void 0);d(this,"isAllowed",()=>this.element.hasAttribute(j)?!1:We(this.element)?!0:xe.includes(this.element.tagName.toLowerCase())?Lt(this.element):$r.includes(this.tag()));d(this,"isSelectable",()=>!this.element.hasAttribute(j));d(this,"isText",()=>_(this.element));d(this,"isImage",()=>F(this.element));d(this,"isButton",()=>$(this.element));d(this,"isInput",()=>U(this.element));d(this,"isIFrame",()=>N(this.element));d(this,"isSvg",()=>R(this.element));d(this,"isHubspotForm",()=>We(this.element));d(this,"value",()=>{if(Ge(this.element)){const t=Ye(this.element);if(!t){console.error("Failed to parse Hubspot script data");return}return t}if(R(this.element))return{value:Qe(this.element)};if(F(this.element))return{url:this.element.src};if($(this.element))return{value:this.element.innerHTML,href:this.element.getAttribute("href")||""};if(U(this.element))return{value:this.element.value,placeholder:this.element.placeholder};if(N(this.element))return{src:this.element.src};if(Ht(this.element))return{value:this.element.innerHTML};if(_(this.element))return{value:this.element.innerHTML};if(Dt(this.element))return{value:""};console.error("Element is not allowed",this.tag())});d(this,"getStyle",()=>{const t=window.getComputedStyle(this.element),n={};for(const r of xr){const s=t.getPropertyValue(r);s&&(n[r]=s)}return n});d(this,"assetProp",()=>{if(F(this.element))return{type:"image",label:"Image",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),src:this.element.srcset||this.element.src,imageType:"custom_url"};if($(this.element)){const t={type:"button",label:"Button",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),value:this.findAllowedChildren().length>0?void 0:this.element.innerHTML,href:this.element.getAttribute("href")||""},n=this.findAllowedChildren();return n.length>0&&(t.children=Nr(n.map(r=>r.assetProp())).map(r=>({...r,parentKey:t.propKey}))),t}if(N(this.element))return{type:"iframe",label:"IFrame Embed",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),src:this.element.src};if(R(this.element))return{type:"svg",label:"SVG",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),value:Qe(this.element)};if(U(this.element))return{type:"input",label:"Input",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),value:this.element.value,placeholder:this.element.placeholder};if(Ge(this.element)){const t=Ye(this.element);return t||console.error("Failed to parse Hubspot script data"),{type:"contactForm",label:"Hubspot Form",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),region:(t==null?void 0:t.region)||"",portalId:(t==null?void 0:t.portalId)||"",formId:(t==null?void 0:t.formId)||""}}if(_(this.element))return{type:"text",label:"Text",propKey:this.id||"",tag:this.tag(),userledId:this.userledTag(),value:this.element.innerHTML};console.error("Element is not allowed",this.tag())});d(this,"selector",t=>{if(!t||!Ee)return this.id;const n=Ee(t,{root:this.element,seedMinLength:1,optimizedMinLength:2});return n?[this.id,n].join(" "):(console.error("Child not found for element",t),this.id)});d(this,"findAllowedChildren",(t=this,n=5)=>{const r=[];if(n===0)return t.isAllowed()?[t]:[];t.id!==this.id&&t.isAllowed()&&r.push(t);for(const s of t.element.children)(s instanceof HTMLElement||s instanceof SVGElement)&&r.push(...this.findAllowedChildren(new V(s,void 0,this.selector(s)),n-1));return r});this.element=t,this.style=n??this.getStyle(),this.id=r}};d(V,"Deserialise",t=>{const r=new DOMParser().parseFromString(t.element,"text/html"),s=r.body.firstChild||r.head.firstChild;return new V(s,t.style,t.id)});let B=V;const Ut=e=>{e.dataset.originalDisplay=e.style.display,e.style.setProperty("display","none","important")},qr=(e,t)=>{var n;e.dataset.userledHubspotFormScriptHandled="true",(n=e.parentElement)==null||n.querySelectorAll(Mt).forEach(r=>{r instanceof HTMLElement&&(r.style.setProperty("display","none","important"),r.dataset.userledHubspotFormId=t)})},Nt=e=>{e.style.display=e.dataset.originalDisplay||"",e.removeAttribute("data-original-display")},Vr=(e,t,{trigger:n}={})=>{const r=document.createElement("script");if(n){const s=document.createTextNode(`hbspt.forms.create(${JSON.stringify({region:t.region,portalId:t.portalId,formId:t.formId})});`);return r.appendChild(s),e.insertAdjacentElement("afterend",r),r}return e.insertAdjacentHTML("afterend",``),e.nextElementSibling},zr=(e,t)=>{var n,r;(r=(n=e.parentElement)==null?void 0:n.querySelectorAll(Mt))==null||r.forEach(s=>{s instanceof HTMLElement&&(s.dataset.userledHubspotFormId?(s.style.removeProperty("display"),delete s.dataset.userledHubspotFormId):(se.set(t,s.cloneNode(!0)),s.remove()))})},Ze=(e,t,n)=>(qr(e,t),se.has(t)&&e.insertAdjacentElement("afterend",se.get(t)),Vr(e,n,{trigger:!se.has(t)})),Rt=(e,t)=>{switch(t.tagName.toLowerCase()){case"button":jr(e,t);break;case"input":Br(e,t);break;case"img":case"div":case"p":case"li":case"span":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":Wr(e,t);break}},jr=(e,t)=>{e.addEventListener("click",()=>{y(t,{event:"click"})}),e.addEventListener("blur",()=>{y(t,{event:"blur"})})},Br=(e,t)=>{e.addEventListener("input",()=>{y(t,{event:"input",value:e.value})}),e.addEventListener("change",()=>{y(t,{event:"change",value:e.value})}),e.addEventListener("focus",()=>{y(t,{event:"focus"})}),e.addEventListener("blur",()=>{y(t,{event:"blur"})})},Wr=(e,t)=>{e.addEventListener("click",()=>{y(t,{event:"click"})}),e.addEventListener("blur",()=>{y(t,{event:"blur"})}),e.addEventListener("focusout",()=>{y(t,{event:"focusout"})})},y=(e,{event:t,...n})=>{var i;if(!(e instanceof Element))throw new Error(`Expected an Element but received ${typeof e} instead!`);const[r,s]=Object.entries(n)[0]??[];if(r){const o=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),r);(i=o==null?void 0:o.set)==null||i.call(e,s)}e.dispatchEvent(new Event(t,{bubbles:!0}))};let k=!1,Kt=-1,D=-1,W=-1,G=0,ee,S;const Gr=38e3;let qt=!1,te=-1;const Vt=7*1e3,Jr=()=>{Kt=new Date().getTime()},Yr=(e,t)=>{Q(!1),ns(),zt(e,t)},Qr=e=>{Q(!1),zt(e)},Zr=e=>{var n;if(S!==void 0&&(clearTimeout(S),S=void 0),k)return;const t=jt()/1e3;Q(!0),(n=e==null?void 0:e.onPageClosedTrack)==null||n.call(e,t,"PAGE_HIDDEN")},Xr=(e,t)=>{let n=0;return(r,s)=>{var o;const i=jt()/1e3;n=n+1,G=0,W=new Date().getTime(),(o=t==null?void 0:t.onPageActiveForFixedInterval)==null||o.call(t,i,`COUNT_${n}_${e}_${new Date().toISOString()}_hasScrolledOnce=${r}_scheduleAdjustment=${s}`)}};function es(e,t,n){te=new Date().getTime();let r=0;const s=Xr(e,n);function i(){let o=t;new Date().getTime()-te>t-500?(te=new Date().getTime(),s(qt,r),r=0):(o=t-(new Date().getTime()-te),r=o),S=setTimeout(i,o)}S=setTimeout(i,t)}const zt=(e,t=Vt)=>{S!==void 0&&(clearTimeout(S),S=void 0),W=new Date().getTime(),G=0,es(Math.random().toPrecision(3),t,e)},ts=()=>{if(k)return;const e=Math.max(Kt,D);e<0||new Date().getTime()-e>Gr&&Q(!0)},ns=()=>{ee!==void 0&&(clearInterval(ee),ee=void 0),D=new Date().getTime(),ee=setInterval(ts,500),window.addEventListener("scroll",()=>{qt=!0,Q(!1)})},jt=()=>{if(k)return G;if(W>D)return new Date().getTime()-W;const e=new Date().getTime()-D;return G+e},Q=e=>{if(e!==k){if(e){const t=Math.max(W,D);G+=new Date().getTime()-t,k=!0;return}k=!1,D=new Date().getTime()}},Xe="a",et="c",tt="ul_e";let pe;const Bt=()=>(pe||(pe=rs()),pe),rs=()=>{const e=pt(window.location.href);if(!e)return console.error("Invalid URL"),{accountId:void 0,contactId:void 0,email:void 0};const t=e.searchParams,n=t.get(Xe)??void 0,r=t.get(et)??void 0,s=t.get(tt)??void 0,i=n||r||s;return n&&t.delete(Xe),r&&t.delete(et),s&&t.delete(tt),i&&window.history.replaceState({},"",e.toString()),{accountId:n,contactId:r,email:s}};let Wt="",H="";const Gt=()=>H;let Ie=[!1,!1],Jt,Yt=f.Website,Qt="",Zt="";const Xt=(e,t)=>{Jt=e,Yt=t.channel,Qt=t.campaignId,Zt=t.caseId??""},ss=()=>({assetId:Jt,channel:Yt,campaignId:Qt,caseId:Zt}),Fe=async({name:e,inboundAssetId:t,campaignId:n,caseId:r})=>{const s=pt(window.location.href);if(!s){console.error("Invalid URL");return}Jr(),Pn(s.href),a(`page url:${s.href} prev:${document.referrer} name:${e}`,A()),H&&en(),H=Y(),Ie=[!1,!1],await is({inboundAssetId:t,campaignId:n,caseId:r}),Wt=s.href,Yr({onPageActiveForFixedInterval:$e()},parseInt(xn)||Vt)};document.addEventListener("visibilitychange",async()=>{document.visibilityState==="hidden"?en():Qr({onPageActiveForFixedInterval:$e()})});const en=()=>{Zr({onPageClosedTrack:$e()})},is=async({inboundAssetId:e,campaignId:t,caseId:n})=>{if(Ie[0]){a("Page already sent");return}Ie[0]=!0;let r;const s=O();let i=f.Website;s?(i=f.Outbound,r=s):e?(i=f.Inbound,r=e):i=f.Website;const o=Bt();await P("PAGE_LOADED",{campaignId:t,pageId:H,pageName:document.title||window.location.href,url:window.location.href,prevUrl:document.referrer||Wt,assetId:r,channel:i,accountId:o.accountId,contactId:o.contactId,email:o.email,caseId:n})};function $e(){return H?function(e,t){var c,u;const n=Math.round(e);if(n==0)return;const{assetId:r,channel:s,caseId:i,campaignId:o}=ss();P("PAGE_CLOSED",{assetId:r,pageId:H,timeActive:n,url:window.location.href,debugMsg:t,channel:s,caseId:i,campaignId:o,customSiteId:(c=ks())==null?void 0:c.id,promptId:(u=Pr())==null?void 0:u.id})}:()=>{}}const os=new RegExp("^[(http(s)?)://(www.)?a-zA-Z0-9@:%._+~#=]{2,256}.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$","i");let ie;const as=()=>ie!==void 0,cs=e=>{var r;if(!(e!=null&&e.oldValue)||!e.target)return[];const t=e.target,n=(r=e.oldValue)==null?void 0:r.split(";").reduce((s,i)=>{var u;const[o,c]=i.split(":");return o&&(s[o.trim()]=(u=c==null?void 0:c.split("!important")[0])==null?void 0:u.trim()),s},{});return Object.entries(t.style).filter(([s,i])=>(n[s]||void 0)!==(i||void 0))};class tn{constructor(t,n){this.mutationObserver=new MutationObserver(()=>{this.isEditing||ge(this)}),this.styleObserver=new MutationObserver(r=>{if(!this.originalElement||!this.element)return;const s=cs(r[0]),i=this.element.style;s.forEach(([o,c])=>{i.setProperty(o,c??null)})}),this.apply=r=>{if(Se===void 0&&ls(),this.isApplied||r!=null&&r.skipClone)return this.originalElement&&this.prop.type==="contactForm"&&Ze(this.originalElement,this.id,this.prop),ge(this),this;const s=this.originalElement;if(s===void 0)return this;s.setAttribute(T,this.id);let i;return this.prop.type==="contactForm"?i=Ze(s,this.id,this.prop):(i=s.cloneNode(!0),this.prop.type==="text"&&C()&&window.userledSettings.enableInlineEditing&&i.setAttribute("contenteditable","true"),Ut(s),s.insertAdjacentElement("afterend",i)),i.setAttribute(x,this.id),this.registerElement(i),ge(this),this.observe(),this.isApplied=!0,w.set(this.id,this),this},this.registerElement=r=>{this.originalElement&&(this.element=r,!C()&&Rt(this.element,this.originalElement))},this.getSelector=()=>this.isApplied?me(this.id):this.prop.propKey,this.getDOMElement=()=>{const r=this.getSelector();return document.querySelector(r)},this.remove=()=>{const r=this.originalElement;if(r===void 0)return console.error("Trying to remove an element with no original ref",this.id),this;const s=this.element;return s===void 0?(console.error("Trying to remove an element which is not on the page",this.id),this):(this.prop.type==="contactForm"?zr(s,this.id):Nt(r),s.remove(),r.removeAttribute(T),w.delete(this.id),this)},this.observe=()=>{var r;this.element!==void 0&&((r=this.mutationObserver)==null||r.observe(this.element,{subtree:!0,characterData:!0}),this.originalElement&&this.styleObserver.observe(this.originalElement,{attributes:!0,attributeFilter:["style"],attributeOldValue:!0}))},this.reset=()=>{this.mutationObserver.disconnect(),this.styleObserver.disconnect(),this.originalElement=void 0,this.element=void 0},this.id=t.userledId||Y(),this.prop=t,this.isApplied=!1,this.originalElement=n,this.isEditing=!1,this.prop.userledId=this.id}}const w=new Map;let Se;const ls=()=>{Se=new MutationObserver(e=>{w.size===0||!e.some(n=>{var r,s;return n.type==="childList"||(((r=n.addedNodes)==null?void 0:r.length)||0)>0||(((s=n.removedNodes)==null?void 0:s.length)||0)>0})||setTimeout(()=>{for(const[,n]of w){let r=n.getDOMElement();n.isApplied&&!r&&(n.isApplied=!1,r=n.getDOMElement()),!n.isApplied&&r&&nn(n.prop)}},25)}),Se.observe(document,{childList:!0,subtree:!0})},ke=(e,t)=>{if(Ds()){a("Legacy site has applied custom site. Ignoring asset.");return}if(ie&&!t){a(`Ignoring applyAsset: there's already an active asset [${ie.id}].`);return}if(!e.url||!ue(e.url,window.location.href)){console.warn(`Trying to apply asset [${e.id}] on the wrong url.`);return}He(),ie=e;const n=Object.values(e.props??{});return De(n),!0},ds=e=>{var t;return(t=w.get(e))==null?void 0:t.prop},nn=async e=>{if(e.userledId&&w.get(e.userledId)){const i=w.get(e.userledId);if(i)return i.prop=e,i.apply(),e}const t=He(),n=[e,...t],r=new Set,s=new Set;return n.forEach(i=>{s.has(i.propKey)||(s.add(i.propKey),r.add(i))}),De([...r]),e},De=e=>{const t=new Set;for(const n of e){const r=document.querySelector(n.propKey)||void 0,s=new tn(n,r);t.add(s)}for(const n of t)n.apply();return e},He=()=>{const e=[];for(const[t,n]of w)rn(t),e.push(n.prop);return e},rn=e=>{var n;const t=w.get(e);if(t!=null&&t.prop.propKey&&((n=document.getElementById(sn(t.prop.propKey)))==null||n.remove()),!t){console.error("Trying to remove an element which is not applied.",e);return}return t.remove(),t.prop},ge=async e=>{const t=e.element,n=e.originalElement;if(!t||!n){console.error("Trying to apply edit with no element or original",t,n);return}switch(e.prop.type){case"text":return C()&&(t.addEventListener("focus",()=>{e.isEditing=!0}),t.addEventListener("blur",()=>{e.isEditing=!1}),t.addEventListener("focusout",()=>{e.isEditing=!1})),e.isEditing?void 0:us(e.prop,t,n);case"image":return ps(e.prop,t,n);case"button":return hs(e.prop,t,n);case"input":return ys(e.prop,t,n);case"iframe":return ms(e.prop,t,n);case"svg":return gs(e.prop,t,n);case"contactForm":return;default:console.error("unknown edit type",e.prop.type);return}},us=async(e,t,n)=>{if(!_(t)||!_(n)){console.error("trying to apply text edit to non-text element",e.propKey);return}const r=E(e.value);r!==null&&(t.innerHTML=r,M(t,n,e.customStyle))},ms=async(e,t,n)=>{if(!N(t)||!N(n)){console.error("trying to apply iframe edit to non-iframe element",e.propKey);return}const r=e.src?E(e.src):null,s=r?!!r.match(os):!1;if(!e.srcdoc&&!s){console.error("invalid iframe source:",e.propKey,r);return}r&&s?t.src=r:e.srcdoc&&(t.srcdoc=e.srcdoc),M(t,n,e.customStyle)},hs=async(e,t,n)=>{if(!$(t)||!$(n)){console.error("trying to apply button edit to non-button element",e.propKey);return}if(e.value!==void 0){const r=E(e.value);if(r===null)return;t.innerHTML=r}t.href=e.href,M(t,n,e.customStyle),e.trackClicks&&e.trackingName&&t.addEventListener("click",()=>{P("BUTTON_CLICKED",{pageId:Gt(),id:e.propKey,name:e.trackingName,assetId:O(),isConversion:e.isConversion||!1,channel:f.Outbound,value:e.value})});for(const r of e.children??[]){const s=r.propKey.substring(e.propKey.length),i=n.querySelector(s);if(!i){console.error("could not find button original child element",r);return}const o=t.querySelector(s);if(!o){console.error("could not find button child element",r);return}const c=new tn(r,i);c.registerElement(o),c.apply({skipClone:!0})}},ps=async(e,t,n)=>{if(!F(t)||!F(n)){console.error("trying to apply image edit to non-image element",e.propKey);return}let r=e.src;if(e.imageType==="smart"&&C()){const{src:i,needApplying:o}=fs(e,t);if(!o)return;r=i}if(r){if(nt(t,r),t.parentElement&&$t(t.parentElement))for(let i=0;i{if(!R(t)||!R(n)){console.error("trying to apply svg edit to non-svg element",e.propKey);return}const r=e.value;if(!r)return;const s=new DOMParser().parseFromString(r,"text/html").body.firstChild;[...s.attributes].forEach(({name:i,value:o})=>{i!==x&&i!==T&&t.setAttribute(i,o)}),t.innerHTML=s.innerHTML,M(t,n,e.customStyle)},nt=(e,t)=>{const n=e.getAttribute("srcset");e.srcset=t,e.src="",n!=null&&n.startsWith("blob:")&&URL.revokeObjectURL(n)},sn=e=>`userled-loader-${e}`,fs=(e,t)=>{var s,i,o,c,u,p;const n=sn(e.propKey);if(!e.props)return(s=document.getElementById(n))==null||s.remove(),t.alt="Please select a smart image",{src:"https://assets.userled.io/media/gradient.png",needApplying:!0};if(e.customSitePreviewBlob)return(i=document.getElementById(n))==null||i.remove(),t.style.display=((o=e.customStyle)==null?void 0:o.display)??"",{src:URL.createObjectURL(e.customSitePreviewBlob),needApplying:!0};if(document.getElementById(n))return{src:"",needApplying:!1};t.style.display="none";const r=vs(n,((c=e.customStyle)==null?void 0:c.width)??"100%",((u=e.customStyle)==null?void 0:u.height)??"100%");return(p=t.parentElement)==null||p.insertBefore(r,t),{src:"",needApplying:!1}},ys=async(e,t,n)=>{if(!U(t)||!U(n)){console.error("trying to apply input edit to non-input element",e.propKey);return}if(e.placeholder===void 0&&e.value===void 0)return;const r=E(e.value??""),s=E(e.placeholder??"");t.value=r??"",t.placeholder=s??"",t.dispatchEvent(new Event("change")),t.dispatchEvent(new Event("input")),M(t,n,e.customStyle)},M=(e,t,n)=>{if(n){e.style.cssText=t.dataset.originalStyle||"";for(const[r,s]of Object.entries(n)){const i=r.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase();e.style.setProperty(i,s)}}},vs=(e,t,n)=>{const r=document.createElement("div");r.id=e,r.style.display="inline-block",r.style.width=t,r.style.height=n;const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.background="linear-gradient(-45deg, #ffe56f 0%, #FFC4F6 100%)",s.style.backgroundSize="300%",s.style.backgroundPosition="center",s.style.display="flex",s.style.justifyContent="center",s.style.alignItems="center";const i=document.createElement("div");return i.classList.add("userled-smart-image-loader"),i.setAttribute(j,"true"),s.appendChild(i),r.appendChild(s),r},ws=e=>e.match(/{{.*?}}/g),bs=e=>{const t=e.match(/{{ *query.([a-zA-Z_]+) *( || +([a-z]+) *){0,1}}}/);if(!t||t.length<2)return["",void 0];const[n,r]=[t[1],t[3]];return n?r?[n,As[r]]:[n,on]:["",void 0]};function Es(e){const t=/[a-z]/;return e.replace(t,Me)}function Is(e){const t=/[a-z]/g;return e.replace(t,Me)}function Me(e){return e.toUpperCase()}function Ss(e){return e.toLowerCase()}const on=e=>e,As={"":on,title:Is,capitalised:Es,upper:Me,lower:Ss},Z=(e,t,n)=>{var r;if(!e)return{};if(!t)return e;if(n!=null&&n.matchedCase){const s=(r=e.caseOverwrites)==null?void 0:r[n.matchedCase.id];e={...e,...s},delete e.caseOverwrites}switch(e.type){case"text":return Ts(e,t,n);case"button":return Ps(e,t,n);case"logo":return xs(e,t);case"image":return Os(e,t,n);case"input":return Ls(e,t,n);case"container":return Cs(e,t,n);case"video":return _s(e,t,n);case"iframe":return Fs(e,t,n);default:return e}},Cs=(e,t,n)=>{const r=e.children.map(s=>Z(s,t,n));return{...e,children:r}},Ts=(e,t,n)=>({...e,value:b(e.value,t,n)}),Ps=(e,t,n)=>{var s;const r=(s=e.children)==null?void 0:s.map(i=>Z(i,t,n));return{...e,value:e.value?b(e.value,t,n):e.value,href:b(e.href,t,n),children:r}},xs=(e,t)=>{const n=gt(e.url);if(n.length===0)return e;const r=t.getValue(n[0]);return typeof r!="string"?e:{...e,url:r}},Os=(e,t,n)=>{if(e.imageType==="variable"&&e.src)return{...e,src:b(e.src,t,n)};if(e.imageType==="smart")return{...e,props:e.props?Object.fromEntries(Object.entries(e.props).map(([s,i])=>[s,Z(i,t,n)])):void 0};if(e.useTargetLogo!==void 0&&!e.useTargetLogo||e.imageType&&e.imageType!=="target_logo")return e;let r=t.getValue(On);return typeof r!="string"?e:{...e,src:r}},Ls=(e,t,n)=>!e.placeholder&&!e.value?e:{...e,value:e.value?b(e.value,t,n):e.value,placeholder:e.placeholder?b(e.placeholder,t,n):e.placeholder},_s=(e,t,n)=>({...e,src:e.src?b(e.src,t,n):e.src}),Fs=(e,t,n)=>({...e,src:e.src?b(e.src,t,n):e.src,srcdoc:e.srcdoc?b(e.srcdoc,t,n):e.srcdoc}),b=(e,t,n)=>gt(e).reduce((s,i)=>{const o=t.getValue(i);return typeof o=="string"?!o&&(n!=null&&n.keepUnresolved)?s:s.replace(i.raw,o):s},e),$s=(e,t)=>{const n=Object.entries(e.props??{}).reduce((r,[s,i])=>(r[s]=Z(i,t),r),{});return{...e,props:n}},an=(e,t,n)=>{if(!e.dynamic||!e.cases)return e;try{const r=Object.entries(e.props??{}).reduce((s,[i,o])=>(s[i]=Z(o,t,{matchedCase:n}),s),{});return{...e,props:r}}catch(r){return console.error(`Could not resolve dynamic asset [${e.id}]: ${r}`),e}},fe="",ne="",cn=new Map;let g;const ks=()=>g,Ds=()=>!!(g!=null&&g.id);class Hs{constructor(t,n){const r=t.id||Y();this.id=r,this.edit=t,this.edit.id=r,this.originalElement=n,this.isApplied=!1}registerElement(t){var n,r;this.originalElement&&(this.element=t,Rt(this.element,this.originalElement),this.edit.original=this.originalElement?new B(this.originalElement).value():void 0,this.edit.computedCSS=new B(t).getStyle(),this.mutationObserver=new MutationObserver(()=>{Ae(this)}),this.intersectionObserver=new IntersectionObserver(s=>{s.some(i=>i.isIntersecting===!1)&&!document.querySelector(me(this.edit.id??""))&&(this.reset(),Re(this))},{root:document.querySelector("body")}),(n=this.mutationObserver)==null||n.observe(t,{subtree:!0,characterData:!0}),(r=this.intersectionObserver)==null||r.observe(t))}disconnect(){var t,n;(t=this.mutationObserver)==null||t.disconnect(),(n=this.intersectionObserver)==null||n.disconnect()}reset(){this.disconnect(),this.originalElement=void 0}}const h=new Map,ln=()=>{const e=[];for(const[t,n]of h)q(t),e.push(n.edit);return e},K=new MutationObserver(e=>{if(e.some(n=>{var r;return n.type==="childList"&&((r=n.addedNodes)==null?void 0:r.length)>0})){for(const[,r]of h)r.originalElement||Ue(r.edit);[...h.values()].every(r=>!!r.originalElement)&&K.disconnect()}});function Ms(e){cn.set(e.id,e);const t=de();if(as()){a("Ignoring applyCustomSite: asset already apply.");return}if(g!=null&&g.id){a("Site already applied",g.id,"Trying to apply site",e.id);return}un(e,t)}const q=e=>{const t=h.get(e),n=t==null?void 0:t.originalElement;if(!t||!n)return;t.disconnect();const r=document.querySelector(me(e)),s=document.querySelector(Kr(e));return!r||!s?void 0:(r.remove(),Nt(s),s.removeAttribute(T),h.delete(e),new B(n).value())},Us=e=>{const t=h.get(e);if(!t){console.warn("Page edit not found");return}return t.edit},E=e=>{if(C())return e;const t=ws(e);if(!t)return e;let n=e;const r=new URLSearchParams(window.location.search);for(const s of t){const[i,o]=bs(s);if(!i||!o)return null;const c=Ln(r.get(i));if(!c)return null;n=n.replace(s,o(c))}return n},ye=(e,t,n)=>{const r=n.appliedCSS;if(r){e.style.cssText=t.dataset.originalStyle||"";for(const[s,i]of Object.entries(r))e.style.setProperty(s,i)}},Ae=e=>{const t=e.element,n=e.originalElement,r=e.edit;if(!n||!t)return!1;if(_(t)&&kr(r)){const s=E(r.value.value);if(s===null)return q(t.id),!1;t.innerHTML=s,ye(t,n,r)}else if($(t)&&Hr(r)){const s=E(r.value.value);if(s===null)return q(t.id),!1;t.innerHTML=s,t.href=r.value.href,ye(t,n,r)}else if(F(t)&&Dr(r))Ks(t,r),ye(t,n,r);else if(Je(r)&&Dt(t))Rs(r);else if(Je(r)&&Ht(t))Ns(r);else throw q(t.id),`unrecognised html tag [${r.tag}]`;return!0},Ns=e=>{const t=E(e.value.value);if(!t)return;const n=document.querySelector(me(e.id??""));n&&n.remove();const r=document.createElement("script");r.textContent=t,r.setAttribute(x,e.id??""),document.body.appendChild(r)},Rs=e=>{const t=E(e.value.value),n=document.querySelector(e.tag);if(!n||!t)return;const r=n.innerHTML,s=r.indexOf(fe),i=r.indexOf(ne);let o;s>-1&&i>-1?o=r.substring(0,s)+fe+t+ne+r.substring(i+ne.length):o=r+fe+t+ne,document.head.innerHTML=o},Ks=(e,t)=>{if(e.srcset=t.value.url,e.src="",e.parentElement&&$t(e.parentElement))for(let n=0;n{if(e.id&&h.get(e.id)){const i=h.get(e.id);if(i)return i.edit=e,Re(i),e}const t=ln(),n=[e,...t],r=new Set,s=new Set;return n.forEach(i=>{s.has(i.selector)||(s.add(i.selector),r.add(i))}),Ne([...r]),e},Ne=e=>{const t=new Set;for(const n of e){const r=n.selector,s=document.querySelector(r)||void 0,i=new Hs(n,s);t.add(i)}for(const n of t)Re(n);return e},Re=e=>{if(!e.originalElement)return h.set(e.id,e),K.observe(document,{childList:!0,subtree:!0}),!0;if(e.isApplied)return Ae(e);const t=e.edit,n=e.originalElement,r=n.cloneNode(!0);return n.setAttribute(T,e.id),Ut(n),n.insertAdjacentElement("afterend",r),r.setAttribute(x,e.id),e.registerElement(r),Ae(e)?(e.isApplied=!0,h.set(e.id,e),!0):(console.error("Failed to apply personalisation. Could not apply edit",t),!1)},dn=()=>{for(const[,e]of h)e==null||e.disconnect();K==null||K.disconnect()};window.onpagehide=()=>{dn()};function qs(e,t,n){a(`Sending CustomSiteRendered: [customSiteId:${e}, url:${t}]`),P("CUSTOM_SITE_RENDERED",{customSiteId:e,url:t,targetId:n,appliedEdits:h.size})}const Vs=()=>{const e=de();if(C()){for(const n of h.values())n.reset(),Ue(n.edit);return}dn(),h.clear();let t=!1;for(const[,n]of cn)if(t=un(n,e),t)break;t||(g=void 0)},un=(e,t,n)=>{for(const r of e.pages)if(ue(r.url,t))return g={id:e.id,pageUrl:r.url},a("Applying custom site",g.id,r.url,e,A()),Ne(r.edits),qs(g.id,t,n),!0;return!1};async function zs(e){if(!e)return;const t=await oe.getAsset(e),n=t.cases||[],r=document.createElement("iframe");r.style.cssText="position:fixed;bottom:2.5rem;height:64px;z-index:1000;left:50%;transform:translateX(-50%);overflow:hidden;border:none;width:calc(100% - 5rem);max-width:834px;",r.setAttribute("scrolling","no"),r.setAttribute("allow","clipboard-write");const s=window.matchMedia("(max-width: 480px)").matches,i=n.length>0,o=n.map(p=>{const L=document.createElement("option");return L.value=p.id,L.innerText=p.name,L}),c=i?`
Preview variant
`:s?"":`
This is a preview for a Userled website.
Internal use only.
`,u=`
${c}
`;r.setAttribute("srcdoc",u),document.body.appendChild(r),window.addEventListener("message",p=>{if(p.data.type==="apply-case"){const L=p.data.caseId,Ke=n.find(he=>he.id===L),gn=Ke?an(t,{getValue:he=>he.raw},Ke):t;ke(gn,!0)}})}const js="userled_asset",O=()=>Fn(window.location.search,js),Bs=async()=>{var n;const e=O(),t=le();if(e)try{const[r,s]=await Promise.all([oe.getAsset(e),window.userledSettings.enableDynamicAssets&&t?oe.matchAssetCase(e,t,window.location.href):Promise.resolve(null)]),i=(n=r.cases)==null?void 0:n.find(c=>c.id===(s==null?void 0:s.caseId)),o=r.dynamic&&s&&i?an(r,{getValue:c=>{if(!(c.raw in s.variables))throw new Error("Variable not found in match result");return s.variables[c.raw]}},i):r;ke(o),Xt(r.id,{channel:f.Outbound,campaignId:r.campaignId,caseId:i==null?void 0:i.id}),await Fe({name:document.title||window.location.href,campaignId:r.campaignId,caseId:i==null?void 0:i.id})}catch(r){console.error(`Could not render site asset [${e}]: ${r}`)}else wr(),Vs()},Ws=function(){let e="";return function(){const t=ht();t&&e!=t&&(e=t,P("HUTK_DETECTED",{hutk:e}))}}();let rt;const Gs=()=>{rt||(rt=window.setInterval(Ws,2e3))},st=async e=>{try{const t=await fetch($n.Inbound(e));if(!t.ok)throw new Error("Failed to fetch inbound campaigns from cloudfront");const n=await t.json();return Qn(n),n}catch(t){throw new Error(`Failed to fetch inbound campaigns: ${t}`)}},Js=async e=>{const t=Zn();return t?(st(e),t):st(e)},Ys=async()=>{const e=v(),t=le();if(!e||!t)return!1;const n=kn(`Fetching and matching inbound campaigns of [${e}]`),[r,s]=await Promise.all([er({orgId:e,userId:t,serverUrl:J,url:window.location.href}),Js(e)]);if(n(),!r)return a("Inbound campaign not matched, skipping"),!1;if(!s||s.length===0)return a("No inbound campaigns, skipping"),!1;const i=s.find(u=>u.id===r.inboundCampaignId);if(!i)return a("No inbound campaign found, skipping"),!1;const o=i.inboundAssets.find(u=>u.status!=="active"?!1:ue(u.url,window.location.href));if(!o)return a("No inbound asset found for the current URL",window.location.href),!1;const c=$s(o,r);return ke(c),Xt(o.id,{channel:f.Inbound,campaignId:i.id}),await Fe({name:document.title||window.location.href,inboundAssetId:o.id,campaignId:i.id}),n(),!0},it={ShowPrompt:"SHOW_PROMPT",ShowCustomSite:"SHOW_CUSTOM_SITE"};function Qs(e){const t=JSON.parse(e.data),n=O();switch(t.type){case it.ShowPrompt:if(n)return;vr(t.body);break;case it.ShowCustomSite:if(n)return;a("Received custom site message",t.body.id),Ms(t.body);break;default:a(`Unrecognised event type: ${t.type}`);return}}const Zs=async({overrideFingerprintEnabled:e}={})=>{const{app_id:t,enableIdentification:n}=Ce();if(!t){a("no userled appId set");return}const r=await Dn({fingerprintEnabled:e||n&&!ce()});if(!(r!=null&&r.userFingerprint)){a("No fingerprint generated");return}return{userFingerprint:r.userFingerprint||void 0,requestId:r.requestId||void 0}};let re,ot;const Xs=async e=>(ot=async()=>{const{app_id:t}=Ce();if(!t){a("no userled appId set");return}a("Opening websocket",A());const n=await Zs(),r=n==null?void 0:n.userFingerprint,s=n==null?void 0:n.requestId;return new Promise(i=>{re=new WebSocket(ni(t,r,s)),re.onopen=()=>{a("Connection opened",A(),Hn()),i()},re.onclose=ei,re.onmessage=o=>ti(o,e)})},ot()),ei=e=>{a(`Connection closed (code:${e.code}) (reason:${e.reason}) (wasClean:${e.wasClean})`)},ti=(e,t)=>{t(e)};function ni(e,t,n){const r=new URL(Mn);r.searchParams.set("app_id",e),r.searchParams.set("browser_id",ri());const s=le();s&&r.searchParams.set("user_id",s),t&&r.searchParams.set("fingerprint",t),n&&r.searchParams.set("request_id",n);const i=Tt();i&&r.searchParams.set("session_id",i);const o=ft();if(o&&r.searchParams.set("snippet_version",o),qn())return r;const c=Nn();c&&r.searchParams.set("snippet_executed_at",c.toString());const u=Rn;u&&r.searchParams.set("sdk_executed_at",u.toString());const p=Kn();return p&&r.searchParams.set("first_visible_at",p.toString()),r.searchParams.set("dom_loaded",(document.readyState!=="loading").toString()),r.searchParams.set("ws_init_at",Un().toString()),r}const at="userled_browser_id";let ve=null;const ri=()=>{if(ve)return ve;let e=dt(at);return e||(e=Y(),ve=e,ut(at,e)),e},si=async()=>Bs(),mn=async e=>{try{await fetch(`${J}/api/debug`,{method:"POST",body:JSON.stringify(e)})}catch(t){console.error("Failed to send debug log",t)}},ii=async e=>{try{await fetch(`${J}/api/metrics`,{method:"POST",body:JSON.stringify(e)})}catch(t){let n;t instanceof Error&&(n=t.stack),mn({message:"Failed to send metrics",error:String(t),stack:n})}},hn=()=>{const e=performance.now();return t=>{const r=(performance.now()-e)/1e3;ii([{name:"userled_sdk_latency_seconds",value:r,labels:t}])}},oi=async()=>{const e=O()??void 0,t=Vn()||!!e&&!zn,n=Bt();return jn(v(),{apiUrl:`${J}/api`,snippetVersion:ft(),useFingerprint:t,assetId:e,accountId:n.accountId,contactId:n.contactId,email:n.email})};(async()=>{if(ce()){a(`Running SDK in DRY mode. Editor: ${C()}, Screenshot: ${Bn()}, Preview: ${yt()}`),lt();return}try{const e=hn(),t=await oi();t.cached||e({org_id:v(),metric:"setup_sdk"}),a("Visitor identity: ",t),Wn()&&await Xs(Qs),lt()}catch(e){console.error(e);let t;e instanceof Error&&(t=e.stack),mn({message:"Failed to identify user",pageId:Gt(),error:String(e),stack:t,userAgent:navigator.userAgent,orgId:v()})}})();function ct(){const e=vt();for(a(`Flushing ${e.queue.length} items from queue`,A());e.queue.length>0;){const t=e.queue.shift();if(!t)continue;const[n,,r,...s]=t,i=pn(r,s);n(i)}}window.onresize=xt;window.addEventListener("load",()=>{ce()||setTimeout(()=>oe.reportLatency(v()),1e3)});async function ai(){const e=O(),t=hn();if(e){await si(),t({org_id:v(),metric:"outbound"});return}if(Gn){let n=!1;try{n=await Ys(),t({org_id:v(),metric:"inbound"})}catch(r){a("Error matching inbound campaign",r)}finally{n||await Fe({name:document.title||window.location.href})}}}async function pn(e,t){switch(e){case"page":return Te.enqueue(()=>ai());case"getPageEdit":return Us(t[0]);case"applyEdit":return Ue(t[0]);case"applyEdits":return Ne(t[0]);case"removeEdit":return q(t[0]);case"removeEdits":return ln();case"getAssetProp":return ds(t[0]);case"applyAssetProp":return nn(t[0]);case"applyAssetProps":return De(t[0]);case"removeAssetProp":return rn(t[0]);case"removeAssetProps":return He();default:return console.error("command undefined: ",e),Promise.resolve()}}function lt(){a("Setting up SDK",A());const e=vt();ct(),e.call=async t=>{const[n,...r]=t;return await pn(n,r)},ct(),yt()&&zs(O()),Gs(),a("Set up SDK",A())}