import{REDOCLY_TEAMS_RBAC as $}from"@redocly/config";import{SEARCH_DOCUMENT_METADATA_KEY as g}from"../../../constants/plugins/search.js";import{slugger as x}from"../../../../utils/slugger.js";import{TagNode as M}from"./nodes/tag-node.js";import{TextNode as U}from"./nodes/text-node.js";import{MdSearchDocument as D}from"./md-search-document.js";import{HeadingNode as N}from"./nodes/heading-node.js";const C=Symbol();function H(r,e){if(!r)return e;if(!e)return r;const d=[" ",`
`,"	"],u=d.some(o=>r.endsWith(o)),s=d.some(o=>e.startsWith(o));return r+(!u&&!s?" ":"")+e}function Y(r,e,d,u,s,a={},o){const h=new Map(Array.from({length:6},(t,c)=>[c,""])),i=new Map;let S=null,_=0;u=u??{},x.reset();for(const t of r.transform()){const c=t.getUrl(e),f={...u};for(const n of t.rbacTeams??[])f[n.toLowerCase()]="read";if(t instanceof U){const n=t.parentNode?.id,m=n?`${c}#${n}`:C,A=i.get(m),l=A??new D(d,e,[],a,f,s),E=Object.keys(l[$]??{});if(A&&t.rbacTeams&&t.rbacTeams.length>0&&(E.length===0||!E.every(p=>(t.rbacTeams||[]).includes(p)))){const p=new D(A?.title??d,c,t.getPath(h),a,f,s);p.text=t.content,i.set(`${c}#rbac-text-${_++}`,p)}else l.text=H(l.text,t.content),l.facets=a,i.set(m,l);continue}if(t instanceof M){const n=`${c}#${t.id}`,m=new D(t.content,t.getUrl(e),t.getPath(h),a,f,s);i.set(n,m);continue}if(t instanceof N){h.set(t.attributes.level,t.content);const n=new D(t.content,t.getUrl(e),t.getPath(h),a,f,s),m=`${c}#${t.id}`;i.set(m,n),S===null&&(S=n)}}const T=Array.from(i.values()),b=S??T[0];if(b&&o?.includes&&(b[g].curated=!0,b[g].includes=o.includes),o?.excludes)for(const t of T)t[g].curated=!0,t[g].excludes=o.excludes;return T}export{Y as getSearchDocuments};
