import{da as r,_ as u}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,a){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,a),a)}};const h="https://api.brevo.com/v3",p=async t=>r({headers:{Accept:"application/json","api-key":{encryption:"hmac_decrypt",value:t}},method:"GET",queryParams:{limit:50,offset:0,sort:"desc"},url:`${h}/contacts/lists`}),d=async t=>r({headers:{Accept:"application/json","api-key":{encryption:"hmac_decrypt",value:t}},method:"GET",url:`${h}/contacts/attributes`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,a){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,a),a)}};const f=async t=>{t.setComponent("list-id",e=>{e.loading=!0});const a=await t.getConnection();if(!a)return;const{data:i,status:s}=await p(a.auth_details.value);if(s!=="success"){t.setComponent("list-id",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status=s,e.invalidMessage=i)}),console.error("Failed to fetch list");return}t.setComponent("list-id",e=>{var o;t.util.isSelectComponent(e)&&(e.options=(o=i==null?void 0:i.lists)==null?void 0:o.map(n=>({label:n.name,value:n.id})),e.loading=!1)})},g=async t=>{t.setComponent("attributes-list",s=>{s.loading=!0});const a=await t.getConnection();if(!a){t.setComponent("attributes-list",s=>{s.loading=!1});return}const{data:i}=await d(a.auth_details.value);t.setComponent("attributes-list",s=>{var c;if(!t.util.isRepeaterFieldComponent(s))return;const e=s.fieldsMetaData[0],o=(c=i==null?void 0:i.attributes)==null?void 0:c.map(l=>({label:l.name,value:l.name})),n=[{label:u("Email"),value:"Email"},...o];e.options=n,s.loading=!1})};export{g as a,f};
