import{s as _}from"./chunk-LvLJmgfZ.js";import{p as b,u as q}from"./useEvent-D91BmmQi.js";import{t as A}from"./react-Bj1aDYRI.js";import{t as C}from"./compiler-runtime-B3qBwwSJ.js";import{t as $}from"./createReducer-3wF4dU7I.js";import{t as y}from"./requests-KshNNAOp.js";import{t as I}from"./createLucideIcon-BTp1tQDO.js";import{t as w}from"./DeferredRequestRegistry-RuL7NV1n.js";import{n as N}from"./useAsyncData-DAQcLiyE.js";var W=I("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);const M=new w("storage-list-entries",async(e,a)=>{await y().listStorageEntries({requestId:e,...a})}),z=new w("storage-download",async(e,a)=>{await y().downloadStorage({requestId:e,...a})});function m(e,a){return`${e}::${a??""}`}function D(e){return`${e}::`}var F=C(),p=_(A(),1);function H(){return{namespaces:[],entriesByPath:new Map,pageMetadataByPath:new Map}}var{reducer:ee,createActions:ae,valueAtom:P,useActions:L}=$(H,{setNamespaces:(e,a)=>{let t=new Map(e.namespaces.map(r=>[r.name,r]));for(let r of a.namespaces)t.set(r.name,r);return{...e,namespaces:[...t.values()]}},setEntries:(e,a)=>{let t=m(a.namespace,a.prefix),r=new Map(e.entriesByPath),s=a.append&&r.has(t)?[...r.get(t)??[],...a.entries]:a.entries;r.set(t,s);let n=new Map(e.pageMetadataByPath);return n.set(t,{nextPageToken:a.nextPageToken??null}),{...e,entriesByPath:r,pageMetadataByPath:n}},clearNamespaceCache:(e,a)=>{let t=new Map(e.entriesByPath),r=new Map(e.pageMetadataByPath),s=D(a);for(let n of t.keys())n.startsWith(s)&&t.delete(n);for(let n of r.keys())n.startsWith(s)&&r.delete(n);return{...e,entriesByPath:t,pageMetadataByPath:r}},filterFromVariables:(e,a)=>{let t=new Set(a),r=e.namespaces.filter(s=>t.has(s.name));return{...e,namespaces:r}}});const x=()=>q(P),R=b(e=>e(P).namespaces);function f(){return L()}async function u({namespace:e,prefix:a,pageToken:t,append:r,setEntries:s}){let n=await M.request({namespace:e,prefix:a??"",limit:150,...t==null?{}:{pageToken:t}});if(n.error)throw Error(n.error);return s({namespace:e,prefix:a,entries:n.entries,nextPageToken:n.next_page_token,append:r}),n}function V(e,a){var h;let{entriesByPath:t,pageMetadataByPath:r}=x(),{setEntries:s}=f(),n=m(e,a),o=t.get(n),i=((h=r.get(n))==null?void 0:h.nextPageToken)??null,c=(0,p.useRef)(!1),[k,d]=(0,p.useState)(!1),[E,g]=(0,p.useState)(),{isPending:B,error:v,refetch:T}=N(async()=>{o||await u({namespace:e,prefix:a,setEntries:s})},[e,a,o===void 0]),S=(0,p.useCallback)(async()=>{if(!(i==null||c.current)){c.current=!0,d(!0),g(void 0);try{await u({namespace:e,prefix:a,pageToken:i,append:!0,setEntries:s})}catch(l){g(l instanceof Error?l:Error(String(l)))}finally{c.current=!1,d(!1)}}},[e,a,i,s]);return{entries:o??[],isPending:B&&!o,error:o?void 0:v,hasMore:i!==null,loadMore:S,isLoadingMore:k,loadMoreError:E,refetch:T}}function j(){let e=(0,F.c)(2),{setEntries:a}=f(),t;return e[0]===a?t=e[1]:(t=r=>u({...r,setEntries:a}),e[0]=a,e[1]=t),t}export{j as a,M as c,V as i,W as l,x as n,m as o,f as r,z as s,R as t};
