var _a;import{addQueryArgs}from"@wordpress/url";export const STATE_INCLUDED_COUNTRIES=["AU","BR","CA","CH","ES","HK","IE","IN","IT","JP","MY","MX","US"];export const POSTAL_CODE_EXCLUDED_COUNTRIES=["HK"];export const CITY_EXCLUDED_COUNTRIES=["SG"];import countries from"./countries.json";export const hasPostal=t=>!POSTAL_CODE_EXCLUDED_COUNTRIES.includes(t);export const hasCity=t=>!CITY_EXCLUDED_COUNTRIES.includes(t);export const hasState=t=>STATE_INCLUDED_COUNTRIES.includes(t);export const hasCompleteAddress=t=>{const{country:o,state:a}=t;return!!hasRequiredFields(t)&&(!hasState(o)||hasCorrectState(o,a))};export const hasCorrectState=(t,o)=>((null==countries?void 0:countries[t])||[]).some((({value:t})=>t===o));export const hasRequiredFields=({city:t,country:o,line_1:a,postal_code:s,state:e})=>!(!o||hasPostal(o)&&!s||hasCity(o)&&!t||hasState(o)&&!e||!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];export const countryChoices=async()=>{var t,o,a,s;const e=addQueryArgs("https://api.surecart.com/v1/public/atlas",{locale:lang}),n=await fetch(e),l=await n.json(),r=null===(t=(null==l?void 0:l.data)||[])||void 0===t?void 0:t.map((({code:t,name:o})=>({value:t,label:o})));return(null===(s=null===(a=null===(o=null===window||void 0===window?void 0:window.wp)||void 0===o?void 0:o.hooks)||void 0===a?void 0:a.applyFilters)||void 0===s?void 0:s.call(a,"surecart_address_countries",r))||r};export const getCountryDetails=async t=>{const o=addQueryArgs(`https://api.surecart.com/v1/public/atlas/${t}`,{locale:lang}),a=await fetch(o);return await a.json()};export const isAddressComplete=t=>(null==t?void 0:t.country)&&(null==t?void 0:t.line_1)&&(!hasPostal(t.country)||(null==t?void 0:t.postal_code))&&(!hasCity(t.country)||(null==t?void 0:t.city))&&(!hasState(t.country)||(null==t?void 0:t.state));export const isAddressCompleteEnough=t=>(null==t?void 0:t.country)&&(!hasPostal(t.country)||(null==t?void 0:t.postal_code))&&(!hasCity(t.country)||(null==t?void 0:t.city))&&(!hasState(t.country)||(null==t?void 0:t.state));