import{r as D}from"./vendor-ClLR6ncd.js";import{u as b,b as R}from"./model-C9Idzwgo.js";import{e as p}from"./model-DAvH-x8m.js";import{E as h,ar as w,i as g,f as F}from"./index-OtVJl4GC.js";import"./lodash-ZyeDnt0e.js";const u=a=>!Array.isArray(a)||a.length===0,f=()=>{};function m(a,t,s=f){const{[a]:e,areRepositoriesUpdated:i,invalidateRepositories:o,selectedCatalog:{catalogId:r}}=b();return D.useEffect(()=>{!t&&!u(e)&&s(e[0].id)},[t,e,s]),{isLoading:i,disabled:u(e),stores:(e||[]).map(({id:l})=>({label:p(r,l),value:p(r,l)})),invalidate:o}}function x(a,t){return m("allRepositories",a,t)}function z(a,t=f){const{stores:s,...e}=m("vectorRepositories",a,t);return{...e,vectorDatabases:s}}function y(a){if(!a||a===".")return"root";const t=String(a).split("/");return R(t[t.length-1]||"root")}function A(a){return y(a)}async function S(){return(await g({url:"/catalogs"})||[]).map(t=>({...t,relativeUri:t.relativeUri??(t.id==="/"?".":t.id)}))}async function E(a){const t=F(a,"/repositories");return await g({url:t,params:{checkMmrStatus:!1}})}const d=["all-vector-repositories"];function B(){const a=h(d,async()=>{const t=await S(),e=(await Promise.all(t.map(async i=>{const o=i.relativeUri||".",r=await E(o),l=y(o),v=A(o);return(r||[]).filter(n=>!!(n!=null&&n.vector)).map(n=>{const c=n.id,I=`${l}:${c}`,C=p(v,c);return{catalogRelativeUri:o,catalogDisplayId:l,repoId:c,label:I,value:C,raw:n}})}))).flat();return e.sort((i,o)=>{const r=i.catalogDisplayId.localeCompare(o.catalogDisplayId);return r!==0?r:i.repoId.localeCompare(o.repoId)}),e},{staleTime:0});return{isLoading:a.isLoading,isFetching:a.isFetching,error:a.error,vectorDatabases:(a.data||[]).map(({label:t,value:s})=>({label:t,value:s})),vectorDatabaseItems:a.data||[],invalidate:()=>w.invalidateQueries(d)}}export{x as a,B as b,z as u};
