import{combineUrls as c}from"@redocly/theme/core/utils";import{removeTrailingSlash as p}from"../../../shared/utils.js";import{getTemplatePath as L}from"./get-template-path.js";import{searchResolver as E}from"./search/search-resolver.js";import{graphqlDocLoader as _}from"./graphql-doc-loader.js";import{getAiDocumentsStore as $}from"./search/ai/get-ai-search-document.js";import{typeGroupNeedsSearchDocument as k}from"./search/ai/utils.js";const w="graphql-docs",x="graphql-docs-";async function C(){return{id:"graphql",requiredEntitlements:["graphql"],loaders:{"graphql-doc":_},processContent:async(e,{fs:l,cache:u,isPathIgnored:q})=>{const b=e.createTemplate(w,L("./template/GraphQLDocs.js"));for(const{relativePath:s}of await l.scan(/(\.gql|\.graphql)$/)){if(await q(s))continue;const g=await u.load(s,"graphql-doc");if(!g.data)continue;const{menu:m,content:R,settings:T,metadata:y,store:d}=g.data,f=`${x}${s}`;await e.createSharedData(f,R);const A=[{key:"graphQlSettings",id:f}],r=[],h=m.getGroups(),G=m.getSidebarItems(),S={type:"graphql",title:h[0].name,...y};let D=!1;for(const o of h)for(const a of o.typeGroups)for(const n of a.items){const t=!D&&k(a.name),P=t?o.name:void 0;t&&(D=!0);const I=`${a.id}/${n}`;r.push({slugSuffix:I,fsPath:s,templateId:b,getStaticData:Q(a,T),sharedData:A,getAiDocumentsStore:$({label:n,groupName:a.name,metadata:S,actions:e,store:d,llmstxtTitle:P,includeInLLMsTxt:t})})}if(!r.length)return;const i=r[r.length-1];i.metadata=S,i.getSidebar=o=>{function a(n){return n.map(t=>({...t,slug:t.slug&&p(c(o.baseSlug,t.slug)),routeSlug:t.routeSlug&&p(c(o.baseSlug,t.routeSlug)),link:t.link&&p(c(o.baseSlug,t.link)),items:t.items&&a(t.items)}))}return a(G)},i.getSearchDocuments=E(e,d);for(const o of r)e.addRoute(o)}}}}function Q(e,l){return async function(u){return{props:{seo:{title:e?.name},settings:{...l,location:{section:e?.id},sidebar:{hide:!0},baseUrlPath:u.baseSlug},disableAutoScroll:!0}}}}export{C as graphqlDocsPlugin};
