import{logger as b}from"../../../utils/index.js";import{HeadingNode as T}from"./nodes/heading-node.js";import{TAG_TITLE_ATTRIBUTES as h,TagNode as g}from"./nodes/tag-node.js";import{TextNode as N}from"./nodes/text-node.js";import{isConditionalNode as x,isContentNode as A,isNode as d}from"../../../../shared/utils.js";import{getNodeAttribute as p}from"../../../../shared/markdoc.js";import{ConditionNode as v}from"./nodes/condition-node.js";function*u({node:r,parentNode:c,partials:f,skipConditionals:t=!1,getInnerContent:i}){if(!(!r||!d(r))){if(x(r)){if(t)return;if(r.attributes.primary?.name==="includes"){const e=r.attributes.primary.parameters;if(e[0]?.path?.[0]==="rbac"&&e[0]?.path?.[1]==="teams"){const a=new v({node:r,content:i([r],{isTrim:!1,skipConditionals:t}),rbacTeam:e[1]});yield a,yield*l({getInnerContent:i,node:r,parentNode:a,partials:f,skipConditionals:t,walk:u})}}return}if(A(r)){yield new N({node:r,parentNode:c,text:i([r],{isTrim:!1,skipConditionals:t})});return}if(r.type==="heading"){yield new T({node:r,content:i([r],{isTrim:!1,skipConditionals:t})});return}if(r.type==="tag"){yield*E({node:r,parentNode:c,partials:f,skipConditionals:t,getInnerContent:i});return}yield*l({getInnerContent:i,node:r,parentNode:c,partials:f,skipConditionals:t,walk:u})}}function*E({node:r,parentNode:c,partials:f,skipConditionals:t,getInnerContent:i}){switch(r.tag){case"partial":const e=r.attributes.file,a=r.attributes.variables??{};if(e&&f[e]){yield*u({node:f[e],parentNode:c,partials:f,skipConditionals:t,getInnerContent:(m,w)=>i(m,{...w,variables:a})});return}b.warn(`Could not create search indexes for partial \u201C${e}\u201D: file not found`);return;case"cards":case"tabs":case"code-walkthrough":yield*l({node:r,parentNode:c,partials:f,skipConditionals:t,getInnerContent:i,walk:u});return;default:const s=h.find(m=>m in r.attributes),o=(s&&p(r,s))??"",y=typeof o=="string"?o:i([o]);if(y){const m=new g({node:r,parentNode:c,title:y});c=m,yield m}yield*l({node:r,parentNode:c,partials:f,skipConditionals:t,getInnerContent:i,walk:u});return}}function*l({getInnerContent:r,node:c,parentNode:f,partials:t,skipConditionals:i,walk:e}){for(const a of c.children)for(const s of e({getInnerContent:r,node:a,parentNode:f,skipConditionals:i,partials:t}))s instanceof T&&(f=s),yield s}export{u as walkSections};
