import A from"path";import{REDOCLY_TEAMS_RBAC as m,REDOCLY_ROUTE_RBAC as y}from"@redocly/config";import{removeTrailingSlash as R}from"../../../utils/url/remove-trailing-slash.js";import{addLeadingSlash as S}from"../../../utils/url/add-leading-slash.js";import{resolveFrontmatterKeys as P}from"../resolve-frontmatter-keys.js";import{resolveItem as T}from"../nav-utils.js";const C=new WeakMap;async function _(l,i,s,e,a){const o=await s.getConfig(),{ast:d,compoundHash:n,info:c}=await a.parseMarkdoc(l,s),g={...o.markdown?.editPage,...e.markdown?.editPage},t=i.fsPath!=null?await s.fs.getFileInfo(i.fsPath):null,f=!g?.hide&&g?.baseUrl?{to:R(g.baseUrl)+S(t?.realRelativePath||i.fsPath||"")}:void 0,k={...o.feedback,...e.feedback},u=e.feedback?{type:k.type||"sentiment",settings:k.settings||{},hide:e.feedback?.hide}:void 0;let w=C.get(d),r=w?.ast;(!r||w?.compoundHash!==n)&&(r=JSON.stringify(d),C.set(d,{ast:r,compoundHash:n}));let h;e.navigation&&(h={...e.navigation,nextButton:await L(e.navigation.nextButton,i,a,s),previousButton:await L(e.navigation.previousButton,i,a,s)});const p=e?.seo?await P(e.seo,["image"],i.fsPath||"",a,s):void 0,v=c.tagList;Array.isArray(v)&&v.includes("code-walkthrough")&&(e.markdown=e.markdown||{},e.markdown.toc={hide:!0},e.footer=e.footer||{},e.footer={hide:!0});const b=e?.seo?.title||await i.getNavText?.();return{ast:r,frontmatter:await P({...e,...u!==void 0?{feedback:u}:{},...p!==void 0?{seo:p}:{},...h!==void 0?{navigation:h}:{}},o.markdown?.frontMatterKeysToResolve||["image","links"],i.fsPath||"",a,s),editPage:f,props:{metadata:{markdoc:{tagList:c.tagList}},seo:{...p,...b?{title:b}:{}}},[m]:i[m],[y]:i[y]}}async function L(l,i,s,e){if(!l||typeof l!="object")return;let a=l,o,d;if("page"in a&&typeof a.page=="string"){const{page:t,...f}=a;a=f,o=t}if("label"in a&&typeof a.label=="string"){const{label:t,...f}=a;a=f,d=t}let n;if(o){const t=await T({page:o},i.fsPath?A.dirname(i.fsPath):".",s,e,{navFile:i.fsPath||""});n=Array.isArray(t)?t[0]:t,n=n?.type!=="error"?n:void 0}const c=n?.routeSlug,g=d??n?.label;return{...a,label:g,link:c}}export{_ as markdownStaticDataLoader};
