@mp70/react-networks 0.3.0-alpha.2 → 0.3.1-alpha.0

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.mjs CHANGED
@@ -1,3 +1,3 @@
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
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 Ke=20,Ct=60,on=300,Ho=5;function xi(e){return e==="system"?typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e}function Ni(e,t){let r=xi(e)==="light"?"react-flow-light":"react-flow-dark";return t?`${r} ${t}`:r}function ki(e){return xi(e)==="light"?"#e5e5e5":"#2a2a2a"}function Pi(e,t){return {width:"100%",height:"100%",...t}}var Ts=["device","server","switch","router"],Ss=new Set(Ts);function Do(e){return typeof e=="string"&&Ss.has(e)}function Xe(e){return !!e&&Do(e.type)}var Is=/-(source|target)$/i;function Le(e){return e?e.replace(Is,""):""}function tt(e){return typeof e=="string"&&e.includes("power")}function vt(e,t){return typeof t.id=="string"&&t.id.length>0?t.id:tt(t.type)?t.label:`${e}-${t.label}`}function rr(e){let t=Le(e).toLowerCase();return t.startsWith("pwr")||t.includes("power")}var Es="Network Ports",Fs="Rear Network Ports",Hs="Power Ports",Ci=8,Ds=92;function nr(e){return Math.max(0,Math.min(100,e))}function rn(e){if(e==="top"||e==="right"||e==="bottom"||e==="left")return e}function vi(e){return typeof e.position?.xPercent=="number"&&typeof e.position?.yPercent=="number"}function _s(e){return typeof e.position?.offsetPercent=="number"||typeof e.position?.offsetPx=="number"}function Ms(e){return e.face==="rear"||e.face==="back"?"rear":e.face==="front"?"front":tt(e.type)?"rear":"front"}function $s(e,t){return typeof e.group=="string"&&e.group.trim().length>0?e.group.trim():tt(e.type)?Hs:t==="rear"?Fs:Es}function ir(e){return typeof e.port.order=="number"&&Number.isFinite(e.port.order)?e.port.order:e.index}function As(e,t){return t<=1?50:Ci+e*(Ds-Ci)/(t-1)}function Ls(e){let t=e.filter(n=>!!rn(n.port.position?.side)&&!vi(n.port)&&!_s(n.port)),o=new Map,r=new Map;return t.forEach(n=>{let i=rn(n.port.position?.side);if(!i)return;let a=r.get(i);if(a){a.push(n);return}r.set(i,[n]);}),r.forEach(n=>{let i=[...n].sort((a,s)=>{let c=ir(a)-ir(s);return c!==0?c:a.index-s.index});i.forEach((a,s)=>{o.set(a.index,As(s,i.length));});}),o}function Bs(e,t){let o=rn(e.position?.side);if(vi(e)){let a={xPercent:nr(e.position?.xPercent),yPercent:nr(e.position?.yPercent)};return o&&(a.side=o),a}if(!o)return;let r={side:o};if(typeof e.position?.offsetPx=="number"&&Number.isFinite(e.position.offsetPx))return r.offsetPx=e.position.offsetPx,r;let i=(typeof e.position?.offsetPercent=="number"&&Number.isFinite(e.position.offsetPercent)?nr(e.position.offsetPercent):void 0)??(typeof t=="number"?nr(t):void 0);return typeof i=="number"&&(r.offsetPercent=i),r}function Os(e,t){let o=Bs(e.port,t);return {id:e.port.id,label:e.port.label,connected:e.port.connected??false,type:e.port.type,cableType:e.port.cableType,connectorType:e.port.connectorType,...o?{position:o}:{}}}function Ri(e){let t=new Map;e.forEach((n,i)=>{if(typeof n.label!="string"||n.label.trim().length===0)return;let a=Ms(n),s=$s(n,a),c=`${a}:${s}`,l=t.get(c);if(l){l.entries.push({index:i,port:{...n,label:n.label.trim()}});return}t.set(c,{face:a,groupName:s,entries:[{index:i,port:{...n,label:n.label.trim()}}]});});let o=[],r=[];return t.forEach(n=>{let i=[...n.entries].sort((c,l)=>{let g=ir(c)-ir(l);return g!==0?g:c.index-l.index}),a=Ls(i),s={name:n.groupName,ports:i.map(c=>Os(c,a.get(c.index)))};if(n.face==="rear"){r.push(s);return}o.push(s);}),{ports:o,rearPorts:r}}function Je(e){return Array.isArray(e?.ports)?Ri(e.ports):{ports:Array.isArray(e?.portGroups)?e.portGroups:[],rearPorts:Array.isArray(e?.rearPortGroups)?e.rearPortGroups:[]}}function nn(e){return Je(e).ports}function an(e){return Je(e).rearPorts}function _o(e){return Array.isArray(e)?e.reduce((t,o)=>t+(Array.isArray(o.ports)?o.ports.length:0),0):0}function Ti(e){return _o(Je(e).ports)>0}function Si(e){return _o(Je(e).rearPorts)>0}function it(e){let t=Ti(e);return Si(e)&&!t?"rear":"front"}function Ii(e){return typeof e=="string"&&e.trim().length>0}function sn(e){let{ports:t,rearPorts:o}=Je(e),r=_o(t)>0||Ii(e.frontImageUrl),n=_o(o)>0||Ii(e.rearImageUrl);if(r&&n)return "both";if(r)return "front";if(n)return "rear"}function Ei(e,t,o,r){let n=e.mountMode;if(n==="front"||n==="rear"||n==="both")return n;let i=sn(e);if(i)return i;if(e.view==="front"||e.view==="rear")return e.view;let a=o+r/2;return t>=a?"front":"rear"}var Ws=24;function zs(e){return e?.rackLayout==="split-face"?"split-face":"single-face"}function Ie(e){return zs(e)==="split-face"}function Lt(e){return typeof e?.rackFaceGapPx=="number"&&Number.isFinite(e.rackFaceGapPx)&&e.rackFaceGapPx>=0?e.rackFaceGapPx:Ws}function $t(e){return e?.rackWidthPx||300}function Mo(e){let t=$t(e);return Ie(e)?t*2+Lt(e):t}function Be(e){if(e?.mountMode==="front"||e?.mountMode==="rear"||e?.mountMode==="both")return e.mountMode;let t=sn(e??{});return t||"both"}function At(e){return e==="front"?["front"]:e==="rear"?["rear"]:["front","rear"]}function ar(e,t){let o=new Set(At(e));return At(t).some(n=>o.has(n))}function sr(e,t){return Ie(e)&&Be(t)==="front"?$t(e)+Lt(e):0}function Fi(e,t){return Ie(e)&&Be(t)==="both"?Mo(e):$t(e)}var Hi=e=>{if(typeof e.parentId=="string")return e.parentId;if(typeof e.parentNode=="string")return e.parentNode},Rt=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):t,Us=()=>"bottom-up",Yt=e=>e.data.uNumberingDirection||Us(),dr=(e,t,o)=>o==="bottom-up"?t-e+1:e,cr=(e,t,o)=>o==="bottom-up"?t-e+1:e;var lr=(e,t,o,r)=>{let n=Hi(e);if(!n||n!==t.id)return o;let i=Rt(e.data.uHeight,1),a=Rt(t.data.uHeight,42),s=Yt(t),c=60,l=o.y-c,g=Math.round(l/20)+1,f;s==="bottom-up"?f=dr(g,a,s)-i+1:f=dr(g,a,s);let p=a-i+1,u=Math.max(1,Math.min(p,f));if(s==="top-down"&&f<=1&&(u=1),!jt(t,e,u,r)){let h=ur(t,e,r,u);if(h!==void 0)u=h;else {let w=Rt(e.data.uPosition,0);if(w>0&&jt(t,e,w,r))u=w;else return {x:sr(t.data,e.data),y:e.position?.y??o.y,uPosition:w>0?w:void 0}}}let y;if(s==="bottom-up"){let h=u+i-1,w=cr(h,a,s);y=c+(w-1)*20-1;}else {let h=cr(u,a,s);y=c+(h-1)*20-1;}return {x:sr(t.data,e.data),y,uPosition:u}},jt=(e,t,o,r)=>{let n=Rt(t.data.uHeight,1),i=Rt(e.data.uHeight,42);if(o<1||o+n-1>i)return false;let a=r.filter(l=>Do(l.type)&&Hi(l)===e.id&&l.id!==t.id),s=Ie(e.data),c=Be(t.data);for(let l of a){let g=Rt(l.data.uPosition,1),f=Rt(l.data.uHeight,1),p=o,u=o+n-1,y=g,h=g+f-1;if(p<=h&&u>=y){if(s){let w=Be(l.data);if(!ar(c,w))continue}return false}}return true},ur=(e,t,o,r=1)=>{let n=Rt(t.data.uHeight,1),a=Rt(e.data.uHeight,42)-n+1;if(a<1)return;let s=Number.isFinite(r)?Math.floor(r):1,c=Math.max(1,Math.min(a,s));for(let l=c;l<=a;l++)if(jt(e,t,l,o))return l;for(let l=1;l<c;l++)if(jt(e,t,l,o))return l},bo=(e,t,o=1,r)=>{let n=60,i=Yt(e),a=e.data.uHeight||42,s=cr(t,a,i),c;if(i==="bottom-up"){let l=t+o-1,g=cr(l,a,i);c=n+(g-1)*20-1;}else c=n+(s-1)*20-1;return {x:sr(e.data,r),y:c}},Di=(e,t,o)=>{let r=e.data.uHeight||1,n=bo(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}}},Vs=(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?Di(e,t,i):e};function bt(e){switch(e){case "active":return "#10b981";case "inactive":return "#ef4444";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var dn=({data:e,selected:t,id:o,onViewChange:r,onRackFaceChange:n,isDragOver:i=false})=>{let{label:a,ports:s=0,status:c="active",uHeight:l=42,face:g="front",customHeaderText:f}=e,p=Ie(e),u=Mo(e),y=$t(e),h=Lt(e),{getNodes:w,setNodes:k}=useReactFlow(),v=w(),[C,R]=useState(e.showUMarkers!==void 0?e.showUMarkers:true),x=()=>{let M=Yt({data:e})==="bottom-up"?"top-down":"bottom-up";k(D=>D.map(U=>U.id===o?{...U,data:{...U.data,uNumberingDirection:M}}:U));},I=()=>{if(p)return;let E=g==="front"?"rear":"front";n?n(o,E):r?v.filter(D=>D.parentId===o).forEach(D=>{r(D.id,E);}):k(M=>M.map(D=>D.id===o?{...D,data:{...D.data,face:E}}:D.parentId===o?{...D,data:{...D.data,view:E}}:D));},_=()=>{let E=[],M=60,D=Yt({data:e});for(let U=1;U<=l;U++){let ee=M+(U-1)*20-4,te=dr(U,l,D);E.push(jsx("div",{style:{position:"absolute",left:"-35px",top:`${ee}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:te},U));}return E};return jsxs("div",{className:`rack-node ${t?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${bt(c)}`,borderRadius:"8px",padding:0,width:`${u}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:a}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",p?"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(),R(!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 ${Yt({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Yt({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),!p&&jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),I();},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:p&&jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[jsx("div",{style:{width:`${y}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:`${h}px`}}),jsx("div",{style:{width:`${y}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:_()})]})};var cn=({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 ${bt(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:bt(r),borderRadius:"50%"}})]})};var _i=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function ze(e){let t=(e-1)%12;return _i[t]}function Zt(e){return e>12}function Tt(e,t){let o=t?.base??ze(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 ln(e){let t=Tt(e);return t.backgroundImage?{background:t.base,backgroundImage:t.backgroundImage}:{background:t.base}}function qt(e){return ze(e)}function St(e){return e.map(t=>({base:ze(t),striped:Zt(t)}))}function Ks(e,t,o,r,n,i,a,s){let c=St(o),l=c.length,g=r?1.2:1,f=!!s?.highlight,p=r?2:1.5,u=s?.highlightWidth??p*3,y=s?.highlightColor??c[0]?.base??"#22d3ee";return jsxs(Fragment,{children:[f&&jsx(BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:y,strokeWidth:u,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${p}px`,"--rn-edge-highlight-to":`${u}px`}}),c.map((h,w)=>{let v=(l-w)*g;return jsx("path",{d:t,stroke:h.base,strokeWidth:v,fill:"none",strokeLinecap:"butt",opacity:h.striped?.9:1,style:n},`${e}-ribbon-${w}`)}),c.some(h=>h.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&s&&(s.bandwidth||s.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${a}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:[s.bandwidth&&jsx("div",{children:s.bandwidth}),s.length&&jsxs("div",{children:[s.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var gr=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:l={},className:g})=>{let[f,p,u]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a}),{bandwidth:y,length:h,color:w="#00FFFF",striped:k=false,ribbonFiberIds:v,isRibbon:C,highlight:R,highlightColor:x,highlightWidth:I}=s||{},_=!!R;if((C||v&&v.length>=6&&v.length<=12)&&v)return Ks(e,f,v,c??false,l??{},p,u,s);let M=c?3:2,D=I??M*3,U={...l,stroke:w,strokeWidth:M,strokeDasharray:"none"};return jsxs(Fragment,{children:[_&&jsx(BaseEdge,{id:`${e}-highlight`,path:f,style:{...l,stroke:x??w,strokeWidth:D,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${M}px`,"--rn-edge-highlight-to":`${D}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&&s&&(y||h)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${p}px,${u}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[y&&jsx("div",{children:y}),h&&jsxs("div",{children:[h,"m"]})]})})]})};var un=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,style:s={},data:c,markerEnd:l})=>{let[g]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a}),f=c?.connectorType||"C13",p=c?.metadata??{},u=typeof c?.powerStrokeWidth=="number"?c.powerStrokeWidth:typeof p.strokeWidth=="number"?p.strokeWidth:void 0,y=typeof c?.powerStrokeDasharray=="string"?c.powerStrokeDasharray:typeof p.strokeDasharray=="string"?p.strokeDasharray:void 0,h=typeof c?.powerOpacity=="number"?c.powerOpacity:typeof p.opacity=="number"?p.opacity:void 0;return jsx(BaseEdge,{id:e,path:g,markerEnd:l,style:(()=>{let v=u??(f==="C19"?5:3),C=y??(f==="C19"?"none":"6,3");return {...{stroke:c?.color||"#f59e0b",strokeWidth:v,strokeLinecap:"round",strokeLinejoin:"round",...h!==void 0?{opacity:h}:{}},strokeDasharray:C,...s}})()})};function td(e,t,o,r,n,i,a,s,c,l,g){let f=St(s),p=f.length,u=c?1.8:1.5,y=!!g?.highlight,h=c?3:2.5,w=g?.highlightWidth??h*3,k=g?.highlightColor??f[0]?.base??"#22d3ee",[v,C,R]=getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a});return jsxs(Fragment,{children:[y&&jsx(BaseEdge,{id:`${e}-highlight`,path:v,style:{...l,stroke:k,strokeWidth:w,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${h}px`,"--rn-edge-highlight-to":`${w}px`}}),f.map((x,I)=>{let E=(p-I)*u;return jsx("path",{d:v,stroke:x.base,strokeWidth:E,fill:"none",strokeLinecap:"butt",opacity:x.striped?.9:1,style:l},`${e}-ribbon-${I}`)}),f.some(x=>x.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:v,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,${R}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:[s.length,"F"]})]})})]})}var Li=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",ribbonFiberIds:p,isRibbon:u,highlight:y,highlightColor:h,highlightWidth:w}=s||{},k=!!y;if((u||p&&p.length>=6&&p.length<=12)&&p)return td(e,t,o,r,n,i,a,p,c??false,l??{},s);let C=c?4:3,R=w??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:a})[0],style:{...l,stroke:h??f,strokeWidth:R,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${R}px`}}),jsx(SmoothStepEdge,{...g,id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:x})]})};function rd({sourceX:e,sourceY:t,targetX:o,targetY:r,sourcePosition:n,targetPosition:i}){let a=n===Position.Left||n===Position.Right,s;if(a){let c=(e+o)/2;s=`M ${e},${t} L ${c},${t} L ${c},${r} L ${o},${r}`;}else {let c=(t+r)/2;s=`M ${e},${t} L ${e},${c} L ${o},${c} L ${o},${r}`;}return s}function nd(e,t,o,r,n,i){let a=St(o),s=a.length,c=r?1.2:1,l=!!i?.highlight,g=r?2:1.5,f=i?.highlightWidth??g*3,p=i?.highlightColor??a[0]?.base??"#22d3ee",u=t.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),y=u?(parseFloat(u[1])+parseFloat(u[3]))/2:0,h=u?(parseFloat(u[2])+parseFloat(u[4]))/2:0;return jsxs(Fragment,{children:[l&&jsx(BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:p,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${g}px`,"--rn-edge-highlight-to":`${f}px`}}),a.map((w,k)=>{let C=(s-k)*c;return jsx("path",{d:t,stroke:w.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:n},`${e}-ribbon-${k}`)}),a.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&&i&&(i.bandwidth||i.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${y}px,${h}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${a[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 Wi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",striped:p=false,ribbonFiberIds:u,isRibbon:y,highlight:h,highlightColor:w,highlightWidth:k}=s||{},v=!!h,C=rd({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a});if((y||u&&u.length>=6&&u.length<=12)&&u)return nd(e,C,u,c??false,l??{},s);let x=c?3:2,I=k??x*3,_={...l,stroke:f,strokeWidth:x,strokeDasharray:"none"};return jsxs(Fragment,{children:[v&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...l,stroke:w??f,strokeWidth:I,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${x}px`,"--rn-edge-highlight-to":`${I}px`}}),jsx(BaseEdge,{id:e,path:C,style:_}),p&&jsx(BaseEdge,{id:`${e}-stripe`,path:C,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var Vi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,style:s={},data:c,markerEnd:l,selected:g})=>{let{color:f="#6366f1",label:p,highlight:u,highlightColor:y,highlightWidth:h}=c||{},w=!!u,k=8,v=h??k*1.8,[C,R,x]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a}),I={...s,stroke:f,strokeWidth:k,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxs(Fragment,{children:[w&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...s,stroke:y??f,strokeWidth:v,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${y??f}) drop-shadow(0 0 16px ${y??f})`,"--rn-edge-highlight-from":`${k}px`,"--rn-edge-highlight-to":`${v}px`}}),jsx(BaseEdge,{id:e,path:C,markerEnd:l,style:I}),p&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${R}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:p})})]})};var Gi=(o=>(o.FULL="full",o.HALF="half",o))(Gi||{});var fn={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 Ot(e){let t=fn[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,a=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",...a}}function Xi(e){let t=fn[e];if(!t)throw new Error(`Unknown connector type: ${e}`);return t}function cd(e){return Xi(e).amperage===16}function mr(e){return e%10<8?"C13":"C19"}function gn(e){let t=e.toLowerCase();return t.includes("mx304")||t.includes("mx480")||t.includes("mx960")?"C20":"C14"}var ud="#6b7280",pd="#374151",bn="#10b981",fd="100% 100%",hr=1,gd={smf:"#fbbf24",cat6:"#8b5cf6",om3:"#06b6d4",om4:"#8b5cf6",om5:"#84cc16",cat5e:"#3b82f6",cat6a:"#ef4444",cat7:"#f97316",fiber:"#3b82f6",ethernet:"#10b981"},bd=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,md=/^data:image\//i,hd=typeof window<"u"?ot.useLayoutEffect:ot.useEffect;function yd(e){return (e??"").toLowerCase().replace(/_/g,"-")}function wd(e){return !bd.test(e)&&!e.startsWith("//")}function xd(e){if(!e)return;let t=e.trim();if(t){if(wd(t))return t;try{let o=new URL(t),r=o.protocol.toLowerCase();return r==="https:"||r==="blob:"?o.href:r==="data:"&&md.test(t)?t:void 0}catch{return}}}function Nd(e){return `url(${JSON.stringify(e)})`}function yn(e){return tt(e.type)}function wn(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":gn(t)}function mn(e,t){return vt(e,t)}function kd(e,t,o,r,n){let i=t.length>0||!!r,a=o.length>0||!!n;return e||(i?"front":a?"rear":"front")}function Pd(e,t){return t===true||e==="fill"?fd:e==="none"?"auto":e==="scale-down"?"contain":e??"cover"}function Cd(e){return yn(e)?e.type==="power_c19"?"#fbbf24":"#f59e0b":e.type==="console"||e.type==="mgmt"?"#8b5cf6":e.type==="usb"?bn:e.cableType?gd[e.cableType]??bn:bn}function vd(e){return e.connected?Cd(e):ud}function Yi(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 Rd(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 Td(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 Oo(e){return Math.max(0,Math.min(100,e))}function st(e,t,o){return Math.max(t,Math.min(o,e))}function hn(e){return typeof e.position?.xPercent=="number"&&typeof e.position?.yPercent=="number"}function Sd(e,t,o,r,n){let i=[];for(let g of e)for(let f of g.ports)hn(f)&&i.push({handleId:mn(g.name,f),xPercent:Oo(f.position.xPercent),yPercent:Oo(f.position.yPercent),side:f.position?.side});if(i.length===0)return {heightByHandleId:new Map,bottomAnchoredHandleIds:new Set};let a=new Set,s=[...new Set(i.map(g=>Number(g.yPercent.toFixed(2))))].sort((g,f)=>g-f);if(s.length>=2){let g=s[s.length-1];for(let f of i)f.side==="top"&&Math.abs(f.yPercent-g)<=.15&&a.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 h of i){if(h.handleId===g.handleId||Math.abs(h.xPercent-g.xPercent)>l)continue;let k=Math.abs(h.yPercent-g.yPercent);k<=0||(f=Math.min(f,k));}if(!Number.isFinite(f))continue;let p=o*f/100,u=Math.floor(p-.25),y=st(u,1,n);y<n&&c.set(g.handleId,y);}return {heightByHandleId:c,bottomAnchoredHandleIds:a}}function Id(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 Ed(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 Fd(e,t,o,r,n,i,a){if(!e.position)return;if(typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number"){let h=Oo(e.position.xPercent),w=Oo(e.position.yPercent),k=a??e.position.side??Ed(h,w),v=t/2+hr,C=Math.max(v,r-t/2),R=o/2+hr,x=Math.max(R,n-o/2),I=st(r*h/100,v,C),_=st(n*w/100,R,x);return {position:Id(k),style:{left:`${I-t/2-hr}px`,top:`${_-o/2-hr}px`,right:"initial",bottom:"initial",transform:"none"}}}if(!e.position.side)return;let c=e.position.side,l=typeof e.position.offsetPercent=="number"?Oo(e.position.offsetPercent):void 0,g=typeof e.position.offsetPx=="number"?e.position.offsetPx:void 0,f=t/2,p=Math.max(f,r-t/2),u=o/2,y=Math.max(u,n-o/2);switch(c){case "top":{let h=g!==void 0?g:r*(l??50)/100,w=st(h,f,p);return {position:Position.Top,style:{top:"0px",left:`${w}px`,right:void 0,bottom:void 0,transform:"translate(-50%, 50%)"}}}case "bottom":{let h=g!==void 0?g:r*(l??50)/100,w=st(h,f,p);return {position:Position.Bottom,style:{bottom:"0px",left:`${w}px`,right:void 0,top:void 0,transform:"translate(-50%, -50%)"}}}case "left":{let h=g!==void 0?g:n*(l??50)/100,w=st(h,u,y);return {position:Position.Left,style:{left:"0px",top:`${w}px`,right:void 0,bottom:void 0,transform:"translate(50%, -50%)"}}}case "right":{let h=g!==void 0?g:n*(l??50)/100,w=st(h,u,y);return {position:Position.Right,style:{right:"0px",top:`${w}px`,left:void 0,bottom:void 0,transform:"translate(-50%, -50%)"}}}default:return}}function Zi(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 qi(e,t,o,r){let n=e%2===0,i=Math.ceil(t/2),a=Math.floor(t/2),s=Math.max(n?i:a,1),c=Math.floor(n?e/2:(e-1)/2),l=Zi(c,s,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 Ki(e,t,o,r,n,i){let a=e%2===0,s=Math.ceil(t/2),c=Math.floor(t/2),l=Math.max(a?s:c,1),g=Math.floor(a?e/2:(e-1)/2),f=Zi(g,l,o,n),p=1,u=st(Math.round(r*.75),1,4),y=Math.max(p,i-r-1),h=st(p+r+u,p,y),w=a?p:h;return {position:Position.Top,style:{transform:"none",left:`${f-o/2}px`,top:`${w}px`,right:void 0,bottom:void 0}}}function Hd(e,t,o,r,n){let i=wn(e,n),a=Ot(i),s;if(r<=20){let g=Math.max(2,r-a.height-2);s=`${o<=1?(2+g)/2:2+t*(g-2)/(o-1)}px`;}else s=`${25+t*50}%`;return {position:Position.Right,style:{transform:"translateX(-50%)",top:s,width:`${a.width}px`,height:`${a.height}px`,background:a.color,border:`1px solid ${a.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:a.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:a.borderRadius,clipPath:a.clipPath}}}function Dd(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 qi(e,t,o,r)}function _d(e,t,o,r,n,i,a,s,c){if(s==="patch-panel"||s==="switch")return qi(t,o,r,i);if(yn(e)){let f=wn(e,c),p=Ot(f),u;if(a<=20){let w=Math.max(2,a-p.height-2);u=`${o<=1?(2+w)/2:2+t*(w-2)/(o-1)}px`;}else u=`${25+t*50}%`;return {position:Position.Left,style:{transform:"translateX(50%)",top:u,width:`${p.width}px`,height:`${p.height}px`,background:p.color,border:`1px solid ${p.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:p.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:p.borderRadius,clipPath:p.clipPath}}}return {position:Position.Right,style:{transform:"translate(-50%, -50%)",top:`${st(o<=1?a/2:n/2+t*Math.max(a-n,0)/Math.max(o-1,1),n/2,Math.max(n/2,a-n/2))}px`}}}function Md(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 ho=({id:e,data:t,selected:o})=>{let r=useUpdateNodeInternals(),{label:n,status:i="active",deviceType:a="server",manufacturer:s,uHeight:c=1,width:l="full",view:g,rackWidthPx:f,frontImageUrl:p,rearImageUrl:u,imageFit:y,imagePosition:h,imageRepeat:w,stretchToFit:k}=t,{ports:v,rearPorts:C}=ot.useMemo(()=>Je(t),[t]),R=yd(a),x=f??300,I=Ie(t),_=Be(t),E=kd(g??it(t),v,C,p,u),M=ot.useMemo(()=>I?At(_):[E],[I,_,E]),D=M[0]??E,U=I&&_==="both",ee=c*20,te=Lt(t),ie=x+te,ce=ot.useMemo(()=>[I?"split":"single",_,M.join(","),D,R,n,ee.toString(),x.toString(),ie.toString(),Yi(v),Yi(C)].join("|"),[I,_,M,D,R,n,ee,x,ie,v,C]);hd(()=>{r(e);},[ce,e,r]);let z=ot.useCallback(oe=>{let J=xd(oe==="rear"?u:p);return J?{backgroundImage:Nd(J),backgroundSize:Pd(y,k),backgroundPosition:h??"center",backgroundRepeat:w??"no-repeat"}:{}},[u,p,y,k,h,w]),V=ot.useMemo(()=>z("front"),[z]),B=ot.useMemo(()=>z("rear"),[z]),O=D==="rear"?B:V,X,Q;if(I)X=`${Fi(t,t)+4}px`,Q=void 0;else {let oe=x+4,re=Math.floor(x/2);X=l==="half"?`${re}px`:`${oe}px`,Q=l==="half"?`${re}px`:void 0;}let $=R==="server"&&c===1,A=bt(i),pe={"--rn-device-bg-image":U?"none":String(O.backgroundImage??"none"),"--rn-device-bg-position":String(O.backgroundPosition??"center"),"--rn-device-bg-repeat":String(O.backgroundRepeat??"no-repeat"),"--rn-device-bg-size":String(O.backgroundSize??"cover"),"--rn-device-border-color":A,"--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":Q??"auto","--rn-device-status-color":A,"--rn-device-translate-y":$?"-1px":"0px","--rn-device-width":X},se=ot.useMemo(()=>{let oe=new Set;for(let re of v)for(let J of re.ports)oe.add(mn(re.name,J));return oe},[v]),le=ot.useCallback((oe,re)=>re==="rear"&&U&&se.has(oe)?`${oe}--rear`:oe,[se,U]),j=ot.useCallback((oe,re,J=0,Oe=x)=>{let Ze=[];if(oe.length===0)return Ze;let{width:wt,height:de}=Td(Oe),{heightByHandleId:xt,bottomAnchoredHandleIds:qe}=Sd(oe,Oe,ee,wt,de),Vr=oe.reduce((Fe,je)=>Fe+je.ports.length,0),xe=(R==="switch"||R==="patch-panel")&&Vr>=24,Ee=R==="switch"||R==="patch-panel";for(let Fe of oe)for(let je=0;je<Fe.ports.length;je+=1){let Pe=Fe.ports[je],co=mn(Fe.name,Pe),ct=yn(Pe),Qe=wt,Nt=de;if(ct){let pt=wn(Pe,n),Dt=Ot(pt);Qe=Dt.width,Nt=Dt.height;}else if(hn(Pe)){let pt=xt.get(co);pt!==void 0&&(Nt=pt,Qe=st(Math.round(Nt*1.2),3,wt));}let lo=vd(Pe),To=Pe.connected?lo:pd,kt=!ct&&hn(Pe)&&Nt<de,qo=Rd(Qe,Nt,lo,To,kt),Jo=re==="front"?ct?Hd(Pe,je,Fe.ports.length,ee,n):xe?Ki(je,Fe.ports.length,wt,de,Oe,ee):Dd(je,Fe.ports.length,wt,Oe):!ct&&xe?Ki(je,Fe.ports.length,wt,de,Oe,ee):_d(Pe,je,Fe.ports.length,wt,de,Oe,ee,R,n),Vt=Fd(Pe,Qe,Nt,Oe,ee,void 0,Ee&&qe.has(co)?"bottom":void 0),lt=Vt?ct?{position:Vt.position,style:{...Jo.style,...Vt.style}}:Vt:Jo,Ae={...{...qo,...lt.style}};Ae.left!==void 0&&J!==0&&(typeof Ae.left=="number"?Ae.left=`${Ae.left+J}px`:Ae.left=`calc(${Ae.left} + ${J}px)`),U&&Ae.left===void 0&&(lt.position===Position.Left?(Ae.left=`${J}px`,Ae.right=void 0):lt.position===Position.Right&&(Ae.left=`${J+Oe}px`,Ae.right=void 0));let Gt=le(co,re),ut=Md(ct,R,re,Pe.connected);if(ut.secondary){let pt=R==="switch"||R==="router"?{...Ae,background:"transparent",border:"none",opacity:0}:Ae,Dt=R==="switch"||R==="router"?`${Fe.name} - ${Pe.label} (input) ${Pe.connected?"(connected)":"(disconnected)"}`:`${Fe.name} - ${Pe.label} (${ut.secondary}) ${Pe.connected?"(connected)":"(disconnected)"}`;Ze.push(jsx(Handle,{id:`${Gt}-${ut.secondary}`,type:ut.secondary,position:lt.position,style:pt,title:Dt},`${Gt}-${ut.secondary}`));}Ze.push(jsx(Handle,{id:Gt,type:ut.primary,position:lt.position,style:Ae,title:`${Fe.name} - ${Pe.label} ${Pe.connected?"(connected)":"(disconnected)"}`,children:ct?je+1:void 0},Gt));}return Ze},[ee,x,n,R,le,U]),ke=ot.useMemo(()=>{let oe=[];for(let re of M){if(re==="front"&&v.length>0){let J=U?ie:0;oe.push(...j(v,"front",J,x));}re==="rear"&&C.length>0&&oe.push(...j(C,"rear",0,x));}return oe},[M,v,C,j,x,U,ie]);return jsxs("div",{className:`device-node ${o?"selected":""} ${U?"device-node--split-both":""}`,style:pe,children:[U&&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:`${x}px`,backgroundImage:String(B.backgroundImage??"none"),backgroundPosition:String(B.backgroundPosition??"center"),backgroundRepeat:String(B.backgroundRepeat??"no-repeat"),backgroundSize:String(B.backgroundSize??"cover")}}),jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${te}px`},children:jsx("div",{className:"device-node__face-bridge-line"})}),jsx("div",{className:"device-node__split-face device-node__split-face--front",style:{width:`${x}px`,backgroundImage:String(V.backgroundImage??"none"),backgroundPosition:String(V.backgroundPosition??"center"),backgroundRepeat:String(V.backgroundRepeat??"no-repeat"),backgroundSize:String(V.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:s})]}),c>1&&jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),jsx("div",{className:"device-node__status-indicator"}),ke]})};var wr=20,yo=3,Nr=2,$d=1,Nn=2,Qi=6,Ad=12;function xn(e){return Math.max(0,Math.min(100,e))}function kn(e,t,o){return Math.max(t,Math.min(o,e))}function Ld(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 xr(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 Bd(e,t){let o=xr(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 Od(e){if(Array.isArray(e.pduPortGroups)&&e.pduPortGroups.length>0)return e.pduPortGroups;let t=an(e);if(t.length>0)return t;let o=nn(e);return o.length>0?o:[]}function Wd(e,t){return !Array.isArray(e.portTypes)||e.portTypes.length===0?Array.from({length:t},(o,r)=>xr(mr(r))??"C13"):Array.from({length:t},(o,r)=>{let n=xr(e.portTypes?.[r]);return n||(xr(mr(r))??"C13")})}function zd(e,t){let o=Od(e),r=Wd(e,t);if(o.length===0)return Array.from({length:t},(a,s)=>({id:`${s+1}`,label:`${s+1}`,connectorType:r[s]??"C13",groupName:"Power"}));let n=[],i=0;return o.forEach(a=>{a.ports.forEach(s=>{let c=r[i]??"C13";n.push({id:vt(a.name,s),label:s.label,connectorType:Bd(s,c),groupName:a.name,position:s.position}),i+=1;});}),n}function Ud(e){return Ot(e.connectorType).height}function Vd(e,t){return !e||t<=0?-1:e==="top"?0:e==="bottom"?t:Math.floor(t/2)}function ea(e,t){let o=[],r=t>=0,n=r?kn(t,0,e.length):-1;for(let i=0;i<=e.length;i+=1)r&&i===n&&o.push({kind:"mgmt",height:Ad}),i<e.length&&o.push({kind:"port",portIndex:i,height:Ud(e[i]),groupName:e[i].groupName});return o}function ta(e,t){return e.kind==="port"&&t.kind==="port"?e.groupName===t.groupName?Nn:Qi:Nn}function Gd(e,t){let o=ea(e,t);if(o.length===0)return Math.max(Nr+yo+1,1);let r=0;for(let n=0;n<o.length;n+=1)r+=o[n].height,n<o.length-1&&(r+=ta(o[n],o[n+1]));return Nr+r+yo}function Xd(e,t,o){let r=ea(e,o);if(r.length===0)return {portCenters:[]};let n=[];for(let h=0;h<r.length-1;h+=1)n.push(ta(r[h],r[h+1]));let i=r.reduce((h,w)=>h+w.height,0),a=n.reduce((h,w)=>h+w,0),s=i+a,c=Math.max(t-Nr-yo,1),l=0,g=n,f=Math.max(0,c-s);if(f>0)if(n.length===0)l=f/2;else {let h=n.map(k=>k===Qi?1.2:1),w=h.reduce((k,v)=>k+v,0);g=n.map((k,v)=>w<=0?k:k+f*h[v]/w);}let p=[],u,y=Nr+l;for(let h=0;h<r.length;h+=1){let w=r[h],k=y+w.height/2;w.kind==="mgmt"?u=k:p[w.portIndex]=k,y+=w.height,h<r.length-1&&(y+=g[h]??Nn);}return {portCenters:p,mgmtCenterY:u}}function jd(e,t,o,r,n,i){if(!e)return {position:Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let a=e.side,s=a==="left"?Position.Left:a==="top"?Position.Top:a==="bottom"?Position.Bottom:Position.Right,c=typeof e.offsetPercent=="number"?xn(e.offsetPercent):void 0,l=typeof e.offsetPx=="number"?e.offsetPx:void 0,g=typeof e.xPercent=="number"?xn(e.xPercent):void 0,f=typeof e.yPercent=="number"?xn(e.yPercent):void 0;if(g!==void 0&&f!==void 0){let y=a??Ld(g,f),h=y==="left"?Position.Left:y==="top"?Position.Top:y==="bottom"?Position.Bottom:Position.Right,w=Math.max(o-yo,1),k=r*g/100,v=kn(w*f/100,i/2,Math.max(i/2,o-i/2));return {position:h,leftPx:k-n/2,topPx:v-i/2}}let p=g!==void 0?r*g/100:r-n/2-1,u=f!==void 0?Math.max(o-yo,1)*f/100:t;return a==="top"||a==="bottom"?(l!==void 0?p=l:c!==void 0&&(p=r*c/100),u=a==="top"?i/2:o-i/2):(l!==void 0?u=l:c!==void 0&&(u=Math.max(o-yo,1)*c/100),a==="left"?p=n/2:a==="right"&&(p=r-n/2-1)),u=kn(u,i/2,Math.max(i/2,o-i/2)),{position:s,leftPx:p-n/2,topPx:u-i/2}}function Yd(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:a=15,mgmt_unit:s}=e,c=Math.max(0,i),l=zd(e,c),g=Vd(s,l.length),f=n*4.2,p=Gd(l,g),u=Math.max(f-wr,p),y=Math.max(a-$d*2,1),h=wr+u,w=Xd(l,u,g);return jsxs("div",{className:`vertical-pdu-node ${t?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${bt(r)}`,borderRadius:"2px",padding:0,width:`${a}px`,height:`${h}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:`${wr}px`,display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsxs("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${h-wr}px`,overflow:"hidden"},children:[typeof w.mgmtCenterY=="number"?Yd(w.mgmtCenterY,y):null,l.map((k,v)=>{let C=w.portCenters[v]??u/2,R=Ot(k.connectorType),x=jd(k.position,C,u,y,R.width,R.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:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,boxSizing:"border-box",transform:"none",cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`${k.groupName} - ${k.label} (${k.connectorType})`,children:k.label},`handle-${k.id}`)})]})]})};var Tn=({data:e,selected:t,id:o})=>{let{lossDb:r,mode:n="single",ribbonFiberIds:i}=e||{},a=useEdges(),s=a.find(x=>x.target===o&&x.targetHandle==="left"),c=a.find(x=>x.source===o&&x.sourceHandle==="right"),l=a.find(x=>x.target===o&&x.targetHandle==="right"),g=c||l,f=s?.data?.color||"#555",p=g?.data?.color||"#555",u=n==="ribbon",y=s?.data?.ribbonFiberIds||i,h=g?.data?.ribbonFiberIds||i,w=u&&y?St(y):null,k=u&&h?St(h):null,v=!!s&&!!g;return jsxs("div",{className:`splice-node ${t?"selected":""}`,style:{width:u?85:69,height:u?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"none"},children:[u&&w&&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:w.map((x,I)=>jsx("div",{style:{flex:1,background:x.base,opacity:x.striped?.9:1}},`left-${I}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:k.map((x,I)=>jsx("div",{style:{flex:1,background:x.base,opacity:x.striped?.9:1}},`right-${I}`))})]}):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:p}})]}),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:u?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsx("div",{children:`${r.toFixed(2)} dB`}),u&&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:u&&w?20:12,borderRadius:u&&w?"6px":"50%",border:"none",background:u&&w?`linear-gradient(to bottom, ${w.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:u&&k?20:12,borderRadius:u&&k?"6px":"50%",border:"none",background:u&&k?`linear-gradient(to bottom, ${k.map(x=>x.base).join(", ")})`:p,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:u&&k?20:12,borderRadius:u&&k?"6px":"50%",border:"none",background:u&&k?`linear-gradient(to bottom, ${k.map(x=>x.base).join(", ")})`:p,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Vo=20,kr=36;var eo=32,oa=4,Wt=12,Zd=69,to=80,Sn=(to-Zd)/2;var In=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data?.mode==="ribbon",i=n?kr:Vo,a=n?32:16,s=eo,c=o.y-s,l=Math.round(c/i)+1,f=Math.max(1,Math.min(Wt,l));if(!Uo(t,e,f,r)){let y=Go(t,e,r,f);if(y!==f){let h=(i-a)/2;return {x:Sn,y:s+(y-1)*i+h,holderPosition:y}}}let p=(i-a)/2,u=s+(f-1)*i+p;return {x:Sn,y:u,holderPosition:f}},Uo=(e,t,o,r)=>!r.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==t.id).some(i=>i.data.holderPosition===o),Go=(e,t,o,r=1)=>{for(let n=r;n<=Wt;n++)if(Uo(e,t,n,o))return n;for(let n=r-1;n>=1;n--)if(Uo(e,t,n,o))return n;return 1},qd=(e,t)=>Xo(e,t,false),Xo=(e,t,o=false)=>{let r=eo,n=o?kr:Vo,a=(n-(o?32:16))/2,s=r+(t-1)*n+a;return {x:Sn,y:s}};var Hn=({data:e,selected:t})=>{let{label:o="Splice Tray"}=e||{},[r,n]=useState(false),i=()=>{if(!r)return null;let a=[],s=eo;for(let c=1;c<=Wt;c++){let l=s+(c-1)*Vo;a.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:`${Vo}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return a};return jsxs("div",{className:`splice-tray-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${to}px`,height:`${eo+Wt*kr+oa}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:`${eo}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:a=>{a.stopPropagation();},onMouseDown:a=>{a.stopPropagation();},onClick:a=>{a.stopPropagation(),a.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:eo,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Dn=({data:e,selected:t,id:o})=>{let{fibersPerTube:r=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},a=e?.mode==="ribbon"||e?.ribbon===true,s=useEdges(),c=`tube-${n}`,l=s.find(te=>te.source===o&&te.sourceHandle===c||te.target===o&&te.targetHandle===c),g=l?.data?.color,f=ze((n-1)%12+1),p=g||f,u=Math.max(1,Math.min(24,Number(r)||12)),y=14,h=4,w=1,k=2,v=20,C=u*y+(u-1)*h,R=Math.max(60,C+w*2+k*2),x=i==="left"?Position.Left:i==="right"?Position.Right:Position.Bottom,I=x!==Position.Bottom,_=I?14:20,E=I?8:20,M=I?`inset ${x===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",D=l?p:I?`linear-gradient(${x===Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${p}`:`radial-gradient(circle, ${p} 40%, transparent 70%)`,U={width:_,height:E,borderRadius:I?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:D,backgroundColor:p,border:l?`2px solid ${p}`:`3px dashed ${p}`,cursor:"crosshair","--fiber-bg":p,boxShadow:l?M:`${M}${M!=="none"?", ":""}0 0 8px ${p}`,transition:"opacity 0.2s, box-shadow 0.2s",...x===Position.Left?{left:-(_-4)}:x===Position.Right?{right:-(_-4)}:{}},ee=useMemo(()=>{let te=[],ie=R-k*2-w*2,ce,z,V=false;i==="left"?(ce=w,z=Position.Top):i==="right"?(ce=w+ie-C,z=Position.Top,V=true):(ce=w+(ie-C)/2,z=Position.Top);for(let B=0;B<u;B++){let O=V?u-B:B+1,X=`fiber-${O}`,Q=s.find(oe=>oe.source===o&&oe.sourceHandle===X||oe.target===o&&oe.targetHandle===X),$=!!Q&&(Q.data?.isRibbon||Q.data?.ribbonFiberIds&&Array.isArray(Q.data.ribbonFiberIds)),A=Q?.data?.color,pe=typeof Q?.data?.striped=="boolean"?Q.data.striped:void 0,se=Tt(O);a||$?se=Tt(O,{base:"#808080",striped:false}):(A||pe!==void 0)&&(se=Tt(O,{...A?{base:A}:{},...pe!==void 0?{striped:pe}:{}}));let le=ce+B*(y+h),j=w,ke={position:"absolute",left:`${le}px`,top:`${j}px`,width:y,height:y,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":se.base,backgroundColor:se.base};se.backgroundImage&&(ke["--fiber-bg-image"]=se.backgroundImage),te.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:ke,"data-fiber-idx":O,"data-fiber-color":se.base}),jsx(Handle,{id:X,type:"source",position:z,className:"tube-fiber-handle",isConnectable:true,style:ke,"data-fiber-idx":O,"data-fiber-color":se.base})]},`fiber-${O}`));}return te},[u,i,R,s,o,y,h,w,k,C,a]);return jsxs("div",{style:{width:R,height:v,borderRadius:4,background:"#111827",border:`${k}px solid ${t?"#3b82f6":p}`,position:"relative",boxShadow:t?`0 0 0 ${k}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:w,boxSizing:"border-box",overflow:"visible"},children:[ee,jsx(Handle,{id:c,type:"target",position:x,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":p,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":p,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var $n=({data:e,selected:t})=>{let{fiberCount:o,cableId:r="CBL-002",label:n,color:i,rotation:a}=e||{},s=ot.useRef(null);ot.useEffect(()=>{if(s.current){let z=typeof a=="number"?a:0;s.current.style.transform=`rotate(${z}deg)`,s.current.style.transformOrigin="center center";}},[a]);let c=Math.max(1,Math.min(24,Number(o)||12)),l=10,g=2,f=6,p=f+l+4,u=60,y=Math.max(120,c*(l+g)+f*2),w=n??`${c}f Cable`,k=r?`Cable ID ${r}`:void 0,v=ze(1),C=i||v,R=t?"#3b82f6":C,x=typeof a=="number"?a:0,I=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},_=()=>{let z=[],V=I(x);for(let B=0;B<c;B++){let O=B+1,X=Tt(O),Q=X.base,$=f+B*(l+g),A=-5,pe=X.backgroundImage?X.backgroundImage:Q,se={position:"absolute",left:`${$}px`,top:`${A}px`,width:l,height:l,borderRadius:"50%",border:"none",background:pe,backgroundColor:Q,zIndex:10,cursor:"pointer","--fiber-bg":Q};X.backgroundImage&&(se["--fiber-bg-image"]=X.backgroundImage);let le=`fiber-${O}`;z.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:le,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:se,"data-fiber-idx":O,"data-fiber-color":Q}),jsx(Handle,{id:le,type:"source",position:V,className:"tube-fiber-handle",isConnectable:true,style:se,"data-fiber-idx":O,"data-fiber-color":Q})]},`fiber-${O}`));}return z},E="cable-button",M=8,D={width:M,height:M,borderRadius:"50%",background:C,backgroundColor:C,border:`1px solid ${C}`,cursor:"pointer",zIndex:10},U=2,te=(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),ie={width:y,height:u,position:"relative",transform:`rotate(${x}deg)`,transformOrigin:"center center","--rotation":`${x}deg`},ce={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${U}px solid ${R}`,boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:f,paddingTop:p,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsx("div",{ref:s,style:ie,children:jsxs("div",{style:ce,children:[_(),jsx(Handle,{id:E,type:"source",position:te,className:"cable-button-handle",isConnectable:true,style:D,"data-handle-type":"cable-button","data-cable-color":C}),jsx(Handle,{id:E,type:"target",position:te,className:"cable-button-handle",isConnectable:true,style:D,"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:w}),k&&jsx("div",{style:{fontSize:10,opacity:.8},children:k})]})]})})};var Ln=({data:e,selected:t})=>{let{tubeCount:o=12,fibersPerTube:r=12,fiberCount:n,cableId:i="CBL-002",label:a,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(o)||12)),g=Math.max(1,Number(s)||1),f=14,p=10,u=3,y=6,h=y+p+4,w=60,k=Math.max(120,l*(f+u)+y*2),v=n??l*(Number(r)||12),C=a??`${v}f Cable`,R=i?`Cable ID ${i}`:void 0,x=ze(g),I=c||x,_=t?"#3b82f6":I,E=()=>{let te=[];for(let ie=0;ie<l;ie++){let ce=g+ie,z=Tt(ce),V=z.base,B=y+ie*(f+u),O=-5,X=z.backgroundImage?z.backgroundImage:V,Q={position:"absolute",left:`${B}px`,top:`${O}px`,width:f,height:p,borderRadius:6,border:"none",background:X,backgroundColor:V,zIndex:10,cursor:"pointer","--fiber-bg":V};z.backgroundImage&&(Q["--fiber-bg-image"]=z.backgroundImage);let $=`tube-${ce}`;te.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:$,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:Q,"data-fiber-idx":ce,"data-tube-idx":ce,"data-tube-color":V}),jsx(Handle,{id:$,type:"source",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:Q,"data-fiber-idx":ce,"data-tube-idx":ce,"data-tube-color":V})]},`tube-${ce}`));}return te},M="cable-button",D=8,U={width:D,height:D,borderRadius:"50%",background:I,backgroundColor:I,border:`1px solid ${I}`,cursor:"pointer",zIndex:10};return jsxs("div",{style:{width:k,height:w,borderRadius:4,background:"#111827",border:`2px solid ${_}`,position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:y,paddingTop:h,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[E(),jsx(Handle,{id:M,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":I}),jsx(Handle,{id:M,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":I}),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}),R&&jsx("div",{style:{fontSize:10,opacity:.8},children:R})]})]})};var Bn=({data:e,selected:t,id:o})=>{let{connector:r="LC",couplerFiberCount:n,label:i,portLabelsLeft:a,portLabelsRight:s}=e||{},c=useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,g=Math.max(1,Math.min(4,l)),f=9,p=3,u=3,y=60,h=30,w=g*f+(g-1)*p,k=Math.max(h,w+u*2),v=Math.max(y,80),C=(I,_)=>{let E=`${I}-${_+1}`;return c.find(D=>D.source===o&&D.sourceHandle===E||D.target===o&&D.targetHandle===E)?.data?.color||"#555"},R=I=>{let _=[],E=I==="left"?Position.Left:Position.Right,M=I==="left"?a:s;for(let D=0;D<g;D++){let U=D+1,ee=`${I}-${U}`,te=C(I,D),z=u+(k-w)/2+D*(f+p),V={position:"absolute",left:I==="left"?-5:void 0,right:I==="right"?-5:void 0,top:`${z}px`,width:f,height:f,borderRadius:"50%",border:"none",background:te,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};_.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:ee,type:"target",position:E,isConnectable:true,style:V}),jsx(Handle,{id:ee,type:"source",position:E,isConnectable:true,style:V})]},ee)),M&&M[D]&&_.push(jsx("div",{style:{position:"absolute",left:I==="left"?-30:void 0,right:I==="right"?-30:void 0,top:`${z}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:I==="left"?"right":"left",width:"25px"},children:M[D]},`${ee}-label`));}return _},x=i||`${r}-${g}f`;return jsxs("div",{className:`coupler-node ${t?"selected":""}`,style:{width:v,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:`${u}px`,boxSizing:"border-box"},children:[R("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})}),R("right")]})};var no=32,Er=30,ic=24,ac=80,Sr=400,Ir=300,la=2,ro=8,ua=120;function Wn(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,a=3,s=60,c=30,l=r*n+(r-1)*i,g=Math.max(c,l+a*2);return {width:Math.max(s,80),height:g}}function Fr(e){let{fibersPerTube:t=12}=e.data||{},o=Math.max(1,Math.min(24,Number(t)||12)),r=14,n=4,i=1,a=2,s=20,c=o*r+(o-1)*n;return {width:Math.max(60,c+i*2+a*2),height:s}}function pa(e){return {width:to,height:0}}function fa(e){return e.type==="coupler"?Wn(e):e.type==="tube"?Fr(e):e.type==="splice-tray"?pa():{width:80,height:30}}function On(e){let t=0;for(let o of e){let r=fa(o),n=(o.position?.x||0)+r.width;n>t&&(t=n);}return t}function ga(e,t=0){let o=t;for(let r of e){let n=fa(r),i=(r.position?.y||0)+n.height;i>o&&(o=i);}return o}function ba(e){return e.data?.panelWidth||Sr}function sc(e){return e.data?.panelHeight||Ir}function ma(e){return ba(e)-la*2-ro*2}function dc(e,t){return ma(e)-t}function ha(e,t=Er){return Math.floor(e/t)+1}function ya(e,t=Er){return (e-1)*t}function cc(e,t,o){let r=Er,n=ha(o.y,r),i=ya(n,r);return {x:o.x,y:i,slotPosition:n}}function zn(e,t){if(t.length===0)return {width:e.data?.panelWidth||Sr,height:e.data?.panelHeight||Ir};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 p of t)if(p.type==="tube"){let u=Fr(p);u.width>c&&(c=u.width);}else if(p.type==="coupler"){let u=Wn(p);u.width>l&&(l=u.width);}let g=c+ua+to+l+5,f=0;i=f+g+f;}else i=On(t)+4;i=Math.max(e.data?.panelWidth||Sr,i);let a=ga(t,no),s=Math.max(e.data?.panelHeight||Ir,a+ro);return {width:i,height:s}}function wa(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 lc(e,t,o){return wa(e,t,o)}var sa=20,da=400,ca=300;function Un(e,t){if(t.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||da,height:e.data?.closureHeight||e.data?.panelHeight||ca};let o=t.some(s=>s.type==="tube"),r=t.some(s=>s.type==="splice-tray"),n;if(o&&r){let s=0,c=0,l=0,g=t.filter(p=>p.type==="tube"),f=t.filter(p=>p.type==="splice-tray");if(g.length>0&&f.length>0){let p=f.map(y=>y.position?.x||0),u=p.reduce((y,h)=>y+h,0)/p.length;for(let y of g){let h=Fr(y);(y.position?.x||0)<u?h.width>s&&(s=h.width):h.width>c&&(c=h.width);}f.length>0&&(l=to),n=ro+s+sa+l+sa+c+5;}else n=On(t)+ro+5;}else n=On(t)+ro+5;n=Math.max(e.data?.closureWidth||e.data?.panelWidth||da,n);let i=ga(t,no),a=Math.max(e.data?.closureHeight||e.data?.panelHeight||ca,i+ro);return {width:n,height:a}}var Xn=({data:e,selected:t,id:o})=>{let{label:r="Patch Panel",header:n,panelWidth:i,panelHeight:a}=e||{},{getNodes:s,setNodes:c}=useReactFlow(),l=useRef(false),g=useRef([]),f=useMemo(()=>{let C=s().filter(R=>R.parentId===o);return (C.length!==g.current.length||C.some((R,x)=>R.id!==g.current[x]?.id))&&(g.current=C),g.current},[s,o]),p=useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:a}}),[o,e,i,a]),u=useMemo(()=>i&&a?{width:i,height:a}:f.length===0?{width:i||400,height:a||300}:zn(p,f),[f,p,i,a]);useEffect(()=>{if(i&&a||l.current)return;let v=i,C=a,R=Math.abs((v||0)-u.width),x=Math.abs((C||0)-u.height);(R>1||x>1)&&(l.current=true,c(I=>I.map(_=>_.id===o?{..._,data:{..._.data,panelWidth:u.width,panelHeight:u.height}}:_)),setTimeout(()=>{l.current=false;},0));},[o,u.width,u.height,i,a,c]);let y=u.width,h=u.height,w=no,k=n||r;return jsxs("div",{className:`patch-panel-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${y}px`,height:`${h}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:`${w}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:w,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Kn=({data:e,selected:t,id:o})=>{let{label:r="Closure",header:n,closureWidth:i,closureHeight:a,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:g}=useReactFlow(),f=useRef(false),p=useRef([]),u=useMemo(()=>{let I=l().filter(_=>_.parentId===o);return (I.length!==p.current.length||I.some((_,E)=>_.id!==p.current[E]?.id))&&(p.current=I),p.current},[l,o]),y=useMemo(()=>({id:o,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||s,closureHeight:a||c}}),[o,e,i,a,s,c]),h=useMemo(()=>i&&a?{width:i,height:a}:s&&c?{width:s,height:c}:u.length===0?{width:i||s||400,height:a||c||300}:Un(y,u),[u,y,i,a,s,c]);useEffect(()=>{if(i&&a||s&&c||f.current)return;let x=i||s,I=a||c,_=Math.abs((x||0)-h.width),E=Math.abs((I||0)-h.height);(_>1||E>1)&&(f.current=true,g(M=>M.map(D=>D.id===o?{...D,data:{...D.data,closureWidth:h.width,closureHeight:h.height}}:D)),setTimeout(()=>{f.current=false;},0));},[o,h.width,h.height,i,a,s,c,g]);let w=h.width,k=h.height,v=no,C=n||r,R=w/2;return jsxs("div",{className:`closure-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${R}px ${R}px 12px 12px`,padding:0,width:`${w}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:`${v}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${R}px ${R}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 qn=({data:e,selected:t,id:o})=>{let{label:r,splitterType:n="splitter",inputCount:i=1,outputCount:a=8}=e||{},s=useEdges(),c=r||(n==="WDM"?"WDM":"Splitter"),l=9,g=3,f=3,p=50,u=30,y=Math.min(Math.max(i||1,1),2),h=y*l+(y-1)*g,w=Math.min(a||8,48),k=w*l+(w-1)*g,v=Math.max(h,k),C=Math.max(u,v+f*2),R=Math.max(p,50),x=ie=>s.find(z=>z.source===o&&z.sourceHandle===ie||z.target===o&&z.targetHandle===ie)?.data?.color||"#555",I=()=>{let ie=[],ce=f+(C-h)/2;for(let z=0;z<y;z++){let V=`input-${z+1}`,B=ce+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%)"};ie.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 ie},_=()=>{let ie=[],ce=f+(C-k)/2;for(let z=0;z<w;z++){let V=`output-${z+1}`,B=ce+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%)"};ie.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 ie},E=Math.max(h+f*4,u*.6),M=(C-E)/2,D=M+E,U=0,ee=C,te=t?"#3b82f6":"#4b5563";return jsxs("div",{className:`trapezoid-node ${t?"selected":""}`,style:{width:R,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:R,height:C,viewBox:`0 0 ${R} ${C}`,style:{position:"absolute",top:0,left:0,width:`${R}px`,height:`${C}px`,pointerEvents:"none",zIndex:0},children:jsx("polygon",{points:`0,${M} 0,${D} ${R},${ee} ${R},${U}`,fill:"#1f2937",stroke:te,strokeWidth:"2"})}),I(),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})}),_()]})};var Pa=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",_r=(e,t)=>Pa(e)||Pa(t),ae=(e,t)=>t?e?.type==="fibre-split"?Le(t):Le(t):t||"";function Mr(e,t){if(!e||!t)return "unknown";let o=Le(t);if(!o)return "unknown";if(e.type==="vertical-pdu")return "power";let r=e.data??{},{ports:n,rearPorts:i}=Je(r);for(let l of [...n,...i])for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:tt(g.type)?g.type:void 0})===o)return tt(g.type)?"power":"network";if(rr(o)||/^\d+$/.test(o))return "power";let a=o.toLowerCase(),s=a.startsWith("net-")||a.startsWith("port-")||a.startsWith("uplink-")||a.includes("fiber")||a.includes("ports"),c=/^[A-Z0-9]+-\d+$/i.test(o)&&!a.startsWith("pwr")&&!a.startsWith("power");return s||c?"network":"unknown"}function io(e,t){return Mr(e,t)==="power"}function yc(e,t){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=t.nodes.find($=>$.id===e.source),r=t.nodes.find($=>$.id===e.target),n=_r(o,r);if(!n){let $=Mr(o,e.sourceHandle),A=Mr(r,e.targetHandle);if($!=="unknown"&&A!=="unknown"&&$!==A)return {valid:false,reason:`Cannot connect ${$} handle to ${A} handle`};let pe=$==="power"&&A==="power",se=o?.type==="vertical-pdu"||r?.type==="vertical-pdu";if(pe&&!se)return {valid:false,reason:"Power connections must include a PDU endpoint"}}let i=ae(o,e.sourceHandle),a=ae(r,e.targetHandle),s=t.edges.some($=>e.ignoreEdgeId&&$.id===e.ignoreEdgeId?false:$.source===e.source?ae(o,$.sourceHandle)===i:$.target===e.source?ae(o,$.targetHandle)===i:false),c=t.edges.some($=>e.ignoreEdgeId&&$.id===e.ignoreEdgeId?false:$.target===e.target?ae(r,$.targetHandle)===a:$.source===e.target?ae(r,$.sourceHandle)===a:false);if((s||c)&&!n)return s?{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=($,A)=>($?.type==="tube"||$?.type==="cable")&&!!A&&A.startsWith("fiber-"),g=($,A)=>($?.type==="tube"||$?.type==="multi-tube-cable")&&!!A&&A.startsWith("tube-"),f=($,A)=>$?.type==="multi-tube-cable"&&!!A&&A.startsWith("tube-"),p=($,A)=>$?.type==="tube"&&!!A&&A.startsWith("tube-"),u=($,A)=>($?.type==="cable"||$?.type==="multi-tube-cable")&&A==="cable-button",y=($,A)=>$?.type==="splice"&&(A==="left"||A==="right"),h=($,A)=>$?.type==="coupler"&&!!A&&(A.startsWith("left-")||A.startsWith("right-")),w=($,A)=>{if($?.type!=="fibre-split"||!A)return false;let pe=ae($,A);return pe.startsWith("input-")||pe.startsWith("output-")};if(!n)return {valid:true};if(o?.type==="splice"&&r?.type==="splice"){let $=o.data?.mode==="ribbon",A=r.data?.mode==="ribbon";if($!==A)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let k=l(o,e.sourceHandle),v=l(r,e.targetHandle),C=y(o,e.sourceHandle),R=y(r,e.targetHandle),x=h(o,e.sourceHandle),I=h(r,e.targetHandle),_=w(o,e.sourceHandle),E=w(r,e.targetHandle),M=u(o,e.sourceHandle),D=u(r,e.targetHandle),U=f(o,e.sourceHandle),ee=f(r,e.targetHandle),te=p(o,e.sourceHandle),ie=p(r,e.targetHandle),ce=g(o,e.sourceHandle),z=g(r,e.targetHandle);return k&&R||v&&C||(C&&(I||E)||R&&(x||_))||(x&&(I||E||R)||I&&(x||_||C))||M&&D||(U&&ie||ee&&te)?{valid:true}:ce&&z?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function $r(e,t){if(!t)return;let o="--rear",r=Le(e),n=r.endsWith(o);n&&(r=r.slice(0,-o.length));let i=t.data??{},a=i.handleSideMap;if(a&&a[r])return a[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{ports:s,rearPorts:c}=Je(i);if(rr(r))return "rear";for(let l of s)for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:tt(g.type)?g.type:void 0})===r)return "front";for(let l of c)for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:tt(g.type)?g.type:void 0})===r)return "rear"}function Jn(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(p=>p(o));},subscribe:f=>(r.add(f),()=>r.delete(f)),selectEdgeZIndex:f=>{let p=k=>{if(typeof k.parentId=="string")return k.parentId;let v=k.parentNode;if(typeof v=="string")return v},u=k=>{let v=p(k),C=v?o.nodes.find(x=>x.id===v&&x.type==="rack"):void 0;return C&&Ie(C.data)?At(Be(k.data)):[k.data?.view||it(k.data)]},y=(k,v)=>{let C=o.nodes.find(ie=>ie.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 I=u(C),_=$r(v||"",C);if(_)return I.includes(_)?1e3:500;let E=(v||"").toString().replace(/-(source|target)$/i,""),M=E.toLowerCase(),D=M.startsWith("pwr")||M.startsWith("power"),U=M.startsWith("net-")||M.startsWith("port-")||M.startsWith("uplink-")||M.includes("fiber")||M.includes("ports"),ee=/^[A-Z0-9]+-\d+$/i.test(E)&&!M.startsWith("pwr")&&!M.startsWith("power"),te=U||ee;if(D)return I.includes("rear")?1e3:500;if(te)return I.includes("front")?1e3:500},h=y(f.target,f.targetHandle);if(h!==void 0)return h;let w=y(f.source,f.sourceHandle);return w!==void 0?w:1e3},validateConnection:f=>(t.validateConnection||yc)(f,o),selectNodeById:f=>o.nodes.find(p=>p.id===f),selectConnectedEdges:f=>o.edges.filter(p=>p.source===f||p.target===f)}}function wc(e){let t=n=>e.subscribe(i=>n()),o=()=>e.getState();return useSyncExternalStore(t,o,o)}function ei(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return useSyncExternalStore(t,o,o)}function ti(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return useSyncExternalStore(t,o,o)}function Ca(e){return e.selectEdgeZIndex}function va(e){let t=Mo(e.data),o=60+(e.data.uHeight||42)*20,r=e.position.x,n=e.position.x+t,i=e.position.y,a=e.position.y+o;return {left:r,right:n,top:i,bottom:a}}function Ra(e,t){let o=va(t);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function Ar(e,t){let o=null,r=1/0;for(let n of t){if(!Ra(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 Me(e){let{edges:t,connection:o,edgeType:r,selectEdgeZIndex:n,findBy:i,matchOn:a=i,data:s}=e,c=i==="source"?o.sourceHandle:o.targetHandle,l=i==="source"?o.source:o.target;if(!c||!l)return null;let g=Le(c),f=t.find(k=>a==="source"?k.source===l&&Le(k.sourceHandle)===g:k.target===l&&Le(k.targetHandle)===g);if(!f)return null;let p=t.filter(k=>k.id!==f.id),u=addEdge(o,p),y=u[u.length-1],h=n({...o,id:y.id,type:r}),w={...y,type:r,zIndex:h,style:{...y.style,zIndex:h},data:s!==void 0?s:y.data};return [...u.slice(0,-1),w]}function Ia(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var Ue=({type:e,children:t})=>{let o=ot.useRef(null),r=ot.useCallback(n=>{if(o.current=n,n){let i=n.parentElement,a=0;for(;i&&!i.classList.contains("react-flow__node")&&a<10;)i=i.parentElement,a++;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})},Ea=(e,t,o)=>({rack:r=>jsx(Ue,{type:"rack",children:jsx(dn,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsx(Ue,{type:"fiber",children:jsx(cn,{...r})}),device:r=>jsx(Ue,{type:"device",children:jsx(ho,{...r})}),server:r=>jsx(Ue,{type:"server",children:jsx(ho,{...r})}),switch:r=>jsx(Ue,{type:"switch",children:jsx(ho,{...r})}),router:r=>jsx(Ue,{type:"router",children:jsx(ho,{...r})}),"vertical-pdu":r=>jsx(Ue,{type:"vertical-pdu",children:jsx(Cn,{...r})}),splice:r=>jsx(Ue,{type:"splice",children:jsx(Tn,{...r})}),"splice-tray":r=>jsx(Ue,{type:"splice-tray",children:jsx(Hn,{...r})}),tube:r=>jsx(Ue,{type:"tube",children:jsx(Dn,{...r})}),cable:r=>jsx(Ue,{type:"cable",children:jsx($n,{...r})}),"multi-tube-cable":r=>jsx(Ue,{type:"multi-tube-cable",children:jsx(Ln,{...r})}),coupler:r=>jsx(Ue,{type:"coupler",children:jsx(Bn,{...r})}),"patch-panel":r=>jsx(Ue,{type:"patch-panel",children:jsx(Xn,{...r})}),closure:r=>jsx(Ue,{type:"closure",children:jsx(Kn,{...r})}),"fibre-split":r=>jsx(Ue,{type:"fibre-split",children:jsx(qn,{...r})})});function Fa(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 Fa(t)&&r&&!io(t,r)&&(r=Le(r)),Fa(o)&&n&&!io(o,n)&&(n=`${Le(n)}-target`),r===e.sourceHandle&&n===e.targetHandle?e:{...e,sourceHandle:r,targetHandle:n}}var Dc={fiber:gr,ethernet:gr,power:un,smoothstep:Li,step:Wi,"thick-cable":Vi},_c=8192,Mc=8192,$c=2048,Ac=4;function Yo(e,t,o){if(!(typeof e!="number"||Number.isNaN(e)))return Math.min(o,Math.max(t,e))}function Lc(e){if(e)return {...e,width:Yo(e.width,1,_c),height:Yo(e.height,1,Mc),padding:Yo(e.padding,0,$c),pixelRatio:Yo(e.pixelRatio,.1,Ac),quality:Yo(e.quality,0,1)}}var Bc=({nodes:e,edges:t,initialNodes:o,initialEdges:r,onNodesChange:n,onEdgesChange:i,store:a,debug:s,onNodeClick:c,onEdgeClick:l,nodeTypes:g,edgeTypes:f,onConnect:p,onEdgeUpdate:u,isValidConnection:y,connectionMode:h,onViewChange:w,onRackFaceChange:k,className:v,style:C,alignRacksToBottom:R,reAssignable:x=true,colorMode:I="dark",onInit:_,onFlowMethods:E,showDownloadButton:M=false,downloadButtonPosition:D="top-right",downloadButtonText:U="Download Image",downloadButtonStyle:ee,useSmoothstepEdgesForTubes:te=false,readOnly:ie=false,interaction:ce,actionPanel:z,connectOnClick:V=true,panOnDrag:B=true,panOnScroll:O=true,zoomOnScroll:X=true,fitViewOptions:Q})=>{let $=useCallback((d,b)=>{let N=new Map,m=[],T=[],F=(H,L)=>!H||!L?false:!!(H.startsWith("tube-")||L.type==="splice"&&(H==="left"||H==="right")||H==="cable-button");for(let H of d){if(!H.source||!H.target||!H.sourceHandle||!H.targetHandle){s&&console.warn("Invalid edge skipped (missing source/target/handles):",H);continue}let L=b.find(Ye=>Ye.id===H.source),S=b.find(Ye=>Ye.id===H.target),Y=`${H.source}:${H.sourceHandle}`,ne=N.get(Y),Ce=F(H.sourceHandle,L),ve=`${H.target}:${H.targetHandle}`,Re=N.get(ve),Ge=F(H.targetHandle,S);if(ne&&!Ce){s&&console.warn("Duplicate connection detected on source handle, removing:",{handle:Y,existingEdge:ne.id,duplicateEdge:H.id}),T.push(H);continue}if(Re&&!Ge){s&&console.warn("Duplicate connection detected on target handle, removing:",{handle:ve,existingEdge:Re.id,duplicateEdge:H.id}),T.push(H);continue}m.push(H),ne||N.set(Y,H),Re||N.set(ve,H);}return s&&T.length>0&&console.log(`Filtered ${T.length} duplicate edge(s) from initial edges`),m},[s]),A=Array.isArray(e)&&Array.isArray(t),pe=ot.useMemo(()=>A?e||[]:o||e||[],[A,e,o]),se=ot.useMemo(()=>A?t||[]:r||t||[],[A,t,r]),le=ot.useMemo(()=>$(se,pe),[se,pe,$]),j=ot.useMemo(()=>a||Jn({nodes:pe,edges:le,debug:s}),[a,A,s,le]),ke=ei(j),oe=ti(j),[re,J]=useNodesState(ke),[Oe,Ze,wt]=useEdgesState(oe),de=Ca(j),xt=useRef(null),[qe,Vr]=useState(false);useEffect(()=>{let d=()=>{Vr(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return d(),window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[]);let xe=ie===true,Ee=useMemo(()=>{let b={...{nodesDraggable:true,nodesConnectable:true,elementsSelectable:!qe,edgesFocusable:!qe,edgesReconnectable:true,connectOnClick:V,panOnDrag:B,panOnScroll:O&&!qe,zoomOnScroll:X&&!qe,zoomOnPinch:!qe,zoomOnDoubleClick:!qe,allowKeyboardDelete:true,showControls:true,showMiniMap:!qe,showInteractiveControl:true},...ce??{}};return xe?{...b,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}:b},[qe,V,B,O,X,ce,xe]),Fe=useMemo(()=>({enabled:z?.enabled??true,showRearToggle:z?.showRearToggle??true,showDeRack:z?.showDeRack??true}),[z]),{toObject:je,setViewport:Pe,setNodes:co,setEdges:ct,getNodes:Qe,getEdges:Nt,fitView:lo,flowToScreenPosition:To}=useReactFlow();useEffect(()=>{E&&E({toObject:()=>je(),setViewport:Pe,setNodes:d=>{co(d),j.setState({nodes:d});},setEdges:d=>{ct(d),j.setState({edges:d});},toImage:d=>xt.current?toPng(xt.current,Lc(d)):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>Qe(),getEdges:()=>Nt(),fitView:d=>{if(d?.nodes&&Array.isArray(d.nodes)&&d.nodes.length>0){let b=d.nodes.map(T=>Qe().find(F=>F.id===T)).filter(T=>T!==void 0),{nodes:N,...m}=d;lo({...m,nodes:b});}else {let{nodes:b,...N}=d||{};lo(N);}}});},[E,je,Pe,co,ct,j,lo,Qe,Nt]);let[kt,qo]=useState(false),Jo=useCallback(()=>{if(!kt){if(!xt.current){s&&console.error("ReactFlow wrapper ref is not available");return}qo(true),toPng(xt.current,{filter:d=>!(d?.classList?.contains("react-flow__minimap")||d?.classList?.contains("react-flow__controls")||d?.classList?.contains("react-flow__attribution")||d?.classList?.contains("download-button")||d?.tagName==="BUTTON"),backgroundColor:I==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(d=>{let b=document.createElement("a");b.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,b.href=d,b.click();}).catch(d=>{s&&console.error("Error downloading image:",d);}).finally(()=>{qo(false);});}},[I,s,kt]),[Vt,lt]=useState(null),Gr=useRef(null),Ae=useRef(w),Gt=useRef(k);useEffect(()=>{Ae.current=w;},[w]),useEffect(()=>{Gt.current=k;},[k]),useEffect(()=>{Gr.current=Vt;},[Vt]);let ut=useCallback((d,b)=>{Ae.current?.(d,b);},[]),pt=useCallback((d,b)=>{Gt.current?.(d,b);},[]),Dt=useCallback(()=>Gr.current,[]),li=useRef({...Ea(ut,pt,Dt),...g??{}});useEffect(()=>{li.current={...Ea(ut,pt,Dt),...g??{}};},[ut,pt,Dt,g]);let ds=useMemo(()=>({...Dc,...f??{}}),[f]),ft=useRef(re);useEffect(()=>{ft.current=re;},[re]);let Z=useRef(Oe);useEffect(()=>{Z.current=Oe;},[Oe]),useEffect(()=>{J(ke);},[ke,J]),useEffect(()=>{Ze(oe);},[oe,Ze]),useEffect(()=>{if(A&&t){let d=$(t,e||[]);d.length!==t.length&&(s&&console.warn(`Controlled edges had ${t.length-d.length} duplicate(s) removed`),i?.(d));}},[A,t,e,$,i,s]),useEffect(()=>{A&&j.setState({nodes:e||[]});},[A,e,j]),useEffect(()=>{A&&j.setState({edges:t||[]});},[A,t,j]),useEffect(()=>{if(!R||!re||re.length===0)return;let d=re.filter(S=>S.type==="rack");if(d.length===0)return;let b=d.map(S=>{let ne=S.data?.uHeight||42,Ce=60+ne*20;return (S.position?.y||0)+Ce}),N=Math.min(...b),m=Math.max(...b);if(m-N<20)return;let F=m,H=re.map(S=>{if(S.type!=="rack")return S;let ne=S.data?.uHeight||42,Ce=60+ne*20,ve=(S.position?.y||0)+Ce,Re=F-ve;return Math.abs(Re)<5?S:{...S,position:{x:S.position?.x||0,y:(S.position?.y||0)+Re}}});H.some((S,Y)=>S.position!==re[Y].position)&&J(H);},[R,re,J]);let So=useRef(new Map);useEffect(()=>{let d=new Map;re.forEach(b=>{d.set(b.id,b);}),So.current=d;},[re]);let fe=useCallback(d=>So.current.get(d),[]),Ve=useCallback(d=>{if(!d)return;if(typeof d.parentId=="string")return d.parentId;let b=d.parentNode;if(typeof b=="string")return b},[]),ui=useCallback(d=>{let b=Ve(d);if(!b)return;let N=fe(b);if(!(!N||N.type!=="rack"))return N},[fe,Ve]),pi=useCallback(d=>!d||d.type!=="rack"?false:Ie(d.data),[]),uo=useCallback(d=>{if(!d||!Xe(d))return false;let b=ui(d);return b?Ie(b.data):false},[ui]),Xr=useCallback(d=>{if(!d||d.type!=="device")return false;let b=d.data?.deviceType;return typeof b=="string"&&b.toLowerCase().replace(/_/g,"-")==="patch-panel"},[]),Qo=useCallback(d=>{ft.current=d;let b=new Map;d.forEach(N=>{b.set(N.id,N);}),So.current=b,J(d),A?n?.(d):j.setState({nodes:d});},[A,j,J,n]),we=useCallback(d=>{Z.current=d,Ze(d),A?i?.(d):j.setState({edges:d});},[A,j,Ze,i]),_t=useCallback(d=>{if(d.positionAbsolute)return d.positionAbsolute;let b=d.position?.x||0,N=d.position?.y||0,m=Ve(d),T=new Set;for(;m&&!T.has(m);){T.add(m);let F=fe(m);if(!F)break;if(F.positionAbsolute){b+=F.positionAbsolute.x,N+=F.positionAbsolute.y;break}b+=F.position?.x||0,N+=F.position?.y||0,m=Ve(F);}return {x:b,y:N}},[fe,Ve]),er=useCallback(d=>{let b=_t(d),N=d.width||0,m=d.height||0;return {x:b.x+N/2,y:b.y+m/2}},[_t]),Io=useCallback((d,b)=>{if(!d||!b)return;let N=fe(d);if(!N)return;let m=b.replace(/-(source|target)$/i,"");if(N.type==="fibre-split"&&m.startsWith("output-")){let F=Z.current.filter(H=>H.target===d&&(H.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(F.length>0){let H=F[0]?.data?.color;if(H)return {color:H}}}if((N.type==="tube"||N.type==="cable")&&b.startsWith("fiber-")){let F=b.replace("fiber-",""),H=parseInt(F,10);if(H>=1&&H<=24){let L=qt(H),S=H>12;return {color:L,striped:S}}}if((N.type==="multi-tube-cable"||N.type==="tube")&&b.startsWith("tube-")){let F=b.replace("tube-",""),H=parseInt(F,10);if(H>=1&&H<=24){let L=ze(H),S=H>12;return {color:L,striped:S}}}let T=N.data;if(T.color)return {color:T.color}},[fe]),fi=useRef(new Map);useEffect(()=>{Ze(d=>{let b=false,N=d.map(m=>{let T=de(m);return fi.current.get(m.id)!==T?(b=true,fi.current.set(m.id,T),{...m,zIndex:T,style:{...m.style,zIndex:T}}):m});return b?N:d});},[re,Ze,de]),useEffect(()=>{let d=re.map(N=>{if(N.type==="coupler"&&N.parentId){let m=fe(N.parentId);if(m&&(m.type==="patch-panel"||m.type==="closure")&&(!N.extent||N.extent!=="parent"))return {...N,extent:"parent"}}if(N.type==="splice"&&N.parentId&&N.data.holderPosition&&(!N.position||N.position.x===0&&N.position.y===0)){let m=fe(N.parentId);if(m&&m.type==="splice-tray"){let T=N.data.mode==="ribbon",F=Xo(m,N.data.holderPosition,T);return {...N,position:F}}}if(Xe(N)&&N.parentId&&N.data.uPosition&&(!N.position||N.position.x===0&&N.position.y===0)){let m=fe(N.parentId);if(m){let T=N.data.uHeight||1,F=bo(m,N.data.uPosition,T,N.data);return {...N,position:F}}}return N});d.some((N,m)=>{let T=re[m];return N.extent!==T.extent||N.position?.x!==T.position?.x||N.position?.y!==T.position?.y})&&J(d);},[re,J,fe]);let cs=useCallback(d=>{if(xe)return null;let b=new Map,N=new Map,m=new Set,T=d.map(L=>{if(L.type==="position"&&L.position){let S=fe(L.id);if(S&&S.type==="coupler"&&S.parentId){let Y=fe(S.parentId);if(Y&&(Y.type==="patch-panel"||Y.type==="closure"))return (!S.extent||S.extent!=="parent")&&m.add(S.id),{...L,position:S.position||{x:0,y:0}}}if(S&&(S.type==="tube"||S.type==="splice-tray")&&S.parentId){let Y=fe(S.parentId);if(Y&&Y.type==="closure")return (!S.extent||S.extent!=="parent")&&m.add(S.id),{...L,position:S.position||{x:0,y:0}}}if(S&&S.type==="splice"&&S.parentId){let Y=fe(S.parentId);if(Y&&Y.type==="splice-tray"){let ne=In(S,Y,L.position,ft.current);return ne.holderPosition!==void 0&&b.set(S.id,ne.holderPosition),{...L,position:{x:ne.x,y:ne.y}}}}if(S&&Xe(S)&&S.parentId){let Y=fe(S.parentId);if(Y&&Y.type==="rack"){let ne=lr(S,Y,L.position,ft.current);return ne.uPosition!==void 0&&N.set(S.id,ne.uPosition),{...L,position:{x:ne.x,y:ne.y}}}}}return L}),F=applyNodeChanges(T,ft.current).map(L=>{let S=L;m.has(L.id)&&(S={...S,extent:"parent"});let Y=b.get(L.id);Y!==void 0&&(S={...S,data:{...S.data,holderPosition:Y}});let ne=N.get(L.id);return ne!==void 0&&(S={...S,data:{...S.data,uPosition:ne}}),S});ft.current=F;let H=new Map;return F.forEach(L=>{H.set(L.id,L);}),So.current=H,J(F),F},[J,fe,xe]),ls=useCallback((d,b)=>{lt(null);},[]),us=useCallback((d,b,N)=>{let m=Ve(b);if(!x||!Xe(b)||m){lt(null);return}let T=ft.current.filter(S=>S.type==="rack").map(S=>S),F=er(b),L=Ar(F,T)?.id??null;lt(S=>S===L?S:L);},[x,er,Ve]),ps=useCallback((d,b,N)=>{lt(null);let m=Ve(b);if(!x||!Xe(b)||m)return;let T=_t(b),F=ft.current.filter(W=>W.type==="rack").map(W=>W),H=er(b),L=Ar(H,F),S=ft.current;if(!L)return;let Y={x:T.x-L.position.x,y:T.y-L.position.y},ne=S.find(W=>W.id===b.id)||b,Ce=Ie(L.data),ve=$t(L.data),Re=Lt(L.data),Ge=Ce?Ei(ne.data,Y.x,ve,Re):"both",Ye=Ce&&Ge==="front"?ve+Re:0,He=Ge==="rear"?"rear":Ge==="front"?"front":ne.data.view==="front"||ne.data.view==="rear"?ne.data.view:void 0,We={...ne,parentId:L.id,extent:"parent",position:{x:Ye,y:Y.y},data:{...ne.data,rackLayout:Ce?"split-face":"single-face",rackWidthPx:ve,rackFaceGapPx:Re,mountMode:Ge,view:He}},De=S.filter(W=>W.id!==b.id).concat(We),Ne=lr(We,L,We.position,De);if(Ne.uPosition===void 0||!jt(L,We,Ne.uPosition,De))return;let et=S.map(W=>W.id!==b.id?W:{...W,parentId:L.id,extent:"parent",position:{x:Ne.x,y:Ne.y},data:{...W.data,rackLayout:Ce?"split-face":"single-face",rackWidthPx:ve,rackFaceGapPx:Re,mountMode:Ge,view:He,uPosition:Ne.uPosition??W.data.uPosition}});Qo(et);},[x,_t,er,Qo,Ve]),fs=useCallback(d=>{if(!d.source||!d.target||!d.sourceHandle||!d.targetHandle)return true;let b=fe(d.source),N=fe(d.target),m=ae(b,d.sourceHandle),T=ae(N,d.targetHandle),F=Z.current.some(K=>K.source===d.source?ae(b,K.sourceHandle)===m:K.target===d.source?ae(b,K.targetHandle)===m:false),H=Z.current.some(K=>K.target===d.target?ae(N,K.targetHandle)===T:K.source===d.target?ae(N,K.sourceHandle)===T:false);if(F&&s&&console.log("Connection will replace: Source handle already connected",{source:d.source,sourceHandle:d.sourceHandle,existingEdges:Z.current.filter(K=>K.source===d.source&&K.sourceHandle===d.sourceHandle||K.target===d.source&&K.targetHandle===d.sourceHandle)}),H&&s&&console.log("Connection will replace: Target handle already connected",{target:d.target,targetHandle:d.targetHandle,existingEdges:Z.current.filter(K=>K.target===d.target&&K.targetHandle===d.targetHandle||K.source===d.target&&K.sourceHandle===d.targetHandle)}),!_r(b,N))return true;if(b?.type==="splice"&&N?.type==="splice"){let K=b.data?.mode==="ribbon",me=N.data?.mode==="ribbon";if(K!==me)return s&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",d),false}let S=(K,me)=>(K?.type==="tube"||K?.type==="cable")&&!!me&&me.startsWith("fiber-"),Y=(K,me)=>(K?.type==="tube"||K?.type==="multi-tube-cable")&&!!me&&me.startsWith("tube-"),ne=(K,me)=>K?.type==="multi-tube-cable"&&!!me&&me.startsWith("tube-"),Ce=(K,me)=>K?.type==="tube"&&!!me&&me.startsWith("tube-"),ve=(K,me)=>(K?.type==="cable"||K?.type==="multi-tube-cable")&&me==="cable-button",Re=(K,me)=>K?.type==="splice"&&(me==="left"||me==="right"),Ge=(K,me)=>K?.type==="coupler"&&!!me&&(me.startsWith("left-")||me.startsWith("right-")),Ye=(K,me)=>{if(K?.type!=="fibre-split"||!me)return false;let P=me.replace(/-(source|target)$/i,"");return P.startsWith("input-")||P.startsWith("output-")},He=S(b,d.sourceHandle),We=S(N,d.targetHandle),De=Re(b,d.sourceHandle),Ne=Re(N,d.targetHandle),et=Ge(b,d.sourceHandle),W=Ge(N,d.targetHandle),Se=Ye(b,d.sourceHandle),ue=Ye(N,d.targetHandle),tr=ve(b,d.sourceHandle),Zr=ve(N,d.targetHandle),fo=ne(b,d.sourceHandle),go=ne(N,d.targetHandle),qr=Ce(b,d.sourceHandle),Jr=Ce(N,d.targetHandle),or=Y(b,d.sourceHandle),Qr=Y(N,d.targetHandle);return He&&Ne||We&&De||(De&&(W||ue)||Ne&&(et||Se))||(et&&(W||ue||Ne)||W&&(et||Se||De))||tr&&Zr||(fo&&Jr||go&&qr)?true:or&&Qr?(s&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",d),false):(s&&console.log("Connection rejected: Connection not allowed by fiber rules",d),false)},[fe,s]),gs=useCallback(d=>{if(xe)return;s&&console.log("onConnect called:",d);let b=fe(d.source),N=fe(d.target);s&&(console.log("onConnect: sourceNode type:",b?.type,"targetNode type:",N?.type),console.log("onConnect: sourceHandle:",d.sourceHandle,"targetHandle:",d.targetHandle));let m=Ha(d,b,N),T=j.validateConnection({source:m.source??null,target:m.target??null,sourceHandle:m.sourceHandle,targetHandle:m.targetHandle});if(!T.valid&&!(T.reason??"").includes("already connected")){s&&console.warn(`Connection rejected: ${T.reason}`);return}let F=b?.type==="vertical-pdu",H=b?.type==="vertical-pdu"||N?.type==="vertical-pdu",L=io(b,m.sourceHandle),S=io(N,m.targetHandle),Y=L&&S&&H,ne=b?.data,Ce=b?.type==="switch"||b?.type==="device"&&ne?.deviceType==="switch",ve=S,Re=!!m.targetHandle&&(m.targetHandle.startsWith("net-")||m.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Le(m.targetHandle))),Ge=!!m.sourceHandle&&(m.sourceHandle.startsWith("net-")||m.sourceHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Le(m.sourceHandle))),Ye=N?.type==="switch"||N?.type==="device"&&N.data?.deviceType==="switch",He=N?.type==="vertical-pdu",We=L,De=b?.type==="tube"&&N?.type==="multi-tube-cable",Ne=b?.type==="multi-tube-cable"&&N?.type==="tube",et=De||Ne,W=m.sourceHandle==="cable-button"&&m.targetHandle==="cable-button",Se="fiber";Y?Se="power":W?Se="thick-cable":et&&(Se=te?"smoothstep":"fiber");let ue,tr=Ia(N),Zr=Ia(b);if(tr||Zr){let P=N?.data,G=b?.data,ye=tr?P.ribbonFiberIds:G.ribbonFiberIds;ye&&Array.isArray(ye)&&ye.length>=6&&ye.length<=12&&(ue={ribbonFiberIds:ye,isRibbon:true});}if(!ue&&(Se==="fiber"||Se==="smoothstep")&&!F){let P;De?P=Io(m.target,m.targetHandle):P=Io(m.source,m.sourceHandle),P&&(ue={color:P.color,striped:P.striped,isRibbon:false});}else if(Se==="thick-cable"&&W){let P=b?.data;ue={color:P?.color||(P?.tubeStartIndex?ze(P.tubeStartIndex):"#6366f1")};}let fo=ae(b,m.sourceHandle),go=ae(N,m.targetHandle),qr=Z.current.some(P=>P.source===m.source?ae(b,P.sourceHandle)===fo:P.target===m.source?ae(b,P.targetHandle)===fo:false),Jr=Z.current.some(P=>P.target===m.target?ae(N,P.targetHandle)===go:P.source===m.target?ae(N,P.sourceHandle)===go:false);if(qr||Jr){let P=new Set;for(let G of Z.current){if(G.source===m.source&&ae(b,G.sourceHandle)===fo){P.add(G.id);continue}if(G.target===m.source&&ae(b,G.targetHandle)===fo){P.add(G.id);continue}if(G.source===m.target&&ae(N,G.sourceHandle)===go){P.add(G.id);continue}G.target===m.target&&ae(N,G.targetHandle)===go&&P.add(G.id);}if(P.size>0){let G=Z.current.filter(gt=>!P.has(gt.id)),ye=addEdge(m,G);if(ye.length===G.length)s&&console.warn("Handle replacement skipped: addEdge did not create a new edge",m);else {let gt=ye[ye.length-1],Mt=de({...m,id:gt.id,type:Se}),Xt={...gt,type:Se,zIndex:Mt,style:{...gt.style,zIndex:Mt},data:ue!==void 0?ue:gt.data};we([...ye.slice(0,-1),Xt]),s&&console.log("Handle replacement: Replaced",P.size,"edge(s)");return}}}if(N?.type==="splice"&&(d.targetHandle==="left"||d.targetHandle==="right")&&d.target&&d.targetHandle){let P=Z.current.find(G=>G.target===d.target&&G.targetHandle===d.targetHandle||G.source===d.target&&G.sourceHandle===d.targetHandle);if(P){s&&(console.log("Splice target handle replacement: Found existing edge",P.id,"on splice handle",d.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=d.source&&d.sourceHandle?Z.current.find(Pt=>Pt.source===d.source&&Pt.sourceHandle===d.sourceHandle):null;s&&G&&console.log("Splice target handle replacement: Also found existing source edge",G.id);let ye=new Set;P&&ye.add(P.id),G&&G.id!==P.id&&ye.add(G.id);let gt=Z.current.filter(Pt=>!ye.has(Pt.id));s&&console.log("Splice target handle replacement: Removing",ye.size,"edge(s), creating new connection");let Mt=`edge-${d.source}-${d.sourceHandle}-${d.target}-${d.targetHandle}-${Date.now()}`,Xt=de({...d,id:Mt,type:"fiber"}),Fo={id:Mt,source:d.source,target:d.target,sourceHandle:d.sourceHandle,targetHandle:d.targetHandle,type:"fiber",zIndex:Xt,style:{zIndex:Xt},data:ue!==void 0?ue:{}},tn=[...gt,Fo];we(tn),s&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Fo.id);return}}if(b?.type==="splice"&&d.sourceHandle==="right"&&d.source&&d.sourceHandle){let P=Z.current.find(G=>G.source===d.source&&G.sourceHandle===d.sourceHandle||G.target===d.source&&G.targetHandle===d.sourceHandle);if(P){s&&console.log("Splice source handle replacement: Found existing edge",P.id,"on splice handle",d.sourceHandle);let G=d.target&&d.targetHandle?Z.current.find(Pt=>Pt.target===d.target&&Pt.targetHandle===d.targetHandle):null;s&&G&&console.log("Splice source handle replacement: Also found existing target edge",G.id);let ye=new Set;P&&ye.add(P.id),G&&G.id!==P.id&&ye.add(G.id);let gt=Z.current.filter(Pt=>!ye.has(Pt.id));s&&console.log("Splice source handle replacement: Removing",ye.size,"edge(s), creating new connection");let Mt=`edge-${d.source}-${d.sourceHandle}-${d.target}-${d.targetHandle}-${Date.now()}`,Xt=de({...d,id:Mt,type:"fiber"}),Fo={id:Mt,source:d.source,target:d.target,sourceHandle:d.sourceHandle,targetHandle:d.targetHandle,type:"fiber",zIndex:Xt,style:{zIndex:Xt},data:ue!==void 0?ue:{}},tn=[...gt,Fo];we(tn),s&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Fo.id);return}}if((b?.type==="tube"||b?.type==="cable")&&d.sourceHandle?.startsWith("fiber-")&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if((N?.type==="tube"||N?.type==="cable")&&d.targetHandle?.startsWith("fiber-")&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if((b?.type==="multi-tube-cable"||b?.type==="tube")&&d.sourceHandle?.startsWith("tube-")&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:Se,selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if((N?.type==="multi-tube-cable"||N?.type==="tube")&&d.targetHandle?.startsWith("tube-")&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:Se,selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(b?.type==="coupler"&&(d.sourceHandle?.startsWith("left-")||d.sourceHandle?.startsWith("right-"))){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if(N?.type==="coupler"&&(d.targetHandle?.startsWith("left-")||d.targetHandle?.startsWith("right-"))){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(W&&d.source&&d.sourceHandle&&d.target&&d.targetHandle){let P=b?.data,G=P?.color||(P?.tubeStartIndex?ze(P.tubeStartIndex):"#6366f1"),ye=Me({edges:Z.current,connection:m,edgeType:"thick-cable",selectEdgeZIndex:de,findBy:"source",data:{color:G}});if(ye){we(ye);return}if(ye=Me({edges:Z.current,connection:m,edgeType:"thick-cable",selectEdgeZIndex:de,findBy:"target",data:{color:G}}),ye){we(ye);return}}if(F&&ve&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"power",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(He&&We&&d.source&&d.sourceHandle&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"power",selectEdgeZIndex:de,findBy:"source",matchOn:"target",data:ue});if(P){we(P);return}}if(Ce&&Re&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(Ye&&Ge&&d.source&&d.sourceHandle&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",matchOn:"source",data:ue});if(P){we(P);return}}let or=j.validateConnection({source:m.source??null,target:m.target??null,sourceHandle:m.sourceHandle,targetHandle:m.targetHandle});if(!or.valid){if(F&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:ve?"power":"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if(He&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:"power",selectEdgeZIndex:de,findBy:"source",matchOn:"target",data:ue});if(P){we(P);return}}if(Ce&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if(Ye&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",matchOn:"source",data:ue});if(P){we(P);return}}s&&console.warn(`Connection rejected: ${or.reason}`);return}let Qr=Z.current.some(P=>P.source===m.source&&P.sourceHandle===m.sourceHandle||P.target===m.source&&P.targetHandle===m.sourceHandle),mi=Z.current.some(P=>P.target===m.target&&P.targetHandle===m.targetHandle||P.source===m.target&&P.sourceHandle===m.targetHandle),en=(P,G)=>!P||!G?false:!!(P.startsWith("tube-")||G.type==="splice"&&(P==="left"||P==="right")||P==="cable-button"),hi=en(m.sourceHandle||"",b),yi=en(m.targetHandle||"",N);if(Qr&&!hi){s&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:d.source,sourceHandle:m.sourceHandle,existingEdges:Z.current.filter(P=>P.source===m.source&&P.sourceHandle===m.sourceHandle||P.target===m.source&&P.targetHandle===m.sourceHandle)});return}if(mi&&!yi){s&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:m.target,targetHandle:m.targetHandle,existingEdges:Z.current.filter(P=>P.target===m.target&&P.targetHandle===m.targetHandle||P.source===m.target&&P.sourceHandle===m.targetHandle)});return}let wi={...m,type:Se,zIndex:de({...m,id:"temp-id"}),data:ue},K=addEdge(wi,Z.current),me=K[K.length-1];me&&(bi(P=>new Set(P).add(me.id)),setTimeout(()=>{bi(P=>{let G=new Set(P);return G.delete(me.id),G});},1e3)),we(K);},[we,j,de,fe,s,Io,te,xe]),bs=useCallback((d,b)=>{if(xe||!b.source||!b.target||!b.sourceHandle||!b.targetHandle)return;let N=fe(b.source),m=fe(b.target),T=Ha(b,N,m),F=ae(N,T.sourceHandle),H=ae(m,T.targetHandle),L=Z.current.some(W=>{if(W.id===d.id)return false;let Se=W.source===T.source&&ae(N,W.sourceHandle)===F||W.target===T.source&&ae(N,W.targetHandle)===F,ue=W.target===T.target&&ae(m,W.targetHandle)===H||W.source===T.target&&ae(m,W.sourceHandle)===H;return Se||ue}),S=j.validateConnection({source:T.source??null,target:T.target??null,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,ignoreEdgeId:d.id});if(!S.valid&&!((S.reason??"").includes("already connected")&&L)){s&&console.warn(`Edge update rejected: ${S.reason}`);return}let Y=N?.type==="vertical-pdu"||m?.type==="vertical-pdu",ne=io(N,T.sourceHandle),Ce=io(m,T.targetHandle),ve=ne&&Ce&&Y,Re=N?.type==="tube"&&m?.type==="multi-tube-cable",Ge=N?.type==="multi-tube-cable"&&m?.type==="tube",Ye=Re||Ge,He;ve?He="power":Ye?He=te?"smoothstep":"fiber":He="fiber";let We;if(He==="fiber"||He==="smoothstep"){let W=Io(T.source,T.sourceHandle);W&&(We={color:W.color,striped:W.striped});}let et=Z.current.filter(W=>{if(W.id===d.id)return true;let Se=W.source===T.source&&ae(N,W.sourceHandle)===F||W.target===T.source&&ae(N,W.targetHandle)===F,ue=W.target===T.target&&ae(m,W.targetHandle)===H||W.source===T.target&&ae(m,W.sourceHandle)===H;return !(Se||ue)}).map(W=>W.id===d.id?{...W,source:T.source,target:T.target,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,type:He,data:We!==void 0?{...W.data,...We}:W.data,zIndex:de({...T,id:W.id,type:He}),style:{...W.style,zIndex:de({...T,id:W.id,type:He})}}:W);we(et);},[we,fe,Io,de,te,s,j,xe]),ms=useCallback((d,b)=>{if(qe){c&&c(b);return}let N=d.metaKey||d.ctrlKey,m=Qe(),T=b,F=Ve(b);if(b.type==="tube"&&F&&!N){let H=m.find(L=>L.id===F&&(L.type==="cable"||L.type==="multi-tube-cable"));H&&(T=H);}if(jr(T),Eo([]),J(H=>H.map(L=>{let S=L.id===T.id;return L.selected===S?L:{...L,selected:S}})),N&&Xe(T)&&!uo(T)){let H=T.data||{},L=H.view||it(H),S=L==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${T.id} from ${L} to ${S}`),w&&w(T.id,S);}c&&c(T);},[w,c,s,Qe,J,qe,Ve,uo]),hs=useCallback(()=>{},[]),ys=useCallback((d,b)=>{jr(null),Eo([b]),J(N=>N.map(m=>m.selected?{...m,selected:false}:m)),c?.(null),l&&l(b);},[l,c,J]),ws=useCallback(()=>{jr(null),Eo([]),J(d=>d.map(b=>b.selected?{...b,selected:false}:b)),c?.(null);},[c,J]),[nt,jr]=useState(null),[gi,bi]=useState(new Set);useOnSelectionChange({onChange:({edges:d})=>{Eo(d||[]);}});let[Yr,Eo]=useState([]);useEffect(()=>{let d=b=>{if(Ee.allowKeyboardDelete&&(b.key==="Backspace"||b.key==="Delete")&&Yr.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let N=Yr.filter(m=>{let T=m.sourceHandle||"",F=m.targetHandle||"";return T.startsWith("tube-")||F.startsWith("tube-")?(s&&console.log("Cannot delete edge connected to tube handle",m),false):true});if(N.length>0){let m=new Set(N.map(F=>F.id)),T=Z.current.filter(F=>!m.has(F.id));we(T),Eo([]),s&&console.log("Deleted edges:",N.map(F=>F.id));}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[Yr,we,s,Ee.allowKeyboardDelete]);let xs=useCallback((d,{nodeId:b,handleType:N})=>{s&&console.log("Connection started from",{nodeId:b,handleType:N});},[s]),Ns=useCallback(d=>{s&&console.log("Connection ended",d);},[s]),ks=useCallback(()=>{if(xe||!nt)return;let d=fe(nt.id);if(d){if(d.type==="rack"){let b=d.data||{};if(Ie(b))return;let m=(b.face||"front")==="front"?"rear":"front";k?(k(d.id,m),w&&Qe().filter(F=>F.parentId===d.id).forEach(F=>{w(F.id,m);})):J(T=>T.map(F=>F.id===d.id?{...F,data:{...F.data,face:m}}:F.parentId===d.id?{...F,data:{...F.data,view:m}}:F));return}if(Xe(d)){if(uo(d))return;let b=d.data||{},m=(b.view||it(b))==="front"?"rear":"front";w?w(d.id,m):J(T=>T.map(F=>F.id===d.id?{...F,data:{...F.data,view:m}}:F));}}},[nt,fe,k,w,J,Qe,xe,uo]),Ps=useCallback(()=>{if(xe||!x||!nt||!Xe(nt))return;let d=fe(nt.id),b=Ve(d);if(!d||!Xe(d)||!b)return;let N=_t(d),T=ft.current.map(F=>F.id!==d.id?F:{...F,parentId:void 0,parentNode:void 0,extent:void 0,position:N,data:{...F.data,uPosition:void 0}});Qo(T);},[xe,x,nt,fe,_t,Qo,Ve]),Cs=useMemo(()=>{let d=So.current;return Oe.map(b=>{let N=b,m=d.get(String(N.source)),T=d.get(String(N.target)),F=$r(N.sourceHandle||"",m),H=$r(N.targetHandle||"",T),L=De=>{if(!De||!Xe(De))return;let Ne=De.data??{},et=typeof De.parentId=="string"?De.parentId:De.parentNode,W=et?d.get(et):void 0;return W&&W.type==="rack"&&Ie(W.data)?At(Be(Ne)):[Ne.view||it(Ne)]},S=L(m),Y=L(T),ne=Xr(m),Ce=Xr(T),ve=Xe(m)&&!ne&&!!S&&!!F&&!S.includes(F),Re=Xe(T)&&!Ce&&!!Y&&!!H&&!Y.includes(H),He=ve||Re,We=b.style;if(He)We={...b.style,opacity:0,pointerEvents:"none",zIndex:0};else if(b.style&&b.style.opacity===0&&b.style.pointerEvents==="none"&&b.style.zIndex===0){let Ne={...b.style};delete Ne.opacity,delete Ne.pointerEvents,delete Ne.zIndex,We=Object.keys(Ne).length>0?Ne:void 0;}return {...b,style:We,className:gi.has(b.id)?"edge-connecting":b.className}})},[Oe,gi,Xr]),Te=useMemo(()=>nt?fe(nt.id)??nt:null,[nt,fe]),po=useMemo(()=>{if(!Te||!Fe.enabled||xe)return {showRearToggle:false,showDeRack:false,count:0};let d=Te.type==="rack"?!pi(Te):Xe(Te)?!uo(Te):false,b=Fe.showRearToggle&&d,N=Fe.showDeRack&&x&&!xe&&Xe(Te)&&!!Ve(Te);return {showRearToggle:b,showDeRack:N,count:(b?1:0)+(N?1:0)}},[Te,Fe,x,xe,Ve,uo,pi]),Kr=useMemo(()=>{if(!Te||po.count===0||!xt.current)return null;let d=xt.current.getBoundingClientRect();if(d.width<=0||d.height<=0)return null;let b=Te.positionAbsolute??_t(Te),N=Te.width||0,m=Te.height||0,T=po.count>1?220:110,F=34;try{let H=To({x:b.x+N/2,y:b.y}),L=To({x:b.x+N/2,y:b.y+m}),S=H.x-d.left-T/2,Y=H.y-d.top-F-10;return Y<8&&(Y=L.y-d.top+10),S=Math.max(8,Math.min(S,d.width-T-8)),Y=Math.max(8,Math.min(Y,d.height-F-8)),{left:S,top:Y}}catch{return null}},[Te,po,_t,To]),vs=Ni(I,v),Rs=Pi(I,{touchAction:"none",...C});return jsxs("div",{ref:xt,className:vs,style:Rs,children:[jsxs(ReactFlow,{nodes:re,edges:Cs,onNodesChange:d=>{if(xe)return;let b=cs(d);b&&(A?n&&n(b):j.setState({nodes:b}));},onEdgesChange:d=>{if(xe)return;let b=d.filter(N=>{if(N.type==="remove"){let m=Z.current.find(T=>T.id===N.id);if(m){let T=m.sourceHandle||"",F=m.targetHandle||"";if(T.startsWith("tube-")||F.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",m),false}}return true});if(b.length>0){let N=applyEdgeChanges(b,Z.current);wt(b),A?i&&i(N):j.setState({edges:N});}},onConnect:xe?void 0:p??gs,onConnectStart:xs,onConnectEnd:Ns,onEdgeUpdate:xe?void 0:u??bs,isValidConnection:y??fs,connectionMode:h,onNodeClick:ms,onNodeDoubleClick:hs,onPaneClick:ws,onNodeDragStart:ls,onNodeDrag:us,onNodeDragStop:ps,onEdgeClick:ys,onInit:_,nodeTypes:li.current,edgeTypes:ds,defaultEdgeOptions:{zIndex:1e3,reconnectable:Ee.edgesReconnectable},nodesDraggable:Ee.nodesDraggable,nodesConnectable:Ee.nodesConnectable,elementsSelectable:Ee.elementsSelectable,edgesFocusable:Ee.edgesFocusable,elevateNodesOnSelect:false,selectNodesOnDrag:false,connectOnClick:Ee.connectOnClick,panOnDrag:Ee.panOnDrag,panOnScroll:Ee.panOnScroll,zoomOnScroll:Ee.zoomOnScroll,zoomOnPinch:Ee.zoomOnPinch,zoomOnDoubleClick:Ee.zoomOnDoubleClick,preventScrolling:qe,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:Q,proOptions:{hideAttribution:true},children:[jsx(Background,{color:ki(I)}),Ee.showControls&&jsx(Controls,{showInteractive:Ee.showInteractiveControl}),Ee.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"})})]}),M&&jsx("button",{className:"download-button",onClick:Jo,disabled:kt,"aria-busy":kt,style:{position:"absolute",top:D.includes("top")?"10px":"auto",bottom:D.includes("bottom")?"10px":"auto",right:D.includes("right")?"10px":"auto",left:D.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:kt?"not-allowed":"pointer",opacity:kt?.7:1,transition:"all 0.2s ease",...ee},children:kt?`${U}...`:U}),Te&&Kr&&po.count>0&&jsxs("div",{style:{position:"absolute",top:Kr.top,left:Kr.left,display:"flex",gap:8,zIndex:2e3},children:[po.showRearToggle&&jsx("button",{onClick:d=>{d.preventDefault(),ks();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let d=Te.data;return Te.type==="rack"?(d?.face||"front")==="front"?"Switch to rear":"Switch to front":(d?.view||it(d))==="front"?"Switch to rear":"Switch to front"})(),children:(()=>{let d=Te.data;return Te.type==="rack"?(d?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front":(d?.view||it(d))==="front"?"\u21C4 Rear":"\u21C4 Front"})()}),po.showDeRack&&jsx("button",{onClick:d=>{d.preventDefault(),Ps();},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"})]})]})},ri=e=>jsx(ReactFlowProvider,{children:jsx(Bc,{...e})});var ni=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 Ko(e,{rowHeight:t,tubeGap:o}){let r=[],n=[],i=e.kind??(e.tubeCount?"tube":"simple"),a=i==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,s=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<a;f+=1){let p=c+f,u=e.tubeColorMap?.[p];n.push({tubeIndex:p,y:g,label:`T${p}`,color:u??ze(p)});for(let y=0;y<s;y+=1){let h=l+y,w=ln(h);r.push({key:`${p}-${h}`,tubeIndex:i==="tube"?p:void 0,fiberIndex:h,y:g,color:qt(h),striped:Zt(h),backgroundImage:typeof w.backgroundImage=="string"?w.backgroundImage:void 0}),g+=t;}f<a-1&&(g+=o);}return {rows:r,tubeLabels:n,height:g}}var ii=e=>typeof e=="object"&&e!==null,Vc=e=>{if(!ii(e.data))return false;if(e.type==="fibre-flow-cable"){let t=e.data;return typeof t.label=="string"&&ii(t.cable)&&(t.side==="left"||t.side==="right")&&typeof t.rowHeight=="number"&&typeof t.columnWidth=="number"&&typeof t.showTubeLabels=="boolean"&&typeof t.showFiberNumbers=="boolean"&&ii(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},Gc=e=>e==="fibre-flow"||e==="fibre-flow-link",Xc=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,jc=e=>e.sourceHandle==="cable-run"||e.targetHandle==="cable-run"?"fibre-flow-link":"fibre-flow",Yc=(e,t=[])=>{let o=new Map(t.map(n=>[n.id,n])),r=[];return e.forEach(n=>{if(!Xc(n))return;let i=o.get(n.id),a=Gc(n.type)?n.type:i?.type??jc(n);r.push({...i??{},...n,type:a});}),r},Aa=e=>`fiber-${e.tube??1}-${e.fiber}`,La=e=>qt(e.fiber),Ba=e=>Zt(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`},Zc=(e,t,o,r,n,i)=>e?`${o} ${i}`:t?`0 ${n} ${r} ${i}`:"6 6",qc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s})=>{let[c,l,g]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,curvature:.35}),f=typeof s?.lossDb=="number"?`${s.lossDb.toFixed(2)} dB`:"",p=s?.label??f,u=s?.sourceColor,y=s?.targetColor,h=s?.color??u??y??"#94a3b8",w=s?.sourceStriped??false,k=s?.targetStriped??false,v=s?.highlighted??true,C=s?.dimmed??false,R=s?.circuitId,x=s?.circuitLabel??R,I=s?.showCircuitId??false,_=u&&y&&u!==y,E=r-t,M=n-o,D=Math.sqrt(E*E+M*M),U=l-t,ee=g-o,te=Math.sqrt(U*U+ee*ee),ie=D>0?te/D*100:50,ce=`fibre-flow-gradient-${e}`,z=w&&!k,V=k&&!w,B=w&&k,O=D*1.25,X=O/2,Q=12,$=Math.ceil(X*1.2/Q),A=Array($).fill("6 6").join(" "),pe=Math.ceil(X*1.2/Q),se=Array(pe).fill("6 6").join(" "),le=I&&x,j=Math.max(p?p.length*6.2+16:0,le?(x?.length||0)*5.5+16:0),ke=le?32:16;return jsxs(Fragment,{children:[jsx("defs",{children:_&&jsxs("linearGradient",{id:ce,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0%",stopColor:u}),jsx("stop",{offset:`${ie}%`,stopColor:u}),jsx("stop",{offset:`${ie}%`,stopColor:y}),jsx("stop",{offset:"100%",stopColor:y})]})}),_?jsx("path",{id:e,d:c,fill:"none",stroke:`url(#${ce})`,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:h,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:Zc(z,V,A,se,X,O),strokeDashoffset:0,opacity:C?.2:.9,style:{mixBlendMode:"normal"}}),(p||le)&&v&&jsx(EdgeLabelRenderer,{children:jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${g}px)`,width:j,height:ke,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:[p&&jsx("div",{style:{lineHeight:1.2},children:p}),le&&jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:p?2:0},children:x})]})})]})},Jc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s})=>{let[c,l,g]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,curvature:.2}),f=s?.label,p=s?.color??"#64748b";return jsxs(Fragment,{children:[jsx(BaseEdge,{id:e,path:c,style:{stroke:p,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 ${p}`,borderRadius:10,fontSize:10,fontFamily:"monospace",color:"#e2e8f0",letterSpacing:.2,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9999},children:f})})]})},Qc=({data:e})=>{let{cable:t,side:o,rowHeight:r,columnWidth:n,showTubeLabels:i,showFiberNumbers:a,layout:s,colorMode:c="dark"}=e,l=c==="light",g=8,f=12,p=-1,u=0,y=t.jacketColor??"#facc15",h=(t.kind??(t.tubeCount?"tube":"simple"))==="tube",w=i&&h,k=o==="left"?g+u:u,v=o==="right"?g+u:u,C=o==="left"?Position.Right:Position.Left,R={width:4,height:4,borderRadius:"50%",background:y,border:`1px solid ${y}`,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:s.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:h?"transparent":y,border:`1px solid ${y}`,boxShadow:h?"none":"inset 0 0 3px rgba(0,0,0,0.3)",overflow:"hidden"},children:h&&s.tubeLabels.map((x,I)=>{let _=s.rows.filter(te=>te.tubeIndex===x.tubeIndex);if(_.length===0)return null;let E=_[0].y,M=_[_.length-1].y+r,D=M-E,U=s.tubeLabels[I+1],ee=U&&U.y-M>0;return jsx("div",{style:{position:"absolute",top:E,left:0,right:0,height:D,background:x.color,borderLeft:`2px solid ${x.color}`,borderRight:`2px solid ${x.color}`,borderTop:I===0?`2px solid ${x.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:ee?"1px solid rgba(0,0,0,0.15)":`2px solid ${x.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:I===0&&!ee||I===0?"4px 4px 0 0":ee?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${x.tubeIndex}`)})}),!w&&jsx("div",{style:{position:"absolute",top:0,bottom:0,left:k,right:v,...o==="left"?{borderRight:`1px solid ${y}`}:{borderLeft:`1px solid ${y}`},pointerEvents:"none",zIndex:0}}),h&&s.tubeLabels.map((x,I)=>{let _=s.rows.filter(U=>U.tubeIndex===x.tubeIndex);if(_.length===0)return null;let E=_[0].y,D=_[_.length-1].y+r-E;return jsx("div",{style:{position:"absolute",top:E,left:k,right:v,height:D,...o==="left"?{borderRight:`2px solid ${x.color}`}:{borderLeft:`2px solid ${x.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${x.tubeIndex}`)}),s.rows.map(x=>{let I=`fiber-${x.tubeIndex??1}-${x.fiberIndex}`,_=x.y+r/2,E={position:"absolute",width:f,height:f,borderRadius:"50%",top:_,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 M=o==="left"?{right:f+p,textAlign:"right"}:{left:f+p,textAlign:"left"};return jsxs(ot.Fragment,{children:[jsx(Handle,{id:I,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:I,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}),a&&jsx("div",{style:{position:"absolute",top:x.y+r/2-6,...M,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:R,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:R,isConnectable:true,"data-handle-type":"cable-run"})]})},el=({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})})},tl=(e,t,o,r,n,i,a,s,c,l="dark")=>{let g=[],f=0;return e.forEach(p=>{let u=Ko(p.leftCable,{rowHeight:o,tubeGap:r}),y=Ko(p.rightCable,{rowHeight:o,tubeGap:r}),h=Math.max(u.height,y.height),w=i*2+a,k=32,v=16,C=w+v*2,R=h+k+v*2,x=`flow-closure-${p.id}`,I=`flow-cable-${p.id}-left`,_=`flow-cable-${p.id}-right`,E=t==="horizontal"?{x:f,y:0}:{x:0,y:f};f+=(t==="horizontal"?C:R)+n;let M=p.chamberId?`${p.id} - ${p.chamberId}`:p.id;g.push({id:x,type:"fibre-flow-closure",position:E,data:{label:M,width:C,height:R,headerHeight:k,colorMode:l},selectable:false,draggable:false,style:{width:C,height:R}});let D=k+v+(h-u.height)/2,U=k+v+(h-y.height)/2;g.push({id:I,type:"fibre-flow-cable",position:{x:v,y:D},parentId:x,extent:"parent",data:{label:p.leftCable.label,cable:p.leftCable,side:"left",rowHeight:o,columnWidth:i,showTubeLabels:s,showFiberNumbers:c,layout:u,colorMode:l},style:{width:i,height:u.height}}),g.push({id:_,type:"fibre-flow-cable",position:{x:v+w-i,y:U},parentId:x,extent:"parent",data:{label:p.rightCable.label,cable:p.rightCable,side:"right",rowHeight:o,columnWidth:i,showTubeLabels:s,showFiberNumbers:c,layout:y,colorMode:l},style:{width:i,height:y.height}});}),g},ol=(e,t,o,r=false)=>{let n=[],i=new Map,a=new Map,s=new Map;return (t??[]).forEach(c=>{c.color&&i.set(c.id,c.color),c.label&&a.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:p,cable:u})=>{let y=s.get(u.id);if(y&&y.closureId!==c.id){let h=Kc(u.distanceMeters??y.distanceMeters,u.distanceLabel??y.distanceLabel),w=u.jacketColor??y.jacketColor??"#64748b";n.push({id:`flow-link-${y.nodeId}-${p}`,type:"fibre-flow-link",source:y.nodeId,target:p,sourceHandle:"cable-run",targetHandle:"cable-run",data:{label:h,color:w}});}s.set(u.id,{nodeId:p,closureId:c.id,jacketColor:u.jacketColor,distanceLabel:u.distanceLabel,distanceMeters:u.distanceMeters});}),c.splices.forEach(p=>{let u=o?p.circuitId===o:true,y=!!o&&!u,h=p.circuitId?i.get(p.circuitId):void 0,w=p.circuitId?a.get(p.circuitId):void 0,k=p.color??h,v=La(p.from),C=La(p.to),R=Ba(p.from),x=Ba(p.to);n.push({id:`flow-edge-${c.id}-${p.id}`,type:"fibre-flow",source:l,target:g,sourceHandle:Aa(p.from),targetHandle:Aa(p.to),data:{lossDb:p.lossDb,label:p.label,color:k,sourceColor:v,targetColor:C,sourceStriped:R,targetStriped:x,highlighted:u,dimmed:y,circuitId:p.circuitId,circuitLabel:w,showCircuitId:r}});});}),n},rl=({closures:e,circuits:t,highlightedCircuitId:o,layout:r="horizontal",rowHeight:n=20,tubeGap:i=10,closureGap:a=140,cableColumnWidth:s=32,spliceAreaWidth:c=260,showTubeLabels:l=true,showFiberNumbers:g=true,colorMode:f="dark",showCircuitId:p=false,className:u,style:y,readOnly:h=false,panOnDrag:w=true,panOnScroll:k=true,zoomOnScroll:v=true})=>{let C=useMemo(()=>tl(e,r,n,i,a,s,c,l,g,f),[e,r,n,i,a,s,c,l,g,f]),R=useMemo(()=>ol(e,t,o,p),[e,t,o,p]),[x,I]=useState(C),[_,E]=useState(R);useEffect(()=>{I(C);},[C,I]),useEffect(()=>{E(R);},[R,E]);let M=useCallback((B,O)=>{if(!B||!O||!O.startsWith("fiber-"))return;let X=x.find(le=>le.id===B);if(!X||X.type!=="fibre-flow-cable")return;let Q=/^fiber-(\d+)-(\d+)$/.exec(O);if(!Q)return;let $=Number(Q[1]),A=Number(Q[2]),se=X.data.layout.rows.find(le=>(le.tubeIndex??1)===$&&le.fiberIndex===A);if(se)return {color:se.color,striped:se.striped??false}},[x]),D=useCallback(B=>{if(h||!B.source||!B.target||!B.sourceHandle||!B.targetHandle)return false;let O=x.find(pe=>pe.id===B.source),X=x.find(pe=>pe.id===B.target);if(!O||!X)return false;let Q=typeof B.sourceHandle=="string"&&B.sourceHandle.startsWith("fiber-"),$=typeof B.targetHandle=="string"&&B.targetHandle.startsWith("fiber-");return B.sourceHandle==="cable-run"||B.targetHandle==="cable-run"?true:Q&&$?O.type==="fibre-flow-cable"&&X.type==="fibre-flow-cable":false},[x,h]),U=useCallback(B=>{if(h)return;let O=B.sourceHandle==="cable-run"||B.targetHandle==="cable-run",X=j=>typeof j=="string"&&j.startsWith("fiber-"),Q=X(B.sourceHandle),$=X(B.targetHandle),A=(j,ke,oe)=>j.source===ke&&j.sourceHandle===oe||j.target===ke&&j.targetHandle===oe,pe=O?void 0:M(B.source,B.sourceHandle),se=O?void 0:M(B.target,B.targetHandle),le=O?void 0:{sourceColor:pe?.color,targetColor:se?.color,color:pe?.color??se?.color,sourceStriped:pe?.striped,targetStriped:se?.striped};E(j=>{let ke=j.filter(oe=>{let re=Q&&A(oe,B.source,B.sourceHandle),J=$&&A(oe,B.target,B.targetHandle);return !(re||J)});return addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:le},ke)});},[M,h,E]),ee=useCallback((B,O)=>{if(h)return;let X=O.sourceHandle==="cable-run"||O.targetHandle==="cable-run",Q=X?void 0:M(O.source,O.sourceHandle),$=X?void 0:M(O.target,O.targetHandle),A=X?void 0:{sourceColor:Q?.color,targetColor:$?.color,color:Q?.color??$?.color,sourceStriped:Q?.striped,targetStriped:$?.striped},pe=le=>typeof le=="string"&&le.startsWith("fiber-"),se=(le,j,ke)=>le.source===j&&le.sourceHandle===ke||le.target===j&&le.targetHandle===ke;E(le=>{let j=le.filter(J=>J.id!==B.id),ke=pe(O.sourceHandle),oe=pe(O.targetHandle),re=j.filter(J=>{let Oe=ke&&se(J,O.source,O.sourceHandle),Ze=oe&&se(J,O.target,O.targetHandle);return !(Oe||Ze)});return addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:A},re)});},[M,h,E]),te=useCallback(B=>{h||I(B.filter(Vc));},[h,I]),ie=useCallback(B=>{h||E(O=>Yc(B,O));},[h,E]),ce=useMemo(()=>({"fibre-flow-cable":Qc,"fibre-flow-closure":el}),[]),z=useMemo(()=>({"fibre-flow":qc,"fibre-flow-link":Jc}),[]),V={borderRadius:8,overflow:"hidden",...y};return jsx(ri,{nodes:x,edges:_,onNodesChange:te,onEdgesChange:ie,onConnect:U,onEdgeUpdate:ee,isValidConnection:D,connectionMode:ConnectionMode.Loose,nodeTypes:ce,edgeTypes:z,className:u,style:V,colorMode:f,readOnly:h,panOnDrag:w,panOnScroll:k,zoomOnScroll:v,fitViewOptions:{padding:.2}})},nl=e=>jsx(rl,{...e});var sl=({cable:e,side:t,rowHeight:o=22,tubeGap:r=10,columnWidth:n=150,layout:i,showTubeLabels:a,showFiberNumbers:s=true,showCableLabel:c=true})=>{let l=useMemo(()=>i??Ko(e,{rowHeight:o,tubeGap:r}),[i,e,o,r]),g=26,f=10,p=18,u=t==="left"?n-p:p,y=8,h=t==="left"?6:n-g-18,w=e.jacketColor??"#facc15",k=a??(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, ${w} 0%, ${w} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${w}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),k&&l.tubeLabels.map(v=>jsxs("div",{style:{position:"absolute",top:v.y+o/2-6,left:h,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,R=t==="left"?u-f/2-y:u+f/2+y;return jsxs(ot.Fragment,{children:[jsx("div",{style:{position:"absolute",top:C,left:u-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)"}}),s&&jsx("div",{style:{position:"absolute",top:v.y+o/2-6,left:R,transform:t==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:v.fiberIndex})]},v.key)})]})};var Va=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}}),Ga=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}}),Xa=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}}},dl=e=>{let t=[],o=[];return e.racks.forEach(r=>t.push(Va(r))),e.devices.forEach(r=>t.push(Ga(r))),e.cables.forEach(r=>o.push(Xa(r))),{nodes:t,edges:o}},cl=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(a=>a.id===n.parentId);if(i){let a=n.data.uPosition||1,s=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+a*20-s*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 ja=e=>typeof e.id=="number"?`device-${e.id}`:`device-${e.name}`,ll="Interfaces",ul="Management",pl="Power",si=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ft=e=>{if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0},Or=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}},Ht=e=>{if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20")return t},fl=e=>typeof e=="string"&&e.toLowerCase()==="rear"?"rear":"front",Wr=e=>si(e.custom_fields)?e.custom_fields:void 0,zr=e=>si(e)?e:void 0,Ya=(e,t)=>{let o=Wr(e),r=zr(o?.layout);return fl(t??e.layout?.face??e.face??r?.face??o?.port_face??o?.portFace??o?.face)},Ka=(e,t,o)=>{let r=Wr(e),n=zr(r?.layout),i=Ft(o)??Ft(e.layout?.group)??Ft(e.port_group)??Ft(n?.group)??Ft(r?.port_group)??Ft(r?.portGroup)??Ft(r?.interface_group)??Ft(r?.interfaceGroup)??Ft(r?.group);return i||(t==="power_ac"||t==="power_c13"||t==="power_c19"?pl:t==="console"||t==="mgmt"?ul:ll)},Za=(e,t,o)=>{let r=Wr(e),n=zr(r?.layout);return Ht(o)??Ht(e.layout?.connectorType)??Ht(e.layout?.connector_type)??Ht(e.connector_type)??Ht(n?.connectorType)??Ht(n?.connector_type)??Ht(r?.connectorType)??Ht(r?.connector_type)??Ht(t)},qa=(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"},Ja=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"}},gl=e=>{if(!si(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=Or(e.offsetPercent??e.offset_percent??e.offsetPct??e.offset_pct),n=Or(e.offsetPx??e.offset_px??e.offsetPixels??e.offset_pixels),i=Or(e.xPercent??e.x_percent??e.xPct??e.x_pct??e.horizontalPercent??e.horizontal_percent??e.x),a=Or(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&&a===void 0))return {side:o,offsetPercent:r,offsetPx:n,xPercent:i,yPercent:a}},Qa=(e,t,o)=>{if(!o)return;let r=Wr(e),n=zr(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 a of i){let s=gl(a);if(s)return s}},bl=(e,t)=>{let o=e.type?.value??e.type?.label??e.layout?.type??void 0,r=Za(e,o),n=qa(o,r),i=Ka(e,n);return {label:e.name,face:Ya(e),group:i,type:n,cableType:Ja(o),connected:!!(e.connected_endpoint||e.cable),connectorType:r,position:Qa(e,void 0,t)}},ml=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)}),hl=(e,t)=>{let{includePortPositions:o=false,mapInterfaceToPort:r}=t,n=[];return ml(e.interfaces??[]).forEach((a,s)=>{let c=r?r({device:e,iface:a,index:s}):bl(a,o);if(!c)return;let l=c.type??a.type?.value??a.type?.label??void 0,g=Za(a,l,c.connectorType),f=qa(l,g),p=Ya(a,c.face),u=Ka(a,f,c.group);n.push({id:c.id,label:c.label??a.name,face:p,group:u,connected:c.connected??!!(a.connected_endpoint||a.cable),type:f,cableType:Ja(c.cableType??a.type?.value??a.type?.label??void 0),connectorType:g,position:Qa(a,c,o)});}),n},es=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}}),ts=(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 r=hl(e,t);r.length>0&&(o.ports=r);}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}},os=e=>({id:`cable-${e.id}`,source:ja(e.termination_a.device),target:ja(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}}),yl=(e,t={})=>{let o=[],r=[],n=new Map;return e.racks.forEach(i=>{o.push(es(i));}),e.devices.forEach(i=>{let a=ts(i,t);o.push(a),n.set(i.name,a.id);}),e.cables.forEach(i=>{let a=os(i),s=(typeof i.termination_a.device.id=="number"?`device-${i.termination_a.device.id}`:void 0)??n.get(i.termination_a.device.name)??a.source,c=(typeof i.termination_b.device.id=="number"?`device-${i.termination_b.device.id}`:void 0)??n.get(i.termination_b.device.name)??a.target;r.push({...a,source:s,target:c});}),{nodes:o,edges:r}},wl=(e,t)=>{let o=new Map,r=new Set;return e.filter(i=>i.position!==null).sort((i,a)=>(i.position||0)-(a.position||0)).forEach(i=>{i.position&&(o.set(i.id,i.position),r.add(i.position));}),o};function Ur(e){let{items:t,checkOutOfBounds:o,checkConflicts:r}=e,n=[],i=[];for(let a of t){let s=o(a);s&&!s.isValid&&s.error&&i.push(s.error);}for(let a=0;a<t.length;a++){let s=t[a];for(let c=a+1;c<t.length;c++){let l=t[c],g=r(s,l);g&&g.hasConflict&&g.conflict&&n.push(g.conflict);}}return {isValid:n.length===0&&i.length===0,conflicts:n,outOfBounds:i}}var vo=class extends Error{constructor(o,r,n,i,a){super(`Device placement conflict: ${r} at U${n}-${n+i-1} in rack ${o}${a?` conflicts with ${a}`:""}`);this.rackId=o;this.deviceId=r;this.uPosition=n;this.uHeight=i;this.conflictWith=a;this.name="DevicePlacementError";}};function di(e,t={}){let o=Ie(e);return Ur({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,a=r.unit+r.height-1,s=n.unit,c=n.unit+n.height-1;if(i<=c&&a>=s){if(o){let l=Be(r),g=Be(n);if(!ar(l,g))return null}return {hasConflict:true,conflict:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,conflictWith:n.id}}}return null}})}function rs(e,t,o={}){let{deviceTypeMapping:r={}}=o,n=r[e.type]||"device",i=bo(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,portGroups:e.portGroups,rearPortGroups:e.rearPortGroups,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:Be(e)}}}function xl(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,rackWidthPx:e.rackWidthPx,rackLayout:e.rackLayout,rackFaceGapPx:e.rackFaceGapPx}}}function Nl(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let a of e){let s=di(a,t);if(!s.isValid&&o==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new vo(a.id,s.conflicts[0]?.deviceId||s.outOfBounds[0]?.deviceId||"unknown",s.conflicts[0]?.uPosition||s.outOfBounds[0]?.uPosition||1,s.conflicts[0]?.uHeight||s.outOfBounds[0]?.uHeight||1)}}for(let a of e){let s=xl(a);n.push(s);for(let c of a.devices)try{let l=rs(c,s,t);i.push(l);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=ur(s,{id:c.id,data:{label:c.name,uHeight:c.height,mountMode:Be(c)}},i,c.unit);if(g!==void 0&&g!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${g} due to conflict`);let f={...c,unit:g},p=rs(f,s,t);i.push(p);}else throw new vo(a.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function kl(e){let t=[],o=e.filter(r=>r.type==="rack");for(let r of o){let i=e.filter(a=>Do(a.type)&&a.parentId===r.id).map(a=>({id:a.id,name:a.data.label,unit:a.data.uPosition||1,height:a.data.uHeight||1,type:a.data.deviceType||"server",width:a.data.width==="full"||a.data.width==="half"?a.data.width:void 0,ports:Array.isArray(a.data.ports)?a.data.ports:void 0,portGroups:Array.isArray(a.data.portGroups)?a.data.portGroups:void 0,rearPortGroups:Array.isArray(a.data.rearPortGroups)?a.data.rearPortGroups:void 0,connections:a.data.connections,frontImageUrl:a.data.frontImageUrl,rearImageUrl:a.data.rearImageUrl,frontImageAttribution:a.data.frontImageAttribution,rearImageAttribution:a.data.rearImageAttribution,imageFit:a.data.imageFit,imagePosition:a.data.imagePosition,imageRepeat:a.data.imageRepeat,stretchToFit:a.data.stretchToFit,mountMode:Be(a.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 Pl(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 Cl(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!di({...i,devices:[...i.devices,o]},r).isValid)throw new vo(t,o.id,o.unit,o.height);return {...i,devices:[...i.devices,o]}})}function vl(e,t,o){return e.map(r=>r.id!==t?r:{...r,devices:r.devices.filter(n=>n.id!==o)})}var Ro=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 ci(e,t={}){return Ur({items:e.splices,checkOutOfBounds:o=>o.holder<1||o.holder>Wt?{isValid:false,error:{spliceId:o.id,holder:o.holder,max:Wt}}:null,checkConflicts:(o,r)=>o.holder===r.holder?{hasConflict:true,conflict:{spliceId:o.id,holder:o.holder,conflictWith:r.id}}:null})}function ns(e,t){let o=e.mode==="ribbon",r=Xo(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 Rl(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 a of e){let s=ci(a,t);if(!s.isValid&&o==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new Ro(a.id,s.conflicts[0]?.spliceId||s.outOfBounds[0]?.spliceId||"unknown",s.conflicts[0]?.holder||s.outOfBounds[0]?.holder||1)}}for(let a of e){let s=Rl(a);n.push(s);for(let c of a.splices)try{let l=c.holder;if(o==="nearest"){let p={id:c.id,type:"splice",position:{x:0,y:0},data:{label:c.name,holderPosition:c.holder}},u=[...n,...i];Uo(s,p,c.holder,u)||(l=Go(s,p,u,c.holder));}let g=l!==c.holder?{...c,holder:l}:c,f=ns(g,s);i.push(f);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=[...n,...i],f=Go(s,{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 p={...c,holder:f},u=ns(p,s);i.push(u);}else throw new Ro(a.id,c.id,c.holder)}}}return n.push(...i),n}function Sl(e){let t=[],o=e.filter(r=>r.type==="splice-tray");for(let r of o){let i=e.filter(a=>a.type==="splice"&&a.parentId===r.id).map(a=>({id:a.id,name:a.data.label,holder:a.data.holderPosition||1,lossDb:a.data.lossDb,mode:a.data.mode||"single",ribbonFiberIds:a.data.ribbonFiberIds}));t.push({id:r.id,name:r.data.label,position:r.position,splices:i});}return t}function Il(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 El(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!ci({...i,splices:[...i.splices,o]},r).isValid)throw new Ro(t,o.id,o.holder);return {...i,splices:[...i.splices,o]}})}function Fl(e,t,o){return e.map(r=>r.id!==t?r:{...r,splices:r.splices.filter(n=>n.id!==o)})}var is=2;var be=e=>typeof e=="string"?e.trim():"",yt=e=>{if(typeof e=="number"&&Number.isFinite(e))return e},Hl=e=>{let t=be(e).toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20"||t==="AC")return t},Dl=(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"},_l=e=>{if(e==="power_c13")return "C13";if(e==="power_c19")return "C19";if(e==="power_ac")return "AC"},Ml=e=>e.toLowerCase().replace(/_/g,"-").trim(),$l=e=>e>=1?"rackable":"zero-u",Al=e=>(e??"").toLowerCase()==="half"?"half":"full",Ll=(e,t,o,r)=>{let n=r.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase();return `${e}-b${t}-${n||`p${o}`}`},as=(e,t)=>`${e}-${t}`.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function Bl(e){let t=[],o=be(e.manufacturer),r=be(e.model),n=be(e.role)||be(e.deviceType)||be(e.device_type)||"device",i=yt(e.uHeight)??yt(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 a=be(e.id)||be(e.slug)||as(o,r)||"unknown",s=be(e.slug)||as(o,r)||a,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(p=>({frontPortId:be(p.frontPortId)||be(p.front_port_id),rearPortId:be(p.rearPortId)||be(p.rear_port_id)}));return {id:a,slug:s,manufacturer:o,model:r,role:n,uHeight:i,width:be(e.width)||void 0,frontBlocks:c,rearBlocks:l,rawLinks:f,frontImageUrl:be(e.frontImageUrl)||be(e.front_image_url)||void 0,rearImageUrl:be(e.rearImageUrl)||be(e.rear_image_url)||void 0,frontImageAttribution:be(e.frontImageAttribution)||void 0,rearImageAttribution:be(e.rearImageAttribution)||void 0,tags:Array.isArray(e.tags)?e.tags.map(be).filter(Boolean):[],sourceRepository:be(e.sourceRepository)||be(e.source_repository)||void 0,sourcePath:be(e.sourcePath)||be(e.source_path)||void 0,issues:t}}function ss(e,t,o){let r=be(e.name)||`Block ${o+1}`,i=(Array.isArray(e.ports)?e.ports:[]).map((a,s)=>{let c=be(a.label)||be(a.name)||`Port ${s+1}`,l=Hl(a.connectorType??a.connector_type),g=Dl(be(a.type),l),f=l??_l(g),u={id:be(a.id)||Ll(t,o,s,c),label:c,type:g,connectorType:f};if(a.position){let y=a.position,h=be(y.side),w={},k=false;h&&["top","right","bottom","left"].includes(h)&&(w.side=h,k=true);let v=yt(y.offsetPercent)??yt(y.offset_percent);v!==void 0&&(w.offsetPercent=v,k=true);let C=yt(y.offsetPx)??yt(y.offset_px);C!==void 0&&(w.offsetPx=C,k=true);let R=yt(y.xPercent)??yt(y.x_percent);R!==void 0&&(w.xPercent=R,k=true);let x=yt(y.yPercent)??yt(y.y_percent);x!==void 0&&(w.yPercent=x,k=true),k&&(u.position=w);}return u});return {name:r,ports:i}}function Ol(e){let t=[],o=Ml(e.role),r=e.uHeight,n=$l(r),i=Al(e.width),a=e.frontBlocks.map((c,l)=>ss(c,"front",l)),s=e.rearBlocks.map((c,l)=>ss(c,"rear",l));return {role:o,mountClass:n,uHeight:r,width:i,frontFace:{portBlocks:a,imageUrl:e.frontImageUrl,imageAttribution:e.frontImageAttribution},rearFace:{portBlocks:s,imageUrl:e.rearImageUrl,imageAttribution:e.rearImageAttribution},issues:t}}function Wl(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 zl(e){let t=[],{front:o,rear:r}=Wl(e.frontFace,e.rearFace),n=e.role;return (!n||n==="device")&&[...o.portBlocks,...r.portBlocks].some(a=>a.ports.some(s=>s.type&&s.type.startsWith("power")))&&e.mountClass==="zero-u"&&(n="pdu"),{frontFace:o,rearFace:r,mountClass:e.mountClass,role:n,issues:t}}function Zo(e){return e.portBlocks.reduce((t,o)=>t+o.ports.length,0)}function Ul(e,t){let o=[],r=[];for(let u of t.frontFace.portBlocks)for(let y of u.ports)r.push({id:y.id,face:"front"});for(let u of t.rearFace.portBlocks)for(let y of u.ports)r.push({id:y.id,face:"rear"});let n=new Map;for(let{id:u}of r)n.set(u,(n.get(u)??0)+1);for(let[u,y]of n)y>1&&o.push({severity:"error",code:"DUPLICATE_PORT_ID",message:`Duplicate port id "${u}" found ${y} times`,path:`ports.${u}`});let i=e.frontBlocks.reduce((u,y)=>u+(Array.isArray(y.ports)?y.ports.length:0),0),a=e.rearBlocks.reduce((u,y)=>u+(Array.isArray(y.ports)?y.ports.length:0),0),s=Zo(t.frontFace),c=Zo(t.rearFace);s!==i&&o.push({severity:"error",code:"FRONT_PORT_COUNT_MISMATCH",message:`Front port count mismatch: raw=${i}, parsed=${s}`,path:"faces.front"}),c!==a&&o.push({severity:"error",code:"REAR_PORT_COUNT_MISMATCH",message:`Rear port count mismatch: raw=${a}, parsed=${c}`,path:"faces.rear"});let l=new Set(r.map(u=>u.id)),g=new Set(r.filter(u=>u.face==="front").map(u=>u.id)),f=new Set(r.filter(u=>u.face==="rear").map(u=>u.id));for(let u of e.rawLinks)u.frontPortId&&!g.has(u.frontPortId)&&!l.has(u.frontPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_FRONT_PORT_MISSING",message:`Pass-through link references unknown front port "${u.frontPortId}"`,path:"frontRearPortLinks"}),u.rearPortId&&!f.has(u.rearPortId)&&!l.has(u.rearPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_REAR_PORT_MISSING",message:`Pass-through link references unknown rear port "${u.rearPortId}"`,path:"frontRearPortLinks"});return {valid:!o.some(u=>u.severity==="error"),issues:o,portCounts:{front:s,rear:c}}}function Vl(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 Gl(e){let t=Bl(e),o=Ol(t),r=zl(o),n=Ul(t,r);return n.issues.push(...t.issues,...o.issues,...r.issues),n.valid?{template:Vl(t,o,r),report:n}:{template:null,report:n}}function Xl(e){return Zo(e)}function jl(e,t,o){let r=[],n=Zo(e.faces.front),i=Zo(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{ic as COUPLERS_PER_PANEL,Er as COUPLER_SLOT_HEIGHT_PX,ac as COUPLER_WIDTH_PX,$n as CableNode,Kn as ClosureNode,Bn as CouplerNode,ho as DeviceNode,vo as DevicePlacementError,ni as DiagramErrorBoundary,_i as FIBER_COLORS_12,gr as FiberEdge,cn as FiberNode,sl as FibreCableWithTubesExpanded,nl as FibreFlowMap,qn as FibreSplitNode,Ho as HANDLE_EXTENSION_PX,Ln as MultiTubeCableNode,ri as NetworkDiagram,la as PANEL_BORDER_WIDTH,no as PANEL_HEADER_HEIGHT,Ir as PANEL_HEIGHT_PX,ro as PANEL_PADDING,ua as PANEL_TUBE_TRAY_SPACING,Sr as PANEL_WIDTH_PX,fn as POWER_CONNECTORS,Xn as PatchPanelNode,un as PowerEdge,Ct as RACK_HEADER_HEIGHT,on as RACK_WIDTH_PX,dn as RackNode,Tn as SpliceNode,Ro as SplicePlacementError,Hn as SpliceTrayNode,is as TEMPLATE_SCHEMA_VERSION,Dn as TubeNode,Ke as U_HEIGHT_PX,Cn as VerticalPDU,Gi as Width,Cl as addDeviceToRack,El as addSpliceToTray,ze as baseColorFor,Nl as buildNodesFromRackConfig,Tl as buildNodesFromSpliceConfig,Ri as buildPortBlocksFromPorts,Un as calculateClosureDimensions,dc as calculateCouplerRightX,lc as calculateCouplerSlotSpacing,wa as calculateCouplerSpacing,bo as calculateDevicePositionFromU,zn as calculatePanelDimensions,ha as calculateSlotPositionFromY,qd as calculateSplicePositionFromNumber,wl as calculateUPositions,ya as calculateYFromSlotPosition,Xl as countTemplateFacePorts,Jn as createNetworkDiagramStore,kl as createRackConfigFromNodes,Sl as createSpliceConfigFromNodes,ln as fiberSolidOrStriped,Ar as findNearestRack,Go as findNextAvailableHolderPosition,ur as findNextAvailableUPosition,cl as generateLayout,Xi as getConnectorConfig,Wn as getCouplerDimensions,it as getDefaultDeviceView,gn as getDeviceConnectorType,qt as getFiberColor,nn as getFrontPortBlocks,ma as getInnerContentWidth,mr as getPDUPortType,sc as getPanelHeight,ba as getPanelWidth,Ot as getPowerPortStyle,va as getRackBounds,an as getRearPortBlocks,Je as getResolvedPortBlocks,bt as getStatusColor,pa as getTrayDimensions,Fr as getTubeDimensions,Ti as hasFrontPorts,Si as hasRearPorts,Xa as inventoryCableToNetworkEdge,Ga as inventoryDeviceToNetworkNode,Va as inventoryRackToNetworkNode,dl as inventoryToNetworkDiagram,cd as isHighPowerConnector,Ra as isPointInRack,Zt as isStriped,jt as isUPositionAvailable,os as netboxCableToNetworkEdge,ts as netboxDeviceToNetworkNode,es as netboxRackToNetworkNode,yl as netboxToNetworkDiagram,Gl as parseNetboxTemplate,vl as removeDeviceFromRack,Fl as removeSpliceFromTray,Me as replaceEdge,cc as snapToCouplerPosition,In as snapToSplicePosition,lr as snapToUPosition,Di as updateDeviceUPosition,Pl as updateDeviceUPositionInSchema,Il as updateSpliceHolderPosition,ti as useDiagramEdges,ei as useDiagramNodes,wc as useNetworkDiagram,Vs as validateAndSnapDevice,di as validateRackDevicePlacements,jl as validateRenderFidelity,ci as validateSplicePlacements};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map