@mp70/react-networks 0.3.0-alpha.0 → 0.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import ot,{useState,useMemo,useRef,useEffect,useSyncExternalStore,Component,useCallback}from'react';import {useReactFlow,Handle,Position,getBezierPath,BaseEdge,EdgeLabelRenderer,useUpdateNodeInternals,useEdges,addEdge,ReactFlowProvider,useNodesState,useEdgesState,applyNodeChanges,useOnSelectionChange,ReactFlow,Background,Controls,MiniMap,Panel,applyEdgeChanges,ConnectionMode,getSmoothStepPath,SmoothStepEdge}from'reactflow';import {toPng}from'html-to-image';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var tt=20,vt=60,jr=300,Ho=5;function ni(e){return e==="system"?typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e}function ii(e,t){let r=ni(e)==="light"?"react-flow-light":"react-flow-dark";return t?`${r} ${t}`:r}function ai(e){return ni(e)==="light"?"#e5e5e5":"#2a2a2a"}function si(e,t){return {width:"100%",height:"100%",...t}}var ns=["device","server","switch","router"],is=new Set(ns);function Do(e){return typeof e=="string"&&is.has(e)}function Je(e){return !!e&&Do(e.type)}var as=24;function ss(e){return e?.rackLayout==="split-face"?"split-face":"single-face"}function $e(e){return ss(e)==="split-face"}function Ot(e){return typeof e?.rackFaceGapPx=="number"&&Number.isFinite(e.rackFaceGapPx)&&e.rackFaceGapPx>=0?e.rackFaceGapPx:as}function Lt(e){return e?.rackWidthPx||300}function _o(e){let t=Lt(e);return $e(e)?t*2+Ot(e):t}function Ve(e){return e?.mountMode==="front"||e?.mountMode==="rear"||e?.mountMode==="both"?e.mountMode:"both"}function Bt(e){return e==="front"?["front"]:e==="rear"?["rear"]:["front","rear"]}function Qo(e,t){let o=new Set(Bt(e));return Bt(t).some(n=>o.has(n))}function Yr(e,t){return $e(e)&&Ve(t)==="front"?Lt(e)+Ot(e):0}function di(e,t){return $e(e)&&Ve(t)==="both"?_o(e):Lt(e)}var ds=()=>"bottom-up",Yt=e=>e.data.uNumberingDirection||ds(),er=(e,t,o)=>o==="bottom-up"?t-e+1:e,tr=(e,t,o)=>o==="bottom-up"?t-e+1:e;var or=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data.uHeight||1,i=t.data.uHeight||42,d=Yt(t),a=60,c=o.y-a,l=Math.round(c/20)+1,b;d==="bottom-up"?b=er(l,i,d)-n+1:b=er(l,i,d);let f=i-n+1,u=Math.max(1,Math.min(f,b));if(d==="top-down"&&b<=1&&(u=1),!Kr(t,e,u,r)){let m=rr(t,e,r,u);m!==u&&(u=m);}let p;if(d==="bottom-up"){let m=u+n-1,x=tr(m,i,d);p=a+(x-1)*20-1;}else {let m=tr(u,i,d);p=a+(m-1)*20-1;}return {x:Yr(t.data,e.data),y:p,uPosition:u}},Kr=(e,t,o,r)=>{let n=t.data.uHeight||1,i=e.data.uHeight||42;if(o<1||o+n-1>i)return false;let d=r.filter(l=>Do(l.type)&&l.parentId===e.id&&l.id!==t.id),a=$e(e.data),c=Ve(t.data);for(let l of d){let b=l.data.uPosition||1,f=l.data.uHeight||1,u=o,p=o+n-1,m=b,x=b+f-1;if(u<=x&&p>=m){if(a){let P=Ve(l.data);if(!Qo(c,P))continue}return false}}return true},rr=(e,t,o,r=1)=>{let n=t.data.uHeight||1,i=e.data.uHeight||42;for(let d=r;d<=i-n+1;d++)if(Kr(e,t,d,o))return d;return 1},go=(e,t,o=1,r)=>{let n=60,i=Yt(e),d=e.data.uHeight||42,a=tr(t,d,i),c;if(i==="bottom-up"){let l=t+o-1,b=tr(l,d,i);c=n+(b-1)*20-1;}else c=n+(a-1)*20-1;return {x:Yr(e.data,r),y:c}},ci=(e,t,o)=>{let r=e.data.uHeight||1,n=go(t,o,r,e.data),i=Array.isArray(e.data.ports)?e.data.ports:void 0;return {...e,position:n,data:{...e.data,ports:i,uPosition:o}}},cs=(e,t)=>{let o=e.data.uPosition||1,r=e.data.uHeight||1,n=t.data.uHeight||42,i=Math.max(1,Math.min(n-r+1,o));return i!==o?ci(e,t,i):e};function mt(e){switch(e){case "active":return "#10b981";case "inactive":return "#ef4444";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var Zr=({data:e,selected:t,id:o,onViewChange:r,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:a=0,status:c="active",uHeight:l=42,face:b="front",customHeaderText:f}=e,u=$e(e),p=_o(e),m=Lt(e),x=Ot(e),{getNodes:P,setNodes:N}=useReactFlow(),v=P(),[C,F]=useState(e.showUMarkers!==void 0?e.showUMarkers:true),w=()=>{let A=Yt({data:e})==="bottom-up"?"top-down":"bottom-up";N(_=>_.map(U=>U.id===o?{...U,data:{...U.data,uNumberingDirection:A}}:U));},R=()=>{if(u)return;let E=b==="front"?"rear":"front";n?n(o,E):r?v.filter(_=>_.parentId===o).forEach(_=>{r(_.id,E);}):N(A=>A.map(_=>_.id===o?{..._,data:{..._.data,face:E}}:_.parentId===o?{..._,data:{..._.data,view:E}}:_));},D=()=>{let E=[],A=60,_=Yt({data:e});for(let U=1;U<=l;U++){let se=A+(U-1)*20-4,j=er(U,l,_);E.push(jsx("div",{style:{position:"absolute",left:"-35px",top:`${se}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${20}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:j},U));}return E};return jsxs("div",{className:`rack-node ${t?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${mt(c)}`,borderRadius:"8px",padding:0,width:`${p}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxs("span",{children:[typeof a=="number"?a:0," ports"]})," \u2022 ",l,"U \u2022 ",u?"rear|front":b]}),jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),F(!C);},style:{background:C?"#10b981":"#374151",color:C?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${C?"Hide":"Show"} U markers`,children:"U"}),jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),w();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch U numbering to ${Yt({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Yt({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),!u&&jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),R();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${b==="front"?"rear":"front"} view`,children:b==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"},children:u&&jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[jsx("div",{style:{width:`${m}px`,borderRight:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.15)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Rear"}),jsx("div",{style:{width:`${x}px`}}),jsx("div",{style:{width:`${m}px`,borderLeft:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.25)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Front"})]})}),C&&jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:D()})]})};var qr=({data:e,selected:t})=>{let{label:o,status:r="active"}=e;return jsxs("div",{className:`fiber-node ${t?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${mt(r)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsx(Handle,{type:"target",position:Position.Top}),jsx(Handle,{type:"source",position:Position.Bottom}),jsx(Handle,{type:"target",position:Position.Left}),jsx(Handle,{type:"source",position:Position.Right}),jsx("div",{style:{textAlign:"center"},children:jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:mt(r),borderRadius:"50%"}})]})};var li=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function Xe(e){let t=(e-1)%12;return li[t]}function Zt(e){return e>12}function Tt(e,t){let o=t?.base??Xe(e),r=t?.striped??Zt(e),n=r?`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`:void 0;return {base:o,striped:r,backgroundImage:n}}function Jr(e){let t=Tt(e);return t.backgroundImage?{background:t.base,backgroundImage:t.backgroundImage}:{background:t.base}}function qt(e){return Xe(e)}function Rt(e){return e.map(t=>({base:Xe(t),striped:Zt(t)}))}function gs(e,t,o,r,n,i,d,a){let c=Rt(o),l=c.length,b=r?1.2:1,f=!!a?.highlight,u=r?2:1.5,p=a?.highlightWidth??u*3,m=a?.highlightColor??c[0]?.base??"#22d3ee";return jsxs(Fragment,{children:[f&&jsx(BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:m,strokeWidth:p,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${u}px`,"--rn-edge-highlight-to":`${p}px`}}),c.map((x,P)=>{let v=(l-P)*b;return jsx("path",{d:t,stroke:x.base,strokeWidth:v,fill:"none",strokeLinecap:"butt",opacity:x.striped?.9:1,style:n},`${e}-ribbon-${P}`)}),c.some(x=>x.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&a&&(a.bandwidth||a.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${d}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[a.bandwidth&&jsx("div",{children:a.bandwidth}),a.length&&jsxs("div",{children:[a.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var ar=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},className:b})=>{let[f,u,p]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),{bandwidth:m,length:x,color:P="#00FFFF",striped:N=false,ribbonFiberIds:v,isRibbon:C,highlight:F,highlightColor:w,highlightWidth:R}=a||{},D=!!F;if((C||v&&v.length>=6&&v.length<=12)&&v)return gs(e,f,v,c??false,l??{},u,p,a);let A=c?3:2,_=R??A*3,U={...l,stroke:P,strokeWidth:A,strokeDasharray:"none"};return jsxs(Fragment,{children:[D&&jsx(BaseEdge,{id:`${e}-highlight`,path:f,style:{...l,stroke:w??P,strokeWidth:_,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${A}px`,"--rn-edge-highlight-to":`${_}px`}}),jsx(BaseEdge,{id:e,path:f,style:U}),N&&jsx(BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsx(EdgeLabelRenderer,{children:c&&a&&(m||x)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${u}px,${p}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${P}`,pointerEvents:"none",zIndex:9999},children:[m&&jsx("div",{children:m}),x&&jsxs("div",{children:[x,"m"]})]})})]})};var Qr=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,style:a={},data:c,markerEnd:l})=>{let[b]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),f=c?.connectorType||"C13",u=c?.metadata??{},p=typeof c?.powerStrokeWidth=="number"?c.powerStrokeWidth:typeof u.strokeWidth=="number"?u.strokeWidth:void 0,m=typeof c?.powerStrokeDasharray=="string"?c.powerStrokeDasharray:typeof u.strokeDasharray=="string"?u.strokeDasharray:void 0,x=typeof c?.powerOpacity=="number"?c.powerOpacity:typeof u.opacity=="number"?u.opacity:void 0;return jsx(BaseEdge,{id:e,path:b,markerEnd:l,style:(()=>{let v=p??(f==="C19"?5:3),C=m??(f==="C19"?"none":"6,3");return {...{stroke:c?.color||"#f59e0b",strokeWidth:v,strokeLinecap:"round",strokeLinejoin:"round",...x!==void 0?{opacity:x}:{}},strokeDasharray:C,...a}})()})};function xs(e,t,o,r,n,i,d,a,c,l,b){let f=Rt(a),u=f.length,p=c?1.8:1.5,m=!!b?.highlight,x=c?3:2.5,P=b?.highlightWidth??x*3,N=b?.highlightColor??f[0]?.base??"#22d3ee",[v,C,F]=getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d});return jsxs(Fragment,{children:[m&&jsx(BaseEdge,{id:`${e}-highlight`,path:v,style:{...l,stroke:N,strokeWidth:P,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${x}px`,"--rn-edge-highlight-to":`${P}px`}}),f.map((w,R)=>{let E=(u-R)*p;return jsx("path",{d:v,stroke:w.base,strokeWidth:E,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:l},`${e}-ribbon-${R}`)}),f.some(w=>w.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:c&&b&&(b.bandwidth||b.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${C}px,${F}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[b.bandwidth&&jsx("div",{children:b.bandwidth}),b.length&&jsxs("div",{children:[b.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[a.length,"F"]})]})})]})}var gi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},...b})=>{let{color:f="#00FFFF",ribbonFiberIds:u,isRibbon:p,highlight:m,highlightColor:x,highlightWidth:P}=a||{},N=!!m;if((p||u&&u.length>=6&&u.length<=12)&&u)return xs(e,t,o,r,n,i,d,u,c??false,l??{},a);let C=c?4:3,F=P??C*3,w={...l,stroke:f,strokeWidth:C};return jsxs(Fragment,{children:[N&&jsx(BaseEdge,{id:`${e}-highlight`,path:getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d})[0],style:{...l,stroke:x??f,strokeWidth:F,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${F}px`}}),jsx(SmoothStepEdge,{...b,id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:w})]})};function ks({sourceX:e,sourceY:t,targetX:o,targetY:r,sourcePosition:n,targetPosition:i}){let d=n===Position.Left||n===Position.Right,a;if(d){let c=(e+o)/2;a=`M ${e},${t} L ${c},${t} L ${c},${r} L ${o},${r}`;}else {let c=(t+r)/2;a=`M ${e},${t} L ${e},${c} L ${o},${c} L ${o},${r}`;}return a}function Ps(e,t,o,r,n,i){let d=Rt(o),a=d.length,c=r?1.2:1,l=!!i?.highlight,b=r?2:1.5,f=i?.highlightWidth??b*3,u=i?.highlightColor??d[0]?.base??"#22d3ee",p=t.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),m=p?(parseFloat(p[1])+parseFloat(p[3]))/2:0,x=p?(parseFloat(p[2])+parseFloat(p[4]))/2:0;return jsxs(Fragment,{children:[l&&jsx(BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:u,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${b}px`,"--rn-edge-highlight-to":`${f}px`}}),d.map((P,N)=>{let C=(a-N)*c;return jsx("path",{d:t,stroke:P.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:P.striped?.9:1,style:n},`${e}-ribbon-${N}`)}),d.some(P=>P.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&i&&(i.bandwidth||i.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${x}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${d[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsx("div",{children:i.bandwidth}),i.length&&jsxs("div",{children:[i.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var hi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},...b})=>{let{color:f="#00FFFF",striped:u=false,ribbonFiberIds:p,isRibbon:m,highlight:x,highlightColor:P,highlightWidth:N}=a||{},v=!!x,C=ks({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d});if((m||p&&p.length>=6&&p.length<=12)&&p)return Ps(e,C,p,c??false,l??{},a);let w=c?3:2,R=N??w*3,D={...l,stroke:f,strokeWidth:w,strokeDasharray:"none"};return jsxs(Fragment,{children:[v&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...l,stroke:P??f,strokeWidth:R,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${w}px`,"--rn-edge-highlight-to":`${R}px`}}),jsx(BaseEdge,{id:e,path:C,style:D}),u&&jsx(BaseEdge,{id:`${e}-stripe`,path:C,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var xi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,style:a={},data:c,markerEnd:l,selected:b})=>{let{color:f="#6366f1",label:u,highlight:p,highlightColor:m,highlightWidth:x}=c||{},P=!!p,N=8,v=x??N*1.8,[C,F,w]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),R={...a,stroke:f,strokeWidth:N,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxs(Fragment,{children:[P&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...a,stroke:m??f,strokeWidth:v,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${m??f}) drop-shadow(0 0 16px ${m??f})`,"--rn-edge-highlight-from":`${N}px`,"--rn-edge-highlight-to":`${v}px`}}),jsx(BaseEdge,{id:e,path:C,markerEnd:l,style:R}),u&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${w}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:u})})]})};var Ni=(o=>(o.FULL="full",o.HALF="half",o))(Ni||{});var tn={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},AC:{type:"AC",color:"#60a5fa",borderColor:"#2563eb",amperage:15,voltage:120,phases:1}};function eo(e){let t=tn[e];if(!t)throw new Error(`Unknown connector type: ${e}`);let o=t.amperage===16,r=t.type==="AC",n=o?12:r?10:8*1.3,i=o?10:r?7:5*1.3,d=o||r?{borderRadius:r?"2px":"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:i,color:t.color,borderColor:t.borderColor,fontSize:o?"3px":r?"3.5px":"4px",...d}}function ki(e){let t=tn[e];if(!t)throw new Error(`Unknown connector type: ${e}`);return t}function Ss(e){return ki(e).amperage===16}function dr(e){return e%10<8?"C13":"C19"}function Bo(e){let t=e.toLowerCase();return t.includes("mx304")||t.includes("mx480")||t.includes("mx960")?"C20":"C14"}var Es=/-(source|target)$/i;function Ge(e){return e?e.replace(Es,""):""}function St(e){return typeof e=="string"&&e.includes("power")}function Et(e,t){return typeof t.id=="string"&&t.id.length>0?t.id:St(t.type)?t.label:`${e}-${t.label}`}function cr(e){let t=Ge(e).toLowerCase();return t.startsWith("pwr")||t.includes("power")}var Fs="#6b7280",Hs="#374151",on="#10b981",Ds="100% 100%",_s={smf:"#fbbf24",cat6:"#8b5cf6",om3:"#06b6d4",om4:"#8b5cf6",om5:"#84cc16",cat5e:"#3b82f6",cat6a:"#ef4444",cat7:"#f97316",fiber:"#3b82f6",ethernet:"#10b981"},Ms=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,$s=/^data:image\//i,As=typeof window<"u"?ot.useLayoutEffect:ot.useEffect;function Ls(e){return (e??"").toLowerCase().replace(/_/g,"-")}function Bs(e){return !Ms.test(e)&&!e.startsWith("//")}function Os(e){if(!e)return;let t=e.trim();if(t){if(Bs(t))return t;try{let o=new URL(t),r=o.protocol.toLowerCase();return r==="https:"||r==="blob:"?o.href:r==="data:"&&$s.test(t)?t:void 0}catch{return}}}function Ws(e){return `url(${JSON.stringify(e)})`}function an(e){return St(e.type)}function rn(e,t){return Et(e,t)}function zs(e){return !!(e.position&&typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number")}function Us(e,t,o,r,n){let i=t.length>0||!!r,d=o.length>0||!!n;return e||(i?"front":d?"rear":"front")}function Vs(e,t){return t===true||e==="fill"?Ds:e==="none"?"auto":e==="scale-down"?"contain":e??"cover"}function Gs(e){return an(e)?e.type==="power_c19"?"#fbbf24":"#f59e0b":e.type==="console"||e.type==="mgmt"?"#8b5cf6":e.type==="usb"?on:e.cableType?_s[e.cableType]??on:on}function Xs(e){return e.connected?Gs(e):Fs}function Ci(e){return e.map(t=>{let o=t.ports.map(r=>{let n=r.position?[r.position.side??"",r.position.offsetPercent??"",r.position.offsetPx??"",r.position.xPercent??"",r.position.yPercent??""].join(":"):"";return [r.id??"",r.label,r.type??"",r.connected?"1":"0",r.cableType??"",r.connectorType??"",n].join(":")}).join(",");return `${t.name}[${o}]`}).join("|")}function js(e,t,o,r,n=false){return {width:`${e}px`,height:`${t}px`,minWidth:n?`${e}px`:void 0,minHeight:n?`${t}px`:void 0,background:o,border:`0.5px solid ${r}`,borderRadius:"1px",cursor:"pointer",zIndex:2}}function Ys(e){let t=Math.max(6,Math.min(10,Math.round(e*.025))),o=Math.max(3,Math.min(5,Math.round(t*.55)));return {width:t,height:o}}function nn(e){return Math.max(0,Math.min(100,e))}function yt(e,t,o){return Math.max(t,Math.min(o,e))}function Ks(e){switch(e){case "top":return Position.Top;case "right":return Position.Right;case "bottom":return Position.Bottom;case "left":return Position.Left;default:return Position.Top}}function Zs(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function qs(e,t,o,r,n,i){if(!e.position)return;if(typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number"){let m=nn(e.position.xPercent),x=nn(e.position.yPercent),P=e.position.side??Zs(m,x),N=yt(r*m/100,t/2,Math.max(t/2,r-t/2)),v=yt(i??n*x/100,o/2,Math.max(o/2,n-o/2));return {position:Ks(P),style:{left:`${N-t/2}px`,top:`${v-o/2}px`,right:void 0,bottom:void 0,transform:"none"}}}if(!e.position.side)return;let a=e.position.side,c=typeof e.position.offsetPercent=="number"?nn(e.position.offsetPercent):void 0,l=typeof e.position.offsetPx=="number"?e.position.offsetPx:void 0,b=t/2,f=Math.max(b,r-t/2),u=o/2,p=Math.max(u,n-o/2);switch(a){case "top":{let m=l!==void 0?l:r*(c??50)/100,x=yt(m,b,f);return {position:Position.Top,style:{top:"0px",left:`${x}px`,right:void 0,bottom:void 0,transform:"translate(-50%, 50%)"}}}case "bottom":{let m=l!==void 0?l:r*(c??50)/100,x=yt(m,b,f);return {position:Position.Bottom,style:{bottom:"0px",left:`${x}px`,right:void 0,top:void 0,transform:"translate(-50%, -50%)"}}}case "left":{let m=l!==void 0?l:n*(c??50)/100,x=yt(m,u,p);return {position:Position.Left,style:{left:"0px",top:`${x}px`,right:void 0,bottom:void 0,transform:"translate(50%, -50%)"}}}case "right":{let m=l!==void 0?l:n*(c??50)/100,x=yt(m,u,p);return {position:Position.Right,style:{right:"0px",top:`${x}px`,left:void 0,bottom:void 0,transform:"translate(-50%, -50%)"}}}default:return}}function Ti(e,t,o,r){let n=o/2,i=Math.max(n,r-o/2),d=n,a=i;if(t>1){let c=i-n,l=c/(t-1),b=t>=20?2:t>=12?3:void 0;if(b!==void 0){let f=o+b;if(l>f){let u=f*(t-1);if(u<c){let p=(c-u)/2;d=n+p,a=i-p;}}}}return t===1?(d+a)/2:d+e*(a-d)/(t-1)}function Ri(e,t,o,r){let n=e%2===0,i=Math.ceil(t/2),d=Math.floor(t/2),a=Math.max(n?i:d,1),c=Math.floor(n?e/2:(e-1)/2),l=Ti(c,a,o,r);return n?{position:Position.Top,style:{transform:"translateY(50%)",left:`${l-o/2}px`}}:{position:Position.Bottom,style:{transform:"translateY(-50%)",left:`${l-o/2}px`}}}function vi(e,t,o,r,n,i){let d=e%2===0,a=Math.ceil(t/2),c=Math.floor(t/2),l=Math.max(d?a:c,1),b=Math.floor(d?e/2:(e-1)/2),f=Ti(b,l,o,n),u=1,p=yt(Math.round(r*.75),1,4),m=Math.max(u,i-r-1),x=yt(u+r+p,u,m),P=d?u:x;return {position:Position.Top,style:{transform:"none",left:`${f-o/2}px`,top:`${P}px`,right:void 0,bottom:void 0}}}function Js(e,t,o,r,n){let i=e.connectorType??(e.type==="power_ac"?"AC":Bo(n)),d=eo(i),a;if(r<=20){let b=Math.max(2,r-d.height-2);a=`${o<=1?(2+b)/2:2+t*(b-2)/(o-1)}px`;}else a=`${25+t*50}%`;return {position:Position.Right,style:{transform:"translateX(-50%)",top:a,width:`${d.width}px`,height:`${d.height}px`,background:d.color,border:`1px solid ${d.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:d.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:d.borderRadius,clipPath:d.clipPath}}}function Qs(e,t,o,r){if(t===1){let n=Math.max(6,Math.round(r*.04)),i=Math.max(o/2,r-n-o/2);return {position:Position.Top,style:{transform:"translateY(50%)",left:`${i}px`,right:void 0}}}return Ri(e,t,o,r)}function ed(e,t,o,r,n,i,d,a,c){if(a==="patch-panel"||a==="switch")return Ri(t,o,r,i);if(an(e)){let f=e.connectorType??(e.type==="power_ac"?"AC":Bo(c)),u=eo(f),p;if(d<=20){let P=Math.max(2,d-u.height-2);p=`${o<=1?(2+P)/2:2+t*(P-2)/(o-1)}px`;}else p=`${25+t*50}%`;return {position:Position.Left,style:{transform:"translateX(50%)",top:p,width:`${u.width}px`,height:`${u.height}px`,background:u.color,border:`1px solid ${u.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:u.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:u.borderRadius,clipPath:u.clipPath}}}return {position:Position.Right,style:{transform:"translate(-50%, -50%)",top:`${yt(o<=1?d/2:n/2+t*Math.max(d-n,0)/Math.max(o-1,1),n/2,Math.max(n/2,d-n/2))}px`}}}function td(e,t,o,r){if(e)return {primary:"target"};let n=t==="patch-panel";return t==="switch"||t==="router"?{primary:"source",secondary:"target"}:n?o==="rear"?{primary:"source",secondary:"target"}:{primary:"target",secondary:"source"}:{primary:r?"source":"target"}}var mo=({id:e,data:t,selected:o})=>{let r=useUpdateNodeInternals(),{label:n,status:i="active",deviceType:d="server",manufacturer:a,uHeight:c=1,width:l="full",ports:b,rearPorts:f,view:u,rackWidthPx:p,frontImageUrl:m,rearImageUrl:x,imageFit:P,imagePosition:N,imageRepeat:v,stretchToFit:C}=t,F=ot.useMemo(()=>Array.isArray(b)?b:[],[b]),w=ot.useMemo(()=>Array.isArray(f)?f:[],[f]),R=Ls(d),D=p??300,E=$e(t),A=Ve(t),_=Us(u,F,w,m,x),U=ot.useMemo(()=>E?Bt(A):[_],[E,A,_]),se=U[0]??_,j=E&&A==="both",Y=c*20,ie=Ot(t),z=D+ie,V=ot.useMemo(()=>[E?"split":"single",A,U.join(","),se,R,n,Y.toString(),D.toString(),z.toString(),Ci(F),Ci(w)].join("|"),[E,A,U,se,R,n,Y,D,z,F,w]);As(()=>{r(e);},[V,e,r]);let B=ot.useCallback(fe=>{let _e=Os(fe==="rear"?x:m);return _e?{backgroundImage:Ws(_e),backgroundSize:Vs(P,C),backgroundPosition:N??"center",backgroundRepeat:v??"no-repeat"}:{}},[x,m,P,C,N,v]),O=ot.useMemo(()=>B("front"),[B]),X=ot.useMemo(()=>B("rear"),[B]),ee=se==="rear"?X:O,M,L;if(E)M=`${di(t,t)+4}px`,L=void 0;else {let fe=D+4,he=Math.floor(D/2);M=l==="half"?`${he}px`:`${fe}px`,L=l==="half"?`${he}px`:void 0;}let de=R==="server"&&c===1,ae=mt(i),ce={"--rn-device-bg-image":j?"none":String(ee.backgroundImage??"none"),"--rn-device-bg-position":String(ee.backgroundPosition??"center"),"--rn-device-bg-repeat":String(ee.backgroundRepeat??"no-repeat"),"--rn-device-bg-size":String(ee.backgroundSize??"cover"),"--rn-device-border-color":ae,"--rn-device-box-shadow":o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)","--rn-device-height":`${Y}px`,"--rn-device-left":L??"auto","--rn-device-status-color":ae,"--rn-device-translate-y":de?"-1px":"0px","--rn-device-width":M},q=ot.useMemo(()=>{let fe=new Set;for(let he of F)for(let _e of he.ports)fe.add(rn(he.name,_e));return fe},[F]),ve=ot.useCallback((fe,he)=>he==="rear"&&j&&q.has(fe)?`${fe}--rear`:fe,[q,j]),De=ot.useCallback((fe,he,_e)=>{let te=new Map;if(Y>24||he.length<=1)return te;let Ae=he.filter(Pe=>zs(Pe)&&Pe.position?.side==="top");if(Ae.length<=1)return te;let Re=[...new Set(Ae.map(Pe=>Number(Pe.position?.yPercent)))].filter(Pe=>Number.isFinite(Pe)).sort((Pe,Qe)=>Pe-Qe);if(Re.length<=1)return te;let dt=_e/2+1,Ne=Math.max(dt,Y-_e/2-1),Se=Math.max(0,Ne-dt),ke=Re.length,Nt=Math.max(_e+2,4),Ye=ke>1?Math.min(Nt,Se/(ke-1)):0,Te=Ye*Math.max(0,ke-1),ct=Ae.reduce((Pe,Qe)=>Pe+Y*Number(Qe.position?.yPercent)/100,0)/Ae.length,rt=yt(ct-Te/2,dt,Ne-Te),kt=new Map;Re.forEach((Pe,Qe)=>{kt.set(Pe,rt+Qe*Ye);});for(let Pe of Ae){let Qe=Number(Pe.position?.yPercent),nt=kt.get(Qe);nt!==void 0&&te.set(rn(fe,Pe),nt);}return te},[Y]),xe=ot.useCallback((fe,he,_e=0,te=D)=>{let Ae=[];if(fe.length===0)return Ae;let{width:Re,height:dt}=Ys(te),Ne=fe.reduce((ke,Nt)=>ke+Nt.ports.length,0),Se=(R==="switch"||R==="patch-panel")&&Ne>=24;for(let ke of fe){let Nt=De(ke.name,ke.ports,dt);for(let Ye=0;Ye<ke.ports.length;Ye+=1){let Te=ke.ports[Ye],ct=an(Te),rt=Re,kt=dt;if(ct){let Gt=Te.connectorType??(Te.type==="power_ac"?"AC":Bo(n)),Xt=eo(Gt);rt=Xt.width,kt=Xt.height;}let Pe=rn(ke.name,Te),Qe=Xs(Te),nt=Te.connected?Qe:Hs,Ko=Nt.has(Pe),Mr=js(rt,kt,Qe,nt,Ko),To=he==="front"?ct?Js(Te,Ye,ke.ports.length,Y,n):Se?vi(Ye,ke.ports.length,Re,dt,te,Y):Qs(Ye,ke.ports.length,Re,te):!ct&&Se?vi(Ye,ke.ports.length,Re,dt,te,Y):ed(Te,Ye,ke.ports.length,Re,dt,te,Y,R,n),Pt=qs(Te,rt,kt,te,Y,Nt.get(Pe)),_t=Pt?ct?{position:Pt.position,style:{...To.style,...Pt.style}}:Pt:To,ze={...{...Mr,..._t.style}};ze.left!==void 0&&_e!==0&&(typeof ze.left=="number"?ze.left=`${ze.left+_e}px`:ze.left=`calc(${ze.left} + ${_e}px)`),j&&ze.left===void 0&&(_t.position===Position.Left?(ze.left=`${_e}px`,ze.right=void 0):_t.position===Position.Right&&(ze.left=`${_e+te}px`,ze.right=void 0));let Mt=ve(Pe,he),ft=td(ct,R,he,Te.connected);if(ft.secondary){let Gt=R==="switch"||R==="router"?{...ze,background:"transparent",border:"none",opacity:0}:ze,Xt=R==="switch"||R==="router"?`${ke.name} - ${Te.label} (input) ${Te.connected?"(connected)":"(disconnected)"}`:`${ke.name} - ${Te.label} (${ft.secondary}) ${Te.connected?"(connected)":"(disconnected)"}`;Ae.push(jsx(Handle,{id:`${Mt}-${ft.secondary}`,type:ft.secondary,position:_t.position,style:Gt,title:Xt},`${Mt}-${ft.secondary}`));}Ae.push(jsx(Handle,{id:Mt,type:ft.primary,position:_t.position,style:ze,title:`${ke.name} - ${Te.label} ${Te.connected?"(connected)":"(disconnected)"}`,children:ct?Ye+1:void 0},Mt));}}return Ae},[De,Y,D,n,R,ve,j]),be=ot.useMemo(()=>{let fe=[];for(let he of U){if(he==="front"&&F.length>0){let _e=j?z:0;fe.push(...xe(F,"front",_e,D));}he==="rear"&&w.length>0&&fe.push(...xe(w,"rear",0,D));}return fe},[U,F,w,xe,D,j,z]);return jsxs("div",{className:`device-node ${o?"selected":""} ${j?"device-node--split-both":""}`,style:ce,children:[j&&jsxs("div",{className:"device-node__split-face-layer",style:{position:"absolute",inset:0,display:"flex",pointerEvents:"none",zIndex:0},children:[jsx("div",{className:"device-node__split-face device-node__split-face--rear",style:{width:`${D}px`,backgroundImage:String(X.backgroundImage??"none"),backgroundPosition:String(X.backgroundPosition??"center"),backgroundRepeat:String(X.backgroundRepeat??"no-repeat"),backgroundSize:String(X.backgroundSize??"cover")}}),jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${ie}px`},children:jsx("div",{className:"device-node__face-bridge-line"})}),jsx("div",{className:"device-node__split-face device-node__split-face--front",style:{width:`${D}px`,backgroundImage:String(O.backgroundImage??"none"),backgroundPosition:String(O.backgroundPosition??"center"),backgroundRepeat:String(O.backgroundRepeat??"no-repeat"),backgroundSize:String(O.backgroundSize??"cover")}})]}),jsxs("div",{className:"device-node__content",style:{position:"relative",zIndex:1},children:[jsx("div",{className:"device-node__label",children:n}),c>1&&jsx("div",{className:"device-node__manufacturer",children:a})]}),c>1&&jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),jsx("div",{className:"device-node__status-indicator"}),be]})};var at=20,ur=3,sn=2,od=1.2;function dn(e){return Math.max(0,Math.min(100,e))}function rd(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function pr(e){if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13")return "C13";if(t==="C19")return "C19";if(t==="AC")return "AC"}function nd(e,t){let o=pr(e.connectorType);if(o)return o;let r=String(e.type??"").toLowerCase();return r.includes("c19")?"C19":r.includes("c13")?"C13":r.includes("power_ac")?"AC":t}function id(e){return Array.isArray(e.pduPortGroups)&&e.pduPortGroups.length>0?e.pduPortGroups:Array.isArray(e.rearPorts)&&e.rearPorts.length>0?e.rearPorts:Array.isArray(e.ports)&&e.ports.length>0?e.ports:[]}function ad(e,t){return !Array.isArray(e.portTypes)||e.portTypes.length===0?Array.from({length:t},(o,r)=>pr(dr(r))??"C13"):Array.from({length:t},(o,r)=>{let n=pr(e.portTypes?.[r]);return n||(pr(dr(r))??"C13")})}function sd(e,t){let o=id(e),r=ad(e,t);if(o.length===0)return Array.from({length:t},(d,a)=>({id:`${a+1}`,label:`${a+1}`,connectorType:r[a]??"C13",groupName:"Power"}));let n=[],i=0;return o.forEach(d=>{d.ports.forEach(a=>{let c=r[i]??"C13";n.push({id:Et(d.name,a),label:a.label,connectorType:nd(a,c),groupName:d.name,position:a.position}),i+=1;});}),n}function dd(e,t){if(e.length===0)return [];let o=Math.max(t-sn-ur,1);if(e.length===1)return [at+sn+o/2];let r=[],n=0;for(let a=0;a<e.length;a+=1)r.push(n),n+=1,a<e.length-1&&e[a].groupName!==e[a+1].groupName&&(n+=od);let i=r[r.length-1]||1,d=i>0?o/i:0;return r.map(a=>at+sn+a*d)}function cd(e,t,o,r,n,i){if(!e)return {position:Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let d=e.side,a=d==="left"?Position.Left:d==="top"?Position.Top:d==="bottom"?Position.Bottom:Position.Right,c=typeof e.offsetPercent=="number"?dn(e.offsetPercent):void 0,l=typeof e.offsetPx=="number"?e.offsetPx:void 0,b=typeof e.xPercent=="number"?dn(e.xPercent):void 0,f=typeof e.yPercent=="number"?dn(e.yPercent):void 0;if(b!==void 0&&f!==void 0){let m=d??rd(b,f),x=m==="left"?Position.Left:m==="top"?Position.Top:m==="bottom"?Position.Bottom:Position.Right,P=Math.max(o-ur,1),N=r*b/100,v=at+P*f/100;return {position:x,leftPx:N-n/2,topPx:v-i/2}}let u=b!==void 0?r*b/100:r-n/2-1,p=f!==void 0?at+Math.max(o-ur,1)*f/100:t;return d==="top"||d==="bottom"?(l!==void 0?u=l:c!==void 0&&(u=r*c/100),p=d==="top"?at+i/2:at+o-i/2):(l!==void 0?p=at+l:c!==void 0&&(p=at+Math.max(o-ur,1)*c/100),d==="left"?u=n/2:d==="right"&&(u=r-n/2-1)),{position:a,leftPx:u-n/2,topPx:p-i/2}}function ld(e,t){return !e||t<=0?-1:e==="top"?0:e==="bottom"?t-1:Math.floor(t/2)}function ud(e,t){return jsxs("div",{style:{position:"absolute",left:`${(t-16)/2}px`,top:`${e-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsx(Handle,{type:"source",position:Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit")}var cn=({data:e,selected:t})=>{let{label:o,status:r="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:a}=e,c=Math.max(0,i),l=sd(e,c),b=n*4.2,f=Math.max(b-at,1),u=dd(l,f),p=ld(a,l.length);return jsxs("div",{className:`vertical-pdu-node ${t?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${mt(r)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${b}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:`${at}px`,display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${b-at}px`,overflow:"hidden"},children:l.map((m,x)=>{let P=u[x]??at+f/2;if(p===x)return ud(P,d);let N=eo(m.connectorType),v=cd(m.position,P,f,d,N.width,N.height);return jsx(Handle,{type:"source",position:v.position,id:m.id,style:{position:"absolute",left:`${v.leftPx}px`,top:`${v.topPx}px`,width:`${N.width}px`,height:`${N.height}px`,background:N.color,border:`1px solid ${N.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:N.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:N.borderRadius,clipPath:N.clipPath},title:`${m.groupName} - ${m.label} (${m.connectorType})`,children:m.label},`handle-${m.id}`)})})]})};var pn=({data:e,selected:t,id:o})=>{let{lossDb:r,mode:n="single",ribbonFiberIds:i}=e||{},d=useEdges(),a=d.find(w=>w.target===o&&w.targetHandle==="left"),c=d.find(w=>w.source===o&&w.sourceHandle==="right"),l=d.find(w=>w.target===o&&w.targetHandle==="right"),b=c||l,f=a?.data?.color||"#555",u=b?.data?.color||"#555",p=n==="ribbon",m=a?.data?.ribbonFiberIds||i,x=b?.data?.ribbonFiberIds||i,P=p&&m?Rt(m):null,N=p&&x?Rt(x):null,v=!!a&&!!b;return jsxs("div",{className:`splice-node ${t?"selected":""}`,style:{width:p?85:69,height:p?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"none"},children:[p&&P&&N?jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:P.map((w,R)=>jsx("div",{style:{flex:1,background:w.base,opacity:w.striped?.9:1}},`left-${R}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:N.map((w,R)=>jsx("div",{style:{flex:1,background:w.base,opacity:w.striped?.9:1}},`right-${R}`))})]}):jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsx("div",{style:{background:f}}),jsx("div",{style:{background:u}})]}),jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),v&&jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),v&&typeof r=="number"&&jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:p?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsx("div",{children:`${r.toFixed(2)} dB`}),p&&i&&jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsx(Handle,{type:"target",position:Position.Left,id:"left",isConnectable:true,style:{width:12,height:p&&P?20:12,borderRadius:p&&P?"6px":"50%",border:"none",background:p&&P?`linear-gradient(to bottom, ${P.map(w=>w.base).join(", ")})`:f,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsx(Handle,{type:"source",position:Position.Right,id:"right",isConnectable:true,style:{width:12,height:p&&N?20:12,borderRadius:p&&N?"6px":"50%",border:"none",background:p&&N?`linear-gradient(to bottom, ${N.map(w=>w.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsx(Handle,{type:"target",position:Position.Right,id:"right",isConnectable:true,style:{width:12,height:p&&N?20:12,borderRadius:p&&N?"6px":"50%",border:"none",background:p&&N?`linear-gradient(to bottom, ${N.map(w=>w.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var zo=20,fr=36;var to=32,Ii=4,zt=12,fd=69,oo=80,fn=(oo-fd)/2;var gn=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data?.mode==="ribbon",i=n?fr:zo,d=n?32:16,a=to,c=o.y-a,l=Math.round(c/i)+1,f=Math.max(1,Math.min(zt,l));if(!Wo(t,e,f,r)){let m=Uo(t,e,r,f);if(m!==f){let x=(i-d)/2;return {x:fn,y:a+(m-1)*i+x,holderPosition:m}}}let u=(i-d)/2,p=a+(f-1)*i+u;return {x:fn,y:p,holderPosition:f}},Wo=(e,t,o,r)=>!r.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==t.id).some(i=>i.data.holderPosition===o),Uo=(e,t,o,r=1)=>{for(let n=r;n<=zt;n++)if(Wo(e,t,n,o))return n;for(let n=r-1;n>=1;n--)if(Wo(e,t,n,o))return n;return 1},gd=(e,t)=>Vo(e,t,false),Vo=(e,t,o=false)=>{let r=to,n=o?fr:zo,d=(n-(o?32:16))/2,a=r+(t-1)*n+d;return {x:fn,y:a}};var hn=({data:e,selected:t})=>{let{label:o="Splice Tray"}=e||{},[r,n]=useState(false),i=()=>{if(!r)return null;let d=[],a=to;for(let c=1;c<=zt;c++){let l=a+(c-1)*zo;d.push(jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${zo}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxs("div",{className:`splice-tray-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${oo}px`,height:`${to+zt*fr+Ii}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${to}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!r);},style:{background:r?"#10b981":"#374151",color:r?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${r?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsx("div",{style:{position:"absolute",top:to,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var yn=({data:e,selected:t,id:o})=>{let{fibersPerTube:r=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=e?.mode==="ribbon"||e?.ribbon===true,a=useEdges(),c=`tube-${n}`,l=a.find(j=>j.source===o&&j.sourceHandle===c||j.target===o&&j.targetHandle===c),b=l?.data?.color,f=Xe((n-1)%12+1),u=b||f,p=Math.max(1,Math.min(24,Number(r)||12)),m=14,x=4,P=1,N=2,v=20,C=p*m+(p-1)*x,F=Math.max(60,C+P*2+N*2),w=i==="left"?Position.Left:i==="right"?Position.Right:Position.Bottom,R=w!==Position.Bottom,D=R?14:20,E=R?8:20,A=R?`inset ${w===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",_=l?u:R?`linear-gradient(${w===Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${u}`:`radial-gradient(circle, ${u} 40%, transparent 70%)`,U={width:D,height:E,borderRadius:R?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:_,backgroundColor:u,border:l?`2px solid ${u}`:`3px dashed ${u}`,cursor:"crosshair","--fiber-bg":u,boxShadow:l?A:`${A}${A!=="none"?", ":""}0 0 8px ${u}`,transition:"opacity 0.2s, box-shadow 0.2s",...w===Position.Left?{left:-(D-4)}:w===Position.Right?{right:-(D-4)}:{}},se=useMemo(()=>{let j=[],Y=F-N*2-P*2,ie,z,V=false;i==="left"?(ie=P,z=Position.Top):i==="right"?(ie=P+Y-C,z=Position.Top,V=true):(ie=P+(Y-C)/2,z=Position.Top);for(let B=0;B<p;B++){let O=V?p-B:B+1,X=`fiber-${O}`,ee=a.find(De=>De.source===o&&De.sourceHandle===X||De.target===o&&De.targetHandle===X),M=!!ee&&(ee.data?.isRibbon||ee.data?.ribbonFiberIds&&Array.isArray(ee.data.ribbonFiberIds)),L=ee?.data?.color,de=typeof ee?.data?.striped=="boolean"?ee.data.striped:void 0,ae=Tt(O);d||M?ae=Tt(O,{base:"#808080",striped:false}):(L||de!==void 0)&&(ae=Tt(O,{...L?{base:L}:{},...de!==void 0?{striped:de}:{}}));let ce=ie+B*(m+x),q=P,ve={position:"absolute",left:`${ce}px`,top:`${q}px`,width:m,height:m,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":ae.base,backgroundColor:ae.base};ae.backgroundImage&&(ve["--fiber-bg-image"]=ae.backgroundImage),j.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:ve,"data-fiber-idx":O,"data-fiber-color":ae.base}),jsx(Handle,{id:X,type:"source",position:z,className:"tube-fiber-handle",isConnectable:true,style:ve,"data-fiber-idx":O,"data-fiber-color":ae.base})]},`fiber-${O}`));}return j},[p,i,F,a,o,m,x,P,N,C,d]);return jsxs("div",{style:{width:F,height:v,borderRadius:4,background:"#111827",border:`${N}px solid ${t?"#3b82f6":u}`,position:"relative",boxShadow:t?`0 0 0 ${N}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:P,boxSizing:"border-box",overflow:"visible"},children:[se,jsx(Handle,{id:c,type:"target",position:w,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":u,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsx(Handle,{id:c,type:"source",position:w,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":u,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var Nn=({data:e,selected:t})=>{let{fiberCount:o,cableId:r="CBL-002",label:n,color:i,rotation:d}=e||{},a=ot.useRef(null);ot.useEffect(()=>{if(a.current){let z=typeof d=="number"?d:0;a.current.style.transform=`rotate(${z}deg)`,a.current.style.transformOrigin="center center";}},[d]);let c=Math.max(1,Math.min(24,Number(o)||12)),l=10,b=2,f=6,u=f+l+4,p=60,m=Math.max(120,c*(l+b)+f*2),P=n??`${c}f Cable`,N=r?`Cable ID ${r}`:void 0,v=Xe(1),C=i||v,F=t?"#3b82f6":C,w=typeof d=="number"?d:0,R=z=>{let V=(z%360+360)%360;return V>=315||V<45?Position.Top:V>=45&&V<135?Position.Right:V>=135&&V<225?Position.Bottom:Position.Left},D=()=>{let z=[],V=R(w);for(let B=0;B<c;B++){let O=B+1,X=Tt(O),ee=X.base,M=f+B*(l+b),L=-5,de=X.backgroundImage?X.backgroundImage:ee,ae={position:"absolute",left:`${M}px`,top:`${L}px`,width:l,height:l,borderRadius:"50%",border:"none",background:de,backgroundColor:ee,zIndex:10,cursor:"pointer","--fiber-bg":ee};X.backgroundImage&&(ae["--fiber-bg-image"]=X.backgroundImage);let ce=`fiber-${O}`;z.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:ce,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":ee}),jsx(Handle,{id:ce,type:"source",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":ee})]},`fiber-${O}`));}return z},E="cable-button",A=8,_={width:A,height:A,borderRadius:"50%",background:C,backgroundColor:C,border:`1px solid ${C}`,cursor:"pointer",zIndex:10},U=2,j=(z=>{let V=(z%360+360)%360;return V>=315||V<45?Position.Bottom:V>=45&&V<135?Position.Left:V>=135&&V<225?Position.Top:Position.Right})(w),Y={width:m,height:p,position:"relative",transform:`rotate(${w}deg)`,transformOrigin:"center center","--rotation":`${w}deg`},ie={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${U}px solid ${F}`,boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:f,paddingTop:u,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsx("div",{ref:a,style:Y,children:jsxs("div",{style:ie,children:[D(),jsx(Handle,{id:E,type:"source",position:j,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsx(Handle,{id:E,type:"target",position:j,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:P}),N&&jsx("div",{style:{fontSize:10,opacity:.8},children:N})]})]})})};var Pn=({data:e,selected:t})=>{let{tubeCount:o=12,fibersPerTube:r=12,fiberCount:n,cableId:i="CBL-002",label:d,tubeStartIndex:a=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(o)||12)),b=Math.max(1,Number(a)||1),f=14,u=10,p=3,m=6,x=m+u+4,P=60,N=Math.max(120,l*(f+p)+m*2),v=n??l*(Number(r)||12),C=d??`${v}f Cable`,F=i?`Cable ID ${i}`:void 0,w=Xe(b),R=c||w,D=t?"#3b82f6":R,E=()=>{let j=[];for(let Y=0;Y<l;Y++){let ie=b+Y,z=Tt(ie),V=z.base,B=m+Y*(f+p),O=-5,X=z.backgroundImage?z.backgroundImage:V,ee={position:"absolute",left:`${B}px`,top:`${O}px`,width:f,height:u,borderRadius:6,border:"none",background:X,backgroundColor:V,zIndex:10,cursor:"pointer","--fiber-bg":V};z.backgroundImage&&(ee["--fiber-bg-image"]=z.backgroundImage);let M=`tube-${ie}`;j.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:M,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:ee,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V}),jsx(Handle,{id:M,type:"source",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:ee,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V})]},`tube-${ie}`));}return j},A="cable-button",_=8,U={width:_,height:_,borderRadius:"50%",background:R,backgroundColor:R,border:`1px solid ${R}`,cursor:"pointer",zIndex:10};return jsxs("div",{style:{width:N,height:P,borderRadius:4,background:"#111827",border:`2px solid ${D}`,position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:m,paddingTop:x,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[E(),jsx(Handle,{id:A,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsx(Handle,{id:A,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:C}),F&&jsx("div",{style:{fontSize:10,opacity:.8},children:F})]})]})};var Cn=({data:e,selected:t,id:o})=>{let{connector:r="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:a}=e||{},c=useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,b=Math.max(1,Math.min(4,l)),f=9,u=3,p=3,m=60,x=30,P=b*f+(b-1)*u,N=Math.max(x,P+p*2),v=Math.max(m,80),C=(R,D)=>{let E=`${R}-${D+1}`;return c.find(_=>_.source===o&&_.sourceHandle===E||_.target===o&&_.targetHandle===E)?.data?.color||"#555"},F=R=>{let D=[],E=R==="left"?Position.Left:Position.Right,A=R==="left"?d:a;for(let _=0;_<b;_++){let U=_+1,se=`${R}-${U}`,j=C(R,_),z=p+(N-P)/2+_*(f+u),V={position:"absolute",left:R==="left"?-5:void 0,right:R==="right"?-5:void 0,top:`${z}px`,width:f,height:f,borderRadius:"50%",border:"none",background:j,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};D.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:se,type:"target",position:E,isConnectable:true,style:V}),jsx(Handle,{id:se,type:"source",position:E,isConnectable:true,style:V})]},se)),A&&A[_]&&D.push(jsx("div",{style:{position:"absolute",left:R==="left"?-30:void 0,right:R==="right"?-30:void 0,top:`${z}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:R==="left"?"right":"left",width:"25px"},children:A[_]},`${se}-label`));}return D},w=i||`${r}-${b}f`;return jsxs("div",{className:`coupler-node ${t?"selected":""}`,style:{width:v,height:N,borderRadius:4,border:`2px solid ${t?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${p}px`,boxSizing:"border-box"},children:[F("left"),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:w})}),F("right")]})};var io=32,Nr=30,kd=24,Pd=80,wr=400,xr=300,Li=2,no=8,Bi=120;function Tn(e){let{couplerFiberCount:t}=e.data||{},o=typeof t=="number"&&[1,2,4].includes(t)?t:2,r=Math.max(1,Math.min(4,o)),n=7,i=3,d=3,a=60,c=30,l=r*n+(r-1)*i,b=Math.max(c,l+d*2);return {width:Math.max(a,80),height:b}}function kr(e){let{fibersPerTube:t=12}=e.data||{},o=Math.max(1,Math.min(24,Number(t)||12)),r=14,n=4,i=1,d=2,a=20,c=o*r+(o-1)*n;return {width:Math.max(60,c+i*2+d*2),height:a}}function Oi(e){return {width:oo,height:0}}function Wi(e){return e.type==="coupler"?Tn(e):e.type==="tube"?kr(e):e.type==="splice-tray"?Oi():{width:80,height:30}}function vn(e){let t=0;for(let o of e){let r=Wi(o),n=(o.position?.x||0)+r.width;n>t&&(t=n);}return t}function zi(e,t=0){let o=t;for(let r of e){let n=Wi(r),i=(r.position?.y||0)+n.height;i>o&&(o=i);}return o}function Ui(e){return e.data?.panelWidth||wr}function Cd(e){return e.data?.panelHeight||xr}function Vi(e){return Ui(e)-Li*2-no*2}function vd(e,t){return Vi(e)-t}function Gi(e,t=Nr){return Math.floor(e/t)+1}function Xi(e,t=Nr){return (e-1)*t}function Td(e,t,o){let r=Nr,n=Gi(o.y,r),i=Xi(n,r);return {x:o.x,y:i,slotPosition:n}}function Rn(e,t){if(t.length===0)return {width:e.data?.panelWidth||wr,height:e.data?.panelHeight||xr};let o=t.some(c=>c.type==="tube"),r=t.some(c=>c.type==="splice-tray"),n=t.some(c=>c.type==="coupler"),i;if(o&&r&&n){let c=0,l=0;for(let u of t)if(u.type==="tube"){let p=kr(u);p.width>c&&(c=p.width);}else if(u.type==="coupler"){let p=Tn(u);p.width>l&&(l=p.width);}let b=c+Bi+oo+l+5,f=0;i=f+b+f;}else i=vn(t)+4;i=Math.max(e.data?.panelWidth||wr,i);let d=zi(t,io),a=Math.max(e.data?.panelHeight||xr,d+no);return {width:i,height:a}}function ji(e,t,o){if(e===0)return 0;if(e===1)return t;let r=e*t,n=o-r,i=Math.max(5,n/(e-1));return t+i}function Rd(e,t,o){return ji(e,t,o)}var Mi=20,$i=400,Ai=300;function Sn(e,t){if(t.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||$i,height:e.data?.closureHeight||e.data?.panelHeight||Ai};let o=t.some(a=>a.type==="tube"),r=t.some(a=>a.type==="splice-tray"),n;if(o&&r){let a=0,c=0,l=0,b=t.filter(u=>u.type==="tube"),f=t.filter(u=>u.type==="splice-tray");if(b.length>0&&f.length>0){let u=f.map(m=>m.position?.x||0),p=u.reduce((m,x)=>m+x,0)/u.length;for(let m of b){let x=kr(m);(m.position?.x||0)<p?x.width>a&&(a=x.width):x.width>c&&(c=x.width);}f.length>0&&(l=oo),n=no+a+Mi+l+Mi+c+5;}else n=vn(t)+no+5;}else n=vn(t)+no+5;n=Math.max(e.data?.closureWidth||e.data?.panelWidth||$i,n);let i=zi(t,io),d=Math.max(e.data?.closureHeight||e.data?.panelHeight||Ai,i+no);return {width:n,height:d}}var Fn=({data:e,selected:t,id:o})=>{let{label:r="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:a,setNodes:c}=useReactFlow(),l=useRef(false),b=useRef([]),f=useMemo(()=>{let C=a().filter(F=>F.parentId===o);return (C.length!==b.current.length||C.some((F,w)=>F.id!==b.current[w]?.id))&&(b.current=C),b.current},[a,o]),u=useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[o,e,i,d]),p=useMemo(()=>i&&d?{width:i,height:d}:f.length===0?{width:i||400,height:d||300}:Rn(u,f),[f,u,i,d]);useEffect(()=>{if(i&&d||l.current)return;let v=i,C=d,F=Math.abs((v||0)-p.width),w=Math.abs((C||0)-p.height);(F>1||w>1)&&(l.current=true,c(R=>R.map(D=>D.id===o?{...D,data:{...D.data,panelWidth:p.width,panelHeight:p.height}}:D)),setTimeout(()=>{l.current=false;},0));},[o,p.width,p.height,i,d,c]);let m=p.width,x=p.height,P=io,N=n||r;return jsxs("div",{className:`patch-panel-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${m}px`,height:`${x}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${P}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:N})}),jsx("div",{style:{position:"absolute",top:P,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var _n=({data:e,selected:t,id:o})=>{let{label:r="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:a,panelHeight:c}=e||{},{getNodes:l,setNodes:b}=useReactFlow(),f=useRef(false),u=useRef([]),p=useMemo(()=>{let R=l().filter(D=>D.parentId===o);return (R.length!==u.current.length||R.some((D,E)=>D.id!==u.current[E]?.id))&&(u.current=R),u.current},[l,o]),m=useMemo(()=>({id:o,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||a,closureHeight:d||c}}),[o,e,i,d,a,c]),x=useMemo(()=>i&&d?{width:i,height:d}:a&&c?{width:a,height:c}:p.length===0?{width:i||a||400,height:d||c||300}:Sn(m,p),[p,m,i,d,a,c]);useEffect(()=>{if(i&&d||a&&c||f.current)return;let w=i||a,R=d||c,D=Math.abs((w||0)-x.width),E=Math.abs((R||0)-x.height);(D>1||E>1)&&(f.current=true,b(A=>A.map(_=>_.id===o?{..._,data:{..._.data,closureWidth:x.width,closureHeight:x.height}}:_)),setTimeout(()=>{f.current=false;},0));},[o,x.width,x.height,i,d,a,c,b]);let P=x.width,N=x.height,v=io,C=n||r,F=P/2;return jsxs("div",{className:`closure-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${F}px ${F}px 12px 12px`,padding:0,width:`${P}px`,height:`${N}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${v}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${F}px ${F}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:C})}),jsx("div",{style:{position:"absolute",top:v,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var $n=({data:e,selected:t,id:o})=>{let{label:r,splitterType:n="splitter",inputCount:i=1,outputCount:d=8}=e||{},a=useEdges(),c=r||(n==="WDM"?"WDM":"Splitter"),l=9,b=3,f=3,u=50,p=30,m=Math.min(Math.max(i||1,1),2),x=m*l+(m-1)*b,P=Math.min(d||8,48),N=P*l+(P-1)*b,v=Math.max(x,N),C=Math.max(p,v+f*2),F=Math.max(u,50),w=Y=>a.find(z=>z.source===o&&z.sourceHandle===Y||z.target===o&&z.targetHandle===Y)?.data?.color||"#555",R=()=>{let Y=[],ie=f+(C-x)/2;for(let z=0;z<m;z++){let V=`input-${z+1}`,B=ie+z*(l+b),O=w(V),X={position:"absolute",left:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};Y.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Left,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position:Position.Left,isConnectable:true,style:X})]},V));}return Y},D=()=>{let Y=[],ie=f+(C-N)/2;for(let z=0;z<P;z++){let V=`output-${z+1}`,B=ie+z*(l+b),O=w(V),X={position:"absolute",right:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};Y.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Right,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position:Position.Right,isConnectable:true,style:X})]},V));}return Y},E=Math.max(x+f*4,p*.6),A=(C-E)/2,_=A+E,U=0,se=C,j=t?"#3b82f6":"#4b5563";return jsxs("div",{className:`trapezoid-node ${t?"selected":""}`,style:{width:F,height:C,position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${f}px`,boxSizing:"border-box"},children:[jsx("svg",{width:F,height:C,viewBox:`0 0 ${F} ${C}`,style:{position:"absolute",top:0,left:0,width:`${F}px`,height:`${C}px`,pointerEvents:"none",zIndex:0},children:jsx("polygon",{points:`0,${A} 0,${_} ${F},${se} ${F},${U}`,fill:"#1f2937",stroke:j,strokeWidth:"2"})}),R(),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:c})}),D()]})};var qi=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",vr=(e,t)=>qi(e)||qi(t),re=(e,t)=>t?e?.type==="fibre-split"?Ge(t):Ge(t):t||"";function Tr(e,t){if(!e||!t)return "unknown";let o=Ge(t);if(!o)return "unknown";if(e.type==="vertical-pdu")return "power";let r=e.data??{},n=Array.isArray(r.ports)?r.ports:[],i=Array.isArray(r.rearPorts)?r.rearPorts:[];for(let l of [...n,...i])for(let b of l.ports||[])if(Et(l.name,{id:b.id,label:b.label,type:St(b.type)?b.type:void 0})===o)return St(b.type)?"power":"network";if(cr(o)||/^\d+$/.test(o))return "power";let d=o.toLowerCase(),a=d.startsWith("net-")||d.startsWith("port-")||d.startsWith("uplink-")||d.includes("fiber")||d.includes("ports"),c=/^[A-Z0-9]+-\d+$/i.test(o)&&!d.startsWith("pwr")&&!d.startsWith("power");return a||c?"network":"unknown"}function ao(e,t){return Tr(e,t)==="power"}function Md(e,t){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=t.nodes.find(M=>M.id===e.source),r=t.nodes.find(M=>M.id===e.target),n=vr(o,r);if(!n){let M=Tr(o,e.sourceHandle),L=Tr(r,e.targetHandle);if(M!=="unknown"&&L!=="unknown"&&M!==L)return {valid:false,reason:`Cannot connect ${M} handle to ${L} handle`};let de=M==="power"&&L==="power",ae=o?.type==="vertical-pdu"||r?.type==="vertical-pdu";if(de&&!ae)return {valid:false,reason:"Power connections must include a PDU endpoint"}}let i=re(o,e.sourceHandle),d=re(r,e.targetHandle),a=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.source===e.source?re(o,M.sourceHandle)===i:M.target===e.source?re(o,M.targetHandle)===i:false),c=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.target===e.target?re(r,M.targetHandle)===d:M.source===e.target?re(r,M.sourceHandle)===d:false);if((a||c)&&!n)return a?{valid:false,reason:`Source handle ${e.sourceHandle} on node ${e.source} is already connected`}:{valid:false,reason:`Target handle ${e.targetHandle} on node ${e.target} is already connected`};let l=(M,L)=>(M?.type==="tube"||M?.type==="cable")&&!!L&&L.startsWith("fiber-"),b=(M,L)=>(M?.type==="tube"||M?.type==="multi-tube-cable")&&!!L&&L.startsWith("tube-"),f=(M,L)=>M?.type==="multi-tube-cable"&&!!L&&L.startsWith("tube-"),u=(M,L)=>M?.type==="tube"&&!!L&&L.startsWith("tube-"),p=(M,L)=>(M?.type==="cable"||M?.type==="multi-tube-cable")&&L==="cable-button",m=(M,L)=>M?.type==="splice"&&(L==="left"||L==="right"),x=(M,L)=>M?.type==="coupler"&&!!L&&(L.startsWith("left-")||L.startsWith("right-")),P=(M,L)=>{if(M?.type!=="fibre-split"||!L)return false;let de=re(M,L);return de.startsWith("input-")||de.startsWith("output-")};if(!n)return {valid:true};if(o?.type==="splice"&&r?.type==="splice"){let M=o.data?.mode==="ribbon",L=r.data?.mode==="ribbon";if(M!==L)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let N=l(o,e.sourceHandle),v=l(r,e.targetHandle),C=m(o,e.sourceHandle),F=m(r,e.targetHandle),w=x(o,e.sourceHandle),R=x(r,e.targetHandle),D=P(o,e.sourceHandle),E=P(r,e.targetHandle),A=p(o,e.sourceHandle),_=p(r,e.targetHandle),U=f(o,e.sourceHandle),se=f(r,e.targetHandle),j=u(o,e.sourceHandle),Y=u(r,e.targetHandle),ie=b(o,e.sourceHandle),z=b(r,e.targetHandle);return N&&F||v&&C||(C&&(R||E)||F&&(w||D))||(w&&(R||E||F)||R&&(w||D||C))||A&&_||(U&&Y||se&&j)?{valid:true}:ie&&z?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function Rr(e,t){if(!t)return;let o="--rear",r=Ge(e),n=r.endsWith(o);n&&(r=r.slice(0,-o.length));let i=t.data??{},d=i.handleSideMap;if(d&&d[r])return d[r];if(n)return "rear";if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let a=Array.isArray(i.ports)?i.ports:[],c=Array.isArray(i.rearPorts)?i.rearPorts:[];if(cr(r))return "rear";for(let l of a)for(let b of l.ports||[])if(Et(l.name,{id:b.id,label:b.label,type:St(b.type)?b.type:void 0})===r)return "front";for(let l of c)for(let b of l.ports||[])if(Et(l.name,{id:b.id,label:b.label,type:St(b.type)?b.type:void 0})===r)return "rear"}function An(e={},t={}){let o={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},r=new Set;return {getState:()=>o,setState:f=>{o={...o,...f},r.forEach(u=>u(o));},subscribe:f=>(r.add(f),()=>r.delete(f)),selectEdgeZIndex:f=>{let u=N=>{if(typeof N.parentId=="string")return N.parentId;let v=N.parentNode;if(typeof v=="string")return v},p=N=>{let v=u(N),C=v?o.nodes.find(D=>D.id===v&&D.type==="rack"):void 0;if(C&&$e(C.data))return Bt(Ve(N.data));let F=Array.isArray(N.data?.rearPorts)&&N.data.rearPorts.length>0,w=Array.isArray(N.data?.ports)&&N.data.ports.length>0;return [N.data?.view||(F&&!w?"rear":"front")]},m=(N,v)=>{let C=o.nodes.find(Y=>Y.id===N);if(!(!!C&&(C.type==="device"||C.type==="server"||C.type==="switch"||C.type==="router"))||!C||C.data?.deviceType?.toLowerCase().replace(/_/g,"-")==="patch-panel")return;let R=p(C),D=Rr(v||"",C);if(D)return R.includes(D)?1e3:500;let E=(v||"").toString().replace(/-(source|target)$/i,""),A=E.toLowerCase(),_=A.startsWith("pwr")||A.startsWith("power"),U=A.startsWith("net-")||A.startsWith("port-")||A.startsWith("uplink-")||A.includes("fiber")||A.includes("ports"),se=/^[A-Z0-9]+-\d+$/i.test(E)&&!A.startsWith("pwr")&&!A.startsWith("power"),j=U||se;if(_)return R.includes("rear")?1e3:500;if(j)return R.includes("front")?1e3:500},x=m(f.target,f.targetHandle);if(x!==void 0)return x;let P=m(f.source,f.sourceHandle);return P!==void 0?P:1e3},validateConnection:f=>(t.validateConnection||Md)(f,o),selectNodeById:f=>o.nodes.find(u=>u.id===f),selectConnectedEdges:f=>o.edges.filter(u=>u.source===f||u.target===f)}}function $d(e){let t=n=>e.subscribe(i=>n()),o=()=>e.getState();return useSyncExternalStore(t,o,o)}function Bn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return useSyncExternalStore(t,o,o)}function On(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return useSyncExternalStore(t,o,o)}function Ji(e){return e.selectEdgeZIndex}function Qi(e){let t=_o(e.data),o=60+(e.data.uHeight||42)*20,r=e.position.x,n=e.position.x+t,i=e.position.y,d=e.position.y+o;return {left:r,right:n,top:i,bottom:d}}function ea(e,t){let o=Qi(t);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function Sr(e,t){let o=null,r=1/0;for(let n of t){if(!ea(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<r&&(r=i,o=n);}return o}function Oe(e){let{edges:t,connection:o,edgeType:r,selectEdgeZIndex:n,findBy:i,matchOn:d=i,data:a}=e,c=i==="source"?o.sourceHandle:o.targetHandle,l=i==="source"?o.source:o.target;if(!c||!l)return null;let b=Ge(c),f=t.find(N=>d==="source"?N.source===l&&Ge(N.sourceHandle)===b:N.target===l&&Ge(N.targetHandle)===b);if(!f)return null;let u=t.filter(N=>N.id!==f.id),p=addEdge(o,u),m=p[p.length-1],x=n({...o,id:m.id,type:r}),P={...m,type:r,zIndex:x,style:{...m.style,zIndex:x},data:a!==void 0?a:m.data};return [...p.slice(0,-1),P]}function ta(e){return Array.isArray(e)?e.reduce((t,o)=>t+(Array.isArray(o.ports)?o.ports.length:0),0):0}function oa(e){return typeof e=="string"&&e.trim().length>0}function Ld(e){let t=ta(e.ports)>0||oa(e.frontImageUrl),o=ta(e.rearPorts)>0||oa(e.rearImageUrl);if(t&&o)return "both";if(t)return "front";if(o)return "rear"}function ra(e,t,o,r){let n=e.mountMode;if(n==="front"||n==="rear"||n==="both")return n;let i=Ld(e);if(i)return i;if(e.view==="front"||e.view==="rear")return e.view;let d=o+r/2;return t>=d?"front":"rear"}function aa(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var je=({type:e,children:t})=>{let o=ot.useRef(null),r=ot.useCallback(n=>{if(o.current=n,n){let i=n.parentElement,d=0;for(;i&&!i.classList.contains("react-flow__node")&&d<10;)i=i.parentElement,d++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return ot.useEffect(()=>{if(o.current){let n=o.current.parentElement,i=0;for(;n&&!n.classList.contains("react-flow__node")&&i<10;)n=n.parentElement,i++;n&&n.classList.contains("react-flow__node")&&n.setAttribute("data-type",e);}},[e]),jsx("div",{ref:r,style:{width:"100%",height:"100%"},children:t})},sa=(e,t,o)=>({rack:r=>jsx(je,{type:"rack",children:jsx(Zr,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsx(je,{type:"fiber",children:jsx(qr,{...r})}),device:r=>jsx(je,{type:"device",children:jsx(mo,{...r})}),server:r=>jsx(je,{type:"server",children:jsx(mo,{...r})}),switch:r=>jsx(je,{type:"switch",children:jsx(mo,{...r})}),router:r=>jsx(je,{type:"router",children:jsx(mo,{...r})}),"vertical-pdu":r=>jsx(je,{type:"vertical-pdu",children:jsx(cn,{...r})}),splice:r=>jsx(je,{type:"splice",children:jsx(pn,{...r})}),"splice-tray":r=>jsx(je,{type:"splice-tray",children:jsx(hn,{...r})}),tube:r=>jsx(je,{type:"tube",children:jsx(yn,{...r})}),cable:r=>jsx(je,{type:"cable",children:jsx(Nn,{...r})}),"multi-tube-cable":r=>jsx(je,{type:"multi-tube-cable",children:jsx(Pn,{...r})}),coupler:r=>jsx(je,{type:"coupler",children:jsx(Cn,{...r})}),"patch-panel":r=>jsx(je,{type:"patch-panel",children:jsx(Fn,{...r})}),closure:r=>jsx(je,{type:"closure",children:jsx(_n,{...r})}),"fibre-split":r=>jsx(je,{type:"fibre-split",children:jsx($n,{...r})})});function da(e){if(!e)return false;if(e.type==="switch")return true;if(e.type!=="device")return false;let t=e.data?.deviceType;return typeof t=="string"&&t.toLowerCase().replace(/_/g,"-")==="switch"}function ca(e,t,o){let r=e.sourceHandle,n=e.targetHandle;return da(t)&&r&&!ao(t,r)&&(r=Ge(r)),da(o)&&n&&!ao(o,n)&&(n=`${Ge(n)}-target`),r===e.sourceHandle&&n===e.targetHandle?e:{...e,sourceHandle:r,targetHandle:n}}var qd={fiber:ar,ethernet:ar,power:Qr,smoothstep:gi,step:hi,"thick-cable":xi},Jd=8192,Qd=8192,ec=2048,tc=4;function Xo(e,t,o){if(!(typeof e!="number"||Number.isNaN(e)))return Math.min(o,Math.max(t,e))}function oc(e){if(e)return {...e,width:Xo(e.width,1,Jd),height:Xo(e.height,1,Qd),padding:Xo(e.padding,0,ec),pixelRatio:Xo(e.pixelRatio,.1,tc),quality:Xo(e.quality,0,1)}}var rc=({nodes:e,edges:t,initialNodes:o,initialEdges:r,onNodesChange:n,onEdgesChange:i,store:d,debug:a,onNodeClick:c,onEdgeClick:l,nodeTypes:b,edgeTypes:f,onConnect:u,onEdgeUpdate:p,isValidConnection:m,connectionMode:x,onViewChange:P,onRackFaceChange:N,className:v,style:C,alignRacksToBottom:F,reAssignable:w=true,colorMode:R="dark",onInit:D,onFlowMethods:E,showDownloadButton:A=false,downloadButtonPosition:_="top-right",downloadButtonText:U="Download Image",downloadButtonStyle:se,useSmoothstepEdgesForTubes:j=false,readOnly:Y=false,interaction:ie,actionPanel:z,connectOnClick:V=true,panOnDrag:B=true,panOnScroll:O=true,zoomOnScroll:X=true,fitViewOptions:ee})=>{let M=useCallback((s,g)=>{let y=new Map,h=[],T=[],I=(H,$)=>!H||!$?false:!!(H.startsWith("tube-")||$.type==="splice"&&(H==="left"||H==="right")||H==="cable-button");for(let H of s){if(!H.source||!H.target||!H.sourceHandle||!H.targetHandle){a&&console.warn("Invalid edge skipped (missing source/target/handles):",H);continue}let $=g.find(et=>et.id===H.source),S=g.find(et=>et.id===H.target),K=`${H.source}:${H.sourceHandle}`,oe=y.get(K),Ee=I(H.sourceHandle,$),Ie=`${H.target}:${H.targetHandle}`,Fe=y.get(Ie),Ze=I(H.targetHandle,S);if(oe&&!Ee){a&&console.warn("Duplicate connection detected on source handle, removing:",{handle:K,existingEdge:oe.id,duplicateEdge:H.id}),T.push(H);continue}if(Fe&&!Ze){a&&console.warn("Duplicate connection detected on target handle, removing:",{handle:Ie,existingEdge:Fe.id,duplicateEdge:H.id}),T.push(H);continue}h.push(H),oe||y.set(K,H),Fe||y.set(Ie,H);}return a&&T.length>0&&console.log(`Filtered ${T.length} duplicate edge(s) from initial edges`),h},[a]),L=Array.isArray(e)&&Array.isArray(t),de=ot.useMemo(()=>L?e||[]:o||e||[],[L,e,o]),ae=ot.useMemo(()=>L?t||[]:r||t||[],[L,t,r]),ce=ot.useMemo(()=>M(ae,de),[ae,de,M]),q=ot.useMemo(()=>d||An({nodes:de,edges:ce,debug:a}),[d,L,a,ce]),ve=Bn(q),De=On(q),[xe,be]=useNodesState(ve),[fe,he,_e]=useEdgesState(De),te=Ji(q),Ae=useRef(null),[Re,dt]=useState(false);useEffect(()=>{let s=()=>{dt(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[]);let Ne=Y===true,Se=useMemo(()=>{let g={...{nodesDraggable:true,nodesConnectable:true,elementsSelectable:!Re,edgesFocusable:!Re,edgesReconnectable:true,connectOnClick:V,panOnDrag:B,panOnScroll:O&&!Re,zoomOnScroll:X&&!Re,zoomOnPinch:!Re,zoomOnDoubleClick:!Re,allowKeyboardDelete:true,showControls:true,showMiniMap:!Re,showInteractiveControl:true},...ie??{}};return Ne?{...g,nodesDraggable:false,nodesConnectable:false,elementsSelectable:false,edgesFocusable:false,edgesReconnectable:false,connectOnClick:false,panOnDrag:false,panOnScroll:false,zoomOnScroll:false,zoomOnPinch:false,zoomOnDoubleClick:false,allowKeyboardDelete:false,showInteractiveControl:false}:g},[Re,V,B,O,X,ie,Ne]),ke=useMemo(()=>({enabled:z?.enabled??true,showRearToggle:z?.showRearToggle??true,showDeRack:z?.showDeRack??true}),[z]),{toObject:Nt,setViewport:Ye,setNodes:Te,setEdges:ct,getNodes:rt,getEdges:kt,fitView:Pe,flowToScreenPosition:Qe}=useReactFlow();useEffect(()=>{E&&E({toObject:()=>Nt(),setViewport:Ye,setNodes:s=>{Te(s),q.setState({nodes:s});},setEdges:s=>{ct(s),q.setState({edges:s});},toImage:s=>Ae.current?toPng(Ae.current,oc(s)):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>rt(),getEdges:()=>kt(),fitView:s=>{if(s?.nodes&&Array.isArray(s.nodes)&&s.nodes.length>0){let g=s.nodes.map(T=>rt().find(I=>I.id===T)).filter(T=>T!==void 0),{nodes:y,...h}=s;Pe({...h,nodes:g});}else {let{nodes:g,...y}=s||{};Pe(y);}}});},[E,Nt,Ye,Te,ct,q,Pe,rt,kt]);let[nt,Ko]=useState(false),Mr=useCallback(()=>{if(!nt){if(!Ae.current){a&&console.error("ReactFlow wrapper ref is not available");return}Ko(true),toPng(Ae.current,{filter:s=>!(s?.classList?.contains("react-flow__minimap")||s?.classList?.contains("react-flow__controls")||s?.classList?.contains("react-flow__attribution")||s?.classList?.contains("download-button")||s?.tagName==="BUTTON"),backgroundColor:R==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(s=>{let g=document.createElement("a");g.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,g.href=s,g.click();}).catch(s=>{a&&console.error("Error downloading image:",s);}).finally(()=>{Ko(false);});}},[R,a,nt]),[To,Pt]=useState(null),_t=useRef(null),$r=useRef(P),ze=useRef(N);useEffect(()=>{$r.current=P;},[P]),useEffect(()=>{ze.current=N;},[N]),useEffect(()=>{_t.current=To;},[To]);let Mt=useCallback((s,g)=>{$r.current?.(s,g);},[]),ft=useCallback((s,g)=>{ze.current?.(s,g);},[]),Gt=useCallback(()=>_t.current,[]),Xt=useRef({...sa(Mt,ft,Gt),...b??{}});useEffect(()=>{Xt.current={...sa(Mt,ft,Gt),...b??{}};},[Mt,ft,Gt,b]);let Ba=useMemo(()=>({...qd,...f??{}}),[f]),gt=useRef(xe);useEffect(()=>{gt.current=xe;},[xe]);let J=useRef(fe);useEffect(()=>{J.current=fe;},[fe]),useEffect(()=>{be(ve);},[ve,be]),useEffect(()=>{he(De);},[De,he]),useEffect(()=>{if(L&&t){let s=M(t,e||[]);s.length!==t.length&&(a&&console.warn(`Controlled edges had ${t.length-s.length} duplicate(s) removed`),i?.(s));}},[L,t,e,M,i,a]),useEffect(()=>{L&&q.setState({nodes:e||[]});},[L,e,q]),useEffect(()=>{L&&q.setState({edges:t||[]});},[L,t,q]),useEffect(()=>{if(!F||!xe||xe.length===0)return;let s=xe.filter(S=>S.type==="rack");if(s.length===0)return;let g=s.map(S=>{let oe=S.data?.uHeight||42,Ee=60+oe*20;return (S.position?.y||0)+Ee}),y=Math.min(...g),h=Math.max(...g);if(h-y<20)return;let I=h,H=xe.map(S=>{if(S.type!=="rack")return S;let oe=S.data?.uHeight||42,Ee=60+oe*20,Ie=(S.position?.y||0)+Ee,Fe=I-Ie;return Math.abs(Fe)<5?S:{...S,position:{x:S.position?.x||0,y:(S.position?.y||0)+Fe}}});H.some((S,K)=>S.position!==xe[K].position)&&be(H);},[F,xe,be]);let Ro=useRef(new Map);useEffect(()=>{let s=new Map;xe.forEach(g=>{s.set(g.id,g);}),Ro.current=s;},[xe]);let le=useCallback(s=>Ro.current.get(s),[]),Ke=useCallback(s=>{if(!s)return;if(typeof s.parentId=="string")return s.parentId;let g=s.parentNode;if(typeof g=="string")return g},[]),Kn=useCallback(s=>{let g=Ke(s);if(!g)return;let y=le(g);if(!(!y||y.type!=="rack"))return y},[le,Ke]),Zn=useCallback(s=>!s||s.type!=="rack"?false:$e(s.data),[]),lo=useCallback(s=>{if(!s||!Je(s))return false;let g=Kn(s);return g?$e(g.data):false},[Kn]),Ar=useCallback(s=>{if(!s||s.type!=="device")return false;let g=s.data?.deviceType;return typeof g=="string"&&g.toLowerCase().replace(/_/g,"-")==="patch-panel"},[]),Zo=useCallback(s=>{gt.current=s;let g=new Map;s.forEach(y=>{g.set(y.id,y);}),Ro.current=g,be(s),L?n?.(s):q.setState({nodes:s});},[L,q,be,n]),we=useCallback(s=>{J.current=s,he(s),L?i?.(s):q.setState({edges:s});},[L,q,he,i]),$t=useCallback(s=>{if(s.positionAbsolute)return s.positionAbsolute;let g=s.position?.x||0,y=s.position?.y||0,h=Ke(s),T=new Set;for(;h&&!T.has(h);){T.add(h);let I=le(h);if(!I)break;if(I.positionAbsolute){g+=I.positionAbsolute.x,y+=I.positionAbsolute.y;break}g+=I.position?.x||0,y+=I.position?.y||0,h=Ke(I);}return {x:g,y}},[le,Ke]),qo=useCallback(s=>{let g=$t(s),y=s.width||0,h=s.height||0;return {x:g.x+y/2,y:g.y+h/2}},[$t]),So=useCallback((s,g)=>{if(!s||!g)return;let y=le(s);if(!y)return;let h=g.replace(/-(source|target)$/i,"");if(y.type==="fibre-split"&&h.startsWith("output-")){let I=J.current.filter(H=>H.target===s&&(H.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(I.length>0){let H=I[0]?.data?.color;if(H)return {color:H}}}if((y.type==="tube"||y.type==="cable")&&g.startsWith("fiber-")){let I=g.replace("fiber-",""),H=parseInt(I,10);if(H>=1&&H<=24){let $=qt(H),S=H>12;return {color:$,striped:S}}}if((y.type==="multi-tube-cable"||y.type==="tube")&&g.startsWith("tube-")){let I=g.replace("tube-",""),H=parseInt(I,10);if(H>=1&&H<=24){let $=Xe(H),S=H>12;return {color:$,striped:S}}}let T=y.data;if(T.color)return {color:T.color}},[le]),qn=useRef(new Map);useEffect(()=>{he(s=>{let g=false,y=s.map(h=>{let T=te(h);return qn.current.get(h.id)!==T?(g=true,qn.current.set(h.id,T),{...h,zIndex:T,style:{...h.style,zIndex:T}}):h});return g?y:s});},[xe,he,te]),useEffect(()=>{let s=xe.map(y=>{if(y.type==="coupler"&&y.parentId){let h=le(y.parentId);if(h&&(h.type==="patch-panel"||h.type==="closure")&&(!y.extent||y.extent!=="parent"))return {...y,extent:"parent"}}if(y.type==="splice"&&y.parentId&&y.data.holderPosition&&(!y.position||y.position.x===0&&y.position.y===0)){let h=le(y.parentId);if(h&&h.type==="splice-tray"){let T=y.data.mode==="ribbon",I=Vo(h,y.data.holderPosition,T);return {...y,position:I}}}if(Je(y)&&y.parentId&&y.data.uPosition&&(!y.position||y.position.x===0&&y.position.y===0)){let h=le(y.parentId);if(h){let T=y.data.uHeight||1,I=go(h,y.data.uPosition,T,y.data);return {...y,position:I}}}return y});s.some((y,h)=>{let T=xe[h];return y.extent!==T.extent||y.position?.x!==T.position?.x||y.position?.y!==T.position?.y})&&be(s);},[xe,be,le]);let Oa=useCallback(s=>{if(Ne)return null;let g=new Map,y=new Map,h=new Set,T=s.map($=>{if($.type==="position"&&$.position){let S=le($.id);if(S&&S.type==="coupler"&&S.parentId){let K=le(S.parentId);if(K&&(K.type==="patch-panel"||K.type==="closure"))return (!S.extent||S.extent!=="parent")&&h.add(S.id),{...$,position:S.position||{x:0,y:0}}}if(S&&(S.type==="tube"||S.type==="splice-tray")&&S.parentId){let K=le(S.parentId);if(K&&K.type==="closure")return (!S.extent||S.extent!=="parent")&&h.add(S.id),{...$,position:S.position||{x:0,y:0}}}if(S&&S.type==="splice"&&S.parentId){let K=le(S.parentId);if(K&&K.type==="splice-tray"){let oe=gn(S,K,$.position,gt.current);return oe.holderPosition!==void 0&&g.set(S.id,oe.holderPosition),{...$,position:{x:oe.x,y:oe.y}}}}if(S&&Je(S)&&S.parentId){let K=le(S.parentId);if(K&&K.type==="rack"){let oe=or(S,K,$.position,gt.current);return oe.uPosition!==void 0&&y.set(S.id,oe.uPosition),{...$,position:{x:oe.x,y:oe.y}}}}}return $}),I=applyNodeChanges(T,gt.current).map($=>{let S=$;h.has($.id)&&(S={...S,extent:"parent"});let K=g.get($.id);K!==void 0&&(S={...S,data:{...S.data,holderPosition:K}});let oe=y.get($.id);return oe!==void 0&&(S={...S,data:{...S.data,uPosition:oe}}),S});gt.current=I;let H=new Map;return I.forEach($=>{H.set($.id,$);}),Ro.current=H,be(I),I},[be,le,Ne]),Wa=useCallback((s,g)=>{Pt(null);},[]),za=useCallback((s,g,y)=>{let h=Ke(g);if(!w||!Je(g)||h){Pt(null);return}let T=gt.current.filter(S=>S.type==="rack").map(S=>S),I=qo(g),$=Sr(I,T)?.id??null;Pt(S=>S===$?S:$);},[w,qo,Ke]),Ua=useCallback((s,g,y)=>{Pt(null);let h=Ke(g);if(!w||!Je(g)||h)return;let T=$t(g),I=gt.current.filter(W=>W.type==="rack").map(W=>W),H=qo(g),$=Sr(H,I),S=gt.current;if(!$)return;let K={x:T.x-$.position.x,y:T.y-$.position.y},oe=S.find(W=>W.id===g.id)||g,Ee=$e($.data),Ie=Lt($.data),Fe=Ot($.data),Ze=Ee?ra(oe.data,K.x,Ie,Fe):"both",et=Ee&&Ze==="front"?Ie+Fe:0,Le=Ze==="rear"?"rear":Ze==="front"?"front":oe.data.view==="front"||oe.data.view==="rear"?oe.data.view:void 0,qe={...oe,parentId:$.id,extent:"parent",position:{x:et,y:K.y},data:{...oe.data,rackLayout:Ee?"split-face":"single-face",rackWidthPx:Ie,rackFaceGapPx:Fe,mountMode:Ze,view:Le}},Ue=S.filter(W=>W.id!==g.id).concat(qe),Ce=or(qe,$,qe.position,Ue),it=S.map(W=>W.id!==g.id?W:{...W,parentId:$.id,extent:"parent",position:{x:Ce.x,y:Ce.y},data:{...W.data,rackLayout:Ee?"split-face":"single-face",rackWidthPx:Ie,rackFaceGapPx:Fe,mountMode:Ze,view:Le,uPosition:Ce.uPosition??W.data.uPosition}});Zo(it);},[w,$t,qo,Zo,Ke]),Va=useCallback(s=>{if(!s.source||!s.target||!s.sourceHandle||!s.targetHandle)return true;let g=le(s.source),y=le(s.target),h=re(g,s.sourceHandle),T=re(y,s.targetHandle),I=J.current.some(Z=>Z.source===s.source?re(g,Z.sourceHandle)===h:Z.target===s.source?re(g,Z.targetHandle)===h:false),H=J.current.some(Z=>Z.target===s.target?re(y,Z.targetHandle)===T:Z.source===s.target?re(y,Z.sourceHandle)===T:false);if(I&&a&&console.log("Connection will replace: Source handle already connected",{source:s.source,sourceHandle:s.sourceHandle,existingEdges:J.current.filter(Z=>Z.source===s.source&&Z.sourceHandle===s.sourceHandle||Z.target===s.source&&Z.targetHandle===s.sourceHandle)}),H&&a&&console.log("Connection will replace: Target handle already connected",{target:s.target,targetHandle:s.targetHandle,existingEdges:J.current.filter(Z=>Z.target===s.target&&Z.targetHandle===s.targetHandle||Z.source===s.target&&Z.sourceHandle===s.targetHandle)}),!vr(g,y))return true;if(g?.type==="splice"&&y?.type==="splice"){let Z=g.data?.mode==="ribbon",ge=y.data?.mode==="ribbon";if(Z!==ge)return a&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",s),false}let S=(Z,ge)=>(Z?.type==="tube"||Z?.type==="cable")&&!!ge&&ge.startsWith("fiber-"),K=(Z,ge)=>(Z?.type==="tube"||Z?.type==="multi-tube-cable")&&!!ge&&ge.startsWith("tube-"),oe=(Z,ge)=>Z?.type==="multi-tube-cable"&&!!ge&&ge.startsWith("tube-"),Ee=(Z,ge)=>Z?.type==="tube"&&!!ge&&ge.startsWith("tube-"),Ie=(Z,ge)=>(Z?.type==="cable"||Z?.type==="multi-tube-cable")&&ge==="cable-button",Fe=(Z,ge)=>Z?.type==="splice"&&(ge==="left"||ge==="right"),Ze=(Z,ge)=>Z?.type==="coupler"&&!!ge&&(ge.startsWith("left-")||ge.startsWith("right-")),et=(Z,ge)=>{if(Z?.type!=="fibre-split"||!ge)return false;let k=ge.replace(/-(source|target)$/i,"");return k.startsWith("input-")||k.startsWith("output-")},Le=S(g,s.sourceHandle),qe=S(y,s.targetHandle),Ue=Fe(g,s.sourceHandle),Ce=Fe(y,s.targetHandle),it=Ze(g,s.sourceHandle),W=Ze(y,s.targetHandle),He=et(g,s.sourceHandle),ne=et(y,s.targetHandle),Io=Ie(g,s.sourceHandle),Wr=Ie(y,s.targetHandle),po=oe(g,s.sourceHandle),fo=oe(y,s.targetHandle),zr=Ee(g,s.sourceHandle),Ur=Ee(y,s.targetHandle),Jo=K(g,s.sourceHandle),Vr=K(y,s.targetHandle);return Le&&Ce||qe&&Ue||(Ue&&(W||ne)||Ce&&(it||He))||(it&&(W||ne||Ce)||W&&(it||He||Ue))||Io&&Wr||(po&&Ur||fo&&zr)?true:Jo&&Vr?(a&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",s),false):(a&&console.log("Connection rejected: Connection not allowed by fiber rules",s),false)},[le,a]),Ga=useCallback(s=>{if(Ne)return;a&&console.log("onConnect called:",s);let g=le(s.source),y=le(s.target);a&&(console.log("onConnect: sourceNode type:",g?.type,"targetNode type:",y?.type),console.log("onConnect: sourceHandle:",s.sourceHandle,"targetHandle:",s.targetHandle));let h=ca(s,g,y),T=q.validateConnection({source:h.source??null,target:h.target??null,sourceHandle:h.sourceHandle,targetHandle:h.targetHandle});if(!T.valid&&!(T.reason??"").includes("already connected")){a&&console.warn(`Connection rejected: ${T.reason}`);return}let I=g?.type==="vertical-pdu",H=g?.type==="vertical-pdu"||y?.type==="vertical-pdu",$=ao(g,h.sourceHandle),S=ao(y,h.targetHandle),K=$&&S&&H,oe=g?.data,Ee=g?.type==="switch"||g?.type==="device"&&oe?.deviceType==="switch",Ie=S,Fe=!!h.targetHandle&&(h.targetHandle.startsWith("net-")||h.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Ge(h.targetHandle))),Ze=!!h.sourceHandle&&(h.sourceHandle.startsWith("net-")||h.sourceHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Ge(h.sourceHandle))),et=y?.type==="switch"||y?.type==="device"&&y.data?.deviceType==="switch",Le=y?.type==="vertical-pdu",qe=$,Ue=g?.type==="tube"&&y?.type==="multi-tube-cable",Ce=g?.type==="multi-tube-cable"&&y?.type==="tube",it=Ue||Ce,W=h.sourceHandle==="cable-button"&&h.targetHandle==="cable-button",He="fiber";K?He="power":W?He="thick-cable":it&&(He=j?"smoothstep":"fiber");let ne,Io=aa(y),Wr=aa(g);if(Io||Wr){let k=y?.data,G=g?.data,ye=Io?k.ribbonFiberIds:G.ribbonFiberIds;ye&&Array.isArray(ye)&&ye.length>=6&&ye.length<=12&&(ne={ribbonFiberIds:ye,isRibbon:true});}if(!ne&&(He==="fiber"||He==="smoothstep")&&!I){let k;Ue?k=So(h.target,h.targetHandle):k=So(h.source,h.sourceHandle),k&&(ne={color:k.color,striped:k.striped,isRibbon:false});}else if(He==="thick-cable"&&W){let k=g?.data;ne={color:k?.color||(k?.tubeStartIndex?Xe(k.tubeStartIndex):"#6366f1")};}let po=re(g,h.sourceHandle),fo=re(y,h.targetHandle),zr=J.current.some(k=>k.source===h.source?re(g,k.sourceHandle)===po:k.target===h.source?re(g,k.targetHandle)===po:false),Ur=J.current.some(k=>k.target===h.target?re(y,k.targetHandle)===fo:k.source===h.target?re(y,k.sourceHandle)===fo:false);if(zr||Ur){let k=new Set;for(let G of J.current){if(G.source===h.source&&re(g,G.sourceHandle)===po){k.add(G.id);continue}if(G.target===h.source&&re(g,G.targetHandle)===po){k.add(G.id);continue}if(G.source===h.target&&re(y,G.sourceHandle)===fo){k.add(G.id);continue}G.target===h.target&&re(y,G.targetHandle)===fo&&k.add(G.id);}if(k.size>0){let G=J.current.filter(bt=>!k.has(bt.id)),ye=addEdge(h,G);if(ye.length===G.length)a&&console.warn("Handle replacement skipped: addEdge did not create a new edge",h);else {let bt=ye[ye.length-1],At=te({...h,id:bt.id,type:He}),jt={...bt,type:He,zIndex:At,style:{...bt.style,zIndex:At},data:ne!==void 0?ne:bt.data};we([...ye.slice(0,-1),jt]),a&&console.log("Handle replacement: Replaced",k.size,"edge(s)");return}}}if(y?.type==="splice"&&(s.targetHandle==="left"||s.targetHandle==="right")&&s.target&&s.targetHandle){let k=J.current.find(G=>G.target===s.target&&G.targetHandle===s.targetHandle||G.source===s.target&&G.sourceHandle===s.targetHandle);if(k){a&&(console.log("Splice target handle replacement: Found existing edge",k.id,"on splice handle",s.targetHandle),console.log("Existing edge details:",{id:k.id,source:k.source,target:k.target,sourceHandle:k.sourceHandle,targetHandle:k.targetHandle,data:k.data}));let G=s.source&&s.sourceHandle?J.current.find(Ct=>Ct.source===s.source&&Ct.sourceHandle===s.sourceHandle):null;a&&G&&console.log("Splice target handle replacement: Also found existing source edge",G.id);let ye=new Set;k&&ye.add(k.id),G&&G.id!==k.id&&ye.add(G.id);let bt=J.current.filter(Ct=>!ye.has(Ct.id));a&&console.log("Splice target handle replacement: Removing",ye.size,"edge(s), creating new connection");let At=`edge-${s.source}-${s.sourceHandle}-${s.target}-${s.targetHandle}-${Date.now()}`,jt=te({...s,id:At,type:"fiber"}),Fo={id:At,source:s.source,target:s.target,sourceHandle:s.sourceHandle,targetHandle:s.targetHandle,type:"fiber",zIndex:jt,style:{zIndex:jt},data:ne!==void 0?ne:{}},Xr=[...bt,Fo];we(Xr),a&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Fo.id);return}}if(g?.type==="splice"&&s.sourceHandle==="right"&&s.source&&s.sourceHandle){let k=J.current.find(G=>G.source===s.source&&G.sourceHandle===s.sourceHandle||G.target===s.source&&G.targetHandle===s.sourceHandle);if(k){a&&console.log("Splice source handle replacement: Found existing edge",k.id,"on splice handle",s.sourceHandle);let G=s.target&&s.targetHandle?J.current.find(Ct=>Ct.target===s.target&&Ct.targetHandle===s.targetHandle):null;a&&G&&console.log("Splice source handle replacement: Also found existing target edge",G.id);let ye=new Set;k&&ye.add(k.id),G&&G.id!==k.id&&ye.add(G.id);let bt=J.current.filter(Ct=>!ye.has(Ct.id));a&&console.log("Splice source handle replacement: Removing",ye.size,"edge(s), creating new connection");let At=`edge-${s.source}-${s.sourceHandle}-${s.target}-${s.targetHandle}-${Date.now()}`,jt=te({...s,id:At,type:"fiber"}),Fo={id:At,source:s.source,target:s.target,sourceHandle:s.sourceHandle,targetHandle:s.targetHandle,type:"fiber",zIndex:jt,style:{zIndex:jt},data:ne!==void 0?ne:{}},Xr=[...bt,Fo];we(Xr),a&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Fo.id);return}}if((g?.type==="tube"||g?.type==="cable")&&s.sourceHandle?.startsWith("fiber-")&&s.source&&s.sourceHandle){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"source",data:ne});if(k){we(k);return}}if((y?.type==="tube"||y?.type==="cable")&&s.targetHandle?.startsWith("fiber-")&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"target",data:ne});if(k){we(k);return}}if((g?.type==="multi-tube-cable"||g?.type==="tube")&&s.sourceHandle?.startsWith("tube-")&&s.source&&s.sourceHandle){let k=Oe({edges:J.current,connection:h,edgeType:He,selectEdgeZIndex:te,findBy:"source",data:ne});if(k){we(k);return}}if((y?.type==="multi-tube-cable"||y?.type==="tube")&&s.targetHandle?.startsWith("tube-")&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:He,selectEdgeZIndex:te,findBy:"target",data:ne});if(k){we(k);return}}if(g?.type==="coupler"&&(s.sourceHandle?.startsWith("left-")||s.sourceHandle?.startsWith("right-"))){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"source",data:ne});if(k){we(k);return}}if(y?.type==="coupler"&&(s.targetHandle?.startsWith("left-")||s.targetHandle?.startsWith("right-"))){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"target",data:ne});if(k){we(k);return}}if(W&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let k=g?.data,G=k?.color||(k?.tubeStartIndex?Xe(k.tubeStartIndex):"#6366f1"),ye=Oe({edges:J.current,connection:h,edgeType:"thick-cable",selectEdgeZIndex:te,findBy:"source",data:{color:G}});if(ye){we(ye);return}if(ye=Oe({edges:J.current,connection:h,edgeType:"thick-cable",selectEdgeZIndex:te,findBy:"target",data:{color:G}}),ye){we(ye);return}}if(I&&Ie&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:te,findBy:"target",data:ne});if(k){we(k);return}}if(Le&&qe&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:te,findBy:"source",matchOn:"target",data:ne});if(k){we(k);return}}if(Ee&&Fe&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"target",data:ne});if(k){we(k);return}}if(et&&Ze&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"target",matchOn:"source",data:ne});if(k){we(k);return}}let Jo=q.validateConnection({source:h.source??null,target:h.target??null,sourceHandle:h.sourceHandle,targetHandle:h.targetHandle});if(!Jo.valid){if(I&&s.source&&s.sourceHandle){let k=Oe({edges:J.current,connection:h,edgeType:Ie?"power":"fiber",selectEdgeZIndex:te,findBy:"source",data:ne});if(k){we(k);return}}if(Le&&s.source&&s.sourceHandle){let k=Oe({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:te,findBy:"source",matchOn:"target",data:ne});if(k){we(k);return}}if(Ee&&s.source&&s.sourceHandle){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"source",data:ne});if(k){we(k);return}}if(et&&s.target&&s.targetHandle){let k=Oe({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:te,findBy:"target",matchOn:"source",data:ne});if(k){we(k);return}}a&&console.warn(`Connection rejected: ${Jo.reason}`);return}let Vr=J.current.some(k=>k.source===h.source&&k.sourceHandle===h.sourceHandle||k.target===h.source&&k.targetHandle===h.sourceHandle),ei=J.current.some(k=>k.target===h.target&&k.targetHandle===h.targetHandle||k.source===h.target&&k.sourceHandle===h.targetHandle),Gr=(k,G)=>!k||!G?false:!!(k.startsWith("tube-")||G.type==="splice"&&(k==="left"||k==="right")||k==="cable-button"),ti=Gr(h.sourceHandle||"",g),oi=Gr(h.targetHandle||"",y);if(Vr&&!ti){a&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:s.source,sourceHandle:h.sourceHandle,existingEdges:J.current.filter(k=>k.source===h.source&&k.sourceHandle===h.sourceHandle||k.target===h.source&&k.targetHandle===h.sourceHandle)});return}if(ei&&!oi){a&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:h.target,targetHandle:h.targetHandle,existingEdges:J.current.filter(k=>k.target===h.target&&k.targetHandle===h.targetHandle||k.source===h.target&&k.sourceHandle===h.targetHandle)});return}let ri={...h,type:He,zIndex:te({...h,id:"temp-id"}),data:ne},Z=addEdge(ri,J.current),ge=Z[Z.length-1];ge&&(Qn(k=>new Set(k).add(ge.id)),setTimeout(()=>{Qn(k=>{let G=new Set(k);return G.delete(ge.id),G});},1e3)),we(Z);},[we,q,te,le,a,So,j,Ne]),Xa=useCallback((s,g)=>{if(Ne||!g.source||!g.target||!g.sourceHandle||!g.targetHandle)return;let y=le(g.source),h=le(g.target),T=ca(g,y,h),I=re(y,T.sourceHandle),H=re(h,T.targetHandle),$=J.current.some(W=>{if(W.id===s.id)return false;let He=W.source===T.source&&re(y,W.sourceHandle)===I||W.target===T.source&&re(y,W.targetHandle)===I,ne=W.target===T.target&&re(h,W.targetHandle)===H||W.source===T.target&&re(h,W.sourceHandle)===H;return He||ne}),S=q.validateConnection({source:T.source??null,target:T.target??null,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,ignoreEdgeId:s.id});if(!S.valid&&!((S.reason??"").includes("already connected")&&$)){a&&console.warn(`Edge update rejected: ${S.reason}`);return}let K=y?.type==="vertical-pdu"||h?.type==="vertical-pdu",oe=ao(y,T.sourceHandle),Ee=ao(h,T.targetHandle),Ie=oe&&Ee&&K,Fe=y?.type==="tube"&&h?.type==="multi-tube-cable",Ze=y?.type==="multi-tube-cable"&&h?.type==="tube",et=Fe||Ze,Le;Ie?Le="power":et?Le=j?"smoothstep":"fiber":Le="fiber";let qe;if(Le==="fiber"||Le==="smoothstep"){let W=So(T.source,T.sourceHandle);W&&(qe={color:W.color,striped:W.striped});}let it=J.current.filter(W=>{if(W.id===s.id)return true;let He=W.source===T.source&&re(y,W.sourceHandle)===I||W.target===T.source&&re(y,W.targetHandle)===I,ne=W.target===T.target&&re(h,W.targetHandle)===H||W.source===T.target&&re(h,W.sourceHandle)===H;return !(He||ne)}).map(W=>W.id===s.id?{...W,source:T.source,target:T.target,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,type:Le,data:qe!==void 0?{...W.data,...qe}:W.data,zIndex:te({...T,id:W.id,type:Le}),style:{...W.style,zIndex:te({...T,id:W.id,type:Le})}}:W);we(it);},[we,le,So,te,j,a,q,Ne]),ja=useCallback((s,g)=>{if(Re){c&&c(g);return}let y=s.metaKey||s.ctrlKey,h=rt(),T=g,I=Ke(g);if(g.type==="tube"&&I&&!y){let H=h.find($=>$.id===I&&($.type==="cable"||$.type==="multi-tube-cable"));H&&(T=H);}if(Lr(T),Eo([]),be(H=>H.map($=>{let S=$.id===T.id;return $.selected===S?$:{...$,selected:S}})),y&&Je(T)&&!lo(T)){let H=T.data||{},$=H.view||(Array.isArray(H.rearPorts)&&H.rearPorts.length>0?"rear":"front"),S=$==="front"?"rear":"front";a&&console.log(`Command+click: Toggling device ${T.id} from ${$} to ${S}`),P&&P(T.id,S);}c&&c(T);},[P,c,a,rt,be,Re,Ke,lo]),Ya=useCallback(()=>{},[]),Ka=useCallback((s,g)=>{Lr(null),Eo([g]),be(y=>y.map(h=>h.selected?{...h,selected:false}:h)),c?.(null),l&&l(g);},[l,c,be]),Za=useCallback(()=>{Lr(null),Eo([]),be(s=>s.map(g=>g.selected?{...g,selected:false}:g)),c?.(null);},[c,be]),[lt,Lr]=useState(null),[Jn,Qn]=useState(new Set);useOnSelectionChange({onChange:({edges:s})=>{Eo(s||[]);}});let[Br,Eo]=useState([]);useEffect(()=>{let s=g=>{if(Se.allowKeyboardDelete&&(g.key==="Backspace"||g.key==="Delete")&&Br.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let y=Br.filter(h=>{let T=h.sourceHandle||"",I=h.targetHandle||"";return T.startsWith("tube-")||I.startsWith("tube-")?(a&&console.log("Cannot delete edge connected to tube handle",h),false):true});if(y.length>0){let h=new Set(y.map(I=>I.id)),T=J.current.filter(I=>!h.has(I.id));we(T),Eo([]),a&&console.log("Deleted edges:",y.map(I=>I.id));}}};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[Br,we,a,Se.allowKeyboardDelete]);let qa=useCallback((s,{nodeId:g,handleType:y})=>{a&&console.log("Connection started from",{nodeId:g,handleType:y});},[a]),Ja=useCallback(s=>{a&&console.log("Connection ended",s);},[a]),Qa=useCallback(()=>{if(Ne||!lt)return;let s=le(lt.id);if(s){if(s.type==="rack"){let g=s.data||{};if($e(g))return;let h=(g.face||"front")==="front"?"rear":"front";N?(N(s.id,h),P&&rt().filter(I=>I.parentId===s.id).forEach(I=>{P(I.id,h);})):be(T=>T.map(I=>I.id===s.id?{...I,data:{...I.data,face:h}}:I.parentId===s.id?{...I,data:{...I.data,view:h}}:I));return}if(Je(s)){if(lo(s))return;let g=s.data||{},y=Array.isArray(g.rearPorts)&&g.rearPorts.length>0,h=Array.isArray(g.ports)&&g.ports.length>0,I=(g.view||(y&&!h?"rear":"front"))==="front"?"rear":"front";P?P(s.id,I):be(H=>H.map($=>$.id===s.id?{...$,data:{...$.data,view:I}}:$));}}},[lt,le,N,P,be,rt,Ne,lo]),es=useCallback(()=>{if(Ne||!w||!lt||!Je(lt))return;let s=le(lt.id),g=Ke(s);if(!s||!Je(s)||!g)return;let y=$t(s),T=gt.current.map(I=>I.id!==s.id?I:{...I,parentId:void 0,parentNode:void 0,extent:void 0,position:y,data:{...I.data,uPosition:void 0}});Zo(T);},[Ne,w,lt,le,$t,Zo,Ke]),ts=useMemo(()=>{let s=Ro.current;return fe.map(g=>{let y=g,h=s.get(String(y.source)),T=s.get(String(y.target)),I=Rr(y.sourceHandle||"",h),H=Rr(y.targetHandle||"",T),$=Ue=>{if(!Ue||!Je(Ue))return;let Ce=Ue.data??{},it=typeof Ue.parentId=="string"?Ue.parentId:Ue.parentNode,W=it?s.get(it):void 0;if(W&&W.type==="rack"&&$e(W.data))return Bt(Ve(Ce));let He=Array.isArray(Ce.rearPorts)&&Ce.rearPorts.length>0,ne=Array.isArray(Ce.ports)&&Ce.ports.length>0;return [Ce.view||(He&&!ne?"rear":"front")]},S=$(h),K=$(T),oe=Ar(h),Ee=Ar(T),Ie=Je(h)&&!oe&&!!S&&!!I&&!S.includes(I),Fe=Je(T)&&!Ee&&!!K&&!!H&&!K.includes(H),Le=Ie||Fe,qe=g.style;if(Le)qe={...g.style,opacity:0,pointerEvents:"none",zIndex:0};else if(g.style&&g.style.opacity===0&&g.style.pointerEvents==="none"&&g.style.zIndex===0){let Ce={...g.style};delete Ce.opacity,delete Ce.pointerEvents,delete Ce.zIndex,qe=Object.keys(Ce).length>0?Ce:void 0;}return {...g,style:qe,className:Jn.has(g.id)?"edge-connecting":g.className}})},[fe,Jn,Ar]),Me=useMemo(()=>lt?le(lt.id)??lt:null,[lt,le]),uo=useMemo(()=>{if(!Me||!ke.enabled||Ne)return {showRearToggle:false,showDeRack:false,count:0};let s=Me.type==="rack"?!Zn(Me):Je(Me)?!lo(Me):false,g=ke.showRearToggle&&s,y=ke.showDeRack&&w&&!Ne&&Je(Me)&&!!Ke(Me);return {showRearToggle:g,showDeRack:y,count:(g?1:0)+(y?1:0)}},[Me,ke,w,Ne,Ke,lo,Zn]),Or=useMemo(()=>{if(!Me||uo.count===0||!Ae.current)return null;let s=Ae.current.getBoundingClientRect();if(s.width<=0||s.height<=0)return null;let g=Me.positionAbsolute??$t(Me),y=Me.width||0,h=Me.height||0,T=uo.count>1?220:110,I=34;try{let H=Qe({x:g.x+y/2,y:g.y}),$=Qe({x:g.x+y/2,y:g.y+h}),S=H.x-s.left-T/2,K=H.y-s.top-I-10;return K<8&&(K=$.y-s.top+10),S=Math.max(8,Math.min(S,s.width-T-8)),K=Math.max(8,Math.min(K,s.height-I-8)),{left:S,top:K}}catch{return null}},[Me,uo,$t,Qe]),os=ii(R,v),rs=si(R,{touchAction:"none",...C});return jsxs("div",{ref:Ae,className:os,style:rs,children:[jsxs(ReactFlow,{nodes:xe,edges:ts,onNodesChange:s=>{if(Ne)return;let g=Oa(s);g&&(L?n&&n(g):q.setState({nodes:g}));},onEdgesChange:s=>{if(Ne)return;let g=s.filter(y=>{if(y.type==="remove"){let h=J.current.find(T=>T.id===y.id);if(h){let T=h.sourceHandle||"",I=h.targetHandle||"";if(T.startsWith("tube-")||I.startsWith("tube-"))return a&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",h),false}}return true});if(g.length>0){let y=applyEdgeChanges(g,J.current);_e(g),L?i&&i(y):q.setState({edges:y});}},onConnect:Ne?void 0:u??Ga,onConnectStart:qa,onConnectEnd:Ja,onEdgeUpdate:Ne?void 0:p??Xa,isValidConnection:m??Va,connectionMode:x,onNodeClick:ja,onNodeDoubleClick:Ya,onPaneClick:Za,onNodeDragStart:Wa,onNodeDrag:za,onNodeDragStop:Ua,onEdgeClick:Ka,onInit:D,nodeTypes:Xt.current,edgeTypes:Ba,defaultEdgeOptions:{zIndex:1e3,reconnectable:Se.edgesReconnectable},nodesDraggable:Se.nodesDraggable,nodesConnectable:Se.nodesConnectable,elementsSelectable:Se.elementsSelectable,edgesFocusable:Se.edgesFocusable,elevateNodesOnSelect:false,selectNodesOnDrag:false,connectOnClick:Se.connectOnClick,panOnDrag:Se.panOnDrag,panOnScroll:Se.panOnScroll,zoomOnScroll:Se.zoomOnScroll,zoomOnPinch:Se.zoomOnPinch,zoomOnDoubleClick:Se.zoomOnDoubleClick,preventScrolling:Re,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:ee,proOptions:{hideAttribution:true},children:[jsx(Background,{color:ai(R)}),Se.showControls&&jsx(Controls,{showInteractive:Se.showInteractiveControl}),Se.showMiniMap&&jsx(MiniMap,{}),jsx(Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&jsx("button",{className:"download-button",onClick:Mr,disabled:nt,"aria-busy":nt,style:{position:"absolute",top:_.includes("top")?"10px":"auto",bottom:_.includes("bottom")?"10px":"auto",right:_.includes("right")?"10px":"auto",left:_.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:nt?"not-allowed":"pointer",opacity:nt?.7:1,transition:"all 0.2s ease",...se},children:nt?`${U}...`:U}),Me&&Or&&uo.count>0&&jsxs("div",{style:{position:"absolute",top:Or.top,left:Or.left,display:"flex",gap:8,zIndex:2e3},children:[uo.showRearToggle&&jsx("button",{onClick:s=>{s.preventDefault(),Qa();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let s=Me.data;if(Me.type==="rack")return (s?.face||"front")==="front"?"Switch to rear":"Switch to front";{let g=Array.isArray(s?.rearPorts)&&s.rearPorts.length>0,y=Array.isArray(s?.ports)&&s.ports.length>0;return (s?.view||(g&&!y?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let s=Me.data;if(Me.type==="rack")return (s?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let g=Array.isArray(s?.rearPorts)&&s.rearPorts.length>0,y=Array.isArray(s?.ports)&&s.ports.length>0;return (s?.view||(g&&!y?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()}),uo.showDeRack&&jsx("button",{onClick:s=>{s.preventDefault(),es();},style:{background:"#7f1d1d",color:"#fee2e2",border:"1px solid #b91c1c",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:"Remove device from rack so it can be moved/reassigned",children:"De-rack"})]})]})},zn=e=>jsx(ReactFlowProvider,{children:jsx(rc,{...e})});var Un=class extends Component{constructor(){super(...arguments);this.state={error:null};this.reset=()=>{this.setState({error:null});};}static getDerivedStateFromError(o){return {error:o}}componentDidCatch(o,r){this.props.onError?.(o,r);}render(){let{error:o}=this.state,{children:r,fallback:n}=this.props;return o?typeof n=="function"?n(o,this.reset):n??jsxs("div",{role:"alert",style:{padding:16,margin:8,border:"1px solid #e53e3e",borderRadius:4,backgroundColor:"#fff5f5",color:"#c53030"},children:[jsx("strong",{children:"Diagram error"}),": ",o.message,jsx("button",{type:"button",onClick:this.reset,style:{marginLeft:12,padding:"4px 8px",cursor:"pointer"},children:"Try again"})]}):r}};function jo(e,{rowHeight:t,tubeGap:o}){let r=[],n=[],i=e.kind??(e.tubeCount?"tube":"simple"),d=i==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,a=i==="tube"?Math.max(1,Math.min(24,e.fibersPerTube??12)):Math.max(1,Math.min(24,e.fiberCount??12)),c=Math.max(1,e.tubeStartIndex??1),l=Math.max(1,e.fiberStartIndex??1),b=0;for(let f=0;f<d;f+=1){let u=c+f,p=e.tubeColorMap?.[u];n.push({tubeIndex:u,y:b,label:`T${u}`,color:p??Xe(u)});for(let m=0;m<a;m+=1){let x=l+m,P=Jr(x);r.push({key:`${u}-${x}`,tubeIndex:i==="tube"?u:void 0,fiberIndex:x,y:b,color:qt(x),striped:Zt(x),backgroundImage:typeof P.backgroundImage=="string"?P.backgroundImage:void 0}),b+=t;}f<d-1&&(b+=o);}return {rows:r,tubeLabels:n,height:b}}var Vn=e=>typeof e=="object"&&e!==null,dc=e=>{if(!Vn(e.data))return false;if(e.type==="fibre-flow-cable"){let t=e.data;return typeof t.label=="string"&&Vn(t.cable)&&(t.side==="left"||t.side==="right")&&typeof t.rowHeight=="number"&&typeof t.columnWidth=="number"&&typeof t.showTubeLabels=="boolean"&&typeof t.showFiberNumbers=="boolean"&&Vn(t.layout)}if(e.type==="fibre-flow-closure"){let t=e.data;return typeof t.label=="string"&&typeof t.width=="number"&&typeof t.height=="number"&&typeof t.headerHeight=="number"}return false},cc=e=>e==="fibre-flow"||e==="fibre-flow-link",lc=e=>typeof e.id=="string"&&e.id.length>0&&typeof e.source=="string"&&e.source.length>0&&typeof e.target=="string"&&e.target.length>0,uc=e=>e.sourceHandle==="cable-run"||e.targetHandle==="cable-run"?"fibre-flow-link":"fibre-flow",pc=(e,t=[])=>{let o=new Map(t.map(n=>[n.id,n])),r=[];return e.forEach(n=>{if(!lc(n))return;let i=o.get(n.id),d=cc(n.type)?n.type:i?.type??uc(n);r.push({...i??{},...n,type:d});}),r},ga=e=>`fiber-${e.tube??1}-${e.fiber}`,ba=e=>qt(e.fiber),ma=e=>Zt(e.fiber),fc=(e,t)=>{if(t)return t;if(!(typeof e!="number"||Number.isNaN(e)))return e>=1e3?`${(e/1e3).toFixed(1)} km`:`${Math.round(e)} m`},gc=(e,t,o,r,n,i)=>e?`${o} ${i}`:t?`0 ${n} ${r} ${i}`:"6 6",bc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a})=>{let[c,l,b]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.35}),f=typeof a?.lossDb=="number"?`${a.lossDb.toFixed(2)} dB`:"",u=a?.label??f,p=a?.sourceColor,m=a?.targetColor,x=a?.color??p??m??"#94a3b8",P=a?.sourceStriped??false,N=a?.targetStriped??false,v=a?.highlighted??true,C=a?.dimmed??false,F=a?.circuitId,w=a?.circuitLabel??F,R=a?.showCircuitId??false,D=p&&m&&p!==m,E=r-t,A=n-o,_=Math.sqrt(E*E+A*A),U=l-t,se=b-o,j=Math.sqrt(U*U+se*se),Y=_>0?j/_*100:50,ie=`fibre-flow-gradient-${e}`,z=P&&!N,V=N&&!P,B=P&&N,O=_*1.25,X=O/2,ee=12,M=Math.ceil(X*1.2/ee),L=Array(M).fill("6 6").join(" "),de=Math.ceil(X*1.2/ee),ae=Array(de).fill("6 6").join(" "),ce=R&&w,q=Math.max(u?u.length*6.2+16:0,ce?(w?.length||0)*5.5+16:0),ve=ce?32:16;return jsxs(Fragment,{children:[jsx("defs",{children:D&&jsxs("linearGradient",{id:ie,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0%",stopColor:p}),jsx("stop",{offset:`${Y}%`,stopColor:p}),jsx("stop",{offset:`${Y}%`,stopColor:m}),jsx("stop",{offset:"100%",stopColor:m})]})}),D?jsx("path",{id:e,d:c,fill:"none",stroke:`url(#${ie})`,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,style:{mixBlendMode:"normal"}}):jsx(BaseEdge,{id:e,path:c,style:{stroke:x,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,mixBlendMode:"normal"}}),(B||z||V)&&jsx("path",{id:`${e}-stripe`,d:c,fill:"none",stroke:"#000",strokeWidth:v?1.6:1.3,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:gc(z,V,L,ae,X,O),strokeDashoffset:0,opacity:C?.2:.9,style:{mixBlendMode:"normal"}}),(u||ce)&&v&&jsx(EdgeLabelRenderer,{children:jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${b}px)`,width:q,height:ve,background:"rgba(248, 250, 252, 0.92)",border:"1px solid rgba(15, 23, 42, 0.4)",borderRadius:4,fontSize:10,fontFamily:"monospace",color:"rgba(15, 23, 42, 0.9)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",pointerEvents:"none",padding:"2px 4px",zIndex:9999},children:[u&&jsx("div",{style:{lineHeight:1.2},children:u}),ce&&jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:u?2:0},children:w})]})})]})},mc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a})=>{let[c,l,b]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.2}),f=a?.label,u=a?.color??"#64748b";return jsxs(Fragment,{children:[jsx(BaseEdge,{id:e,path:c,style:{stroke:u,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),f&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${b}px)`,padding:"2px 8px",background:"rgba(30, 41, 59, 0.9)",border:`1px solid ${u}`,borderRadius:10,fontSize:10,fontFamily:"monospace",color:"#e2e8f0",letterSpacing:.2,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9999},children:f})})]})},hc=({data:e})=>{let{cable:t,side:o,rowHeight:r,columnWidth:n,showTubeLabels:i,showFiberNumbers:d,layout:a,colorMode:c="dark"}=e,l=c==="light",b=8,f=12,u=-1,p=0,m=t.jacketColor??"#facc15",x=(t.kind??(t.tubeCount?"tube":"simple"))==="tube",P=i&&x,N=o==="left"?b+p:p,v=o==="right"?b+p:p,C=o==="left"?Position.Right:Position.Left,F={width:4,height:4,borderRadius:"50%",background:m,border:`1px solid ${m}`,boxShadow:"0 0 1px rgba(0,0,0,0.4)",top:"50%",position:"absolute",...o==="left"?{left:0,transform:"translate(-50%, -50%)"}:{right:0,transform:"translate(50%, -50%)"}};return jsxs("div",{style:{position:"relative",width:n,height:a.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[jsx("div",{style:{position:"absolute",top:-18,left:o==="left"?0:void 0,right:o==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:l?"rgba(248, 250, 252, 0.95)":"rgba(15, 23, 42, 0.9)",color:l?"#1a1a1a":"#f8fafc",padding:"2px 6px",borderRadius:4,whiteSpace:"nowrap",maxWidth:n,overflow:"hidden",textOverflow:"ellipsis",zIndex:10,...o==="right"?{textAlign:"right"}:{}},children:t.label}),jsx("div",{style:{position:"absolute",top:0,bottom:0,width:b,left:o==="left"?0:void 0,right:o==="right"?0:void 0,borderRadius:4,background:x?"transparent":m,border:`1px solid ${m}`,boxShadow:x?"none":"inset 0 0 3px rgba(0,0,0,0.3)",overflow:"hidden"},children:x&&a.tubeLabels.map((w,R)=>{let D=a.rows.filter(j=>j.tubeIndex===w.tubeIndex);if(D.length===0)return null;let E=D[0].y,A=D[D.length-1].y+r,_=A-E,U=a.tubeLabels[R+1],se=U&&U.y-A>0;return jsx("div",{style:{position:"absolute",top:E,left:0,right:0,height:_,background:w.color,borderLeft:`2px solid ${w.color}`,borderRight:`2px solid ${w.color}`,borderTop:R===0?`2px solid ${w.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:se?"1px solid rgba(0,0,0,0.15)":`2px solid ${w.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:R===0&&!se||R===0?"4px 4px 0 0":se?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${w.tubeIndex}`)})}),!P&&jsx("div",{style:{position:"absolute",top:0,bottom:0,left:N,right:v,...o==="left"?{borderRight:`1px solid ${m}`}:{borderLeft:`1px solid ${m}`},pointerEvents:"none",zIndex:0}}),x&&a.tubeLabels.map((w,R)=>{let D=a.rows.filter(U=>U.tubeIndex===w.tubeIndex);if(D.length===0)return null;let E=D[0].y,_=D[D.length-1].y+r-E;return jsx("div",{style:{position:"absolute",top:E,left:N,right:v,height:_,...o==="left"?{borderRight:`2px solid ${w.color}`}:{borderLeft:`2px solid ${w.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${w.tubeIndex}`)}),a.rows.map(w=>{let R=`fiber-${w.tubeIndex??1}-${w.fiberIndex}`,D=w.y+r/2,E={position:"absolute",width:f,height:f,borderRadius:"50%",top:D,background:w.backgroundImage?w.backgroundImage:w.color,backgroundColor:w.color,border:`2px solid ${w.color}`,boxShadow:"0 0 6px rgba(0,0,0,0.3)",...o==="left"?{right:-f/2}:{left:-f/2},transform:"translateY(-50%)",zIndex:1e3,cursor:"crosshair","--fiber-bg":w.color,minWidth:f,minHeight:f};w.backgroundImage&&(E["--fiber-bg-image"]=w.backgroundImage);let A=o==="left"?{right:f+u,textAlign:"right"}:{left:f+u,textAlign:"left"};return jsxs(ot.Fragment,{children:[jsx(Handle,{id:R,type:"source",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":w.fiberIndex,"data-tube-idx":w.tubeIndex,"data-fiber-color":w.color}),jsx(Handle,{id:R,type:"target",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":w.fiberIndex,"data-tube-idx":w.tubeIndex,"data-fiber-color":w.color}),d&&jsx("div",{style:{position:"absolute",top:w.y+r/2-6,...A,fontSize:8,fontWeight:600,color:l?"rgba(15, 23, 42, 0.7)":"rgba(148, 163, 184, 0.95)",whiteSpace:"nowrap",lineHeight:1},children:w.fiberIndex})]},w.key)}),jsx(Handle,{id:"cable-run",type:"source",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:F,isConnectable:true,"data-handle-type":"cable-run"}),jsx(Handle,{id:"cable-run",type:"target",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:F,isConnectable:true,"data-handle-type":"cable-run"})]})},yc=({data:e})=>{let t=e.colorMode==="light";return jsx("div",{style:{width:e.width,height:e.height,background:"transparent",border:t?"1px solid rgba(148, 163, 184, 0.3)":"1px solid rgba(148, 163, 184, 0.5)",borderRadius:12,boxShadow:t?"0 12px 24px rgba(0, 0, 0, 0.1)":"0 12px 24px rgba(15, 23, 42, 0.2)",position:"relative",pointerEvents:"none"},children:jsx("div",{style:{height:e.headerHeight,display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"monospace",fontWeight:700,fontSize:12,letterSpacing:.6,textTransform:"uppercase",color:t?"rgba(15, 23, 42, 0.9)":"rgba(226, 232, 240, 0.9)",background:t?"rgba(241, 245, 249, 0.7)":"rgba(15, 23, 42, 0.6)",borderBottom:t?"1px solid rgba(148, 163, 184, 0.2)":"1px solid rgba(148, 163, 184, 0.35)",borderTopLeftRadius:12,borderTopRightRadius:12},children:e.label})})},wc=(e,t,o,r,n,i,d,a,c,l="dark")=>{let b=[],f=0;return e.forEach(u=>{let p=jo(u.leftCable,{rowHeight:o,tubeGap:r}),m=jo(u.rightCable,{rowHeight:o,tubeGap:r}),x=Math.max(p.height,m.height),P=i*2+d,N=32,v=16,C=P+v*2,F=x+N+v*2,w=`flow-closure-${u.id}`,R=`flow-cable-${u.id}-left`,D=`flow-cable-${u.id}-right`,E=t==="horizontal"?{x:f,y:0}:{x:0,y:f};f+=(t==="horizontal"?C:F)+n;let A=u.chamberId?`${u.id} - ${u.chamberId}`:u.id;b.push({id:w,type:"fibre-flow-closure",position:E,data:{label:A,width:C,height:F,headerHeight:N,colorMode:l},selectable:false,draggable:false,style:{width:C,height:F}});let _=N+v+(x-p.height)/2,U=N+v+(x-m.height)/2;b.push({id:R,type:"fibre-flow-cable",position:{x:v,y:_},parentId:w,extent:"parent",data:{label:u.leftCable.label,cable:u.leftCable,side:"left",rowHeight:o,columnWidth:i,showTubeLabels:a,showFiberNumbers:c,layout:p,colorMode:l},style:{width:i,height:p.height}}),b.push({id:D,type:"fibre-flow-cable",position:{x:v+P-i,y:U},parentId:w,extent:"parent",data:{label:u.rightCable.label,cable:u.rightCable,side:"right",rowHeight:o,columnWidth:i,showTubeLabels:a,showFiberNumbers:c,layout:m,colorMode:l},style:{width:i,height:m.height}});}),b},xc=(e,t,o,r=false)=>{let n=[],i=new Map,d=new Map,a=new Map;return (t??[]).forEach(c=>{c.color&&i.set(c.id,c.color),c.label&&d.set(c.id,c.label);}),e.forEach(c=>{let l=`flow-cable-${c.id}-left`,b=`flow-cable-${c.id}-right`;[{nodeId:l,cable:c.leftCable},{nodeId:b,cable:c.rightCable}].forEach(({nodeId:u,cable:p})=>{let m=a.get(p.id);if(m&&m.closureId!==c.id){let x=fc(p.distanceMeters??m.distanceMeters,p.distanceLabel??m.distanceLabel),P=p.jacketColor??m.jacketColor??"#64748b";n.push({id:`flow-link-${m.nodeId}-${u}`,type:"fibre-flow-link",source:m.nodeId,target:u,sourceHandle:"cable-run",targetHandle:"cable-run",data:{label:x,color:P}});}a.set(p.id,{nodeId:u,closureId:c.id,jacketColor:p.jacketColor,distanceLabel:p.distanceLabel,distanceMeters:p.distanceMeters});}),c.splices.forEach(u=>{let p=o?u.circuitId===o:true,m=!!o&&!p,x=u.circuitId?i.get(u.circuitId):void 0,P=u.circuitId?d.get(u.circuitId):void 0,N=u.color??x,v=ba(u.from),C=ba(u.to),F=ma(u.from),w=ma(u.to);n.push({id:`flow-edge-${c.id}-${u.id}`,type:"fibre-flow",source:l,target:b,sourceHandle:ga(u.from),targetHandle:ga(u.to),data:{lossDb:u.lossDb,label:u.label,color:N,sourceColor:v,targetColor:C,sourceStriped:F,targetStriped:w,highlighted:p,dimmed:m,circuitId:u.circuitId,circuitLabel:P,showCircuitId:r}});});}),n},Nc=({closures:e,circuits:t,highlightedCircuitId:o,layout:r="horizontal",rowHeight:n=20,tubeGap:i=10,closureGap:d=140,cableColumnWidth:a=32,spliceAreaWidth:c=260,showTubeLabels:l=true,showFiberNumbers:b=true,colorMode:f="dark",showCircuitId:u=false,className:p,style:m,readOnly:x=false,panOnDrag:P=true,panOnScroll:N=true,zoomOnScroll:v=true})=>{let C=useMemo(()=>wc(e,r,n,i,d,a,c,l,b,f),[e,r,n,i,d,a,c,l,b,f]),F=useMemo(()=>xc(e,t,o,u),[e,t,o,u]),[w,R]=useState(C),[D,E]=useState(F);useEffect(()=>{R(C);},[C,R]),useEffect(()=>{E(F);},[F,E]);let A=useCallback((B,O)=>{if(!B||!O||!O.startsWith("fiber-"))return;let X=w.find(ce=>ce.id===B);if(!X||X.type!=="fibre-flow-cable")return;let ee=/^fiber-(\d+)-(\d+)$/.exec(O);if(!ee)return;let M=Number(ee[1]),L=Number(ee[2]),ae=X.data.layout.rows.find(ce=>(ce.tubeIndex??1)===M&&ce.fiberIndex===L);if(ae)return {color:ae.color,striped:ae.striped??false}},[w]),_=useCallback(B=>{if(x||!B.source||!B.target||!B.sourceHandle||!B.targetHandle)return false;let O=w.find(de=>de.id===B.source),X=w.find(de=>de.id===B.target);if(!O||!X)return false;let ee=typeof B.sourceHandle=="string"&&B.sourceHandle.startsWith("fiber-"),M=typeof B.targetHandle=="string"&&B.targetHandle.startsWith("fiber-");return B.sourceHandle==="cable-run"||B.targetHandle==="cable-run"?true:ee&&M?O.type==="fibre-flow-cable"&&X.type==="fibre-flow-cable":false},[w,x]),U=useCallback(B=>{if(x)return;let O=B.sourceHandle==="cable-run"||B.targetHandle==="cable-run",X=q=>typeof q=="string"&&q.startsWith("fiber-"),ee=X(B.sourceHandle),M=X(B.targetHandle),L=(q,ve,De)=>q.source===ve&&q.sourceHandle===De||q.target===ve&&q.targetHandle===De,de=O?void 0:A(B.source,B.sourceHandle),ae=O?void 0:A(B.target,B.targetHandle),ce=O?void 0:{sourceColor:de?.color,targetColor:ae?.color,color:de?.color??ae?.color,sourceStriped:de?.striped,targetStriped:ae?.striped};E(q=>{let ve=q.filter(De=>{let xe=ee&&L(De,B.source,B.sourceHandle),be=M&&L(De,B.target,B.targetHandle);return !(xe||be)});return addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:ce},ve)});},[A,x,E]),se=useCallback((B,O)=>{if(x)return;let X=O.sourceHandle==="cable-run"||O.targetHandle==="cable-run",ee=X?void 0:A(O.source,O.sourceHandle),M=X?void 0:A(O.target,O.targetHandle),L=X?void 0:{sourceColor:ee?.color,targetColor:M?.color,color:ee?.color??M?.color,sourceStriped:ee?.striped,targetStriped:M?.striped},de=ce=>typeof ce=="string"&&ce.startsWith("fiber-"),ae=(ce,q,ve)=>ce.source===q&&ce.sourceHandle===ve||ce.target===q&&ce.targetHandle===ve;E(ce=>{let q=ce.filter(be=>be.id!==B.id),ve=de(O.sourceHandle),De=de(O.targetHandle),xe=q.filter(be=>{let fe=ve&&ae(be,O.source,O.sourceHandle),he=De&&ae(be,O.target,O.targetHandle);return !(fe||he)});return addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:L},xe)});},[A,x,E]),j=useCallback(B=>{x||R(B.filter(dc));},[x,R]),Y=useCallback(B=>{x||E(O=>pc(B,O));},[x,E]),ie=useMemo(()=>({"fibre-flow-cable":hc,"fibre-flow-closure":yc}),[]),z=useMemo(()=>({"fibre-flow":bc,"fibre-flow-link":mc}),[]),V={borderRadius:8,overflow:"hidden",...m};return jsx(zn,{nodes:w,edges:D,onNodesChange:j,onEdgesChange:Y,onConnect:U,onEdgeUpdate:se,isValidConnection:_,connectionMode:ConnectionMode.Loose,nodeTypes:ie,edgeTypes:z,className:p,style:V,colorMode:f,readOnly:x,panOnDrag:P,panOnScroll:N,zoomOnScroll:v,fitViewOptions:{padding:.2}})},kc=e=>jsx(Nc,{...e});var vc=({cable:e,side:t,rowHeight:o=22,tubeGap:r=10,columnWidth:n=150,layout:i,showTubeLabels:d,showFiberNumbers:a=true,showCableLabel:c=true})=>{let l=useMemo(()=>i??jo(e,{rowHeight:o,tubeGap:r}),[i,e,o,r]),b=26,f=10,u=18,p=t==="left"?n-u:u,m=8,x=t==="left"?6:n-b-18,P=e.jacketColor??"#facc15",N=d??(e.kind??(e.tubeCount?"tube":"simple"))==="tube";return jsxs("div",{style:{position:"relative",width:n,height:l.height,fontFamily:"monospace",color:"inherit"},children:[c&&jsx("div",{style:{position:"absolute",top:-18,left:t==="left"?0:void 0,right:t==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:"rgba(15, 23, 42, 0.85)",color:"#f8fafc",padding:"2px 6px",borderRadius:4},children:e.label}),jsx("div",{style:{position:"absolute",top:0,bottom:0,width:b,left:t==="left"?0:void 0,right:t==="right"?0:void 0,borderRadius:14,background:`linear-gradient(90deg, ${P} 0%, ${P} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${P}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),N&&l.tubeLabels.map(v=>jsxs("div",{style:{position:"absolute",top:v.y+o/2-6,left:x,fontSize:9,fontWeight:700,textTransform:"uppercase",color:"rgba(15, 23, 42, 0.75)",background:"rgba(255, 255, 255, 0.6)",padding:"1px 6px 1px 4px",borderRadius:10,display:"flex",alignItems:"center",gap:4},children:[jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:v.color,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 3px rgba(0,0,0,0.25)"}}),jsx("span",{children:v.label})]},`tube-${v.tubeIndex}`)),l.rows.map(v=>{let C=v.y+o/2-f/2,F=t==="left"?p-f/2-m:p+f/2+m;return jsxs(ot.Fragment,{children:[jsx("div",{style:{position:"absolute",top:C,left:p-f/2,width:f,height:f,borderRadius:"50%",backgroundColor:v.color,backgroundImage:v.backgroundImage,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 4px rgba(0,0,0,0.25)"}}),a&&jsx("div",{style:{position:"absolute",top:v.y+o/2-6,left:F,transform:t==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:v.fiberIndex})]},v.key)})]})};var Na=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,uHeight:e.u_height??e.units??42,inventoryId:e.id,inventoryType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:typeof e.site=="object"&&e.site?e.site.name:e.site,role:typeof e.role=="object"&&e.role?e.role.name:e.role,tenant:typeof e.tenant=="object"&&e.tenant?e.tenant.name:e.tenant}}),ka=e=>({id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${typeof e.rack=="object"&&e.rack?e.rack.id:e.rack}`:void 0,extent:e.rack?"parent":void 0,data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,deviceType:e.device_type?.model??e.model,manufacturer:e.device_type?.manufacturer?.name??e.manufacturer,role:typeof e.device_role=="object"&&e.device_role?e.device_role.name:e.role,uHeight:e.device_type?.u_height??e.u_height??1,uPosition:e.position||1,view:e.face||"front",inventoryId:e.id,inventoryType:"device",primaryIp4:typeof e.primary_ip4=="object"&&e.primary_ip4?e.primary_ip4.address:e.primary_ip4,primaryIp6:typeof e.primary_ip6=="object"&&e.primary_ip6?e.primary_ip6.address:e.primary_ip6,site:typeof e.site=="object"&&e.site?e.site.name:e.site,rack:typeof e.rack=="object"&&e.rack?e.rack.name:e.rack}}),Pa=e=>{let t=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},o=t(e.termination_a),r=t(e.termination_b);return {id:`cable-${e.id}`,source:`device-${o}`,target:`device-${r}`,type:"fiber",data:{bandwidth:e.type?.label??e.bandwidth,length:e.length||0,color:e.color,inventoryId:e.id,inventoryType:"cable",status:typeof e.status=="object"&&e.status?e.status.value:e.status,terminationA:typeof e.termination_a=="object"&&e.termination_a?e.termination_a.name:e.termination_a,terminationB:typeof e.termination_b=="object"&&e.termination_b?e.termination_b.name:e.termination_b}}},Tc=e=>{let t=[],o=[];return e.racks.forEach(r=>t.push(Na(r))),e.devices.forEach(r=>t.push(ka(r))),e.cables.forEach(r=>o.push(Pa(r))),{nodes:t,edges:o}},Rc=e=>{let t=e.filter(n=>n.type==="rack"),o=e.filter(n=>n.type==="device"),r=e.filter(n=>!["rack","device"].includes(n.type));return t.forEach((n,i)=>{n.position={x:i*300,y:100};}),o.forEach(n=>{if(n.parentId){let i=t.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,a=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-a*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),r.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var Ca=e=>typeof e.id=="number"?`device-${e.id}`:`device-${e.name}`,Sc="Interfaces",Ec="Management",Ic="Power",Xn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ht=e=>{if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0},Fr=e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim().length>0){let t=Number(e);if(Number.isFinite(t))return t}},Dt=e=>{if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20")return t},Fc=e=>typeof e=="string"&&e.toLowerCase()==="rear"?"rear":"front",Hr=e=>Xn(e.custom_fields)?e.custom_fields:void 0,Dr=e=>Xn(e)?e:void 0,va=(e,t)=>{let o=Hr(e),r=Dr(o?.layout);return Fc(t??e.layout?.face??e.face??r?.face??o?.port_face??o?.portFace??o?.face)},Ta=(e,t,o)=>{let r=Hr(e),n=Dr(r?.layout),i=Ht(o)??Ht(e.layout?.group)??Ht(e.port_group)??Ht(n?.group)??Ht(r?.port_group)??Ht(r?.portGroup)??Ht(r?.interface_group)??Ht(r?.interfaceGroup)??Ht(r?.group);return i||(t==="power_ac"||t==="power_c13"||t==="power_c19"?Ic:t==="console"||t==="mgmt"?Ec:Sc)},Ra=(e,t,o)=>{let r=Hr(e),n=Dr(r?.layout);return Dt(o)??Dt(e.layout?.connectorType)??Dt(e.layout?.connector_type)??Dt(e.connector_type)??Dt(n?.connectorType)??Dt(n?.connector_type)??Dt(r?.connectorType)??Dt(r?.connector_type)??Dt(t)},Sa=(e,t)=>{if(t==="C13")return "power_c13";if(t==="C19")return "power_c19";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")||o.includes("dac")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")||o.includes("oob")?"mgmt":o.includes("usb")?"usb":"ethernet"},Ea=e=>{let t=(e??"").toLowerCase();if(t){if(t.includes("om3"))return "om3";if(t.includes("om4"))return "om4";if(t.includes("om5"))return "om5";if(t.includes("smf")||t.includes("singlemode"))return "smf";if(t.includes("cat5e"))return "cat5e";if(t.includes("cat6a"))return "cat6a";if(t.includes("cat6"))return "cat6";if(t.includes("cat7"))return "cat7";if(t.includes("fiber")||t.includes("sfp")||t.includes("qsfp"))return "fiber";if(t.includes("ethernet")||t.includes("rj45")||t.includes("1000base")||t.includes("10gbase")||t.includes("base-t"))return "ethernet"}},Hc=e=>{if(!Xn(e))return;let t=e.side??e.port_side??e.portSide,o=typeof t=="string"&&["top","right","bottom","left"].includes(t.toLowerCase())?t.toLowerCase():void 0,r=Fr(e.offsetPercent??e.offset_percent??e.offsetPct??e.offset_pct),n=Fr(e.offsetPx??e.offset_px??e.offsetPixels??e.offset_pixels),i=Fr(e.xPercent??e.x_percent??e.xPct??e.x_pct??e.horizontalPercent??e.horizontal_percent??e.x),d=Fr(e.yPercent??e.y_percent??e.yPct??e.y_pct??e.verticalPercent??e.vertical_percent??e.y);if(!(o===void 0&&r===void 0&&n===void 0&&i===void 0&&d===void 0))return {side:o,offsetPercent:r,offsetPx:n,xPercent:i,yPercent:d}},Ia=(e,t,o)=>{if(!o)return;let r=Hr(e),n=Dr(r?.layout),i=[t?.position,t,e.layout?.position,e.layout,n?.position,n,r?.port_position,r?.portPosition,r?.position,r,e];for(let d of i){let a=Hc(d);if(a)return a}},Dc=(e,t)=>{let o=e.type?.value??e.type?.label??e.layout?.type??void 0,r=Ra(e,o),n=Sa(o,r),i=Ta(e,n);return {label:e.name,face:va(e),group:i,type:n,cableType:Ea(o),connected:!!(e.connected_endpoint||e.cable),connectorType:r,position:Ia(e,void 0,t)}},_c=e=>[...e].sort((t,o)=>{let r=typeof t.position=="number"?t.position:Number.MAX_SAFE_INTEGER,n=typeof o.position=="number"?o.position:Number.MAX_SAFE_INTEGER;return r!==n?r-n:t.name.localeCompare(o.name)}),Mc=(e,t)=>{let o=e.find(n=>n.name===t);if(o)return o;let r={name:t,ports:[]};return e.push(r),r},$c=(e,t)=>{let{includePortPositions:o=false,mapInterfaceToPort:r}=t,n=[],i=[];return _c(e.interfaces??[]).forEach((a,c)=>{let l=r?r({device:e,iface:a,index:c}):Dc(a,o);if(!l)return;let b=l.type??a.type?.value??a.type?.label??void 0,f=Ra(a,b,l.connectorType),u=Sa(b,f),p=va(a,l.face),m=Ta(a,u,l.group);Mc(p==="rear"?i:n,m).ports.push({id:l.id,label:l.label??a.name,connected:l.connected??!!(a.connected_endpoint||a.cable),type:u,cableType:Ea(l.cableType??a.type?.value??a.type?.label??void 0),connectorType:f,position:Ia(a,l,o)});}),{front:n,rear:i}},Fa=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:e.status.value,uHeight:e.u_height,netboxId:e.id,netboxType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:e.site.name,role:e.role?.name,tenant:e.tenant?.name}}),Ha=(e,t={})=>{let o={label:e.name,status:e.status.value,deviceType:e.device_type.model,manufacturer:e.device_type.manufacturer.name,role:e.device_role.name,uHeight:1,uPosition:e.position||1,face:e.face||"front",netboxId:e.id,netboxType:"device",primaryIp4:e.primary_ip4?.address,primaryIp6:e.primary_ip6?.address,site:e.site.name,rack:e.rack?.name};if(t.includeInterfacePorts&&Array.isArray(e.interfaces)&&e.interfaces.length>0){let{front:r,rear:n}=$c(e,t);r.length>0&&(o.ports=r),n.length>0&&(o.rearPorts=n);}return {id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${e.rack.id}`:void 0,extent:e.rack?"parent":void 0,data:o}},Da=e=>({id:`cable-${e.id}`,source:Ca(e.termination_a.device),target:Ca(e.termination_b.device),type:"fiber",data:{bandwidth:e.type.label,length:e.length||0,color:e.color,netboxId:e.id,netboxType:"cable",status:e.status.value,terminationA:e.termination_a.name,terminationB:e.termination_b.name}}),Ac=(e,t={})=>{let o=[],r=[],n=new Map;return e.racks.forEach(i=>{o.push(Fa(i));}),e.devices.forEach(i=>{let d=Ha(i,t);o.push(d),n.set(i.name,d.id);}),e.cables.forEach(i=>{let d=Da(i),a=(typeof i.termination_a.device.id=="number"?`device-${i.termination_a.device.id}`:void 0)??n.get(i.termination_a.device.name)??d.source,c=(typeof i.termination_b.device.id=="number"?`device-${i.termination_b.device.id}`:void 0)??n.get(i.termination_b.device.name)??d.target;r.push({...d,source:a,target:c});}),{nodes:o,edges:r}},Lc=(e,t)=>{let o=new Map,r=new Set;return e.filter(i=>i.position!==null).sort((i,d)=>(i.position||0)-(d.position||0)).forEach(i=>{i.position&&(o.set(i.id,i.position),r.add(i.position));}),o};function _r(e){let{items:t,checkOutOfBounds:o,checkConflicts:r}=e,n=[],i=[];for(let d of t){let a=o(d);a&&!a.isValid&&a.error&&i.push(a.error);}for(let d=0;d<t.length;d++){let a=t[d];for(let c=d+1;c<t.length;c++){let l=t[c],b=r(a,l);b&&b.hasConflict&&b.conflict&&n.push(b.conflict);}}return {isValid:n.length===0&&i.length===0,conflicts:n,outOfBounds:i}}var Co=class extends Error{constructor(o,r,n,i,d){super(`Device placement conflict: ${r} at U${n}-${n+i-1} in rack ${o}${d?` conflicts with ${d}`:""}`);this.rackId=o;this.deviceId=r;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function jn(e,t={}){let o=$e(e);return _r({items:e.devices,checkOutOfBounds:r=>r.unit+r.height-1>e.units?{isValid:false,error:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,rackUHeight:e.units}}:null,checkConflicts:(r,n)=>{let i=r.unit,d=r.unit+r.height-1,a=n.unit,c=n.unit+n.height-1;if(i<=c&&d>=a){if(o){let l=Ve(r),b=Ve(n);if(!Qo(l,b))return null}return {hasConflict:true,conflict:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,conflictWith:n.id}}}return null}})}function _a(e,t,o={}){let{deviceTypeMapping:r={}}=o,n=r[e.type]||"device",i=go(t,e.unit,e.height,e);return {id:e.id,type:n,position:i,parentId:t.id,extent:"parent",data:{label:e.name,status:e.status||"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections,frontImageUrl:e.frontImageUrl,rearImageUrl:e.rearImageUrl,frontImageAttribution:e.frontImageAttribution,rearImageAttribution:e.rearImageAttribution,imageFit:e.imageFit,imagePosition:e.imagePosition,imageRepeat:e.imageRepeat,stretchToFit:e.stretchToFit,rackWidthPx:t.data.rackWidthPx,rackLayout:t.data.rackLayout,rackFaceGapPx:t.data.rackFaceGapPx,mountMode:Ve(e)}}}function Bc(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[],rackWidthPx:e.rackWidthPx,rackLayout:e.rackLayout,rackFaceGapPx:e.rackFaceGapPx}}}function Oc(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let d of e){let a=jn(d,t);if(!a.isValid&&o==="strict"){let c=[];throw a.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),a.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new Co(d.id,a.conflicts[0]?.deviceId||a.outOfBounds[0]?.deviceId||"unknown",a.conflicts[0]?.uPosition||a.outOfBounds[0]?.uPosition||1,a.conflicts[0]?.uHeight||a.outOfBounds[0]?.uHeight||1)}}for(let d of e){let a=Bc(d);n.push(a);for(let c of d.devices)try{let l=_a(c,a,t);i.push(l);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let b=rr(a,{id:c.id,data:{label:c.name,uHeight:c.height,mountMode:Ve(c)}},i,c.unit);if(b!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${b} due to conflict`);let f={...c,unit:b},u=_a(f,a,t);i.push(u);}else throw new Co(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Wc(e){let t=[],o=e.filter(r=>r.type==="rack");for(let r of o){let i=e.filter(d=>Do(d.type)&&d.parentId===r.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width==="full"||d.data.width==="half"?d.data.width:void 0,ports:Array.isArray(d.data.ports)?d.data.ports:void 0,connections:d.data.connections,frontImageUrl:d.data.frontImageUrl,rearImageUrl:d.data.rearImageUrl,frontImageAttribution:d.data.frontImageAttribution,rearImageAttribution:d.data.rearImageAttribution,imageFit:d.data.imageFit,imagePosition:d.data.imagePosition,imageRepeat:d.data.imageRepeat,stretchToFit:d.data.stretchToFit,mountMode:Ve(d.data)}));t.push({id:r.id,name:r.data.label,position:r.position,units:r.data.uHeight||42,uNumberingDirection:r.data.uNumberingDirection||"bottom-up",customHeaderText:r.data.customHeaderText,rackLayout:r.data.rackLayout,rackFaceGapPx:r.data.rackFaceGapPx,devices:i,rackWidthPx:r.data.rackWidthPx});}return t}function zc(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,devices:n.devices.map(i=>i.id!==o?i:{...i,unit:r})})}function Uc(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!jn({...i,devices:[...i.devices,o]},r).isValid)throw new Co(t,o.id,o.unit,o.height);return {...i,devices:[...i.devices,o]}})}function Vc(e,t,o){return e.map(r=>r.id!==t?r:{...r,devices:r.devices.filter(n=>n.id!==o)})}var vo=class extends Error{constructor(o,r,n,i){super(`Splice placement conflict: ${r} at holder ${n} in tray ${o}${i?` conflicts with ${i}`:""}`);this.trayId=o;this.spliceId=r;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function Yn(e,t={}){return _r({items:e.splices,checkOutOfBounds:o=>o.holder<1||o.holder>zt?{isValid:false,error:{spliceId:o.id,holder:o.holder,max:zt}}:null,checkConflicts:(o,r)=>o.holder===r.holder?{hasConflict:true,conflict:{spliceId:o.id,holder:o.holder,conflictWith:r.id}}:null})}function Ma(e,t){let o=e.mode==="ribbon",r=Vo(t,e.holder,o);return {id:e.id,type:"splice",position:r,parentId:t.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function Gc(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Xc(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let d of e){let a=Yn(d,t);if(!a.isValid&&o==="strict"){let c=[];throw a.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),a.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new vo(d.id,a.conflicts[0]?.spliceId||a.outOfBounds[0]?.spliceId||"unknown",a.conflicts[0]?.holder||a.outOfBounds[0]?.holder||1)}}for(let d of e){let a=Gc(d);n.push(a);for(let c of d.splices)try{let l=c.holder;if(o==="nearest"){let u={id:c.id,type:"splice",position:{x:0,y:0},data:{label:c.name,holderPosition:c.holder}},p=[...n,...i];Wo(a,u,c.holder,p)||(l=Uo(a,u,p,c.holder));}let b=l!==c.holder?{...c,holder:l}:c,f=Ma(b,a);i.push(f);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let b=[...n,...i],f=Uo(a,{id:c.id,data:{label:c.name,holderPosition:c.holder}},b,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let u={...c,holder:f},p=Ma(u,a);i.push(p);}else throw new vo(d.id,c.id,c.holder)}}}return n.push(...i),n}function jc(e){let t=[],o=e.filter(r=>r.type==="splice-tray");for(let r of o){let i=e.filter(d=>d.type==="splice"&&d.parentId===r.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb,mode:d.data.mode||"single",ribbonFiberIds:d.data.ribbonFiberIds}));t.push({id:r.id,name:r.data.label,position:r.position,splices:i});}return t}function Yc(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,splices:n.splices.map(i=>i.id!==o?i:{...i,holder:r})})}function Kc(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!Yn({...i,splices:[...i.splices,o]},r).isValid)throw new vo(t,o.id,o.holder);return {...i,splices:[...i.splices,o]}})}function Zc(e,t,o){return e.map(r=>r.id!==t?r:{...r,splices:r.splices.filter(n=>n.id!==o)})}var $a=2;var pe=e=>typeof e=="string"?e.trim():"",xt=e=>{if(typeof e=="number"&&Number.isFinite(e))return e},qc=e=>{let t=pe(e).toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20"||t==="AC")return t},Jc=(e,t)=>{if(t==="C13"||t==="C14")return "power_c13";if(t==="C19"||t==="C20")return "power_c19";if(t==="AC")return "power_ac";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")?"mgmt":o.includes("usb")?"usb":"ethernet"},Qc=e=>{if(e==="power_c13")return "C13";if(e==="power_c19")return "C19";if(e==="power_ac")return "AC"},el=e=>e.toLowerCase().replace(/_/g,"-").trim(),tl=e=>e>=1?"rackable":"zero-u",ol=e=>(e??"").toLowerCase()==="half"?"half":"full",rl=(e,t,o,r)=>{let n=r.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase();return `${e}-b${t}-${n||`p${o}`}`},Aa=(e,t)=>`${e}-${t}`.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function nl(e){let t=[],o=pe(e.manufacturer),r=pe(e.model),n=pe(e.role)||pe(e.deviceType)||pe(e.device_type)||"device",i=xt(e.uHeight)??xt(e.u_height)??0;o||t.push({severity:"warning",code:"MISSING_MANUFACTURER",message:"Template is missing manufacturer",path:"manufacturer"}),r||t.push({severity:"warning",code:"MISSING_MODEL",message:"Template is missing model",path:"model"});let d=pe(e.id)||pe(e.slug)||Aa(o,r)||"unknown",a=pe(e.slug)||Aa(o,r)||d,c=Array.isArray(e.ports)?e.ports:[],l=Array.isArray(e.rearPorts)?e.rearPorts:Array.isArray(e.rear_ports)?e.rear_ports:[],f=(Array.isArray(e.frontRearPortLinks)?e.frontRearPortLinks:Array.isArray(e.front_rear_port_links)?e.front_rear_port_links:[]).map(u=>({frontPortId:pe(u.frontPortId)||pe(u.front_port_id),rearPortId:pe(u.rearPortId)||pe(u.rear_port_id)}));return {id:d,slug:a,manufacturer:o,model:r,role:n,uHeight:i,width:pe(e.width)||void 0,frontBlocks:c,rearBlocks:l,rawLinks:f,frontImageUrl:pe(e.frontImageUrl)||pe(e.front_image_url)||void 0,rearImageUrl:pe(e.rearImageUrl)||pe(e.rear_image_url)||void 0,frontImageAttribution:pe(e.frontImageAttribution)||void 0,rearImageAttribution:pe(e.rearImageAttribution)||void 0,tags:Array.isArray(e.tags)?e.tags.map(pe).filter(Boolean):[],sourceRepository:pe(e.sourceRepository)||pe(e.source_repository)||void 0,sourcePath:pe(e.sourcePath)||pe(e.source_path)||void 0,issues:t}}function La(e,t,o){let r=pe(e.name)||`Block ${o+1}`,i=(Array.isArray(e.ports)?e.ports:[]).map((d,a)=>{let c=pe(d.label)||pe(d.name)||`Port ${a+1}`,l=qc(d.connectorType??d.connector_type),b=Jc(pe(d.type),l),f=l??Qc(b),p={id:pe(d.id)||rl(t,o,a,c),label:c,type:b,connectorType:f};if(d.position){let m=d.position,x=pe(m.side),P={},N=false;x&&["top","right","bottom","left"].includes(x)&&(P.side=x,N=true);let v=xt(m.offsetPercent)??xt(m.offset_percent);v!==void 0&&(P.offsetPercent=v,N=true);let C=xt(m.offsetPx)??xt(m.offset_px);C!==void 0&&(P.offsetPx=C,N=true);let F=xt(m.xPercent)??xt(m.x_percent);F!==void 0&&(P.xPercent=F,N=true);let w=xt(m.yPercent)??xt(m.y_percent);w!==void 0&&(P.yPercent=w,N=true),N&&(p.position=P);}return p});return {name:r,ports:i}}function il(e){let t=[],o=el(e.role),r=e.uHeight,n=tl(r),i=ol(e.width),d=e.frontBlocks.map((c,l)=>La(c,"front",l)),a=e.rearBlocks.map((c,l)=>La(c,"rear",l));return {role:o,mountClass:n,uHeight:r,width:i,frontFace:{portBlocks:d,imageUrl:e.frontImageUrl,imageAttribution:e.frontImageAttribution},rearFace:{portBlocks:a,imageUrl:e.rearImageUrl,imageAttribution:e.rearImageAttribution},issues:t}}function al(e,t){let o=new Set(e.portBlocks.map(i=>i.name)),r=new Set(t.portBlocks.map(i=>i.name)),n=[...o].filter(i=>r.has(i));return n.length===0?{front:e,rear:t}:{front:{...e,portBlocks:e.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Front \xB7 ${i.name}`}:i)},rear:{...t,portBlocks:t.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Rear \xB7 ${i.name}`}:i)}}}function sl(e){let t=[],{front:o,rear:r}=al(e.frontFace,e.rearFace),n=e.role;return (!n||n==="device")&&[...o.portBlocks,...r.portBlocks].some(d=>d.ports.some(a=>a.type&&a.type.startsWith("power")))&&e.mountClass==="zero-u"&&(n="pdu"),{frontFace:o,rearFace:r,mountClass:e.mountClass,role:n,issues:t}}function Yo(e){return e.portBlocks.reduce((t,o)=>t+o.ports.length,0)}function dl(e,t){let o=[],r=[];for(let p of t.frontFace.portBlocks)for(let m of p.ports)r.push({id:m.id,face:"front"});for(let p of t.rearFace.portBlocks)for(let m of p.ports)r.push({id:m.id,face:"rear"});let n=new Map;for(let{id:p}of r)n.set(p,(n.get(p)??0)+1);for(let[p,m]of n)m>1&&o.push({severity:"error",code:"DUPLICATE_PORT_ID",message:`Duplicate port id "${p}" found ${m} times`,path:`ports.${p}`});let i=e.frontBlocks.reduce((p,m)=>p+(Array.isArray(m.ports)?m.ports.length:0),0),d=e.rearBlocks.reduce((p,m)=>p+(Array.isArray(m.ports)?m.ports.length:0),0),a=Yo(t.frontFace),c=Yo(t.rearFace);a!==i&&o.push({severity:"error",code:"FRONT_PORT_COUNT_MISMATCH",message:`Front port count mismatch: raw=${i}, parsed=${a}`,path:"faces.front"}),c!==d&&o.push({severity:"error",code:"REAR_PORT_COUNT_MISMATCH",message:`Rear port count mismatch: raw=${d}, parsed=${c}`,path:"faces.rear"});let l=new Set(r.map(p=>p.id)),b=new Set(r.filter(p=>p.face==="front").map(p=>p.id)),f=new Set(r.filter(p=>p.face==="rear").map(p=>p.id));for(let p of e.rawLinks)p.frontPortId&&!b.has(p.frontPortId)&&!l.has(p.frontPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_FRONT_PORT_MISSING",message:`Pass-through link references unknown front port "${p.frontPortId}"`,path:"frontRearPortLinks"}),p.rearPortId&&!f.has(p.rearPortId)&&!l.has(p.rearPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_REAR_PORT_MISSING",message:`Pass-through link references unknown rear port "${p.rearPortId}"`,path:"frontRearPortLinks"});return {valid:!o.some(p=>p.severity==="error"),issues:o,portCounts:{front:a,rear:c}}}function cl(e,t,o){let r=e.rawLinks.filter(i=>!!i.frontPortId&&!!i.rearPortId).map(i=>({frontPortId:i.frontPortId,rearPortId:i.rearPortId})),n=e.sourceRepository?{kind:"netbox",repository:e.sourceRepository,path:e.sourcePath}:void 0;return {templateSchemaVersion:2,id:e.id,slug:e.slug,manufacturer:e.manufacturer,model:e.model,role:o.role,mountClass:o.mountClass,uHeight:t.uHeight,width:t.width,faces:{front:o.frontFace,rear:o.rearFace},frontRearPortLinks:r,images:{front:o.frontFace.imageUrl??null,rear:o.rearFace.imageUrl??null},source:n,tags:e.tags.length>0?e.tags:void 0}}function ll(e){let t=nl(e),o=il(t),r=sl(o),n=dl(t,r);return n.issues.push(...t.issues,...o.issues,...r.issues),n.valid?{template:cl(t,o,r),report:n}:{template:null,report:n}}function ul(e){return Yo(e)}function pl(e,t,o){let r=[],n=Yo(e.faces.front),i=Yo(e.faces.rear);return t!==n&&r.push({severity:"error",code:"RENDER_FRONT_COUNT_MISMATCH",message:`Rendered front handle count (${t}) does not match template (${n})`,path:"faces.front"}),o!==i&&r.push({severity:"error",code:"RENDER_REAR_COUNT_MISMATCH",message:`Rendered rear handle count (${o}) does not match template (${i})`,path:"faces.rear"}),r}
|
|
2
|
-
export{
|
|
1
|
+
import Qe,{useState,useMemo,useRef,useEffect,useSyncExternalStore,Component,useCallback}from'react';import {useReactFlow,Handle,Position,getBezierPath,BaseEdge,EdgeLabelRenderer,useUpdateNodeInternals,useEdges,addEdge,ReactFlowProvider,useNodesState,useEdgesState,applyNodeChanges,useOnSelectionChange,ReactFlow,Background,Controls,MiniMap,Panel,applyEdgeChanges,ConnectionMode,getSmoothStepPath,SmoothStepEdge}from'reactflow';import {toPng}from'html-to-image';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var Je=20,xt=60,Zr=300,Eo=5;function li(e){return e==="system"?typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e}function ui(e,t){let r=li(e)==="light"?"react-flow-light":"react-flow-dark";return t?`${r} ${t}`:r}function pi(e){return li(e)==="light"?"#e5e5e5":"#2a2a2a"}function fi(e,t){return {width:"100%",height:"100%",...t}}var us=["device","server","switch","router"],ps=new Set(us);function Ho(e){return typeof e=="string"&&ps.has(e)}function Ke(e){return !!e&&Ho(e.type)}var fs=24;function gs(e){return e?.rackLayout==="split-face"?"split-face":"single-face"}function He(e){return gs(e)==="split-face"}function $t(e){return typeof e?.rackFaceGapPx=="number"&&Number.isFinite(e.rackFaceGapPx)&&e.rackFaceGapPx>=0?e.rackFaceGapPx:fs}function _t(e){return e?.rackWidthPx||300}function Fo(e){let t=_t(e);return He(e)?t*2+$t(e):t}function Oe(e){return e?.mountMode==="front"||e?.mountMode==="rear"||e?.mountMode==="both"?e.mountMode:"both"}function Mt(e){return e==="front"?["front"]:e==="rear"?["rear"]:["front","rear"]}function Qo(e,t){let o=new Set(Mt(e));return Mt(t).some(n=>o.has(n))}function qr(e,t){return He(e)&&Oe(t)==="front"?_t(e)+$t(e):0}function gi(e,t){return He(e)&&Oe(t)==="both"?Fo(e):_t(e)}var bs=()=>"bottom-up",Xt=e=>e.data.uNumberingDirection||bs(),er=(e,t,o)=>o==="bottom-up"?t-e+1:e,tr=(e,t,o)=>o==="bottom-up"?t-e+1:e;var or=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data.uHeight||1,i=t.data.uHeight||42,s=Xt(t),d=60,c=o.y-d,l=Math.round(c/20)+1,g;s==="bottom-up"?g=er(l,i,s)-n+1:g=er(l,i,s);let f=i-n+1,u=Math.max(1,Math.min(f,g));if(s==="top-down"&&g<=1&&(u=1),!Jr(t,e,u,r)){let b=rr(t,e,r,u);b!==u&&(u=b);}let p;if(s==="bottom-up"){let b=u+n-1,w=tr(b,i,s);p=d+(w-1)*20-1;}else {let b=tr(u,i,s);p=d+(b-1)*20-1;}return {x:qr(t.data,e.data),y:p,uPosition:u}},Jr=(e,t,o,r)=>{let n=t.data.uHeight||1,i=e.data.uHeight||42;if(o<1||o+n-1>i)return false;let s=r.filter(l=>Ho(l.type)&&l.parentId===e.id&&l.id!==t.id),d=He(e.data),c=Oe(t.data);for(let l of s){let g=l.data.uPosition||1,f=l.data.uHeight||1,u=o,p=o+n-1,b=g,w=g+f-1;if(u<=w&&p>=b){if(d){let N=Oe(l.data);if(!Qo(c,N))continue}return false}}return true},rr=(e,t,o,r=1)=>{let n=t.data.uHeight||1,i=e.data.uHeight||42;for(let s=r;s<=i-n+1;s++)if(Jr(e,t,s,o))return s;return 1},po=(e,t,o=1,r)=>{let n=60,i=Xt(e),s=e.data.uHeight||42,d=tr(t,s,i),c;if(i==="bottom-up"){let l=t+o-1,g=tr(l,s,i);c=n+(g-1)*20-1;}else c=n+(d-1)*20-1;return {x:qr(e.data,r),y:c}},bi=(e,t,o)=>{let r=e.data.uHeight||1,n=po(t,o,r,e.data),i=Array.isArray(e.data.ports)?e.data.ports:void 0;return {...e,position:n,data:{...e.data,ports:i,uPosition:o}}},ms=(e,t)=>{let o=e.data.uPosition||1,r=e.data.uHeight||1,n=t.data.uHeight||42,i=Math.max(1,Math.min(n-r+1,o));return i!==o?bi(e,t,i):e};function gt(e){switch(e){case "active":return "#10b981";case "inactive":return "#ef4444";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var Qr=({data:e,selected:t,id:o,onViewChange:r,onRackFaceChange:n,isDragOver:i=false})=>{let{label:s,ports:d=0,status:c="active",uHeight:l=42,face:g="front",customHeaderText:f}=e,u=He(e),p=Fo(e),b=_t(e),w=$t(e),{getNodes:N,setNodes:k}=useReactFlow(),T=N(),[C,S]=useState(e.showUMarkers!==void 0?e.showUMarkers:true),x=()=>{let A=Xt({data:e})==="bottom-up"?"top-down":"bottom-up";k(_=>_.map(U=>U.id===o?{...U,data:{...U.data,uNumberingDirection:A}}:U));},v=()=>{if(u)return;let E=g==="front"?"rear":"front";n?n(o,E):r?T.filter(_=>_.parentId===o).forEach(_=>{r(_.id,E);}):k(A=>A.map(_=>_.id===o?{..._,data:{..._.data,face:E}}:_.parentId===o?{..._,data:{..._.data,view:E}}:_));},D=()=>{let E=[],A=60,_=Xt({data:e});for(let U=1;U<=l;U++){let se=A+(U-1)*20-4,Y=er(U,l,_);E.push(jsx("div",{style:{position:"absolute",left:"-35px",top:`${se}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${20}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:Y},U));}return E};return jsxs("div",{className:`rack-node ${t?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${gt(c)}`,borderRadius:"8px",padding:0,width:`${p}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:s}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxs("span",{children:[typeof d=="number"?d:0," ports"]})," \u2022 ",l,"U \u2022 ",u?"rear|front":g]}),jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),S(!C);},style:{background:C?"#10b981":"#374151",color:C?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${C?"Hide":"Show"} U markers`,children:"U"}),jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),x();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch U numbering to ${Xt({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Xt({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),!u&&jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),v();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${g==="front"?"rear":"front"} view`,children:g==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"},children:u&&jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[jsx("div",{style:{width:`${b}px`,borderRight:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.15)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Rear"}),jsx("div",{style:{width:`${w}px`}}),jsx("div",{style:{width:`${b}px`,borderLeft:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.25)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Front"})]})}),C&&jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:D()})]})};var en=({data:e,selected:t})=>{let{label:o,status:r="active"}=e;return jsxs("div",{className:`fiber-node ${t?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${gt(r)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsx(Handle,{type:"target",position:Position.Top}),jsx(Handle,{type:"source",position:Position.Bottom}),jsx(Handle,{type:"target",position:Position.Left}),jsx(Handle,{type:"source",position:Position.Right}),jsx("div",{style:{textAlign:"center"},children:jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:gt(r),borderRadius:"50%"}})]})};var mi=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function Ue(e){let t=(e-1)%12;return mi[t]}function Yt(e){return e>12}function Nt(e,t){let o=t?.base??Ue(e),r=t?.striped??Yt(e),n=r?`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`:void 0;return {base:o,striped:r,backgroundImage:n}}function tn(e){let t=Nt(e);return t.backgroundImage?{background:t.base,backgroundImage:t.backgroundImage}:{background:t.base}}function Kt(e){return Ue(e)}function kt(e){return e.map(t=>({base:Ue(t),striped:Yt(t)}))}function Ns(e,t,o,r,n,i,s,d){let c=kt(o),l=c.length,g=r?1.2:1,f=!!d?.highlight,u=r?2:1.5,p=d?.highlightWidth??u*3,b=d?.highlightColor??c[0]?.base??"#22d3ee";return jsxs(Fragment,{children:[f&&jsx(BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:b,strokeWidth:p,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${u}px`,"--rn-edge-highlight-to":`${p}px`}}),c.map((w,N)=>{let T=(l-N)*g;return jsx("path",{d:t,stroke:w.base,strokeWidth:T,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:n},`${e}-ribbon-${N}`)}),c.some(w=>w.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&d&&(d.bandwidth||d.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${s}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[d.bandwidth&&jsx("div",{children:d.bandwidth}),d.length&&jsxs("div",{children:[d.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var ar=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,data:d,selected:c,style:l={},className:g})=>{let[f,u,p]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:s}),{bandwidth:b,length:w,color:N="#00FFFF",striped:k=false,ribbonFiberIds:T,isRibbon:C,highlight:S,highlightColor:x,highlightWidth:v}=d||{},D=!!S;if((C||T&&T.length>=6&&T.length<=12)&&T)return Ns(e,f,T,c??false,l??{},u,p,d);let A=c?3:2,_=v??A*3,U={...l,stroke:N,strokeWidth:A,strokeDasharray:"none"};return jsxs(Fragment,{children:[D&&jsx(BaseEdge,{id:`${e}-highlight`,path:f,style:{...l,stroke:x??N,strokeWidth:_,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${A}px`,"--rn-edge-highlight-to":`${_}px`}}),jsx(BaseEdge,{id:e,path:f,style:U}),k&&jsx(BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsx(EdgeLabelRenderer,{children:c&&d&&(b||w)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${u}px,${p}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${N}`,pointerEvents:"none",zIndex:9999},children:[b&&jsx("div",{children:b}),w&&jsxs("div",{children:[w,"m"]})]})})]})};var on=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,style:d={},data:c,markerEnd:l})=>{let[g]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:s}),f=c?.connectorType||"C13",u=c?.metadata??{},p=typeof c?.powerStrokeWidth=="number"?c.powerStrokeWidth:typeof u.strokeWidth=="number"?u.strokeWidth:void 0,b=typeof c?.powerStrokeDasharray=="string"?c.powerStrokeDasharray:typeof u.strokeDasharray=="string"?u.strokeDasharray:void 0,w=typeof c?.powerOpacity=="number"?c.powerOpacity:typeof u.opacity=="number"?u.opacity:void 0;return jsx(BaseEdge,{id:e,path:g,markerEnd:l,style:(()=>{let T=p??(f==="C19"?5:3),C=b??(f==="C19"?"none":"6,3");return {...{stroke:c?.color||"#f59e0b",strokeWidth:T,strokeLinecap:"round",strokeLinejoin:"round",...w!==void 0?{opacity:w}:{}},strokeDasharray:C,...d}})()})};function Rs(e,t,o,r,n,i,s,d,c,l,g){let f=kt(d),u=f.length,p=c?1.8:1.5,b=!!g?.highlight,w=c?3:2.5,N=g?.highlightWidth??w*3,k=g?.highlightColor??f[0]?.base??"#22d3ee",[T,C,S]=getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s});return jsxs(Fragment,{children:[b&&jsx(BaseEdge,{id:`${e}-highlight`,path:T,style:{...l,stroke:k,strokeWidth:N,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${w}px`,"--rn-edge-highlight-to":`${N}px`}}),f.map((x,v)=>{let E=(u-v)*p;return jsx("path",{d:T,stroke:x.base,strokeWidth:E,fill:"none",strokeLinecap:"butt",opacity:x.striped?.9:1,style:l},`${e}-ribbon-${v}`)}),f.some(x=>x.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:T,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:c&&g&&(g.bandwidth||g.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${C}px,${S}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[g.bandwidth&&jsx("div",{children:g.bandwidth}),g.length&&jsxs("div",{children:[g.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[d.length,"F"]})]})})]})}var xi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,data:d,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",ribbonFiberIds:u,isRibbon:p,highlight:b,highlightColor:w,highlightWidth:N}=d||{},k=!!b;if((p||u&&u.length>=6&&u.length<=12)&&u)return Rs(e,t,o,r,n,i,s,u,c??false,l??{},d);let C=c?4:3,S=N??C*3,x={...l,stroke:f,strokeWidth:C};return jsxs(Fragment,{children:[k&&jsx(BaseEdge,{id:`${e}-highlight`,path:getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s})[0],style:{...l,stroke:w??f,strokeWidth:S,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${S}px`}}),jsx(SmoothStepEdge,{...g,id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,data:d,selected:c,style:x})]})};function Is({sourceX:e,sourceY:t,targetX:o,targetY:r,sourcePosition:n,targetPosition:i}){let s=n===Position.Left||n===Position.Right,d;if(s){let c=(e+o)/2;d=`M ${e},${t} L ${c},${t} L ${c},${r} L ${o},${r}`;}else {let c=(t+r)/2;d=`M ${e},${t} L ${e},${c} L ${o},${c} L ${o},${r}`;}return d}function Es(e,t,o,r,n,i){let s=kt(o),d=s.length,c=r?1.2:1,l=!!i?.highlight,g=r?2:1.5,f=i?.highlightWidth??g*3,u=i?.highlightColor??s[0]?.base??"#22d3ee",p=t.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),b=p?(parseFloat(p[1])+parseFloat(p[3]))/2:0,w=p?(parseFloat(p[2])+parseFloat(p[4]))/2:0;return jsxs(Fragment,{children:[l&&jsx(BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:u,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${g}px`,"--rn-edge-highlight-to":`${f}px`}}),s.map((N,k)=>{let C=(d-k)*c;return jsx("path",{d:t,stroke:N.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:N.striped?.9:1,style:n},`${e}-ribbon-${k}`)}),s.some(N=>N.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&i&&(i.bandwidth||i.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${b}px,${w}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${s[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsx("div",{children:i.bandwidth}),i.length&&jsxs("div",{children:[i.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var Pi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,data:d,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",striped:u=false,ribbonFiberIds:p,isRibbon:b,highlight:w,highlightColor:N,highlightWidth:k}=d||{},T=!!w,C=Is({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:s});if((b||p&&p.length>=6&&p.length<=12)&&p)return Es(e,C,p,c??false,l??{},d);let x=c?3:2,v=k??x*3,D={...l,stroke:f,strokeWidth:x,strokeDasharray:"none"};return jsxs(Fragment,{children:[T&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...l,stroke:N??f,strokeWidth:v,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${x}px`,"--rn-edge-highlight-to":`${v}px`}}),jsx(BaseEdge,{id:e,path:C,style:D}),u&&jsx(BaseEdge,{id:`${e}-stripe`,path:C,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var Ti=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,style:d={},data:c,markerEnd:l,selected:g})=>{let{color:f="#6366f1",label:u,highlight:p,highlightColor:b,highlightWidth:w}=c||{},N=!!p,k=8,T=w??k*1.8,[C,S,x]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:s}),v={...d,stroke:f,strokeWidth:k,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxs(Fragment,{children:[N&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...d,stroke:b??f,strokeWidth:T,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${b??f}) drop-shadow(0 0 16px ${b??f})`,"--rn-edge-highlight-from":`${k}px`,"--rn-edge-highlight-to":`${T}px`}}),jsx(BaseEdge,{id:e,path:C,markerEnd:l,style:v}),u&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${S}px,${x}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:u})})]})};var Ri=(o=>(o.FULL="full",o.HALF="half",o))(Ri||{});var nn={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},AC:{type:"AC",color:"#60a5fa",borderColor:"#2563eb",amperage:15,voltage:120,phases:1}};function Lt(e){let t=nn[e];if(!t)throw new Error(`Unknown connector type: ${e}`);let o=t.amperage===16,r=t.type==="AC",n=o?12:r?10:8*1.3,i=o?10:r?7:5*1.3,s=o||r?{borderRadius:r?"2px":"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:i,color:t.color,borderColor:t.borderColor,fontSize:o?"3px":r?"3.5px":"4px",...s}}function Si(e){let t=nn[e];if(!t)throw new Error(`Unknown connector type: ${e}`);return t}function Ms(e){return Si(e).amperage===16}function dr(e){return e%10<8?"C13":"C19"}function an(e){let t=e.toLowerCase();return t.includes("mx304")||t.includes("mx480")||t.includes("mx960")?"C20":"C14"}var $s=/-(source|target)$/i;function We(e){return e?e.replace($s,""):""}function Pt(e){return typeof e=="string"&&e.includes("power")}function Ct(e,t){return typeof t.id=="string"&&t.id.length>0?t.id:Pt(t.type)?t.label:`${e}-${t.label}`}function cr(e){let t=We(e).toLowerCase();return t.startsWith("pwr")||t.includes("power")}var Ls="#6b7280",Bs="#374151",sn="#10b981",Os="100% 100%",lr=1,Ws={smf:"#fbbf24",cat6:"#8b5cf6",om3:"#06b6d4",om4:"#8b5cf6",om5:"#84cc16",cat5e:"#3b82f6",cat6a:"#ef4444",cat7:"#f97316",fiber:"#3b82f6",ethernet:"#10b981"},zs=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,Us=/^data:image\//i,Vs=typeof window<"u"?Qe.useLayoutEffect:Qe.useEffect;function Gs(e){return (e??"").toLowerCase().replace(/_/g,"-")}function Xs(e){return !zs.test(e)&&!e.startsWith("//")}function js(e){if(!e)return;let t=e.trim();if(t){if(Xs(t))return t;try{let o=new URL(t),r=o.protocol.toLowerCase();return r==="https:"||r==="blob:"?o.href:r==="data:"&&Us.test(t)?t:void 0}catch{return}}}function Ys(e){return `url(${JSON.stringify(e)})`}function ln(e){return Pt(e.type)}function un(e,t){if(typeof e.connectorType=="string"&&e.connectorType.trim().length>0)return e.connectorType;let o=String(e.type??"").toLowerCase();return o.includes("c19")||o.includes("c20")?"C19":o.includes("c13")||o.includes("c14")?"C13":o.includes("power_ac")?"AC":an(t)}function dn(e,t){return Ct(e,t)}function Ks(e,t,o,r,n){let i=t.length>0||!!r,s=o.length>0||!!n;return e||(i?"front":s?"rear":"front")}function Zs(e,t){return t===true||e==="fill"?Os:e==="none"?"auto":e==="scale-down"?"contain":e??"cover"}function qs(e){return ln(e)?e.type==="power_c19"?"#fbbf24":"#f59e0b":e.type==="console"||e.type==="mgmt"?"#8b5cf6":e.type==="usb"?sn:e.cableType?Ws[e.cableType]??sn:sn}function Js(e){return e.connected?qs(e):Ls}function Ei(e){return e.map(t=>{let o=t.ports.map(r=>{let n=r.position?[r.position.side??"",r.position.offsetPercent??"",r.position.offsetPx??"",r.position.xPercent??"",r.position.yPercent??""].join(":"):"";return [r.id??"",r.label,r.type??"",r.connected?"1":"0",r.cableType??"",r.connectorType??"",n].join(":")}).join(",");return `${t.name}[${o}]`}).join("|")}function Qs(e,t,o,r,n=false){return {width:`${e}px`,height:`${t}px`,minWidth:n?`${e}px`:void 0,minHeight:n?`${t}px`:void 0,background:o,border:`0.5px solid ${r}`,boxSizing:"border-box",borderRadius:"1px",cursor:"pointer",zIndex:2}}function ed(e){let t=Math.max(5,Math.min(7,Math.round(e*.02))),o=Math.max(8,Math.min(10,Math.round(t*1.45)));return {width:t,height:o}}function Ao(e){return Math.max(0,Math.min(100,e))}function it(e,t,o){return Math.max(t,Math.min(o,e))}function cn(e){return typeof e.position?.xPercent=="number"&&typeof e.position?.yPercent=="number"}function td(e,t,o,r,n){let i=[];for(let g of e)for(let f of g.ports)cn(f)&&i.push({handleId:dn(g.name,f),xPercent:Ao(f.position.xPercent),yPercent:Ao(f.position.yPercent),side:f.position?.side});if(i.length===0)return {heightByHandleId:new Map,bottomAnchoredHandleIds:new Set};let s=new Set,d=[...new Set(i.map(g=>Number(g.yPercent.toFixed(2))))].sort((g,f)=>g-f);if(d.length>=2){let g=d[d.length-1];for(let f of i)f.side==="top"&&Math.abs(f.yPercent-g)<=.15&&s.add(f.handleId);}let c=new Map,l=Math.max(1.75,(r+1)/Math.max(t,1)*100+.2);for(let g of i){let f=Number.POSITIVE_INFINITY;for(let w of i){if(w.handleId===g.handleId||Math.abs(w.xPercent-g.xPercent)>l)continue;let k=Math.abs(w.yPercent-g.yPercent);k<=0||(f=Math.min(f,k));}if(!Number.isFinite(f))continue;let u=o*f/100,p=Math.floor(u-.25),b=it(p,1,n);b<n&&c.set(g.handleId,b);}return {heightByHandleId:c,bottomAnchoredHandleIds:s}}function od(e){switch(e){case "top":return Position.Top;case "right":return Position.Right;case "bottom":return Position.Bottom;case "left":return Position.Left;default:return Position.Top}}function rd(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function nd(e,t,o,r,n,i,s){if(!e.position)return;if(typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number"){let w=Ao(e.position.xPercent),N=Ao(e.position.yPercent),k=s??e.position.side??rd(w,N),T=t/2+lr,C=Math.max(T,r-t/2),S=o/2+lr,x=Math.max(S,n-o/2),v=it(r*w/100,T,C),D=it(n*N/100,S,x);return {position:od(k),style:{left:`${v-t/2-lr}px`,top:`${D-o/2-lr}px`,right:"initial",bottom:"initial",transform:"none"}}}if(!e.position.side)return;let c=e.position.side,l=typeof e.position.offsetPercent=="number"?Ao(e.position.offsetPercent):void 0,g=typeof e.position.offsetPx=="number"?e.position.offsetPx:void 0,f=t/2,u=Math.max(f,r-t/2),p=o/2,b=Math.max(p,n-o/2);switch(c){case "top":{let w=g!==void 0?g:r*(l??50)/100,N=it(w,f,u);return {position:Position.Top,style:{top:"0px",left:`${N}px`,right:void 0,bottom:void 0,transform:"translate(-50%, 50%)"}}}case "bottom":{let w=g!==void 0?g:r*(l??50)/100,N=it(w,f,u);return {position:Position.Bottom,style:{bottom:"0px",left:`${N}px`,right:void 0,top:void 0,transform:"translate(-50%, -50%)"}}}case "left":{let w=g!==void 0?g:n*(l??50)/100,N=it(w,p,b);return {position:Position.Left,style:{left:"0px",top:`${N}px`,right:void 0,bottom:void 0,transform:"translate(50%, -50%)"}}}case "right":{let w=g!==void 0?g:n*(l??50)/100,N=it(w,p,b);return {position:Position.Right,style:{right:"0px",top:`${N}px`,left:void 0,bottom:void 0,transform:"translate(-50%, -50%)"}}}default:return}}function Fi(e,t,o,r){let n=o/2,i=Math.max(n,r-o/2);return t===1?(n+i)/2:n+e*(i-n)/(t-1)}function Di(e,t,o,r){let n=e%2===0,i=Math.ceil(t/2),s=Math.floor(t/2),d=Math.max(n?i:s,1),c=Math.floor(n?e/2:(e-1)/2),l=Fi(c,d,o,r);return n?{position:Position.Top,style:{transform:"translateY(50%)",left:`${l-o/2}px`}}:{position:Position.Bottom,style:{transform:"translateY(-50%)",left:`${l-o/2}px`}}}function Hi(e,t,o,r,n,i){let s=e%2===0,d=Math.ceil(t/2),c=Math.floor(t/2),l=Math.max(s?d:c,1),g=Math.floor(s?e/2:(e-1)/2),f=Fi(g,l,o,n),u=1,p=it(Math.round(r*.75),1,4),b=Math.max(u,i-r-1),w=it(u+r+p,u,b),N=s?u:w;return {position:Position.Top,style:{transform:"none",left:`${f-o/2}px`,top:`${N}px`,right:void 0,bottom:void 0}}}function id(e,t,o,r,n){let i=un(e,n),s=Lt(i),d;if(r<=20){let g=Math.max(2,r-s.height-2);d=`${o<=1?(2+g)/2:2+t*(g-2)/(o-1)}px`;}else d=`${25+t*50}%`;return {position:Position.Right,style:{transform:"translateX(-50%)",top:d,width:`${s.width}px`,height:`${s.height}px`,background:s.color,border:`1px solid ${s.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:s.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:s.borderRadius,clipPath:s.clipPath}}}function ad(e,t,o,r){if(t===1){let n=Math.max(6,Math.round(r*.04)),i=Math.max(o/2,r-n-o/2);return {position:Position.Top,style:{transform:"translateY(50%)",left:`${i}px`,right:void 0}}}return Di(e,t,o,r)}function sd(e,t,o,r,n,i,s,d,c){if(d==="patch-panel"||d==="switch")return Di(t,o,r,i);if(ln(e)){let f=un(e,c),u=Lt(f),p;if(s<=20){let N=Math.max(2,s-u.height-2);p=`${o<=1?(2+N)/2:2+t*(N-2)/(o-1)}px`;}else p=`${25+t*50}%`;return {position:Position.Left,style:{transform:"translateX(50%)",top:p,width:`${u.width}px`,height:`${u.height}px`,background:u.color,border:`1px solid ${u.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:u.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:u.borderRadius,clipPath:u.clipPath}}}return {position:Position.Right,style:{transform:"translate(-50%, -50%)",top:`${it(o<=1?s/2:n/2+t*Math.max(s-n,0)/Math.max(o-1,1),n/2,Math.max(n/2,s-n/2))}px`}}}function dd(e,t,o,r){if(e)return {primary:"target"};let n=t==="patch-panel";return t==="switch"||t==="router"?{primary:"source",secondary:"target"}:n?o==="rear"?{primary:"source",secondary:"target"}:{primary:"target",secondary:"source"}:{primary:r?"source":"target"}}var go=({id:e,data:t,selected:o})=>{let r=useUpdateNodeInternals(),{label:n,status:i="active",deviceType:s="server",manufacturer:d,uHeight:c=1,width:l="full",ports:g,rearPorts:f,view:u,rackWidthPx:p,frontImageUrl:b,rearImageUrl:w,imageFit:N,imagePosition:k,imageRepeat:T,stretchToFit:C}=t,S=Qe.useMemo(()=>Array.isArray(g)?g:[],[g]),x=Qe.useMemo(()=>Array.isArray(f)?f:[],[f]),v=Gs(s),D=p??300,E=He(t),A=Oe(t),_=Ks(u,S,x,b,w),U=Qe.useMemo(()=>E?Mt(A):[_],[E,A,_]),se=U[0]??_,Y=E&&A==="both",ee=c*20,ie=$t(t),z=D+ie,V=Qe.useMemo(()=>[E?"split":"single",A,U.join(","),se,v,n,ee.toString(),D.toString(),z.toString(),Ei(S),Ei(x)].join("|"),[E,A,U,se,v,n,ee,D,z,S,x]);Vs(()=>{r(e);},[V,e,r]);let B=Qe.useCallback(j=>{let ke=js(j==="rear"?w:b);return ke?{backgroundImage:Ys(ke),backgroundSize:Zs(N,C),backgroundPosition:k??"center",backgroundRepeat:T??"no-repeat"}:{}},[w,b,N,C,k,T]),O=Qe.useMemo(()=>B("front"),[B]),X=Qe.useMemo(()=>B("rear"),[B]),te=se==="rear"?X:O,M,L;if(E)M=`${gi(t,t)+4}px`,L=void 0;else {let j=D+4,ye=Math.floor(D/2);M=l==="half"?`${ye}px`:`${j}px`,L=l==="half"?`${ye}px`:void 0;}let de=v==="server"&&c===1,ae=gt(i),ce={"--rn-device-bg-image":Y?"none":String(te.backgroundImage??"none"),"--rn-device-bg-position":String(te.backgroundPosition??"center"),"--rn-device-bg-repeat":String(te.backgroundRepeat??"no-repeat"),"--rn-device-bg-size":String(te.backgroundSize??"cover"),"--rn-device-border-color":ae,"--rn-device-box-shadow":o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)","--rn-device-height":`${ee}px`,"--rn-device-left":L??"auto","--rn-device-status-color":ae,"--rn-device-translate-y":de?"-1px":"0px","--rn-device-width":M},q=Qe.useMemo(()=>{let j=new Set;for(let ye of S)for(let ke of ye.ports)j.add(dn(ye.name,ke));return j},[S]),xe=Qe.useCallback((j,ye)=>ye==="rear"&&Y&&q.has(j)?`${j}--rear`:j,[q,Y]),Ce=Qe.useCallback((j,ye,ke=0,st=D)=>{let le=[];if(j.length===0)return le;let{width:Ge,height:Fe}=ed(st),{heightByHandleId:Ar,bottomAnchoredHandleIds:Pe}=td(j,st,ee,Ge,Fe),De=j.reduce((ze,Ze)=>ze+Ze.ports.length,0),zt=(v==="switch"||v==="patch-panel")&&De>=24,jo=v==="switch"||v==="patch-panel";for(let ze of j)for(let Ze=0;Ze<ze.ports.length;Ze+=1){let ve=ze.ports[Ze],ot=dn(ze.name,ve),dt=ln(ve),It=Ge,ct=Fe;if(dt){let yt=un(ve,n),ao=Lt(yt);It=ao.width,ct=ao.height;}else if(cn(ve)){let yt=Ar.get(ot);yt!==void 0&&(ct=yt,It=it(Math.round(ct*1.2),3,Ge));}let lt=Js(ve),Yo=ve.connected?lt:Bs,Lr=!dt&&cn(ve)&&ct<Fe,Ko=Qs(It,ct,lt,Yo,Lr),Ut=ye==="front"?dt?id(ve,Ze,ze.ports.length,ee,n):zt?Hi(Ze,ze.ports.length,Ge,Fe,st,ee):ad(Ze,ze.ports.length,Ge,st):!dt&&zt?Hi(Ze,ze.ports.length,Ge,Fe,st,ee):sd(ve,Ze,ze.ports.length,Ge,Fe,st,ee,v,n),Vt=nd(ve,It,ct,st,ee,void 0,jo&&Pe.has(ot)?"bottom":void 0),Et=Vt?dt?{position:Vt.position,style:{...Ut.style,...Vt.style}}:Vt:Ut,_e={...{...Ko,...Et.style}};_e.left!==void 0&&ke!==0&&(typeof _e.left=="number"?_e.left=`${_e.left+ke}px`:_e.left=`calc(${_e.left} + ${ke}px)`),Y&&_e.left===void 0&&(Et.position===Position.Left?(_e.left=`${ke}px`,_e.right=void 0):Et.position===Position.Right&&(_e.left=`${ke+st}px`,_e.right=void 0));let Ht=xe(ot,ye),ut=dd(dt,v,ye,ve.connected);if(ut.secondary){let yt=v==="switch"||v==="router"?{..._e,background:"transparent",border:"none",opacity:0}:_e,ao=v==="switch"||v==="router"?`${ze.name} - ${ve.label} (input) ${ve.connected?"(connected)":"(disconnected)"}`:`${ze.name} - ${ve.label} (${ut.secondary}) ${ve.connected?"(connected)":"(disconnected)"}`;le.push(jsx(Handle,{id:`${Ht}-${ut.secondary}`,type:ut.secondary,position:Et.position,style:yt,title:ao},`${Ht}-${ut.secondary}`));}le.push(jsx(Handle,{id:Ht,type:ut.primary,position:Et.position,style:_e,title:`${ze.name} - ${ve.label} ${ve.connected?"(connected)":"(disconnected)"}`,children:dt?Ze+1:void 0},Ht));}return le},[ee,D,n,v,xe,Y]),Ne=Qe.useMemo(()=>{let j=[];for(let ye of U){if(ye==="front"&&S.length>0){let ke=Y?z:0;j.push(...Ce(S,"front",ke,D));}ye==="rear"&&x.length>0&&j.push(...Ce(x,"rear",0,D));}return j},[U,S,x,Ce,D,Y,z]);return jsxs("div",{className:`device-node ${o?"selected":""} ${Y?"device-node--split-both":""}`,style:ce,children:[Y&&jsxs("div",{className:"device-node__split-face-layer",style:{position:"absolute",inset:0,display:"flex",pointerEvents:"none",zIndex:0},children:[jsx("div",{className:"device-node__split-face device-node__split-face--rear",style:{width:`${D}px`,backgroundImage:String(X.backgroundImage??"none"),backgroundPosition:String(X.backgroundPosition??"center"),backgroundRepeat:String(X.backgroundRepeat??"no-repeat"),backgroundSize:String(X.backgroundSize??"cover")}}),jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${ie}px`},children:jsx("div",{className:"device-node__face-bridge-line"})}),jsx("div",{className:"device-node__split-face device-node__split-face--front",style:{width:`${D}px`,backgroundImage:String(O.backgroundImage??"none"),backgroundPosition:String(O.backgroundPosition??"center"),backgroundRepeat:String(O.backgroundRepeat??"no-repeat"),backgroundSize:String(O.backgroundSize??"cover")}})]}),jsxs("div",{className:"device-node__content",style:{position:"relative",zIndex:1},children:[jsx("div",{className:"device-node__label",children:n}),c>1&&jsx("div",{className:"device-node__manufacturer",children:d})]}),c>1&&jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),jsx("div",{className:"device-node__status-indicator"}),Ne]})};var pr=20,mo=3,gr=2,cd=1,fn=2,gn=6,ld=12;function pn(e){return Math.max(0,Math.min(100,e))}function _i(e,t,o){return Math.max(t,Math.min(o,e))}function ud(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function fr(e){if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13")return "C13";if(t==="C19")return "C19";if(t==="AC")return "AC"}function pd(e,t){let o=fr(e.connectorType);if(o)return o;let r=String(e.type??"").toLowerCase();return r.includes("c19")?"C19":r.includes("c13")?"C13":r.includes("power_ac")?"AC":t}function fd(e){return Array.isArray(e.pduPortGroups)&&e.pduPortGroups.length>0?e.pduPortGroups:Array.isArray(e.rearPorts)&&e.rearPorts.length>0?e.rearPorts:Array.isArray(e.ports)&&e.ports.length>0?e.ports:[]}function gd(e,t){return !Array.isArray(e.portTypes)||e.portTypes.length===0?Array.from({length:t},(o,r)=>fr(dr(r))??"C13"):Array.from({length:t},(o,r)=>{let n=fr(e.portTypes?.[r]);return n||(fr(dr(r))??"C13")})}function bd(e,t){let o=fd(e),r=gd(e,t);if(o.length===0)return Array.from({length:t},(s,d)=>({id:`${d+1}`,label:`${d+1}`,connectorType:r[d]??"C13",groupName:"Power"}));let n=[],i=0;return o.forEach(s=>{s.ports.forEach(d=>{let c=r[i]??"C13";n.push({id:Ct(s.name,d),label:d.label,connectorType:pd(d,c),groupName:s.name,position:d.position}),i+=1;});}),n}function $i(e,t,o){return t===o?ld:Lt(e.connectorType).height}function md(e,t){if(e.length===0)return Math.max(gr+mo+1,1);let o=0;for(let r=0;r<e.length;r+=1)o+=$i(e[r],r,t),r<e.length-1&&(o+=e[r].groupName===e[r+1].groupName?fn:gn);return gr+o+mo}function hd(e,t,o){if(e.length===0)return [];let r=e.map((b,w)=>$i(b,w,o)),n=[];for(let b=0;b<e.length-1;b+=1)n.push(e[b].groupName===e[b+1].groupName?fn:gn);let i=r.reduce((b,w)=>b+w,0),s=n.reduce((b,w)=>b+w,0),d=i+s,c=Math.max(t-gr-mo,1),l=0,g=n,f=Math.max(0,c-d);if(f>0)if(n.length===0)l=f/2;else {let b=n.map(N=>N===gn?1.2:1),w=b.reduce((N,k)=>N+k,0);g=n.map((N,k)=>w<=0?N:N+f*b[k]/w);}let u=[],p=gr+l;for(let b=0;b<r.length;b+=1){let w=r[b];u.push(p+w/2),p+=w,b<r.length-1&&(p+=g[b]??fn);}return u}function yd(e,t,o,r,n,i){if(!e)return {position:Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let s=e.side,d=s==="left"?Position.Left:s==="top"?Position.Top:s==="bottom"?Position.Bottom:Position.Right,c=typeof e.offsetPercent=="number"?pn(e.offsetPercent):void 0,l=typeof e.offsetPx=="number"?e.offsetPx:void 0,g=typeof e.xPercent=="number"?pn(e.xPercent):void 0,f=typeof e.yPercent=="number"?pn(e.yPercent):void 0;if(g!==void 0&&f!==void 0){let b=s??ud(g,f),w=b==="left"?Position.Left:b==="top"?Position.Top:b==="bottom"?Position.Bottom:Position.Right,N=Math.max(o-mo,1),k=r*g/100,T=_i(N*f/100,i/2,Math.max(i/2,o-i/2));return {position:w,leftPx:k-n/2,topPx:T-i/2}}let u=g!==void 0?r*g/100:r-n/2-1,p=f!==void 0?Math.max(o-mo,1)*f/100:t;return s==="top"||s==="bottom"?(l!==void 0?u=l:c!==void 0&&(u=r*c/100),p=s==="top"?i/2:o-i/2):(l!==void 0?p=l:c!==void 0&&(p=Math.max(o-mo,1)*c/100),s==="left"?u=n/2:s==="right"&&(u=r-n/2-1)),p=_i(p,i/2,Math.max(i/2,o-i/2)),{position:d,leftPx:u-n/2,topPx:p-i/2}}function wd(e,t){return !e||t<=0?-1:e==="top"?0:e==="bottom"?t-1:Math.floor(t/2)}function xd(e,t){return jsxs("div",{style:{position:"absolute",left:`${(t-16)/2}px`,top:`${e-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsx(Handle,{type:"source",position:Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit")}var bn=({data:e,selected:t})=>{let{label:o,status:r="active",heightCm:n=100,powerPorts:i=36,widthPx:s=15,mgmt_unit:d}=e,c=Math.max(0,i),l=bd(e,c),g=wd(d,l.length),f=n*4.2,u=md(l,g),p=Math.max(f-pr,u),b=Math.max(s-cd*2,1),w=pr+p,N=hd(l,p,g);return jsxs("div",{className:`vertical-pdu-node ${t?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${gt(r)}`,borderRadius:"2px",padding:0,width:`${s}px`,height:`${w}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",boxSizing:"border-box",position:"relative",display:"flex",flexDirection:"column"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:`${pr}px`,display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${w-pr}px`,overflow:"hidden"},children:l.map((k,T)=>{let C=N[T]??p/2;if(g===T)return xd(C,b);let S=Lt(k.connectorType),x=yd(k.position,C,p,b,S.width,S.height);return jsx(Handle,{type:"source",position:x.position,id:k.id,style:{position:"absolute",left:`${x.leftPx}px`,top:`${x.topPx}px`,right:"initial",bottom:"initial",width:`${S.width}px`,height:`${S.height}px`,background:S.color,border:`1px solid ${S.borderColor}`,boxSizing:"border-box",transform:"none",cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:S.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:S.borderRadius,clipPath:S.clipPath},title:`${k.groupName} - ${k.label} (${k.connectorType})`,children:k.label},`handle-${k.id}`)})})]})};var yn=({data:e,selected:t,id:o})=>{let{lossDb:r,mode:n="single",ribbonFiberIds:i}=e||{},s=useEdges(),d=s.find(x=>x.target===o&&x.targetHandle==="left"),c=s.find(x=>x.source===o&&x.sourceHandle==="right"),l=s.find(x=>x.target===o&&x.targetHandle==="right"),g=c||l,f=d?.data?.color||"#555",u=g?.data?.color||"#555",p=n==="ribbon",b=d?.data?.ribbonFiberIds||i,w=g?.data?.ribbonFiberIds||i,N=p&&b?kt(b):null,k=p&&w?kt(w):null,T=!!d&&!!g;return jsxs("div",{className:`splice-node ${t?"selected":""}`,style:{width:p?85:69,height:p?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"none"},children:[p&&N&&k?jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:N.map((x,v)=>jsx("div",{style:{flex:1,background:x.base,opacity:x.striped?.9:1}},`left-${v}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:k.map((x,v)=>jsx("div",{style:{flex:1,background:x.base,opacity:x.striped?.9:1}},`right-${v}`))})]}):jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsx("div",{style:{background:f}}),jsx("div",{style:{background:u}})]}),jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),T&&jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),T&&typeof r=="number"&&jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:p?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsx("div",{children:`${r.toFixed(2)} dB`}),p&&i&&jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsx(Handle,{type:"target",position:Position.Left,id:"left",isConnectable:true,style:{width:12,height:p&&N?20:12,borderRadius:p&&N?"6px":"50%",border:"none",background:p&&N?`linear-gradient(to bottom, ${N.map(x=>x.base).join(", ")})`:f,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsx(Handle,{type:"source",position:Position.Right,id:"right",isConnectable:true,style:{width:12,height:p&&k?20:12,borderRadius:p&&k?"6px":"50%",border:"none",background:p&&k?`linear-gradient(to bottom, ${k.map(x=>x.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsx(Handle,{type:"target",position:Position.Right,id:"right",isConnectable:true,style:{width:12,height:p&&k?20:12,borderRadius:p&&k?"6px":"50%",border:"none",background:p&&k?`linear-gradient(to bottom, ${k.map(x=>x.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Oo=20,br=36;var Jt=32,Li=4,Bt=12,kd=69,Qt=80,wn=(Qt-kd)/2;var xn=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data?.mode==="ribbon",i=n?br:Oo,s=n?32:16,d=Jt,c=o.y-d,l=Math.round(c/i)+1,f=Math.max(1,Math.min(Bt,l));if(!Bo(t,e,f,r)){let b=Wo(t,e,r,f);if(b!==f){let w=(i-s)/2;return {x:wn,y:d+(b-1)*i+w,holderPosition:b}}}let u=(i-s)/2,p=d+(f-1)*i+u;return {x:wn,y:p,holderPosition:f}},Bo=(e,t,o,r)=>!r.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==t.id).some(i=>i.data.holderPosition===o),Wo=(e,t,o,r=1)=>{for(let n=r;n<=Bt;n++)if(Bo(e,t,n,o))return n;for(let n=r-1;n>=1;n--)if(Bo(e,t,n,o))return n;return 1},Pd=(e,t)=>zo(e,t,false),zo=(e,t,o=false)=>{let r=Jt,n=o?br:Oo,s=(n-(o?32:16))/2,d=r+(t-1)*n+s;return {x:wn,y:d}};var Pn=({data:e,selected:t})=>{let{label:o="Splice Tray"}=e||{},[r,n]=useState(false),i=()=>{if(!r)return null;let s=[],d=Jt;for(let c=1;c<=Bt;c++){let l=d+(c-1)*Oo;s.push(jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${Oo}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return s};return jsxs("div",{className:`splice-tray-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${Qt}px`,height:`${Jt+Bt*br+Li}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${Jt}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),jsx("button",{onPointerDown:s=>{s.stopPropagation();},onMouseDown:s=>{s.stopPropagation();},onClick:s=>{s.stopPropagation(),s.preventDefault(),n(!r);},style:{background:r?"#10b981":"#374151",color:r?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${r?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsx("div",{style:{position:"absolute",top:Jt,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Cn=({data:e,selected:t,id:o})=>{let{fibersPerTube:r=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},s=e?.mode==="ribbon"||e?.ribbon===true,d=useEdges(),c=`tube-${n}`,l=d.find(Y=>Y.source===o&&Y.sourceHandle===c||Y.target===o&&Y.targetHandle===c),g=l?.data?.color,f=Ue((n-1)%12+1),u=g||f,p=Math.max(1,Math.min(24,Number(r)||12)),b=14,w=4,N=1,k=2,T=20,C=p*b+(p-1)*w,S=Math.max(60,C+N*2+k*2),x=i==="left"?Position.Left:i==="right"?Position.Right:Position.Bottom,v=x!==Position.Bottom,D=v?14:20,E=v?8:20,A=v?`inset ${x===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",_=l?u:v?`linear-gradient(${x===Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${u}`:`radial-gradient(circle, ${u} 40%, transparent 70%)`,U={width:D,height:E,borderRadius:v?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:_,backgroundColor:u,border:l?`2px solid ${u}`:`3px dashed ${u}`,cursor:"crosshair","--fiber-bg":u,boxShadow:l?A:`${A}${A!=="none"?", ":""}0 0 8px ${u}`,transition:"opacity 0.2s, box-shadow 0.2s",...x===Position.Left?{left:-(D-4)}:x===Position.Right?{right:-(D-4)}:{}},se=useMemo(()=>{let Y=[],ee=S-k*2-N*2,ie,z,V=false;i==="left"?(ie=N,z=Position.Top):i==="right"?(ie=N+ee-C,z=Position.Top,V=true):(ie=N+(ee-C)/2,z=Position.Top);for(let B=0;B<p;B++){let O=V?p-B:B+1,X=`fiber-${O}`,te=d.find(Ce=>Ce.source===o&&Ce.sourceHandle===X||Ce.target===o&&Ce.targetHandle===X),M=!!te&&(te.data?.isRibbon||te.data?.ribbonFiberIds&&Array.isArray(te.data.ribbonFiberIds)),L=te?.data?.color,de=typeof te?.data?.striped=="boolean"?te.data.striped:void 0,ae=Nt(O);s||M?ae=Nt(O,{base:"#808080",striped:false}):(L||de!==void 0)&&(ae=Nt(O,{...L?{base:L}:{},...de!==void 0?{striped:de}:{}}));let ce=ie+B*(b+w),q=N,xe={position:"absolute",left:`${ce}px`,top:`${q}px`,width:b,height:b,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":ae.base,backgroundColor:ae.base};ae.backgroundImage&&(xe["--fiber-bg-image"]=ae.backgroundImage),Y.push(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:xe,"data-fiber-idx":O,"data-fiber-color":ae.base}),jsx(Handle,{id:X,type:"source",position:z,className:"tube-fiber-handle",isConnectable:true,style:xe,"data-fiber-idx":O,"data-fiber-color":ae.base})]},`fiber-${O}`));}return Y},[p,i,S,d,o,b,w,N,k,C,s]);return jsxs("div",{style:{width:S,height:T,borderRadius:4,background:"#111827",border:`${k}px solid ${t?"#3b82f6":u}`,position:"relative",boxShadow:t?`0 0 0 ${k}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:N,boxSizing:"border-box",overflow:"visible"},children:[se,jsx(Handle,{id:c,type:"target",position:x,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":u,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsx(Handle,{id:c,type:"source",position:x,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":u,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var Rn=({data:e,selected:t})=>{let{fiberCount:o,cableId:r="CBL-002",label:n,color:i,rotation:s}=e||{},d=Qe.useRef(null);Qe.useEffect(()=>{if(d.current){let z=typeof s=="number"?s:0;d.current.style.transform=`rotate(${z}deg)`,d.current.style.transformOrigin="center center";}},[s]);let c=Math.max(1,Math.min(24,Number(o)||12)),l=10,g=2,f=6,u=f+l+4,p=60,b=Math.max(120,c*(l+g)+f*2),N=n??`${c}f Cable`,k=r?`Cable ID ${r}`:void 0,T=Ue(1),C=i||T,S=t?"#3b82f6":C,x=typeof s=="number"?s:0,v=z=>{let V=(z%360+360)%360;return V>=315||V<45?Position.Top:V>=45&&V<135?Position.Right:V>=135&&V<225?Position.Bottom:Position.Left},D=()=>{let z=[],V=v(x);for(let B=0;B<c;B++){let O=B+1,X=Nt(O),te=X.base,M=f+B*(l+g),L=-5,de=X.backgroundImage?X.backgroundImage:te,ae={position:"absolute",left:`${M}px`,top:`${L}px`,width:l,height:l,borderRadius:"50%",border:"none",background:de,backgroundColor:te,zIndex:10,cursor:"pointer","--fiber-bg":te};X.backgroundImage&&(ae["--fiber-bg-image"]=X.backgroundImage);let ce=`fiber-${O}`;z.push(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:ce,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te}),jsx(Handle,{id:ce,type:"source",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te})]},`fiber-${O}`));}return z},E="cable-button",A=8,_={width:A,height:A,borderRadius:"50%",background:C,backgroundColor:C,border:`1px solid ${C}`,cursor:"pointer",zIndex:10},U=2,Y=(z=>{let V=(z%360+360)%360;return V>=315||V<45?Position.Bottom:V>=45&&V<135?Position.Left:V>=135&&V<225?Position.Top:Position.Right})(x),ee={width:b,height:p,position:"relative",transform:`rotate(${x}deg)`,transformOrigin:"center center","--rotation":`${x}deg`},ie={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${U}px solid ${S}`,boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:f,paddingTop:u,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsx("div",{ref:d,style:ee,children:jsxs("div",{style:ie,children:[D(),jsx(Handle,{id:E,type:"source",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsx(Handle,{id:E,type:"target",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:N}),k&&jsx("div",{style:{fontSize:10,opacity:.8},children:k})]})]})})};var In=({data:e,selected:t})=>{let{tubeCount:o=12,fibersPerTube:r=12,fiberCount:n,cableId:i="CBL-002",label:s,tubeStartIndex:d=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(o)||12)),g=Math.max(1,Number(d)||1),f=14,u=10,p=3,b=6,w=b+u+4,N=60,k=Math.max(120,l*(f+p)+b*2),T=n??l*(Number(r)||12),C=s??`${T}f Cable`,S=i?`Cable ID ${i}`:void 0,x=Ue(g),v=c||x,D=t?"#3b82f6":v,E=()=>{let Y=[];for(let ee=0;ee<l;ee++){let ie=g+ee,z=Nt(ie),V=z.base,B=b+ee*(f+p),O=-5,X=z.backgroundImage?z.backgroundImage:V,te={position:"absolute",left:`${B}px`,top:`${O}px`,width:f,height:u,borderRadius:6,border:"none",background:X,backgroundColor:V,zIndex:10,cursor:"pointer","--fiber-bg":V};z.backgroundImage&&(te["--fiber-bg-image"]=z.backgroundImage);let M=`tube-${ie}`;Y.push(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:M,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V}),jsx(Handle,{id:M,type:"source",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V})]},`tube-${ie}`));}return Y},A="cable-button",_=8,U={width:_,height:_,borderRadius:"50%",background:v,backgroundColor:v,border:`1px solid ${v}`,cursor:"pointer",zIndex:10};return jsxs("div",{style:{width:k,height:N,borderRadius:4,background:"#111827",border:`2px solid ${D}`,position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:b,paddingTop:w,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[E(),jsx(Handle,{id:A,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":v}),jsx(Handle,{id:A,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":v}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:C}),S&&jsx("div",{style:{fontSize:10,opacity:.8},children:S})]})]})};var En=({data:e,selected:t,id:o})=>{let{connector:r="LC",couplerFiberCount:n,label:i,portLabelsLeft:s,portLabelsRight:d}=e||{},c=useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,g=Math.max(1,Math.min(4,l)),f=9,u=3,p=3,b=60,w=30,N=g*f+(g-1)*u,k=Math.max(w,N+p*2),T=Math.max(b,80),C=(v,D)=>{let E=`${v}-${D+1}`;return c.find(_=>_.source===o&&_.sourceHandle===E||_.target===o&&_.targetHandle===E)?.data?.color||"#555"},S=v=>{let D=[],E=v==="left"?Position.Left:Position.Right,A=v==="left"?s:d;for(let _=0;_<g;_++){let U=_+1,se=`${v}-${U}`,Y=C(v,_),z=p+(k-N)/2+_*(f+u),V={position:"absolute",left:v==="left"?-5:void 0,right:v==="right"?-5:void 0,top:`${z}px`,width:f,height:f,borderRadius:"50%",border:"none",background:Y,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};D.push(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:se,type:"target",position:E,isConnectable:true,style:V}),jsx(Handle,{id:se,type:"source",position:E,isConnectable:true,style:V})]},se)),A&&A[_]&&D.push(jsx("div",{style:{position:"absolute",left:v==="left"?-30:void 0,right:v==="right"?-30:void 0,top:`${z}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:v==="left"?"right":"left",width:"25px"},children:A[_]},`${se}-label`));}return D},x=i||`${r}-${g}f`;return jsxs("div",{className:`coupler-node ${t?"selected":""}`,style:{width:T,height:k,borderRadius:4,border:`2px solid ${t?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${p}px`,boxSizing:"border-box"},children:[S("left"),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:x})}),S("right")]})};var oo=32,Pr=30,Hd=24,Fd=80,Nr=400,kr=300,Xi=2,to=8,ji=120;function Fn(e){let{couplerFiberCount:t}=e.data||{},o=typeof t=="number"&&[1,2,4].includes(t)?t:2,r=Math.max(1,Math.min(4,o)),n=7,i=3,s=3,d=60,c=30,l=r*n+(r-1)*i,g=Math.max(c,l+s*2);return {width:Math.max(d,80),height:g}}function Cr(e){let{fibersPerTube:t=12}=e.data||{},o=Math.max(1,Math.min(24,Number(t)||12)),r=14,n=4,i=1,s=2,d=20,c=o*r+(o-1)*n;return {width:Math.max(60,c+i*2+s*2),height:d}}function Yi(e){return {width:Qt,height:0}}function Ki(e){return e.type==="coupler"?Fn(e):e.type==="tube"?Cr(e):e.type==="splice-tray"?Yi():{width:80,height:30}}function Hn(e){let t=0;for(let o of e){let r=Ki(o),n=(o.position?.x||0)+r.width;n>t&&(t=n);}return t}function Zi(e,t=0){let o=t;for(let r of e){let n=Ki(r),i=(r.position?.y||0)+n.height;i>o&&(o=i);}return o}function qi(e){return e.data?.panelWidth||Nr}function Dd(e){return e.data?.panelHeight||kr}function Ji(e){return qi(e)-Xi*2-to*2}function _d(e,t){return Ji(e)-t}function Qi(e,t=Pr){return Math.floor(e/t)+1}function ea(e,t=Pr){return (e-1)*t}function Md(e,t,o){let r=Pr,n=Qi(o.y,r),i=ea(n,r);return {x:o.x,y:i,slotPosition:n}}function Dn(e,t){if(t.length===0)return {width:e.data?.panelWidth||Nr,height:e.data?.panelHeight||kr};let o=t.some(c=>c.type==="tube"),r=t.some(c=>c.type==="splice-tray"),n=t.some(c=>c.type==="coupler"),i;if(o&&r&&n){let c=0,l=0;for(let u of t)if(u.type==="tube"){let p=Cr(u);p.width>c&&(c=p.width);}else if(u.type==="coupler"){let p=Fn(u);p.width>l&&(l=p.width);}let g=c+ji+Qt+l+5,f=0;i=f+g+f;}else i=Hn(t)+4;i=Math.max(e.data?.panelWidth||Nr,i);let s=Zi(t,oo),d=Math.max(e.data?.panelHeight||kr,s+to);return {width:i,height:d}}function ta(e,t,o){if(e===0)return 0;if(e===1)return t;let r=e*t,n=o-r,i=Math.max(5,n/(e-1));return t+i}function $d(e,t,o){return ta(e,t,o)}var Ui=20,Vi=400,Gi=300;function _n(e,t){if(t.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||Vi,height:e.data?.closureHeight||e.data?.panelHeight||Gi};let o=t.some(d=>d.type==="tube"),r=t.some(d=>d.type==="splice-tray"),n;if(o&&r){let d=0,c=0,l=0,g=t.filter(u=>u.type==="tube"),f=t.filter(u=>u.type==="splice-tray");if(g.length>0&&f.length>0){let u=f.map(b=>b.position?.x||0),p=u.reduce((b,w)=>b+w,0)/u.length;for(let b of g){let w=Cr(b);(b.position?.x||0)<p?w.width>d&&(d=w.width):w.width>c&&(c=w.width);}f.length>0&&(l=Qt),n=to+d+Ui+l+Ui+c+5;}else n=Hn(t)+to+5;}else n=Hn(t)+to+5;n=Math.max(e.data?.closureWidth||e.data?.panelWidth||Vi,n);let i=Zi(t,oo),s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Gi,i+to);return {width:n,height:s}}var An=({data:e,selected:t,id:o})=>{let{label:r="Patch Panel",header:n,panelWidth:i,panelHeight:s}=e||{},{getNodes:d,setNodes:c}=useReactFlow(),l=useRef(false),g=useRef([]),f=useMemo(()=>{let C=d().filter(S=>S.parentId===o);return (C.length!==g.current.length||C.some((S,x)=>S.id!==g.current[x]?.id))&&(g.current=C),g.current},[d,o]),u=useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:s}}),[o,e,i,s]),p=useMemo(()=>i&&s?{width:i,height:s}:f.length===0?{width:i||400,height:s||300}:Dn(u,f),[f,u,i,s]);useEffect(()=>{if(i&&s||l.current)return;let T=i,C=s,S=Math.abs((T||0)-p.width),x=Math.abs((C||0)-p.height);(S>1||x>1)&&(l.current=true,c(v=>v.map(D=>D.id===o?{...D,data:{...D.data,panelWidth:p.width,panelHeight:p.height}}:D)),setTimeout(()=>{l.current=false;},0));},[o,p.width,p.height,i,s,c]);let b=p.width,w=p.height,N=oo,k=n||r;return jsxs("div",{className:`patch-panel-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${b}px`,height:`${w}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${N}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:k})}),jsx("div",{style:{position:"absolute",top:N,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var On=({data:e,selected:t,id:o})=>{let{label:r="Closure",header:n,closureWidth:i,closureHeight:s,panelWidth:d,panelHeight:c}=e||{},{getNodes:l,setNodes:g}=useReactFlow(),f=useRef(false),u=useRef([]),p=useMemo(()=>{let v=l().filter(D=>D.parentId===o);return (v.length!==u.current.length||v.some((D,E)=>D.id!==u.current[E]?.id))&&(u.current=v),u.current},[l,o]),b=useMemo(()=>({id:o,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||d,closureHeight:s||c}}),[o,e,i,s,d,c]),w=useMemo(()=>i&&s?{width:i,height:s}:d&&c?{width:d,height:c}:p.length===0?{width:i||d||400,height:s||c||300}:_n(b,p),[p,b,i,s,d,c]);useEffect(()=>{if(i&&s||d&&c||f.current)return;let x=i||d,v=s||c,D=Math.abs((x||0)-w.width),E=Math.abs((v||0)-w.height);(D>1||E>1)&&(f.current=true,g(A=>A.map(_=>_.id===o?{..._,data:{..._.data,closureWidth:w.width,closureHeight:w.height}}:_)),setTimeout(()=>{f.current=false;},0));},[o,w.width,w.height,i,s,d,c,g]);let N=w.width,k=w.height,T=oo,C=n||r,S=N/2;return jsxs("div",{className:`closure-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${S}px ${S}px 12px 12px`,padding:0,width:`${N}px`,height:`${k}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${T}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${S}px ${S}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:C})}),jsx("div",{style:{position:"absolute",top:T,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var zn=({data:e,selected:t,id:o})=>{let{label:r,splitterType:n="splitter",inputCount:i=1,outputCount:s=8}=e||{},d=useEdges(),c=r||(n==="WDM"?"WDM":"Splitter"),l=9,g=3,f=3,u=50,p=30,b=Math.min(Math.max(i||1,1),2),w=b*l+(b-1)*g,N=Math.min(s||8,48),k=N*l+(N-1)*g,T=Math.max(w,k),C=Math.max(p,T+f*2),S=Math.max(u,50),x=ee=>d.find(z=>z.source===o&&z.sourceHandle===ee||z.target===o&&z.targetHandle===ee)?.data?.color||"#555",v=()=>{let ee=[],ie=f+(C-w)/2;for(let z=0;z<b;z++){let V=`input-${z+1}`,B=ie+z*(l+g),O=x(V),X={position:"absolute",left:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};ee.push(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Left,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position:Position.Left,isConnectable:true,style:X})]},V));}return ee},D=()=>{let ee=[],ie=f+(C-k)/2;for(let z=0;z<N;z++){let V=`output-${z+1}`,B=ie+z*(l+g),O=x(V),X={position:"absolute",right:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};ee.push(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Right,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position:Position.Right,isConnectable:true,style:X})]},V));}return ee},E=Math.max(w+f*4,p*.6),A=(C-E)/2,_=A+E,U=0,se=C,Y=t?"#3b82f6":"#4b5563";return jsxs("div",{className:`trapezoid-node ${t?"selected":""}`,style:{width:S,height:C,position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${f}px`,boxSizing:"border-box"},children:[jsx("svg",{width:S,height:C,viewBox:`0 0 ${S} ${C}`,style:{position:"absolute",top:0,left:0,width:`${S}px`,height:`${C}px`,pointerEvents:"none",zIndex:0},children:jsx("polygon",{points:`0,${A} 0,${_} ${S},${se} ${S},${U}`,fill:"#1f2937",stroke:Y,strokeWidth:"2"})}),v(),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:c})}),D()]})};var ia=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",Rr=(e,t)=>ia(e)||ia(t),re=(e,t)=>t?e?.type==="fibre-split"?We(t):We(t):t||"";function Sr(e,t){if(!e||!t)return "unknown";let o=We(t);if(!o)return "unknown";if(e.type==="vertical-pdu")return "power";let r=e.data??{},n=Array.isArray(r.ports)?r.ports:[],i=Array.isArray(r.rearPorts)?r.rearPorts:[];for(let l of [...n,...i])for(let g of l.ports||[])if(Ct(l.name,{id:g.id,label:g.label,type:Pt(g.type)?g.type:void 0})===o)return Pt(g.type)?"power":"network";if(cr(o)||/^\d+$/.test(o))return "power";let s=o.toLowerCase(),d=s.startsWith("net-")||s.startsWith("port-")||s.startsWith("uplink-")||s.includes("fiber")||s.includes("ports"),c=/^[A-Z0-9]+-\d+$/i.test(o)&&!s.startsWith("pwr")&&!s.startsWith("power");return d||c?"network":"unknown"}function ro(e,t){return Sr(e,t)==="power"}function Vd(e,t){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=t.nodes.find(M=>M.id===e.source),r=t.nodes.find(M=>M.id===e.target),n=Rr(o,r);if(!n){let M=Sr(o,e.sourceHandle),L=Sr(r,e.targetHandle);if(M!=="unknown"&&L!=="unknown"&&M!==L)return {valid:false,reason:`Cannot connect ${M} handle to ${L} handle`};let de=M==="power"&&L==="power",ae=o?.type==="vertical-pdu"||r?.type==="vertical-pdu";if(de&&!ae)return {valid:false,reason:"Power connections must include a PDU endpoint"}}let i=re(o,e.sourceHandle),s=re(r,e.targetHandle),d=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.source===e.source?re(o,M.sourceHandle)===i:M.target===e.source?re(o,M.targetHandle)===i:false),c=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.target===e.target?re(r,M.targetHandle)===s:M.source===e.target?re(r,M.sourceHandle)===s:false);if((d||c)&&!n)return d?{valid:false,reason:`Source handle ${e.sourceHandle} on node ${e.source} is already connected`}:{valid:false,reason:`Target handle ${e.targetHandle} on node ${e.target} is already connected`};let l=(M,L)=>(M?.type==="tube"||M?.type==="cable")&&!!L&&L.startsWith("fiber-"),g=(M,L)=>(M?.type==="tube"||M?.type==="multi-tube-cable")&&!!L&&L.startsWith("tube-"),f=(M,L)=>M?.type==="multi-tube-cable"&&!!L&&L.startsWith("tube-"),u=(M,L)=>M?.type==="tube"&&!!L&&L.startsWith("tube-"),p=(M,L)=>(M?.type==="cable"||M?.type==="multi-tube-cable")&&L==="cable-button",b=(M,L)=>M?.type==="splice"&&(L==="left"||L==="right"),w=(M,L)=>M?.type==="coupler"&&!!L&&(L.startsWith("left-")||L.startsWith("right-")),N=(M,L)=>{if(M?.type!=="fibre-split"||!L)return false;let de=re(M,L);return de.startsWith("input-")||de.startsWith("output-")};if(!n)return {valid:true};if(o?.type==="splice"&&r?.type==="splice"){let M=o.data?.mode==="ribbon",L=r.data?.mode==="ribbon";if(M!==L)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let k=l(o,e.sourceHandle),T=l(r,e.targetHandle),C=b(o,e.sourceHandle),S=b(r,e.targetHandle),x=w(o,e.sourceHandle),v=w(r,e.targetHandle),D=N(o,e.sourceHandle),E=N(r,e.targetHandle),A=p(o,e.sourceHandle),_=p(r,e.targetHandle),U=f(o,e.sourceHandle),se=f(r,e.targetHandle),Y=u(o,e.sourceHandle),ee=u(r,e.targetHandle),ie=g(o,e.sourceHandle),z=g(r,e.targetHandle);return k&&S||T&&C||(C&&(v||E)||S&&(x||D))||(x&&(v||E||S)||v&&(x||D||C))||A&&_||(U&&ee||se&&Y)?{valid:true}:ie&&z?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function Ir(e,t){if(!t)return;let o="--rear",r=We(e),n=r.endsWith(o);n&&(r=r.slice(0,-o.length));let i=t.data??{},s=i.handleSideMap;if(s&&s[r])return s[r];if(n)return "rear";if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let d=Array.isArray(i.ports)?i.ports:[],c=Array.isArray(i.rearPorts)?i.rearPorts:[];if(cr(r))return "rear";for(let l of d)for(let g of l.ports||[])if(Ct(l.name,{id:g.id,label:g.label,type:Pt(g.type)?g.type:void 0})===r)return "front";for(let l of c)for(let g of l.ports||[])if(Ct(l.name,{id:g.id,label:g.label,type:Pt(g.type)?g.type:void 0})===r)return "rear"}function Un(e={},t={}){let o={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},r=new Set;return {getState:()=>o,setState:f=>{o={...o,...f},r.forEach(u=>u(o));},subscribe:f=>(r.add(f),()=>r.delete(f)),selectEdgeZIndex:f=>{let u=k=>{if(typeof k.parentId=="string")return k.parentId;let T=k.parentNode;if(typeof T=="string")return T},p=k=>{let T=u(k),C=T?o.nodes.find(D=>D.id===T&&D.type==="rack"):void 0;if(C&&He(C.data))return Mt(Oe(k.data));let S=Array.isArray(k.data?.rearPorts)&&k.data.rearPorts.length>0,x=Array.isArray(k.data?.ports)&&k.data.ports.length>0;return [k.data?.view||(S&&!x?"rear":"front")]},b=(k,T)=>{let C=o.nodes.find(ee=>ee.id===k);if(!(!!C&&(C.type==="device"||C.type==="server"||C.type==="switch"||C.type==="router"))||!C||C.data?.deviceType?.toLowerCase().replace(/_/g,"-")==="patch-panel")return;let v=p(C),D=Ir(T||"",C);if(D)return v.includes(D)?1e3:500;let E=(T||"").toString().replace(/-(source|target)$/i,""),A=E.toLowerCase(),_=A.startsWith("pwr")||A.startsWith("power"),U=A.startsWith("net-")||A.startsWith("port-")||A.startsWith("uplink-")||A.includes("fiber")||A.includes("ports"),se=/^[A-Z0-9]+-\d+$/i.test(E)&&!A.startsWith("pwr")&&!A.startsWith("power"),Y=U||se;if(_)return v.includes("rear")?1e3:500;if(Y)return v.includes("front")?1e3:500},w=b(f.target,f.targetHandle);if(w!==void 0)return w;let N=b(f.source,f.sourceHandle);return N!==void 0?N:1e3},validateConnection:f=>(t.validateConnection||Vd)(f,o),selectNodeById:f=>o.nodes.find(u=>u.id===f),selectConnectedEdges:f=>o.edges.filter(u=>u.source===f||u.target===f)}}function Gd(e){let t=n=>e.subscribe(i=>n()),o=()=>e.getState();return useSyncExternalStore(t,o,o)}function Gn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return useSyncExternalStore(t,o,o)}function Xn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return useSyncExternalStore(t,o,o)}function aa(e){return e.selectEdgeZIndex}function sa(e){let t=Fo(e.data),o=60+(e.data.uHeight||42)*20,r=e.position.x,n=e.position.x+t,i=e.position.y,s=e.position.y+o;return {left:r,right:n,top:i,bottom:s}}function da(e,t){let o=sa(t);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function Er(e,t){let o=null,r=1/0;for(let n of t){if(!da(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<r&&(r=i,o=n);}return o}function Ae(e){let{edges:t,connection:o,edgeType:r,selectEdgeZIndex:n,findBy:i,matchOn:s=i,data:d}=e,c=i==="source"?o.sourceHandle:o.targetHandle,l=i==="source"?o.source:o.target;if(!c||!l)return null;let g=We(c),f=t.find(k=>s==="source"?k.source===l&&We(k.sourceHandle)===g:k.target===l&&We(k.targetHandle)===g);if(!f)return null;let u=t.filter(k=>k.id!==f.id),p=addEdge(o,u),b=p[p.length-1],w=n({...o,id:b.id,type:r}),N={...b,type:r,zIndex:w,style:{...b.style,zIndex:w},data:d!==void 0?d:b.data};return [...p.slice(0,-1),N]}function ca(e){return Array.isArray(e)?e.reduce((t,o)=>t+(Array.isArray(o.ports)?o.ports.length:0),0):0}function la(e){return typeof e=="string"&&e.trim().length>0}function jd(e){let t=ca(e.ports)>0||la(e.frontImageUrl),o=ca(e.rearPorts)>0||la(e.rearImageUrl);if(t&&o)return "both";if(t)return "front";if(o)return "rear"}function ua(e,t,o,r){let n=e.mountMode;if(n==="front"||n==="rear"||n==="both")return n;let i=jd(e);if(i)return i;if(e.view==="front"||e.view==="rear")return e.view;let s=o+r/2;return t>=s?"front":"rear"}function ga(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var Ve=({type:e,children:t})=>{let o=Qe.useRef(null),r=Qe.useCallback(n=>{if(o.current=n,n){let i=n.parentElement,s=0;for(;i&&!i.classList.contains("react-flow__node")&&s<10;)i=i.parentElement,s++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return Qe.useEffect(()=>{if(o.current){let n=o.current.parentElement,i=0;for(;n&&!n.classList.contains("react-flow__node")&&i<10;)n=n.parentElement,i++;n&&n.classList.contains("react-flow__node")&&n.setAttribute("data-type",e);}},[e]),jsx("div",{ref:r,style:{width:"100%",height:"100%"},children:t})},ba=(e,t,o)=>({rack:r=>jsx(Ve,{type:"rack",children:jsx(Qr,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsx(Ve,{type:"fiber",children:jsx(en,{...r})}),device:r=>jsx(Ve,{type:"device",children:jsx(go,{...r})}),server:r=>jsx(Ve,{type:"server",children:jsx(go,{...r})}),switch:r=>jsx(Ve,{type:"switch",children:jsx(go,{...r})}),router:r=>jsx(Ve,{type:"router",children:jsx(go,{...r})}),"vertical-pdu":r=>jsx(Ve,{type:"vertical-pdu",children:jsx(bn,{...r})}),splice:r=>jsx(Ve,{type:"splice",children:jsx(yn,{...r})}),"splice-tray":r=>jsx(Ve,{type:"splice-tray",children:jsx(Pn,{...r})}),tube:r=>jsx(Ve,{type:"tube",children:jsx(Cn,{...r})}),cable:r=>jsx(Ve,{type:"cable",children:jsx(Rn,{...r})}),"multi-tube-cable":r=>jsx(Ve,{type:"multi-tube-cable",children:jsx(In,{...r})}),coupler:r=>jsx(Ve,{type:"coupler",children:jsx(En,{...r})}),"patch-panel":r=>jsx(Ve,{type:"patch-panel",children:jsx(An,{...r})}),closure:r=>jsx(Ve,{type:"closure",children:jsx(On,{...r})}),"fibre-split":r=>jsx(Ve,{type:"fibre-split",children:jsx(zn,{...r})})});function ma(e){if(!e)return false;if(e.type==="switch")return true;if(e.type!=="device")return false;let t=e.data?.deviceType;return typeof t=="string"&&t.toLowerCase().replace(/_/g,"-")==="switch"}function ha(e,t,o){let r=e.sourceHandle,n=e.targetHandle;return ma(t)&&r&&!ro(t,r)&&(r=We(r)),ma(o)&&n&&!ro(o,n)&&(n=`${We(n)}-target`),r===e.sourceHandle&&n===e.targetHandle?e:{...e,sourceHandle:r,targetHandle:n}}var ac={fiber:ar,ethernet:ar,power:on,smoothstep:xi,step:Pi,"thick-cable":Ti},sc=8192,dc=8192,cc=2048,lc=4;function Vo(e,t,o){if(!(typeof e!="number"||Number.isNaN(e)))return Math.min(o,Math.max(t,e))}function uc(e){if(e)return {...e,width:Vo(e.width,1,sc),height:Vo(e.height,1,dc),padding:Vo(e.padding,0,cc),pixelRatio:Vo(e.pixelRatio,.1,lc),quality:Vo(e.quality,0,1)}}var pc=({nodes:e,edges:t,initialNodes:o,initialEdges:r,onNodesChange:n,onEdgesChange:i,store:s,debug:d,onNodeClick:c,onEdgeClick:l,nodeTypes:g,edgeTypes:f,onConnect:u,onEdgeUpdate:p,isValidConnection:b,connectionMode:w,onViewChange:N,onRackFaceChange:k,className:T,style:C,alignRacksToBottom:S,reAssignable:x=true,colorMode:v="dark",onInit:D,onFlowMethods:E,showDownloadButton:A=false,downloadButtonPosition:_="top-right",downloadButtonText:U="Download Image",downloadButtonStyle:se,useSmoothstepEdgesForTubes:Y=false,readOnly:ee=false,interaction:ie,actionPanel:z,connectOnClick:V=true,panOnDrag:B=true,panOnScroll:O=true,zoomOnScroll:X=true,fitViewOptions:te})=>{let M=useCallback((a,m)=>{let y=new Map,h=[],R=[],H=(F,$)=>!F||!$?false:!!(F.startsWith("tube-")||$.type==="splice"&&(F==="left"||F==="right")||F==="cable-button");for(let F of a){if(!F.source||!F.target||!F.sourceHandle||!F.targetHandle){d&&console.warn("Invalid edge skipped (missing source/target/handles):",F);continue}let $=m.find(qe=>qe.id===F.source),I=m.find(qe=>qe.id===F.target),K=`${F.source}:${F.sourceHandle}`,oe=y.get(K),Te=H(F.sourceHandle,$),Re=`${F.target}:${F.targetHandle}`,Se=y.get(Re),je=H(F.targetHandle,I);if(oe&&!Te){d&&console.warn("Duplicate connection detected on source handle, removing:",{handle:K,existingEdge:oe.id,duplicateEdge:F.id}),R.push(F);continue}if(Se&&!je){d&&console.warn("Duplicate connection detected on target handle, removing:",{handle:Re,existingEdge:Se.id,duplicateEdge:F.id}),R.push(F);continue}h.push(F),oe||y.set(K,F),Se||y.set(Re,F);}return d&&R.length>0&&console.log(`Filtered ${R.length} duplicate edge(s) from initial edges`),h},[d]),L=Array.isArray(e)&&Array.isArray(t),de=Qe.useMemo(()=>L?e||[]:o||e||[],[L,e,o]),ae=Qe.useMemo(()=>L?t||[]:r||t||[],[L,t,r]),ce=Qe.useMemo(()=>M(ae,de),[ae,de,M]),q=Qe.useMemo(()=>s||Un({nodes:de,edges:ce,debug:d}),[s,L,d,ce]),xe=Gn(q),Ce=Xn(q),[Ne,j]=useNodesState(xe),[ye,ke,st]=useEdgesState(Ce),le=aa(q),Ge=useRef(null),[Fe,Ar]=useState(false);useEffect(()=>{let a=()=>{Ar(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]);let Pe=ee===true,De=useMemo(()=>{let m={...{nodesDraggable:true,nodesConnectable:true,elementsSelectable:!Fe,edgesFocusable:!Fe,edgesReconnectable:true,connectOnClick:V,panOnDrag:B,panOnScroll:O&&!Fe,zoomOnScroll:X&&!Fe,zoomOnPinch:!Fe,zoomOnDoubleClick:!Fe,allowKeyboardDelete:true,showControls:true,showMiniMap:!Fe,showInteractiveControl:true},...ie??{}};return Pe?{...m,nodesDraggable:false,nodesConnectable:false,elementsSelectable:false,edgesFocusable:false,edgesReconnectable:false,connectOnClick:false,panOnDrag:false,panOnScroll:false,zoomOnScroll:false,zoomOnPinch:false,zoomOnDoubleClick:false,allowKeyboardDelete:false,showInteractiveControl:false}:m},[Fe,V,B,O,X,ie,Pe]),zt=useMemo(()=>({enabled:z?.enabled??true,showRearToggle:z?.showRearToggle??true,showDeRack:z?.showDeRack??true}),[z]),{toObject:jo,setViewport:ze,setNodes:Ze,setEdges:ve,getNodes:ot,getEdges:dt,fitView:It,flowToScreenPosition:ct}=useReactFlow();useEffect(()=>{E&&E({toObject:()=>jo(),setViewport:ze,setNodes:a=>{Ze(a),q.setState({nodes:a});},setEdges:a=>{ve(a),q.setState({edges:a});},toImage:a=>Ge.current?toPng(Ge.current,uc(a)):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>ot(),getEdges:()=>dt(),fitView:a=>{if(a?.nodes&&Array.isArray(a.nodes)&&a.nodes.length>0){let m=a.nodes.map(R=>ot().find(H=>H.id===R)).filter(R=>R!==void 0),{nodes:y,...h}=a;It({...h,nodes:m});}else {let{nodes:m,...y}=a||{};It(y);}}});},[E,jo,ze,Ze,ve,q,It,ot,dt]);let[lt,Yo]=useState(false),Lr=useCallback(()=>{if(!lt){if(!Ge.current){d&&console.error("ReactFlow wrapper ref is not available");return}Yo(true),toPng(Ge.current,{filter:a=>!(a?.classList?.contains("react-flow__minimap")||a?.classList?.contains("react-flow__controls")||a?.classList?.contains("react-flow__attribution")||a?.classList?.contains("download-button")||a?.tagName==="BUTTON"),backgroundColor:v==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(a=>{let m=document.createElement("a");m.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,m.href=a,m.click();}).catch(a=>{d&&console.error("Error downloading image:",a);}).finally(()=>{Yo(false);});}},[v,d,lt]),[Ko,Ut]=useState(null),Vt=useRef(null),Et=useRef(N),Br=useRef(k);useEffect(()=>{Et.current=N;},[N]),useEffect(()=>{Br.current=k;},[k]),useEffect(()=>{Vt.current=Ko;},[Ko]);let _e=useCallback((a,m)=>{Et.current?.(a,m);},[]),Ht=useCallback((a,m)=>{Br.current?.(a,m);},[]),ut=useCallback(()=>Vt.current,[]),yt=useRef({...ba(_e,Ht,ut),...g??{}});useEffect(()=>{yt.current={...ba(_e,Ht,ut),...g??{}};},[_e,Ht,ut,g]);let ao=useMemo(()=>({...ac,...f??{}}),[f]),pt=useRef(Ne);useEffect(()=>{pt.current=Ne;},[Ne]);let J=useRef(ye);useEffect(()=>{J.current=ye;},[ye]),useEffect(()=>{j(xe);},[xe,j]),useEffect(()=>{ke(Ce);},[Ce,ke]),useEffect(()=>{if(L&&t){let a=M(t,e||[]);a.length!==t.length&&(d&&console.warn(`Controlled edges had ${t.length-a.length} duplicate(s) removed`),i?.(a));}},[L,t,e,M,i,d]),useEffect(()=>{L&&q.setState({nodes:e||[]});},[L,e,q]),useEffect(()=>{L&&q.setState({edges:t||[]});},[L,t,q]),useEffect(()=>{if(!S||!Ne||Ne.length===0)return;let a=Ne.filter(I=>I.type==="rack");if(a.length===0)return;let m=a.map(I=>{let oe=I.data?.uHeight||42,Te=60+oe*20;return (I.position?.y||0)+Te}),y=Math.min(...m),h=Math.max(...m);if(h-y<20)return;let H=h,F=Ne.map(I=>{if(I.type!=="rack")return I;let oe=I.data?.uHeight||42,Te=60+oe*20,Re=(I.position?.y||0)+Te,Se=H-Re;return Math.abs(Se)<5?I:{...I,position:{x:I.position?.x||0,y:(I.position?.y||0)+Se}}});F.some((I,K)=>I.position!==Ne[K].position)&&j(F);},[S,Ne,j]);let vo=useRef(new Map);useEffect(()=>{let a=new Map;Ne.forEach(m=>{a.set(m.id,m);}),vo.current=a;},[Ne]);let ue=useCallback(a=>vo.current.get(a),[]),Xe=useCallback(a=>{if(!a)return;if(typeof a.parentId=="string")return a.parentId;let m=a.parentNode;if(typeof m=="string")return m},[]),ti=useCallback(a=>{let m=Xe(a);if(!m)return;let y=ue(m);if(!(!y||y.type!=="rack"))return y},[ue,Xe]),oi=useCallback(a=>!a||a.type!=="rack"?false:He(a.data),[]),so=useCallback(a=>{if(!a||!Ke(a))return false;let m=ti(a);return m?He(m.data):false},[ti]),Or=useCallback(a=>{if(!a||a.type!=="device")return false;let m=a.data?.deviceType;return typeof m=="string"&&m.toLowerCase().replace(/_/g,"-")==="patch-panel"},[]),Zo=useCallback(a=>{pt.current=a;let m=new Map;a.forEach(y=>{m.set(y.id,y);}),vo.current=m,j(a),L?n?.(a):q.setState({nodes:a});},[L,q,j,n]),he=useCallback(a=>{J.current=a,ke(a),L?i?.(a):q.setState({edges:a});},[L,q,ke,i]),Ft=useCallback(a=>{if(a.positionAbsolute)return a.positionAbsolute;let m=a.position?.x||0,y=a.position?.y||0,h=Xe(a),R=new Set;for(;h&&!R.has(h);){R.add(h);let H=ue(h);if(!H)break;if(H.positionAbsolute){m+=H.positionAbsolute.x,y+=H.positionAbsolute.y;break}m+=H.position?.x||0,y+=H.position?.y||0,h=Xe(H);}return {x:m,y}},[ue,Xe]),qo=useCallback(a=>{let m=Ft(a),y=a.width||0,h=a.height||0;return {x:m.x+y/2,y:m.y+h/2}},[Ft]),To=useCallback((a,m)=>{if(!a||!m)return;let y=ue(a);if(!y)return;let h=m.replace(/-(source|target)$/i,"");if(y.type==="fibre-split"&&h.startsWith("output-")){let H=J.current.filter(F=>F.target===a&&(F.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(H.length>0){let F=H[0]?.data?.color;if(F)return {color:F}}}if((y.type==="tube"||y.type==="cable")&&m.startsWith("fiber-")){let H=m.replace("fiber-",""),F=parseInt(H,10);if(F>=1&&F<=24){let $=Kt(F),I=F>12;return {color:$,striped:I}}}if((y.type==="multi-tube-cable"||y.type==="tube")&&m.startsWith("tube-")){let H=m.replace("tube-",""),F=parseInt(H,10);if(F>=1&&F<=24){let $=Ue(F),I=F>12;return {color:$,striped:I}}}let R=y.data;if(R.color)return {color:R.color}},[ue]),ri=useRef(new Map);useEffect(()=>{ke(a=>{let m=false,y=a.map(h=>{let R=le(h);return ri.current.get(h.id)!==R?(m=true,ri.current.set(h.id,R),{...h,zIndex:R,style:{...h.style,zIndex:R}}):h});return m?y:a});},[Ne,ke,le]),useEffect(()=>{let a=Ne.map(y=>{if(y.type==="coupler"&&y.parentId){let h=ue(y.parentId);if(h&&(h.type==="patch-panel"||h.type==="closure")&&(!y.extent||y.extent!=="parent"))return {...y,extent:"parent"}}if(y.type==="splice"&&y.parentId&&y.data.holderPosition&&(!y.position||y.position.x===0&&y.position.y===0)){let h=ue(y.parentId);if(h&&h.type==="splice-tray"){let R=y.data.mode==="ribbon",H=zo(h,y.data.holderPosition,R);return {...y,position:H}}}if(Ke(y)&&y.parentId&&y.data.uPosition&&(!y.position||y.position.x===0&&y.position.y===0)){let h=ue(y.parentId);if(h){let R=y.data.uHeight||1,H=po(h,y.data.uPosition,R,y.data);return {...y,position:H}}}return y});a.some((y,h)=>{let R=Ne[h];return y.extent!==R.extent||y.position?.x!==R.position?.x||y.position?.y!==R.position?.y})&&j(a);},[Ne,j,ue]);let ja=useCallback(a=>{if(Pe)return null;let m=new Map,y=new Map,h=new Set,R=a.map($=>{if($.type==="position"&&$.position){let I=ue($.id);if(I&&I.type==="coupler"&&I.parentId){let K=ue(I.parentId);if(K&&(K.type==="patch-panel"||K.type==="closure"))return (!I.extent||I.extent!=="parent")&&h.add(I.id),{...$,position:I.position||{x:0,y:0}}}if(I&&(I.type==="tube"||I.type==="splice-tray")&&I.parentId){let K=ue(I.parentId);if(K&&K.type==="closure")return (!I.extent||I.extent!=="parent")&&h.add(I.id),{...$,position:I.position||{x:0,y:0}}}if(I&&I.type==="splice"&&I.parentId){let K=ue(I.parentId);if(K&&K.type==="splice-tray"){let oe=xn(I,K,$.position,pt.current);return oe.holderPosition!==void 0&&m.set(I.id,oe.holderPosition),{...$,position:{x:oe.x,y:oe.y}}}}if(I&&Ke(I)&&I.parentId){let K=ue(I.parentId);if(K&&K.type==="rack"){let oe=or(I,K,$.position,pt.current);return oe.uPosition!==void 0&&y.set(I.id,oe.uPosition),{...$,position:{x:oe.x,y:oe.y}}}}}return $}),H=applyNodeChanges(R,pt.current).map($=>{let I=$;h.has($.id)&&(I={...I,extent:"parent"});let K=m.get($.id);K!==void 0&&(I={...I,data:{...I.data,holderPosition:K}});let oe=y.get($.id);return oe!==void 0&&(I={...I,data:{...I.data,uPosition:oe}}),I});pt.current=H;let F=new Map;return H.forEach($=>{F.set($.id,$);}),vo.current=F,j(H),H},[j,ue,Pe]),Ya=useCallback((a,m)=>{Ut(null);},[]),Ka=useCallback((a,m,y)=>{let h=Xe(m);if(!x||!Ke(m)||h){Ut(null);return}let R=pt.current.filter(I=>I.type==="rack").map(I=>I),H=qo(m),$=Er(H,R)?.id??null;Ut(I=>I===$?I:$);},[x,qo,Xe]),Za=useCallback((a,m,y)=>{Ut(null);let h=Xe(m);if(!x||!Ke(m)||h)return;let R=Ft(m),H=pt.current.filter(W=>W.type==="rack").map(W=>W),F=qo(m),$=Er(F,H),I=pt.current;if(!$)return;let K={x:R.x-$.position.x,y:R.y-$.position.y},oe=I.find(W=>W.id===m.id)||m,Te=He($.data),Re=_t($.data),Se=$t($.data),je=Te?ua(oe.data,K.x,Re,Se):"both",qe=Te&&je==="front"?Re+Se:0,Me=je==="rear"?"rear":je==="front"?"front":oe.data.view==="front"||oe.data.view==="rear"?oe.data.view:void 0,Ye={...oe,parentId:$.id,extent:"parent",position:{x:qe,y:K.y},data:{...oe.data,rackLayout:Te?"split-face":"single-face",rackWidthPx:Re,rackFaceGapPx:Se,mountMode:je,view:Me}},Be=I.filter(W=>W.id!==m.id).concat(Ye),we=or(Ye,$,Ye.position,Be),et=I.map(W=>W.id!==m.id?W:{...W,parentId:$.id,extent:"parent",position:{x:we.x,y:we.y},data:{...W.data,rackLayout:Te?"split-face":"single-face",rackWidthPx:Re,rackFaceGapPx:Se,mountMode:je,view:Me,uPosition:we.uPosition??W.data.uPosition}});Zo(et);},[x,Ft,qo,Zo,Xe]),qa=useCallback(a=>{if(!a.source||!a.target||!a.sourceHandle||!a.targetHandle)return true;let m=ue(a.source),y=ue(a.target),h=re(m,a.sourceHandle),R=re(y,a.targetHandle),H=J.current.some(Z=>Z.source===a.source?re(m,Z.sourceHandle)===h:Z.target===a.source?re(m,Z.targetHandle)===h:false),F=J.current.some(Z=>Z.target===a.target?re(y,Z.targetHandle)===R:Z.source===a.target?re(y,Z.sourceHandle)===R:false);if(H&&d&&console.log("Connection will replace: Source handle already connected",{source:a.source,sourceHandle:a.sourceHandle,existingEdges:J.current.filter(Z=>Z.source===a.source&&Z.sourceHandle===a.sourceHandle||Z.target===a.source&&Z.targetHandle===a.sourceHandle)}),F&&d&&console.log("Connection will replace: Target handle already connected",{target:a.target,targetHandle:a.targetHandle,existingEdges:J.current.filter(Z=>Z.target===a.target&&Z.targetHandle===a.targetHandle||Z.source===a.target&&Z.sourceHandle===a.targetHandle)}),!Rr(m,y))return true;if(m?.type==="splice"&&y?.type==="splice"){let Z=m.data?.mode==="ribbon",ge=y.data?.mode==="ribbon";if(Z!==ge)return d&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",a),false}let I=(Z,ge)=>(Z?.type==="tube"||Z?.type==="cable")&&!!ge&&ge.startsWith("fiber-"),K=(Z,ge)=>(Z?.type==="tube"||Z?.type==="multi-tube-cable")&&!!ge&&ge.startsWith("tube-"),oe=(Z,ge)=>Z?.type==="multi-tube-cable"&&!!ge&&ge.startsWith("tube-"),Te=(Z,ge)=>Z?.type==="tube"&&!!ge&&ge.startsWith("tube-"),Re=(Z,ge)=>(Z?.type==="cable"||Z?.type==="multi-tube-cable")&&ge==="cable-button",Se=(Z,ge)=>Z?.type==="splice"&&(ge==="left"||ge==="right"),je=(Z,ge)=>Z?.type==="coupler"&&!!ge&&(ge.startsWith("left-")||ge.startsWith("right-")),qe=(Z,ge)=>{if(Z?.type!=="fibre-split"||!ge)return false;let P=ge.replace(/-(source|target)$/i,"");return P.startsWith("input-")||P.startsWith("output-")},Me=I(m,a.sourceHandle),Ye=I(y,a.targetHandle),Be=Se(m,a.sourceHandle),we=Se(y,a.targetHandle),et=je(m,a.sourceHandle),W=je(y,a.targetHandle),Ie=qe(m,a.sourceHandle),ne=qe(y,a.targetHandle),So=Re(m,a.sourceHandle),Vr=Re(y,a.targetHandle),lo=oe(m,a.sourceHandle),uo=oe(y,a.targetHandle),Gr=Te(m,a.sourceHandle),Xr=Te(y,a.targetHandle),Jo=K(m,a.sourceHandle),jr=K(y,a.targetHandle);return Me&&we||Ye&&Be||(Be&&(W||ne)||we&&(et||Ie))||(et&&(W||ne||we)||W&&(et||Ie||Be))||So&&Vr||(lo&&Xr||uo&&Gr)?true:Jo&&jr?(d&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",a),false):(d&&console.log("Connection rejected: Connection not allowed by fiber rules",a),false)},[ue,d]),Ja=useCallback(a=>{if(Pe)return;d&&console.log("onConnect called:",a);let m=ue(a.source),y=ue(a.target);d&&(console.log("onConnect: sourceNode type:",m?.type,"targetNode type:",y?.type),console.log("onConnect: sourceHandle:",a.sourceHandle,"targetHandle:",a.targetHandle));let h=ha(a,m,y),R=q.validateConnection({source:h.source??null,target:h.target??null,sourceHandle:h.sourceHandle,targetHandle:h.targetHandle});if(!R.valid&&!(R.reason??"").includes("already connected")){d&&console.warn(`Connection rejected: ${R.reason}`);return}let H=m?.type==="vertical-pdu",F=m?.type==="vertical-pdu"||y?.type==="vertical-pdu",$=ro(m,h.sourceHandle),I=ro(y,h.targetHandle),K=$&&I&&F,oe=m?.data,Te=m?.type==="switch"||m?.type==="device"&&oe?.deviceType==="switch",Re=I,Se=!!h.targetHandle&&(h.targetHandle.startsWith("net-")||h.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(We(h.targetHandle))),je=!!h.sourceHandle&&(h.sourceHandle.startsWith("net-")||h.sourceHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(We(h.sourceHandle))),qe=y?.type==="switch"||y?.type==="device"&&y.data?.deviceType==="switch",Me=y?.type==="vertical-pdu",Ye=$,Be=m?.type==="tube"&&y?.type==="multi-tube-cable",we=m?.type==="multi-tube-cable"&&y?.type==="tube",et=Be||we,W=h.sourceHandle==="cable-button"&&h.targetHandle==="cable-button",Ie="fiber";K?Ie="power":W?Ie="thick-cable":et&&(Ie=Y?"smoothstep":"fiber");let ne,So=ga(y),Vr=ga(m);if(So||Vr){let P=y?.data,G=m?.data,me=So?P.ribbonFiberIds:G.ribbonFiberIds;me&&Array.isArray(me)&&me.length>=6&&me.length<=12&&(ne={ribbonFiberIds:me,isRibbon:true});}if(!ne&&(Ie==="fiber"||Ie==="smoothstep")&&!H){let P;Be?P=To(h.target,h.targetHandle):P=To(h.source,h.sourceHandle),P&&(ne={color:P.color,striped:P.striped,isRibbon:false});}else if(Ie==="thick-cable"&&W){let P=m?.data;ne={color:P?.color||(P?.tubeStartIndex?Ue(P.tubeStartIndex):"#6366f1")};}let lo=re(m,h.sourceHandle),uo=re(y,h.targetHandle),Gr=J.current.some(P=>P.source===h.source?re(m,P.sourceHandle)===lo:P.target===h.source?re(m,P.targetHandle)===lo:false),Xr=J.current.some(P=>P.target===h.target?re(y,P.targetHandle)===uo:P.source===h.target?re(y,P.sourceHandle)===uo:false);if(Gr||Xr){let P=new Set;for(let G of J.current){if(G.source===h.source&&re(m,G.sourceHandle)===lo){P.add(G.id);continue}if(G.target===h.source&&re(m,G.targetHandle)===lo){P.add(G.id);continue}if(G.source===h.target&&re(y,G.sourceHandle)===uo){P.add(G.id);continue}G.target===h.target&&re(y,G.targetHandle)===uo&&P.add(G.id);}if(P.size>0){let G=J.current.filter(ft=>!P.has(ft.id)),me=addEdge(h,G);if(me.length===G.length)d&&console.warn("Handle replacement skipped: addEdge did not create a new edge",h);else {let ft=me[me.length-1],Dt=le({...h,id:ft.id,type:Ie}),Gt={...ft,type:Ie,zIndex:Dt,style:{...ft.style,zIndex:Dt},data:ne!==void 0?ne:ft.data};he([...me.slice(0,-1),Gt]),d&&console.log("Handle replacement: Replaced",P.size,"edge(s)");return}}}if(y?.type==="splice"&&(a.targetHandle==="left"||a.targetHandle==="right")&&a.target&&a.targetHandle){let P=J.current.find(G=>G.target===a.target&&G.targetHandle===a.targetHandle||G.source===a.target&&G.sourceHandle===a.targetHandle);if(P){d&&(console.log("Splice target handle replacement: Found existing edge",P.id,"on splice handle",a.targetHandle),console.log("Existing edge details:",{id:P.id,source:P.source,target:P.target,sourceHandle:P.sourceHandle,targetHandle:P.targetHandle,data:P.data}));let G=a.source&&a.sourceHandle?J.current.find(wt=>wt.source===a.source&&wt.sourceHandle===a.sourceHandle):null;d&&G&&console.log("Splice target handle replacement: Also found existing source edge",G.id);let me=new Set;P&&me.add(P.id),G&&G.id!==P.id&&me.add(G.id);let ft=J.current.filter(wt=>!me.has(wt.id));d&&console.log("Splice target handle replacement: Removing",me.size,"edge(s), creating new connection");let Dt=`edge-${a.source}-${a.sourceHandle}-${a.target}-${a.targetHandle}-${Date.now()}`,Gt=le({...a,id:Dt,type:"fiber"}),Io={id:Dt,source:a.source,target:a.target,sourceHandle:a.sourceHandle,targetHandle:a.targetHandle,type:"fiber",zIndex:Gt,style:{zIndex:Gt},data:ne!==void 0?ne:{}},Kr=[...ft,Io];he(Kr),d&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Io.id);return}}if(m?.type==="splice"&&a.sourceHandle==="right"&&a.source&&a.sourceHandle){let P=J.current.find(G=>G.source===a.source&&G.sourceHandle===a.sourceHandle||G.target===a.source&&G.targetHandle===a.sourceHandle);if(P){d&&console.log("Splice source handle replacement: Found existing edge",P.id,"on splice handle",a.sourceHandle);let G=a.target&&a.targetHandle?J.current.find(wt=>wt.target===a.target&&wt.targetHandle===a.targetHandle):null;d&&G&&console.log("Splice source handle replacement: Also found existing target edge",G.id);let me=new Set;P&&me.add(P.id),G&&G.id!==P.id&&me.add(G.id);let ft=J.current.filter(wt=>!me.has(wt.id));d&&console.log("Splice source handle replacement: Removing",me.size,"edge(s), creating new connection");let Dt=`edge-${a.source}-${a.sourceHandle}-${a.target}-${a.targetHandle}-${Date.now()}`,Gt=le({...a,id:Dt,type:"fiber"}),Io={id:Dt,source:a.source,target:a.target,sourceHandle:a.sourceHandle,targetHandle:a.targetHandle,type:"fiber",zIndex:Gt,style:{zIndex:Gt},data:ne!==void 0?ne:{}},Kr=[...ft,Io];he(Kr),d&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Io.id);return}}if((m?.type==="tube"||m?.type==="cable")&&a.sourceHandle?.startsWith("fiber-")&&a.source&&a.sourceHandle){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if((y?.type==="tube"||y?.type==="cable")&&a.targetHandle?.startsWith("fiber-")&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if((m?.type==="multi-tube-cable"||m?.type==="tube")&&a.sourceHandle?.startsWith("tube-")&&a.source&&a.sourceHandle){let P=Ae({edges:J.current,connection:h,edgeType:Ie,selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if((y?.type==="multi-tube-cable"||y?.type==="tube")&&a.targetHandle?.startsWith("tube-")&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:Ie,selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(m?.type==="coupler"&&(a.sourceHandle?.startsWith("left-")||a.sourceHandle?.startsWith("right-"))){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if(y?.type==="coupler"&&(a.targetHandle?.startsWith("left-")||a.targetHandle?.startsWith("right-"))){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(W&&a.source&&a.sourceHandle&&a.target&&a.targetHandle){let P=m?.data,G=P?.color||(P?.tubeStartIndex?Ue(P.tubeStartIndex):"#6366f1"),me=Ae({edges:J.current,connection:h,edgeType:"thick-cable",selectEdgeZIndex:le,findBy:"source",data:{color:G}});if(me){he(me);return}if(me=Ae({edges:J.current,connection:h,edgeType:"thick-cable",selectEdgeZIndex:le,findBy:"target",data:{color:G}}),me){he(me);return}}if(H&&Re&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(Me&&Ye&&a.source&&a.sourceHandle&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:le,findBy:"source",matchOn:"target",data:ne});if(P){he(P);return}}if(Te&&Se&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(qe&&je&&a.source&&a.sourceHandle&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",matchOn:"source",data:ne});if(P){he(P);return}}let Jo=q.validateConnection({source:h.source??null,target:h.target??null,sourceHandle:h.sourceHandle,targetHandle:h.targetHandle});if(!Jo.valid){if(H&&a.source&&a.sourceHandle){let P=Ae({edges:J.current,connection:h,edgeType:Re?"power":"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if(Me&&a.source&&a.sourceHandle){let P=Ae({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:le,findBy:"source",matchOn:"target",data:ne});if(P){he(P);return}}if(Te&&a.source&&a.sourceHandle){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if(qe&&a.target&&a.targetHandle){let P=Ae({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",matchOn:"source",data:ne});if(P){he(P);return}}d&&console.warn(`Connection rejected: ${Jo.reason}`);return}let jr=J.current.some(P=>P.source===h.source&&P.sourceHandle===h.sourceHandle||P.target===h.source&&P.targetHandle===h.sourceHandle),ai=J.current.some(P=>P.target===h.target&&P.targetHandle===h.targetHandle||P.source===h.target&&P.sourceHandle===h.targetHandle),Yr=(P,G)=>!P||!G?false:!!(P.startsWith("tube-")||G.type==="splice"&&(P==="left"||P==="right")||P==="cable-button"),si=Yr(h.sourceHandle||"",m),di=Yr(h.targetHandle||"",y);if(jr&&!si){d&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:a.source,sourceHandle:h.sourceHandle,existingEdges:J.current.filter(P=>P.source===h.source&&P.sourceHandle===h.sourceHandle||P.target===h.source&&P.targetHandle===h.sourceHandle)});return}if(ai&&!di){d&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:h.target,targetHandle:h.targetHandle,existingEdges:J.current.filter(P=>P.target===h.target&&P.targetHandle===h.targetHandle||P.source===h.target&&P.sourceHandle===h.targetHandle)});return}let ci={...h,type:Ie,zIndex:le({...h,id:"temp-id"}),data:ne},Z=addEdge(ci,J.current),ge=Z[Z.length-1];ge&&(ii(P=>new Set(P).add(ge.id)),setTimeout(()=>{ii(P=>{let G=new Set(P);return G.delete(ge.id),G});},1e3)),he(Z);},[he,q,le,ue,d,To,Y,Pe]),Qa=useCallback((a,m)=>{if(Pe||!m.source||!m.target||!m.sourceHandle||!m.targetHandle)return;let y=ue(m.source),h=ue(m.target),R=ha(m,y,h),H=re(y,R.sourceHandle),F=re(h,R.targetHandle),$=J.current.some(W=>{if(W.id===a.id)return false;let Ie=W.source===R.source&&re(y,W.sourceHandle)===H||W.target===R.source&&re(y,W.targetHandle)===H,ne=W.target===R.target&&re(h,W.targetHandle)===F||W.source===R.target&&re(h,W.sourceHandle)===F;return Ie||ne}),I=q.validateConnection({source:R.source??null,target:R.target??null,sourceHandle:R.sourceHandle,targetHandle:R.targetHandle,ignoreEdgeId:a.id});if(!I.valid&&!((I.reason??"").includes("already connected")&&$)){d&&console.warn(`Edge update rejected: ${I.reason}`);return}let K=y?.type==="vertical-pdu"||h?.type==="vertical-pdu",oe=ro(y,R.sourceHandle),Te=ro(h,R.targetHandle),Re=oe&&Te&&K,Se=y?.type==="tube"&&h?.type==="multi-tube-cable",je=y?.type==="multi-tube-cable"&&h?.type==="tube",qe=Se||je,Me;Re?Me="power":qe?Me=Y?"smoothstep":"fiber":Me="fiber";let Ye;if(Me==="fiber"||Me==="smoothstep"){let W=To(R.source,R.sourceHandle);W&&(Ye={color:W.color,striped:W.striped});}let et=J.current.filter(W=>{if(W.id===a.id)return true;let Ie=W.source===R.source&&re(y,W.sourceHandle)===H||W.target===R.source&&re(y,W.targetHandle)===H,ne=W.target===R.target&&re(h,W.targetHandle)===F||W.source===R.target&&re(h,W.sourceHandle)===F;return !(Ie||ne)}).map(W=>W.id===a.id?{...W,source:R.source,target:R.target,sourceHandle:R.sourceHandle,targetHandle:R.targetHandle,type:Me,data:Ye!==void 0?{...W.data,...Ye}:W.data,zIndex:le({...R,id:W.id,type:Me}),style:{...W.style,zIndex:le({...R,id:W.id,type:Me})}}:W);he(et);},[he,ue,To,le,Y,d,q,Pe]),es=useCallback((a,m)=>{if(Fe){c&&c(m);return}let y=a.metaKey||a.ctrlKey,h=ot(),R=m,H=Xe(m);if(m.type==="tube"&&H&&!y){let F=h.find($=>$.id===H&&($.type==="cable"||$.type==="multi-tube-cable"));F&&(R=F);}if(Wr(R),Ro([]),j(F=>F.map($=>{let I=$.id===R.id;return $.selected===I?$:{...$,selected:I}})),y&&Ke(R)&&!so(R)){let F=R.data||{},$=F.view||(Array.isArray(F.rearPorts)&&F.rearPorts.length>0?"rear":"front"),I=$==="front"?"rear":"front";d&&console.log(`Command+click: Toggling device ${R.id} from ${$} to ${I}`),N&&N(R.id,I);}c&&c(R);},[N,c,d,ot,j,Fe,Xe,so]),ts=useCallback(()=>{},[]),os=useCallback((a,m)=>{Wr(null),Ro([m]),j(y=>y.map(h=>h.selected?{...h,selected:false}:h)),c?.(null),l&&l(m);},[l,c,j]),rs=useCallback(()=>{Wr(null),Ro([]),j(a=>a.map(m=>m.selected?{...m,selected:false}:m)),c?.(null);},[c,j]),[rt,Wr]=useState(null),[ni,ii]=useState(new Set);useOnSelectionChange({onChange:({edges:a})=>{Ro(a||[]);}});let[zr,Ro]=useState([]);useEffect(()=>{let a=m=>{if(De.allowKeyboardDelete&&(m.key==="Backspace"||m.key==="Delete")&&zr.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let y=zr.filter(h=>{let R=h.sourceHandle||"",H=h.targetHandle||"";return R.startsWith("tube-")||H.startsWith("tube-")?(d&&console.log("Cannot delete edge connected to tube handle",h),false):true});if(y.length>0){let h=new Set(y.map(H=>H.id)),R=J.current.filter(H=>!h.has(H.id));he(R),Ro([]),d&&console.log("Deleted edges:",y.map(H=>H.id));}}};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[zr,he,d,De.allowKeyboardDelete]);let ns=useCallback((a,{nodeId:m,handleType:y})=>{d&&console.log("Connection started from",{nodeId:m,handleType:y});},[d]),is=useCallback(a=>{d&&console.log("Connection ended",a);},[d]),as=useCallback(()=>{if(Pe||!rt)return;let a=ue(rt.id);if(a){if(a.type==="rack"){let m=a.data||{};if(He(m))return;let h=(m.face||"front")==="front"?"rear":"front";k?(k(a.id,h),N&&ot().filter(H=>H.parentId===a.id).forEach(H=>{N(H.id,h);})):j(R=>R.map(H=>H.id===a.id?{...H,data:{...H.data,face:h}}:H.parentId===a.id?{...H,data:{...H.data,view:h}}:H));return}if(Ke(a)){if(so(a))return;let m=a.data||{},y=Array.isArray(m.rearPorts)&&m.rearPorts.length>0,h=Array.isArray(m.ports)&&m.ports.length>0,H=(m.view||(y&&!h?"rear":"front"))==="front"?"rear":"front";N?N(a.id,H):j(F=>F.map($=>$.id===a.id?{...$,data:{...$.data,view:H}}:$));}}},[rt,ue,k,N,j,ot,Pe,so]),ss=useCallback(()=>{if(Pe||!x||!rt||!Ke(rt))return;let a=ue(rt.id),m=Xe(a);if(!a||!Ke(a)||!m)return;let y=Ft(a),R=pt.current.map(H=>H.id!==a.id?H:{...H,parentId:void 0,parentNode:void 0,extent:void 0,position:y,data:{...H.data,uPosition:void 0}});Zo(R);},[Pe,x,rt,ue,Ft,Zo,Xe]),ds=useMemo(()=>{let a=vo.current;return ye.map(m=>{let y=m,h=a.get(String(y.source)),R=a.get(String(y.target)),H=Ir(y.sourceHandle||"",h),F=Ir(y.targetHandle||"",R),$=Be=>{if(!Be||!Ke(Be))return;let we=Be.data??{},et=typeof Be.parentId=="string"?Be.parentId:Be.parentNode,W=et?a.get(et):void 0;if(W&&W.type==="rack"&&He(W.data))return Mt(Oe(we));let Ie=Array.isArray(we.rearPorts)&&we.rearPorts.length>0,ne=Array.isArray(we.ports)&&we.ports.length>0;return [we.view||(Ie&&!ne?"rear":"front")]},I=$(h),K=$(R),oe=Or(h),Te=Or(R),Re=Ke(h)&&!oe&&!!I&&!!H&&!I.includes(H),Se=Ke(R)&&!Te&&!!K&&!!F&&!K.includes(F),Me=Re||Se,Ye=m.style;if(Me)Ye={...m.style,opacity:0,pointerEvents:"none",zIndex:0};else if(m.style&&m.style.opacity===0&&m.style.pointerEvents==="none"&&m.style.zIndex===0){let we={...m.style};delete we.opacity,delete we.pointerEvents,delete we.zIndex,Ye=Object.keys(we).length>0?we:void 0;}return {...m,style:Ye,className:ni.has(m.id)?"edge-connecting":m.className}})},[ye,ni,Or]),Ee=useMemo(()=>rt?ue(rt.id)??rt:null,[rt,ue]),co=useMemo(()=>{if(!Ee||!zt.enabled||Pe)return {showRearToggle:false,showDeRack:false,count:0};let a=Ee.type==="rack"?!oi(Ee):Ke(Ee)?!so(Ee):false,m=zt.showRearToggle&&a,y=zt.showDeRack&&x&&!Pe&&Ke(Ee)&&!!Xe(Ee);return {showRearToggle:m,showDeRack:y,count:(m?1:0)+(y?1:0)}},[Ee,zt,x,Pe,Xe,so,oi]),Ur=useMemo(()=>{if(!Ee||co.count===0||!Ge.current)return null;let a=Ge.current.getBoundingClientRect();if(a.width<=0||a.height<=0)return null;let m=Ee.positionAbsolute??Ft(Ee),y=Ee.width||0,h=Ee.height||0,R=co.count>1?220:110,H=34;try{let F=ct({x:m.x+y/2,y:m.y}),$=ct({x:m.x+y/2,y:m.y+h}),I=F.x-a.left-R/2,K=F.y-a.top-H-10;return K<8&&(K=$.y-a.top+10),I=Math.max(8,Math.min(I,a.width-R-8)),K=Math.max(8,Math.min(K,a.height-H-8)),{left:I,top:K}}catch{return null}},[Ee,co,Ft,ct]),cs=ui(v,T),ls=fi(v,{touchAction:"none",...C});return jsxs("div",{ref:Ge,className:cs,style:ls,children:[jsxs(ReactFlow,{nodes:Ne,edges:ds,onNodesChange:a=>{if(Pe)return;let m=ja(a);m&&(L?n&&n(m):q.setState({nodes:m}));},onEdgesChange:a=>{if(Pe)return;let m=a.filter(y=>{if(y.type==="remove"){let h=J.current.find(R=>R.id===y.id);if(h){let R=h.sourceHandle||"",H=h.targetHandle||"";if(R.startsWith("tube-")||H.startsWith("tube-"))return d&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",h),false}}return true});if(m.length>0){let y=applyEdgeChanges(m,J.current);st(m),L?i&&i(y):q.setState({edges:y});}},onConnect:Pe?void 0:u??Ja,onConnectStart:ns,onConnectEnd:is,onEdgeUpdate:Pe?void 0:p??Qa,isValidConnection:b??qa,connectionMode:w,onNodeClick:es,onNodeDoubleClick:ts,onPaneClick:rs,onNodeDragStart:Ya,onNodeDrag:Ka,onNodeDragStop:Za,onEdgeClick:os,onInit:D,nodeTypes:yt.current,edgeTypes:ao,defaultEdgeOptions:{zIndex:1e3,reconnectable:De.edgesReconnectable},nodesDraggable:De.nodesDraggable,nodesConnectable:De.nodesConnectable,elementsSelectable:De.elementsSelectable,edgesFocusable:De.edgesFocusable,elevateNodesOnSelect:false,selectNodesOnDrag:false,connectOnClick:De.connectOnClick,panOnDrag:De.panOnDrag,panOnScroll:De.panOnScroll,zoomOnScroll:De.zoomOnScroll,zoomOnPinch:De.zoomOnPinch,zoomOnDoubleClick:De.zoomOnDoubleClick,preventScrolling:Fe,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:te,proOptions:{hideAttribution:true},children:[jsx(Background,{color:pi(v)}),De.showControls&&jsx(Controls,{showInteractive:De.showInteractiveControl}),De.showMiniMap&&jsx(MiniMap,{}),jsx(Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&jsx("button",{className:"download-button",onClick:Lr,disabled:lt,"aria-busy":lt,style:{position:"absolute",top:_.includes("top")?"10px":"auto",bottom:_.includes("bottom")?"10px":"auto",right:_.includes("right")?"10px":"auto",left:_.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:lt?"not-allowed":"pointer",opacity:lt?.7:1,transition:"all 0.2s ease",...se},children:lt?`${U}...`:U}),Ee&&Ur&&co.count>0&&jsxs("div",{style:{position:"absolute",top:Ur.top,left:Ur.left,display:"flex",gap:8,zIndex:2e3},children:[co.showRearToggle&&jsx("button",{onClick:a=>{a.preventDefault(),as();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let a=Ee.data;if(Ee.type==="rack")return (a?.face||"front")==="front"?"Switch to rear":"Switch to front";{let m=Array.isArray(a?.rearPorts)&&a.rearPorts.length>0,y=Array.isArray(a?.ports)&&a.ports.length>0;return (a?.view||(m&&!y?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let a=Ee.data;if(Ee.type==="rack")return (a?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let m=Array.isArray(a?.rearPorts)&&a.rearPorts.length>0,y=Array.isArray(a?.ports)&&a.ports.length>0;return (a?.view||(m&&!y?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()}),co.showDeRack&&jsx("button",{onClick:a=>{a.preventDefault(),ss();},style:{background:"#7f1d1d",color:"#fee2e2",border:"1px solid #b91c1c",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:"Remove device from rack so it can be moved/reassigned",children:"De-rack"})]})]})},Yn=e=>jsx(ReactFlowProvider,{children:jsx(pc,{...e})});var Kn=class extends Component{constructor(){super(...arguments);this.state={error:null};this.reset=()=>{this.setState({error:null});};}static getDerivedStateFromError(o){return {error:o}}componentDidCatch(o,r){this.props.onError?.(o,r);}render(){let{error:o}=this.state,{children:r,fallback:n}=this.props;return o?typeof n=="function"?n(o,this.reset):n??jsxs("div",{role:"alert",style:{padding:16,margin:8,border:"1px solid #e53e3e",borderRadius:4,backgroundColor:"#fff5f5",color:"#c53030"},children:[jsx("strong",{children:"Diagram error"}),": ",o.message,jsx("button",{type:"button",onClick:this.reset,style:{marginLeft:12,padding:"4px 8px",cursor:"pointer"},children:"Try again"})]}):r}};function Go(e,{rowHeight:t,tubeGap:o}){let r=[],n=[],i=e.kind??(e.tubeCount?"tube":"simple"),s=i==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,d=i==="tube"?Math.max(1,Math.min(24,e.fibersPerTube??12)):Math.max(1,Math.min(24,e.fiberCount??12)),c=Math.max(1,e.tubeStartIndex??1),l=Math.max(1,e.fiberStartIndex??1),g=0;for(let f=0;f<s;f+=1){let u=c+f,p=e.tubeColorMap?.[u];n.push({tubeIndex:u,y:g,label:`T${u}`,color:p??Ue(u)});for(let b=0;b<d;b+=1){let w=l+b,N=tn(w);r.push({key:`${u}-${w}`,tubeIndex:i==="tube"?u:void 0,fiberIndex:w,y:g,color:Kt(w),striped:Yt(w),backgroundImage:typeof N.backgroundImage=="string"?N.backgroundImage:void 0}),g+=t;}f<s-1&&(g+=o);}return {rows:r,tubeLabels:n,height:g}}var Zn=e=>typeof e=="object"&&e!==null,hc=e=>{if(!Zn(e.data))return false;if(e.type==="fibre-flow-cable"){let t=e.data;return typeof t.label=="string"&&Zn(t.cable)&&(t.side==="left"||t.side==="right")&&typeof t.rowHeight=="number"&&typeof t.columnWidth=="number"&&typeof t.showTubeLabels=="boolean"&&typeof t.showFiberNumbers=="boolean"&&Zn(t.layout)}if(e.type==="fibre-flow-closure"){let t=e.data;return typeof t.label=="string"&&typeof t.width=="number"&&typeof t.height=="number"&&typeof t.headerHeight=="number"}return false},yc=e=>e==="fibre-flow"||e==="fibre-flow-link",wc=e=>typeof e.id=="string"&&e.id.length>0&&typeof e.source=="string"&&e.source.length>0&&typeof e.target=="string"&&e.target.length>0,xc=e=>e.sourceHandle==="cable-run"||e.targetHandle==="cable-run"?"fibre-flow-link":"fibre-flow",Nc=(e,t=[])=>{let o=new Map(t.map(n=>[n.id,n])),r=[];return e.forEach(n=>{if(!wc(n))return;let i=o.get(n.id),s=yc(n.type)?n.type:i?.type??xc(n);r.push({...i??{},...n,type:s});}),r},ka=e=>`fiber-${e.tube??1}-${e.fiber}`,Pa=e=>Kt(e.fiber),Ca=e=>Yt(e.fiber),kc=(e,t)=>{if(t)return t;if(!(typeof e!="number"||Number.isNaN(e)))return e>=1e3?`${(e/1e3).toFixed(1)} km`:`${Math.round(e)} m`},Pc=(e,t,o,r,n,i)=>e?`${o} ${i}`:t?`0 ${n} ${r} ${i}`:"6 6",Cc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,data:d})=>{let[c,l,g]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,curvature:.35}),f=typeof d?.lossDb=="number"?`${d.lossDb.toFixed(2)} dB`:"",u=d?.label??f,p=d?.sourceColor,b=d?.targetColor,w=d?.color??p??b??"#94a3b8",N=d?.sourceStriped??false,k=d?.targetStriped??false,T=d?.highlighted??true,C=d?.dimmed??false,S=d?.circuitId,x=d?.circuitLabel??S,v=d?.showCircuitId??false,D=p&&b&&p!==b,E=r-t,A=n-o,_=Math.sqrt(E*E+A*A),U=l-t,se=g-o,Y=Math.sqrt(U*U+se*se),ee=_>0?Y/_*100:50,ie=`fibre-flow-gradient-${e}`,z=N&&!k,V=k&&!N,B=N&&k,O=_*1.25,X=O/2,te=12,M=Math.ceil(X*1.2/te),L=Array(M).fill("6 6").join(" "),de=Math.ceil(X*1.2/te),ae=Array(de).fill("6 6").join(" "),ce=v&&x,q=Math.max(u?u.length*6.2+16:0,ce?(x?.length||0)*5.5+16:0),xe=ce?32:16;return jsxs(Fragment,{children:[jsx("defs",{children:D&&jsxs("linearGradient",{id:ie,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0%",stopColor:p}),jsx("stop",{offset:`${ee}%`,stopColor:p}),jsx("stop",{offset:`${ee}%`,stopColor:b}),jsx("stop",{offset:"100%",stopColor:b})]})}),D?jsx("path",{id:e,d:c,fill:"none",stroke:`url(#${ie})`,strokeWidth:T?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,style:{mixBlendMode:"normal"}}):jsx(BaseEdge,{id:e,path:c,style:{stroke:w,strokeWidth:T?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,mixBlendMode:"normal"}}),(B||z||V)&&jsx("path",{id:`${e}-stripe`,d:c,fill:"none",stroke:"#000",strokeWidth:T?1.6:1.3,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:Pc(z,V,L,ae,X,O),strokeDashoffset:0,opacity:C?.2:.9,style:{mixBlendMode:"normal"}}),(u||ce)&&T&&jsx(EdgeLabelRenderer,{children:jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${g}px)`,width:q,height:xe,background:"rgba(248, 250, 252, 0.92)",border:"1px solid rgba(15, 23, 42, 0.4)",borderRadius:4,fontSize:10,fontFamily:"monospace",color:"rgba(15, 23, 42, 0.9)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",pointerEvents:"none",padding:"2px 4px",zIndex:9999},children:[u&&jsx("div",{style:{lineHeight:1.2},children:u}),ce&&jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:u?2:0},children:x})]})})]})},vc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,data:d})=>{let[c,l,g]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:s,curvature:.2}),f=d?.label,u=d?.color??"#64748b";return jsxs(Fragment,{children:[jsx(BaseEdge,{id:e,path:c,style:{stroke:u,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),f&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${g}px)`,padding:"2px 8px",background:"rgba(30, 41, 59, 0.9)",border:`1px solid ${u}`,borderRadius:10,fontSize:10,fontFamily:"monospace",color:"#e2e8f0",letterSpacing:.2,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9999},children:f})})]})},Tc=({data:e})=>{let{cable:t,side:o,rowHeight:r,columnWidth:n,showTubeLabels:i,showFiberNumbers:s,layout:d,colorMode:c="dark"}=e,l=c==="light",g=8,f=12,u=-1,p=0,b=t.jacketColor??"#facc15",w=(t.kind??(t.tubeCount?"tube":"simple"))==="tube",N=i&&w,k=o==="left"?g+p:p,T=o==="right"?g+p:p,C=o==="left"?Position.Right:Position.Left,S={width:4,height:4,borderRadius:"50%",background:b,border:`1px solid ${b}`,boxShadow:"0 0 1px rgba(0,0,0,0.4)",top:"50%",position:"absolute",...o==="left"?{left:0,transform:"translate(-50%, -50%)"}:{right:0,transform:"translate(50%, -50%)"}};return jsxs("div",{style:{position:"relative",width:n,height:d.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[jsx("div",{style:{position:"absolute",top:-18,left:o==="left"?0:void 0,right:o==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:l?"rgba(248, 250, 252, 0.95)":"rgba(15, 23, 42, 0.9)",color:l?"#1a1a1a":"#f8fafc",padding:"2px 6px",borderRadius:4,whiteSpace:"nowrap",maxWidth:n,overflow:"hidden",textOverflow:"ellipsis",zIndex:10,...o==="right"?{textAlign:"right"}:{}},children:t.label}),jsx("div",{style:{position:"absolute",top:0,bottom:0,width:g,left:o==="left"?0:void 0,right:o==="right"?0:void 0,borderRadius:4,background:w?"transparent":b,border:`1px solid ${b}`,boxShadow:w?"none":"inset 0 0 3px rgba(0,0,0,0.3)",overflow:"hidden"},children:w&&d.tubeLabels.map((x,v)=>{let D=d.rows.filter(Y=>Y.tubeIndex===x.tubeIndex);if(D.length===0)return null;let E=D[0].y,A=D[D.length-1].y+r,_=A-E,U=d.tubeLabels[v+1],se=U&&U.y-A>0;return jsx("div",{style:{position:"absolute",top:E,left:0,right:0,height:_,background:x.color,borderLeft:`2px solid ${x.color}`,borderRight:`2px solid ${x.color}`,borderTop:v===0?`2px solid ${x.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:se?"1px solid rgba(0,0,0,0.15)":`2px solid ${x.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:v===0&&!se||v===0?"4px 4px 0 0":se?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${x.tubeIndex}`)})}),!N&&jsx("div",{style:{position:"absolute",top:0,bottom:0,left:k,right:T,...o==="left"?{borderRight:`1px solid ${b}`}:{borderLeft:`1px solid ${b}`},pointerEvents:"none",zIndex:0}}),w&&d.tubeLabels.map((x,v)=>{let D=d.rows.filter(U=>U.tubeIndex===x.tubeIndex);if(D.length===0)return null;let E=D[0].y,_=D[D.length-1].y+r-E;return jsx("div",{style:{position:"absolute",top:E,left:k,right:T,height:_,...o==="left"?{borderRight:`2px solid ${x.color}`}:{borderLeft:`2px solid ${x.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${x.tubeIndex}`)}),d.rows.map(x=>{let v=`fiber-${x.tubeIndex??1}-${x.fiberIndex}`,D=x.y+r/2,E={position:"absolute",width:f,height:f,borderRadius:"50%",top:D,background:x.backgroundImage?x.backgroundImage:x.color,backgroundColor:x.color,border:`2px solid ${x.color}`,boxShadow:"0 0 6px rgba(0,0,0,0.3)",...o==="left"?{right:-f/2}:{left:-f/2},transform:"translateY(-50%)",zIndex:1e3,cursor:"crosshair","--fiber-bg":x.color,minWidth:f,minHeight:f};x.backgroundImage&&(E["--fiber-bg-image"]=x.backgroundImage);let A=o==="left"?{right:f+u,textAlign:"right"}:{left:f+u,textAlign:"left"};return jsxs(Qe.Fragment,{children:[jsx(Handle,{id:v,type:"source",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":x.fiberIndex,"data-tube-idx":x.tubeIndex,"data-fiber-color":x.color}),jsx(Handle,{id:v,type:"target",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":x.fiberIndex,"data-tube-idx":x.tubeIndex,"data-fiber-color":x.color}),s&&jsx("div",{style:{position:"absolute",top:x.y+r/2-6,...A,fontSize:8,fontWeight:600,color:l?"rgba(15, 23, 42, 0.7)":"rgba(148, 163, 184, 0.95)",whiteSpace:"nowrap",lineHeight:1},children:x.fiberIndex})]},x.key)}),jsx(Handle,{id:"cable-run",type:"source",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:S,isConnectable:true,"data-handle-type":"cable-run"}),jsx(Handle,{id:"cable-run",type:"target",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:S,isConnectable:true,"data-handle-type":"cable-run"})]})},Rc=({data:e})=>{let t=e.colorMode==="light";return jsx("div",{style:{width:e.width,height:e.height,background:"transparent",border:t?"1px solid rgba(148, 163, 184, 0.3)":"1px solid rgba(148, 163, 184, 0.5)",borderRadius:12,boxShadow:t?"0 12px 24px rgba(0, 0, 0, 0.1)":"0 12px 24px rgba(15, 23, 42, 0.2)",position:"relative",pointerEvents:"none"},children:jsx("div",{style:{height:e.headerHeight,display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"monospace",fontWeight:700,fontSize:12,letterSpacing:.6,textTransform:"uppercase",color:t?"rgba(15, 23, 42, 0.9)":"rgba(226, 232, 240, 0.9)",background:t?"rgba(241, 245, 249, 0.7)":"rgba(15, 23, 42, 0.6)",borderBottom:t?"1px solid rgba(148, 163, 184, 0.2)":"1px solid rgba(148, 163, 184, 0.35)",borderTopLeftRadius:12,borderTopRightRadius:12},children:e.label})})},Sc=(e,t,o,r,n,i,s,d,c,l="dark")=>{let g=[],f=0;return e.forEach(u=>{let p=Go(u.leftCable,{rowHeight:o,tubeGap:r}),b=Go(u.rightCable,{rowHeight:o,tubeGap:r}),w=Math.max(p.height,b.height),N=i*2+s,k=32,T=16,C=N+T*2,S=w+k+T*2,x=`flow-closure-${u.id}`,v=`flow-cable-${u.id}-left`,D=`flow-cable-${u.id}-right`,E=t==="horizontal"?{x:f,y:0}:{x:0,y:f};f+=(t==="horizontal"?C:S)+n;let A=u.chamberId?`${u.id} - ${u.chamberId}`:u.id;g.push({id:x,type:"fibre-flow-closure",position:E,data:{label:A,width:C,height:S,headerHeight:k,colorMode:l},selectable:false,draggable:false,style:{width:C,height:S}});let _=k+T+(w-p.height)/2,U=k+T+(w-b.height)/2;g.push({id:v,type:"fibre-flow-cable",position:{x:T,y:_},parentId:x,extent:"parent",data:{label:u.leftCable.label,cable:u.leftCable,side:"left",rowHeight:o,columnWidth:i,showTubeLabels:d,showFiberNumbers:c,layout:p,colorMode:l},style:{width:i,height:p.height}}),g.push({id:D,type:"fibre-flow-cable",position:{x:T+N-i,y:U},parentId:x,extent:"parent",data:{label:u.rightCable.label,cable:u.rightCable,side:"right",rowHeight:o,columnWidth:i,showTubeLabels:d,showFiberNumbers:c,layout:b,colorMode:l},style:{width:i,height:b.height}});}),g},Ic=(e,t,o,r=false)=>{let n=[],i=new Map,s=new Map,d=new Map;return (t??[]).forEach(c=>{c.color&&i.set(c.id,c.color),c.label&&s.set(c.id,c.label);}),e.forEach(c=>{let l=`flow-cable-${c.id}-left`,g=`flow-cable-${c.id}-right`;[{nodeId:l,cable:c.leftCable},{nodeId:g,cable:c.rightCable}].forEach(({nodeId:u,cable:p})=>{let b=d.get(p.id);if(b&&b.closureId!==c.id){let w=kc(p.distanceMeters??b.distanceMeters,p.distanceLabel??b.distanceLabel),N=p.jacketColor??b.jacketColor??"#64748b";n.push({id:`flow-link-${b.nodeId}-${u}`,type:"fibre-flow-link",source:b.nodeId,target:u,sourceHandle:"cable-run",targetHandle:"cable-run",data:{label:w,color:N}});}d.set(p.id,{nodeId:u,closureId:c.id,jacketColor:p.jacketColor,distanceLabel:p.distanceLabel,distanceMeters:p.distanceMeters});}),c.splices.forEach(u=>{let p=o?u.circuitId===o:true,b=!!o&&!p,w=u.circuitId?i.get(u.circuitId):void 0,N=u.circuitId?s.get(u.circuitId):void 0,k=u.color??w,T=Pa(u.from),C=Pa(u.to),S=Ca(u.from),x=Ca(u.to);n.push({id:`flow-edge-${c.id}-${u.id}`,type:"fibre-flow",source:l,target:g,sourceHandle:ka(u.from),targetHandle:ka(u.to),data:{lossDb:u.lossDb,label:u.label,color:k,sourceColor:T,targetColor:C,sourceStriped:S,targetStriped:x,highlighted:p,dimmed:b,circuitId:u.circuitId,circuitLabel:N,showCircuitId:r}});});}),n},Ec=({closures:e,circuits:t,highlightedCircuitId:o,layout:r="horizontal",rowHeight:n=20,tubeGap:i=10,closureGap:s=140,cableColumnWidth:d=32,spliceAreaWidth:c=260,showTubeLabels:l=true,showFiberNumbers:g=true,colorMode:f="dark",showCircuitId:u=false,className:p,style:b,readOnly:w=false,panOnDrag:N=true,panOnScroll:k=true,zoomOnScroll:T=true})=>{let C=useMemo(()=>Sc(e,r,n,i,s,d,c,l,g,f),[e,r,n,i,s,d,c,l,g,f]),S=useMemo(()=>Ic(e,t,o,u),[e,t,o,u]),[x,v]=useState(C),[D,E]=useState(S);useEffect(()=>{v(C);},[C,v]),useEffect(()=>{E(S);},[S,E]);let A=useCallback((B,O)=>{if(!B||!O||!O.startsWith("fiber-"))return;let X=x.find(ce=>ce.id===B);if(!X||X.type!=="fibre-flow-cable")return;let te=/^fiber-(\d+)-(\d+)$/.exec(O);if(!te)return;let M=Number(te[1]),L=Number(te[2]),ae=X.data.layout.rows.find(ce=>(ce.tubeIndex??1)===M&&ce.fiberIndex===L);if(ae)return {color:ae.color,striped:ae.striped??false}},[x]),_=useCallback(B=>{if(w||!B.source||!B.target||!B.sourceHandle||!B.targetHandle)return false;let O=x.find(de=>de.id===B.source),X=x.find(de=>de.id===B.target);if(!O||!X)return false;let te=typeof B.sourceHandle=="string"&&B.sourceHandle.startsWith("fiber-"),M=typeof B.targetHandle=="string"&&B.targetHandle.startsWith("fiber-");return B.sourceHandle==="cable-run"||B.targetHandle==="cable-run"?true:te&&M?O.type==="fibre-flow-cable"&&X.type==="fibre-flow-cable":false},[x,w]),U=useCallback(B=>{if(w)return;let O=B.sourceHandle==="cable-run"||B.targetHandle==="cable-run",X=q=>typeof q=="string"&&q.startsWith("fiber-"),te=X(B.sourceHandle),M=X(B.targetHandle),L=(q,xe,Ce)=>q.source===xe&&q.sourceHandle===Ce||q.target===xe&&q.targetHandle===Ce,de=O?void 0:A(B.source,B.sourceHandle),ae=O?void 0:A(B.target,B.targetHandle),ce=O?void 0:{sourceColor:de?.color,targetColor:ae?.color,color:de?.color??ae?.color,sourceStriped:de?.striped,targetStriped:ae?.striped};E(q=>{let xe=q.filter(Ce=>{let Ne=te&&L(Ce,B.source,B.sourceHandle),j=M&&L(Ce,B.target,B.targetHandle);return !(Ne||j)});return addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:ce},xe)});},[A,w,E]),se=useCallback((B,O)=>{if(w)return;let X=O.sourceHandle==="cable-run"||O.targetHandle==="cable-run",te=X?void 0:A(O.source,O.sourceHandle),M=X?void 0:A(O.target,O.targetHandle),L=X?void 0:{sourceColor:te?.color,targetColor:M?.color,color:te?.color??M?.color,sourceStriped:te?.striped,targetStriped:M?.striped},de=ce=>typeof ce=="string"&&ce.startsWith("fiber-"),ae=(ce,q,xe)=>ce.source===q&&ce.sourceHandle===xe||ce.target===q&&ce.targetHandle===xe;E(ce=>{let q=ce.filter(j=>j.id!==B.id),xe=de(O.sourceHandle),Ce=de(O.targetHandle),Ne=q.filter(j=>{let ye=xe&&ae(j,O.source,O.sourceHandle),ke=Ce&&ae(j,O.target,O.targetHandle);return !(ye||ke)});return addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:L},Ne)});},[A,w,E]),Y=useCallback(B=>{w||v(B.filter(hc));},[w,v]),ee=useCallback(B=>{w||E(O=>Nc(B,O));},[w,E]),ie=useMemo(()=>({"fibre-flow-cable":Tc,"fibre-flow-closure":Rc}),[]),z=useMemo(()=>({"fibre-flow":Cc,"fibre-flow-link":vc}),[]),V={borderRadius:8,overflow:"hidden",...b};return jsx(Yn,{nodes:x,edges:D,onNodesChange:Y,onEdgesChange:ee,onConnect:U,onEdgeUpdate:se,isValidConnection:_,connectionMode:ConnectionMode.Loose,nodeTypes:ie,edgeTypes:z,className:p,style:V,colorMode:f,readOnly:w,panOnDrag:N,panOnScroll:k,zoomOnScroll:T,fitViewOptions:{padding:.2}})},Hc=e=>jsx(Ec,{...e});var _c=({cable:e,side:t,rowHeight:o=22,tubeGap:r=10,columnWidth:n=150,layout:i,showTubeLabels:s,showFiberNumbers:d=true,showCableLabel:c=true})=>{let l=useMemo(()=>i??Go(e,{rowHeight:o,tubeGap:r}),[i,e,o,r]),g=26,f=10,u=18,p=t==="left"?n-u:u,b=8,w=t==="left"?6:n-g-18,N=e.jacketColor??"#facc15",k=s??(e.kind??(e.tubeCount?"tube":"simple"))==="tube";return jsxs("div",{style:{position:"relative",width:n,height:l.height,fontFamily:"monospace",color:"inherit"},children:[c&&jsx("div",{style:{position:"absolute",top:-18,left:t==="left"?0:void 0,right:t==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:"rgba(15, 23, 42, 0.85)",color:"#f8fafc",padding:"2px 6px",borderRadius:4},children:e.label}),jsx("div",{style:{position:"absolute",top:0,bottom:0,width:g,left:t==="left"?0:void 0,right:t==="right"?0:void 0,borderRadius:14,background:`linear-gradient(90deg, ${N} 0%, ${N} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${N}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),k&&l.tubeLabels.map(T=>jsxs("div",{style:{position:"absolute",top:T.y+o/2-6,left:w,fontSize:9,fontWeight:700,textTransform:"uppercase",color:"rgba(15, 23, 42, 0.75)",background:"rgba(255, 255, 255, 0.6)",padding:"1px 6px 1px 4px",borderRadius:10,display:"flex",alignItems:"center",gap:4},children:[jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:T.color,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 3px rgba(0,0,0,0.25)"}}),jsx("span",{children:T.label})]},`tube-${T.tubeIndex}`)),l.rows.map(T=>{let C=T.y+o/2-f/2,S=t==="left"?p-f/2-b:p+f/2+b;return jsxs(Qe.Fragment,{children:[jsx("div",{style:{position:"absolute",top:C,left:p-f/2,width:f,height:f,borderRadius:"50%",backgroundColor:T.color,backgroundImage:T.backgroundImage,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 4px rgba(0,0,0,0.25)"}}),d&&jsx("div",{style:{position:"absolute",top:T.y+o/2-6,left:S,transform:t==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:T.fiberIndex})]},T.key)})]})};var Ia=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,uHeight:e.u_height??e.units??42,inventoryId:e.id,inventoryType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:typeof e.site=="object"&&e.site?e.site.name:e.site,role:typeof e.role=="object"&&e.role?e.role.name:e.role,tenant:typeof e.tenant=="object"&&e.tenant?e.tenant.name:e.tenant}}),Ea=e=>({id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${typeof e.rack=="object"&&e.rack?e.rack.id:e.rack}`:void 0,extent:e.rack?"parent":void 0,data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,deviceType:e.device_type?.model??e.model,manufacturer:e.device_type?.manufacturer?.name??e.manufacturer,role:typeof e.device_role=="object"&&e.device_role?e.device_role.name:e.role,uHeight:e.device_type?.u_height??e.u_height??1,uPosition:e.position||1,view:e.face||"front",inventoryId:e.id,inventoryType:"device",primaryIp4:typeof e.primary_ip4=="object"&&e.primary_ip4?e.primary_ip4.address:e.primary_ip4,primaryIp6:typeof e.primary_ip6=="object"&&e.primary_ip6?e.primary_ip6.address:e.primary_ip6,site:typeof e.site=="object"&&e.site?e.site.name:e.site,rack:typeof e.rack=="object"&&e.rack?e.rack.name:e.rack}}),Ha=e=>{let t=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},o=t(e.termination_a),r=t(e.termination_b);return {id:`cable-${e.id}`,source:`device-${o}`,target:`device-${r}`,type:"fiber",data:{bandwidth:e.type?.label??e.bandwidth,length:e.length||0,color:e.color,inventoryId:e.id,inventoryType:"cable",status:typeof e.status=="object"&&e.status?e.status.value:e.status,terminationA:typeof e.termination_a=="object"&&e.termination_a?e.termination_a.name:e.termination_a,terminationB:typeof e.termination_b=="object"&&e.termination_b?e.termination_b.name:e.termination_b}}},Mc=e=>{let t=[],o=[];return e.racks.forEach(r=>t.push(Ia(r))),e.devices.forEach(r=>t.push(Ea(r))),e.cables.forEach(r=>o.push(Ha(r))),{nodes:t,edges:o}},$c=e=>{let t=e.filter(n=>n.type==="rack"),o=e.filter(n=>n.type==="device"),r=e.filter(n=>!["rack","device"].includes(n.type));return t.forEach((n,i)=>{n.position={x:i*300,y:100};}),o.forEach(n=>{if(n.parentId){let i=t.find(s=>s.id===n.parentId);if(i){let s=n.data.uPosition||1,d=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+s*20-d*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),r.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var Fa=e=>typeof e.id=="number"?`device-${e.id}`:`device-${e.name}`,Ac="Interfaces",Lc="Management",Bc="Power",Jn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Rt=e=>{if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0},Dr=e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim().length>0){let t=Number(e);if(Number.isFinite(t))return t}},St=e=>{if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20")return t},Oc=e=>typeof e=="string"&&e.toLowerCase()==="rear"?"rear":"front",_r=e=>Jn(e.custom_fields)?e.custom_fields:void 0,Mr=e=>Jn(e)?e:void 0,Da=(e,t)=>{let o=_r(e),r=Mr(o?.layout);return Oc(t??e.layout?.face??e.face??r?.face??o?.port_face??o?.portFace??o?.face)},_a=(e,t,o)=>{let r=_r(e),n=Mr(r?.layout),i=Rt(o)??Rt(e.layout?.group)??Rt(e.port_group)??Rt(n?.group)??Rt(r?.port_group)??Rt(r?.portGroup)??Rt(r?.interface_group)??Rt(r?.interfaceGroup)??Rt(r?.group);return i||(t==="power_ac"||t==="power_c13"||t==="power_c19"?Bc:t==="console"||t==="mgmt"?Lc:Ac)},Ma=(e,t,o)=>{let r=_r(e),n=Mr(r?.layout);return St(o)??St(e.layout?.connectorType)??St(e.layout?.connector_type)??St(e.connector_type)??St(n?.connectorType)??St(n?.connector_type)??St(r?.connectorType)??St(r?.connector_type)??St(t)},$a=(e,t)=>{if(t==="C13")return "power_c13";if(t==="C19")return "power_c19";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")||o.includes("dac")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")||o.includes("oob")?"mgmt":o.includes("usb")?"usb":"ethernet"},Aa=e=>{let t=(e??"").toLowerCase();if(t){if(t.includes("om3"))return "om3";if(t.includes("om4"))return "om4";if(t.includes("om5"))return "om5";if(t.includes("smf")||t.includes("singlemode"))return "smf";if(t.includes("cat5e"))return "cat5e";if(t.includes("cat6a"))return "cat6a";if(t.includes("cat6"))return "cat6";if(t.includes("cat7"))return "cat7";if(t.includes("fiber")||t.includes("sfp")||t.includes("qsfp"))return "fiber";if(t.includes("ethernet")||t.includes("rj45")||t.includes("1000base")||t.includes("10gbase")||t.includes("base-t"))return "ethernet"}},Wc=e=>{if(!Jn(e))return;let t=e.side??e.port_side??e.portSide,o=typeof t=="string"&&["top","right","bottom","left"].includes(t.toLowerCase())?t.toLowerCase():void 0,r=Dr(e.offsetPercent??e.offset_percent??e.offsetPct??e.offset_pct),n=Dr(e.offsetPx??e.offset_px??e.offsetPixels??e.offset_pixels),i=Dr(e.xPercent??e.x_percent??e.xPct??e.x_pct??e.horizontalPercent??e.horizontal_percent??e.x),s=Dr(e.yPercent??e.y_percent??e.yPct??e.y_pct??e.verticalPercent??e.vertical_percent??e.y);if(!(o===void 0&&r===void 0&&n===void 0&&i===void 0&&s===void 0))return {side:o,offsetPercent:r,offsetPx:n,xPercent:i,yPercent:s}},La=(e,t,o)=>{if(!o)return;let r=_r(e),n=Mr(r?.layout),i=[t?.position,t,e.layout?.position,e.layout,n?.position,n,r?.port_position,r?.portPosition,r?.position,r,e];for(let s of i){let d=Wc(s);if(d)return d}},zc=(e,t)=>{let o=e.type?.value??e.type?.label??e.layout?.type??void 0,r=Ma(e,o),n=$a(o,r),i=_a(e,n);return {label:e.name,face:Da(e),group:i,type:n,cableType:Aa(o),connected:!!(e.connected_endpoint||e.cable),connectorType:r,position:La(e,void 0,t)}},Uc=e=>[...e].sort((t,o)=>{let r=typeof t.position=="number"?t.position:Number.MAX_SAFE_INTEGER,n=typeof o.position=="number"?o.position:Number.MAX_SAFE_INTEGER;return r!==n?r-n:t.name.localeCompare(o.name)}),Vc=(e,t)=>{let o=e.find(n=>n.name===t);if(o)return o;let r={name:t,ports:[]};return e.push(r),r},Gc=(e,t)=>{let{includePortPositions:o=false,mapInterfaceToPort:r}=t,n=[],i=[];return Uc(e.interfaces??[]).forEach((d,c)=>{let l=r?r({device:e,iface:d,index:c}):zc(d,o);if(!l)return;let g=l.type??d.type?.value??d.type?.label??void 0,f=Ma(d,g,l.connectorType),u=$a(g,f),p=Da(d,l.face),b=_a(d,u,l.group);Vc(p==="rear"?i:n,b).ports.push({id:l.id,label:l.label??d.name,connected:l.connected??!!(d.connected_endpoint||d.cable),type:u,cableType:Aa(l.cableType??d.type?.value??d.type?.label??void 0),connectorType:f,position:La(d,l,o)});}),{front:n,rear:i}},Ba=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:e.status.value,uHeight:e.u_height,netboxId:e.id,netboxType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:e.site.name,role:e.role?.name,tenant:e.tenant?.name}}),Oa=(e,t={})=>{let o={label:e.name,status:e.status.value,deviceType:e.device_type.model,manufacturer:e.device_type.manufacturer.name,role:e.device_role.name,uHeight:1,uPosition:e.position||1,face:e.face||"front",netboxId:e.id,netboxType:"device",primaryIp4:e.primary_ip4?.address,primaryIp6:e.primary_ip6?.address,site:e.site.name,rack:e.rack?.name};if(t.includeInterfacePorts&&Array.isArray(e.interfaces)&&e.interfaces.length>0){let{front:r,rear:n}=Gc(e,t);r.length>0&&(o.ports=r),n.length>0&&(o.rearPorts=n);}return {id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${e.rack.id}`:void 0,extent:e.rack?"parent":void 0,data:o}},Wa=e=>({id:`cable-${e.id}`,source:Fa(e.termination_a.device),target:Fa(e.termination_b.device),type:"fiber",data:{bandwidth:e.type.label,length:e.length||0,color:e.color,netboxId:e.id,netboxType:"cable",status:e.status.value,terminationA:e.termination_a.name,terminationB:e.termination_b.name}}),Xc=(e,t={})=>{let o=[],r=[],n=new Map;return e.racks.forEach(i=>{o.push(Ba(i));}),e.devices.forEach(i=>{let s=Oa(i,t);o.push(s),n.set(i.name,s.id);}),e.cables.forEach(i=>{let s=Wa(i),d=(typeof i.termination_a.device.id=="number"?`device-${i.termination_a.device.id}`:void 0)??n.get(i.termination_a.device.name)??s.source,c=(typeof i.termination_b.device.id=="number"?`device-${i.termination_b.device.id}`:void 0)??n.get(i.termination_b.device.name)??s.target;r.push({...s,source:d,target:c});}),{nodes:o,edges:r}},jc=(e,t)=>{let o=new Map,r=new Set;return e.filter(i=>i.position!==null).sort((i,s)=>(i.position||0)-(s.position||0)).forEach(i=>{i.position&&(o.set(i.id,i.position),r.add(i.position));}),o};function $r(e){let{items:t,checkOutOfBounds:o,checkConflicts:r}=e,n=[],i=[];for(let s of t){let d=o(s);d&&!d.isValid&&d.error&&i.push(d.error);}for(let s=0;s<t.length;s++){let d=t[s];for(let c=s+1;c<t.length;c++){let l=t[c],g=r(d,l);g&&g.hasConflict&&g.conflict&&n.push(g.conflict);}}return {isValid:n.length===0&&i.length===0,conflicts:n,outOfBounds:i}}var Po=class extends Error{constructor(o,r,n,i,s){super(`Device placement conflict: ${r} at U${n}-${n+i-1} in rack ${o}${s?` conflicts with ${s}`:""}`);this.rackId=o;this.deviceId=r;this.uPosition=n;this.uHeight=i;this.conflictWith=s;this.name="DevicePlacementError";}};function Qn(e,t={}){let o=He(e);return $r({items:e.devices,checkOutOfBounds:r=>r.unit+r.height-1>e.units?{isValid:false,error:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,rackUHeight:e.units}}:null,checkConflicts:(r,n)=>{let i=r.unit,s=r.unit+r.height-1,d=n.unit,c=n.unit+n.height-1;if(i<=c&&s>=d){if(o){let l=Oe(r),g=Oe(n);if(!Qo(l,g))return null}return {hasConflict:true,conflict:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,conflictWith:n.id}}}return null}})}function za(e,t,o={}){let{deviceTypeMapping:r={}}=o,n=r[e.type]||"device",i=po(t,e.unit,e.height,e);return {id:e.id,type:n,position:i,parentId:t.id,extent:"parent",data:{label:e.name,status:e.status||"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections,frontImageUrl:e.frontImageUrl,rearImageUrl:e.rearImageUrl,frontImageAttribution:e.frontImageAttribution,rearImageAttribution:e.rearImageAttribution,imageFit:e.imageFit,imagePosition:e.imagePosition,imageRepeat:e.imageRepeat,stretchToFit:e.stretchToFit,rackWidthPx:t.data.rackWidthPx,rackLayout:t.data.rackLayout,rackFaceGapPx:t.data.rackFaceGapPx,mountMode:Oe(e)}}}function Yc(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[],rackWidthPx:e.rackWidthPx,rackLayout:e.rackLayout,rackFaceGapPx:e.rackFaceGapPx}}}function Kc(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let s of e){let d=Qn(s,t);if(!d.isValid&&o==="strict"){let c=[];throw d.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),d.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new Po(s.id,d.conflicts[0]?.deviceId||d.outOfBounds[0]?.deviceId||"unknown",d.conflicts[0]?.uPosition||d.outOfBounds[0]?.uPosition||1,d.conflicts[0]?.uHeight||d.outOfBounds[0]?.uHeight||1)}}for(let s of e){let d=Yc(s);n.push(d);for(let c of s.devices)try{let l=za(c,d,t);i.push(l);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=rr(d,{id:c.id,data:{label:c.name,uHeight:c.height,mountMode:Oe(c)}},i,c.unit);if(g!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${g} due to conflict`);let f={...c,unit:g},u=za(f,d,t);i.push(u);}else throw new Po(s.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Zc(e){let t=[],o=e.filter(r=>r.type==="rack");for(let r of o){let i=e.filter(s=>Ho(s.type)&&s.parentId===r.id).map(s=>({id:s.id,name:s.data.label,unit:s.data.uPosition||1,height:s.data.uHeight||1,type:s.data.deviceType||"server",width:s.data.width==="full"||s.data.width==="half"?s.data.width:void 0,ports:Array.isArray(s.data.ports)?s.data.ports:void 0,connections:s.data.connections,frontImageUrl:s.data.frontImageUrl,rearImageUrl:s.data.rearImageUrl,frontImageAttribution:s.data.frontImageAttribution,rearImageAttribution:s.data.rearImageAttribution,imageFit:s.data.imageFit,imagePosition:s.data.imagePosition,imageRepeat:s.data.imageRepeat,stretchToFit:s.data.stretchToFit,mountMode:Oe(s.data)}));t.push({id:r.id,name:r.data.label,position:r.position,units:r.data.uHeight||42,uNumberingDirection:r.data.uNumberingDirection||"bottom-up",customHeaderText:r.data.customHeaderText,rackLayout:r.data.rackLayout,rackFaceGapPx:r.data.rackFaceGapPx,devices:i,rackWidthPx:r.data.rackWidthPx});}return t}function qc(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,devices:n.devices.map(i=>i.id!==o?i:{...i,unit:r})})}function Jc(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!Qn({...i,devices:[...i.devices,o]},r).isValid)throw new Po(t,o.id,o.unit,o.height);return {...i,devices:[...i.devices,o]}})}function Qc(e,t,o){return e.map(r=>r.id!==t?r:{...r,devices:r.devices.filter(n=>n.id!==o)})}var Co=class extends Error{constructor(o,r,n,i){super(`Splice placement conflict: ${r} at holder ${n} in tray ${o}${i?` conflicts with ${i}`:""}`);this.trayId=o;this.spliceId=r;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function ei(e,t={}){return $r({items:e.splices,checkOutOfBounds:o=>o.holder<1||o.holder>Bt?{isValid:false,error:{spliceId:o.id,holder:o.holder,max:Bt}}:null,checkConflicts:(o,r)=>o.holder===r.holder?{hasConflict:true,conflict:{spliceId:o.id,holder:o.holder,conflictWith:r.id}}:null})}function Ua(e,t){let o=e.mode==="ribbon",r=zo(t,e.holder,o);return {id:e.id,type:"splice",position:r,parentId:t.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function el(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function tl(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let s of e){let d=ei(s,t);if(!d.isValid&&o==="strict"){let c=[];throw d.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),d.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new Co(s.id,d.conflicts[0]?.spliceId||d.outOfBounds[0]?.spliceId||"unknown",d.conflicts[0]?.holder||d.outOfBounds[0]?.holder||1)}}for(let s of e){let d=el(s);n.push(d);for(let c of s.splices)try{let l=c.holder;if(o==="nearest"){let u={id:c.id,type:"splice",position:{x:0,y:0},data:{label:c.name,holderPosition:c.holder}},p=[...n,...i];Bo(d,u,c.holder,p)||(l=Wo(d,u,p,c.holder));}let g=l!==c.holder?{...c,holder:l}:c,f=Ua(g,d);i.push(f);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=[...n,...i],f=Wo(d,{id:c.id,data:{label:c.name,holderPosition:c.holder}},g,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let u={...c,holder:f},p=Ua(u,d);i.push(p);}else throw new Co(s.id,c.id,c.holder)}}}return n.push(...i),n}function ol(e){let t=[],o=e.filter(r=>r.type==="splice-tray");for(let r of o){let i=e.filter(s=>s.type==="splice"&&s.parentId===r.id).map(s=>({id:s.id,name:s.data.label,holder:s.data.holderPosition||1,lossDb:s.data.lossDb,mode:s.data.mode||"single",ribbonFiberIds:s.data.ribbonFiberIds}));t.push({id:r.id,name:r.data.label,position:r.position,splices:i});}return t}function rl(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,splices:n.splices.map(i=>i.id!==o?i:{...i,holder:r})})}function nl(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!ei({...i,splices:[...i.splices,o]},r).isValid)throw new Co(t,o.id,o.holder);return {...i,splices:[...i.splices,o]}})}function il(e,t,o){return e.map(r=>r.id!==t?r:{...r,splices:r.splices.filter(n=>n.id!==o)})}var Va=2;var fe=e=>typeof e=="string"?e.trim():"",ht=e=>{if(typeof e=="number"&&Number.isFinite(e))return e},al=e=>{let t=fe(e).toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20"||t==="AC")return t},sl=(e,t)=>{if(t==="C13"||t==="C14")return "power_c13";if(t==="C19"||t==="C20")return "power_c19";if(t==="AC")return "power_ac";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")?"mgmt":o.includes("usb")?"usb":"ethernet"},dl=e=>{if(e==="power_c13")return "C13";if(e==="power_c19")return "C19";if(e==="power_ac")return "AC"},cl=e=>e.toLowerCase().replace(/_/g,"-").trim(),ll=e=>e>=1?"rackable":"zero-u",ul=e=>(e??"").toLowerCase()==="half"?"half":"full",pl=(e,t,o,r)=>{let n=r.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase();return `${e}-b${t}-${n||`p${o}`}`},Ga=(e,t)=>`${e}-${t}`.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function fl(e){let t=[],o=fe(e.manufacturer),r=fe(e.model),n=fe(e.role)||fe(e.deviceType)||fe(e.device_type)||"device",i=ht(e.uHeight)??ht(e.u_height)??0;o||t.push({severity:"warning",code:"MISSING_MANUFACTURER",message:"Template is missing manufacturer",path:"manufacturer"}),r||t.push({severity:"warning",code:"MISSING_MODEL",message:"Template is missing model",path:"model"});let s=fe(e.id)||fe(e.slug)||Ga(o,r)||"unknown",d=fe(e.slug)||Ga(o,r)||s,c=Array.isArray(e.ports)?e.ports:[],l=Array.isArray(e.rearPorts)?e.rearPorts:Array.isArray(e.rear_ports)?e.rear_ports:[],f=(Array.isArray(e.frontRearPortLinks)?e.frontRearPortLinks:Array.isArray(e.front_rear_port_links)?e.front_rear_port_links:[]).map(u=>({frontPortId:fe(u.frontPortId)||fe(u.front_port_id),rearPortId:fe(u.rearPortId)||fe(u.rear_port_id)}));return {id:s,slug:d,manufacturer:o,model:r,role:n,uHeight:i,width:fe(e.width)||void 0,frontBlocks:c,rearBlocks:l,rawLinks:f,frontImageUrl:fe(e.frontImageUrl)||fe(e.front_image_url)||void 0,rearImageUrl:fe(e.rearImageUrl)||fe(e.rear_image_url)||void 0,frontImageAttribution:fe(e.frontImageAttribution)||void 0,rearImageAttribution:fe(e.rearImageAttribution)||void 0,tags:Array.isArray(e.tags)?e.tags.map(fe).filter(Boolean):[],sourceRepository:fe(e.sourceRepository)||fe(e.source_repository)||void 0,sourcePath:fe(e.sourcePath)||fe(e.source_path)||void 0,issues:t}}function Xa(e,t,o){let r=fe(e.name)||`Block ${o+1}`,i=(Array.isArray(e.ports)?e.ports:[]).map((s,d)=>{let c=fe(s.label)||fe(s.name)||`Port ${d+1}`,l=al(s.connectorType??s.connector_type),g=sl(fe(s.type),l),f=l??dl(g),p={id:fe(s.id)||pl(t,o,d,c),label:c,type:g,connectorType:f};if(s.position){let b=s.position,w=fe(b.side),N={},k=false;w&&["top","right","bottom","left"].includes(w)&&(N.side=w,k=true);let T=ht(b.offsetPercent)??ht(b.offset_percent);T!==void 0&&(N.offsetPercent=T,k=true);let C=ht(b.offsetPx)??ht(b.offset_px);C!==void 0&&(N.offsetPx=C,k=true);let S=ht(b.xPercent)??ht(b.x_percent);S!==void 0&&(N.xPercent=S,k=true);let x=ht(b.yPercent)??ht(b.y_percent);x!==void 0&&(N.yPercent=x,k=true),k&&(p.position=N);}return p});return {name:r,ports:i}}function gl(e){let t=[],o=cl(e.role),r=e.uHeight,n=ll(r),i=ul(e.width),s=e.frontBlocks.map((c,l)=>Xa(c,"front",l)),d=e.rearBlocks.map((c,l)=>Xa(c,"rear",l));return {role:o,mountClass:n,uHeight:r,width:i,frontFace:{portBlocks:s,imageUrl:e.frontImageUrl,imageAttribution:e.frontImageAttribution},rearFace:{portBlocks:d,imageUrl:e.rearImageUrl,imageAttribution:e.rearImageAttribution},issues:t}}function bl(e,t){let o=new Set(e.portBlocks.map(i=>i.name)),r=new Set(t.portBlocks.map(i=>i.name)),n=[...o].filter(i=>r.has(i));return n.length===0?{front:e,rear:t}:{front:{...e,portBlocks:e.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Front \xB7 ${i.name}`}:i)},rear:{...t,portBlocks:t.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Rear \xB7 ${i.name}`}:i)}}}function ml(e){let t=[],{front:o,rear:r}=bl(e.frontFace,e.rearFace),n=e.role;return (!n||n==="device")&&[...o.portBlocks,...r.portBlocks].some(s=>s.ports.some(d=>d.type&&d.type.startsWith("power")))&&e.mountClass==="zero-u"&&(n="pdu"),{frontFace:o,rearFace:r,mountClass:e.mountClass,role:n,issues:t}}function Xo(e){return e.portBlocks.reduce((t,o)=>t+o.ports.length,0)}function hl(e,t){let o=[],r=[];for(let p of t.frontFace.portBlocks)for(let b of p.ports)r.push({id:b.id,face:"front"});for(let p of t.rearFace.portBlocks)for(let b of p.ports)r.push({id:b.id,face:"rear"});let n=new Map;for(let{id:p}of r)n.set(p,(n.get(p)??0)+1);for(let[p,b]of n)b>1&&o.push({severity:"error",code:"DUPLICATE_PORT_ID",message:`Duplicate port id "${p}" found ${b} times`,path:`ports.${p}`});let i=e.frontBlocks.reduce((p,b)=>p+(Array.isArray(b.ports)?b.ports.length:0),0),s=e.rearBlocks.reduce((p,b)=>p+(Array.isArray(b.ports)?b.ports.length:0),0),d=Xo(t.frontFace),c=Xo(t.rearFace);d!==i&&o.push({severity:"error",code:"FRONT_PORT_COUNT_MISMATCH",message:`Front port count mismatch: raw=${i}, parsed=${d}`,path:"faces.front"}),c!==s&&o.push({severity:"error",code:"REAR_PORT_COUNT_MISMATCH",message:`Rear port count mismatch: raw=${s}, parsed=${c}`,path:"faces.rear"});let l=new Set(r.map(p=>p.id)),g=new Set(r.filter(p=>p.face==="front").map(p=>p.id)),f=new Set(r.filter(p=>p.face==="rear").map(p=>p.id));for(let p of e.rawLinks)p.frontPortId&&!g.has(p.frontPortId)&&!l.has(p.frontPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_FRONT_PORT_MISSING",message:`Pass-through link references unknown front port "${p.frontPortId}"`,path:"frontRearPortLinks"}),p.rearPortId&&!f.has(p.rearPortId)&&!l.has(p.rearPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_REAR_PORT_MISSING",message:`Pass-through link references unknown rear port "${p.rearPortId}"`,path:"frontRearPortLinks"});return {valid:!o.some(p=>p.severity==="error"),issues:o,portCounts:{front:d,rear:c}}}function yl(e,t,o){let r=e.rawLinks.filter(i=>!!i.frontPortId&&!!i.rearPortId).map(i=>({frontPortId:i.frontPortId,rearPortId:i.rearPortId})),n=e.sourceRepository?{kind:"netbox",repository:e.sourceRepository,path:e.sourcePath}:void 0;return {templateSchemaVersion:2,id:e.id,slug:e.slug,manufacturer:e.manufacturer,model:e.model,role:o.role,mountClass:o.mountClass,uHeight:t.uHeight,width:t.width,faces:{front:o.frontFace,rear:o.rearFace},frontRearPortLinks:r,images:{front:o.frontFace.imageUrl??null,rear:o.rearFace.imageUrl??null},source:n,tags:e.tags.length>0?e.tags:void 0}}function wl(e){let t=fl(e),o=gl(t),r=ml(o),n=hl(t,r);return n.issues.push(...t.issues,...o.issues,...r.issues),n.valid?{template:yl(t,o,r),report:n}:{template:null,report:n}}function xl(e){return Xo(e)}function Nl(e,t,o){let r=[],n=Xo(e.faces.front),i=Xo(e.faces.rear);return t!==n&&r.push({severity:"error",code:"RENDER_FRONT_COUNT_MISMATCH",message:`Rendered front handle count (${t}) does not match template (${n})`,path:"faces.front"}),o!==i&&r.push({severity:"error",code:"RENDER_REAR_COUNT_MISMATCH",message:`Rendered rear handle count (${o}) does not match template (${i})`,path:"faces.rear"}),r}
|
|
2
|
+
export{Hd as COUPLERS_PER_PANEL,Pr as COUPLER_SLOT_HEIGHT_PX,Fd as COUPLER_WIDTH_PX,Rn as CableNode,On as ClosureNode,En as CouplerNode,go as DeviceNode,Po as DevicePlacementError,Kn as DiagramErrorBoundary,mi as FIBER_COLORS_12,ar as FiberEdge,en as FiberNode,_c as FibreCableWithTubesExpanded,Hc as FibreFlowMap,zn as FibreSplitNode,Eo as HANDLE_EXTENSION_PX,In as MultiTubeCableNode,Yn as NetworkDiagram,Xi as PANEL_BORDER_WIDTH,oo as PANEL_HEADER_HEIGHT,kr as PANEL_HEIGHT_PX,to as PANEL_PADDING,ji as PANEL_TUBE_TRAY_SPACING,Nr as PANEL_WIDTH_PX,nn as POWER_CONNECTORS,An as PatchPanelNode,on as PowerEdge,xt as RACK_HEADER_HEIGHT,Zr as RACK_WIDTH_PX,Qr as RackNode,yn as SpliceNode,Co as SplicePlacementError,Pn as SpliceTrayNode,Va as TEMPLATE_SCHEMA_VERSION,Cn as TubeNode,Je as U_HEIGHT_PX,bn as VerticalPDU,Ri as Width,Jc as addDeviceToRack,nl as addSpliceToTray,Ue as baseColorFor,Kc as buildNodesFromRackConfig,tl as buildNodesFromSpliceConfig,_n as calculateClosureDimensions,_d as calculateCouplerRightX,$d as calculateCouplerSlotSpacing,ta as calculateCouplerSpacing,po as calculateDevicePositionFromU,Dn as calculatePanelDimensions,Qi as calculateSlotPositionFromY,Pd as calculateSplicePositionFromNumber,jc as calculateUPositions,ea as calculateYFromSlotPosition,xl as countTemplateFacePorts,Un as createNetworkDiagramStore,Zc as createRackConfigFromNodes,ol as createSpliceConfigFromNodes,tn as fiberSolidOrStriped,Er as findNearestRack,Wo as findNextAvailableHolderPosition,rr as findNextAvailableUPosition,$c as generateLayout,Si as getConnectorConfig,Fn as getCouplerDimensions,an as getDeviceConnectorType,Kt as getFiberColor,Ji as getInnerContentWidth,dr as getPDUPortType,Dd as getPanelHeight,qi as getPanelWidth,Lt as getPowerPortStyle,sa as getRackBounds,gt as getStatusColor,Yi as getTrayDimensions,Cr as getTubeDimensions,Ha as inventoryCableToNetworkEdge,Ea as inventoryDeviceToNetworkNode,Ia as inventoryRackToNetworkNode,Mc as inventoryToNetworkDiagram,Ms as isHighPowerConnector,da as isPointInRack,Yt as isStriped,Jr as isUPositionAvailable,Wa as netboxCableToNetworkEdge,Oa as netboxDeviceToNetworkNode,Ba as netboxRackToNetworkNode,Xc as netboxToNetworkDiagram,wl as parseNetboxTemplate,Qc as removeDeviceFromRack,il as removeSpliceFromTray,Ae as replaceEdge,Md as snapToCouplerPosition,xn as snapToSplicePosition,or as snapToUPosition,bi as updateDeviceUPosition,qc as updateDeviceUPositionInSchema,rl as updateSpliceHolderPosition,Xn as useDiagramEdges,Gn as useDiagramNodes,Gd as useNetworkDiagram,ms as validateAndSnapDevice,Qn as validateRackDevicePlacements,Nl as validateRenderFidelity,ei as validateSplicePlacements};//# sourceMappingURL=index.mjs.map
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|