const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-BDjhC0aB.js","assets/index-CstErxPE.js","assets/index-CKHIyAh9.css","assets/string-Bl2zznvy.js"])))=>i.map(i=>d[i]);
import{r as t,a as w,_ as j,j as i}from"./index-CstErxPE.js";let g=null,m=null,v=null,h=0,y=Promise.resolve();async function k(){return m||(m=j(()=>import("./mermaid.core-BDjhC0aB.js").then(o=>o.b9),__vite__mapDeps([0,1,2,3])).then(o=>{g=o.default})),await m,g}function _(){const o=t.useRef(null),n=w(a=>a.theme),l=t.useCallback(async a=>{const u=y.then(async()=>{let r="";try{const s=await k(),e=n==="dark"?"dark":"default";v!==e&&(s.initialize({startOnLoad:!1,theme:e,flowchart:{useMaxWidth:!0,htmlLabels:!0},securityLevel:"strict"}),v=e),h+=1,r=`mermaid-render-${h}`,await s.parse(a);const{svg:c}=await s.render(r,a),d=document.getElementById(`d${r}`);return d&&d.remove(),{svg:c,error:null}}catch(s){if(r){const e=document.getElementById(`d${r}`);e&&e.remove()}return{svg:"",error:String(s)}}});return y=u.catch(()=>{}),u},[n]);return{renderRef:o,render:l}}const M=t.memo(function({source:n,className:l}){const{render:a}=_(),[u,r]=t.useState(null),[s,e]=t.useState(""),[c,d]=t.useState(!0),f=t.useCallback(async b=>{d(!0);const{svg:p,error:x}=await a(b);if(x){r(x),e(""),d(!1);return}r(null),e(p),d(!1)},[a]);return t.useEffect(()=>{n.trim()?f(n):(r(null),e(""),d(!1))},[n,f]),u?i.jsxs("div",{className:l,children:[i.jsx("div",{className:"mb-2 rounded bg-red-50 px-3 py-1.5 text-xs text-red-600 dark:bg-red-900/20 dark:text-red-400",children:"Mermaid render error"}),i.jsx("pre",{className:"overflow-x-auto rounded-xl border border-gray-200 bg-gray-50 p-4 text-xs text-gray-800 dark:border-gray-700 dark:bg-gray-950 dark:text-gray-100",children:i.jsx("code",{children:n})})]}):c?i.jsx("div",{className:`flex items-center justify-center py-8 ${l??""}`,children:i.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-blue-500"})}):i.jsx("div",{className:`mermaid-preview overflow-x-auto ${l??""}`,dangerouslySetInnerHTML:{__html:s}})});export{M as MermaidPreview};
