import{a as d}from"./machine.-tangy-colts-beg-869.js";import{da as r,y as c}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,a){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,a),a)}};const l=e=>({Authorization:["Basic ",{encryption:"base64_encode",value:[{encryption:"hmac_decrypt",value:e.username},":",{encryption:"hmac_decrypt",value:e.password}]}]}),h=e=>r({headers:l(e),method:"GET",url:`${c.WP_API_URL.base}newsletter/v2/lists`}),m=e=>r({headers:l(e),method:"GET",url:`${c.WP_API_URL.base}newsletter/v2/extrafields`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,a){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,a),a)}};const u=async e=>{const a=await e.getConnection();if(a)return a.auth_details},g=async e=>{const a=await u(e);if(!a)return;e.setComponent("lists",t=>{t.loading=!0});const{data:s,status:o}=await h(a);if(o!=="success"){e.setComponent("lists",t=>{e.util.isSelectComponent(t)&&(t.loading=!1,t.status=o,t.invalidMessage=s)});return}e.setComponent("lists",t=>{if(!e.util.isSelectComponent(t))return;const i=Array.isArray(s)?s:[];t.options=i.map(n=>({label:n.name,value:n.id})),t.loading=!1})},y=async e=>{const a=await u(e);if(!a)return;e.setComponent("custom-field-map",t=>{t.loading=!0});const{data:s}=await m(a),o=(Array.isArray(s)?s:[]).map(t=>({label:t.name,required:!!t.required,value:t.id}));e.setComponent("custom-field-map",t=>{if(!e.util.isRepeaterFieldComponent(t))return;const i=t.fieldsMetaData[0];i.options=o,t.loading=!1}),d({$:e,componentId:"custom-field-map",dbKey:"customFieldMap",fields:o,mapFieldKey:"newsletterCustomField",mapFieldValue:"value"})};export{g as a,y as f};
