import{TagNode as l}from"./nodes/tag-node.js";import{TextNode as h}from"./nodes/text-node.js";import{slugger as w}from"../../../utils/slugger.js";import{MdSearchDocument as f}from"./md-search-document.js";import{HeadingNode as T}from"./nodes/heading-node.js";const U=Symbol();function b(u,m,g,p,i,d={}){const s=new Map(Array.from({length:6},(t,c)=>[c,""])),r=new Map;let e=p??{};w.reset();for(const t of u){const c=t.getUrl(m);if(e=t.rbacTeam?{...e,[t.rbacTeam.toLowerCase()]:"read"}:e,t instanceof h){const n=t.parentNode?.id,o=n?`${c}#${n}`:U,a=r.get(o)??new f(g,m,[],d,e,i);a.text+=t.content,a.facets=d,r.set(o,a);continue}if(t instanceof l){if(!t.content.length)continue;const n=`${c}#${t.id}`,o=new f(t.content,t.getUrl(m),t.getPath(s),d,e,i);r.set(n,o);continue}if(t instanceof T){s.set(t.attributes.level,t.content);const n=new f(t.content,t.getUrl(m),t.getPath(s),d,e,i),o=`${c}#${t.id}`;r.set(o,n)}}return Array.from(r.values())}export{b as getSearchDocuments};
