"use strict";var sonder=(()=>{var a=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},u=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of p(t))!c.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(i=d(t,r))||i.enumerable});return e};var g=e=>u(a({},"__esModule",{value:!0}),e);var h={};l(h,{SonderClient:()=>o});var o=class{apiUrl;apiKey;spokeId;anonymousId;constructor(t={}){this.apiUrl=t.apiUrl||"https://sonderprotocol.com",this.apiKey=t.apiKey,this.spokeId=t.spokeId||"web_client",this.anonymousId=t.anonymousId||this.getOrCreateAnonymousId()}getOrCreateAnonymousId(){if(typeof window<"u"&&window.localStorage){let t=localStorage.getItem("__snd_anon_id");return t||(t=`snd_anon_${Math.random().toString(36).substring(2,10)}`,localStorage.setItem("__snd_anon_id",t)),t}return`snd_anon_${Math.random().toString(36).substring(2,10)}`}async track(t,n={},i){let r={personId:i,anonymousId:this.anonymousId,spokeId:this.spokeId,eventType:t,eventPayload:n,timestamp:new Date().toISOString()};try{let s=await fetch(`${this.apiUrl}/v1/signal`,{method:"POST",headers:{"Content-Type":"application/json",...this.apiKey?{Authorization:`Bearer ${this.apiKey}`}:{}},body:JSON.stringify(r)});return s.status===202||s.status===200}catch{return!1}}async decide(t,n="default"){try{let i=await fetch(`${this.apiUrl}/v1/decide`,{method:"POST",headers:{"Content-Type":"application/json",...this.apiKey?{Authorization:`Bearer ${this.apiKey}`}:{}},body:JSON.stringify({personId:t,spokeId:this.spokeId,context:n})});return i.ok?await i.json():null}catch{return null}}async checkPreflight(t,n){try{let r=await(await fetch(`${this.apiUrl}/v1/gate/preflight`,{method:"POST",headers:{"Content-Type":"application/json",...this.apiKey?{Authorization:`Bearer ${this.apiKey}`}:{}},body:JSON.stringify({targetPersonId:t,proposedSubject:n})})).json();return{approved:r.status==="APPROVED",proof:r.attentionProof?.headerValue}}catch{return{approved:!1}}}};if(typeof window<"u"){let e=document.currentScript,t=e?.getAttribute("data-spoke")||"browser",n=e?.getAttribute("data-api-key")||void 0,i=e?.getAttribute("data-api-url")||void 0;window.sonder=new o({spokeId:t,apiKey:n,apiUrl:i})}return g(h);})();