import{da as r,_ as d}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,t){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,t),t)}};const u="https://www.googleapis.com/calendar/v3",m=e=>r({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:e}]},method:"GET",url:`${u}/users/me/calendarList`}),h=(e,t)=>r({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:e}]},method:"GET",url:`${u}/calendars/${encodeURIComponent(t)}/events`}),C=(e,t)=>r({headers:{Authorization:["Bearer ",{encryption:"hmac_decrypt",value:e}]},method:"GET",url:`${u}/calendars/${encodeURIComponent(t)}/acl`});globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,t){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,t),t)}};const p=async e=>{e.setComponent("calendar-id",t=>{e.util.isSelectComponent(t)&&(t.loading=!0)});try{const t=await e.getConnection();if(!t)return;const{data:n,status:c}=await m(t.auth_details.access_token);if(c!=="success"){e.setComponent("calendar-id",o=>{e.util.isSelectComponent(o)&&(o.status=c,o.invalidMessage=n)}),console.error("Failed to fetch calendar list");return}e.setComponent("calendar-id",o=>{var i;e.util.isSelectComponent(o)&&(o.options=((i=n==null?void 0:n.items)==null?void 0:i.map(s=>({label:s.summary,value:s.id})))||[])})}finally{e.setComponent("calendar-id",t=>{e.util.isSelectComponent(t)&&(t.loading=!1)})}},g=async e=>{var t;e.setComponent("event-select",n=>{e.util.isSelectComponent(n)&&(n.loading=!0)});try{const n=await e.getConnection();if(!n)return;const c=(t=e.getComponent("calendar-id"))==null?void 0:t.value;if(!c)return;const{data:o,status:i}=await h(n.auth_details.access_token,c);if(i!=="success"){e.setComponent("event-select",s=>{e.util.isSelectComponent(s)&&(s.status=i,s.invalidMessage=o)}),console.error("Failed to fetch events list");return}e.setComponent("event-select",s=>{var l;e.util.isSelectComponent(s)&&(s.options=((l=o==null?void 0:o.items)==null?void 0:l.map(a=>({label:a.summary||a.id||d("Untitled Event"),value:a.id})))||[])})}finally{e.setComponent("event-select",n=>{e.util.isSelectComponent(n)&&(n.loading=!1)})}},y=async e=>{var t;e.setComponent("acl-rule-select",n=>{e.util.isSelectComponent(n)&&(n.loading=!0)});try{const n=await e.getConnection();if(!n)return;const c=(t=e.getComponent("calendar-id"))==null?void 0:t.value;if(!c)return;const{data:o,status:i}=await C(n.auth_details.access_token,c);if(i!=="success"){e.setComponent("acl-rule-select",s=>{e.util.isSelectComponent(s)&&(s.status=i,s.invalidMessage=o)}),console.error("Failed to fetch access control rules list");return}e.setComponent("acl-rule-select",s=>{var l;e.util.isSelectComponent(s)&&(s.options=((l=o==null?void 0:o.items)==null?void 0:l.map(a=>({label:`${a.role} - ${a.scope.type}${a.scope.value?` (${a.scope.value})`:""}`,value:a.id})))||[])})}finally{e.setComponent("acl-rule-select",n=>{e.util.isSelectComponent(n)&&(n.loading=!1)})}};export{p as a,y as b,g as f};
