import{r as l,f as S,j as v}from"./vendor-ClLR6ncd.js";import{E as x}from"./lodash-ZyeDnt0e.js";import{b as f,f as p,E as d,ar as Q,i as u}from"./index-OtVJl4GC.js";const y=l.createContext();function F(){return l.useContext(y)}function U(e){return e==="/"?"root":e}function q(e){return e==="root"?"/":e}function k(){return d(["catalogs"],async()=>(await u({url:"/catalogs"})).map(({id:e,relativeUri:r,...t})=>({...t,name:U(e),id:r})))}const g=e=>[e,"repositories"];function w(e,r){return d(g(e),async()=>await u({url:p(r,"/repositories"),params:{checkMmrStatus:!1}}))}function D(e,r){return!Array.isArray(e)||!Array.isArray(r)?e:e.map(t=>{var o;const a=(o=r.find(({id:s})=>s===t["location-id"]))==null?void 0:o.catalog;return{...t,repo:[a,t.repo].filter(Boolean).join(":")}})}function E(e){return d(["fedshard-definitions"],async()=>(await u({url:"/fedshard/define"})).map(({key:r,...t})=>({...t,fedshardKey:r,isDefinition:!0,id:t.repo,kbs:D(t.kbs,t.locations)})),{enabled:e})}function B(e){return e==="/"||e==="root"?".":p("/catalogs",e).slice(1)}function I(e,r){if(!Array.isArray(e))return e;const t=Array.isArray(r)?r:[],a=Object.assign({},...t.map(s=>({[s.repo]:s}))),o=new Set(e.map(({id:s})=>s));return e.map(s=>({...s,definition:a[s.id]})).concat(t.filter(({repo:s})=>!o.has(s)))}const m=e=>!!(e!=null&&e.vector),P=e=>!m(e);function J(){const{repositoryId:e}=f(),{vectorRepositories:r}=F();return!r.find(({id:t})=>t===e)}function L({children:e}){const r=S(),{catalogId:t}=f(),a=B(t),{data:o}=k(),{data:s,isFetching:C}=w(t,a),n=a==="catalogs/fedshard",{data:h,isFetching:A}=E(n),i=n?I(s,h):s,R={catalogs:o,areRepositoriesUpdated:C||n?!1:A,allRepositories:i,repositories:Array.isArray(i)?i.filter(P):i,vectorRepositories:Array.isArray(i)?i.filter(m):i,selectedCatalog:{isFedshard:n,id:a,catalogId:x(a.split("/")),...(o||[]).find(({id:c})=>a===c)},setSelectedCatalog:({id:c})=>{r(`./${c}`)},invalidateRepositories:()=>{Q.invalidateQueries(g(t))}};return v.jsx(y.Provider,{value:R,children:e})}export{L as S,P as a,U as b,B as c,k as d,J as e,m as i,g as r,q as t,F as u};
