import{logger as a}from"../../../tools/notifiers/logger.js";import{HeadingNode as h}from"./nodes/heading-node.js";import{TAG_TITLE_ATTRIBUTES as u,TagNode as n}from"./nodes/tag-node.js";import{TextNode as l}from"./nodes/text-node.js";import{isNode as p}from"../markdoc/helpers/guards/is-node.js";import{isConditionalNode as y}from"../markdoc/helpers/guards/is-conditional-node.js";import{isContentNode as N}from"../markdoc/helpers/guards/is-content-node.js";import{getNodeAttribute as f}from"../markdoc/helpers/get-node-attribute.js";import{extractRbacFromCondition as T}from"../markdoc/helpers/extract-rbac-from-condition-node.js";class E{#t;#o;#i;#r;constructor({ast:i,partials:t,skipConditionals:s=!1,getInnerContent:r}){if(this.#t=i,this.#o=t,this.#i=s,this.#r=r,!this.#t||!p(this.#t))throw new Error("ast is not a valid Markdoc Node.")}*transform(){yield*this.#c(this.#t,{parentNode:null})}*#c(i,t,s=this.#r){if(!(!i||!p(i))){if(y(i)){if(this.#i)return;const r=T(i);r!==null&&(yield*this.#s(i,{...t,rbacTeam:r},s));return}if(N(i)){yield new l({node:i,content:s([i],{skipConditionals:this.#i}),...t});return}if(i.type==="heading"){yield new h({node:i,content:s([i],{skipConditionals:this.#i}),rbacTeam:t?.rbacTeam});return}if(i.type==="tag"){yield*this.#e(i,t,s);return}yield*this.#s(i,t,s)}}*#e(i,t,s=this.#r){switch(i.tag){case"partial":{const r=i.attributes.file,o=i.attributes.variables??{};if(r&&this.#o[r]){yield*this.#c(this.#o[r],t,(c,e)=>s(c,{...e,variables:o}));return}a.warn(`Could not create search indexes for partial \u201C${r}\u201D: file not found`);return}case"cards":case"tabs":case"code-walkthrough":{yield*this.#s(i,t,s);return}case"markdoc-example":{const r=s([i],{skipConditionals:this.#i});yield new l({node:i,content:r,...t});return}case"code-snippet":{const r=f(i,"title"),o=f(i,"rawContent");if(r){const c=new n({node:i,content:r,...t});t={...t,parentNode:c},yield c}o&&(yield new l({node:i,content:o,...t}));return}default:{const r=u.find(e=>e in i.attributes),o=(r&&f(i,r))??"",c=typeof o=="string"?o:s([o]);if(c){const e=new n({node:i,content:c,...t});t={...t,parentNode:e},yield e}yield*this.#s(i,t,s);return}}}*#s(i,t,s=this.#r){for(const r of[...Object.values(i.slots),...i.children])for(const o of this.#c(r,t,s))o instanceof h&&(t={...t,parentNode:o}),yield o}}export{E as AstToSearchNodeTransformer};
