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