import{da as l,_ as c}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,e){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,e),e)}};const r="https://clientapi.benchmarkemail.com",m=async t=>l({headers:{AuthToken:{encryption:"hmac_decrypt",value:t}},method:"GET",url:`${r}/Contact/`}),u=async(t,e)=>l({headers:{AuthToken:{encryption:"hmac_decrypt",value:t}},method:"GET",url:`${r}/Contact/${e}`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,e){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,e),e)}};const p=t=>Object.keys(t).filter(e=>e.startsWith("Field")&&e.endsWith("Name")).map(e=>({label:e.replace("Name",""),value:t[e]})),C=async t=>{t.setComponent("list-id",a=>{a.loading=!0});const e=await t.getConnection();if(!e)return;const{data:n}=await m(e.auth_details.value);if(!n){t.setComponent("list-id",a=>{t.util.isSelectComponent(a)&&(a.loading=!1,a.invalidMessage=n)}),console.error("Failed to fetch list");return}t.setComponent("list-id",a=>{var i,o;t.util.isSelectComponent(a)&&(a.options=(o=(i=n==null?void 0:n.Response)==null?void 0:i.Data)==null?void 0:o.map(s=>({label:s.Name,value:s.ID})),a.loading=!1)})},f=async t=>{var i;t.setComponent("contact-row",o=>{o.loading=!0});const e=await t.getConnection();if(!e){t.setComponent("contact-row",o=>{o.loading=!1});return}const n=(i=t.getComponent("list-id"))==null?void 0:i.value,{data:a}=await u(e.auth_details.value,n);t.setComponent("contact-row",o=>{if(!t.util.isRepeaterFieldComponent(o))return;const s=o.fieldsMetaData[0],h=p(a.Response.Data),d=[{label:c("Email"),value:"Email"},{label:c("First Name"),value:"FirstName"},{label:c("Last Name"),value:"LastName"},{label:c("Middle Name"),value:"MiddleName"},...h];s.options=d,o.loading=!1})};export{f as a,C as f};
