import{nanoid as p}from"nanoid";import{sha as h}from"../../../../utils/crypto.js";import{logger as m}from"../../../../utils/index.js";const a={};function i(e){if(e.toLowerCase().includes("gantt")&&!e.toLowerCase().includes("todaymarker off")){const o=new Date().toISOString().split("T")[0];return h(e+o)}return h(e)}async function y(e,c="default"){if(e.length===0)return[];const r=[];for(let t=0;t<e.length;t++){const n=i(e[t]);a[n]||r.push(e[t])}if(r.length){const t=process.env.REDOCLY_MERMAID_MICROSERVICE_URL||"https://api.redocly.com/mermaid",n=m.startTiming(),d=p(),f=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json","x-request-id":process.env.REQUEST_ID||""},body:JSON.stringify({definitions:r,rayId:d,theme:c,organizationId:process.env.ORGANIZATION_ID})});if(f.status!==200)throw new Error(`Something went wrong during remote rendering. Please, save this Ray ID: ${d} and contact Redocly team.`);m.verboseTime(n,"Rendered mermaid diagrams (%s)",r.length);const g=await f.json();for(let s=0;s<r.length;s++){const l=i(r[s]);a[l]=g[s]}}const o=[];for(let t=0;t<e.length;t++){const n=i(e[t]);o.push(a[n])}return o}export{a as cache,i as generateDiagramHash,y as renderMermaid};
