import{TYPE_GROUPS as S}from"../../constants.js";import{getLocaleFromRelativePath as D}from"../../../../fs/utils/get-locale-from-relative-path.js";import{convertDocumentToMarkdown as y,getSearchDocument as P}from"./utils.js";import{extractDocumentSearchFacets as L}from"../search-facets.js";const F=({label:o,groupName:r,metadata:a,actions:i,store:m,includeInLLMsTxt:e,llmstxtTitle:c,isTypeGroup:f,items:u})=>async t=>{const s=D(t.fsPath),n=L(i,a),h=t.slug===t.baseSlug,g=e!==void 0?e:h,l=A(o,r,t,m,s,n,f,u,h);if(l)return{async getLLMsTxts(){return[{slug:l.url,fsPath:t.fsPath,title:c||l.title,content:l.content,includeInLLMsTxt:g}]},async getSearchDocuments(){return[l]}}};function d(o,r,a,i,m){const e=[];for(const c of S){const f=c.charAt(0).toUpperCase()+c.slice(1),u=P({label:f,groupName:c,store:a,isTypeGroup:!0}),t=(Array.isArray(u)?u:[u]).filter(n=>!!(n&&n.name));if(t.length===0)continue;e.push(`## ${f}`);const s=t.map(n=>`- ${n.name}: ${n.description}`);e.push(...s)}return{url:r.slug,fsPath:r.fsPath,content:e.join(`
`),title:o,locale:i,facets:m}}function A(o,r,a,i,m,e,c,f,u){if(u)return d(o,a,i,m,e);const t=c?P({label:o,groupName:r,store:i,isTypeGroup:c,items:f??new Set}):P({label:o,groupName:r,store:i}),s=(Array.isArray(t)?t:[t]).filter(p=>!!p);if(s.length===0)return;const n=s.length===1,h=n?1:2,g=s.map(p=>y(p,h)).join(`---

`),l=n?s[0].name:o;return{url:a.slug,fsPath:a.fsPath,content:g,title:l??"",locale:m,facets:e}}export{F as getAiDocumentsStore};
