import{isObject as l}from"../../../../shared/jsUtils.js";import{isPartial as u}from"../../../../server/plugins/markdown/is-partial.js";import{parseAndResolveMarkdoc as T}from"../../../../server/plugins/markdown/compiler.js";import{importUserTags as k}from"../../../../server/plugins/markdown/markdoc/import-user-tags.js";const w=async({context:t,store:s})=>{const i=await t.fs.scan(/\.md$/),d=await h(s),n=new Set,o={markdocTags:{},htmlTags:{},customMarkdocTags:[],filesWithMarkdocTags:0,filesWithoutMarkdocTags:0};for(const e of i){if(e.isVirtual||await t.isPathIgnored(e.relativePath)||u(e.relativePath,s.getConfig().markdown?.partialsFolders??[]))continue;const{data:{info:g}}=await T({relativePath:e.relativePath},s.markdocOptions,{actions:s,context:t});if(!l(g))continue;const{tagList:r,htmlTagsList:m,tagOccurrence:f}=g;if(!(!r||!m)){for(const a in f){const c=r.includes(a)?o.markdocTags:o.htmlTags;d.includes(a)&&n.add(a),c[a]||(c[a]={count:0,files:0}),c[a].files++,c[a].count+=f[a]}r.length>0||m.length>0?o.filesWithMarkdocTags++:o.filesWithoutMarkdocTags++}}return{version:"1",name:"markdocUsage",value:JSON.stringify({...o,customMarkdocTags:Array.from(n)})}};async function h(t){const i=(await k(t.serverOutDir))?.schema?.tags;return l(i)?Object.keys(i):[]}export{w as getMarkdocUsage};
