import{da as d}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,o){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,o),o)}};const g=(t,o)=>d({headers:{Accept:"application/json",Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://api.zoom.us/v2/meetings/${o}`}),h=(t,o=10,s="")=>d({headers:{Accept:"application/json",Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://api.zoom.us/v2/users/me/meetings?page_size=${o}${s?`&next_page_token=${s}`:""}`}),p=(t,o=10,s="")=>d({headers:{Accept:"application/json",Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://api.zoom.us/v2/contacts?page_size=${o}${s?`&next_page_token=${s}`:""}`}),m=(t,o=10,s="")=>d({headers:{Accept:"application/json",Authorization:["Bearer ",{encryption:"hmac_decrypt",value:t}]},method:"GET",url:`https://api.zoom.us/v2/chat/users/me/channels?page_size=${o}${s?`&next_page_token=${s}`:""}`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(t,o){return this.cache.has(t)?this.cache.get(t):(this.cache.set(t,o),o)}};let l="",r="",u="";const C=async(t,o)=>{t.setComponent("occurrenceId",n=>{n.loading=!0});const s=await t.getConnection();if(!s){t.setComponent("occurrenceId",n=>{n.loading=!1});return}const{data:a,status:c}=await g(s.auth_details.access_token,o);if(c!=="success"){t.setComponent("occurrenceId",n=>{t.util.isSelectComponent(n)&&(n.loading=!1,n.status="error",n.invalidMessage=typeof a=="string"?a:"Failed to fetch meeting details")}),console.error("Failed to fetch meeting details");return}if(a.occurrences&&Array.isArray(a.occurrences)&&a.occurrences.length>0){const n=a.occurrences.map(e=>({label:`${e.occurrence_id} (${e.duration} min) - ${e.status}`,value:e.occurrence_id}));t.setComponent("occurrenceId",e=>{t.util.isSelectComponent(e)&&(e.options=n,e.loading=!1,e.status=void 0)})}else t.setComponent("occurrenceId",n=>{t.util.isSelectComponent(n)&&(n.options=[],n.value=void 0,n.loading=!1,n.status=void 0)})},_=async(t,o=0)=>{t.setComponent("meetingId",e=>{e.loading=!0});const s=await t.getConnection();if(!s){t.setComponent("meetingId",e=>{e.loading=!1});return}o===0&&(l="");const{data:a,status:c}=await h(s.auth_details.access_token,10,l);if(c!=="success"){t.setComponent("meetingId",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status="error",e.invalidMessage=typeof a=="string"?a:"Failed to fetch meetings")}),console.error("Failed to fetch meetings");return}l=typeof a.next_page_token=="string"?a.next_page_token:"",l||t.setComponent("meetingId",e=>{t.util.isSelectComponent(e)&&(e.isLoadable=!1)});const n=a.meetings.map(e=>({label:e.topic,value:e.id}));t.setComponent("meetingId",e=>{var i;t.util.isSelectComponent(e)&&(e.options=o>0?(i=e.options)==null?void 0:i.concat(n):n,e.loading=!1)})},y=async(t,o=0)=>{t.setComponent("contactId",e=>{e.loading=!0});const s=await t.getConnection();if(!s){t.setComponent("contactId",e=>{e.loading=!1});return}o===0&&(r="");const{data:a,status:c}=await p(s.auth_details.access_token,10,r);if(c!=="success"){t.setComponent("contactId",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status="error",e.invalidMessage=typeof a=="string"?a:"Failed to fetch contacts")});return}r=typeof a.next_page_token=="string"?a.next_page_token:"",r||t.setComponent("contactId",e=>{t.util.isSelectComponent(e)&&(e.isLoadable=!1)});const n=a.contacts.map(e=>({label:e.name||e.email,value:e.id}));t.setComponent("contactId",e=>{var i;t.util.isSelectComponent(e)&&(e.options=o>0?(i=e.options)==null?void 0:i.concat(n):n,e.loading=!1)})},I=async(t,o=0)=>{t.setComponent("channelId",e=>{e.loading=!0});const s=await t.getConnection();if(!s){t.setComponent("channelId",e=>{e.loading=!1});return}o===0&&(u="");const{data:a,status:c}=await m(s.auth_details.access_token,10,u);if(c!=="success"){t.setComponent("channelId",e=>{t.util.isSelectComponent(e)&&(e.loading=!1,e.status="error",e.invalidMessage=typeof a=="string"?a:"Failed to fetch channels")});return}u=typeof a.next_page_token=="string"?a.next_page_token:"",u||t.setComponent("channelId",e=>{t.util.isSelectComponent(e)&&(e.isLoadable=!1)});const n=a.channels.map(e=>({label:e.name,value:e.id}));t.setComponent("channelId",e=>{var i;t.util.isSelectComponent(e)&&(e.options=o>0?(i=e.options)==null?void 0:i.concat(n):n,e.loading=!1)})};export{_ as a,y as b,I as c,C as f};
