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