import{r as u,u as S,V as s,G as p,a as G,L as v,j as T}from"./index-C0htHi5J.js";import{G as b,N as m,E as y,C as x}from"./preset-BK3rOLto.js";const k=u.memo(function({data:i}){const o=u.useRef(null),l=u.useRef(null),f=u.useRef(!1),{selectedItems:h,selectItem:H,clearSelection:C,resetTrigger:D}=S(),g=u.useCallback((d,E)=>{var c,r;const e=l.current;if(!(!e||e.destroyed||!d||!f.current))try{const t={};if((c=d.nodes)==null||c.forEach(n=>{if(!n.id||!e.getNodeData(n.id))return;const a=[];E.has(n.id)&&a.push(s.SELECTED),n.highlighted&&a.push(s.HIGHLIGHTED),t[n.id]=a}),(r=d.edges)==null||r.forEach(n=>{if(!n.id||!e.getEdgeData(n.id))return;const a=[];E.has(n.id)&&a.push(s.SELECTED),n.highlighted&&a.push(s.HIGHLIGHTED),t[n.id]=a}),Object.keys(t).length===0)return;e.setElementState(t)}catch{}},[]);return u.useEffect(()=>{if(!o.current||!(i!=null&&i.nodes))return;l.current&&l.current.destroy();const d=i.nodes.map(({x:e,y:c,...r})=>r),E=(i.edges||[]).map(({x:e,y:c,...r})=>r);try{const e=new b({container:o.current,width:o.current.clientWidth,height:o.current.clientHeight,layout:{type:"force",collide:{radius:v.nodeCollideRadius},preventOverlap:!0,animated:!0},behaviors:["drag-canvas","zoom-canvas","drag-element"],transforms:[{type:"process-parallel-edges",distance:30}],node:{style:{labelText:r=>{var t;return((t=r.data)==null?void 0:t.label)||r.id},labelBackground:!0,...G[s.DEFAULT]},state:{[s.SELECTED]:{labelBackground:!0,...G[s.SELECTED]},[s.HIGHLIGHTED]:{labelBackground:!0,...G[s.HIGHLIGHTED]}}},edge:{style:{labelText:r=>{var t;return((t=r.data)==null?void 0:t.label)||""},labelBackground:!0,...p[s.DEFAULT]},state:{[s.SELECTED]:{labelBackground:!0,...p[s.SELECTED]},[s.HIGHLIGHTED]:{labelBackground:!0,...p[s.HIGHLIGHTED]}}},data:{nodes:d,edges:E}});e.on(m.CLICK,r=>{const t=r.target.id;t&&H(t,"node")}),e.on(y.CLICK,r=>{const t=r.target.id;t&&H(t,"edge")}),e.on(x.CLICK,()=>{C()}),e.on(m.DBLCLICK,r=>{const t=r.target.id;if(!t)return;const n=e.getNeighborNodesData(t)||[],a={};n.forEach(L=>{const I=e.getElementState(L.id)||[];I.includes(s.HIGHLIGHTED)||(a[L.id]=[...I,s.HIGHLIGHTED])}),e.setElementState(a)}),l.current=e,e.render().then(()=>{e.destroyed||(f.current=!0,g(i,h))});const c=()=>{o.current&&l.current&&l.current.resize(o.current.clientWidth,o.current.clientHeight)};return window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c),e.destroy(),l.current=null,f.current=!1}}catch(e){console.error("[GraphView] Error initializing graph:",e)}},[D,i]),u.useEffect(()=>{g(i,h)},[h,g]),T.jsx("div",{className:"w-full h-full flex flex-col overflow-hidden",children:T.jsx("div",{ref:o,className:"graph-view flex-1"})})});export{k as default};
//# sourceMappingURL=GraphView-DUPXmSV_.js.map
