import{da as m}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,i){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,i),i)}};const d=(t,i)=>m({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://${i}.flowlu.com/api/v1/module/crm/account/list`}),f=(t,i)=>m({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://${i}.flowlu.com/api/v1/module/crm/pipeline_stage/list`}),p=(t,i)=>m({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://${i}.flowlu.com/api/v1/module/task/tasks/list`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,i){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,i),i)}};const C=async t=>{var i,r;t.setComponent("account-id",n=>{t.util.isSelectComponent(n)&&(n.loading=!0)});try{const n=await t.getConnection();if(!n)return;const l=n.auth_details.access_token,c=(i=n.auth_details.extraData)==null?void 0:i.domain;if(!c){t.setComponent("account-id",e=>{t.util.isSelectComponent(e)&&(e.status="error",e.invalidMessage="Domain is required for Flowlu API")});return}const{data:s,status:a}=await d(l,c);if(a!=="success"){t.setComponent("account-id",e=>{t.util.isSelectComponent(e)&&(e.status=a,e.invalidMessage=s)}),console.error("Failed to fetch accounts");return}if(!((r=s==null?void 0:s.response)!=null&&r.items))return;t.setComponent("account-id",e=>{t.util.isSelectComponent(e)&&(e.options=s.response.items.filter(o=>o.type===1).map(o=>({label:o.name||`${o.first_name||""} ${o.last_name||""}`.trim()||"Unnamed Account",value:o.id})),e.status=void 0)})}finally{t.setComponent("account-id",n=>{t.util.isSelectComponent(n)&&(n.loading=!1)})}},g=async t=>{var l,c;const i=(s,a)=>{t.setComponent(s,e=>{t.util.isSelectComponent(e)&&(e.loading=a)})},r=(s,a)=>{t.setComponent(s,e=>{t.util.isSelectComponent(e)&&(e.status="error",e.invalidMessage=a)})},n=(s,a)=>{t.setComponent(s,e=>{t.util.isSelectComponent(e)&&(e.options=a.map(o=>({label:o.name,value:o.id})),e.status=void 0)})};i("task-id",!0),i("parent-task-id",!0);try{const s=await t.getConnection();if(!s)return;const a=s.auth_details.access_token,e=(l=s.auth_details.extraData)==null?void 0:l.domain;if(!e){r("task-id","Domain is required for Flowlu API"),r("parent-task-id","Domain is required for Flowlu API");return}const{data:o,status:u}=await p(a,e);if(u!=="success"){r("task-id",o),r("parent-task-id",o),console.error("Failed to fetch tasks");return}if(!((c=o==null?void 0:o.response)!=null&&c.items))return;n("task-id",o.response.items),n("parent-task-id",o.response.items)}finally{i("task-id",!1),i("parent-task-id",!1)}},y=async t=>{var i,r;t.setComponent("contact-id",n=>{t.util.isSelectComponent(n)&&(n.loading=!0)});try{const n=await t.getConnection();if(!n)return;const l=n.auth_details.access_token,c=(i=n.auth_details.extraData)==null?void 0:i.domain;if(!c){t.setComponent("contact-id",e=>{t.util.isSelectComponent(e)&&(e.status="error",e.invalidMessage="Domain is required for Flowlu API")});return}const{data:s,status:a}=await d(l,c);if(a!=="success"){t.setComponent("contact-id",e=>{t.util.isSelectComponent(e)&&(e.status=a,e.invalidMessage=s)}),console.error("Failed to fetch contacts");return}if(!((r=s==null?void 0:s.response)!=null&&r.items))return;t.setComponent("contact-id",e=>{t.util.isSelectComponent(e)&&(e.options=s.response.items.filter(o=>o.type===2).map(o=>({label:`${o.first_name||""} ${o.last_name||""}`.trim()||o.name||"Unnamed Contact",value:o.id})),e.status=void 0)})}finally{t.setComponent("contact-id",n=>{t.util.isSelectComponent(n)&&(n.loading=!1)})}},k=async t=>{var i,r;t.setComponent("stage-id",n=>{t.util.isSelectComponent(n)&&(n.loading=!0)});try{const n=await t.getConnection();if(!n)return;const l=n.auth_details.access_token,c=(i=n.auth_details.extraData)==null?void 0:i.domain;if(!c){t.setComponent("stage-id",e=>{t.util.isSelectComponent(e)&&(e.status="error",e.invalidMessage="Domain is required for Flowlu API")});return}const{data:s,status:a}=await f(l,c);if(a!=="success"){t.setComponent("stage-id",e=>{t.util.isSelectComponent(e)&&(e.status=a,e.invalidMessage=s)}),console.error("Failed to fetch opportunity stages");return}if(!((r=s==null?void 0:s.response)!=null&&r.items))return;t.setComponent("stage-id",e=>{t.util.isSelectComponent(e)&&(e.options=s.response.items.map(o=>({label:o.name,value:o.id})),e.status=void 0)})}finally{t.setComponent("stage-id",n=>{t.util.isSelectComponent(n)&&(n.loading=!1)})}};export{y as a,C as b,g as c,k as f};
