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