import c from"node:path";import v from"is-glob";import m from"picomatch";import{parseFileChunks as h}from"./file-chunk-parser.js";import{getNodeAttribute as b,setNodeAttributeValue as d}from"../../../../../shared/markdoc.js";import{readFileContent as g}from"../../read-file-content.js";import{resolvePathInMarkdown as x}from"../../resolve-path-in-markdown.js";import{removeL10nPrefix as P}from"../../../../fs/utils/remove-l10n-prefix.js";import{mapFileExtensionToLanguage as k}from"./map-file-extension-to-language.js";async function T(a,f,p,u){const{actions:{contentDir:F},context:{fs:n}}=u,i=b(a,f);if(!Array.isArray(i))d(a,"resolvedFilesets",[]);else{const w=await Promise.all(i.map(async e=>{const s=Array.isArray(e.files)?e.files:[],o=Array.isArray(e.downloadAssociatedFiles)?e.downloadAssociatedFiles:[],r=await Promise.all(s.map(l)),t=await Promise.all(o.map(l));return{...e,files:r.flat(),downloadAssociatedFiles:t.flat()}}));d(a,"resolvedFilesets",w.filter(e=>!!e));async function l(e){const s=x(e,P(p),F),o=await A(s);return(await Promise.all(o.map(y))).filter(t=>t!==null)}async function A(e){if(!v(e))return[e];const{base:s}=m.scan(e);return(await n.scan(new RegExp(s))).filter(({isVirtual:t})=>!t).map(({realRelativePath:t})=>t).filter(t=>m(e)(t))}async function y(e){const s=await g(e,n);if(s==null)return null;const{root:o,metadata:r}=h(s,e);return{path:e,content:o,metadata:r,basename:c.basename(e),language:k(c.extname(e))}}}}export{T as resolveCodeWalkthroughFilesets};
