import{on as e,ot as t}from"./src-DTHkTkyy-Ce1TZuRw.js";import{A as n}from"./connect-BSkeWkEI-BYzoVZOI.js";import{useEffect as r,useMemo as i}from"react";var a=`REGISTRY_PACKAGES:${`https://registry.dev.vetra.io`.endsWith(`/`)?`https://registry.dev.vetra.io`.slice(0,-1):`https://registry.dev.vetra.io`}`;function o(){let o=e(),u=o?.packages,[d,f]=n(a,{}),p=i(()=>Array.from(Object.values(d)).filter(e=>e!==void 0),[d]);r(()=>{async function e(){if(!o)return;let e=await t(`https://registry.dev.vetra.io`);f(t=>{let n={...t};for(let t of e){let e=n[t.name];if(e){let r=o.getPackageVersion(t.name);n[t.name]={...e,manifest:t.manifest??e.manifest,version:r??t.version??e.version,distTags:t.distTags??e.distTags,versions:t.versions??e.versions,documentTypes:t.documentTypes.length?t.documentTypes:e.documentTypes}}else{let e=l(o.getPackageSource(t.name));n[t.name]=c(t,e)}}return n})}e().catch(console.error)},[]),r(()=>{if(o&&u?.length)for(let e of u)f(t=>{let n=e.manifest.name,r=t[n],i={...t},a=o.getPackageVersion(n);return r?i[n]={...r,version:a??r.version}:i[n]=s(e,l(o.getPackageSource(n)),a),i})},[u]);function m(e,t){f(n=>{let r={...n},i=r[e];return i?(r[e]={...i,status:t},r):(console.error(`Attempting to update status for package that does not exist.`),r)})}function h(e,t,n,r){f(i=>{let a={...i};return a[e]={...s(t,r,n),name:e},a})}return{registryPackagesMap:d,registryPackageList:p,updateRegistryPackageStatus:m,registerFallbackRegistryPackage:h}}function s(e,t,n){return{name:e.manifest.name,path:`stub-path`,documentTypes:e.documentModels.map(e=>e.documentModel.global.id),status:t,manifest:e.manifest,version:n}}function c(e,t){return{...e,documentTypes:e.manifest?.documentModels?.map(e=>e.id)??[],status:t}}function l(e){return e===null?`available`:e===`local-install`||e===`common`||e===`project`?`local-install`:e===`registry-install`?`registry-install`:`available`}export{o as t};
//# sourceMappingURL=useRegistryPackages-BOX4NMAb-DVr04Tdy.js.map