"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),t=require("./App-47594b83.js"),v=require("./chakra-ui-skeleton.esm-bfd9872d.js");require("@emotion/react");require("react-dom");require("@emotion/styled");require("@feedloop/formula-editor");require("@feedloop/expression-parser");function y(){var E,b;const m=t.useSchema(),[h,x]=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,o=new Set;let e="erDiagram";const u=a.concat().sort((n,r)=>r.name==="users"?0:1);let i="";return u.forEach(n=>{e+=`
${n.name} {
`,n.columns.forEach(r=>{if(r.references||(e+=`${r.type} ${r.name}
`),r.references){const p=r.name.split("_")[0],g=[n.name,r.references.targetTable].sort().concat(r.references.type||"ManyToMany").join("_");o.has(g)||(o.add(g),r.references.type==="OneToMany"?i+=`${n.name} }o--|| ${r.references.targetTable} : ${p}
`:i+=`${n.name} }o--o{ ${r.references.targetTable} : ${p}
`)}}),e+=`}
`}),`${e}${i}`},[(b=(E=m.data)==null?void 0:E.data)==null?void 0:b.tables]),S=f.useCallback(a=>{const o=new Blob([a]),e=document.createElement("a");e.download="ERD.svg",e.href=URL.createObjectURL(o),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:o}=await Promise.resolve().then(()=>require("./mermaid.esm.min-ea9c6c72.js")),e=await Promise.resolve().then(()=>require("./index-4d9c30f9.js"));o.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}),o.mermaidAPI.render("graph",s,u=>{x(u),setTimeout(()=>{const i=e.zoom().on("zoom",l),c=e.select("#erd").call(i);function l({transform:d}){c.select("#graph").attr("transform",d)}},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:()=>S(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(v.SkeletonCircle,{})}exports.default=y;
