1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exportGraphImage-CB7KoxfF.js","assets/jspdf.es.min-C5zBKndN.js","assets/index-BRTDjk9K.js","assets/react-vendor-DhSP975V.js","assets/query-vendor-n0_7bG_F.js","assets/ui-vendor-DdP2sx6P.js","assets/supabase-vendor-BlcNSqHb.js","assets/icons-vendor-DGAlFwT6.js","assets/index-7GTji0x6.css","assets/style-BEAhYEon.js","assets/string-CDPTw3GU.js","assets/style-Fd0xVSp_.css"])))=>i.map(i=>d[i]); 2var e=Object.defineProperty,t=(t,r,n)=>((t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n)(t,"symbol"!=typeof r?r+"":r,n);import{r,g as n,j as o,v as a,k as s}from"./react-vendor-DhSP975V.js";import{H as i}from"./Header-Cs9IpE4J.js";import{u as d,b as l}from"./query-vendor-n0_7bG_F.js";import{s as c}from"./client-dIm-I_1l.js";import{c as h}from"./useConcepts-D7Vz3eIZ.js";import{u}from"./useRelationshipTypes-9I2HJrtL.js";import{u as p}from"./formatDistanceToNow-Dg-DDeOJ.js";import{u as g,a as f,g as m,z as v,P as b,c as w,i as x,p as y,h as _,s as E,j,k as N,M as k,H as C,d as O,l as I,E as M,e as T,f as R,R as L,B as S,m as F}from"./style-BEAhYEon.js";import{u as P}from"./useClasses-5k7R5QMT.js";import{u as G}from"./useLocales-DhHGr-fL.js";import{u as D,B as z,_ as V}from"./index-BRTDjk9K.js";import{S as $}from"./switch-v4UFVtl2.js";import{I as B}from"./input-CD1u45TZ.js";import{S as W,a as Y,b as q,c as A,d as H}from"./select-DcZ5m3oV.js";import{B as K}from"./badge-BM65uDYM.js";import{a4 as X,X as Z,br as Q,t as U,aA as J,L as ee,av as te,o as re,h as ne,W as oe,R as ae,Z as se,bs as ie,s as de}from"./icons-vendor-DGAlFwT6.js";import{D as le,a as ce,b as he,c as ue,e as pe,d as ge}from"./alert-dialog-DE5qkilm.js";import{b as fe}from"./AppProtected-LVckdBot.js";import{u as me}from"./use-toast-VS3PAP1g.js";import"./useAuth-B7Ivpqlt.js";import"./ui-vendor-DdP2sx6P.js";import"./supabase-vendor-BlcNSqHb.js";import"./dialog-BJz8_4t4.js";import"./label-CGScN9or.js";import"./Trans-DnhvXxtZ.js";import"./useSubscription-B5rmSgxu.js";import"./string-CDPTw3GU.js";
2import"./activityLog-CKkQifGJ.js";import"./links-DS6srBkI.js";const ve=({id:e,x:t,y:r,width:o,height:a,style:s,color:i,strokeColor:d,strokeWidth:l,className:c,borderRadius:h,shapeRendering:u,onClick:p,selected:g})=>{const{background:f,backgroundColor:m}=s||{},v=i||f||m;return n.createElement("rect",{className:w(["react-flow__minimap-node",{selected:g},c]),x:t,y:r,rx:h,ry:h,width:o,height:a,fill:v,stroke:d,strokeWidth:l,shapeRendering:u,onClick:p?t=>p(t,e):void 0})};ve.displayName="MiniMapNode";var be=r.memo(ve);const we=e=>e.nodeOrigin,xe=e=>e.getNodes().filter(e=>!e.hidden&&e.width&&e.height),ye=e=>e instanceof Function?e:()=>e;var _e=r.memo(function({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:r="",nodeBorderRadius:o=5,nodeStrokeWidth:a=2,nodeComponent:s=be,onClick:i}){const d=f(xe,E),l=f(we),c=ye(t),h=ye(e),u=ye(r),p="undefined"==typeof window||window.chrome?"crispEdges":"geometricPrecision";return n.createElement(n.Fragment,null,d.map(e=>{const{x:t,y:r}=_(e,l).positionAbsolute;return n.createElement(s,{key:e.id,x:t,y:r,width:e.width,height:e.height,style:e.style,selected:e.selected,className:u(e),color:c(e),borderRadius:o,strokeColor:h(e),strokeWidth:a,shapeRendering:p,onClick:i,id:e.id})}))});const Ee=e=>{const t=e.getNodes(),r={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:r,boundingRect:t.length>0?j(N(t,e.nodeOrigin),r):r,rfId:e.rfId}};function je({style:e,className:t,nodeStrokeColor:o="transparent",nodeColor:a="#e2e2e2",nodeClassName:s="",nodeBorderRadius:i=5,nodeStrokeWidth:d=2,nodeComponent:l,maskColor:c="rgb(240, 240, 240, 0.6)",maskStrokeColor:h="none",maskStrokeWidth:u=1,position:p="bottom-right",onClick:_,onNodeClick:j,pannable:N=!1,zoomable:k=!1,ariaLabel:C="React Flow mini map",inversePan:O=!1,zoomStep:I=10,offsetScale:M=5}){const T=g(),R=r.useRef(null),{boundingRect:L,viewBB:S,rfId:F}=f(Ee,E),P=(null==e?void 0:e.width)??200,G=(null==e?void 0:e.height)??150,D=L.width/P,z=L.height/G,V=Math.max(D,z),$=V*P,B=V*G,W=M*V,Y=L.x-($-L.width)/2-W,q=L.y-(B-L.height)/2-W,A=$+2*W,H=B+2*W,K=`react-flow__minimap-desc-${F}`,X=r.useRef(0);X.current=V,r.useEffect(()=>{if(R.current){const e=m(R.current),t=e=>{const{transform:t,d3Selection:r,d3Zoom:n}=T.getState();if("wheel"!==e.sourceEvent.type||!r||!n)return;const o=-e.sourceEvent.deltaY*(1===e.sourceEvent.deltaMode?.05:e.sourceEvent.deltaMode?1:.002)*I,a=t[2]*Math.pow(2,o);n.scaleTo(r,a)},r=e=>{const{transform:t,d3Selection:r,d3Zoom:n,translateExtent:o,width:a,height:s}=T.getState();if("mousemove"!==e.sourceEvent.type||!r||!n)return;const i=X.current*Math.max(1,t[2])*(O?-1:1),d={x:t[0]-e.sourceEvent.movementX*i,y:t[1]-e.sourceEvent.movementY*i},l=[[0,0],[a,s]],c=x.translate(d.x,d.y).scale(t[2]),h=n.constrain()(c,l,o);n.transform(r,h)},n=v().on("zoom",N?r:null).on("zoom.wheel",k?t:null);return e.call(n),()=>{e.on("zoom",null)}}},[N,k,O,I]);const Z=_?e=>{const t=y(e);_(e,{x:t[0],y:t[1]})}:void 0,Q=j?(e,t)=>{const r=T.getState().nodeInternals.get(t);j(e,r)}:void 0;return n.createElement(b,{position:p,style:e,className:w(["react-flow__minimap",t]),"data-testid":"rf__minimap"},n.createElement("svg",{width:P,height:G,viewBox:`${Y} ${q} ${A} ${H}`,role:"img","aria-labelledby":K,ref:R,onClick:Z},C&&n.createElement("title",{id:K},C),n.createElement(_e,{onClick:Q,nodeColor:a,nodeStrokeColor:o,nodeBorderRadius:i,nodeClassName:s,nodeStrokeWidth:d,nodeComponent:l}),n.createElement("path",{className:"react-flow__minimap-mask",d:`M${Y-W},${q-W}h${A+2*W}v${H+2*W}h${-A-2*W}z\n M${S.x},${S.y}h${S.width}v${S.height}h${-S.width}z`,fill:c,fillRule:"evenodd",stroke:h,strokeWidth:u,pointerEvents:"none"})))}je.displayName="MiniMap";var Ne=r.memo(je);function ke(e){return e?{available:"available",planned:"planned",not_available:"not_available",unapproved:"unapproved",not_set:"not_set"}[e]??"not_set":"not_set"}const Ce={available:{bg:"bg-emerald-500/10",border:"border-emerald-500",dot:"bg-emerald-500"},planned:{bg:"bg-blue-500/10",border:"border-blue-500",dot:"bg-blue-500"},unapproved:{bg:"bg-orange-500/10",border:"border-orange-500",dot:"bg-orange-500"},not_available:{bg:"bg-red-500/10",border:"border-red-500",dot:"bg-red-500"},not_set:{bg:"bg-muted/50",border:"border-border",dot:"bg-muted-foreground"}},Oe=r.memo(function({data:e}){const t=e.availability||"not_set",r=Ce[t],n=e.isRoot;return o.jsxs("div",{className:"relative",children:[o.jsx(C,{type:"target",position:O.Left,className:"!w-2 !h-2 !bg-muted-foreground
2/50 !border-0"}),o.jsxs("div",{className:`\n px-4 py-3 rounded-lg bg-card shadow-sm transition-all hover:shadow-md\n ${n?"border-[3px] min-w-[200px] max-w-[280px]":"border-2 min-w-[160px] max-w-[220px]"}\n ${r.border}\n `,children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:`w-2 h-2 rounded-full ${r.dot}`}),o.jsx("span",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-medium",children:t.replace("_"," ")})]}),o.jsx("div",{className:"font-medium text-foreground truncate "+(n?"text-base":"text-sm"),children:e.label}),e.targetTerm&&e.targetTerm!==e.label&&o.jsxs("div",{className:"text-xs text-muted-foreground truncate mt-0.5 italic",children:['"',e.targetTerm,'"']}),e.category&&o.jsx("div",{className:"text-xs mt-1.5 truncate font-medium",style:{color:e.category.color},children:e.category.name})]}),o.jsx(C,{type:"source",position:O.Right,className:"!w-2 !h-2 !bg-muted-foreground/50 !border-0"})]})}),Ie=r.memo(function({id:e,sourceX:t,sourceY:r,targetX:n,targetY:a,sourcePosition:s,targetPosition:i,data:d,markerEnd:l}){const[c,h,u]=I({sourceX:t,sourceY:r,sourcePosition:s,targetX:n,targetY:a,targetPosition:i,curvature:.25});return o.jsxs(o.Fragment,{children:[o.jsx("path",{id:e,className:"react-flow__edge-path",d:c,strokeWidth:2,stroke:"hsl(var(--primary) / 0.6)",strokeDasharray:"6 4",fill:"none",markerEnd:l}),(null==d?void 0:d.label)&&o.jsx(M,{children:o.jsx("div",{className:"absolute px-2 py-1 rounded text-xs font-medium bg-background border border-border text-foreground shadow-sm pointer-events-none whitespace-nowrap",style:{transform:`translate(-50%, -50%) translate(${h}px,${u}px)`},children:d.label})})]})});var Me="\0";function Te(e,t){e[t]?e[t]++:e[t]=1}function Re(e,t){--e[t]||delete e[t]}function Le(e,t,r,n){var o=""+t,a=""+r;if(!e&&o>a){var s=o;o=a,a=s}return o+"�"+a+"�"+(void 0===n?"\0":n)}function Se(e,t){return Le(e,t.v,t.w,t.name)}var Fe=class{constructor(e){t(this,"_isDirected",!0),t(this,"_isMultigraph",!1),t(this,"_isCompound",!1),t(this,"_label"),t(this,"_defaultNodeLabelFn",()=>{}),t(this,"_defaultEdgeLabelFn",()=>{}),t(this,"_nodes",{}),t(this,"_in",{}),t(this,"_preds",{}),t(this,"_out",{}),t(this,"_sucs",{}),t(this,"_edgeObjs",{}),t(this,"_edgeLabels",{}),t(this,"_nodeCount",0),t(this,"_edgeCount",0),t(this,"_parent"),t(this,"_children"),e&&(this._isDirected=!Object.hasOwn(e,"directed")||e.directed,this._isMultigraph=!!Object.hasOwn(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.hasOwn(e,"compound")&&e.compound),this._isCompound&&
2(this._parent={},this._children={},this._children[Me]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=e,"function"!=typeof e&&(this._defaultNodeLabelFn=()=>e),this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._in[t]).length)}sinks(){var e=this;return this.nodes().filter(t=>0===Object.keys(e._out[t]).length)}setNodes(e,t){var r=arguments,n=this;return e.forEach(function(e){r.length>1?n.setNode(e,t):n.setNode(e)}),this}setNode(e,t){return Object.hasOwn(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=Me,this._children[e]={},this._children[Me][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.hasOwn(this._nodes,e)}removeNode(e){var t=this;if(Object.hasOwn(this._nodes,e)){var r=e=>t.removeEdge(t._edgeObjs[e]);
2delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(function(e){t.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(r),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(r),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(void 0===t)t=Me;else{for(var r=t+="";void 0!==r;r=this.parent(r))if(r===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==Me)return t}}children(e=Me){if(this._isCompound){var t=this._children[e];if(t)return Object.keys(t)}else{if(e===Me)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return Object.keys(t)}successors(e){var t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){var t=this.predecessors(e);if(t){const n=new Set(t);for(var r of this.successors(e))n.add(r);return Array.from(n.values())}}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var r=this;Object.entries(this._nodes).forEach(function([r,n]){e(r)&&t.setNode(r,n)}),Object.values(this._edgeObjs).forEach(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,r.edge(e))});var n={};function o(e){var a=r.parent(e);return void 0===a||t.hasNode(a)?(n[e]=a,a):a in n?n[a]:o(a)}return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,o(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=e,"function"!=typeof e&&(this._defaultEdgeLabelFn=()=>e),this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){var r=this,n=arguments;return e.reduce(function(e,o){return n.length>1?r.setEdge(e,o,t):r.setEdge(e,o),o}),this}setEdge(){var e,t,r,n,o=!1,a=arguments[0];"object"==typeof a&&null!==a&&"v"in a?(e=a.v,t=a.w,r=a.name,2===arguments.length&&(n=arguments[1],o=!0)):(e=a,t=arguments[1],r=arguments[3],arguments.length>2&&(n=arguments[2],o=!0)),e=""+e,t=""+t,void 0!==r&&(r=""+r);var s=Le(this._isDirected,e,t,r);if(Object.hasOwn(this._edgeLabels,s))return o&&(this._edgeLabels[s]=n),this;if(void 0!==r&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[s]=o?n:this._defaultEdgeLabelFn(e,t,r);var i=function(e,t,r,n){var o=""+t,a=""+r;if(!e&&o>a){var s=o;o=a,a=s}var i={v:o,w:a};return n&&(i.name=n),i}(this._isDirected,e,t,r);return e=i.v,t=i.w,Object.freeze(i),this._edgeObjs[s]=i,Te(this._preds[t],e),Te(this._sucs[e],t),this._in[t][s]=i,this._out[e][s]=i,this._edgeCount++,this}edge(e,t,r){var n=1===arguments.length?Se(this._isDirected,arguments[0]):Le(this._isDirected,e,t,r);return this._edgeLabels[n]}edgeAsObj(){const e=this.edge(...arguments);return"object"!=typeof e?{label:e}:e}hasEdge(e,t,r){var n=1===arguments.length?Se(this._isDirected,arguments[0]):Le(this._isDirected,e,t,r);return Object.hasOwn(this._edgeLabels,n)}removeEdge(e,t,r){var n=1===arguments.length?Se(this._isDirected,arguments[0]):Le(this._isDirected,e,t,r),o=this._edgeObjs[n];return o&&(e=o.v,t=o.w,delete this._edgeLabels[n],delete this._edgeObjs[n],Re(this._preds[t],e),Re(this._sucs[e],t),delete this._in[t][n],delete this._out[e][n],this._edgeCount--),this}inEdges(e,t){var r=this._in[e];if(r){var n=Object.values(r);return t?n.filter(e=>e.v===t):n}}outEdges(e,t){var r=this._out[e];if(r){var n=Object.values(r);return t?n.filter(e=>e.w===t):n}}nodeEdges(e,t){var r=this.inEdges(e,t);if(r)return r.concat(this.outEdges(e,t))}},Pe=Fe,Ge="2.2.4",De=Fe,ze={write:function(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Ve(e),edges:$e(e)};return void 0!==e.graph()&&(t.value=structuredClone(e.graph())),t},read:function(e){var t=new De(e.options).setGraph(e.value);
2return e.nodes.forEach(function(e){t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(function(e){t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}};function Ve(e){return e.nodes().map(function(t){var r=e.node(t),n=e.parent(t),o={v:t};return void 0!==r&&(o.value=r),void 0!==n&&(o.parent=n),o})}function $e(e){return e.edges().map(function(t){var r=e.edge(t),n={v:t.v,w:t.w};return void 0!==t.name&&(n.name=t.name),void 0!==r&&(n.value=r),n})}var Be=class{constructor(){t(this,"_arr",[]),t(this,"_keyIndices",{})}size(){return this._arr.length}keys(){return this._arr.map(function(e){return e.key})}has(e){return Object.hasOwn(this._keyIndices,e)}priority(e){var t=this._keyIndices[e];if(void 0!==t)return this._arr[t].priority}min(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key}add(e,t){var r=this._keyIndices;if(e=String(e),!Object.hasOwn(r,e)){var n=this._arr,o=n.length;return r[e]=o,n.push({key:e,priority:t}),this._decrease(o),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){var r=this._keyIndices[e];if(t>this._arr[r].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[r].priority+" New: "+t);this._arr[r].priority=t,this._decrease(r)}_heapify(e){var t=this._arr,r=2*e,n=r+1,o=e;r<t.length&&(o=t[r].priority<t[o].priority?r:o,n<t.length&&(o=t[n].priority<t[o].priority?n:o),o!==e&&(this._swap(e,o),this._heapify(o)
2))}_decrease(e){for(var t,r=this._arr,n=r[e].priority;0!==e&&!(r[t=e>>1].priority<n);)this._swap(e,t),e=t}_swap(e,t){var r=this._arr,n=this._keyIndices,o=r[e],a=r[t];r[e]=a,r[t]=o,n[a.key]=e,n[o.key]=t}},We=Be,Ye=function(e,t,r,n){return function(e,t,r,n){var o,a,s={},i=new We,d=function(e){var t=e.v!==o?e.v:e.w,n=s[t],d=r(e),l=a.distance+d;if(d<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+e+" Weight: "+d);l<n.distance&&(n.distance=l,n.predecessor=o,i.decrease(t,l))};for(e.nodes().forEach(function(e){var r=e===t?0:Number.POSITIVE_INFINITY;s[e]={distance:r},i.add(e,r)});i.size()>0&&(o=i.removeMin(),(a=s[o]).distance!==Number.POSITIVE_INFINITY);)n(o).forEach(d);return s}(e,String(t),r||qe,n||function(t){return e.outEdges(t)})},qe=()=>1,Ae=Ye,He=function(e){var t=0,r=[],n={},o=[];function a(s){var i=n[s]={onStack:!0,lowlink:t,index:t++};if(r.push(s),e.successors(s).forEach(function(e){Object.hasOwn(n,e)?n[e].onStack&&(i.lowlink=Math.min(i.lowlink,n[e].index)):(a(e),i.lowlink=Math.min(i.lowlink,n[e].lowlink))}),i.lowlink===i.index){var d,l=[];do{d=r.pop(),n[d].onStack=!1,l.push(d)}while(s!==d);o.push(l)}}return e.nodes().forEach(function(e){Object.hasOwn(n,e)||a(e)}),o},Ke=He,Xe=()=>1;function Ze(e){var t={},r={},n=[];if(e.sinks().forEach(function o(a){if(Object.hasOwn(r,a))throw new Qe;Object.hasOwn(t,a)||(r[a]=!0,t[a]=!0,e.predecessors(a).forEach(o),delete r[a],n.push(a))}),Object.keys(t).length!==e.nodeCount())throw new Qe;return n}class Qe extends Error{constructor(){super(...arguments)}}var Ue=Ze;Ze.CycleException=Qe;var Je=Ue,et=function(e,t,r){Array.isArray(t)||(t=[t]);var n=e.isDirected()?t=>e.successors(t):t=>e.neighbors(t),o="post"===r?tt:rt,a=[],s={};return t.forEach(t=>{if(!e.hasNode(t))throw new Error("Graph does not have node: "+t);o(t,n,s,a)}),a};function tt(e,t,r,n){for(var o=[[e,!1]];o.length>0;){var a=o.pop();a[1]?n.push(a[0]):Object.hasOwn(r,a[0])||(r[a[0]]=!0,o.push([a[0],!0]),nt(t(a[0]),e=>o.push([e,!1])))}}function rt(e,t,r,n){for(var o=[e];o.length>0;){var a=o.pop();Object.hasOwn(r,a)||(r[a]=!0,n.push(a),nt(t(a),e=>o.push(e)))}}function nt(e,t){for(var r=e.length;r--;)t(e[r],r,e);return e}var ot=et,at=et,st=Fe,it=Be,dt={Graph:Pe,json:ze,alg:{components:function(e){var t,r={},n=[];function o(n){Object.hasOwn(r,n)||(r[n]=!0,t.push(n),e.successors(n).forEach(o),e.predecessors(n).forEach(o))}return e.nodes().forEach(function(e){t=[],o(e),t.length&&n.push(t)}),n},dijkstra:Ye,dijkstraAll:function(e,t,r){return e.nodes().reduce(function(n,o){return n[o]=Ae(e,o,t,r),n},{})},findCycles:function(e){return Ke(e).filter(function(t){return t.length>1||1===t.length&&e.hasEdge(t[0],t[0])})},floydWarshall:function(e,t,r){return function(e,t,r){var n={},o=e.nodes();return o.forEach(function(e){n[e]={},n[e][e]={distance:0},o.forEach(function(t){e!==t&&(n[e][t]={distance:Number.POSITIVE_INFINITY})}),r(e).forEach(function(r){var o=r.v===e?r.w:r.v,a=t(r);n[e][o]={distance:a,predecessor:e}})}),o.forEach(function(e){var t=n[e];o.forEach(function(r){var a=n[r];o.forEach(function(r){var n=a[e],o=t[r],s=a[r],i=n.distance+o.distance;i<s.distance&&(s.distance=i,s.predecessor=o.predecessor)})})}),n}(e,t||Xe,r||function(t){return e.outEdges(t)})},isAcyclic:function(e){try{Je(e)}catch(t){if(t instanceof Je.CycleException)return!1;throw t}return!0},postorder:function(e,t){return ot(e,t,"post")},preorder:function(e,t){return at(e,t,"pre")},prim:function(e,t){var r,n=new st,o={},a=new it;function s(e){var n=e.v===r?e.w:e.v,s=a.priority(n);if(void 0!==s){var i=t(e);i<s&&(o[n]=r,a.decrease(n,i))}}if(0===e.nodeCount())return n;e.nodes().forEach(function(e){a.add(e,Number.POSITIVE_INFINITY),n.setNode(e)}),a.decrease(e.nodes()[0],0);for(var i=!1;a.size()>0;){if(r=a.removeMin(),Object.hasOwn(o,r))n.setEdge(r,o[r]);else{if(i)throw new Error("Input graph is not connected: "+e);i=!0}e.nodeEdges(r).forEach(s)}return n},tarjan:He,topsort:Ue},version:Ge};function lt(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function ct(e,t){if("_next"!==e&&"_prev"!==e)return t}let ht=dt.Graph,ut=class{constructor(){let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return lt(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&<(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,r=t._prev;
2for(;r!==t;)e.push(JSON.stringify(r,ct)),r=r._prev;return"["+e.join(", ")+"]"}};let pt=()=>1;function gt(e,t,r,n,o){let a=o?[]:void 0;return e.inEdges(n.v).forEach(n=>{let s=e.edge(n),i=e.node(n.v);o&&a.push({v:n.v,w:n.w}),i.out-=s,ft(t,r,i)}),e.outEdges(n.v).forEach(n=>{let o=e.edge(n),a=n.w,s=e.node(a);s.in-=o,ft(t,r,s)}),e.removeNode(n.v),a}function ft(e,t,r){r.out?r.in?e[r.out-r.in+t].enqueue(r):e[e.length-1].enqueue(r):e[0].enqueue(r)}let mt=dt.Graph;var vt={addBorderNode:function(e,t,r,n){let o={width:0,height:0};return arguments.length>=4&&(o.rank=r,o.order=n),bt(e,"border",o,t)},addDummyNode:bt,applyWithChunking:xt,asNonCompoundGraph:function(e){let t=new mt({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(r=>{e.children(r).length||t.setNode(r,e.node(r))}),e.edges().forEach(r=>{t.setEdge(r,e.edge(r))}),t},buildLayerMatrix:function(e){let t=jt(yt(e)+1).map(()=>[]);return e.nodes().forEach(r=>{let n=e.node(r),o=n.rank;void 0!==o&&(t[o][n.order]=r)}),t},intersectRect:function(e,t){let r,n,o=e.x,a=e.y,s=t.x-o,i=t.y-a,d=e.width/2,l=e.height/2;if(!s&&!i)throw new Error("Not possible to find intersection inside of the rectangle");return Math.abs(i)*d>Math.abs(s)*l?(i<0&&(l=-l),r=l*s/i,n=l):(s<0&&(d=-d),r=d,n=d*i/s),{x:o+r,y:a+n}},mapValues:function(e,t){let r=t;return"string"==typeof t&&(r=e=>e[t]),Object.entries(e).reduce((e,[t,n])=>(e[t]=r(n,t),e),{})},maxRank:yt,normalizeRanks:function(e){let t=e.nodes().map(t=>{let r=e.node(t).rank;return void 0===r?Number.MAX_VALUE:r}),r=xt(Math.min,t);e.nodes().forEach(t=>{let n=e.node(t);Object.hasOwn(n,"rank")&&(n.rank-=r)})},notime:function(e,t){return t()},partition:function(e,t){let r={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?r.lhs.push(e):r.rhs.push(e)}),r},pick:function(e,t){const r={};for(const n of t)void 0!==e[n]&&(r[n]=e[n]);return r},predecessorWeights:function(e){let t=e.nodes().map(t=>{let r={};return e.inEdges(t).forEach(t=>{r[t.v]=(r[t.v]||0)+e.edge(t).weight}),r});return Nt(e.nodes(),t)},range:jt,removeEmptyRanks:function(e){let t=e.nodes().map(t=>e.node(t).rank),r=xt(Math.min,t),n=[];e.nodes().forEach(t=>{let o=e.node(t).rank-r;n[o]||(n[o]=[]),n[o].push(t)});let o=0,a=e.graph().nodeRankFactor;Array.from(n).forEach((t,r)=>{void 0===t&&r%a!==0?--o:void 0!==t&&o&&t.forEach(t=>e.node(t).rank+=o)})},simplify:function(e){let t=(new mt).setGraph(e.graph());return e.nodes().forEach(r=>
2t.setNode(r,e.node(r))),e.edges().forEach(r=>{let n=t.edge(r.v,r.w)||{weight:0,minlen:1},o=e.edge(r);t.setEdge(r.v,r.w,{weight:n.weight+o.weight,minlen:Math.max(n.minlen,o.minlen)})}),t},successorWeights:function(e){let t=e.nodes().map(t=>{let r={};return e.outEdges(t).forEach(t=>{r[t.w]=(r[t.w]||0)+e.edge(t).weight}),r});return Nt(e.nodes(),t)},time:function(e,t){let r=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-r)+"ms")}},uniqueId:Et,zipObject:Nt};function bt(e,t,r,n){for(var o=n;e.hasNode(o);)o=Et(n);return r.dummy=t,e.setNode(o,r),o}const wt=65535;function xt(e,t){if(t.length>wt){const r=function(e,t=wt){const r=[];for(let n=0;n<e.length;n+=t){const o=e.slice(n,n+t);r.push(o)}return r}(t);return e.apply(null,r.map(t=>e.apply(null,t)))}return e.apply(null,t)}function yt(e){const t=e.nodes().map(t=>{let r=e.node(t).rank;return void 0===r?Number.MIN_VALUE:r});return xt(Math.max,t)}let _t=0;function Et(e){return e+""+ ++_t}function jt(e,t,r=1){null==t&&(t=e,e=0);let n=e=>e<t;r<0&&(n=e=>t<e);const o=[];for(let a=e;n(a);a+=r)o.push(a);return o}function Nt(e,t){return e.reduce((e,r,n)=>(e[r]=t[n],e),{})}let kt=function(e,t){if(e.nodeCount()<=1)return[];let r=function(e,t){let r=new ht,n=0,o=0;e.nodes().forEach(e=>{r.setNode(e,{v:e,in:0,out:0})}
2),e.edges().forEach(e=>{let a=r.edge(e.v,e.w)||0,s=t(e),i=a+s;r.setEdge(e.v,e.w,i),o=Math.max(o,r.node(e.v).out+=s),n=Math.max(n,r.node(e.w).in+=s)});let a=function(e){const t=[];for(let r=0;r<e;r++)t.push(r);return t}(o+n+3).map(()=>new ut),s=n+1;return r.nodes().forEach(e=>{ft(a,s,r.node(e))}),{graph:r,buckets:a,zeroIdx:s}}(e,t||pt);return function(e,t,r){let n,o=[],a=t[t.length-1],s=t[0];for(;e.nodeCount();){for(;n=s.dequeue();)gt(e,t,r,n);for(;n=a.dequeue();)gt(e,t,r,n);if(e.nodeCount())for(let a=t.length-2;a>0;--a)if(n=t[a].dequeue(),n){o=o.concat(gt(e,t,r,n,!0));break}}return o}(r.graph,r.buckets,r.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w))},Ct=vt.uniqueId;var Ot={run:function(e){var t;("greedy"===e.graph().acyclicer?kt(e,(t=e,e=>t.edge(e).weight)):function(e){let t=[],r={},n={};return e.nodes().forEach(function o(a){Object.hasOwn(n,a)||(n[a]=!0,r[a]=!0,e.outEdges(a).forEach(e=>{Object.hasOwn(r,e.w)?t.push(e):o(e.w)}),delete r[a])}),t}(e)).forEach(t=>{let r=e.edge(t);e.removeEdge(t),r.forwardName=t.name,r.reversed=!0,e.setEdge(t.w,t.v,r,Ct("rev"))})}
2,undo:function(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.reversed){e.removeEdge(t);let n=r.forwardName;delete r.reversed,delete r.forwardName,e.setEdge(t.w,t.v,r,n)}})}};let It=vt;var Mt={run:function(e){e.graph().dummyChains=[],e.edges().forEach(t=>function(e,t){let r,n,o,a=t.v,s=e.node(a).rank,i=t.w,d=e.node(i).rank,l=t.name,c=e.edge(t),h=c.labelRank;if(d!==s+1){for(e.removeEdge(t),o=0,++s;s<d;++o,++s)c.points=[],n={width:0,height:0,edgeLabel:c,edgeObj:t,rank:s},r=It.addDummyNode(e,"edge",n,"_d"),s===h&&(n.width=c.width,n.height=c.height,n.dummy="edge-label",n.labelpos=c.labelpos),e.setEdge(a,r,{weight:c.weight},l),0===o&&e.graph().dummyChains.push(r),a=r;e.setEdge(a,i,{weight:c.weight},l)}}(e,t))},undo:function(e){e.graph().dummyChains.forEach(t=>{let r,n=e.node(t),o=n.edgeLabel;for(e.setEdge(n.edgeObj,o);n.dummy;)r=e.successors(t)[0],e.removeNode(t),o.points.push({x:n.x,y:n.y}),"edge-label"===n.dummy&&(o.x=n.x,o.y=n.y,o.width=n.width,o.height=n.height),t=r,n=e.node(t)})}};const{applyWithChunking:Tt}=vt;var Rt=function(e){var t={};e.sources().forEach(function r(n){var o=e.node(n);if(Object.hasOwn(t,n))return o.rank;t[n]=!0;let a=e.outEdges(n).map(t=>null==t?Number.POSITIVE_INFINITY:r(t.w)-e.edge(t).minlen);var s=Tt(Math.min,a);return s===Number.POSITIVE_INFINITY&&(s=0),o.rank=s})},Lt=function(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen},St=dt.Graph,Ft=Lt,Pt=function(e){var t,r,n=new St({directed:!1}),o=e.nodes()[0],a=e.nodeCount();for(n.setNode(o,{});Gt(n,e)<a;)t=Dt(n,e),r=n.hasNode(t.v)?Ft(e,t):-Ft(e,t),zt(n,e,r);return n};function Gt(e,t){return e.nodes().forEach(function r(n){t.nodeEdges(n).forEach(o=>{var a=o.v,s=n===a?o.w:a;e.hasNode(s)||Ft(t,o)||(e.setNode(s,{}),e.setEdge(n,s,{}),r(s))})}),e.nodeCount()}function Dt(e,t){return t.edges().reduce((r,n)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(n.v)!==e.hasNode(n.w)&&(o=Ft(t,n)),o<r[0]?[o,n]:r},[Number.POSITIVE_INFINITY,null])[1]}function zt(e,t,r){e.nodes().forEach(e=>t.node(e).rank+=r)}var Vt=Pt,$t=Lt,Bt=Rt,Wt=dt.alg.preorder,Yt=dt.alg.postorder,qt=vt.simplify,At=Ht;function Ht(e){e=qt(e),Bt(e);var t,r=Vt(e);for(Zt(r),Kt(r,e);t=Ut(r);)er(r,e,t,Jt(r,e,t))}function Kt(e,t){var r=Yt(e,e.nodes());(r=r.slice(0,r.length-1)).forEach(r=>function(e,t,r){var n=e.node(r).parent;e.edge(r,n).cutvalue=Xt(e,t,r)}(e,t,r))}function Xt(e,t,r){var n=e.node(r).parent,o=!0,a=t.edge(r,n),s=0;return a||(o=!1,a=t.edge(n,r)),s=a.weight,t.nodeEdges(r).forEach(a=>{var i,d,l=a.v===r,c=l?a.w:a.v;if(c!==n){var h=l===o,u=t.edge(a).weight;if(s+=h?u:-u,i=r,d=c,e.hasEdge(i,d)){var p=e.edge(r,c).cutvalue;s+=h?-p:p}}}),s}function Zt(e,t){arguments.length<2&&(t=e.nodes()[0]),Qt(e,{},1,t)}function Qt(e,t,r,n,o){var a=r,s=e.node(n);return t[n]=!0,e.neighbors(n).forEach(o=>{Object.hasOwn(t,o)||(r=Qt(e,t,r,o,n))}),s.low=a,s.lim=r++,o?s.parent=o:delete s.parent,r}function Ut(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function Jt(e,t,r){var n=r.v,o=r.w;t.hasEdge(n,o)||(n=r.w,o=r.v);var a=e.node(n),s=e.node(o),i=a,d=!1;return a.lim>s.lim&&(i=s,d=!0),t.edges().filter(t=>d===tr(0,e.node(t.v),i)&&d!==tr(0,e.node(t.w),i)).reduce((e,r)=>$t(t,r)<$t(t,e)?r:e)}function er(e,t,r,n){var o=r.v,a=r.w;e.removeEdge(o,a),e.setEdge(n.v,n.w,{}),Zt(e),Kt(e,t),function(e,t){var r=e.nodes().find(e=>!t.node(e).parent),n=Wt(e,r);(n=n.slice(1)).forEach(r=>{var n=e.node(r).parent,o=t.edge(r,n),a=!1;o||(o=t.edge(n,r),a=!0),t.node(r).rank=t.node(n).rank+(a?o.minlen:-o.minlen)})}(e,t)}function tr(e,t,r){return r.low<=t.lim&&t.lim<=r.lim}Ht.initLowLimValues=Zt,Ht.initCutValues=Kt,Ht.calcCutValue=Xt,Ht.leaveEdge=Ut,Ht.enterEdge=Jt,Ht.exchangeEdges=er;var rr=Rt,nr=Pt,or=At,ar=rr;let sr=vt;function ir(e,t,r,n,o,a,s){let i=e.children(s);if(!i.length)return void(s!==t&&e.setEdge(t,s,{weight:0,minlen:r}));let d=sr.addBorderNode(e,"_bt"),l=sr.addBorderNode(e,"_bb"),c=e.node(s);e.setParent(d,s),c.borderTop=d,e.setParent(l,s),c.borderBottom=l,i.forEach(i=>{ir(e,t,r,n,o,a,i);let c=e.node(i),h=c.borderTop?c.borderTop:i,u=c.borderBottom?c.borderBottom:i,p=c.borderTop?n:2*n,g=h!==u?1:o-a[s]+1;e.setEdge(d,h,{weight:p,minlen:g,nestingEdge:!0}),e.setEdge(u,l,{weight:p,minlen:g,nestingEdge:!0})}),e.parent(s)||e.setEdge(t,d,{weight:0,minlen:o+a[s]})}let dr=vt;function lr(e,t,r,n,o,a){let s={width:0,height:0,rank:a,borderType:t},i=o[t][a-1],d=dr.addDummyNode(e,"border",s,r);o[t][a]=d,e.setParent(d,n),i&&e.setEdge(i,d,{weight:1})}
2function cr(e){e.nodes().forEach(t=>hr(e.node(t))),e.edges().forEach(t=>hr(e.edge(t)))}function hr(e){let t=e.width;e.width=e.height,e.height=t}function ur(e){e.y=-e.y}function pr(e){let t=e.x;e.x=e.y,e.y=t}let gr=vt,fr=vt.zipObject;function mr(e,t,r){let n=fr(r,r.map((e,t)=>t)),o=t.flatMap(t=>e.outEdges(t).map(t=>({pos:n[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos)),a=1;for(;a<r.length;)a<<=1;let s=2*a-1;a-=1;let i=new Array(s).fill(0),d=0;return o.forEach(e=>{let t=e.pos+a;i[t]+=e.weight;let r=0;for(;t>0;)t%2&&(r+=i[t+1]),t=t-1>>1,i[t]+=e.weight;d+=e.weight*r}),d}let vr=vt,br=vt;function wr(e,t,r){let n;for(;t.length&&(n=t[t.length-1]).i<=r;)t.pop(),e.push(n.vs),r++;return r}let xr=dt.Graph,yr=vt,_r=function(e,t){let r=0;for(let n=1;n<t.length;++n)r+=mr(e,t[n-1],t[n]);return r},Er=function e(t,r,n,o){let a=t.children(r),s=t.node(r),i=s?s.borderLeft:void 0,d=s?s.borderRight:void 0,l={};i&&(a=a.filter(e=>e!==i&&e!==d));let c=function(e,t=[]){return t.map(t=>{let r=e.inEdges(t);if(r.length){let n=r.reduce((t,r)=>{let n=e.edge(r),o=e.node(r.v);return{sum:t.sum+n.weight*o.order,weight:t.weight+n.weight}},{sum:0,weight:0});return{v:t,barycenter:n.sum/n.weight,weight:n.weight}}return{v:t}})}(t,a);c.forEach(r=>{if(t.children(r.v).length){let i=e(t,r.v,n,o);l[r.v]=i,Object.hasOwn(i,"barycenter")&&(s=i,void 0!==(a=r).barycenter?(a.barycenter=(a.barycenter*a.weight+s.barycenter*s.weight)/(a.weight+s.weight),a.weight+=s.weight):(a.barycenter=s.barycenter,a.weight=s.weight))}var a,s});let h=function(e,t){let r={};return e.forEach((e,t)=>{let n=r[e.v]={indegree:0,in:[],out:[],vs:[e.v],i:t};void 0!==e.barycenter&&(n.barycenter=e.barycenter,n.weight=e.weight)}
2),t.edges().forEach(e=>{let t=r[e.v],n=r[e.w];void 0!==t&&void 0!==n&&(n.indegree++,t.out.push(r[e.w]))}),function(e){let t=[];function r(e){return t=>{t.merged||(void 0===t.barycenter||void 0===e.barycenter||t.barycenter>=e.barycenter)&&function(e,t){let r=0,n=0;e.weight&&(r+=e.barycenter*e.weight,n+=e.weight),t.weight&&(r+=t.barycenter*t.weight,n+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=r/n,e.weight=n,e.i=Math.min(t.i,e.i),t.merged=!0}(e,t)}}function n(t){return r=>{r.in.push(t),0===--r.indegree&&e.push(r)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(r(o)),o.out.forEach(n(o))}return t.filter(e=>!e.merged).map(e=>vr.pick(e,["vs","i","barycenter","weight"]))}(Object.values(r).filter(e=>!e.indegree))}(c,n);!function(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}(h,l);let u=function(e,t){let r=br.partition(e,e=>Object.hasOwn(e,"barycenter")),n=r.lhs,o=r.rhs.sort((e,t)=>t.i-e.i),a=[],s=0,i=0,d=0;var l;n.sort((l=!!t,(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:l?t.i-e.i:e.i-t.i)),d=wr(a,o,d),n.forEach(e=>{d+=e.vs.length,a.push(e.vs),s+=e.barycenter*e.weight,i+=e.weight,d=wr(a,o,d)});let c={vs:a.flat(!0)};return i&&(c.barycenter=s/i,c.weight=i),c}(h,o);if(i&&(u.vs=[i,u.vs,d].flat(!0),t.predecessors(i).length)){let e=t.node(t.predecessors(i)[0]),r=t.node(t.predecessors(d)[0]);Object.hasOwn(u,"barycenter")||(u.barycenter=0,u.weight=0),u.barycenter=(u.barycenter*u.weight+e.order+r.order)/(u.weight+2),u.weight+=2}return u},jr=dt.Graph,Nr=vt;function kr(e,t,r){const n=new Map,o=(e,t)=>{n.has(e)||n.set(e,[]),n.get(e).push(t)};for(const a of e.nodes()){const t=e.node(a);if("number"==typeof t.rank&&o(t.rank,a),"number"==typeof t.minRank&&"number"==typeof t.maxRank)for(let e=t.minRank;e<=t.maxRank;e++)e!==t.rank&&o(e,a)}return t.map(function(t){return function(e,t,r,n){n||(n=e.nodes());let o=function(e){for(var t;e.hasNode(t=yr.uniqueId("_root")););return t}(e),a=new xr({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(t=>e.node(t));return n.forEach(n=>{let s=e.node(n),i=e.parent(n);(s.rank===t||s.minRank<=t&&t<=s.maxRank)&&(a.setNode(n),a.setParent(n,i||o),e[r](n).forEach(t=>{let r=t.v===n?t.w:t.v,o=a.edge(r,n),s=void 0!==o?o.weight:0;a.setEdge(r,n,{weight:e.edge(t).weight+s})}),Object.hasOwn(s,"minRank")&&a.setNode(n,{borderLeft:s.borderLeft[t],borderRight:s.borderRight[t]}))}),a}(e,t,r,n.get(t)||[])})}function Cr(e,t){let r=new jr;e.forEach(function(e){let n=e.graph().root,o=Er(e,n,r,t);o.vs.forEach((t,r)=>e.node(t).order=r),function(e,t,r){let n,o={};r.forEach(r=>{let a,s,i=e.parent(r);for(;i;){if(a=e.parent(i),a?(s=o[a],o[a]=i):(s=n,n=i),s&&s!==i)return void t.setEdge(s,i);i=a}})}(e,r,o.vs)})}function Or(e,t){Object.values(t).forEach(t=>t.forEach((t,r)=>e.node(t).order=r))}let Ir=dt.Graph,Mr=vt;function Tr(e,t,r){if(t>r){let e=t;t=r,r=e}let n=e[t];n||(e[t]=n={}),n[r]=!0}function Rr(e,t,r){if(t>r){let e=t;t=r,r=e}return!!e[t]&&Object.hasOwn(e[t],r)}let Lr=vt,Sr=Ot,Fr=Mt,Pr=function(e){var t=e.graph().ranker;if(t instanceof Function)return t(e);switch(e.graph().ranker){case"network-simplex":default:!function(e){or(e)}(e);break;case"tight-tree":!function(e){rr(e),nr(e)}(e);break;case"longest-path":ar(e);case"none":}},Gr=vt.normalizeRanks,Dr=vt.removeEmptyRanks,zr=function(e){let t=sr.addDummyNode(e,"root",{},"_root"),r=function(e){var t={};function r(n,o){var a=e.children(n);a&&a.length&&a.forEach(e=>r(e,o+1)),t[n]=o}
2return e.children().forEach(e=>r(e,1)),t}(e),n=Object.values(r),o=sr.applyWithChunking(Math.max,n)-1,a=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let s=function(e){return e.edges().reduce((t,r)=>t+e.edge(r).weight,0)}(e)+1;e.children().forEach(n=>ir(e,t,a,s,o,r,n)),e.graph().nodeRankFactor=a},Vr=function(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})},$r=function(e){let t=e.graph().rankdir.toLowerCase();"lr"!==t&&"rl"!==t||cr(e)},Br=function(e){let t=e.graph().rankdir.toLowerCase();"bt"!==t&&"rl"!==t||function(e){e.nodes().forEach(t=>ur(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(ur),Object.hasOwn(r,"y")&&ur(r)})}(e),"lr"!==t&&"rl"!==t||(function(e){e.nodes().forEach(t=>pr(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);r.points.forEach(pr),Object.hasOwn(r,"x")&&pr(r)})}(e),cr(e))},Wr=function e(t,r){if(r&&"function"==typeof r.customOrder)return void r.customOrder(t,e);let n=Nr.maxRank(t),o=kr(t,Nr.range(1,n+1),"inEdges"),a=kr(t,Nr.range(n-1,-1,-1),"outEdges"),s=function(e){let t={},r=e.nodes().filter(t=>!e.children(t).length),n=r.map(t=>e.node(t).rank),o=gr.applyWithChunking(Math.max,n),a=gr.range(o+1).map(()=>[]);return r.sort((t,r)=>e.node(t).rank-e.node(r).rank).forEach(function r(n){if(t[n])return;t[n]=!0;let o=e.node(n);a[o.rank].push(n),e.successors(n).forEach(r)}),a}(t);if(Or(t,s),r&&r.disableOptimalOrderHeuristic)return;let i,d=Number.POSITIVE_INFINITY;for(let l=0,c=0;c<4;++l,++c){Cr(l%2?o:a,l%4>=2),s=Nr.buildLayerMatrix(t);let e=_r(t,s);e<d&&(c=0,i=Object.assign({},s),d=e)}Or(t,i)},Yr=function(e){(function(e){let t=Lr.buildLayerMatrix(e),r=e.graph().ranksep,n=0;t.forEach(t=>{const o=t.reduce((t,r)=>{const n=e.node(r).height;return t>n?t:n},0);t.forEach(t=>e.node(t).y=n+o/2),n+=o+r})})(e=Lr.asNonCompoundGraph(e)),Object.entries(function(e){let t,r=Mr.buildLayerMatrix(e),n=Object.assign(function(e,t){let r={};return t.length&&t.reduce(function(t,n){let o=0,a=0,s=t.length,i=n[n.length-1];return n.forEach((t,d)=>{let l=function(e,t){if(e.node(t).dummy)return e.predecessors(t).find(t=>e.node(t).dummy)}(e,t),c=l?e.node(l).order:s;(l||t===i)&&(n.slice(a,d+1).forEach(t=>{e.predecessors(t).forEach(n=>{let a=e.node(n),s=a.order;!(s<o||c<s)||a.dummy&&e.node(t).dummy||Tr(r,n,t)})}),a=d+1,o=c)}),n}),r}(e,r),function(e,t){let r={};function n(t,n,o,a,s){let i;Mr.range(n,o).forEach(n=>{i=t[n],e.node(i).dummy&&e.predecessors(i).forEach(t=>{let n=e.node(t);n.dummy&&(n.order<a||n.order>s)&&Tr(r,t,i)})})}return t.length&&t.reduce(function(t,r){let o,a=-1,s=0;return r.forEach((i,d)=>{if("border"===e.node(i).dummy){let t=e.predecessors(i);t.length&&(o=e.node(t[0]).order,n(r,s,d,a,o),s=d,a=o)}n(r,s,r.length,o,t.length)}),r}),r}(e,r)),o={};["u","d"].forEach(a=>{t="u"===a?r:Object.values(r).reverse(),["l","r"].forEach(r=>{"r"===r&&(t=t.map(e=>Object.values(e).reverse()));let s=("u"===a?e.predecessors:e.successors).bind(e),i=function(e,t,r,n){let o={},a={},s={};return t.forEach(e=>{e.forEach((e,t)=>{o[e]=e,a[e]=e,s[e]=t})}),t.forEach(e=>{let t=-1;e.forEach(e=>{let i=n(e);if(i.length){i=i.sort((e,t)=>s[e]-s[t]);let n=(i.length-1)/2;for(let d=Math.floor(n),l=Math.ceil(n);d<=l;++d){let n=i[d];a[e]===e&&t<s[n]&&!Rr(r,e,n)&&(a[n]=e,a[e]=o[e]=o[n],t=s[n])}}})}),{root:o,align:a}}(0,t,n,s),d=function(e,t,r,n,o){let a={},s=function(e,t,r,n){let o=new Ir,a=e.graph(),s=function(e,t,r){return(n,o,a)=>{let s,i=n.node(o),d=n.node(a),l=0;if(l+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":s=-i.width/2;break;case"r":s=i.width/2}if(s&&(l+=r?s:-s),s=0,l+=(i.dummy?t:e)/2,l+=(d.dummy?t:e)/2,l+=d.width/2,Object.hasOwn(d,"labelpos"))switch(d.labelpos.toLowerCase()){case"l":s=d.width/2;break;case"r":s=-d.width/2}return s&&(l+=r?s:-s),s=0,l}}(a.nodesep,a.edgesep,n);return t.forEach(t=>{let n;t.forEach(t=>{let a=r[t];if(o.setNode(a),n){var i=r[n],d=o.edge(i,a);o.setEdge(i,a,Math.max(s(e,t,n),d||0))}n=t})}),o}(e,t,r,o),i=o?"borderLeft":"borderRight";function d(e,t){let r=s.nodes(),n=r.pop(),o={};for(;n;)o[n]?e(n):(o[n]=!0,r.push(n),r=r.concat(t(n))),n=r.pop()}return d(function(e){a[e]=s.inEdges(e).reduce((e,t)=>
2Math.max(e,a[t.v]+s.edge(t)),0)},s.predecessors.bind(s)),d(function(t){let r=s.outEdges(t).reduce((e,t)=>Math.min(e,a[t.w]-s.edge(t)),Number.POSITIVE_INFINITY),n=e.node(t);r!==Number.POSITIVE_INFINITY&&n.borderType!==i&&(a[t]=Math.max(a[t],r))},s.successors.bind(s)),Object.keys(n).forEach(e=>a[e]=a[r[e]]),a}(e,t,i.root,i.align,"r"===r);"r"===r&&(d=Mr.mapValues(d,e=>-e)),o[a+r]=d})});let a=function(e,t){return Object.values(t).reduce((t,r)=>{let n=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;Object.entries(r).forEach(([t,r])=>{let a=function(e,t){return e.node(t).width}(e,t)/2;n=Math.max(r+a,n),o=Math.min(r-a,o)});const a=n-o;return a<t[0]&&(t=[a,r]),t},[Number.POSITIVE_INFINITY,null])[1]}(e,o);return function(e,t){let r=Object.values(t),n=Mr.applyWithChunking(Math.min,r),o=Mr.applyWithChunking(Math.max,r);["u","d"].forEach(r=>{["l","r"].forEach(a=>{let s=r+a,i=e[s];if(i===t)return;let d=Object.values(i),l=n-Mr.applyWithChunking(Math.min,d);"l"!==a&&(l=o-Mr.applyWithChunking(Math.max,d)),l&&(e[s]=Mr.mapValues(i,e=>e+l))})})}(o,a),function(e,t){return Mr.mapValues(e.ul,(r,n)=>{if(t)return e[t.toLowerCase()][n];{let t=Object.values(e).map(e=>e[n]).sort((e,t)=>e-t);return(t[1]+t[2])/2}})}(o,e.graph().align)}(e)).forEach(([t,r])=>e.node(t).x=r)},qr=vt,Ar=dt.Graph;let Hr=["nodesep","edgesep","ranksep","marginx","marginy"],Kr={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},Xr=["acyclicer","ranker","rankdir","align"],Zr=["width","height","rank"],Qr={width:0,height:0},Ur=["minlen","weight","width","height","labeloffset"],Jr={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},en=["labelpos"];function tn(e,t){return qr.mapValues(qr.pick(e,t),Number)}function rn(e){var t={};return e&&Object.entries(e).forEach(([e,r])=>{"string"==typeof e&&(e=e.toLowerCase()),t[e]=r}),t}let nn=vt,on=dt.Graph;const an=a({graphlib:dt,layout:function(e,t){let r=t&&t.debugTiming?qr.time:qr.notime;r("layout",()=>{let n=r(" buildLayoutGraph",()=>function(e){let t=new Ar({multigraph:!0,compound:!0}),r=rn(e.graph());return t.setGraph(Object.assign({},Kr,tn(r,Hr),qr.pick(r,Xr))),e.nodes().forEach(r=>{const n=tn(rn(e.node(r)),Zr);Object.keys(Qr).forEach(e=>{void 0===n[e]&&(n[e]=Qr[e])}),t.setNode(r,n),t.setParent(r,e.parent(r))}
2),e.edges().forEach(r=>{let n=rn(e.edge(r));t.setEdge(r,Object.assign({},Jr,tn(n,Ur),qr.pick(n,en)))}),t}(e));r(" runLayout",()=>function(e,t,r){t(" makeSpaceForEdgeLabels",()=>function(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(r=>{let n=e.edge(r);n.minlen*=2,"c"!==n.labelpos.toLowerCase()&&("TB"===t.rankdir||"BT"===t.rankdir?n.width+=n.labeloffset:n.height+=n.labeloffset)})}(e)),t(" removeSelfEdges",()=>function(e){e.edges().forEach(t=>{if(t.v===t.w){var r=e.node(t.v);r.selfEdges||(r.selfEdges=[]),r.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}(e)),t(" acyclic",()=>Sr.run(e)),t(" nestingGraph.run",()=>zr(e)),t(" rank",()=>Pr(qr.asNonCompoundGraph(e))),t(" injectEdgeLabelProxies",()=>function(e){e.edges().forEach(t=>{let r=e.edge(t);if(r.width&&r.height){let r=e.node(t.v),n={rank:(e.node(t.w).rank-r.rank)/2+r.rank,e:t};qr.addDummyNode(e,"edge-proxy",n,"_ep")}})}(e)),t(" removeEmptyRanks",()=>Dr(e)),t(" nestingGraph.cleanup",()=>Vr(e)),t(" normalizeRanks",()=>Gr(e)),t(" assignRankMinMax",()=>function(e){let t=0;e.nodes().forEach(r=>{let n=e.node(r);n.borderTop&&(n.minRank=e.node(n.borderTop).rank,n.maxRank=e.node(n.borderBottom).rank,t=Math.max(t,n.maxRank))}),e.graph().maxRank=t}(e)),t(" removeEdgeLabelProxies",()=>function(e){e.nodes().forEach(t=>{let r=e.node(t);"edge-proxy"===r.dummy&&(e.edge(r.e).labelRank=r.rank,e.removeNode(t))})}(e)),t(" normalize.run",()=>Fr.run(e)),t(" parentDummyChains",()=>function(e){let t=function(e){let t={},r=0;
2return e.children().forEach(function n(o){let a=r;e.children(o).forEach(n),t[o]={low:a,lim:r++}}),t}(e);e.graph().dummyChains.forEach(r=>{let n=e.node(r),o=n.edgeObj,a=function(e,t,r,n){let o,a,s=[],i=[],d=Math.min(t[r].low,t[n].low),l=Math.max(t[r].lim,t[n].lim);o=r;do{o=e.parent(o),s.push(o)}while(o&&(t[o].low>d||l>t[o].lim));for(a=o,o=n;(o=e.parent(o))!==a;)i.push(o);return{path:s.concat(i.reverse()),lca:a}}(e,t,o.v,o.w),s=a.path,i=a.lca,d=0,l=s[d],c=!0;for(;r!==o.w;){if(n=e.node(r),c){for(;(l=s[d])!==i&&e.node(l).maxRank<n.rank;)d++;l===i&&(c=!1)}if(!c){for(;d<s.length-1&&e.node(l=s[d+1]).minRank<=n.rank;)d++;l=s[d]}e.setParent(r,l),r=e.successors(r)[0]}})}(e)),t(" addBorderSegments",()=>function(e){e.children().forEach(function t(r){let n=e.children(r),o=e.node(r);if(n.length&&n.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let t=o.minRank,n=o.maxRank+1;t<n;++t)lr(e,"borderLeft","_bl",r,o,t),lr(e,"borderRight","_br",r,o,t)}})}(e)),t(" order",()=>Wr(e,r)),t(" insertSelfEdges",()=>function(e){qr.buildLayerMatrix(e).forEach(t=>{var r=0;t.forEach((t,n)=>{var o=e.node(t);o.order=n+r,(o.selfEdges||[]).forEach(t=>{qr.addDummyNode(e,"selfedge",{width:t.label.width,height:t.label.height,rank:o.rank,order:n+ ++r,e:t.e,label:t.label},"_se")}),delete o.selfEdges})})}(e)),t(" adjustCoordinateSystem",()=>$r(e)),t(" position",()=>Yr(e)),t(" positionSelfEdges",()=>function(e){e.nodes().forEach(t=>{var r=e.node(t);if("selfedge"===r.dummy){var n=e.node(r.e.v),o=n.x+n.width/2,a=n.y,s=r.x-o,i=n.height/2;e.setEdge(r.e,r.label),e.removeNode(t),r.label.points=[{x:o+2*s/3,y:a-i},{x:o+5*s/6,y:a-i},{x:o+s,y:a},{x:o+5*s/6,y:a+i},{x:o+2*s/3,y:a+i}],r.label.x=r.x,r.label.y=r.y}})}(e)),t(" removeBorderNodes",()=>function(e){e.nodes().forEach(t=>{if(e.children(t).length){let r=e.node(t),n=e.node(r.borderTop),o=e.node(r.borderBottom),a=e.node(r.borderLeft[r.borderLeft.length-1]),s=e.node(r.borderRight[r.borderRight.length-1]);r.width=Math.abs(s.x-a.x),r.height=Math.abs(o.y-n.y),r.x=a.x+r.width/2,r.y=n.y+r.height/2}}),e.nodes().forEach(t=>{"border"===e.node(t).dummy&&e.removeNode(t)})}(e)),t(" normalize.undo",()=>Fr.undo(e)),t(" fixupEdgeLabelCoords",()=>
vendor: 1,201 bytes, line 2
2function(e){e.edges().forEach(t=>{let r=e.edge(t);if(Object.hasOwn(r,"x"))switch("l"!==r.labelpos&&"r"!==r.labelpos||(r.width-=r.labeloffset),r.labelpos){case"l":r.x-=r.width/2+r.labeloffset;break;case"r":r.x+=r.width/2+r.labeloffset}})}(e)),t(" undoCoordinateSystem",()=>Br(e)),t(" translateGraph",()=>function(e){let t=Number.POSITIVE_INFINITY,r=0,n=Number.POSITIVE_INFINITY,o=0,a=e.graph(),s=a.marginx||0,i=a.marginy||0;function d(e){let a=e.x,s=e.y,i=e.width,d=e.height;t=Math.min(t,a-i/2),r=Math.max(r,a+i/2),n=Math.min(n,s-d/2),o=Math.max(o,s+d/2)}e.nodes().forEach(t=>d(e.node(t))),e.edges().forEach(t=>{let r=e.edge(t);Object.hasOwn(r,"x")&&d(r)}),t-=s,n-=i,e.nodes().forEach(r=>{let o=e.node(r);o.x-=t,o.y-=n}),e.edges().forEach(r=>{let o=e.edge(r);o.points.forEach(e=>{e.x-=t,e.y-=n}),Object.hasOwn(o,"x")&&(o.x-=t),Object.hasOwn(o,"y")&&(o.y-=n)}),a.width=r-t+s,a.height=o-n+i}(e)),t(" assignNodeIntersects",()=>function(e){e.edges().forEach(t=>{let r,n,o=e.edge(t),a=e.node(t.v),s=e.node(t.w);o.points?(r=o.points[0],n=o.points[o.points.length-1]):(o.points=[],r=s,n=a),o.points.unshift(qr.intersectRect(a,r)),o.points.push(qr.intersectRect(s,n))})}(e)),t(" reversePoints",()=>
2function(e){e.edges().forEach(t=>{let r=e.edge(t);r.reversed&&r.points.reverse()})}(e)),t(" acyclic.undo",()=>Sr.undo(e))}(n,r,t)),r(" updateInputGraph",()=>function(e,t){e.nodes().forEach(r=>{let n=e.node(r),o=t.node(r);n&&(n.x=o.x,n.y=o.y,n.rank=o.rank,t.children(r).length&&(n.width=o.width,n.height=o.height))}),e.edges().forEach(r=>{let n=e.edge(r),o=t.edge(r);n.points=o.points,Object.hasOwn(o,"x")&&(n.x=o.x,n.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}(e,n))})},debug:{debugOrdering:function(e){let t=nn.buildLayerMatrix(e),r=new on({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{r.setNode(t,{label:t}),r.setParent(t,"layer"+e.node(t).rank)}),e.edges().forEach(e=>r.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let n="layer"+t;r.setNode(n,{rank:"same"}),e.reduce((e,t)=>(r.setEdge(e,t,{style:"invis"}),t))}),r}},util:{time:vt.time,notime:vt.notime},version:"1.1.8"});function sn({filters:e,onChange:t,classes:r,locales:n,relationshipTypes:a,showSearch:s=!0}){const{t:i}=D("data-io"),d=[e.marketCode,e.categoryId,e.relationshipTypeId,e.search].filter(Boolean).length;return o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s&&o.jsxs("div",{className:"relative",children:[o.jsx(X,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),o.jsx(B,{placeholder:i("graph.filters.searchPlaceholder"),value:e.search,onChange:r=>t({...e,search:r.target.value}),className:"pl-8 w-48 h-9"})]}),o.jsxs(W,{value:e.marketCode??"all",onValueChange:r=>t({...e,marketCode:"all"===r?null:r}),children:[o.jsx(Y,{className:"w-36 h-9",children:o.jsx(q,{placeholder:i("graph.filters.marketPlaceholder")})}),o.jsxs(A,{children:[o.jsx(H,{value:"all",children:i("graph.filters.allMarkets")}),n.map(e=>o.jsx(H,{value:e.code,children:e.name},e.code))]})]}),o.jsxs(W,{value:e.categoryId??"all",onValueChange:r=>t({...e,categoryId:"all"===r?null:r}),children:[o.jsx(Y,{className:"w-36 h-9",children:o.jsx(q,{placeholder:i("graph.filters.categoryPlaceholder")})}),o.jsxs(A,{children:[o.jsx(H,{value:"all",children:i("graph.filters.allCategories")}),r.map(e=>o.jsx(H,{value:e.id,children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.id))]})]}),o.jsxs(W,{value:e.relationshipTypeId??"all",onValueChange:r=>t({...e,relationshipTypeId:"all"===r?null:r}),children:[o.jsx(Y,{className:"w-40 h-9",children:o.jsx(q,{placeholder:i("graph.filters.relationshipPlaceholder")})}),o.jsxs(A,{children:[o.jsx(H,{value:"all",children:i("graph.filters.allRelationships")}),a.map(e=>o.jsx(H,{value:e.id,children:e.label},e.id))]})]}),d>0&&o.jsxs(z,{variant:"ghost",size:"sm",onClick:()=>{t({search:"",marketCode:null,categoryId:null,relationshipTypeId:null})},className:"h-9 gap-1.5",children:[o.jsx(Z,{className:"w-3.5 h-3.5"}),i("graph.filters.clear"),o.jsx(K,{variant:"secondary",className:"ml-1 px-1.5 py-0 text-xs",children:d})]})]})}const dn=n.forwardRef(function({conceptCount:e,relationshipCount:t,relationshipTypeCount:r,visibleNodeCount:n,visibleEdgeCount:a},s){const{t:i}=D("data-io"),d=[{icon:Q,label:i("graph.stats.concepts"),value:e,visible:n},{icon:U,label:i("graph.stats.relationships"),value:t,visible:a},{icon:J,label:i("graph.stats.types"),value:r}];return o.jsx("div",{ref:s,className:"flex items-center gap-4 px-4 py-2 bg-card/50 backdrop-blur rounded-lg border border-border/50",children:d.map((e,t)=>o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(e.icon,{className:"w-4 h-4 text-primary"}),o.jsxs("div",{className:"text-sm",children:[o.jsx("span",{className:"font-medium text-foreground",children:void 0!==e.visible&&e.visible!==e.value?`${e.visible}/${e.value}`:e.value}),o.jsx("span",{className:"text-muted-foreground ml-1",children:e.label})]}),t<d.length-1&&o.jsx("div",{className:"w-px h-4 bg-border ml-2"})]},e.label))})}),ln=()=>V(()=>import("./exportGraphImage-CB7KoxfF.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]));function cn({getWrapper:e,getInstance:t,getNodes:n,disabled:a}){const{t:i}=D("data-io"),{isPro:d}=fe(),{toast:l}=me(),c=s(),[h,u]=r.useState(null),p=async(r,o)=>{const a=e(),s=t(),d=n();if(a&&s&&0!==d.length)try{u(r),await o(a,s,d),l({title:i("graph.exportMenu.exportReadyTitle"),description:i("graph.exportMenu.exportReadyDescription",{label:r})})}catch(c){console.error(c),l({title:i("graph.exportMenu.exportFailedTitle"),description:c instanceof Error?c.message:i("graph.exportMenu.unknownError"),variant:"destructive"})}finally{u(null)}else l({title:i("graph.exportMenu.nothingToExportTitle"),description:i("graph.exportMenu.nothingToExportDescription"),variant:"destructive"})},g=()=>{l({title:i("graph.exportMenu.proFeatureTitle"),description:i("graph.exportMenu.proFeatureDescription")}),c("/app/pricing")};return o.jsxs(le,{children:[o.jsx(ce,{asChild:!0,children:o.jsxs(z,{variant:"secondary",size:"sm",className:"h-9 gap-1.5",disabled:a,children:[h?o.jsx(ee,{className:"w-4 h-4 animate-spin"}):o.jsx(te,{className:"w-4 h-4"}),i("graph.exportMenu.exportView")]})}),o.jsxs(he,{align:"end",className:"w-56",children:[o.jsx(ue,{children:i("graph.exportMenu.imageGroup")}),o.jsxs(pe,{onClick:()=>p(i("graph.exportMenu.labels.png1x"),async(e,t,r)=>{const n=await ln();await n.exportGraphToPng(e,t,r,{fileName:n.buildGraphFileName(),scale:1})}),children:[o.jsx(re,{className:"w-4 h-4 mr-2"}),i("graph.exportMenu.pngStandard")]}),o.jsxs(pe,{onClick:d?()=>p(i("graph.exportMenu.labels.png2x"),async(e,t,r)=>{const n=await ln();await n.exportGraphToPng(e,t,r,{fileName:n.buildGraphFileName(),scale:2})}):g,children:[o.jsx(re,{className:"w-4 h-4 mr-2"}),i("graph.exportMenu.pngRetina"),!d&&o.jsx(ne,{className:"w-3 h-3 ml-auto opacity-60"})]}),o.jsxs(pe,{onClick:d?()=>p(i("graph.exportMenu.labels.png4x"),async(e,t,r)=>{const n=await ln();await n.exportGraphToPng(e,t,r,{fileName:n.buildGraphFileName(),scale:4})}):g,children:[o.jsx(re,{className:"w-4 h-4 mr-2"}),i("graph.exportMenu.pngPrint"),!d&&o.jsx(ne,{className:"w-3 h-3 ml-auto opacity-60"})]}),o.jsx(ge,{}),o.jsx(ue,{children:i("graph.exportMenu.vectorGroup")}),o.jsxs(pe,{onClick:d?()=>p(i("graph.exportMenu.labels.svg"),async(e,t,r)=>{const n=await ln();await n.exportGraphToSvg(e,t,r,{fileName:n.buildGraphFileName()})}):g,children:[o.jsx(re,{className:"w-4 h-4 mr-2"}),i("graph.exportMenu.svg"),!d&&o.jsx(ne,{className:"w-3 h-3 ml-auto opacity-60"})]}),o.jsxs(pe,{onClick:d?()=>p(i("graph.exportMenu.labels.pdf"),async(e,t,r)=>{const n=await ln();await n.exportGraphToPdf(e,t,r,{fileName:n.buildGraphFileName(),scale:2})}):g,children:[o.jsx(oe,{className:"w-4 h-4 mr-2"}),i("graph.exportMenu.pdf"),!d&&o.jsx(ne,{className:"w-3 h-3 ml-auto opacity-60"})]})]})]})}const hn={concept:Oe},un={concept:Ie},pn={type:"concept",animated:!0,markerEnd:{type:k.ArrowClosed,color:"hsl(var(--primary) / 0.6)"}};function gn(){const{t:e}=D("data-io"),t=s(),n=l(),[a,g]=r.useState({search:"",marketCode:null,categoryId:null,relationshipTypeId:null}),[f,m]=r.useState(null),[v,b]=r.useState(!1),{data:w=[]}=P(),{data:x=[]}=G(),{reactFlowData:y,isLoading:_,error:E,concepts:j,relationshipTypes:N,allConceptCount:C,allRelationshipCount:O}=function(e,t){const{activeWorkspace:n}=p(),o=null==n?void 0:n.id,{data:a=[],isLoading:s,error:i}=h(),{data:l=[],isLoading:g,error:f}=u(),{data:m=[],isLoading:v,error:b}=d({queryKey:["all_concept_relationships",o],queryFn:async()=>
2{if(!o)return[];const{data:e,error:t}=await c.from("concept_relationships").select("id, source_concept_id, target_concept_id, relationship_type_id, concepts!concept_relationships_source_concept_id_fkey!inner(workspace_id)").eq("concepts.workspace_id",o).order("created_at",{ascending:!0});if(t)throw t;return(e??[]).map(e=>({id:e.id,source_concept_id:e.source_concept_id,target_concept_id:e.target_concept_id,relationship_type_id:e.relationship_type_id}))},enabled:!!o}),{data:w=[],isLoading:x}=d({queryKey:["all_concept_terms_summary",o],queryFn:async()=>{if(!o)return[];const{data:e,error:t}=await c.from("multilingual_terms").select("concept_id, locale_code, preferred_term, market_availability, is_source, concepts!inner(workspace_id)").eq("concepts.workspace_id",o);if(t)throw t;return e??[]},enabled:!!o}),y=s||g||v||x,_=i??f??b,E=r.useMemo(()=>{const e=new Map;return w.forEach(t=>{e.has(t.concept_id)||e.set(t.concept_id,[]),e.get(t.concept_id).push(t)}),e},[w]),j=r.useMemo(()=>new Map(l.map(e=>[e.id,e])),[l]);return{reactFlowData:r.useMemo(()=>{const{search:r,marketCode:n,categoryId:o,relationshipTypeId:s}=e??{};let i=(null==t?void 0:t.focusedConceptId)??null,d=a,l=[];if(null==r?void 0:r.trim()){const e=r.toLowerCase();l=d.filter(t=>{var r;return t.name.toLowerCase().includes(e)||t.id.toLowerCase().includes(e)||(null==(r=E.get(t.id))?void 0:r.some(t=>t.preferred_term.toLowerCase().includes(e)))}),1!==l.length||i||(i=l[0].id)}o&&(d=d.filter(e=>e.category_id===o),l=l.filter(e=>e.category_id===o)),n&&(d=d.filter(e=>{var t;return null==(t=E.get(e.id))?void 0:t.some(e=>e.locale_code===n)}),l=l.filter(e=>{var t;return null==(t=E.get(e.id))?void 0:t.some(e=>e.locale_code===n)}));let c=i?m:m.filter(e=>d.some(t=>t.id===e.source_concept_id)&&d.some(t=>t.id===e.target_concept_id));s&&(c=c.filter(e=>e.relationship_type_id===s));const h=(null==t?void 0:t.oneHopEnabled)??!1;if(i){const e=c.filter(e=>e.source_concept_id===i||e.target_concept_id===i),t=new Set([i]);e.forEach(e=>{t.add(e.source_concept_id),t.add(e.target_concept_id)});let r=e,n=new Set(t);if(h){const o=c.filter(r=>(t.has(r.source_concept_id)||t.has(r.target_concept_id))&&!e.some(e=>e.id===r.id));o.forEach(e=>{n.add(e.source_concept_id),n.add(e.target_concept_id)}),r=[...e,...o]}d=a.filter(e=>n.has(e.id)),c=r}else(null==r?void 0:r.trim())&&(d=l,c=m.filter(e=>d.some(t=>t.id===e.source_concept_id)&&d.some(t=>t.id===e.target_concept_id)));const u=d.map(e=>{const t=(e=>{const t=E.get(e);if(!t)return{availability:"not_set",targetTerm:void 0};if(n){const e=t.find(e=>e.locale_code===n);if(e)return{availability:ke(e.market_availability),targetTerm:e.preferred_term}}const r=t.find(e=>e.is_source);return{availability:ke(null==r?void 0:r.market_availability),targetTerm:void 0}})(e.id);return{id:e.id,type:"concept",position:{x:0,y:0},draggable:!0,data:{label:e.name,category:e.categories,availability:t.availability,targetTerm:t.targetTerm,isRoot:e.id===i}}}),p=new Set;return{nodes:u,edges:c.filter(e=>{const t=j.get(e.relationship_type_id);if("bidirectional"===(null==t?void 0:t.directionality)){const[t,r]=e.source_concept_id<e.target_concept_id?[e.source_concept_id,e.target_concept_id]:[e.target_concept_id,e.source_concept_id],n=`${t}|${r}`;return!p.has(n)&&(p.add(n),!0)}return!0}).map(e=>{const t=j.get(e.relationship_type_id);let r=e.source_concept_id,n=e.target_concept_id,o=(null==t?void 0:t.label)||"relates to",a=e.id;return i&&(e.target_concept_id===i?(r=i,n=e.source_concept_id,o=(null==t?void 0:t.inverse_label)||o,a=`${e.id}_inv`):e.source_concept_id===i&&(r=i,n=e.target_concept_id,o=(null==t?void 0:t.label)||o)),{id:a,source:r,target:n,type:"concept",animated:!0,data:{label:o},markerEnd:{type:k.ArrowClosed,color:"hsl(var(--primary) / 0.6)"}}})}},[a,m,l,e,t,E,j]),isLoading:y,error:_,concepts:a,relationships:m,relationshipTypes:l,allConceptCount:a.length,allRelationshipCount:m.length}}(a,{focusedConceptId:f,oneHopEnabled:v}),I=r.useRef(null),M=r.useRef(null),[V,B]=r.useState(!1),[W,Y]=r.useState({width:0,height:0}),{nodes:q,edges:A}=function(e,t,n={}){const{direction:o="LR",nodeWidth:a=180,nodeHeight:s=80,rankSep:i=100,nodeSep:d=50}=n,l=e.map(e=>e.id).join(","),c=t.map(e=>`${e.source}-${e.target}`).join(",");return r.useMemo(()=>
2{if(0===e.length)return{nodes:[],edges:t};const r=(new an.graphlib.Graph).setDefaultEdgeLabel(()=>({}));r.setGraph({rankdir:o,ranksep:i,nodesep:d}),e.forEach(e=>{r.setNode(e.id,{width:a,height:s})}),t.forEach(e=>{r.setEdge(e.source,e.target)}),an.layout(r);const n=e.map((e,t)=>{const n=r.node(e.id),o=n&&Number.isFinite(n.x)?n.x-a/2:80,i=n&&Number.isFinite(n.y)?n.y-s/2:80+t*(s+24);return{...e,position:{x:o,y:i}}}),l=n.map(e=>e.position.x).filter(Number.isFinite),c=n.map(e=>e.position.y).filter(Number.isFinite),h=l.length?Math.min(...l):0,u=c.length?Math.min(...c):0,p=h<0?80-h:0,g=u<0?80-u:0;return{nodes:p||g?n.map(e=>({...e,position:{x:e.position.x+p,y:e.position.y+g}})):n,edges:t}},[l,c,o,a,s,i,d,e,t])}(y.nodes,y.edges,{direction:"LR",nodeWidth:200,nodeHeight:90,rankSep:150,nodeSep:60}),[H,K,X]=T(q),[Q,U,te]=R(A),[re,ne]=r.useState(!1),oe=r.useMemo(()=>`${a.search}-${a.marketCode}-${a.categoryId}-${a.relationshipTypeId}-${f}-${v}`,[a,f,v]);r.useEffect(()=>{ne(!1)},[oe]);const le=r.useRef(q);le.current=q;const ce=r.useCallback(e=>{const t=M.current,r=I.current,n=le.current;if(!t||!r||0===n.length)return;const o=r.getBoundingClientRect();if(o.width<20||o.height<20)return;const a=n.map(e=>{var t;return null==(t=e.position)?void 0:t.x}).filter(e=>Number.isFinite(e)),s=n.map(e=>{var t;return null==(t=e.position)?void 0:t.y}).filter(e=>Number.isFinite(e)),i=a.length?Math.min(...a):0,d=s.length?Math.min(...s):0,l=a.length?Math.max(...a)+220:220,c=s.length?Math.max(...s)+110:110,h={x:i,y:d,width:Math.max(1,l-i),height:Math.max(1,c-d)};try{if("function"==typeof t.getViewportForBounds){const r=t.getViewportForBounds(h,.1,2,.2);if(r&&Number.isFinite(r.zoom))return void t.setViewport(r,{duration:null==e?void 0:e.duration})}t.fitView({padding:.2,duration:null==e?void 0:e.duration})}catch{const r=n[0];(null==r?void 0:r.position)&&t.setCenter(r.position.x+110,r.position.y+55,{zoom:.9,duration:null==e?void 0:e.duration})}},[]);r.useEffect(()=>{if(!re||0===H.length){const e=requestAnimationFrame(()=>{K(q),U(A),ne(!0)});return()=>cancelAnimationFrame(e)}},[q,A,K,U,re,H.length]),r.useEffect(()=>{if(!V)return;const e=setTimeout(()=>{ce()},50);return()=>clearTimeout(e)},[V,q.length,ce]),r.useEffect(()=>{if(!I.current)return;const e=I.current,t=()=>{const t=e.getBoundingClientRect();Y({width:Math.round(t.width),height:Math.round(t.height)}),V&&ce()},r=new ResizeObserver(t);return r.observe(e),t(),()=>r.disconnect()},[V,ce]);const he=r.useCallback((e,t)=>{m(t.id)},[]),ue=r.useCallback((e,r)=>{t(`/concepts/${r.id}`)},[t]),pe=r.useCallback(()=>{var e;null==(e=M.current)||e.zoomIn({duration:300})},[]),ge=r.useCallback(()=>{var e;null==(e=M.current)||e.zoomOut({duration:300})},[]),fe=r.useCallback(()=>{ce({duration:300})},[ce]),me=r.useCallback(()=>{n.invalidateQueries({queryKey:["concepts"]}),n.invalidateQueries({queryKey:["relationship_types"]}),n.invalidateQueries({queryKey:["all_concept_relationships"]}),n.invalidateQueries({queryKey:["all_concept_terms_summary"]})},[n]),ve=j.length>0;return o.jsxs("div",{className:"page-container flex flex-col",children:[o.jsx(i,{title:e("graph.page.title"),subtitle:e("graph.page.subtitle")}),o.jsxs("div",{className:"flex-1 p-6 flex flex-col gap-4",children:[o.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[o.jsx(sn,{filters:a,onChange:g,classes:w,locales:x,relationshipTypes:N,showSearch:!0}),o.jsx(dn,{conceptCount:C,relationshipCount:O,relationshipTypeCount:N.length,visibleNodeCount:H.length,visibleEdgeCount:Q.length})]}),o.jsxs("div",{ref:I,className:"dashboard-card flex-1 min-h-[500px] relative overflow-hidden p-0",style:{width:"100%"},children:[o.jsxs("div",{"data-graph-overlay":!0,className:"absolute top-4 right-4 flex items-center gap-2 z-10",children:[o.jsx(cn,{getWrapper:()=>I.current,getInstance:()=>M.current,getNodes:()=>H,disabled:!V||0===H.length}),o.jsxs(z,{variant:"secondary",size:"sm",className:"h-9 gap-1.5",onClick:()=>{ne(!1),K(q),U(A)},children:[o.jsx(ae,{className:"w-4 h-4"}),e("graph.controls.resetLayout")]}),f&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-card/80 backdrop-blur rounded-lg border border-border/50",children:[o.jsx($,{id:"one-hop-toggle",checked:v,onCheckedChange:b}),o.jsx("label",{htmlFor:"one-hop-toggle",className:"text-sm text-muted-foreground cursor-pointer",children:e("graph.controls.oneHop")})]}),o.jsxs(z,{variant:"secondary",size:"sm",className:"h-9 gap-1.5",onClick:()=>{m(null),b(!1)},children:[o.jsx(Z,{className:"w-4 h-4"}),e("graph.controls.clearFocus")]})]}),o.jsx(z,{variant:"secondary",size:"icon",className:"h-9 w-9",onClick:pe,children:o.jsx(se,{className:"w-4 h-4"})}),o.jsx(z,{variant:"secondary",size:"icon",className:"h-9 w-9",onClick:ge,children:o.jsx(ie,{className:"w-4 h-4"})}),o.jsx(z,{variant:"secondary",size:"icon",className:"h-9 w-9",onClick:fe,children:o.jsx(de,{className:"w-4 h-4"})})]}),o.jsxs("div",{"data-graph-overlay":!0,className:"absolute bottom-4 left-4 z-10 flex flex-wrap items-center gap-3 px-3 py-2 bg-card/80 backdrop-blur rounded-lg border border-border/50 text-xs",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"hsl(var(--success))"}}),o.jsx("span",{className:"text-muted-foreground",children:e("graph.legend.available")})]}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"hsl(var(--primary))"}}),o.jsx("span",{className:"text-muted-foreground",children:e("graph.legend.planned")})]}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"hsl(var(--warning))"}}),o.jsx("span",{className:"text-muted-foreground",children:e("graph.legend.unapproved")})]}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:"hsl(var(--destructive))"}}),o.jsx("span",{className:"text-muted-foreground",children:e("graph.legend.notAvailable")})]})]}),_?o.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:o.jsx(ee,{className:"w-8 h-8 animate-spin text-primary"})}):E?o.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-6",children:o.jsxs("div",{className:"max-w-lg text-center",children:[o.jsx("div",{className:"w-24 h-24 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto mb-6",children:o.jsx(J,{className:"w-12 h-12 text-primary"})}),o.jsx("h3",{className:"text-xl font-medium text-foreground mb-2",children:e("graph.state.errorTitle")}),o.jsx("p",{className:"text-muted-foreground mb-4",children:E.message||e("graph.state.errorFallback")}),o.jsx(z,{variant:"secondary",onClick:me,children:e("graph.state.retry")})]})}):ve&&H.length>0?o.jsx("div",{className:"absolute inset-0",children:o.jsxs(L,{nodes:H,edges:Q,onNodesChange:X,onEdgesChange:te,onNodeClick:he,onNodeDoubleClick:ue,onInit:e=>{M.current=e,B(!0),setTimeout(()=>{ce({duration:200})},50)},nodeTypes:hn,edgeTypes:un,defaultEdgeOptions:pn,minZoom:.1,maxZoom:2,attributionPosition:"bottom-left",proOptions:{hideAttribution:!0},className:"w-full h-full",children:[o.jsx(S,{variant:F.Dots,gap:20,size:1,color:"hsl(var(--muted-foreground) / 0.2)"}),o.jsx(Ne,{nodeColor:e=>({available:"hsl(var(--success))",planned:"hsl(var(--primary))",unapproved:"hsl(var(--warning))",not_available:"hsl(var(--destructive))",not_set:"hsl(var(--muted-foreground))"}[e.data.availability||"not_set"]||"hsl(var(--muted-foreground))"),maskColor:"hsl(var(--background) / 0.8)",className:"!bg-card !border !border-border rounded-lg"})]})}):o.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:o.jsxs("div",{className:"text-center",children:[o.jsx("div",{className:"w-24 h-24 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto mb-6 animate-float",children:o.jsx(J,{className:"w-12 h-12 text-primary"})}),o.jsx("h3",{className:"text-xl font-medium text-foreground mb-2",children:e(ve?"graph.state.noMatchingConcepts":"graph.state.interactiveTitle")}),o.jsx("p",{className:"text-muted-foreground max-w-md",children:e(ve?"graph.state.adjustFiltersHint":"graph.state.noConceptsHint")})]})})]})]})]})}export{gn as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.