import{At as e,C as t,Dt as n,J as r,Lt as i,S as a,U as o,Y as s,a as c,jt as l,kt as u,u as d}from"./chunk.p3hCiSrt.js";import{t as f}from"./chunk.DOwjsMaD.js";import"./chunk.TIounDiA.js";import{a as p,c as m,d as h,i as g,l as _,n as v,o as y,r as b,s as x,t as S}from"./chunk.D9MCnLj_.js";var C=i(l(),1),w=e(),T={entity:({data:e})=>{let n=e;return(0,w.jsxs)(`div`,{style:{background:d.colors.surface,border:`1px solid ${d.colors.border}`,borderRadius:8,minWidth:240,overflow:`hidden`},children:[(0,w.jsx)(g,{type:`target`,position:h.Top,style:{background:`var(--mantine-color-blue-6)`}}),(0,w.jsx)(`div`,{style:{padding:`8px 12px`,borderBottom:`1px solid ${d.colors.border}`,background:d.colors.elevated},children:(0,w.jsxs)(c,{gap:`xs`,children:[(0,w.jsx)(r,{fz:`sm`,fw:700,children:n.name}),(0,w.jsx)(o,{size:`xs`,variant:`light`,color:`gray`,children:n.provider})]})}),(0,w.jsx)(c,{direction:`column`,gap:0,p:0,children:(n.columns??[]).map(e=>(0,w.jsxs)(c,{gap:`xs`,px:`sm`,py:4,style:{borderBottom:`1px solid ${d.colors.border}20`},wrap:`nowrap`,children:[e.primaryKey&&(0,w.jsx)(t,{size:10,color:`var(--mantine-color-yellow-6)`}),e.ref&&(0,w.jsx)(a,{size:10,color:`var(--mantine-color-blue-6)`}),!e.primaryKey&&!e.ref&&(0,w.jsx)(`span`,{style:{width:10}}),(0,w.jsx)(r,{fz:11,ff:`monospace`,style:{flex:1},children:e.name}),(0,w.jsx)(r,{fz:10,c:`dimmed`,ff:`monospace`,children:e.type}),e.nullable&&(0,w.jsx)(r,{fz:9,c:`dimmed`,children:`?`})]},e.name))}),(0,w.jsx)(g,{type:`source`,position:h.Bottom,style:{background:`var(--mantine-color-blue-6)`}})]})}},E=e=>{let t=e.map((t,n)=>{let r=Math.ceil(Math.sqrt(e.length)),i=Math.floor(n/r),a=n%r;return{id:t.name,type:`entity`,position:{x:a*320,y:i*300},data:t}}),n=[];for(let t of e)for(let e of t.columns??[])e.ref&&n.push({id:`${t.name}.${e.name}->${e.ref.entity}`,source:t.name,target:e.ref.entity,label:`${e.name} → ${e.ref.column}`,style:{stroke:`var(--mantine-color-blue-6)`,strokeWidth:1.5},labelStyle:{fontSize:10,fill:`var(--mantine-color-dimmed)`},animated:!0});return{nodes:t,edges:n}},D=({entities:e})=>{let t=(0,C.useMemo)(()=>E(e),[e]),[n,r,i]=_(t.nodes),[a,o,s]=m(t.edges);return(0,C.useEffect)(()=>{r(t.nodes),o(t.edges)},[t,r,o]),(0,w.jsxs)(x,{nodes:n,edges:a,onNodesChange:i,onEdgesChange:s,nodeTypes:T,fitView:!0,fitViewOptions:{padding:.2},minZoom:.1,maxZoom:2,proOptions:{hideAttribution:!0},style:{background:d.colors.background},children:[(0,w.jsx)(S,{variant:v.Dots,gap:20,size:1}),(0,w.jsx)(b,{}),(0,w.jsx)(p,{nodeColor:`var(--mantine-color-dark-4)`,maskColor:`rgba(0,0,0,0.6)`,style:{backgroundColor:d.colors.surface}})]})},O=({entities:e})=>(0,w.jsx)(s,{flex:1,h:`100%`,style:{position:`absolute`,top:0,left:0,right:0,bottom:0},children:(0,w.jsx)(y,{children:(0,w.jsx)(D,{entities:e})})}),k=()=>{let e=u(n),[t,r]=(0,C.useState)([]);return(0,C.useEffect)(()=>{e.fetch(`/__devtools/api/metadata`,{schema:{response:f}}).then(e=>r(e.data.entities??[])).catch(()=>{})},[e]),(0,w.jsx)(s,{flex:1,style:{position:`relative`},children:(0,w.jsx)(O,{entities:t})})};export{k as default};