import{a as addQueryArgs}from"./add-query-args.js";var _a;const lang=(null===(_a=window.scData)||void 0===_a?void 0:_a.locale)||navigator.language||(null===navigator||void 0===navigator?void 0:navigator.browserLanguage)||(navigator.languages||["en"])[0];let cachedCountryChoices=null;const countryDetailsCache=new Map,countryChoices=async()=>{var a,o,t,e;if(cachedCountryChoices)return cachedCountryChoices;const n=addQueryArgs("https://api.surecart.com/v1/public/atlas",{locale:lang}),r=await fetch(n),i=await r.json(),s=null===(a=(null==i?void 0:i.data)||[])||void 0===a?void 0:a.map((({code:a,name:o})=>({value:a,label:o})));return cachedCountryChoices=(null===(e=null===(t=null===(o=null===window||void 0===window?void 0:window.wp)||void 0===o?void 0:o.hooks)||void 0===t?void 0:t.applyFilters)||void 0===e?void 0:e.call(t,"surecart_address_countries",s))||s,cachedCountryChoices},getCountryDetails=async a=>{if(countryDetailsCache.has(a))return countryDetailsCache.get(a);const o=addQueryArgs(`https://api.surecart.com/v1/public/atlas/${a}`,{locale:lang}),t=await fetch(o),e=await t.json();return countryDetailsCache.set(a,e),e},getCountryRegions=async a=>{if(!a)return[];const o=await getCountryDetails(a);return((null==o?void 0:o.states)||[]).map((a=>({value:a.code,label:a.name})))};export{getCountryRegions as a,countryChoices as c,getCountryDetails as g};