import{da as d}from"./main-tangy-colts-beg.js";import{a as p}from"./suitedas-tangy-colts-beg-185.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,o){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,o),o)}};const m="https://app.suitedash.com/secure-api",y=async(e,o,c)=>{try{const t=await d({headers:{"Content-Type":"application/json","X-Public-ID":{encryption:"hmac_decrypt",value:e},"X-Secret-Key":{encryption:"hmac_decrypt",value:o}},method:"GET",url:`${m}/contact?page=${c}`});if(t.data.success===!1)throw new Error(`${t.data.message}`);return t}catch(t){throw console.error("Error in Get Contacts:",t),t}},f=async(e,o,c)=>{try{const t=await d({headers:{"Content-Type":"application/json","X-Public-ID":{encryption:"hmac_decrypt",value:e},"X-Secret-Key":{encryption:"hmac_decrypt",value:o}},method:"GET",url:`${m}/company?page=${c}`});if(t.data.success===!1)throw new Error(`${t.data.message}`);return t}catch(t){throw console.error("Error in Get Companies:",t),t}};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,o){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,o),o)}};const w=async(e,o=1)=>{e.setComponent("contact-id",i=>{i.loading=!0});const c=await e.getConnection();if(!c)return;const t=c.auth_details.key,h=c.auth_details.value;try{const{data:i,status:s}=await y(t,h,o);if(s!=="success")throw new Error("Invalid response format");e.setComponent("contact-id",n=>{var u;if(!e.util.isSelectComponent(n))return;const l=i.data.map(a=>({label:a.email===null?`${a.first_name} ${a.last_name} (${a.uid})`:`${a.email} (${a.uid})`,value:a.uid})),r=p(l,n.options,a=>a.value);n.options=(r==null?void 0:r.length)===0?n.options:(u=n.options)==null?void 0:u.concat(l),n.loading=!1})}catch(i){e.setComponent("contact-id",s=>{e.util.isSelectComponent(s)&&(s.loading=!1,s.status="error",s.invalidMessage=i.message)})}},_=async(e,o=1)=>{e.setComponent("company-id",i=>{i.loading=!0});const c=await e.getConnection();if(!c)return;const t=c.auth_details.key,h=c.auth_details.value;try{const{data:i,status:s}=await f(t,h,o);if(s!=="success")throw new Error("Invalid response format");e.setComponent("company-id",n=>{var u;if(!e.util.isSelectComponent(n))return;const l=i.data.map(a=>({label:`${a.name} (${a.uid})`,value:a.uid})),r=p(l,n.options,a=>a.value);n.options=(r==null?void 0:r.length)==0?n.options:(u=n.options)==null?void 0:u.concat(l),n.loading=!1})}catch(i){e.setComponent("company-id",s=>{e.util.isSelectComponent(s)&&(s.loading=!1,s.status="error",s.invalidMessage=i.message)})}};export{w as a,_ as f};
