import{da as r}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,n){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,n),n)}};const u="https://slack.com/api",h=(t,n)=>r({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`${u}/conversations.list?limit=10&cursor=${n}`}),d=(t,n)=>r({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`${u}/users.list?limit=10&cursor=${n}`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,n){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,n),n)}};let s="";const f=async(t,n=0)=>{t.setComponent("channel-id",e=>{e.loading=!0});const a=await t.getConnection();if(!a){t.setComponent("channel-id",e=>{e.loading=!1});return}n===0&&(s="");const{data:o,status:i}=await h(a.auth_details.token,s);if(i!=="success"){t.setComponent("channel-id",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status=i,e.invalidMessage=o)}),console.error("Failed to fetch channel list");return}s=o.response_metadata.next_cursor,s===""&&t.setComponent("channel-id",e=>{t.util.isSelectComponent(e)&&(e.isLoadable=!1)});const c=o.channels.map(e=>({label:e.name,value:e.id}));t.setComponent("channel-id",e=>{var l;t.util.isSelectComponent(e)&&(e.options=n>0?(l=e.options)==null?void 0:l.concat(c):c,e.loading=!1)})},C=async(t,n=0)=>{t.setComponent("user-id",e=>{e.loading=!0});const a=await t.getConnection();if(!a){t.setComponent("user-id",e=>{e.loading=!1});return}n===0&&(s="");const{data:o,status:i}=await d(a.auth_details.token,s);if(i!=="success"){t.setComponent("user-id",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status=i,e.invalidMessage=o)}),console.error("Failed to fetch users");return}s=o.response_metadata.next_cursor,s===""&&t.setComponent("user-id",e=>{t.util.isSelectComponent(e)&&(e.isLoadable=!1)});const c=o.members.map(e=>({label:e.name,value:e.id}));t.setComponent("user-id",e=>{var l;t.util.isSelectComponent(e)&&(e.options=n>0?(l=e.options)==null?void 0:l.concat(c):c,e.loading=!1)})};export{C as a,f};
