import{r as c,u as v,h as Y,V as s,H as m,i as k,k as N,j as w,l as P,m as S,n as F,o as C,L as U}from"./index-C0htHi5J.js";const B=c.memo(function({data:i,meta:j}){const f=c.useRef(null),E=c.useRef(null),R=c.useRef(new Map),h=c.useRef(new Map),{selectedItems:T,selectItem:y,clearSelection:A,resetTrigger:_}=v();Y(),c.useEffect(()=>{h.current=T},[T]);const g=c.useCallback((t,d,r)=>{if(!t||t.destroyed)return;const b={};[...d.nodes||[],...d.edges||[]].forEach(o=>{const e=[];r.has(o.id)&&e.push(s.SELECTED),o.highlighted&&e.push(s.HIGHLIGHTED),b[o.id]=e}),t.setElementState(b),(d.hyperedges||[]).forEach((o,e)=>{const n=r.has(o.id),u=o.highlighted?s.HIGHLIGHTED:n?s.SELECTED:s.DEFAULT,p=P(u,e),I=`bubble-sets-${o.id}`;try{t.updatePlugin({key:I,fill:p.fill,fillOpacity:k[u],stroke:p.stroke,strokeOpacity:m[u]})}catch{}}),t.draw()},[]),x=c.useCallback(t=>{var r;const d=(r=t.target)==null?void 0:r.id;d&&y(d,"node")},[y]),O=c.useCallback(t=>{y(t,"hyperedge")},[y]),G=c.useCallback((t,d)=>t.map((r,b)=>{R.current.set(r.id,r);const D=d.has(r.id),o=r.highlighted===!0?s.HIGHLIGHTED:D?s.SELECTED:s.DEFAULT,e=P(o,b);return{key:`bubble-sets-${r.id}`,type:"bubble-sets",members:r.linked_nodes,fill:e.fill,fillOpacity:k[o],stroke:e.stroke,strokeOpacity:m[o],label:!0,labelText:r.label,...N,hyperedge:r}}),[]),H=c.useRef(null);return c.useEffect(()=>{g(E.current,i,T)},[T,g]),c.useEffect(()=>{const t=E.current;t&&!t.destroyed&&i&&(t.setData({nodes:i.nodes,edges:i.edges||[]}),t.setPlugins(G(i.hyperedges||[],h.current)),t.render().then(()=>{t.destroyed||g(t,i,h.current)}))},[i,G,g]),c.useEffect(()=>{if(!f.current||!(i!=null&&i.nodes)||!window.G6)return;H.current&&H.current.abort();const t=new AbortController;return H.current=t,(async()=>{try{if(E.current&&E.current.destroy(),t.signal.aborted)return;R.current.clear();const r=G(i.hyperedges||[],h.current),b=i.nodes.map(({x:e,y:n,...a})=>a),D=(i.edges||[]).map(({x:e,y:n,...a})=>a),l=new window.G6.Graph({container:f.current,width:f.current.clientWidth,height:f.current.clientHeight,layout:{type:"force",collide:{radius:U.nodeCollideRadius},preventOverlap:!0},behaviors:["drag-canvas","zoom-canvas","drag-element"],node:{style:{labelText:e=>{var a;const n=((a=e.data)==null?void 0:a.label)||e.id;return n.length>10?n.substring(0,10)+"...":n},...C[s.DEFAULT]},state:{[s.SELECTED]:C[s.SELECTED],[s.HIGHLIGHTED]:C[s.HIGHLIGHTED]}},edge:{style:{labelText:e=>{var n;return((n=e.data)==null?void 0:n.label)||""},...F,...S[s.DEFAULT],labelFontSize:9},state:{[s.SELECTED]:S[s.SELECTED],[s.HIGHLIGHTED]:S[s.HIGHLIGHTED]}},data:{nodes:b,edges:D},plugins:r,autoFit:"center"}),o=e=>{var n,a;if(e.targetType==="bubble-sets"){const u=((n=e.target)==null?void 0:n.options)||e.target;if((a=u==null?void 0:u.hyperedge)!=null&&a.id)return O(u.hyperedge.id),!0}return!1};if(l.on("node:click",x),l.on("click",e=>{o(e)||e.targetType==="canvas"&&A()}),l.on("pointerdown",o),l.on("pointermove",e=>{f.current&&(f.current.style.cursor=e.targetType==="bubble-sets"?"pointer":"default")}),l.on("node:dblclick",e=>{var p;const n=(p=e.target)==null?void 0:p.id;if(!n)return;const a=l.getNeighborNodesData(n)||[],u={};a.forEach(I=>{const L=l.getElementState(I.id)||[];L.includes(s.HIGHLIGHTED)||(u[I.id]=[...L,s.HIGHLIGHTED])}),l.setElementState(u)}),t.signal.aborted){l.destroy();return}await l.render(),!t.signal.aborted&&!l.destroyed&&(g(l,i,h.current),E.current=l)}catch(r){console.warn("[HypergraphView] Initialize error:",r)}})(),()=>{H.current&&H.current.abort(),E.current&&(E.current.destroy(),E.current=null)}},[_,G,g]),w.jsx("div",{className:"w-full h-full flex flex-col overflow-hidden",children:w.jsx("div",{ref:f,className:"hypergraph-view flex-1"})})});export{B as default};
//# sourceMappingURL=HypergraphView-DWW3Xp5z.js.map
