import*as l from"path";import{MARKDOC_PARTIALS_DATA_KEY as f,MARKDOC_PARTIALS_DEPS_KEY as D}from"../../../store.js";import{isPartial as h}from"../is-partial.js";function A(e,t){return Promise.all(e.map(t)).then(o=>e.filter((i,n)=>o[n]))}async function C(e,t){const{markdown:o}=await e.getConfig(),i=o?.partialsFolders??[],n=await A(await e.fs.scan(/\.md$/),async a=>!(!l.posix.basename(a.relativePath).endsWith(".md")||await e.isPathIgnored(a.relativePath)||!h(a.relativePath,i)));t.setGlobalConfig({[f]:Object.fromEntries(n.map(a=>[a.relativePath,{}]))});const m={},p={};for(const a of n){const{ast:s,info:r}=await t.parseMarkdoc(a,e);m[a.relativePath]=s;const c=Array.isArray(r.dynamicMarkdocComponents)?r.dynamicMarkdocComponents:[],d=r.sharedDataDeps instanceof Set?Array.from(r.sharedDataDeps):Array.isArray(r.sharedDataDeps)?r.sharedDataDeps:[];p[a.relativePath]={dynamicComponents:new Set(c),sharedDataDeps:new Set(d)}}return t.setGlobalConfig({[D]:Object.fromEntries(Object.entries(p).map(([a,s])=>[a,{dynamicComponents:Array.from(s.dynamicComponents),sharedDataDeps:Array.from(s.sharedDataDeps)}]))}),m}export{C as prepareMarkdocPartials};
