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