function ue(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}const L=Symbol.for("RemoteUi::Retain"),R=Symbol.for("RemoteUi::Release"),$=Symbol.for("RemoteUi::RetainedBy");class q{constructor(){this.memoryManaged=new Set}add(t){this.memoryManaged.add(t),t[$].add(this),t[L]()}release(){for(const t of this.memoryManaged)t[$].delete(this),t[R]();this.memoryManaged.clear()}}function Q(s){return!!(s&&s[L]&&s[R])}function k(s){if(s==null||typeof s!="object")return!1;const t=Object.getPrototypeOf(s);return t==null||t===Object.prototype}const O="_@f";function V(s){const t=new Map,o=new Map,c=new Map;return{encode:p,decode:d,async call(e,r){const l=new q,i=o.get(e);if(i==null)throw new Error("You attempted to call a function that was already released.");try{const u=Q(i)?[l,...i[$]]:[l];return await i(...d(r,u))}finally{l.release()}},release(e){const r=o.get(e);r&&(o.delete(e),t.delete(r))},terminate(){t.clear(),o.clear(),c.clear()}};function p(e,r=new Map){if(e==null)return[e];const l=r.get(e);if(l)return l;if(typeof e=="object"){if(Array.isArray(e)){r.set(e,[void 0]);const u=[],y=[e.map(h=>{const[g,n=[]]=p(h,r);return u.push(...n),g}),u];return r.set(e,y),y}if(k(e)){r.set(e,[void 0]);const u=[],y=[Object.keys(e).reduce((h,g)=>{const[n,a=[]]=p(e[g],r);return u.push(...a),{...h,[g]:n}},{}),u];return r.set(e,y),y}}if(typeof e=="function"){if(t.has(e)){const y=t.get(e),h=[{[O]:y}];return r.set(e,h),h}const u=s.uuid();t.set(e,u),o.set(u,e);const m=[{[O]:u}];return r.set(e,m),m}const i=[e];return r.set(e,i),i}function d(e,r){if(typeof e=="object"){if(e==null)return e;if(Array.isArray(e))return e.map(l=>d(l,r));if(O in e){const l=e[O];if(c.has(l))return c.get(l);let i=0,u=!1;const m=()=>{i-=1,i===0&&(u=!0,c.delete(l),s.release(l))},y=()=>{i+=1},h=new Set(r),g=(...n)=>{if(u)throw new Error("You attempted to call a function that was already released.");if(!c.has(l))throw new Error("You attempted to call a function that was already revoked.");return s.call(l,n)};Object.defineProperties(g,{[R]:{value:m,writable:!1},[L]:{value:y,writable:!1},[$]:{value:h,writable:!1}});for(const n of h)n.add(g);return c.set(l,g),g}if(k(e))return Object.keys(e).reduce((l,i)=>({...l,[i]:d(e[i],r)}),{})}return e}}const v=0,N=1,_=2,j=3,M=5,P=6;function X(s,{uuid:t=J,createEncoder:o=V,callable:c}={}){let p=!1,d=s;const e=new Map,r=new Map,l=Y(y,c),i=o({uuid:t,release(n){u(j,[n])},call(n,a,f){const E=t(),T=h(E,f),[w,b]=i.encode(a);return u(M,[E,n,w],b),T}});return d.addEventListener("message",m),{call:l,replace(n){const a=d;d=n,a.removeEventListener("message",m),n.addEventListener("message",m)},expose(n){for(const a of Object.keys(n)){const f=n[a];typeof f=="function"?e.set(a,f):e.delete(a)}},callable(...n){if(c!=null)for(const a of n)Object.defineProperty(l,a,{value:y(a),writable:!1,configurable:!0,enumerable:!0})},terminate(){u(_,void 0),g(),d.terminate&&d.terminate()}};function u(n,a,f){p||d.postMessage(a?[n,a]:[n],f)}async function m(n){const{data:a}=n;if(!(a==null||!Array.isArray(a)))switch(a[0]){case _:{g();break}case v:{const f=new q,[E,T,w]=a[1],b=e.get(T);try{if(b==null)throw new Error(`No '${T}' method is exposed on this endpoint`);const[S,A]=i.encode(await b(...i.decode(w,[f])));u(N,[E,void 0,S],A)}catch(S){const{name:A,message:D,stack:G}=S;throw u(N,[E,{name:A,message:D,stack:G}]),S}finally{f.release()}break}case N:{const[f]=a[1];r.get(f)(...a[1]),r.delete(f);break}case j:{const[f]=a[1];i.release(f);break}case P:{const[f]=a[1];r.get(f)(...a[1]),r.delete(f);break}case M:{const[f,E,T]=a[1];try{const w=await i.call(E,T),[b,S]=i.encode(w);u(P,[f,void 0,b],S)}catch(w){const{name:b,message:S,stack:A}=w;throw u(P,[f,{name:b,message:S,stack:A}]),w}break}}}function y(n){return(...a)=>{if(p)return Promise.reject(new Error("You attempted to call a function on a terminated web worker."));if(typeof n!="string"&&typeof n!="number")return Promise.reject(new Error(`Can’t call a symbol method on a remote endpoint: ${n.toString()}`));const f=t(),E=h(f),[T,w]=i.encode(a);return u(v,[f,n,T],w),E}}function h(n,a){return new Promise((f,E)=>{r.set(n,(T,w,b)=>{if(w==null)f(b&&i.decode(b,a));else{const S=new Error;Object.assign(S,w),E(S)}})})}function g(){var n;p=!0,e.clear(),r.clear(),(n=i.terminate)===null||n===void 0||n.call(i),d.removeEventListener("message",m)}}function J(){return`${I()}-${I()}-${I()}-${I()}`}function I(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)}function Y(s,t){let o;if(t==null){if(typeof Proxy!="function")throw new Error("You must pass an array of callable methods in environments without Proxies.");const c=new Map;o=new Proxy({},{get(p,d){if(c.has(d))return c.get(d);const e=s(d);return c.set(d,e),e}})}else{o={};for(const c of t)Object.defineProperty(o,c,{value:s(c),writable:!1,configurable:!0,enumerable:!0})}return o}function x(){return typeof performance>"u"?Date.now():performance.now()}const B=` query validation($address: AddressInput!, $locale: String!, $matchingStrategy: MatchingStrategy) { validation(address: $address, locale: $locale, matchingStrategy: $matchingStrategy) { validationScope locale fields { name value } concerns { fieldNames code type typeLevel suggestionIds message } id suggestions { id address1 streetName streetNumber address2 line2 neighborhood city zip provinceCode province countryCode } } } `;class z extends Error{constructor(t,o){super(`GraphQL fetch failed with network failure or prevented the request from completing: ${o.message}. headers: ${JSON.stringify(Object.fromEntries(t.entries()))}`),this.headers=t,this.error=o}name="AddressValidatorGraphQLFetchNetworkError"}class W extends Error{constructor(t,o){super(`GraphQL fetch failed with status: ${t}, response: ${o}`),this.status=t,this.response=o}name="AddressValidatorHttpError"}const K="validation",Z={"Content-Type":"application/json",Accept:"application/json"};class ee{validationEndpoint;constructor({validationEndpoint:t}){this.validationEndpoint=t}async validate({address:t,locale:o,matchingStrategy:c},p={}){const d=new Headers({...Z,...p.overrideHeaders}),e=await fetch(this.validationEndpoint,{method:"POST",headers:d,body:JSON.stringify({query:B,operationName:K,variables:{address:t,locale:o,matchingStrategy:c}})}).catch(i=>i);if(e instanceof Error)throw new z(d,e);if(!e.ok)throw new W(e.status,await e.text());const{data:r,errors:l}=await e.json();return{data:r.validation,errors:l}}}const te="atlas.shopifysvc.com",C=`https://${te}/graphql`,F="elasticsearch",U="google",ne=new Map([["ELASTICSEARCH_AUTOCOMPLETE",F],["GOOGLE_PLACE_AUTOCOMPLETE",U]]);class H extends Error{name="AutocompletePredictionError"}const re=` query predictions($query: String, $countryCode: AutocompleteSupportedCountry!, $locale: String!, $location: LocationInput, $sessionToken: String!, $adapterOverride: String) { predictions(query: $query, countryCode: $countryCode, locale: $locale, location: $location, sessionToken: $sessionToken, adapterOverride: $adapterOverride) { addressId description completionService matchedSubstrings { length offset } } } `,oe=` query address($addressId: String!, $locale: String!, $sessionToken: String!, $adapterOverride: String, $extendedFields: Boolean = false) { address(id: $addressId, locale: $locale, sessionToken: $sessionToken, adapterOverride: $adapterOverride, extendedFields: $extendedFields) { address1 address2 city country countryCode province provinceCode zip latitude longitude } } `,se=` query countries($locale: SupportedLocale!) { countries(locale: $locale) { name code phoneNumberPrefix } } `,ae=async(s,t)=>{const o={addressId:s,locale:t.locale,sessionToken:t.requestToken,adapterOverride:ne.get(t.completionService),extendedFields:t.extendedFields},c=await fetch(C,{method:"POST",headers:{"Content-Type":"application/json","X-Shop-Id":t.shopId,"X-Client-Request-Id":t.sourceId},body:JSON.stringify({query:oe,variables:o})}),{data:{address:p}}=await c.json(),{address1:d,address2:e,city:r,countryCode:l,provinceCode:i,zip:u,latitude:m,longitude:y}=p,h={latitude:m,longitude:y};return{postalCode:u,city:r,address1:d,address2:e,countryCode:l,zoneCode:i,coordinates:h.latitude&&h.longitude?h:void 0}},ie=async(s,t,o)=>{const c={query:s,countryCode:t.countryCode,location:t.location,locale:t.locale,sessionToken:t.requestToken};[F,U].includes(String(o))&&(c.adapterOverride=o);const p=x(),d=await fetch(C,{method:"POST",headers:{"Content-Type":"application/json","X-Shop-Id":t.shopId,"X-Client-Request-Id":t.sourceId},body:JSON.stringify({query:re,variables:c})}),e=x(),r=await d.json();if(!r.data)throw new H(`No data returned from autocomplete query ${JSON.stringify(r)}`);return{data:r.data.predictions,duration:{start:p,end:e}}},ce=new ee({validationEndpoint:C}),de=async(s,t,o,c)=>{const p={"X-Shop-Id":c?.shopId||"","X-Client-Request-Id":c?.sourceId||""};return ce.validate({address:s,locale:t,matchingStrategy:o},{overrideHeaders:p})},le=async(s,t)=>{async function o(e){return fetch(C,{method:"POST",headers:{"Content-Type":"application/json","X-Shop-Id":t?.shopId??"","X-Client-Request-Id":t?.sourceId??""},body:JSON.stringify({query:se,variables:{locale:e.replace(/-/,"_").toUpperCase()}})})}const p=await(await o(s)).json(),{data:d}=p;if(!d)throw new H(`No data returned from fetch countries with phone number prefix query ${JSON.stringify(p)}`);return d.countries};typeof window<"u"&&X({addEventListener:window.addEventListener.bind(window),removeEventListener:window.removeEventListener.bind(window),postMessage(t,o){window.parent.postMessage(t,"*",o)}},{callable:["search","fetchAddress","validation","fetchCountriesWithPhoneNumberPrefix"]}).expose({search:ie,fetchAddress:ae,validation:de,fetchCountriesWithPhoneNumberPrefix:le});export{ue as __vite_legacy_guard};