"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),t=require("./App-57333a77.js"),x=require("./chakra-ui-skeleton.esm-c6699b28.js");require("@emotion/react");require("react-dom");require("@emotion/styled");require("@feedloop/formula-editor");require("@feedloop/expression-parser");require("crypto-js");require("react-mentions");function y(){var E,p;const m=t.useSchema(),[h,S]=f.useState("<svg></svg>"),s=f.useMemo(()=>{var c,l,d;if(!((l=(c=m.data)==null?void 0:c.data)!=null&&l.tables))return;const a=(d=m.data)==null?void 0:d.data.tables,n=new Set;let e="erDiagram";const u=a.concat().sort((o,r)=>r.name==="users"?0:1);let i="";return u.forEach(o=>{e+=`
${o.name} {
`,o.columns.forEach(r=>{if(r.references||(e+=`${r.type} ${r.name}
`),r.references){const b=r.name.split("_")[0],g=[o.name,r.references.targetTable].sort().concat(r.references.type||"ManyToMany").join("_");n.has(g)||(n.add(g),r.references.type==="OneToMany"?i+=`${o.name} }o--|| ${r.references.targetTable} : ${b}
`:i+=`${o.name} }o--o{ ${r.references.targetTable} : ${b}
`)}}),e+=`}
`}),`${e}${i}`},[(p=(E=m.data)==null?void 0:E.data)==null?void 0:p.tables]),v=f.useCallback(a=>{const n=new Blob([a]),e=document.createElement("a");e.download="ERD.svg",e.href=URL.createObjectURL(n),document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(e.href)},[]);return f.useEffect(()=>{const a=setTimeout(async()=>{if(!s)return;const{default:n}=await Promise.resolve().then(()=>require("./mermaid.esm.min-ea9c6c72.js")),e=await Promise.resolve().then(()=>require("./index-4d9c30f9.js"));n.initialize({theme:"forest",themeCSS:`
          .entityBox {
            fill: #F6F6F6;
            stroke: #E9E9E9;
          }
          .attributeBoxOdd {
            fill: #ffffff;
            stroke: #E9E9E9;
          }
          .attributeBoxEven {
            fill: #F6F6F6;
            stroke: #E9E9E9;
          }
          .relationshipLabelBox {
            fill: #E9E9E9;
            opacity: 0.7;
          }`,maxTextSize:9e4}),n.mermaidAPI.render("graph",s,u=>{const i=u.replace(/ height="[^"]*"/,"");S(i),setTimeout(()=>{const c=e.zoom().on("zoom",d),l=e.select("#erd").call(c);function d({transform:o}){l.select("#graph").attr("transform",o)}},500)})},300);return()=>clearTimeout(a)},[s]),s?t.jsx(t.MainContainer,{Header:t.jsx(t.HeaderContainer,{children:t.jsx(t.Button,{size:"sm",variant:"outline",fontSize:"sm",fontWeight:"400",onClick:()=>v(h),leftIcon:t.jsx(t.SvgImport,{fontSize:"16px"}),children:"Download"})}),MainComponent:t.jsx(t.Box,{position:"relative",width:"100%",id:"zoom-container",overflow:"hidden",children:t.jsx(t.Box,{id:"erd",dangerouslySetInnerHTML:{__html:h}})})}):t.jsx(x.SkeletonCircle,{})}exports.default=y;
