import{da as r,_ as c}from"./main-tangy-colts-beg.js";globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,i){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,i),i)}};const d="https://www.googleapis.com",u=e=>({Authorization:["Bearer ",{encryption:"hmac_decrypt",value:e}]}),f=e=>r({headers:u(e),method:"GET",url:`${d}/drive/v3/drives`}),p=(e,i,t,a,n,o)=>{const s=new URLSearchParams({corpora:"allDrives",includeItemsFromAllDrives:"true",q:i,spaces:"appDataFolder, drive",supportsAllDrives:"true"});return s.append("pageSize",t.toString()),s.append("fields","nextPageToken, files(*)"),s.set("corpora","user"),s.set("spaces","drive"),s.set("includeItemsFromAllDrives","false"),s.set("supportsAllDrives","false"),r({headers:u(e),method:"GET",url:`${d}/drive/v3/files?${s.toString()}`})};globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(e,i){return this.cache.has(e)?this.cache.get(e):(this.cache.set(e,i),i)}};const h=(e,i)=>{const t=e.getComponent("file-id"),a=e.getComponent("folder-id"),n=e.getComponent("drive-id");i.isSelectComponent(t)&&t.value&&t.options&&!t.options.some(o=>o.value===t.value)&&(e.setComponent("file-id",o=>{o.value=void 0}),e.setDb(o=>{o.fileId=void 0})),i.isSelectComponent(a)&&a.value&&a.options&&!a.options.some(o=>o.value===a.value)&&(e.setComponent("folder-id",o=>{o.value=void 0}),e.setDb(o=>{o.folderId=void 0})),i.isSelectComponent(n)&&n.value&&n.options&&!n.options.some(o=>o.value===n.value)&&(e.setComponent("drive-id",o=>{o.value=void 0}),e.setDb(o=>{o.driveId=void 0}))},g=async(e,i)=>{e.setComponent("file-id",t=>{e.util.isSelectComponent(t)&&(t.loading=!0)});try{const t=await e.getConnection("expires_in");if(!t)return;const a=i?`name contains '${i.replaceAll("'",String.raw`\'`)}' and trashed = false and mimeType != 'application/vnd.google-apps.folder'`:"trashed = false and mimeType != 'application/vnd.google-apps.folder'",{data:n,status:o}=await p(t.auth_details.access_token,a,100);if(o!=="success"){e.setComponent("file-id",s=>{e.util.isSelectComponent(s)&&(s.status=o,s.invalidMessage=n)}),console.error("Failed to fetch files");return}if(!(n!=null&&n.files))return;e.setComponent("file-id",s=>{e.util.isSelectComponent(s)&&(s.options=n.files.map(l=>({label:l.name||"",value:l.id||""})))})}finally{e.setComponent("file-id",t=>{e.util.isSelectComponent(t)&&(t.loading=!1)})}},v=async(e,i)=>{e.setComponent("folder-id",t=>{e.util.isSelectComponent(t)&&(t.loading=!0)});try{const t=await e.getConnection("expires_in");if(!t)return;const a=i?`name contains '${i.replaceAll("'",String.raw`\'`)}' and trashed = false and mimeType = 'application/vnd.google-apps.folder'`:"trashed = false and mimeType = 'application/vnd.google-apps.folder'",{data:n,status:o}=await p(t.auth_details.access_token,a,100);if(o!=="success"){e.setComponent("folder-id",s=>{e.util.isSelectComponent(s)&&(s.status=o,s.invalidMessage=n)}),console.error("Failed to fetch folders");return}if(!(n!=null&&n.files))return;e.setComponent("folder-id",s=>{e.util.isSelectComponent(s)&&(s.options=[{label:c("/ (Root folder)"),value:"root"},...n.files.map(l=>({label:l.name||"",value:l.id||""}))])})}finally{e.setComponent("folder-id",t=>{e.util.isSelectComponent(t)&&(t.loading=!1)})}},C=async e=>{e.setComponent("drive-id",i=>{e.util.isSelectComponent(i)&&(i.loading=!0)});try{const i=await e.getConnection("expires_in");if(!i)return;const{data:t,status:a}=await f(i.auth_details.access_token);if(a!=="success"){e.setComponent("drive-id",n=>{e.util.isSelectComponent(n)&&(n.status=a,n.invalidMessage=t)}),console.error("Failed to fetch drives");return}if(!(t!=null&&t.drives))return;e.setComponent("drive-id",n=>{e.util.isSelectComponent(n)&&(n.options=[{label:c("My Drive"),value:"root"},...t.drives.map(o=>({label:o.name||"",value:o.id||""}))])})}finally{e.setComponent("drive-id",i=>{e.util.isSelectComponent(i)&&(i.loading=!1)})}};export{g as a,C as b,v as f,h};
