import{_ as R}from"./AbstraButton.vue_vue_type_script_setup_true_lang.bef4d8ba.js";import{a as F}from"./asyncComputed.d7c4e941.js";import{F as S}from"./PhKey.vue.f616de22.js";import{G as V}from"./PhPencil.vue.6d6dc1ad.js";import{_ as j,a as A}from"./vue-flow-minimap.ecf273de.js";import{u as B,f as G,j as v,c as w,d as h}from"./index.03907aa7.js";import{d as H,e4 as M,g as $,f as P,r as Q,K as k,b as s,u as a,c as f,w as r,ec as U,aL as x,o as d,br as q,d5 as m,az as _,eb as g,ea as J,da as C,F as O,Q as W}from"./index.b7bd503f.js";import"./gateway.6db311e2.js";import{T as I}from"./columns.c99cb402.js";import{_ as X}from"./TablesTabs.vue_vue_type_script_setup_true_lang.8a3243e9.js";import{A as Y}from"./index.173038d0.js";import{C as Z}from"./Card.611b7fe6.js";import"./popupNotifcation.bbf38424.js";import"./record.c86f39d9.js";import"./string.9a3a939b.js";import"./TabPane.3b3150c6.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},p=new Error().stack;p&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[p]="54bf7f81-6003-43e6-9a74-de8cd9560eba",l._sentryDebugIdIdentifier="sentry-dbid-54bf7f81-6003-43e6-9a74-de8cd9560eba")}catch{}})();const ee=H({__name:"TablesDiagram",setup(l){const p=(t,n)=>{const o=new h.graphlib.Graph;return o.setGraph({rankdir:"LR",align:"UL",ranker:"longest-path"}),o.setDefaultEdgeLabel(()=>({})),t.forEach(e=>{o.setNode(e.id,{width:500,height:200+e.data.getColumns().length*20})}),n.forEach(e=>{o.setEdge(e.source,e.target)}),h.layout(o),t.map(e=>({...e,position:{x:o.node(e.id).x,y:o.node(e.id).y}}))},u=M().params.projectId,{result:c,loading:y}=F(async()=>{const t=await I.list(u);return Promise.all(t.map(n=>I.get(u,n.id)))}),b=$(()=>{var t,n;return(n=(t=c.value)==null?void 0:t.flatMap(o=>o.getColumns().filter(e=>e.foreignKey).map(e=>({id:`${o.id}:${e.id}:${e.foreignKey.columnId}`,source:o.id,target:c.value.find(i=>i.getColumn(e.foreignKey.columnId)).id,targetHandle:`target-${e.foreignKey.columnId}`,sourceHandle:`source-${e.id}`}))))!=null?n:[]}),L=$(()=>y.value?[]:p(c.value.map(t=>({id:t.id,type:"table",data:t,position:{x:0,y:0}})),b.value)),{onInit:T,onNodeDragStop:E,onConnect:z,addEdges:K}=B(),N=P(!1);return T(t=>{t.fitView()}),E(({event:t,nodes:n,node:o})=>{console.log("Node Drag Stop",{event:t,nodes:n,node:o})}),z(t=>{K(t)}),(t,n)=>{const o=Q("RouterLink");return d(),k(x,null,[s(X),a(y)?(d(),f(a(q),{key:0,style:{width:"100%"}})):(d(),f(a(G),{key:1,nodes:L.value,edges:b.value,class:U([{dark:N.value},"basic-flow"]),"default-viewport":{zoom:1.5},"fit-view-on-init":"","min-zoom":.2,"max-zoom":4,"pan-on-scroll":""},{"node-table":r(e=>[s(a(Z),{style:{padding:"0"}},{title:r(()=>[s(a(m),{level:5},{default:r(()=>[_(g(e.data.name),1)]),_:2},1024)]),extra:r(()=>[s(o,{to:`/projects/${a(u)}/tables/${e.data.id}`},{default:r(()=>[s(a(Y),{size:"large"}),s(R,null,{default:r(()=>[s(a(V))]),_:1})]),_:2},1032,["to"])]),default:r(()=>[(d(!0),k(x,null,J(e.data.getColumns(),i=>(d(),f(a(C),{key:i.id,vertical:""},{default:r(()=>[s(a(C),{align:"center",gap:"small",style:{position:"relative"}},{default:r(()=>[s(a(v),{id:`target-${i.id}`,type:"target",position:a(w).Left,connectable:!1},null,8,["id","position"]),s(a(m),null,{default:r(()=>[_(g(i.name),1)]),_:2},1024),s(a(m),{type:"secondary"},{default:r(()=>[_(g(i.type),1)]),_:2},1024),i.primaryKey?(d(),f(a(S),{key:0})):O("",!0),s(a(v),{id:`source-${i.id}`,type:"source",position:a(w).Right,connectable:!1},null,8,["id","position"])]),_:2},1024)]),_:2},1024))),128))]),_:2},1024)]),default:r(()=>[s(a(j),{"pattern-color":"#aaa",gap:16}),s(a(A),{pannable:""})]),_:1},8,["nodes","edges","class"]))],64)}}});const ye=W(ee,[["__scopeId","data-v-f0dbbd69"]]);export{ye as default};
//# sourceMappingURL=TablesDiagram.8a554eb4.js.map
