@mp70/react-networks 0.1.8-beta → 0.2.0-beta.1
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/README.md +45 -23
- package/dist/index.css +32 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +493 -5
- package/dist/index.d.ts +493 -5
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import nt,{useState,useMemo,useRef,useEffect,useSyncExternalStore,useCallback}from'react';import {useReactFlow,Handle,Position,getBezierPath,BaseEdge,EdgeLabelRenderer,useEdges,addEdge,ReactFlowProvider,useNodesState,useEdgesState,useOnSelectionChange,ReactFlow,Background,Controls,MiniMap,Panel,getSmoothStepPath,SmoothStepEdge}from'reactflow';import {toPng}from'html-to-image';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Dn=()=>"bottom-up",Ge=e=>e.data.uNumberingDirection||Dn(),Ft=(e,o,r)=>r==="bottom-up"?o-e+1:e,Wt=(e,o,r)=>r==="bottom-up"?o-e+1:e;var mo=(e,o,r,n)=>{if(!e.parentId||e.parentId!==o.id)return r;let a=e.data.uHeight||1,i=o.data.uHeight||42,d=Ge(o),s=60,c=r.y-s,l=Math.round(c/20)+1,h;d==="bottom-up"?h=Ft(l,i,d)-a+1:h=Ft(l,i,d);let u=i-a+1,m=Math.max(1,Math.min(u,h));if(d==="top-down"&&h<=1&&(m=1),!yo(o,e,m,n)){let H=zt(o,e,n,m);H!==m&&(m=H);}let f;if(d==="bottom-up"){let H=m+a-1,k=Wt(H,i,d);f=s+(k-1)*20-1;}else {let H=Wt(m,i,d);f=s+(H-1)*20-1;}return {x:r.x,y:f,uPosition:m}},yo=(e,o,r,n)=>{let a=o.data.uHeight||1,i=e.data.uHeight||42;if(r<1||r+a-1>i)return false;let d=n.filter(s=>s.type==="device"&&s.parentId===e.id&&s.id!==o.id);for(let s of d){let c=s.data.uPosition||1,l=s.data.uHeight||1,h=r,u=r+a-1,m=c,f=c+l-1;if(h<=f&&u>=m)return false}return true},zt=(e,o,r,n=1)=>{let a=o.data.uHeight||1,i=e.data.uHeight||42;for(let d=n;d<=i-a+1;d++)if(yo(e,o,d,r))return d;return 1},at=(e,o,r=1)=>{let n=60,a=Ge(e),i=e.data.uHeight||42,d=Wt(o,i,a),s;if(a==="bottom-up"){let c=o+r-1,l=Wt(c,i,a);s=n+(l-1)*20-1;}else s=n+(d-1)*20-1;return {x:0,y:s}},wr=(e,o,r)=>{let n=e.data.uHeight||1,a=at(o,r,n);return {...e,position:a,data:{...e.data,uPosition:r}}},$n=(e,o)=>{let r=e.data.uPosition||1,n=e.data.uHeight||1,a=o.data.uHeight||42,i=Math.max(1,Math.min(a-n+1,r));return i!==r?wr(e,o,i):e};function Ee(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var xo=({data:e,selected:o,id:r,onViewChange:n,onRackFaceChange:a,isDragOver:i=false})=>{let{label:d,ports:s=0,status:c="active",uHeight:l=42,face:h="front",customHeaderText:u,rackWidthPx:m}=e,f=m||300,{getNodes:H,setNodes:k}=useReactFlow(),w=H(),[R,M]=useState(e.showUMarkers!==void 0?e.showUMarkers:true),I=()=>{let W=Ge({data:e})==="bottom-up"?"top-down":"bottom-up";k(C=>C.map(D=>D.id===r?{...D,data:{...D.data,uNumberingDirection:W}}:D));},z=()=>{let x=h==="front"?"rear":"front";a?(a(r,x),n&&w.filter(C=>C.parentId===r).forEach(C=>{n(C.id,x);})):n?w.filter(C=>C.parentId===r).forEach(C=>{n(C.id,x);}):k(W=>W.map(C=>C.id===r?{...C,data:{...C.data,face:x}}:C.parentId===r?{...C,data:{...C.data,view:x}}:C));},P=()=>{let x=[],W=60,C=Ge({data:e});for(let D=1;D<=l;D++){let $=W+(D-1)*20-4,_=Ft(D,l,C);x.push(jsx("div",{style:{position:"absolute",left:"-35px",top:`${$}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:_},D));}return x};return jsxs("div",{className:`rack-node ${o?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${Ee(c)}`,borderRadius:"8px",padding:0,width:`${f}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":o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[u?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:u}):jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",h]}),jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),M(!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"} U markers`,children:"U"}),jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),I();},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 ${Ge({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Ge({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),z();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${h==="front"?"rear":"front"} view`,children:h==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"}}),R&&jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:P()})]})};var wo=({data:e,selected:o})=>{let{label:r,status:n="active"}=e;return jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${Ee(n)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:o?"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:r})}),jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:Ee(n),borderRadius:"50%"}})]})};var kr=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function fe(e){let o=(e-1)%12;return kr[o]}function No(e){return e>12}function Ke(e){let o=fe(e);return No(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function ko(e){return fe(e)}function De(e){return e.map(o=>({base:fe(o),striped:No(o)}))}function An(e,o,r,n,a,i,d,s){let c=De(r),l=c.length,h=n?1.2:1,u=!!s?.highlight,m=n?2:1.5,f=s?.highlightWidth??m*3,H=s?.highlightColor??c[0]?.base??"#22d3ee";return jsxs(Fragment,{children:[u&&jsx(BaseEdge,{id:`${e}-highlight`,path:o,style:{...a,stroke:H,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${m}px`,"--rn-edge-highlight-to":`${f}px`}}),c.map((k,w)=>{let M=(l-w)*h;return jsx("path",{d:o,stroke:k.base,strokeWidth:M,fill:"none",strokeLinecap:"butt",opacity:k.striped?.9:1,style:a},`${e}-ribbon-${w}`)}),c.some(k=>k.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:o,style:{...a,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:n&&s&&(s.bandwidth||s.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${d}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[s.bandwidth&&jsx("div",{children:s.bandwidth}),s.length&&jsxs("div",{children:[s.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[r.length,"F"]})]})})]})}var vo=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},className:h})=>{let[u,m,f]=getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d}),{bandwidth:H,length:k,color:w="#00FFFF",striped:R=false,ribbonFiberIds:M,isRibbon:I,highlight:z,highlightColor:P,highlightWidth:x}=s||{},W=!!z;if((I||M&&M.length>=6&&M.length<=12)&&M)return An(e,u,M,c??false,l??{},m,f,s);let D=c?3:2,$=x??D*3,_={...l,stroke:w,strokeWidth:D,strokeDasharray:"none"};return jsxs(Fragment,{children:[W&&jsx(BaseEdge,{id:`${e}-highlight`,path:u,style:{...l,stroke:P??w,strokeWidth:$,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${D}px`,"--rn-edge-highlight-to":`${$}px`}}),jsx(BaseEdge,{id:e,path:u,style:_}),R&&jsx(BaseEdge,{id:`${e}-stripe`,path:u,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsx(EdgeLabelRenderer,{children:c&&s&&(H||k)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${f}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[H&&jsx("div",{children:H}),k&&jsxs("div",{children:[k,"m"]})]})})]})};var Ho=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l})=>{let[h]=getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d}),u=c?.connectorType||"C13";return jsx(BaseEdge,{id:e,path:h,markerEnd:l,style:(()=>{let f={stroke:c?.color||"#f59e0b",strokeWidth:u==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return u==="C19"?{...f,strokeDasharray:"none"}:{...f,strokeDasharray:"6,3"}})()})};function Vn(e,o,r,n,a,i,d,s,c,l,h){let u=De(s),m=u.length,f=c?1.8:1.5,H=!!h?.highlight,k=c?3:2.5,w=h?.highlightWidth??k*3,R=h?.highlightColor??u[0]?.base??"#22d3ee",[M,I,z]=getSmoothStepPath({sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d});return jsxs(Fragment,{children:[H&&jsx(BaseEdge,{id:`${e}-highlight`,path:M,style:{...l,stroke:R,strokeWidth:w,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${k}px`,"--rn-edge-highlight-to":`${w}px`}}),u.map((P,x)=>{let C=(m-x)*f;return jsx("path",{d:M,stroke:P.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:P.striped?.9:1,style:l},`${e}-ribbon-${x}`)}),u.some(P=>P.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:M,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:c&&h&&(h.bandwidth||h.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${I}px,${z}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${u[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[h.bandwidth&&jsx("div",{children:h.bandwidth}),h.length&&jsxs("div",{children:[h.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[s.length,"F"]})]})})]})}var Pr=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...h})=>{let{color:u="#00FFFF",ribbonFiberIds:m,isRibbon:f,highlight:H,highlightColor:k,highlightWidth:w}=s||{},R=!!H;if((f||m&&m.length>=6&&m.length<=12)&&m)return Vn(e,o,r,n,a,i,d,m,c??false,l??{},s);let I=c?4:3,z=w??I*3,P={...l,stroke:u,strokeWidth:I};return jsxs(Fragment,{children:[R&&jsx(BaseEdge,{id:`${e}-highlight`,path:getSmoothStepPath({sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d})[0],style:{...l,stroke:k??u,strokeWidth:z,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${I}px`,"--rn-edge-highlight-to":`${z}px`}}),jsx(SmoothStepEdge,{...h,id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:P})]})};function Xn({sourceX:e,sourceY:o,targetX:r,targetY:n,sourcePosition:a,targetPosition:i}){let d=a===Position.Left||a===Position.Right,s;if(d){let c=(e+r)/2;s=`M ${e},${o} L ${c},${o} L ${c},${n} L ${r},${n}`;}else {let c=(o+n)/2;s=`M ${e},${o} L ${e},${c} L ${r},${c} L ${r},${n}`;}return s}function jn(e,o,r,n,a,i){let d=De(r),s=d.length,c=n?1.2:1,l=!!i?.highlight,h=n?2:1.5,u=i?.highlightWidth??h*3,m=i?.highlightColor??d[0]?.base??"#22d3ee",f=o.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),H=f?(parseFloat(f[1])+parseFloat(f[3]))/2:0,k=f?(parseFloat(f[2])+parseFloat(f[4]))/2:0;return jsxs(Fragment,{children:[l&&jsx(BaseEdge,{id:`${e}-highlight`,path:o,style:{...a,stroke:m,strokeWidth:u,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${h}px`,"--rn-edge-highlight-to":`${u}px`}}),d.map((w,R)=>{let I=(s-R)*c;return jsx("path",{d:o,stroke:w.base,strokeWidth:I,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:a},`${e}-ribbon-${R}`)}),d.some(w=>w.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:o,style:{...a,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:n&&i&&(i.bandwidth||i.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${k}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${d[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsx("div",{children:i.bandwidth}),i.length&&jsxs("div",{children:[i.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[r.length,"F"]})]})})]})}var Rr=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...h})=>{let{color:u="#00FFFF",striped:m=false,ribbonFiberIds:f,isRibbon:H,highlight:k,highlightColor:w,highlightWidth:R}=s||{},M=!!k,I=Xn({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d});if((H||f&&f.length>=6&&f.length<=12)&&f)return jn(e,I,f,c??false,l??{},s);let P=c?3:2,x=R??P*3,W={...l,stroke:u,strokeWidth:P,strokeDasharray:"none"};return jsxs(Fragment,{children:[M&&jsx(BaseEdge,{id:`${e}-highlight`,path:I,style:{...l,stroke:w??u,strokeWidth:x,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${P}px`,"--rn-edge-highlight-to":`${x}px`}}),jsx(BaseEdge,{id:e,path:I,style:W}),m&&jsx(BaseEdge,{id:`${e}-stripe`,path:I,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var Dr=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l,selected:h})=>{let{color:u="#6366f1",label:m,highlight:f,highlightColor:H,highlightWidth:k}=c||{},w=!!f,R=8,M=k??R*1.8,[I,z,P]=getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d}),x={...s,stroke:u,strokeWidth:R,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxs(Fragment,{children:[w&&jsx(BaseEdge,{id:`${e}-highlight`,path:I,style:{...s,stroke:H??u,strokeWidth:M,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${H??u}) drop-shadow(0 0 16px ${H??u})`,"--rn-edge-highlight-from":`${R}px`,"--rn-edge-highlight-to":`${M}px`}}),jsx(BaseEdge,{id:e,path:I,markerEnd:l,style:x}),m&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${z}px,${P}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${u}`,pointerEvents:"none",zIndex:9999},children:m})})]})};var $r=(r=>(r.FULL="full",r.HALF="half",r))($r||{});var Po={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}};function st(e){let o=Po[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let r=o.amperage===16,n=r?12:8,a=r?10:5,i=r?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:a,color:o.color,borderColor:o.borderColor,fontSize:r?"3px":"4px",...i}}function Ot(e){let o=Po[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function Jn(e){return Ot(e).amperage===16}function Co(e){return e%10<8?"C13":"C19"}function Bt(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Ro=({data:e,selected:o})=>{let{label:r,status:n="active",deviceType:a="server",manufacturer:i,role:d,uHeight:s=1,width:c="full",ports:l=[],rearPorts:h=[],view:u,rackWidthPx:m}=e,f=m||300,H=u||(h.length>0&&l.length===0?"rear":"front"),k={};k["net-top"]="front",k["net-bottom"]="front",l.length>0&&l.forEach(C=>{C.ports.forEach(D=>{let $=D.type?.includes("power")?D.label:`${C.name}-${D.label}`;k[$]="front";});}),k["pwr-left-1"]="rear",k["pwr-left-2"]="rear",k["net-right-1"]="rear",k["net-right-2"]="rear",h.length>0&&h.forEach(C=>{C.ports.forEach(D=>{let $=D.type?.includes("power")?D.label:`${C.name}-${D.label}`;k[$]="rear";});});let w=s*20,R=f+4,M=Math.floor(f/2),I=c==="half"?`${M}px`:`${R}px`,z=c==="half"?`${M}px`:void 0,P=(C,D)=>{let $=[];if(C.length===0)return $;let _=Math.max(4,Math.floor(w*.4)),X=Math.max(2,Math.floor(w*.2));return C.forEach((Z,oe)=>{Z.ports.forEach((U,S)=>{let O=!!U.type&&U.type.includes("power");if(D==="front"&&O)return;let te=O?`${U.label}`:`${Z.name}-${U.label}`,V=U.connected,A="#6b7280";if(V)if(U.type?.includes("power"))A=U.type==="power_c19"?"#fbbf24":"#f59e0b";else if(U.type==="console"||U.type==="mgmt")A="#8b5cf6";else if(U.type==="usb")A="#10b981";else switch(U.cableType){case "smf":A="#fbbf24";break;case "cat6":A="#8b5cf6";break;case "om3":A="#06b6d4";break;case "om4":A="#8b5cf6";break;case "om5":A="#84cc16";break;case "cat5e":A="#3b82f6";break;case "cat6a":A="#ef4444";break;case "cat7":A="#f97316";break;case "fiber":A="#3b82f6";break;case "ethernet":A="#10b981";break;default:A="#10b981";}let re=Position.Top,T={width:`${_}px`,height:`${X}px`,background:V?A:"#6b7280",border:`1px solid ${V?A:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(D==="front")S%2===0?(re=Position.Top,T.transform="translateY(50%)",T.left=`${S/2*(_+2)}px`):(re=Position.Bottom,T.transform="translateY(-50%)",T.left=`${(S-1)/2*(_+2)}px`);else if((a?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel"||a==="switch")S%2===0?(re=Position.Top,T.transform="translateY(50%)",T.left=`${S/2*(_+2)}px`):(re=Position.Bottom,T.transform="translateY(-50%)",T.left=`${(S-1)/2*(_+2)}px`);else if(U.type?.includes("power")){re=Position.Left,T.transform="translateX(50%)";let Pt=w<=20?10:20,Ct=w<=20?30:50;T.top=`${Pt+S*Ct}%`;let Et=Bt(r),_e=st(Et);T={...T,width:`${_e.width}px`,height:`${_e.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:_e.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:_e.borderRadius,clipPath:_e.clipPath};}else re=Position.Right,T.transform="translateX(-50%)",T.top=`${25+S*50}%`;let be=(a?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",q;if(O)q="target";else if(a==="switch"||a==="router")q="source",$.push(jsx(Handle,{id:`${te}-target`,type:"target",position:re,style:T,title:`${Z.name} - ${U.label} (input) ${V?"(connected)":"(disconnected)"}`},`${te}-target`));else if(be){q=D==="rear"?"source":"target";let he=D==="rear"?"target":"source";$.push(jsx(Handle,{id:`${te}-${he}`,type:he,position:re,style:T,title:`${Z.name} - ${U.label} (${he}) ${V?"(connected)":"(disconnected)"}`},`${te}-${he}`));}else q=V?"source":"target";$.push(jsx(Handle,{id:te,type:q,position:re,style:T,title:`${Z.name} - ${U.label} ${V?"(connected)":"(disconnected)"}`,children:O?S+1:void 0},te));});}),$},x=()=>{let C=[],D=Math.max(4,Math.floor(w*.4)),$=Math.max(2,Math.floor(w*.2));if(H==="front"){if(l.length>0)return P(l,"front");if(a==="switch"&&(r.toLowerCase().includes("agg")||r.toLowerCase().includes("core")||d==="agg"||d==="core"))return W();C.push(jsx(Handle,{id:"net-top",type:"target",position:Position.Top,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),C.push(jsx(Handle,{id:"net-bottom",type:"target",position:Position.Bottom,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(H==="rear"){if(h.length>0)return P(h,"rear");let _=a==="switch",Z=(a?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!Z){let oe=Bt(r),U=Ot(oe),S=st(oe),O=w<=20?"10%":"25%";C.push(jsx(Handle,{id:"pwr-left-1",type:"target",position:Position.Left,style:{width:`${S.width}px`,height:`${S.height}px`,background:S.color,border:`1px solid ${S.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:O,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:S.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:S.borderRadius,clipPath:S.clipPath},title:`Power Port 1 (${U.type}) - ${U.voltage}V, ${U.amperage}A`,children:"1"},"pwr-1"));let te=w<=20?"50%":"75%";C.push(jsx(Handle,{id:"pwr-left-2",type:"target",position:Position.Left,style:{width:`${S.width}px`,height:`${S.height}px`,background:S.color,border:`1px solid ${S.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:te,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:S.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:S.borderRadius,clipPath:S.clipPath},title:`Power Port 2 (${U.type}) - ${U.voltage}V, ${U.amperage}A`,children:"2"},"pwr-2"));}!_&&!Z&&(C.push(jsx(Handle,{id:"net-right-1",type:"target",position:Position.Right,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"25%"},title:"Network Port 1 (Right)"},"net-right-1")),C.push(jsx(Handle,{id:"net-right-2",type:"target",position:Position.Right,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"75%"},title:"Network Port 2 (Right)"},"net-right-2")));}return C},W=()=>{let C=[],D=Math.max(10,Math.floor(w*.45)),$=Math.max(5,Math.floor(w*.25));for(let _=1;_<=16;_++){let X=jsx(Handle,{id:`port-${_}`,type:"source",position:Position.Top,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(_-1)*(D+2)}px`},title:`Port ${_}`},`port-${_}`);C.push(X);}for(let _=17;_<=32;_++){let X=_-16,Z=jsx(Handle,{id:`port-${_}`,type:"source",position:Position.Bottom,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${(X-1)*(D+2)}px`},title:`Port ${_}`},`port-${_}`);C.push(Z);}for(let _=1;_<=4;_++){let X=Math.max(4,Math.floor(w*.3)),Z=Math.max(3,Math.floor(w*.15));C.push(jsx(Handle,{id:`uplink-${_}`,type:"source",position:Position.Right,style:{width:`${X}px`,height:`${Z}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${_}`},`uplink-${_}`));}return C};return jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${Ee(n)}`,borderRadius:"2px",padding:"0px",width:I,...z&&{left:z},height:`${w}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r}),s>1&&jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:i})]}),s>1&&jsxs("div",{style:{position:"absolute",bottom:"1px",right:"1px",background:"#374151",color:"#9ca3af",padding:"1px 2px",borderRadius:"1px",fontSize:"6px",lineHeight:"1"},children:[s,"U"]}),jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:Ee(n),borderRadius:"50%"}}),x()]})};var To=({data:e,selected:o})=>{let{label:r,status:n="active",heightCm:a=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:s}=e,c=a*4.2,l=()=>{let m=Math.ceil(i/10),f=Array(10).fill(0).map((x,W)=>W<8?"10A":"16A");for(let x=0,W=0;x<m;++x)for(let C=0;C<10&&W<i;++C,++W){f[C];}let R=[],M=15,P=(c-M-3)/(i-9)*.5;for(let x=0;x<i;x++){let W=M-2+P*x,C=`${x+1}`;if(s&&(s==="top"&&x===0||s==="middle"&&x===Math.floor(i/2)||s==="bottom"&&x===i-1)){R.push(h(W));continue}let $=Co(x),_=st($),X=Math.round((d-_.width)/2-1);R.push(jsx(Handle,{type:"source",position:Position.Right,id:C,style:{position:"absolute",left:`${X}px`,top:`${W-_.height/2}px`,width:`${_.width}px`,height:`${_.height}px`,background:_.color,border:`1px solid ${_.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:_.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:_.borderRadius,clipPath:_.clipPath},title:`Power Port ${x+1} (${$})`,children:x+1},`handle-${C}`));}return R},h=u=>jsxs("div",{style:{position:"absolute",left:`${(d-16)/2}px`,top:`${u-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");return jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${Ee(n)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${c}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:"20px",display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:r})}),jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${c-20}px`,overflow:"hidden"},children:l()})]})};var $o=({data:e,selected:o,id:r})=>{let{lossDb:n,mode:a="single",ribbonFiberIds:i}=e||{},d=useEdges(),s=d.find(P=>P.target===r&&P.targetHandle==="left"),c=d.find(P=>P.source===r&&P.sourceHandle==="right"),l=d.find(P=>P.target===r&&P.targetHandle==="right"),h=c||l,u=s?.data?.color||"#555",m=h?.data?.color||"#555",f=a==="ribbon",H=s?.data?.ribbonFiberIds||i,k=h?.data?.ribbonFiberIds||i,w=f&&H?De(H):null,R=f&&k?De(k):null,M=!!s&&!!h;return jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:f?85:69,height:f?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[f&&w&&R?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((P,x)=>jsx("div",{style:{flex:1,background:P.base,opacity:P.striped?.9:1}},`left-${x}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:R.map((P,x)=>jsx("div",{style:{flex:1,background:P.base,opacity:P.striped?.9:1}},`right-${x}`))})]}):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:u}}),jsx("div",{style:{background:m}})]}),jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),M&&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}}),M&&typeof n=="number"&&jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:f?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsx("div",{children:`${n.toFixed(2)} dB`}),f&&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:f&&w?20:12,borderRadius:f&&w?"6px":"50%",border:"none",background:f&&w?`linear-gradient(to bottom, ${w.map(P=>P.base).join(", ")})`:u,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:f&&R?20:12,borderRadius:f&&R?"6px":"50%",border:"none",background:f&&R?`linear-gradient(to bottom, ${R.map(P=>P.base).join(", ")})`:m,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:f&&R?20:12,borderRadius:f&&R?"6px":"50%",border:"none",background:f&&R?`linear-gradient(to bottom, ${R.map(P=>P.base).join(", ")})`:m,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Nt=20,Ut=36;var Qe=32,zr=4,Oe=12,ei=69,et=80,_o=(et-ei)/2;var Wo=(e,o,r,n)=>{if(!e.parentId||e.parentId!==o.id)return r;let a=e.data?.mode==="ribbon",i=a?Ut:Nt,d=a?32:16,s=Qe,c=r.y-s,l=Math.round(c/i)+1,u=Math.max(1,Math.min(Oe,l));if(!Fo(o,e,u,n)){let H=Vt(o,e,n,u);if(H!==u){let k=(i-d)/2;return {x:_o,y:s+(H-1)*i+k,holderPosition:H}}}let m=(i-d)/2,f=s+(u-1)*i+m;return {x:_o,y:f,holderPosition:u}},Fo=(e,o,r,n)=>!n.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==o.id).some(i=>i.data.holderPosition===r),Vt=(e,o,r,n=1)=>{for(let a=n;a<=Oe;a++)if(Fo(e,o,a,r))return a;for(let a=n-1;a>=1;a--)if(Fo(e,o,a,r))return a;return 1},ti=(e,o)=>kt(e,o,false),kt=(e,o,r=false)=>{let n=Qe,a=r?Ut:Nt,d=(a-(r?32:16))/2,s=n+(o-1)*a+d;return {x:_o,y:s}};var Mo=({data:e,selected:o})=>{let{label:r="Splice Tray"}=e||{},[n,a]=useState(false),i=()=>{if(!n)return null;let d=[],s=Qe;for(let c=1;c<=Oe;c++){let l=s+(c-1)*Nt;d.push(jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${Nt}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxs("div",{className:`splice-tray-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${et}px`,height:`${Qe+Oe*Ut+zr}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"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:`${Qe}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:r}),jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),a(!n);},style:{background:n?"#10b981":"#374151",color:n?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${n?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsx("div",{style:{position:"absolute",top:Qe,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Lo=({data:e,selected:o,id:r})=>{let{fibersPerTube:n=12,tubeIndex:a=1,startOn:i="left-center"}=e||{},d=e?.mode==="ribbon"||e?.ribbon===true,s=useEdges(),c=`tube-${a}`,l=s.find(Z=>Z.source===r&&Z.sourceHandle===c||Z.target===r&&Z.targetHandle===c),h=l?.data?.color,u=fe((a-1)%12+1),m=h||u,f=Math.max(1,Math.min(24,Number(n)||12)),H=14,k=4,w=1,R=2,M=20,I=f*H+(f-1)*k,z=Math.max(60,I+w*2+R*2),P=i==="left"?Position.Left:i==="right"?Position.Right:Position.Bottom,x=P!==Position.Bottom,W=x?14:20,C=x?8:20,D=x?`inset ${P===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",$=l?m:x?`linear-gradient(${P===Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${m}`:`radial-gradient(circle, ${m} 40%, transparent 70%)`,_={width:W,height:C,borderRadius:x?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:$,backgroundColor:m,border:l?`2px solid ${m}`:`3px dashed ${m}`,cursor:"crosshair","--fiber-bg":m,boxShadow:l?D:`${D}${D!=="none"?", ":""}0 0 8px ${m}`,transition:"opacity 0.2s, box-shadow 0.2s",...P===Position.Left?{left:-(W-4)}:P===Position.Right?{right:-(W-4)}:{}},X=useMemo(()=>{let Z=[],oe=z-R*2-w*2,U,S,O=false;i==="left"?(U=w,S=Position.Top):i==="right"?(U=w+oe-I,S=Position.Top,O=true):(U=w+(oe-I)/2,S=Position.Top);for(let te=0;te<f;te++){let V=O?f-te:te+1,A=Ke(V),re=fe(V),T=`fiber-${V}`,F=s.find(Ve=>Ve.source===r&&Ve.sourceHandle===T||Ve.target===r&&Ve.targetHandle===T),be=null;F&&(F.data?.isRibbon||F.data?.ribbonFiberIds&&Array.isArray(F.data.ribbonFiberIds)?be="#808080":be=F.data?.color||null);let q=U+te*(H+k),he=w,ue={position:"absolute",left:`${q}px`,top:`${he}px`,width:H,height:H,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":be||(d?"#808080":re)};be?ue.backgroundColor=be:d?ue.backgroundColor="#808080":A.backgroundImage?ue["--fiber-bg-image"]=A.backgroundImage:ue.backgroundColor=re,Z.push(jsxs(nt.Fragment,{children:[jsx(Handle,{id:T,type:"target",position:S,className:"tube-fiber-handle",isConnectable:true,style:ue,"data-fiber-idx":V,"data-fiber-color":be||(d?"#808080":re)}),jsx(Handle,{id:T,type:"source",position:S,className:"tube-fiber-handle",isConnectable:true,style:ue,"data-fiber-idx":V,"data-fiber-color":be||(d?"#808080":re)})]},`fiber-${V}`));}return Z},[f,i,z,s,r,H,k,w,R,I,d]);return jsxs("div",{style:{width:z,height:M,borderRadius:4,background:"#111827",border:`${R}px solid ${o?"#3b82f6":m}`,position:"relative",boxShadow:o?`0 0 0 ${R}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:w,boxSizing:"border-box",overflow:"visible"},children:[X,jsx(Handle,{id:c,type:"target",position:P,isConnectable:true,className:"tube-connection-handle",style:_,"data-tube-idx":a,"data-tube-color":m,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsx(Handle,{id:c,type:"source",position:P,isConnectable:true,className:"tube-connection-handle",style:_,"data-tube-idx":a,"data-tube-color":m,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var Uo=({data:e,selected:o})=>{let{fiberCount:r,cableId:n="CBL-002",label:a,color:i,rotation:d}=e||{},s=nt.useRef(null);nt.useEffect(()=>{if(s.current){let S=typeof d=="number"?d:0;s.current.style.transform=`rotate(${S}deg)`,s.current.style.transformOrigin="center center";}},[d]);let c=Math.max(1,Math.min(24,Number(r)||12)),l=10,h=2,u=6,m=u+l+4,f=60,H=Math.max(120,c*(l+h)+u*2),w=a??`${c}f Cable`,R=n?`Cable ID ${n}`:void 0,M=fe(1),I=i||M,z=o?"#3b82f6":I,P=typeof d=="number"?d:0,x=S=>{let O=(S%360+360)%360;return O>=315||O<45?Position.Top:O>=45&&O<135?Position.Right:O>=135&&O<225?Position.Bottom:Position.Left},W=()=>{let S=[],O=x(P);for(let te=0;te<c;te++){let V=te+1,A=Ke(V),re=fe(V),T=u+te*(l+h),F=-5,be=A.backgroundImage?A.backgroundImage:re,q={position:"absolute",left:`${T}px`,top:`${F}px`,width:l,height:l,borderRadius:"50%",border:"none",background:be,backgroundColor:re,zIndex:10,cursor:"pointer","--fiber-bg":re};A.backgroundImage&&(q["--fiber-bg-image"]=A.backgroundImage);let he=`fiber-${V}`;S.push(jsxs(nt.Fragment,{children:[jsx(Handle,{id:he,type:"target",position:O,className:"tube-fiber-handle",isConnectable:true,style:q,"data-fiber-idx":V,"data-fiber-color":re}),jsx(Handle,{id:he,type:"source",position:O,className:"tube-fiber-handle",isConnectable:true,style:q,"data-fiber-idx":V,"data-fiber-color":re})]},`fiber-${V}`));}return S},C="cable-button",D=8,$={width:D,height:D,borderRadius:"50%",background:I,backgroundColor:I,border:`1px solid ${I}`,cursor:"pointer",zIndex:10},_=2,Z=(S=>{let O=(S%360+360)%360;return O>=315||O<45?Position.Bottom:O>=45&&O<135?Position.Left:O>=135&&O<225?Position.Top:Position.Right})(P),oe={width:H,height:f,position:"relative",transform:`rotate(${P}deg)`,transformOrigin:"center center","--rotation":`${P}deg`},U={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${_}px solid ${z}`,boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:u,paddingTop:m,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:oe,children:jsxs("div",{style:U,children:[W(),jsx(Handle,{id:C,type:"source",position:Z,className:"cable-button-handle",isConnectable:true,style:$,"data-handle-type":"cable-button","data-cable-color":I}),jsx(Handle,{id:C,type:"target",position:Z,className:"cable-button-handle",isConnectable:true,style:$,"data-handle-type":"cable-button","data-cable-color":I}),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}),R&&jsx("div",{style:{fontSize:10,opacity:.8},children:R})]})]})})};var Yo=({data:e,selected:o})=>{let{tubeCount:r=12,fibersPerTube:n=12,fiberCount:a,cableId:i="CBL-002",label:d,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(r)||12)),h=Math.max(1,Number(s)||1),u=14,m=10,f=3,H=6,k=H+m+4,w=60,R=Math.max(120,l*(u+f)+H*2),M=a??l*(Number(n)||12),I=d??`${M}f Cable`,z=i?`Cable ID ${i}`:void 0,P=fe(h),x=c||P,W=o?"#3b82f6":x,C=()=>{let Z=[];for(let oe=0;oe<l;oe++){let U=h+oe,S=Ke(U),O=fe(U),te=H+oe*(u+f),V=-5,A=S.backgroundImage?S.backgroundImage:O,re={position:"absolute",left:`${te}px`,top:`${V}px`,width:u,height:m,borderRadius:6,border:"none",background:A,backgroundColor:O,zIndex:10,cursor:"pointer","--fiber-bg":O};S.backgroundImage&&(re["--fiber-bg-image"]=S.backgroundImage);let T=`tube-${U}`;Z.push(jsxs(nt.Fragment,{children:[jsx(Handle,{id:T,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:re,"data-fiber-idx":U,"data-tube-idx":U,"data-tube-color":O}),jsx(Handle,{id:T,type:"source",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:re,"data-fiber-idx":U,"data-tube-idx":U,"data-tube-color":O})]},`tube-${U}`));}return Z},D="cable-button",$=8,_={width:$,height:$,borderRadius:"50%",background:x,backgroundColor:x,border:`1px solid ${x}`,cursor:"pointer",zIndex:10};return jsxs("div",{style:{width:R,height:w,borderRadius:4,background:"#111827",border:`2px solid ${W}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:H,paddingTop:k,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[C(),jsx(Handle,{id:D,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":x}),jsx(Handle,{id:D,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":x}),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:I}),z&&jsx("div",{style:{fontSize:10,opacity:.8},children:z})]})]})};var Xo=({data:e,selected:o,id:r})=>{let{connector:n="LC",couplerFiberCount:a,label:i,portLabelsLeft:d,portLabelsRight:s}=e||{},c=useEdges(),l=typeof a=="number"&&[1,2,4].includes(a)?a:2,h=Math.max(1,Math.min(4,l)),u=9,m=3,f=3,H=60,k=30,w=h*u+(h-1)*m,R=Math.max(k,w+f*2),M=Math.max(H,80),I=(x,W)=>{let C=`${x}-${W+1}`;return c.find($=>$.source===r&&$.sourceHandle===C||$.target===r&&$.targetHandle===C)?.data?.color||"#555"},z=x=>{let W=[],C=x==="left"?Position.Left:Position.Right,D=x==="left"?d:s;for(let $=0;$<h;$++){let _=$+1,X=`${x}-${_}`,Z=I(x,$),S=f+(R-w)/2+$*(u+m),O={position:"absolute",left:x==="left"?-5:void 0,right:x==="right"?-5:void 0,top:`${S}px`,width:u,height:u,borderRadius:"50%",border:"none",background:Z,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};W.push(jsxs(nt.Fragment,{children:[jsx(Handle,{id:X,type:"target",position:C,isConnectable:true,style:O}),jsx(Handle,{id:X,type:"source",position:C,isConnectable:true,style:O})]},X)),D&&D[$]&&W.push(jsx("div",{style:{position:"absolute",left:x==="left"?-30:void 0,right:x==="right"?-30:void 0,top:`${S}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:x==="left"?"right":"left",width:"25px"},children:D[$]},`${X}-label`));}return W},P=i||`${n}-${h}f`;return jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:M,height:R,borderRadius:4,border:`2px solid ${o?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:o?"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:[z("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:P})}),z("right")]})};var rt=32,Jt=30,ci=24,li=80,Kt=400,qt=300,Yr=2,ot=8,Xr=120;function jo(e){let{couplerFiberCount:o}=e.data||{},r=typeof o=="number"&&[1,2,4].includes(o)?o:2,n=Math.max(1,Math.min(4,r)),a=7,i=3,d=3,s=60,c=30,l=n*a+(n-1)*i,h=Math.max(c,l+d*2);return {width:Math.max(s,80),height:h}}function Qt(e){let{fibersPerTube:o=12}=e.data||{},r=Math.max(1,Math.min(24,Number(o)||12)),n=14,a=4,i=1,d=2,s=20,c=r*n+(r-1)*a;return {width:Math.max(60,c+i*2+d*2),height:s}}function jr(e){return {width:et,height:0}}function Ht(e){return e.type==="coupler"?jo(e):e.type==="tube"?Qt(e):e.type==="splice-tray"?jr():{width:80,height:30}}function Gr(e){return e.data?.panelWidth||Kt}function pi(e){return e.data?.panelHeight||qt}function Zr(e){return Gr(e)-Yr*2-ot*2}function ui(e,o){return Zr(e)-o}function Kr(e,o=Jt){return Math.floor(e/o)+1}function qr(e,o=Jt){return (e-1)*o}function gi(e,o,r){let n=Jt,a=Kr(r.y,n),i=qr(a,n);return {x:r.x,y:i,slotPosition:a}}function Go(e,o){if(o.length===0)return {width:e.data?.panelWidth||Kt,height:e.data?.panelHeight||qt};let r=o.some(l=>l.type==="tube"),n=o.some(l=>l.type==="splice-tray"),a=o.some(l=>l.type==="coupler"),i,d=5;if(r&&n&&a){let l=0,h=0;for(let f of o)if(f.type==="tube"){let H=Qt(f);H.width>l&&(l=H.width);}else if(f.type==="coupler"){let H=jo(f);H.width>h&&(h=H.width);}let u=l+Xr+et+h+d,m=0;i=m+u+m;}else {let l=0;for(let u of o){let m=Ht(u),f=(u.position?.x||0)+m.width;f>l&&(l=f);}i=l+4;}i=Math.max(e.data?.panelWidth||Kt,i);let s=rt;for(let l of o){let h=Ht(l),u=(l.position?.y||0)+h.height;u>s&&(s=u);}let c=Math.max(e.data?.panelHeight||qt,s+ot);return {width:i,height:c}}function Jr(e,o,r){if(e===0)return 0;if(e===1)return o;let n=e*o,a=r-n,i=Math.max(5,a/(e-1));return o+i}function fi(e,o,r){return Jr(e,o,r)}var Br=20,Ur=400,Vr=300;function Qr(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||Ur,height:e.data?.closureHeight||e.data?.panelHeight||Vr};let r=o.some(c=>c.type==="tube"),n=o.some(c=>c.type==="splice-tray"),a,i=5;if(r&&n){let c=0,l=0,h=0,u=o.filter(f=>f.type==="tube"),m=o.filter(f=>f.type==="splice-tray");if(u.length>0&&m.length>0){let f=m.map(k=>k.position?.x||0),H=f.reduce((k,w)=>k+w,0)/f.length;for(let k of u){let w=Qt(k);(k.position?.x||0)<H?w.width>c&&(c=w.width):w.width>l&&(l=w.width);}m.length>0&&(h=et),a=ot+c+Br+h+Br+l+i;}else {let f=0;for(let H of o){let k=Ht(H),w=(H.position?.x||0)+k.width;w>f&&(f=w);}a=f+ot+i;}}else {let c=0;for(let l of o){let h=Ht(l),u=(l.position?.x||0)+h.width;u>c&&(c=u);}a=c+ot+i;}a=Math.max(e.data?.closureWidth||e.data?.panelWidth||Ur,a);let d=rt;for(let c of o){let l=Ht(c),h=(c.position?.y||0)+l.height;h>d&&(d=h);}let s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Vr,d+ot);return {width:a,height:s}}var qo=({data:e,selected:o,id:r})=>{let{label:n="Patch Panel",header:a,panelWidth:i,panelHeight:d}=e||{},{getNodes:s,setNodes:c}=useReactFlow(),l=useRef(false),h=useRef([]),u=useMemo(()=>{let I=s().filter(z=>z.parentId===r);return (I.length!==h.current.length||I.some((z,P)=>z.id!==h.current[P]?.id))&&(h.current=I),h.current},[s,r]),m=useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),f=useMemo(()=>i&&d?{width:i,height:d}:u.length===0?{width:i||400,height:d||300}:Go(m,u),[u,m,i,d]);useEffect(()=>{if(i&&d||l.current)return;let M=i,I=d,z=Math.abs((M||0)-f.width),P=Math.abs((I||0)-f.height);(z>1||P>1)&&(l.current=true,c(x=>x.map(W=>W.id===r?{...W,data:{...W.data,panelWidth:f.width,panelHeight:f.height}}:W)),setTimeout(()=>{l.current=false;},0));},[r,f.width,f.height,i,d,c]);let H=f.width,k=f.height,w=rt,R=a||n;return jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${H}px`,height:`${k}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"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:R})}),jsx("div",{style:{position:"absolute",top:w,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var er=({data:e,selected:o,id:r})=>{let{label:n="Closure",header:a,closureWidth:i,closureHeight:d,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:h}=useReactFlow(),u=useRef(false),m=useRef([]),f=useMemo(()=>{let x=l().filter(W=>W.parentId===r);return (x.length!==m.current.length||x.some((W,C)=>W.id!==m.current[C]?.id))&&(m.current=x),m.current},[l,r]),H=useMemo(()=>({id:r,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||s,closureHeight:d||c}}),[r,e,i,d,s,c]),k=useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:f.length===0?{width:i||s||400,height:d||c||300}:Qr(H,f),[f,H,i,d,s,c]);useEffect(()=>{if(i&&d||s&&c||u.current)return;let P=i||s,x=d||c,W=Math.abs((P||0)-k.width),C=Math.abs((x||0)-k.height);(W>1||C>1)&&(u.current=true,h(D=>D.map($=>$.id===r?{...$,data:{...$.data,closureWidth:k.width,closureHeight:k.height}}:$)),setTimeout(()=>{u.current=false;},0));},[r,k.width,k.height,i,d,s,c,h]);let w=k.width,R=k.height,M=rt,I=a||n,z=w/2;return jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${z}px ${z}px 12px 12px`,padding:0,width:`${w}px`,height:`${R}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"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:`${M}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${z}px ${z}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:I})}),jsx("div",{style:{position:"absolute",top:M,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var or=({data:e,selected:o,id:r})=>{let{label:n,splitterType:a="splitter",inputCount:i=1,outputCount:d=8}=e||{},s=useEdges(),c=n||(a==="WDM"?"WDM":"Splitter"),l=9,h=3,u=3,m=50,f=30,H=Math.min(Math.max(i||1,1),2),k=H*l+(H-1)*h,w=Math.min(d||8,48),R=w*l+(w-1)*h,M=Math.max(k,R),I=Math.max(f,M+u*2),z=Math.max(m,50),P=oe=>s.find(S=>S.source===r&&S.sourceHandle===oe||S.target===r&&S.targetHandle===oe)?.data?.color||"#555",x=()=>{let oe=[],U=u+(I-k)/2;for(let S=0;S<H;S++){let O=`input-${S+1}`,te=U+S*(l+h),V=P(O),A={position:"absolute",left:-5,top:`${te}px`,width:l,height:l,borderRadius:"50%",border:"none",background:V,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};oe.push(jsxs(nt.Fragment,{children:[jsx(Handle,{id:`${O}-target`,type:"target",position:Position.Left,isConnectable:true,style:A}),jsx(Handle,{id:`${O}-source`,type:"source",position:Position.Left,isConnectable:true,style:A})]},O));}return oe},W=()=>{let oe=[],U=u+(I-R)/2;for(let S=0;S<w;S++){let O=`output-${S+1}`,te=U+S*(l+h),V=P(O),A={position:"absolute",right:-5,top:`${te}px`,width:l,height:l,borderRadius:"50%",border:"none",background:V,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};oe.push(jsxs(nt.Fragment,{children:[jsx(Handle,{id:`${O}-target`,type:"target",position:Position.Right,isConnectable:true,style:A}),jsx(Handle,{id:`${O}-source`,type:"source",position:Position.Right,isConnectable:true,style:A})]},O));}return oe},C=Math.max(k+u*4,f*.6),D=(I-C)/2,$=D+C,_=0,X=I,Z=o?"#3b82f6":"#4b5563";return jsxs("div",{className:`trapezoid-node ${o?"selected":""}`,style:{width:z,height:I,position:"relative",background:"transparent",boxShadow:o?"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:[jsx("svg",{width:z,height:I,viewBox:`0 0 ${z} ${I}`,style:{position:"absolute",top:0,left:0,width:`${z}px`,height:`${I}px`,pointerEvents:"none",zIndex:0},children:jsx("polygon",{points:`0,${D} 0,${$} ${z},${X} ${z},${_}`,fill:"#1f2937",stroke:Z,strokeWidth:"2"})}),x(),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})}),W()]})};var rn=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",lt=(e,o)=>rn(e)||rn(o),ee=(e,o)=>o?e?.type==="fibre-split"?o.replace(/-(source|target)$/i,""):o:o||"";function ki(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let r=o.nodes.find(T=>T.id===e.source),n=o.nodes.find(T=>T.id===e.target),a=ee(r,e.sourceHandle),i=ee(n,e.targetHandle),d=o.edges.some(T=>T.source===e.source?ee(r,T.sourceHandle)===a:T.target===e.source?ee(r,T.targetHandle)===a:false),s=o.edges.some(T=>T.target===e.target?ee(n,T.targetHandle)===i:T.source===e.target?ee(n,T.sourceHandle)===i:false),c=lt(r,n);if((d||s)&&!c)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=(T,F)=>(T?.type==="tube"||T?.type==="cable")&&!!F&&F.startsWith("fiber-"),h=(T,F)=>(T?.type==="tube"||T?.type==="multi-tube-cable")&&!!F&&F.startsWith("tube-"),u=(T,F)=>T?.type==="multi-tube-cable"&&!!F&&F.startsWith("tube-"),m=(T,F)=>T?.type==="tube"&&!!F&&F.startsWith("tube-"),f=(T,F)=>(T?.type==="cable"||T?.type==="multi-tube-cable")&&F==="cable-button",H=(T,F)=>T?.type==="splice"&&(F==="left"||F==="right"),k=(T,F)=>T?.type==="coupler"&&!!F&&(F.startsWith("left-")||F.startsWith("right-")),w=(T,F)=>{if(T?.type!=="fibre-split"||!F)return false;let be=ee(T,F);return be.startsWith("input-")||be.startsWith("output-")};if(!c)return {valid:true};if(r?.type==="splice"&&n?.type==="splice"){let T=r.data?.mode==="ribbon",F=n.data?.mode==="ribbon";if(T!==F)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let R=l(r,e.sourceHandle),M=l(n,e.targetHandle),I=H(r,e.sourceHandle),z=H(n,e.targetHandle),P=k(r,e.sourceHandle),x=k(n,e.targetHandle),W=w(r,e.sourceHandle),C=w(n,e.targetHandle),D=f(r,e.sourceHandle),$=f(n,e.targetHandle),_=u(r,e.sourceHandle),X=u(n,e.targetHandle),Z=m(r,e.sourceHandle),oe=m(n,e.targetHandle),U=h(r,e.sourceHandle),S=h(n,e.targetHandle);return R&&z||M&&I||(I&&(x||C)||z&&(P||W))||(P&&(x||C||z)||x&&(P||W||I))||D&&$||(_&&oe||X&&Z)?{valid:true}:U&&S?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function oo(e,o){if(!o)return;let r=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,n=o.data??{},a=n.handleSideMap;if(a&&a[r])return a[r];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 i=Array.isArray(n.ports)?n.ports:[],d=Array.isArray(n.rearPorts)?n.rearPorts:[];if(r.startsWith("pwr")||r.includes("power"))return "rear";for(let c of i)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "front";for(let c of d)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "rear"}function rr(e={},o={}){let r={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},n=new Set;return {getState:()=>r,setState:u=>{r={...r,...u},n.forEach(m=>m(r));},subscribe:u=>(n.add(u),()=>n.delete(u)),selectEdgeZIndex:u=>{let m=r.nodes.find(P=>P.id===u.target);if(!m||m.type!=="device")return 1e3;let f=m.data?.view||"front",H=oo(u.targetHandle||"",m);if(H)return f===H?1e3:500;let k=(u.targetHandle||"").toString(),w=k.toLowerCase(),R=w.startsWith("pwr")||w.startsWith("power"),M=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),I=/^[A-Z0-9]+-\d+$/i.test(k)&&!w.startsWith("pwr")&&!w.startsWith("power"),z=M||I;return R?f==="rear"?1e3:500:z?f==="front"?1e3:500:1e3},validateConnection:u=>(o.validateConnection||ki)(u,r),selectNodeById:u=>r.nodes.find(m=>m.id===u),selectConnectedEdges:u=>r.edges.filter(m=>m.source===u||m.target===u)}}function vi(e){let o=a=>e.subscribe(a),r=()=>e.getState();return useSyncExternalStore(o,r,r)}function ir(e){let o=n=>e.subscribe(n),r=()=>e.getState().nodes;return useSyncExternalStore(o,r,r)}function ar(e){let o=n=>e.subscribe(n),r=()=>e.getState().edges;return useSyncExternalStore(o,r,r)}function nn(e){return e.selectEdgeZIndex}function an(e){let o=e.data.rackWidthPx||300,r=(e.data.uHeight||42)*20,n=e.position.x,a=e.position.x+o,i=e.position.y,d=e.position.y+r;return {left:n,right:a,top:i,bottom:d}}function ro(e,o){let r=an(o);return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom}function no(e,o){let r=null,n=1/0;for(let a of o){if(!ro(e,a))continue;let i=Math.sqrt(Math.pow(e.x-a.position.x,2)+Math.pow(e.y-a.position.y,2));i<n&&(n=i,r=a);}return r}function we(e){let{edges:o,connection:r,edgeType:n,selectEdgeZIndex:a,findBy:i,data:d}=e,s=i==="source"?r.sourceHandle:r.targetHandle,c=i==="source"?r.source:r.target;if(!s||!c)return null;let l=o.find(k=>i==="source"?k.source===c&&k.sourceHandle===s:k.target===c&&k.targetHandle===s);if(!l)return null;let h=o.filter(k=>k.id!==l.id),u=addEdge(r,h),m=u[u.length-1],f=a({...r,id:m.id,type:n}),H={...m,type:n,zIndex:f,style:{...m.style,zIndex:f},data:d!==void 0?d:m.data};return [...u.slice(0,-1),H]}function cn(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var ke=({type:e,children:o})=>{let r=nt.useRef(null),n=nt.useCallback(a=>{if(r.current=a,a){let i=a.parentElement,d=0;for(;i&&!i.classList.contains("react-flow__node")&&d<10;)i=i.parentElement,d++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return nt.useEffect(()=>{if(r.current){let a=r.current.parentElement,i=0;for(;a&&!a.classList.contains("react-flow__node")&&i<10;)a=a.parentElement,i++;a&&a.classList.contains("react-flow__node")&&a.setAttribute("data-type",e);}},[e]),jsx("div",{ref:n,style:{width:"100%",height:"100%"},children:o})},ln=(e,o,r)=>({rack:n=>jsx(ke,{type:"rack",children:jsx(xo,{...n,onViewChange:e,onRackFaceChange:o,isDragOver:r?r()===n.id:false})}),fiber:n=>jsx(ke,{type:"fiber",children:jsx(wo,{...n})}),device:n=>jsx(ke,{type:"device",children:jsx(Ro,{...n})}),"vertical-pdu":n=>jsx(ke,{type:"vertical-pdu",children:jsx(To,{...n})}),splice:n=>jsx(ke,{type:"splice",children:jsx($o,{...n})}),"splice-tray":n=>jsx(ke,{type:"splice-tray",children:jsx(Mo,{...n})}),tube:n=>jsx(ke,{type:"tube",children:jsx(Lo,{...n})}),cable:n=>jsx(ke,{type:"cable",children:jsx(Uo,{...n})}),"multi-tube-cable":n=>jsx(ke,{type:"multi-tube-cable",children:jsx(Yo,{...n})}),coupler:n=>jsx(ke,{type:"coupler",children:jsx(Xo,{...n})}),"patch-panel":n=>jsx(ke,{type:"patch-panel",children:jsx(qo,{...n})}),closure:n=>jsx(ke,{type:"closure",children:jsx(er,{...n})}),"fibre-split":n=>jsx(ke,{type:"fibre-split",children:jsx(or,{...n})})}),Wi={fiber:vo,power:Ho,smoothstep:Pr,step:Rr,"thick-cable":Dr},zi=({nodes:e,edges:o,initialNodes:r,initialEdges:n,onNodesChange:a,onEdgesChange:i,store:d,debug:s,onNodeClick:c,onEdgeClick:l,onViewChange:h,onRackFaceChange:u,className:m,style:f,alignRacksToBottom:H,colorMode:k="dark",onInit:w,onFlowMethods:R,showDownloadButton:M=false,downloadButtonPosition:I="top-right",downloadButtonText:z="Download Image",downloadButtonStyle:P,useSmoothstepEdgesForTubes:x=false,connectOnClick:W=true,panOnDrag:C=true,panOnScroll:D=true,zoomOnScroll:$=true})=>{let _=useCallback((t,p)=>{let g=new Map,b=[],N=[],v=(E,j)=>!E||!j?false:!!(E.startsWith("tube-")||j.type==="splice"&&(E==="left"||E==="right")||E==="cable-button");for(let E of t){if(!E.source||!E.target||!E.sourceHandle||!E.targetHandle){s&&console.warn("Invalid edge skipped (missing source/target/handles):",E);continue}let j=p.find(ve=>ve.id===E.source),Y=p.find(ve=>ve.id===E.target),ce=`${E.source}:${E.sourceHandle}`,ie=g.get(ce),ye=v(E.sourceHandle,j),le=`${E.target}:${E.targetHandle}`,de=g.get(le),J=v(E.targetHandle,Y);if(ie&&!ye){s&&console.warn("Duplicate connection detected on source handle, removing:",{handle:ce,existingEdge:ie.id,duplicateEdge:E.id}),N.push(E);continue}if(de&&!J){s&&console.warn("Duplicate connection detected on target handle, removing:",{handle:le,existingEdge:de.id,duplicateEdge:E.id}),N.push(E);continue}b.push(E),ie||g.set(ce,E),de||g.set(le,E);}return s&&N.length>0&&console.log(`Filtered ${N.length} duplicate edge(s) from initial edges`),b},[s]),X=Array.isArray(e)&&Array.isArray(o),Z=nt.useMemo(()=>X?e||[]:r||e||[],[X,e,r]),oe=nt.useMemo(()=>X?o||[]:n||o||[],[X,o,n]),U=nt.useMemo(()=>_(oe,Z),[oe,Z,_]),S=nt.useMemo(()=>d||rr({nodes:Z,edges:U,debug:s}),[d,X,s,U]),O=ir(S),te=ar(S),[V,A,re]=useNodesState(O),[T,F,be]=useEdgesState(te),q=nn(S),he=useRef(null),[ue,Ve]=useState(false);useEffect(()=>{let t=()=>{Ve(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]);let{toObject:Pt,setViewport:Ct,setNodes:Et,setEdges:_e,getNodes:Fe,getEdges:cr,fitView:io}=useReactFlow();useEffect(()=>{R&&R({toObject:Pt,setViewport:Ct,setNodes:t=>{Et(t),S.setState({nodes:t});},setEdges:t=>{_e(t),S.setState({edges:t});},toImage:t=>he.current?toPng(he.current,t):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>Fe(),getEdges:()=>cr(),fitView:t=>{if(t?.nodes&&Array.isArray(t.nodes)&&t.nodes.length>0){let p=t.nodes.map(N=>Fe().find(v=>v.id===N)).filter(N=>N!==void 0),{nodes:g,...b}=t;io({...b,nodes:p});}else {let{nodes:p,...g}=t||{};io(g);}}});},[R,Pt,Ct,Et,_e,S,io,Fe,cr]);let mn=useCallback(()=>{if(!he.current){s&&console.error("ReactFlow wrapper ref is not available");return}toPng(he.current,{filter:t=>!(t?.classList?.contains("react-flow__minimap")||t?.classList?.contains("react-flow__controls")||t?.classList?.contains("react-flow__attribution")||t?.classList?.contains("download-button")||t?.tagName==="BUTTON"),backgroundColor:k==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(t=>{let p=document.createElement("a");p.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,p.href=t,p.click();}).catch(t=>{s&&console.error("Error downloading image:",t);});},[k,s]),[lr,Rt]=useState(null),pr=useRef(null),ur=useRef(h),gr=useRef(u);useEffect(()=>{ur.current=h;},[h]),useEffect(()=>{gr.current=u;},[u]),useEffect(()=>{pr.current=lr;},[lr]);let ao=useCallback((t,p)=>{ur.current?.(t,p);},[]),so=useCallback((t,p)=>{gr.current?.(t,p);},[]),co=useCallback(()=>pr.current,[]),fr=useRef(ln(ao,so,co));useEffect(()=>{fr.current=ln(ao,so,co);},[ao,so,co]);let We=useRef(V);useEffect(()=>{We.current=V;},[V]);let K=useRef(T);useEffect(()=>{K.current=T;},[T]),useEffect(()=>{A(O);},[O,A]),useEffect(()=>{F(te);},[te,F]),useEffect(()=>{if(X&&o){let t=_(o,e||[]);t.length!==o.length&&(s&&console.warn(`Controlled edges had ${o.length-t.length} duplicate(s) removed`),i?.(t));}},[X,o,e,_,i,s]),useEffect(()=>{X&&S.setState({nodes:e||[]});},[X,e,S]),useEffect(()=>{X&&S.setState({edges:o||[]});},[X,o,S]),useEffect(()=>{if(!H||!V||V.length===0)return;let t=V.filter(Y=>Y.type==="rack");if(t.length===0)return;let p=t.map(Y=>{let ie=Y.data?.uHeight||42,ye=60+ie*20;return (Y.position?.y||0)+ye}),g=Math.min(...p),b=Math.max(...p);if(b-g<20)return;let v=b,E=V.map(Y=>{if(Y.type!=="rack")return Y;let ie=Y.data?.uHeight||42,ye=60+ie*20,le=(Y.position?.y||0)+ye,de=v-le;return Math.abs(de)<5?Y:{...Y,position:{x:Y.position?.x||0,y:(Y.position?.y||0)+de}}});E.some((Y,ce)=>Y.position!==V[ce].position)&&A(E);},[H,V,A]);let lo=useRef(new Map);useEffect(()=>{let t=new Map;V.forEach(p=>{t.set(p.id,p);}),lo.current=t;},[V]);let se=useCallback(t=>lo.current.get(t),[]),gt=useCallback((t,p)=>{if(!t||!p)return;let g=se(t);if(!g)return;let b=p.replace(/-(source|target)$/i,"");if(g.type==="fibre-split"&&b.startsWith("output-")){let v=K.current.filter(E=>E.target===t&&(E.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(v.length>0){let E=v[0]?.data?.color;if(E)return {color:E}}}if((g.type==="tube"||g.type==="cable")&&p.startsWith("fiber-")){let v=p.replace("fiber-",""),E=parseInt(v,10);if(E>=1&&E<=24){let j=ko(E),Y=E>12;return {color:j,striped:Y}}}if((g.type==="multi-tube-cable"||g.type==="tube")&&p.startsWith("tube-")){let v=p.replace("tube-",""),E=parseInt(v,10);if(E>=1&&E<=24){let j=fe(E),Y=E>12;return {color:j,striped:Y}}}let N=g.data;if(N.color)return {color:N.color}},[se]),br=useRef(new Map);useEffect(()=>{F(t=>{let p=false,g=t.map(b=>{let N=q(b);return br.current.get(b.id)!==N?(p=true,br.current.set(b.id,N),{...b,zIndex:N,style:{...b.style,zIndex:N}}):b});return p?g:t});},[V,F,q]),useEffect(()=>{let t=V.map(g=>{if(g.type==="coupler"&&g.parentId){let b=se(g.parentId);if(b&&(b.type==="patch-panel"||b.type==="closure")&&(!g.extent||g.extent!=="parent"))return {...g,extent:"parent"}}if(g.type==="splice"&&g.parentId&&g.data.holderPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let b=se(g.parentId);if(b&&b.type==="splice-tray"){let N=g.data.mode==="ribbon",v=kt(b,g.data.holderPosition,N);return {...g,position:v}}}if(g.type==="device"&&g.parentId&&g.data.uPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let b=se(g.parentId);if(b){let N=at(b,g.data.uPosition);return {...g,position:N}}}return g});t.some((g,b)=>{let N=V[b];return g.extent!==N.extent||g.position?.x!==N.position?.x||g.position?.y!==N.position?.y})&&A(t);},[V,A,se]);let yn=useCallback(t=>{let p=t.map(g=>{if(g.type==="position"&&g.position){let b=se(g.id);if(b&&b.type==="coupler"&&b.parentId){let N=se(b.parentId);if(N&&(N.type==="patch-panel"||N.type==="closure")){if(!b.extent||b.extent!=="parent"){let v={...b,extent:"parent"};A(E=>E.map(j=>j.id===b.id?v:j));}return {...g,position:b.position||{x:0,y:0}}}}if(b&&(b.type==="tube"||b.type==="splice-tray")&&b.parentId){let N=se(b.parentId);if(N&&N.type==="closure"){if(!b.extent||b.extent!=="parent"){let v={...b,extent:"parent"};A(E=>E.map(j=>j.id===b.id?v:j));}return {...g,position:b.position||{x:0,y:0}}}}if(b&&b.type==="splice"&&b.parentId){let N=se(b.parentId);if(N&&N.type==="splice-tray"){let v=Wo(b,N,g.position,We.current);if(v.holderPosition!==void 0){let E={...b,data:{...b.data,holderPosition:v.holderPosition}};A(j=>j.map(Y=>Y.id===b.id?E:Y));}return {...g,position:{x:v.x,y:v.y}}}}if(b&&b.type==="device"&&b.parentId){let N=se(b.parentId);if(N){let v=mo(b,N,g.position,We.current);if(v.uPosition!==void 0){let E={...b,data:{...b.data,uPosition:v.uPosition}};A(j=>j.map(Y=>Y.id===b.id?E:Y));}return {...g,position:{x:v.x,y:v.y}}}}if(b&&b.type==="device"&&b.parentId){let N=se(b.parentId);if(N){let v=N;if(!ro(g.position,v)){let E=g.position.x+v.position.x,j=g.position.y+v.position.y,Y={...b,parentId:void 0,extent:void 0,data:{...b.data,uPosition:void 0}};return A(ce=>ce.map(ie=>ie.id===b.id?Y:ie)),{...g,position:{x:E,y:j}}}}}}return g});re(p);},[re,A,se]),xn=useCallback((t,p)=>{Rt(null);},[]),wn=useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let b=We.current.filter(v=>v.type==="rack").map(v=>v),N=no(p.position,b);Rt(N?.id??null);}else Rt(null);},[]),Nn=useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let b=We.current.filter(v=>v.type==="rack").map(v=>v),N=no(p.position,b);if(N){let v=p.position.x-N.position.x,E=p.position.y-N.position.y,j={...p,parentId:N.id,extent:"parent",position:{x:v,y:E},data:{...p.data,uPosition:1}},Y=We.current.map(ce=>ce.id===p.id?j:ce);A(Y),X||S.setState({nodes:Y});}}Rt(null);},[A,X,S]),kn=useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let p=se(t.source),g=se(t.target),b=ee(p,t.sourceHandle),N=ee(g,t.targetHandle),v=K.current.some(B=>B.source===t.source?ee(p,B.sourceHandle)===b:B.target===t.source?ee(p,B.targetHandle)===b:false),E=K.current.some(B=>B.target===t.target?ee(g,B.targetHandle)===N:B.source===t.target?ee(g,B.sourceHandle)===N:false);v&&s&&console.log("Connection will replace: Source handle already connected",{source:t.source,sourceHandle:t.sourceHandle,existingEdges:K.current.filter(B=>B.source===t.source&&B.sourceHandle===t.sourceHandle||B.target===t.source&&B.targetHandle===t.sourceHandle)}),E&&s&&console.log("Connection will replace: Target handle already connected",{target:t.target,targetHandle:t.targetHandle,existingEdges:K.current.filter(B=>B.target===t.target&&B.targetHandle===t.targetHandle||B.source===t.target&&B.sourceHandle===t.targetHandle)});let j=lt(p,g);if((v||E)&&!j)return s&&console.log("Connection rejected: Non-fiber handle already connected",t),false;if(!j)return true;if(p?.type==="splice"&&g?.type==="splice"){let B=p.data?.mode==="ribbon",ae=g.data?.mode==="ribbon";if(B!==ae)return s&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",t),false}let Y=(B,ae)=>(B?.type==="tube"||B?.type==="cable")&&!!ae&&ae.startsWith("fiber-"),ce=(B,ae)=>(B?.type==="tube"||B?.type==="multi-tube-cable")&&!!ae&&ae.startsWith("tube-"),ie=(B,ae)=>B?.type==="multi-tube-cable"&&!!ae&&ae.startsWith("tube-"),ye=(B,ae)=>B?.type==="tube"&&!!ae&&ae.startsWith("tube-"),le=(B,ae)=>(B?.type==="cable"||B?.type==="multi-tube-cable")&&ae==="cable-button",de=(B,ae)=>B?.type==="splice"&&(ae==="left"||ae==="right"),J=(B,ae)=>B?.type==="coupler"&&!!ae&&(ae.startsWith("left-")||ae.startsWith("right-")),ve=(B,ae)=>{if(B?.type!=="fibre-split"||!ae)return false;let xr=ae.replace(/-(source|target)$/i,"");return xr.startsWith("input-")||xr.startsWith("output-")},Tt=Y(p,t.sourceHandle),Ye=Y(g,t.targetHandle),ne=de(p,t.sourceHandle),Xe=de(g,t.targetHandle),je=J(p,t.sourceHandle),It=J(g,t.targetHandle),ft=ve(p,t.sourceHandle),Dt=ve(g,t.targetHandle),go=le(p,t.sourceHandle),$t=le(g,t.targetHandle),fo=ie(p,t.sourceHandle),bo=ie(g,t.targetHandle),ho=ye(p,t.sourceHandle),y=ye(g,t.targetHandle),L=ce(p,t.sourceHandle),Q=ce(g,t.targetHandle);return Tt&&Xe||Ye&&ne||(ne&&(It||Dt)||Xe&&(je||ft))||(je&&(It||Dt||Xe)||It&&(je||ft||ne))||go&&$t||(fo&&y||bo&&ho)?true:L&&Q?(s&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",t),false):(s&&console.log("Connection rejected: Connection not allowed by fiber rules",t),false)},[se,s]),vn=useCallback(t=>{s&&console.log("onConnect called:",t);let p=se(t.source),g=se(t.target);s&&(console.log("onConnect: sourceNode type:",p?.type,"targetNode type:",g?.type),console.log("onConnect: sourceHandle:",t.sourceHandle,"targetHandle:",t.targetHandle));let b=S.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!b.valid){s&&console.warn(`Connection rejected: ${b.reason}`);return}let N=p?.type==="vertical-pdu",v=p?.data,E=p?.type==="device"&&v?.deviceType==="switch",j=!!t.targetHandle&&(t.targetHandle.startsWith("pwr")||t.targetHandle.startsWith("power")),Y=!!t.targetHandle&&(t.targetHandle.startsWith("net-")||t.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(t.targetHandle)),ce=p?.type==="tube"&&g?.type==="multi-tube-cable",ie=p?.type==="multi-tube-cable"&&g?.type==="tube",ye=ce||ie,le=t.sourceHandle==="cable-button"&&t.targetHandle==="cable-button",de="fiber";N&&j?de="power":le?de="thick-cable":ye&&(de=x?"smoothstep":"fiber");let J,ve=cn(g),Tt=cn(p);if(ve||Tt){let y=g?.data,L=p?.data,Q=ve?y.ribbonFiberIds:L.ribbonFiberIds;Q&&Array.isArray(Q)&&Q.length>=6&&Q.length<=12&&(J={ribbonFiberIds:Q,isRibbon:true});}if(!J&&(de==="fiber"||de==="smoothstep")&&!N){let y;ce?y=gt(t.target,t.targetHandle):y=gt(t.source,t.sourceHandle),y&&(J={color:y.color,striped:y.striped,isRibbon:false});}else if(de==="thick-cable"&&le){let y=p?.data;J={color:y?.color||(y?.tubeStartIndex?fe(y.tubeStartIndex):"#6366f1")};}let Ye=ee(p,t.sourceHandle),ne=ee(g,t.targetHandle),Xe=K.current.some(y=>y.source===t.source?ee(p,y.sourceHandle)===Ye:y.target===t.source?ee(p,y.targetHandle)===Ye:false),je=K.current.some(y=>y.target===t.target?ee(g,y.targetHandle)===ne:y.source===t.target?ee(g,y.sourceHandle)===ne:false);if(lt(p,g)&&(Xe||je)){let y=new Set;for(let L of K.current){if(L.source===t.source&&ee(p,L.sourceHandle)===Ye){y.add(L.id);continue}if(L.target===t.source&&ee(p,L.targetHandle)===Ye){y.add(L.id);continue}if(L.source===t.target&&ee(g,L.sourceHandle)===ne){y.add(L.id);continue}L.target===t.target&&ee(g,L.targetHandle)===ne&&y.add(L.id);}if(y.size>0){let L=K.current.filter(Ae=>!y.has(Ae.id)),Q=addEdge(t,L),Ne=Q[Q.length-1],He=q({...t,id:Ne.id,type:de}),ze={...Ne,type:de,zIndex:He,style:{...Ne.style,zIndex:He},data:J!==void 0?J:Ne.data};F([...Q.slice(0,-1),ze]),s&&console.log("Fiber handle replacement: Replaced",y.size,"edge(s)");return}}if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let y=K.current.find(L=>L.target===t.target&&L.targetHandle===t.targetHandle||L.source===t.target&&L.sourceHandle===t.targetHandle);if(y){s&&(console.log("Splice target handle replacement: Found existing edge",y.id,"on splice handle",t.targetHandle),console.log("Existing edge details:",{id:y.id,source:y.source,target:y.target,sourceHandle:y.sourceHandle,targetHandle:y.targetHandle,data:y.data}));let L=t.source&&t.sourceHandle?K.current.find(B=>B.source===t.source&&B.sourceHandle===t.sourceHandle):null;s&&L&&console.log("Splice target handle replacement: Also found existing source edge",L.id);let Q=new Set;y&&Q.add(y.id),L&&L.id!==y.id&&Q.add(L.id);let Ne=K.current.filter(B=>!Q.has(B.id));s&&console.log("Splice target handle replacement: Removing",Q.size,"edge(s), creating new connection");let He=`edge-${t.source}-${t.sourceHandle}-${t.target}-${t.targetHandle}-${Date.now()}`,ze=q({...t,id:He,type:"fiber"}),Ae={id:He,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle,type:"fiber",zIndex:ze,style:{zIndex:ze},data:J!==void 0?J:{}},_t=[...Ne,Ae];F(_t),s&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Ae.id);return}}if(p?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let y=K.current.find(L=>L.source===t.source&&L.sourceHandle===t.sourceHandle||L.target===t.source&&L.targetHandle===t.sourceHandle);if(y){s&&console.log("Splice source handle replacement: Found existing edge",y.id,"on splice handle",t.sourceHandle);let L=t.target&&t.targetHandle?K.current.find(B=>B.target===t.target&&B.targetHandle===t.targetHandle):null;s&&L&&console.log("Splice source handle replacement: Also found existing target edge",L.id);let Q=new Set;y&&Q.add(y.id),L&&L.id!==y.id&&Q.add(L.id);let Ne=K.current.filter(B=>!Q.has(B.id));s&&console.log("Splice source handle replacement: Removing",Q.size,"edge(s), creating new connection");let He=`edge-${t.source}-${t.sourceHandle}-${t.target}-${t.targetHandle}-${Date.now()}`,ze=q({...t,id:He,type:"fiber"}),Ae={id:He,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle,type:"fiber",zIndex:ze,style:{zIndex:ze},data:J!==void 0?J:{}},_t=[...Ne,Ae];F(_t),s&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Ae.id);return}}if((p?.type==="tube"||p?.type==="cable")&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if((g?.type==="tube"||g?.type==="cable")&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if((p?.type==="multi-tube-cable"||p?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:de,selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if((g?.type==="multi-tube-cable"||g?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:de,selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if(p?.type==="coupler"&&(t.sourceHandle?.startsWith("left-")||t.sourceHandle?.startsWith("right-"))){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if(g?.type==="coupler"&&(t.targetHandle?.startsWith("left-")||t.targetHandle?.startsWith("right-"))){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if(le&&t.source&&t.sourceHandle&&t.target&&t.targetHandle){let y=p?.data,L=y?.color||(y?.tubeStartIndex?fe(y.tubeStartIndex):"#6366f1"),Q=we({edges:K.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:q,findBy:"source",data:{color:L}});if(Q){F(Q);return}if(Q=we({edges:K.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:q,findBy:"target",data:{color:L}}),Q){F(Q);return}}if(N&&j&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:"power",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if(E&&Y&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}let ft=S.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!ft.valid){if(N&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:j?"power":"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if(E&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}s&&console.warn(`Connection rejected: ${ft.reason}`);return}let Dt=K.current.some(y=>y.source===t.source&&y.sourceHandle===t.sourceHandle||y.target===t.source&&y.targetHandle===t.sourceHandle),go=K.current.some(y=>y.target===t.target&&y.targetHandle===t.targetHandle||y.source===t.target&&y.sourceHandle===t.targetHandle),$t=(y,L)=>!y||!L?false:!!(y.startsWith("tube-")||L.type==="splice"&&(y==="left"||y==="right")||y==="cable-button"),fo=$t(t.sourceHandle||"",p),bo=$t(t.targetHandle||"",g);if(Dt&&!fo){s&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:t.source,sourceHandle:t.sourceHandle,existingEdges:K.current.filter(y=>y.source===t.source&&y.sourceHandle===t.sourceHandle||y.target===t.source&&y.targetHandle===t.sourceHandle)});return}if(go&&!bo){s&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:t.target,targetHandle:t.targetHandle,existingEdges:K.current.filter(y=>y.target===t.target&&y.targetHandle===t.targetHandle||y.source===t.target&&y.sourceHandle===t.targetHandle)});return}let ho={...t,type:de,zIndex:q({...t,id:"temp-id"}),data:J};F(y=>{let L=addEdge(ho,y),Q=L[L.length-1];return Q&&(mr(Ne=>new Set(Ne).add(Q.id)),setTimeout(()=>{mr(Ne=>{let He=new Set(Ne);return He.delete(Q.id),He});},1e3)),L});},[F,S,q,se,s,gt,x]),Hn=useCallback((t,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let g=S.validateConnection({source:p.source??null,target:p.target??null,sourceHandle:p.sourceHandle??null,targetHandle:p.targetHandle??null});if(!g.valid){s&&console.warn(`Edge update rejected: ${g.reason}`);return}let b=se(p.source),N=se(p.target),v=b?.type==="vertical-pdu",E=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),j=b?.type==="tube"&&N?.type==="multi-tube-cable",Y=b?.type==="multi-tube-cable"&&N?.type==="tube",ce=j||Y,ie;v&&E?ie="power":ce?ie=x?"smoothstep":"fiber":ie="fiber";let ye;if((ie==="fiber"||ie==="smoothstep")&&!v){let le=gt(p.source,p.sourceHandle);le&&(ye={color:le.color,striped:le.striped});}F(le=>{let de=lt(b,N),J=ee(b,p.sourceHandle),ve=ee(N,p.targetHandle);return (de?le.filter(ne=>{if(ne.id===t.id)return true;let Xe=ne.source===p.source&&ee(b,ne.sourceHandle)===J||ne.target===p.source&&ee(b,ne.targetHandle)===J,je=ne.target===p.target&&ee(N,ne.targetHandle)===ve||ne.source===p.target&&ee(N,ne.sourceHandle)===ve;return !(Xe||je)}):le).map(ne=>ne.id===t.id?{...ne,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:ie,data:ye!==void 0?{...ne.data,...ye}:ne.data,zIndex:q({...p,id:ne.id,type:ie}),style:{...ne.style,zIndex:q({...p,id:ne.id,type:ie})}}:ne)});},[F,se,gt,q,x,s,S]),Sn=useCallback((t,p)=>{if(ue){c&&c(p);return}let g=t.metaKey||t.ctrlKey;if(p.type==="tube"&&p.parentId&&!g){let N=Fe().find(v=>v.id===p.parentId&&(v.type==="cable"||v.type==="multi-tube-cable"));if(N){A(v=>v.map(E=>({...E,selected:E.id===N.id}))),c&&c(N);return}}if(g&&p.type==="device"){let b=p.data||{},N=b.view||(Array.isArray(b.rearPorts)&&b.rearPorts.length>0?"rear":"front"),v=N==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${p.id} from ${N} to ${v}`),h&&h(p.id,v),c&&c(p);}else c&&c(p);},[h,c,s,Fe,A,ue]),Pn=useCallback(()=>{},[]),Cn=useCallback((t,p)=>{l&&l(p);},[l]),[Te,po]=useState(null),[hr,mr]=useState(new Set);useOnSelectionChange({onChange:({nodes:t,edges:p})=>{if(yr(p||[]),!ue)if(t&&t.length===1){let g=t[0];if(g.type==="tube"&&g.parentId){let N=Fe().find(v=>v.id===g.parentId&&(v.type==="cable"||v.type==="multi-tube-cable"));if(N){po(N),A(v=>v.map(E=>({...E,selected:E.id===N.id}))),c&&c(N);return}}po(g),c&&c(g);}else po(null),c&&c(null);}});let[uo,yr]=useState([]);useEffect(()=>{let t=p=>{if((p.key==="Backspace"||p.key==="Delete")&&uo.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let g=uo.filter(b=>{let N=b.sourceHandle||"",v=b.targetHandle||"";return N.startsWith("tube-")||v.startsWith("tube-")?(s&&console.log("Cannot delete edge connected to tube handle",b),false):true});if(g.length>0){let b=new Set(g.map(N=>N.id));F(N=>N.filter(v=>!b.has(v.id))),yr([]),s&&console.log("Deleted edges:",g.map(N=>N.id));}}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[uo,F,s]);let En=useCallback((t,{nodeId:p,handleType:g})=>{s&&console.log("Connection started from",{nodeId:p,handleType:g});},[s]),Rn=useCallback(t=>{s&&console.log("Connection ended",t);},[s]),Tn=useCallback(()=>{if(!Te)return;let t=se(Te.id);if(t){if(t.type==="rack"){let b=((t.data||{}).face||"front")==="front"?"rear":"front";u?(u(t.id,b),h&&Fe().filter(v=>v.parentId===t.id).forEach(v=>{h(v.id,b);})):A(N=>N.map(v=>v.id===t.id?{...v,data:{...v.data,face:b}}:v.parentId===t.id?{...v,data:{...v.data,view:b}}:v));return}if(t.type==="device"){let p=t.data||{},g=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,b=Array.isArray(p.ports)&&p.ports.length>0,v=(p.view||(g&&!b?"rear":"front"))==="front"?"rear":"front";h?h(t.id,v):A(E=>E.map(j=>j.id===t.id?{...j,data:{...j.data,view:v}}:j));}}},[Te,se,u,h,A,Fe]),In=useMemo(()=>{let t=lo.current;return T.map(p=>{let g=p,b=t.get(String(g.source)),N=t.get(String(g.target)),v=oo(g.sourceHandle||"",b),E=oo(g.targetHandle||"",N),j=b&&b.data?.view,Y=N&&N.data?.view,ce=b?.type==="device"&&j==="rear",ie=N?.type==="device"&&Y==="rear",J=ce&&v!=="rear"||ie&&E!=="rear"?{...p.style,opacity:0,pointerEvents:"none",zIndex:0}:p.style;return {...p,style:J,className:hr.has(p.id)?"edge-connecting":p.className}})},[T,hr]);return jsxs("div",{ref:he,className:`${m||""} ${k==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",touchAction:"none",...f},children:[jsxs(ReactFlow,{nodes:V,edges:In,onNodesChange:t=>{yn(t),X?a&&a(We.current):S.setState({nodes:We.current});},onEdgesChange:t=>{let p=t.filter(g=>{if(g.type==="remove"){let b=K.current.find(N=>N.id===g.id);if(b){let N=b.sourceHandle||"",v=b.targetHandle||"";if(N.startsWith("tube-")||v.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",b),false}}return true});p.length>0&&(be(p),X?i&&i(K.current):S.setState({edges:K.current}));},onConnect:vn,onConnectStart:En,onConnectEnd:Rn,onEdgeUpdate:Hn,isValidConnection:kn,onNodeClick:Sn,onNodeDoubleClick:Pn,onNodeDragStart:xn,onNodeDrag:wn,onNodeDragStop:Nn,onEdgeClick:Cn,onInit:w,nodeTypes:fr.current,edgeTypes:Wi,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:!ue,nodesConnectable:true,elementsSelectable:!ue,edgesFocusable:!ue,selectNodesOnDrag:false,connectOnClick:W,panOnDrag:C,panOnScroll:D&&!ue,zoomOnScroll:$&&!ue,preventScrolling:ue,onlyRenderVisibleElements:true,fitView:true,proOptions:{hideAttribution:true},children:[jsx(Background,{color:k==="light"?"#e5e5e5":"#2a2a2a"}),jsx(Controls,{}),!ue&&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:mn,style:{position:"absolute",top:I.includes("top")?"10px":"auto",bottom:I.includes("bottom")?"10px":"auto",right:I.includes("right")?"10px":"auto",left:I.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:"pointer",transition:"all 0.2s ease",...P},children:z}),Te&&(Te.type==="rack"||Te.type==="device")&&jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsx("button",{onClick:t=>{t.preventDefault(),Tn();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=Te.data;if(Te.type==="rack")return (t?.face||"front")==="front"?"Switch to rear":"Switch to front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!g?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let t=Te.data;if(Te.type==="rack")return (t?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!g?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},Ai=e=>jsx(ReactFlowProvider,{children:jsx(zi,{...e})});var un=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}}),gn=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}}),fn=e=>{let o=a=>{if(!a)return;if(typeof a=="string")return a;let i=a.device;return typeof i=="object"&&i?i.id:i},r=o(e.termination_a),n=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${r}`,target:`device-${n}`,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}}},Mi=e=>{let o=[],r=[];return e.racks.forEach(n=>o.push(un(n))),e.devices.forEach(n=>o.push(gn(n))),e.cables.forEach(n=>r.push(fn(n))),{nodes:o,edges:r}},Li=e=>{let o=e.filter(a=>a.type==="rack"),r=e.filter(a=>a.type==="device"),n=e.filter(a=>!["rack","device"].includes(a.type));return o.forEach((a,i)=>{a.position={x:i*300,y:100};}),r.forEach(a=>{if(a.parentId){let i=o.find(d=>d.id===a.parentId);if(i){let d=a.data.uPosition||1,s=a.data.uHeight||1;a.position={x:i.position.x+50,y:i.position.y+d*20-s*10};}}else a.position={x:Math.random()*400+100,y:Math.random()*200+50};}),n.forEach((a,i)=>{a.position={x:i*150+100,y:300};}),e};var pt=class extends Error{constructor(r,n,a,i,d){super(`Device placement conflict: ${n} at U${a}-${a+i-1} in rack ${r}${d?` conflicts with ${d}`:""}`);this.rackId=r;this.deviceId=n;this.uPosition=a;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function sr(e,o={}){let r=[],n=[];for(let a of e.devices)a.unit+a.height-1>e.units&&n.push({deviceId:a.id,uPosition:a.unit,uHeight:a.height,rackUHeight:e.units});for(let a=0;a<e.devices.length;a++){let i=e.devices[a],d=i.unit,s=i.unit+i.height-1;for(let c=a+1;c<e.devices.length;c++){let l=e.devices[c],h=l.unit,u=l.unit+l.height-1;d<=u&&s>=h&&r.push({deviceId:i.id,uPosition:i.unit,uHeight:i.height,conflictWith:l.id});}}return {isValid:r.length===0&&n.length===0,conflicts:r,outOfBounds:n}}function bn(e,o,r={}){let{deviceTypeMapping:n={}}=r,a=n[e.type]||"device",i=at(o,e.unit,e.height);return {id:e.id,type:a,position:i,parentId:o.id,extent:"parent",data:{label:e.name,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,rackWidthPx:o.data.rackWidthPx}}}function Oi(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}}}function Bi(e,o={}){let{conflictPolicy:r="strict",validatePlacements:n=true}=o,a=[],i=[];if(n)for(let d of e){let s=sr(d,o);if(!s.isValid&&r==="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 pt(d.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 d of e){let s=Oi(d);a.push(s);for(let c of d.devices)try{let l=bn(c,s,o);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=zt(s,{id:c.id,data:{label:c.name,uHeight:c.height}},i,c.unit);if(h!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${h} due to conflict`);let u={...c,unit:h},m=bn(u,s,o);i.push(m);}else throw new pt(d.id,c.id,c.unit,c.height)}}}return a.push(...i),a}function Ui(e){let o=[],r=e.filter(n=>n.type==="rack");for(let n of r){let i=e.filter(d=>d.type==="device"&&d.parentId===n.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width,ports:d.data.ports,connections:d.data.connections}));o.push({id:n.id,name:n.data.label,position:n.position,units:n.data.uHeight||42,uNumberingDirection:n.data.uNumberingDirection||"bottom-up",customHeaderText:n.data.customHeaderText,devices:i,rackWidthPx:n.data.rackWidthPx});}return o}function Vi(e,o,r,n){return e.map(a=>a.id!==o?a:{...a,devices:a.devices.map(i=>i.id!==r?i:{...i,unit:n})})}function Yi(e,o,r,n={}){let{conflictPolicy:a="strict"}=n;return e.map(i=>{if(i.id!==o)return i;if(a==="strict"&&!sr({...i,devices:[...i.devices,r]},n).isValid)throw new pt(o,r.id,r.unit,r.height);return {...i,devices:[...i.devices,r]}})}function Xi(e,o,r){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.filter(a=>a.id!==r)})}var ut=class extends Error{constructor(r,n,a,i){super(`Splice placement conflict: ${n} at holder ${a} in tray ${r}${i?` conflicts with ${i}`:""}`);this.trayId=r;this.spliceId=n;this.holder=a;this.conflictWith=i;this.name="SplicePlacementError";}};function dr(e,o={}){let r=[],n=[];for(let a of e.splices)(a.holder<1||a.holder>Oe)&&n.push({spliceId:a.id,holder:a.holder,max:Oe});for(let a=0;a<e.splices.length;a++){let i=e.splices[a];for(let d=a+1;d<e.splices.length;d++){let s=e.splices[d];i.holder===s.holder&&r.push({spliceId:i.id,holder:i.holder,conflictWith:s.id});}}return {isValid:r.length===0&&n.length===0,conflicts:r,outOfBounds:n}}function hn(e,o){let r=e.mode==="ribbon",n=kt(o,e.holder,r);return {id:e.id,type:"splice",position:n,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function ji(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Gi(e,o={}){let{conflictPolicy:r="strict",validatePlacements:n=true}=o,a=[],i=[];if(n)for(let d of e){let s=dr(d,o);if(!s.isValid&&r==="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 ut(d.id,s.conflicts[0]?.spliceId||s.outOfBounds[0]?.spliceId||"unknown",s.conflicts[0]?.holder||s.outOfBounds[0]?.holder||1)}}for(let d of e){let s=ji(d);a.push(s);for(let c of d.splices)try{let l=hn(c,s);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=[...a,...i],u=Vt(s,{id:c.id,data:{label:c.name,holderPosition:c.holder}},h,c.holder);if(u!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${u} due to conflict`);let m={...c,holder:u},f=hn(m,s);i.push(f);}else throw new ut(d.id,c.id,c.holder)}}}return a.push(...i),a}function Zi(e){let o=[],r=e.filter(n=>n.type==="splice-tray");for(let n of r){let i=e.filter(d=>d.type==="splice"&&d.parentId===n.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb,mode:d.data.mode||"single",ribbonFiberIds:d.data.ribbonFiberIds}));o.push({id:n.id,name:n.data.label,position:n.position,splices:i});}return o}function Ki(e,o,r,n){return e.map(a=>a.id!==o?a:{...a,splices:a.splices.map(i=>i.id!==r?i:{...i,holder:n})})}function qi(e,o,r,n={}){let{conflictPolicy:a="strict"}=n;return e.map(i=>{if(i.id!==o)return i;if(a==="strict"&&!dr({...i,splices:[...i.splices,r]},n).isValid)throw new ut(o,r.id,r.holder);return {...i,splices:[...i.splices,r]}})}function Ji(e,o,r){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.filter(a=>a.id!==r)})}
|
|
2
|
-
export{
|
|
1
|
+
import ft,{useState,useMemo,useRef,useEffect,useSyncExternalStore,Component,useCallback}from'react';import {useReactFlow,Handle,Position,getBezierPath,BaseEdge,EdgeLabelRenderer,useEdges,addEdge,ReactFlowProvider,useNodesState,useEdgesState,useOnSelectionChange,ReactFlow,Background,Controls,MiniMap,Panel,applyEdgeChanges,ConnectionMode,getSmoothStepPath,SmoothStepEdge}from'reactflow';import {toPng}from'html-to-image';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Se=20,je=60,qt=300,Rt=5;function Ar(e){return e==="system"?typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e}function Or(e,o){let n=Ar(e)==="light"?"react-flow-light":"react-flow-dark";return o?`${n} ${o}`:n}function Br(e){return Ar(e)==="light"?"#e5e5e5":"#2a2a2a"}function Ur(e,o){return {width:"100%",height:"100%",...o}}var wi=()=>"bottom-up",ot=e=>e.data.uNumberingDirection||wi(),Jt=(e,o,t)=>t==="bottom-up"?o-e+1:e,Qt=(e,o,t)=>t==="bottom-up"?o-e+1:e;var Mo=(e,o,t,n)=>{if(!e.parentId||e.parentId!==o.id)return t;let s=e.data.uHeight||1,a=o.data.uHeight||42,l=ot(o),i=60,d=t.y-i,u=Math.round(d/20)+1,h;l==="bottom-up"?h=Jt(u,a,l)-s+1:h=Jt(u,a,l);let g=a-s+1,c=Math.max(1,Math.min(g,h));if(l==="top-down"&&h<=1&&(c=1),!Lo(o,e,c,n)){let x=eo(o,e,n,c);x!==c&&(c=x);}let f;if(l==="bottom-up"){let x=c+s-1,C=Qt(x,a,l);f=i+(C-1)*20-1;}else {let x=Qt(c,a,l);f=i+(x-1)*20-1;}return {x:t.x,y:f,uPosition:c}},Lo=(e,o,t,n)=>{let s=o.data.uHeight||1,a=e.data.uHeight||42;if(t<1||t+s-1>a)return false;let l=n.filter(i=>i.type==="device"&&i.parentId===e.id&&i.id!==o.id);for(let i of l){let d=i.data.uPosition||1,u=i.data.uHeight||1,h=t,g=t+s-1,c=d,f=d+u-1;if(h<=f&&g>=c)return false}return true},eo=(e,o,t,n=1)=>{let s=o.data.uHeight||1,a=e.data.uHeight||42;for(let l=n;l<=a-s+1;l++)if(Lo(e,o,l,t))return l;return 1},bt=(e,o,t=1)=>{let n=60,s=ot(e),a=e.data.uHeight||42,l=Qt(o,a,s),i;if(s==="bottom-up"){let d=o+t-1,u=Qt(d,a,s);i=n+(u-1)*20-1;}else i=n+(l-1)*20-1;return {x:0,y:i}},Vr=(e,o,t)=>{let n=e.data.uHeight||1,s=bt(o,t,n);return {...e,position:s,data:{...e.data,uPosition:t}}},xi=(e,o)=>{let t=e.data.uPosition||1,n=e.data.uHeight||1,s=o.data.uHeight||42,a=Math.max(1,Math.min(s-n+1,t));return a!==t?Vr(e,o,a):e};function Te(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var zo=({data:e,selected:o,id:t,onViewChange:n,onRackFaceChange:s,isDragOver:a=false})=>{let{label:l,ports:i=0,status:d="active",uHeight:u=42,face:h="front",customHeaderText:g,rackWidthPx:c}=e,f=c||300,{getNodes:x,setNodes:C}=useReactFlow(),k=x(),[S,I]=useState(e.showUMarkers!==void 0?e.showUMarkers:true),E=()=>{let R=ot({data:e})==="bottom-up"?"top-down":"bottom-up";C(F=>F.map(W=>W.id===t?{...W,data:{...W.data,uNumberingDirection:R}}:W));},D=()=>{let w=h==="front"?"rear":"front";s?(s(t,w),n&&k.filter(F=>F.parentId===t).forEach(F=>{n(F.id,w);})):n?k.filter(F=>F.parentId===t).forEach(F=>{n(F.id,w);}):C(R=>R.map(F=>F.id===t?{...F,data:{...F.data,face:w}}:F.parentId===t?{...F,data:{...F.data,view:w}}:F));},m=()=>{let w=[],R=60,F=ot({data:e});for(let W=1;W<=u;W++){let L=R+(W-1)*20-4,j=Jt(W,u,F);w.push(jsx("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:`${20}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:j},W));}return w};return jsxs("div",{className:`rack-node ${o?"selected":""} ${a?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${Te(d)}`,borderRadius:"8px",padding:0,width:`${f}px`,height:`${60+u*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:a?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":o?"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:l}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[g?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:g}):jsxs("span",{children:[typeof i=="number"?i:0," ports"]})," \u2022 ",u,"U \u2022 ",h]}),jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsx("button",{onPointerDown:w=>{w.stopPropagation();},onMouseDown:w=>{w.stopPropagation();},onClick:w=>{w.stopPropagation(),w.preventDefault(),I(!S);},style:{background:S?"#10b981":"#374151",color:S?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${S?"Hide":"Show"} U markers`,children:"U"}),jsx("button",{onPointerDown:w=>{w.stopPropagation();},onMouseDown:w=>{w.stopPropagation();},onClick:w=>{w.stopPropagation(),w.preventDefault(),E();},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 ${ot({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:ot({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsx("button",{onPointerDown:w=>{w.stopPropagation();},onMouseDown:w=>{w.stopPropagation();},onClick:w=>{w.stopPropagation(),w.preventDefault(),D();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${h==="front"?"rear":"front"} view`,children:h==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${u*20}px`,overflow:"hidden"}}),S&&jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:m()})]})};var Ao=({data:e,selected:o})=>{let{label:t,status:n="active"}=e;return jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${Te(n)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:o?"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:t})}),jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:Te(n),borderRadius:"50%"}})]})};var jr=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function xe(e){let o=(e-1)%12;return jr[o]}function nt(e){return e>12}function ze(e){let o=xe(e);return nt(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function it(e){return xe(e)}function Ae(e){return e.map(o=>({base:xe(o),striped:nt(o)}))}function Si(e,o,t,n,s,a,l,i){let d=Ae(t),u=d.length,h=n?1.2:1,g=!!i?.highlight,c=n?2:1.5,f=i?.highlightWidth??c*3,x=i?.highlightColor??d[0]?.base??"#22d3ee";return jsxs(Fragment,{children:[g&&jsx(BaseEdge,{id:`${e}-highlight`,path:o,style:{...s,stroke:x,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${c}px`,"--rn-edge-highlight-to":`${f}px`}}),d.map((C,k)=>{let I=(u-k)*h;return jsx("path",{d:o,stroke:C.base,strokeWidth:I,fill:"none",strokeLinecap:"butt",opacity:C.striped?.9:1,style:s},`${e}-ribbon-${k}`)}),d.some(C=>C.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:o,style:{...s,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:n&&i&&(i.bandwidth||i.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${a}px,${l}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${d[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsx("div",{children:i.bandwidth}),i.length&&jsxs("div",{children:[i.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[t.length,"F"]})]})})]})}var ro=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,data:i,selected:d,style:u={},className:h})=>{let[g,c,f]=getBezierPath({sourceX:o,sourceY:t,sourcePosition:a,targetX:n,targetY:s,targetPosition:l}),{bandwidth:x,length:C,color:k="#00FFFF",striped:S=false,ribbonFiberIds:I,isRibbon:E,highlight:D,highlightColor:m,highlightWidth:w}=i||{},R=!!D;if((E||I&&I.length>=6&&I.length<=12)&&I)return Si(e,g,I,d??false,u??{},c,f,i);let W=d?3:2,L=w??W*3,j={...u,stroke:k,strokeWidth:W,strokeDasharray:"none"};return jsxs(Fragment,{children:[R&&jsx(BaseEdge,{id:`${e}-highlight`,path:g,style:{...u,stroke:m??k,strokeWidth:L,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${W}px`,"--rn-edge-highlight-to":`${L}px`}}),jsx(BaseEdge,{id:e,path:g,style:j}),S&&jsx(BaseEdge,{id:`${e}-stripe`,path:g,style:{...u,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsx(EdgeLabelRenderer,{children:d&&i&&(x||C)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${c}px,${f}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${k}`,pointerEvents:"none",zIndex:9999},children:[x&&jsx("div",{children:x}),C&&jsxs("div",{children:[C,"m"]})]})})]})};var Oo=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,style:i={},data:d,markerEnd:u})=>{let[h]=getBezierPath({sourceX:o,sourceY:t,sourcePosition:a,targetX:n,targetY:s,targetPosition:l}),g=d?.connectorType||"C13";return jsx(BaseEdge,{id:e,path:h,markerEnd:u,style:(()=>{let f={stroke:d?.color||"#f59e0b",strokeWidth:g==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...i};return g==="C19"?{...f,strokeDasharray:"none"}:{...f,strokeDasharray:"6,3"}})()})};function Fi(e,o,t,n,s,a,l,i,d,u,h){let g=Ae(i),c=g.length,f=d?1.8:1.5,x=!!h?.highlight,C=d?3:2.5,k=h?.highlightWidth??C*3,S=h?.highlightColor??g[0]?.base??"#22d3ee",[I,E,D]=getSmoothStepPath({sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l});return jsxs(Fragment,{children:[x&&jsx(BaseEdge,{id:`${e}-highlight`,path:I,style:{...u,stroke:S,strokeWidth:k,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${k}px`}}),g.map((m,w)=>{let F=(c-w)*f;return jsx("path",{d:I,stroke:m.base,strokeWidth:F,fill:"none",strokeLinecap:"butt",opacity:m.striped?.9:1,style:u},`${e}-ribbon-${w}`)}),g.some(m=>m.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:I,style:{...u,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:d&&h&&(h.bandwidth||h.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${E}px,${D}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${g[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[h.bandwidth&&jsx("div",{children:h.bandwidth}),h.length&&jsxs("div",{children:[h.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[i.length,"F"]})]})})]})}var Kr=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,data:i,selected:d,style:u={},...h})=>{let{color:g="#00FFFF",ribbonFiberIds:c,isRibbon:f,highlight:x,highlightColor:C,highlightWidth:k}=i||{},S=!!x;if((f||c&&c.length>=6&&c.length<=12)&&c)return Fi(e,o,t,n,s,a,l,c,d??false,u??{},i);let E=d?4:3,D=k??E*3,m={...u,stroke:g,strokeWidth:E};return jsxs(Fragment,{children:[S&&jsx(BaseEdge,{id:`${e}-highlight`,path:getSmoothStepPath({sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l})[0],style:{...u,stroke:C??g,strokeWidth:D,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${E}px`,"--rn-edge-highlight-to":`${D}px`}}),jsx(SmoothStepEdge,{...h,id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,data:i,selected:d,style:m})]})};function Di({sourceX:e,sourceY:o,targetX:t,targetY:n,sourcePosition:s,targetPosition:a}){let l=s===Position.Left||s===Position.Right,i;if(l){let d=(e+t)/2;i=`M ${e},${o} L ${d},${o} L ${d},${n} L ${t},${n}`;}else {let d=(o+n)/2;i=`M ${e},${o} L ${e},${d} L ${t},${d} L ${t},${n}`;}return i}function $i(e,o,t,n,s,a){let l=Ae(t),i=l.length,d=n?1.2:1,u=!!a?.highlight,h=n?2:1.5,g=a?.highlightWidth??h*3,c=a?.highlightColor??l[0]?.base??"#22d3ee",f=o.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),x=f?(parseFloat(f[1])+parseFloat(f[3]))/2:0,C=f?(parseFloat(f[2])+parseFloat(f[4]))/2:0;return jsxs(Fragment,{children:[u&&jsx(BaseEdge,{id:`${e}-highlight`,path:o,style:{...s,stroke:c,strokeWidth:g,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${h}px`,"--rn-edge-highlight-to":`${g}px`}}),l.map((k,S)=>{let E=(i-S)*d;return jsx("path",{d:o,stroke:k.base,strokeWidth:E,fill:"none",strokeLinecap:"butt",opacity:k.striped?.9:1,style:s},`${e}-ribbon-${S}`)}),l.some(k=>k.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:o,style:{...s,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:n&&a&&(a.bandwidth||a.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${x}px,${C}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${l[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[a.bandwidth&&jsx("div",{children:a.bandwidth}),a.length&&jsxs("div",{children:[a.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[t.length,"F"]})]})})]})}var Jr=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,data:i,selected:d,style:u={},...h})=>{let{color:g="#00FFFF",striped:c=false,ribbonFiberIds:f,isRibbon:x,highlight:C,highlightColor:k,highlightWidth:S}=i||{},I=!!C,E=Di({sourceX:o,sourceY:t,sourcePosition:a,targetX:n,targetY:s,targetPosition:l});if((x||f&&f.length>=6&&f.length<=12)&&f)return $i(e,E,f,d??false,u??{},i);let m=d?3:2,w=S??m*3,R={...u,stroke:g,strokeWidth:m,strokeDasharray:"none"};return jsxs(Fragment,{children:[I&&jsx(BaseEdge,{id:`${e}-highlight`,path:E,style:{...u,stroke:k??g,strokeWidth:w,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${m}px`,"--rn-edge-highlight-to":`${w}px`}}),jsx(BaseEdge,{id:e,path:E,style:R}),c&&jsx(BaseEdge,{id:`${e}-stripe`,path:E,style:{...u,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var tn=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,style:i={},data:d,markerEnd:u,selected:h})=>{let{color:g="#6366f1",label:c,highlight:f,highlightColor:x,highlightWidth:C}=d||{},k=!!f,S=8,I=C??S*1.8,[E,D,m]=getBezierPath({sourceX:o,sourceY:t,sourcePosition:a,targetX:n,targetY:s,targetPosition:l}),w={...i,stroke:g,strokeWidth:S,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxs(Fragment,{children:[k&&jsx(BaseEdge,{id:`${e}-highlight`,path:E,style:{...i,stroke:x??g,strokeWidth:I,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${x??g}) drop-shadow(0 0 16px ${x??g})`,"--rn-edge-highlight-from":`${S}px`,"--rn-edge-highlight-to":`${I}px`}}),jsx(BaseEdge,{id:e,path:E,markerEnd:u,style:w}),c&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${D}px,${m}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${g}`,pointerEvents:"none",zIndex:9999},children:c})})]})};var on=(t=>(t.FULL="full",t.HALF="half",t))(on||{});var Uo={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}};function _t(e){let o=Uo[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let t=o.amperage===16,n=t?12:8,s=t?10:5,a=t?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:s,color:o.color,borderColor:o.borderColor,fontSize:t?"3px":"4px",...a}}function rn(e){let o=Uo[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function zi(e){return rn(e).amperage===16}function Vo(e){return e%10<8?"C13":"C19"}function jo(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var mt=({data:e,selected:o})=>{let {label:t,status:n="active",deviceType:s="server",manufacturer:a,role:l,uHeight:i=1,width:d="full",ports:u=[],rearPorts:h=[],view:g,rackWidthPx:c,frontImageUrl:f,rearImageUrl:x,imageFit:C,imagePosition:k,imageRepeat:S,stretchToFit:I}=e,E=c||300,D=g||(h.length>0&&u.length===0?"rear":"front"),m=D==="rear"?x:f,w=m?{backgroundImage:`url(${m})`,backgroundSize:I?"100% 100%":C??"cover",backgroundPosition:k??"center",backgroundRepeat:S??"no-repeat"}:{};u.length>0&&u.forEach(Z=>{Z.ports.forEach(M=>{M.type?.includes("power")?M.label:`${Z.name}-${M.label}`;});}),h.length>0&&h.forEach(Z=>{Z.ports.forEach(M=>{M.type?.includes("power")?M.label:`${Z.name}-${M.label}`;});});let F=i*20,W=E+4,L=Math.floor(E/2),j=d==="half"?`${L}px`:`${W}px`,re=d==="half"?`${L}px`:void 0,ae=(Z,M)=>{let H=[];if(Z.length===0)return H;let A=Math.max(4,Math.floor(F*.4)),z=Math.max(2,Math.floor(F*.2));return Z.forEach((X,oe)=>{X.ports.forEach((_,T)=>{let Q=!!_.type&&_.type.includes("power");if(M==="front"&&Q)return;let J=Q?`${_.label}`:`${X.name}-${_.label}`,V=_.connected,O="#6b7280",we="#374151";if(V)if(_.type?.includes("power"))O=_.type==="power_c19"?"#fbbf24":"#f59e0b";else if(_.type==="console"||_.type==="mgmt")O="#8b5cf6";else if(_.type==="usb")O="#10b981";else switch(_.cableType){case "smf":O="#fbbf24";break;case "cat6":O="#8b5cf6";break;case "om3":O="#06b6d4";break;case "om4":O="#8b5cf6";break;case "om5":O="#84cc16";break;case "cat5e":O="#3b82f6";break;case "cat6a":O="#ef4444";break;case "cat7":O="#f97316";break;case "fiber":O="#3b82f6";break;case "ethernet":O="#10b981";break;default:O="#10b981";}let Fe=V?O:we,G=Position.Top,he={width:`${A}px`,height:`${z}px`,background:O,border:`0.5px solid ${Fe}`,borderRadius:"1px",cursor:"pointer"};if(M==="front")T%2===0?(G=Position.Top,he.transform="translateY(50%)",he.left=`${T/2*(A+2)}px`):(G=Position.Bottom,he.transform="translateY(-50%)",he.left=`${(T-1)/2*(A+2)}px`);else if((s?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel"||s==="switch")T%2===0?(G=Position.Top,he.transform="translateY(50%)",he.left=`${T/2*(A+2)}px`):(G=Position.Bottom,he.transform="translateY(-50%)",he.left=`${(T-1)/2*(A+2)}px`);else if(_.type?.includes("power")){G=Position.Left,he.transform="translateX(50%)";let Vt=F<=20?10:25,jt=F<=20?40:50;he.top=`${Vt+T*jt}%`;let $e=jo(t),_e=_t($e);he={...he,width:`${_e.width}px`,height:`${_e.height}px`,background:_e.color,border:`1px solid ${_e.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:_e.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:_e.borderRadius,clipPath:_e.clipPath};}else G=Position.Right,he.transform="translateX(-50%)",he.top=`${25+T*50}%`;let qe=(s?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",ke;if(Q)ke="target";else if(s==="switch"||s==="router")ke="source",H.push(jsx(Handle,{id:`${J}-target`,type:"target",position:G,style:he,title:`${X.name} - ${_.label} (input) ${V?"(connected)":"(disconnected)"}`},`${J}-target`));else if(qe){ke=M==="rear"?"source":"target";let Je=M==="rear"?"target":"source";H.push(jsx(Handle,{id:`${J}-${Je}`,type:Je,position:G,style:he,title:`${X.name} - ${_.label} (${Je}) ${V?"(connected)":"(disconnected)"}`},`${J}-${Je}`));}else ke=V?"source":"target";H.push(jsx(Handle,{id:J,type:ke,position:G,style:he,title:`${X.name} - ${_.label} ${V?"(connected)":"(disconnected)"}`,children:Q?T+1:void 0},J));});}),H},se=()=>D==="front"?u.length>0?ae(u,"front"):[]:D==="rear"?h.length>0?ae(h,"rear"):[]:[];return jsxs("div",{className:`device-node ${o?"selected":""}`,style:{backgroundColor:"#1f2937",...w,border:`1px solid ${Te(n)}`,borderRadius:"2px",padding:"0px",width:j,...re&&{left:re},height:`${F}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),i>1&&jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:a})]}),i>1&&jsxs("div",{style:{position:"absolute",bottom:"1px",right:"1px",background:"#374151",color:"#9ca3af",padding:"1px 2px",borderRadius:"1px",fontSize:"6px",lineHeight:"1"},children:[i,"U"]}),jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:Te(n),borderRadius:"50%"}}),se()]})};var Go=({data:e,selected:o})=>{let{label:t,status:n="active",heightCm:s=100,powerPorts:a=36,widthPx:l=15,mgmt_unit:i}=e,d=s*4.2,u=()=>{let c=Math.ceil(a/10),f=Array(10).fill(0).map((w,R)=>R<8?"10A":"16A");for(let w=0,R=0;w<c;++w)for(let F=0;F<10&&R<a;++F,++R){f[F];}let S=[],I=15,m=(d-I-3)/(a-9)*.5;for(let w=0;w<a;w++){let R=I-2+m*w,F=`${w+1}`;if(i&&(i==="top"&&w===0||i==="middle"&&w===Math.floor(a/2)||i==="bottom"&&w===a-1)){S.push(h(R));continue}let L=Vo(w),j=_t(L),re=Math.round((l-j.width)/2-1);S.push(jsx(Handle,{type:"source",position:Position.Right,id:F,style:{position:"absolute",left:`${re}px`,top:`${R-j.height/2}px`,width:`${j.width}px`,height:`${j.height}px`,background:j.color,border:`1px solid ${j.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:j.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:j.borderRadius,clipPath:j.clipPath},title:`Power Port ${w+1} (${L})`,children:w+1},`handle-${F}`));}return S},h=g=>jsxs("div",{style:{position:"absolute",left:`${(l-16)/2}px`,top:`${g-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");return jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${Te(n)}`,borderRadius:"2px",padding:0,width:`${l}px`,height:`${d}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:"20px",display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:t})}),jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${d-20}px`,overflow:"hidden"},children:u()})]})};var qo=({data:e,selected:o,id:t})=>{let{lossDb:n,mode:s="single",ribbonFiberIds:a}=e||{},l=useEdges(),i=l.find(m=>m.target===t&&m.targetHandle==="left"),d=l.find(m=>m.source===t&&m.sourceHandle==="right"),u=l.find(m=>m.target===t&&m.targetHandle==="right"),h=d||u,g=i?.data?.color||"#555",c=h?.data?.color||"#555",f=s==="ribbon",x=i?.data?.ribbonFiberIds||a,C=h?.data?.ribbonFiberIds||a,k=f&&x?Ae(x):null,S=f&&C?Ae(C):null,I=!!i&&!!h;return jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:f?85:69,height:f?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[f&&k&&S?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:k.map((m,w)=>jsx("div",{style:{flex:1,background:m.base,opacity:m.striped?.9:1}},`left-${w}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:S.map((m,w)=>jsx("div",{style:{flex:1,background:m.base,opacity:m.striped?.9:1}},`right-${w}`))})]}):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:g}}),jsx("div",{style:{background:c}})]}),jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),I&&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}}),I&&typeof n=="number"&&jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:f?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsx("div",{children:`${n.toFixed(2)} dB`}),f&&a&&jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[a.length,"F"]})]}),jsx(Handle,{type:"target",position:Position.Left,id:"left",isConnectable:true,style:{width:12,height:f&&k?20:12,borderRadius:f&&k?"6px":"50%",border:"none",background:f&&k?`linear-gradient(to bottom, ${k.map(m=>m.base).join(", ")})`:g,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:f&&S?20:12,borderRadius:f&&S?"6px":"50%",border:"none",background:f&&S?`linear-gradient(to bottom, ${S.map(m=>m.base).join(", ")})`:c,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:f&&S?20:12,borderRadius:f&&S?"6px":"50%",border:"none",background:f&&S?`linear-gradient(to bottom, ${S.map(m=>m.base).join(", ")})`:c,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Lt=20,io=36;var lt=32,dn=4,Ge=12,Oi=69,ct=80,Jo=(ct-Oi)/2;var Qo=(e,o,t,n)=>{if(!e.parentId||e.parentId!==o.id)return t;let s=e.data?.mode==="ribbon",a=s?io:Lt,l=s?32:16,i=lt,d=t.y-i,u=Math.round(d/a)+1,g=Math.max(1,Math.min(Ge,u));if(!Mt(o,e,g,n)){let x=zt(o,e,n,g);if(x!==g){let C=(a-l)/2;return {x:Jo,y:i+(x-1)*a+C,holderPosition:x}}}let c=(a-l)/2,f=i+(g-1)*a+c;return {x:Jo,y:f,holderPosition:g}},Mt=(e,o,t,n)=>!n.filter(a=>a.parentId===e.id&&a.type==="splice"&&a.id!==o.id).some(a=>a.data.holderPosition===t),zt=(e,o,t,n=1)=>{for(let s=n;s<=Ge;s++)if(Mt(e,o,s,t))return s;for(let s=n-1;s>=1;s--)if(Mt(e,o,s,t))return s;return 1},Bi=(e,o)=>At(e,o,false),At=(e,o,t=false)=>{let n=lt,s=t?io:Lt,l=(s-(t?32:16))/2,i=n+(o-1)*s+l;return {x:Jo,y:i}};var or=({data:e,selected:o})=>{let{label:t="Splice Tray"}=e||{},[n,s]=useState(false),a=()=>{if(!n)return null;let l=[],i=lt;for(let d=1;d<=Ge;d++){let u=i+(d-1)*Lt;l.push(jsxs("div",{style:{position:"absolute",left:"-35px",top:`${u}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:`${Lt}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",d]},d));}return l};return jsxs("div",{className:`splice-tray-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${ct}px`,height:`${lt+Ge*io+dn}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"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:`${lt}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:t}),jsx("button",{onPointerDown:l=>{l.stopPropagation();},onMouseDown:l=>{l.stopPropagation();},onClick:l=>{l.stopPropagation(),l.preventDefault(),s(!n);},style:{background:n?"#10b981":"#374151",color:n?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${n?"Hide":"Show"} holder markers`,children:"H"})]}),a(),jsx("div",{style:{position:"absolute",top:lt,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var rr=({data:e,selected:o,id:t})=>{let{fibersPerTube:n=12,tubeIndex:s=1,startOn:a="left-center"}=e||{},l=e?.mode==="ribbon"||e?.ribbon===true,i=useEdges(),d=`tube-${s}`,u=i.find(ae=>ae.source===t&&ae.sourceHandle===d||ae.target===t&&ae.targetHandle===d),h=u?.data?.color,g=xe((s-1)%12+1),c=h||g,f=Math.max(1,Math.min(24,Number(n)||12)),x=14,C=4,k=1,S=2,I=20,E=f*x+(f-1)*C,D=Math.max(60,E+k*2+S*2),m=a==="left"?Position.Left:a==="right"?Position.Right:Position.Bottom,w=m!==Position.Bottom,R=w?14:20,F=w?8:20,W=w?`inset ${m===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",L=u?c:w?`linear-gradient(${m===Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${c}`:`radial-gradient(circle, ${c} 40%, transparent 70%)`,j={width:R,height:F,borderRadius:w?6:"50%",opacity:u?.3:.9,pointerEvents:"auto",background:L,backgroundColor:c,border:u?`2px solid ${c}`:`3px dashed ${c}`,cursor:"crosshair","--fiber-bg":c,boxShadow:u?W:`${W}${W!=="none"?", ":""}0 0 8px ${c}`,transition:"opacity 0.2s, box-shadow 0.2s",...m===Position.Left?{left:-(R-4)}:m===Position.Right?{right:-(R-4)}:{}},re=useMemo(()=>{let ae=[],se=D-S*2-k*2,Z,M,H=false;a==="left"?(Z=k,M=Position.Top):a==="right"?(Z=k+se-E,M=Position.Top,H=true):(Z=k+(se-E)/2,M=Position.Top);for(let A=0;A<f;A++){let z=H?f-A:A+1,X=ze(z),oe=xe(z),_=`fiber-${z}`,T=i.find(we=>we.source===t&&we.sourceHandle===_||we.target===t&&we.targetHandle===_),Q=null;T&&(T.data?.isRibbon||T.data?.ribbonFiberIds&&Array.isArray(T.data.ribbonFiberIds)?Q="#808080":Q=T.data?.color||null);let J=Z+A*(x+C),V=k,O={position:"absolute",left:`${J}px`,top:`${V}px`,width:x,height:x,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":Q||(l?"#808080":oe)};Q?O.backgroundColor=Q:l?O.backgroundColor="#808080":X.backgroundImage?O["--fiber-bg-image"]=X.backgroundImage:O.backgroundColor=oe,ae.push(jsxs(ft.Fragment,{children:[jsx(Handle,{id:_,type:"target",position:M,className:"tube-fiber-handle",isConnectable:true,style:O,"data-fiber-idx":z,"data-fiber-color":Q||(l?"#808080":oe)}),jsx(Handle,{id:_,type:"source",position:M,className:"tube-fiber-handle",isConnectable:true,style:O,"data-fiber-idx":z,"data-fiber-color":Q||(l?"#808080":oe)})]},`fiber-${z}`));}return ae},[f,a,D,i,t,x,C,k,S,E,l]);return jsxs("div",{style:{width:D,height:I,borderRadius:4,background:"#111827",border:`${S}px solid ${o?"#3b82f6":c}`,position:"relative",boxShadow:o?`0 0 0 ${S}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:k,boxSizing:"border-box",overflow:"visible"},children:[re,jsx(Handle,{id:d,type:"target",position:m,isConnectable:true,className:"tube-connection-handle",style:j,"data-tube-idx":s,"data-tube-color":c,title:u?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsx(Handle,{id:d,type:"source",position:m,isConnectable:true,className:"tube-connection-handle",style:j,"data-tube-idx":s,"data-tube-color":c,title:u?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var ar=({data:e,selected:o})=>{let{fiberCount:t,cableId:n="CBL-002",label:s,color:a,rotation:l}=e||{},i=ft.useRef(null);ft.useEffect(()=>{if(i.current){let M=typeof l=="number"?l:0;i.current.style.transform=`rotate(${M}deg)`,i.current.style.transformOrigin="center center";}},[l]);let d=Math.max(1,Math.min(24,Number(t)||12)),u=10,h=2,g=6,c=g+u+4,f=60,x=Math.max(120,d*(u+h)+g*2),k=s??`${d}f Cable`,S=n?`Cable ID ${n}`:void 0,I=xe(1),E=a||I,D=o?"#3b82f6":E,m=typeof l=="number"?l:0,w=M=>{let H=(M%360+360)%360;return H>=315||H<45?Position.Top:H>=45&&H<135?Position.Right:H>=135&&H<225?Position.Bottom:Position.Left},R=()=>{let M=[],H=w(m);for(let A=0;A<d;A++){let z=A+1,X=ze(z),oe=xe(z),_=g+A*(u+h),T=-5,Q=X.backgroundImage?X.backgroundImage:oe,J={position:"absolute",left:`${_}px`,top:`${T}px`,width:u,height:u,borderRadius:"50%",border:"none",background:Q,backgroundColor:oe,zIndex:10,cursor:"pointer","--fiber-bg":oe};X.backgroundImage&&(J["--fiber-bg-image"]=X.backgroundImage);let V=`fiber-${z}`;M.push(jsxs(ft.Fragment,{children:[jsx(Handle,{id:V,type:"target",position:H,className:"tube-fiber-handle",isConnectable:true,style:J,"data-fiber-idx":z,"data-fiber-color":oe}),jsx(Handle,{id:V,type:"source",position:H,className:"tube-fiber-handle",isConnectable:true,style:J,"data-fiber-idx":z,"data-fiber-color":oe})]},`fiber-${z}`));}return M},F="cable-button",W=8,L={width:W,height:W,borderRadius:"50%",background:E,backgroundColor:E,border:`1px solid ${E}`,cursor:"pointer",zIndex:10},j=2,ae=(M=>{let H=(M%360+360)%360;return H>=315||H<45?Position.Bottom:H>=45&&H<135?Position.Left:H>=135&&H<225?Position.Top:Position.Right})(m),se={width:x,height:f,position:"relative",transform:`rotate(${m}deg)`,transformOrigin:"center center","--rotation":`${m}deg`},Z={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${j}px solid ${D}`,boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:g,paddingTop:c,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsx("div",{ref:i,style:se,children:jsxs("div",{style:Z,children:[R(),jsx(Handle,{id:F,type:"source",position:ae,className:"cable-button-handle",isConnectable:true,style:L,"data-handle-type":"cable-button","data-cable-color":E}),jsx(Handle,{id:F,type:"target",position:ae,className:"cable-button-handle",isConnectable:true,style:L,"data-handle-type":"cable-button","data-cable-color":E}),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:k}),S&&jsx("div",{style:{fontSize:10,opacity:.8},children:S})]})]})})};var dr=({data:e,selected:o})=>{let{tubeCount:t=12,fibersPerTube:n=12,fiberCount:s,cableId:a="CBL-002",label:l,tubeStartIndex:i=1,color:d}=e||{},u=Math.max(1,Math.min(24,Number(t)||12)),h=Math.max(1,Number(i)||1),g=14,c=10,f=3,x=6,C=x+c+4,k=60,S=Math.max(120,u*(g+f)+x*2),I=s??u*(Number(n)||12),E=l??`${I}f Cable`,D=a?`Cable ID ${a}`:void 0,m=xe(h),w=d||m,R=o?"#3b82f6":w,F=()=>{let ae=[];for(let se=0;se<u;se++){let Z=h+se,M=ze(Z),H=xe(Z),A=x+se*(g+f),z=-5,X=M.backgroundImage?M.backgroundImage:H,oe={position:"absolute",left:`${A}px`,top:`${z}px`,width:g,height:c,borderRadius:6,border:"none",background:X,backgroundColor:H,zIndex:10,cursor:"pointer","--fiber-bg":H};M.backgroundImage&&(oe["--fiber-bg-image"]=M.backgroundImage);let _=`tube-${Z}`;ae.push(jsxs(ft.Fragment,{children:[jsx(Handle,{id:_,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:oe,"data-fiber-idx":Z,"data-tube-idx":Z,"data-tube-color":H}),jsx(Handle,{id:_,type:"source",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:oe,"data-fiber-idx":Z,"data-tube-idx":Z,"data-tube-color":H})]},`tube-${Z}`));}return ae},W="cable-button",L=8,j={width:L,height:L,borderRadius:"50%",background:w,backgroundColor:w,border:`1px solid ${w}`,cursor:"pointer",zIndex:10};return jsxs("div",{style:{width:S,height:k,borderRadius:4,background:"#111827",border:`2px solid ${R}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:x,paddingTop:C,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[F(),jsx(Handle,{id:W,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:j,"data-handle-type":"cable-button","data-cable-color":w}),jsx(Handle,{id:W,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:j,"data-handle-type":"cable-button","data-cable-color":w}),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:E}),D&&jsx("div",{style:{fontSize:10,opacity:.8},children:D})]})]})};var lr=({data:e,selected:o,id:t})=>{let{connector:n="LC",couplerFiberCount:s,label:a,portLabelsLeft:l,portLabelsRight:i}=e||{},d=useEdges(),u=typeof s=="number"&&[1,2,4].includes(s)?s:2,h=Math.max(1,Math.min(4,u)),g=9,c=3,f=3,x=60,C=30,k=h*g+(h-1)*c,S=Math.max(C,k+f*2),I=Math.max(x,80),E=(w,R)=>{let F=`${w}-${R+1}`;return d.find(L=>L.source===t&&L.sourceHandle===F||L.target===t&&L.targetHandle===F)?.data?.color||"#555"},D=w=>{let R=[],F=w==="left"?Position.Left:Position.Right,W=w==="left"?l:i;for(let L=0;L<h;L++){let j=L+1,re=`${w}-${j}`,ae=E(w,L),M=f+(S-k)/2+L*(g+c),H={position:"absolute",left:w==="left"?-5:void 0,right:w==="right"?-5:void 0,top:`${M}px`,width:g,height:g,borderRadius:"50%",border:"none",background:ae,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};R.push(jsxs(ft.Fragment,{children:[jsx(Handle,{id:re,type:"target",position:F,isConnectable:true,style:H}),jsx(Handle,{id:re,type:"source",position:F,isConnectable:true,style:H})]},re)),W&&W[L]&&R.push(jsx("div",{style:{position:"absolute",left:w==="left"?-30:void 0,right:w==="right"?-30:void 0,top:`${M}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:w==="left"?"right":"left",width:"25px"},children:W[L]},`${re}-label`));}return R},m=a||`${n}-${h}f`;return jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:I,height:S,borderRadius:4,border:`2px solid ${o?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:o?"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:[D("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:m})}),D("right")]})};var gt=32,fo=30,Zi=24,qi=80,po=400,go=300,hn=2,pt=8,mn=120;function ur(e){let{couplerFiberCount:o}=e.data||{},t=typeof o=="number"&&[1,2,4].includes(o)?o:2,n=Math.max(1,Math.min(4,t)),s=7,a=3,l=3,i=60,d=30,u=n*s+(n-1)*a,h=Math.max(d,u+l*2);return {width:Math.max(i,80),height:h}}function bo(e){let{fibersPerTube:o=12}=e.data||{},t=Math.max(1,Math.min(24,Number(o)||12)),n=14,s=4,a=1,l=2,i=20,d=t*n+(t-1)*s;return {width:Math.max(60,d+a*2+l*2),height:i}}function yn(e){return {width:ct,height:0}}function wn(e){return e.type==="coupler"?ur(e):e.type==="tube"?bo(e):e.type==="splice-tray"?yn():{width:80,height:30}}function cr(e){let o=0;for(let t of e){let n=wn(t),s=(t.position?.x||0)+n.width;s>o&&(o=s);}return o}function xn(e,o=0){let t=o;for(let n of e){let s=wn(n),a=(n.position?.y||0)+s.height;a>t&&(t=a);}return t}function Nn(e){return e.data?.panelWidth||po}function Ji(e){return e.data?.panelHeight||go}function kn(e){return Nn(e)-hn*2-pt*2}function Qi(e,o){return kn(e)-o}function Cn(e,o=fo){return Math.floor(e/o)+1}function vn(e,o=fo){return (e-1)*o}function ea(e,o,t){let n=fo,s=Cn(t.y,n),a=vn(s,n);return {x:t.x,y:a,slotPosition:s}}function pr(e,o){if(o.length===0)return {width:e.data?.panelWidth||po,height:e.data?.panelHeight||go};let t=o.some(d=>d.type==="tube"),n=o.some(d=>d.type==="splice-tray"),s=o.some(d=>d.type==="coupler"),a;if(t&&n&&s){let d=0,u=0;for(let c of o)if(c.type==="tube"){let f=bo(c);f.width>d&&(d=f.width);}else if(c.type==="coupler"){let f=ur(c);f.width>u&&(u=f.width);}let h=d+mn+ct+u+5,g=0;a=g+h+g;}else a=cr(o)+4;a=Math.max(e.data?.panelWidth||po,a);let l=xn(o,gt),i=Math.max(e.data?.panelHeight||go,l+pt);return {width:a,height:i}}function Sn(e,o,t){if(e===0)return 0;if(e===1)return o;let n=e*o,s=t-n,a=Math.max(5,s/(e-1));return o+a}function ta(e,o,t){return Sn(e,o,t)}var gn=20,fn=400,bn=300;function Hn(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||fn,height:e.data?.closureHeight||e.data?.panelHeight||bn};let t=o.some(i=>i.type==="tube"),n=o.some(i=>i.type==="splice-tray"),s;if(t&&n){let i=0,d=0,u=0,h=o.filter(c=>c.type==="tube"),g=o.filter(c=>c.type==="splice-tray");if(h.length>0&&g.length>0){let c=g.map(x=>x.position?.x||0),f=c.reduce((x,C)=>x+C,0)/c.length;for(let x of h){let C=bo(x);(x.position?.x||0)<f?C.width>i&&(i=C.width):C.width>d&&(d=C.width);}g.length>0&&(u=ct),s=pt+i+gn+u+gn+d+5;}else s=cr(o)+pt+5;}else s=cr(o)+pt+5;s=Math.max(e.data?.closureWidth||e.data?.panelWidth||fn,s);let a=xn(o,gt),l=Math.max(e.data?.closureHeight||e.data?.panelHeight||bn,a+pt);return {width:s,height:l}}var br=({data:e,selected:o,id:t})=>{let{label:n="Patch Panel",header:s,panelWidth:a,panelHeight:l}=e||{},{getNodes:i,setNodes:d}=useReactFlow(),u=useRef(false),h=useRef([]),g=useMemo(()=>{let E=i().filter(D=>D.parentId===t);return (E.length!==h.current.length||E.some((D,m)=>D.id!==h.current[m]?.id))&&(h.current=E),h.current},[i,t]),c=useMemo(()=>({id:t,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:a,panelHeight:l}}),[t,e,a,l]),f=useMemo(()=>a&&l?{width:a,height:l}:g.length===0?{width:a||400,height:l||300}:pr(c,g),[g,c,a,l]);useEffect(()=>{if(a&&l||u.current)return;let I=a,E=l,D=Math.abs((I||0)-f.width),m=Math.abs((E||0)-f.height);(D>1||m>1)&&(u.current=true,d(w=>w.map(R=>R.id===t?{...R,data:{...R.data,panelWidth:f.width,panelHeight:f.height}}:R)),setTimeout(()=>{u.current=false;},0));},[t,f.width,f.height,a,l,d]);let x=f.width,C=f.height,k=gt,S=s||n;return jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${x}px`,height:`${C}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"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:`${k}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:S})}),jsx("div",{style:{position:"absolute",top:k,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var yr=({data:e,selected:o,id:t})=>{let{label:n="Closure",header:s,closureWidth:a,closureHeight:l,panelWidth:i,panelHeight:d}=e||{},{getNodes:u,setNodes:h}=useReactFlow(),g=useRef(false),c=useRef([]),f=useMemo(()=>{let w=u().filter(R=>R.parentId===t);return (w.length!==c.current.length||w.some((R,F)=>R.id!==c.current[F]?.id))&&(c.current=w),c.current},[u,t]),x=useMemo(()=>({id:t,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:a||i,closureHeight:l||d}}),[t,e,a,l,i,d]),C=useMemo(()=>a&&l?{width:a,height:l}:i&&d?{width:i,height:d}:f.length===0?{width:a||i||400,height:l||d||300}:Hn(x,f),[f,x,a,l,i,d]);useEffect(()=>{if(a&&l||i&&d||g.current)return;let m=a||i,w=l||d,R=Math.abs((m||0)-C.width),F=Math.abs((w||0)-C.height);(R>1||F>1)&&(g.current=true,h(W=>W.map(L=>L.id===t?{...L,data:{...L.data,closureWidth:C.width,closureHeight:C.height}}:L)),setTimeout(()=>{g.current=false;},0));},[t,C.width,C.height,a,l,i,d,h]);let k=C.width,S=C.height,I=gt,E=s||n,D=k/2;return jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${D}px ${D}px 12px 12px`,padding:0,width:`${k}px`,height:`${S}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"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:`${I}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${D}px ${D}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:E})}),jsx("div",{style:{position:"absolute",top:I,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var xr=({data:e,selected:o,id:t})=>{let{label:n,splitterType:s="splitter",inputCount:a=1,outputCount:l=8}=e||{},i=useEdges(),d=n||(s==="WDM"?"WDM":"Splitter"),u=9,h=3,g=3,c=50,f=30,x=Math.min(Math.max(a||1,1),2),C=x*u+(x-1)*h,k=Math.min(l||8,48),S=k*u+(k-1)*h,I=Math.max(C,S),E=Math.max(f,I+g*2),D=Math.max(c,50),m=se=>i.find(M=>M.source===t&&M.sourceHandle===se||M.target===t&&M.targetHandle===se)?.data?.color||"#555",w=()=>{let se=[],Z=g+(E-C)/2;for(let M=0;M<x;M++){let H=`input-${M+1}`,A=Z+M*(u+h),z=m(H),X={position:"absolute",left:-5,top:`${A}px`,width:u,height:u,borderRadius:"50%",border:"none",background:z,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};se.push(jsxs(ft.Fragment,{children:[jsx(Handle,{id:`${H}-target`,type:"target",position:Position.Left,isConnectable:true,style:X}),jsx(Handle,{id:`${H}-source`,type:"source",position:Position.Left,isConnectable:true,style:X})]},H));}return se},R=()=>{let se=[],Z=g+(E-S)/2;for(let M=0;M<k;M++){let H=`output-${M+1}`,A=Z+M*(u+h),z=m(H),X={position:"absolute",right:-5,top:`${A}px`,width:u,height:u,borderRadius:"50%",border:"none",background:z,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};se.push(jsxs(ft.Fragment,{children:[jsx(Handle,{id:`${H}-target`,type:"target",position:Position.Right,isConnectable:true,style:X}),jsx(Handle,{id:`${H}-source`,type:"source",position:Position.Right,isConnectable:true,style:X})]},H));}return se},F=Math.max(C+g*4,f*.6),W=(E-F)/2,L=W+F,j=0,re=E,ae=o?"#3b82f6":"#4b5563";return jsxs("div",{className:`trapezoid-node ${o?"selected":""}`,style:{width:D,height:E,position:"relative",background:"transparent",boxShadow:o?"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:`${g}px`,boxSizing:"border-box"},children:[jsx("svg",{width:D,height:E,viewBox:`0 0 ${D} ${E}`,style:{position:"absolute",top:0,left:0,width:`${D}px`,height:`${E}px`,pointerEvents:"none",zIndex:0},children:jsx("polygon",{points:`0,${W} 0,${L} ${D},${re} ${D},${j}`,fill:"#1f2937",stroke:ae,strokeWidth:"2"})}),w(),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:d})}),R()]})};var In=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",xt=(e,o)=>In(e)||In(o),ie=(e,o)=>o?e?.type==="fibre-split"?o.replace(/-(source|target)$/i,""):o:o||"";function la(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let t=o.nodes.find(_=>_.id===e.source),n=o.nodes.find(_=>_.id===e.target),s=ie(t,e.sourceHandle),a=ie(n,e.targetHandle),l=o.edges.some(_=>_.source===e.source?ie(t,_.sourceHandle)===s:_.target===e.source?ie(t,_.targetHandle)===s:false),i=o.edges.some(_=>_.target===e.target?ie(n,_.targetHandle)===a:_.source===e.target?ie(n,_.sourceHandle)===a:false),d=xt(t,n);if((l||i)&&!d)return l?{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 u=(_,T)=>(_?.type==="tube"||_?.type==="cable")&&!!T&&T.startsWith("fiber-"),h=(_,T)=>(_?.type==="tube"||_?.type==="multi-tube-cable")&&!!T&&T.startsWith("tube-"),g=(_,T)=>_?.type==="multi-tube-cable"&&!!T&&T.startsWith("tube-"),c=(_,T)=>_?.type==="tube"&&!!T&&T.startsWith("tube-"),f=(_,T)=>(_?.type==="cable"||_?.type==="multi-tube-cable")&&T==="cable-button",x=(_,T)=>_?.type==="splice"&&(T==="left"||T==="right"),C=(_,T)=>_?.type==="coupler"&&!!T&&(T.startsWith("left-")||T.startsWith("right-")),k=(_,T)=>{if(_?.type!=="fibre-split"||!T)return false;let Q=ie(_,T);return Q.startsWith("input-")||Q.startsWith("output-")};if(!d)return {valid:true};if(t?.type==="splice"&&n?.type==="splice"){let _=t.data?.mode==="ribbon",T=n.data?.mode==="ribbon";if(_!==T)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let S=u(t,e.sourceHandle),I=u(n,e.targetHandle),E=x(t,e.sourceHandle),D=x(n,e.targetHandle),m=C(t,e.sourceHandle),w=C(n,e.targetHandle),R=k(t,e.sourceHandle),F=k(n,e.targetHandle),W=f(t,e.sourceHandle),L=f(n,e.targetHandle),j=g(t,e.sourceHandle),re=g(n,e.targetHandle),ae=c(t,e.sourceHandle),se=c(n,e.targetHandle),Z=h(t,e.sourceHandle),M=h(n,e.targetHandle);return S&&D||I&&E||(E&&(w||F)||D&&(m||R))||(m&&(w||F||D)||w&&(m||R||E))||W&&L||(j&&se||re&&ae)?{valid:true}:Z&&M?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function yo(e,o){if(!o)return;let t=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,n=o.data??{},s=n.handleSideMap;if(s&&s[t])return s[t];if(t==="net-top"||t==="net-bottom")return "front";if(t==="pwr-left-1"||t==="pwr-left-2"||t==="net-right-1"||t==="net-right-2")return "rear";let a=Array.isArray(n.ports)?n.ports:[],l=Array.isArray(n.rearPorts)?n.rearPorts:[];if(t.startsWith("pwr")||t.includes("power"))return "rear";for(let d of a)for(let u of d.ports||[])if((!!u.type&&String(u.type).includes("power")?u.label:`${d.name}-${u.label}`)===t)return "front";for(let d of l)for(let u of d.ports||[])if((!!u.type&&String(u.type).includes("power")?u.label:`${d.name}-${u.label}`)===t)return "rear"}function Nr(e={},o={}){let t={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},n=new Set;return {getState:()=>t,setState:g=>{t={...t,...g},n.forEach(c=>c(t));},subscribe:g=>(n.add(g),()=>n.delete(g)),selectEdgeZIndex:g=>{let c=t.nodes.find(m=>m.id===g.target);if(!c||c.type!=="device")return 1e3;let f=c.data?.view||"front",x=yo(g.targetHandle||"",c);if(x)return f===x?1e3:500;let C=(g.targetHandle||"").toString(),k=C.toLowerCase(),S=k.startsWith("pwr")||k.startsWith("power"),I=k.startsWith("net-")||k.startsWith("port-")||k.startsWith("uplink-")||k.includes("fiber")||k.includes("ports"),E=/^[A-Z0-9]+-\d+$/i.test(C)&&!k.startsWith("pwr")&&!k.startsWith("power"),D=I||E;return S?f==="rear"?1e3:500:D?f==="front"?1e3:500:1e3},validateConnection:g=>(o.validateConnection||la)(g,t),selectNodeById:g=>t.nodes.find(c=>c.id===g),selectConnectedEdges:g=>t.edges.filter(c=>c.source===g||c.target===g)}}function ca(e){let o=s=>e.subscribe(s),t=()=>e.getState();return useSyncExternalStore(o,t,t)}function Cr(e){let o=n=>e.subscribe(n),t=()=>e.getState().nodes;return useSyncExternalStore(o,t,t)}function vr(e){let o=n=>e.subscribe(n),t=()=>e.getState().edges;return useSyncExternalStore(o,t,t)}function Fn(e){return e.selectEdgeZIndex}function Tn(e){let o=e.data.rackWidthPx||300,t=(e.data.uHeight||42)*20,n=e.position.x,s=e.position.x+o,a=e.position.y,l=e.position.y+t;return {left:n,right:s,top:a,bottom:l}}function wo(e,o){let t=Tn(o);return e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom}function xo(e,o){let t=null,n=1/0;for(let s of o){if(!wo(e,s))continue;let a=Math.sqrt(Math.pow(e.x-s.position.x,2)+Math.pow(e.y-s.position.y,2));a<n&&(n=a,t=s);}return t}function He(e){let{edges:o,connection:t,edgeType:n,selectEdgeZIndex:s,findBy:a,data:l}=e,i=a==="source"?t.sourceHandle:t.targetHandle,d=a==="source"?t.source:t.target;if(!i||!d)return null;let u=o.find(C=>a==="source"?C.source===d&&C.sourceHandle===i:C.target===d&&C.targetHandle===i);if(!u)return null;let h=o.filter(C=>C.id!==u.id),g=addEdge(t,h),c=g[g.length-1],f=s({...t,id:c.id,type:n}),x={...c,type:n,zIndex:f,style:{...c.style,zIndex:f},data:l!==void 0?l:c.data};return [...g.slice(0,-1),x]}function Wn(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var Ce=({type:e,children:o})=>{let t=ft.useRef(null),n=ft.useCallback(s=>{if(t.current=s,s){let a=s.parentElement,l=0;for(;a&&!a.classList.contains("react-flow__node")&&l<10;)a=a.parentElement,l++;a&&a.classList.contains("react-flow__node")&&a.setAttribute("data-type",e);}},[e]);return ft.useEffect(()=>{if(t.current){let s=t.current.parentElement,a=0;for(;s&&!s.classList.contains("react-flow__node")&&a<10;)s=s.parentElement,a++;s&&s.classList.contains("react-flow__node")&&s.setAttribute("data-type",e);}},[e]),jsx("div",{ref:n,style:{width:"100%",height:"100%"},children:o})},Mn=(e,o,t)=>({rack:n=>jsx(Ce,{type:"rack",children:jsx(zo,{...n,onViewChange:e,onRackFaceChange:o,isDragOver:t?t()===n.id:false})}),fiber:n=>jsx(Ce,{type:"fiber",children:jsx(Ao,{...n})}),device:n=>jsx(Ce,{type:"device",children:jsx(mt,{...n})}),server:n=>jsx(Ce,{type:"server",children:jsx(mt,{...n})}),switch:n=>jsx(Ce,{type:"switch",children:jsx(mt,{...n})}),router:n=>jsx(Ce,{type:"router",children:jsx(mt,{...n})}),"vertical-pdu":n=>jsx(Ce,{type:"vertical-pdu",children:jsx(Go,{...n})}),splice:n=>jsx(Ce,{type:"splice",children:jsx(qo,{...n})}),"splice-tray":n=>jsx(Ce,{type:"splice-tray",children:jsx(or,{...n})}),tube:n=>jsx(Ce,{type:"tube",children:jsx(rr,{...n})}),cable:n=>jsx(Ce,{type:"cable",children:jsx(ar,{...n})}),"multi-tube-cable":n=>jsx(Ce,{type:"multi-tube-cable",children:jsx(dr,{...n})}),coupler:n=>jsx(Ce,{type:"coupler",children:jsx(lr,{...n})}),"patch-panel":n=>jsx(Ce,{type:"patch-panel",children:jsx(br,{...n})}),closure:n=>jsx(Ce,{type:"closure",children:jsx(yr,{...n})}),"fibre-split":n=>jsx(Ce,{type:"fibre-split",children:jsx(xr,{...n})})}),Ca={fiber:ro,ethernet:ro,power:Oo,smoothstep:Kr,step:Jr,"thick-cable":tn},va=({nodes:e,edges:o,initialNodes:t,initialEdges:n,onNodesChange:s,onEdgesChange:a,store:l,debug:i,onNodeClick:d,onEdgeClick:u,nodeTypes:h,edgeTypes:g,onConnect:c,onEdgeUpdate:f,isValidConnection:x,connectionMode:C,onViewChange:k,onRackFaceChange:S,className:I,style:E,alignRacksToBottom:D,colorMode:m="dark",onInit:w,onFlowMethods:R,showDownloadButton:F=false,downloadButtonPosition:W="top-right",downloadButtonText:L="Download Image",downloadButtonStyle:j,useSmoothstepEdgesForTubes:re=false,connectOnClick:ae=true,panOnDrag:se=true,panOnScroll:Z=true,zoomOnScroll:M=true,fitViewOptions:H})=>{let A=useCallback((r,p)=>{let b=new Map,y=[],v=[],P=($,q)=>!$||!q?false:!!($.startsWith("tube-")||q.type==="splice"&&($==="left"||$==="right")||$==="cable-button");for(let $ of r){if(!$.source||!$.target||!$.sourceHandle||!$.targetHandle){i&&console.warn("Invalid edge skipped (missing source/target/handles):",$);continue}let q=p.find(Pe=>Pe.id===$.source),K=p.find(Pe=>Pe.id===$.target),be=`${$.source}:${$.sourceHandle}`,ce=b.get(be),ve=P($.sourceHandle,q),me=`${$.target}:${$.targetHandle}`,pe=b.get(me),te=P($.targetHandle,K);if(ce&&!ve){i&&console.warn("Duplicate connection detected on source handle, removing:",{handle:be,existingEdge:ce.id,duplicateEdge:$.id}),v.push($);continue}if(pe&&!te){i&&console.warn("Duplicate connection detected on target handle, removing:",{handle:me,existingEdge:pe.id,duplicateEdge:$.id}),v.push($);continue}y.push($),ce||b.set(be,$),pe||b.set(me,$);}return i&&v.length>0&&console.log(`Filtered ${v.length} duplicate edge(s) from initial edges`),y},[i]),z=Array.isArray(e)&&Array.isArray(o),X=ft.useMemo(()=>z?e||[]:t||e||[],[z,e,t]),oe=ft.useMemo(()=>z?o||[]:n||o||[],[z,o,n]),_=ft.useMemo(()=>A(oe,X),[oe,X,A]),T=ft.useMemo(()=>l||Nr({nodes:X,edges:_,debug:i}),[l,z,i,_]),Q=Cr(T),J=vr(T),[V,O,we]=useNodesState(Q),[Fe,G,he]=useEdgesState(J),ue=Fn(T),qe=useRef(null),[ke,Je]=useState(false);useEffect(()=>{let r=()=>{Je(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return r(),window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[]);let{toObject:vo,setViewport:So,setNodes:Vt,setEdges:jt,getNodes:$e,getEdges:_e,fitView:Ho}=useReactFlow();useEffect(()=>{R&&R({toObject:vo,setViewport:So,setNodes:r=>{Vt(r),T.setState({nodes:r});},setEdges:r=>{jt(r),T.setState({edges:r});},toImage:r=>qe.current?toPng(qe.current,r):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>$e(),getEdges:()=>_e(),fitView:r=>{if(r?.nodes&&Array.isArray(r.nodes)&&r.nodes.length>0){let p=r.nodes.map(v=>$e().find(P=>P.id===v)).filter(v=>v!==void 0),{nodes:b,...y}=r;Ho({...y,nodes:p});}else {let{nodes:p,...b}=r||{};Ho(b);}}});},[R,vo,So,Vt,jt,T,Ho,$e,_e]);let ti=useCallback(()=>{if(!qe.current){i&&console.error("ReactFlow wrapper ref is not available");return}toPng(qe.current,{filter:r=>!(r?.classList?.contains("react-flow__minimap")||r?.classList?.contains("react-flow__controls")||r?.classList?.contains("react-flow__attribution")||r?.classList?.contains("download-button")||r?.tagName==="BUTTON"),backgroundColor:m==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(r=>{let p=document.createElement("a");p.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,p.href=r,p.click();}).catch(r=>{i&&console.error("Error downloading image:",r);});},[m,i]),[Ir,Yt]=useState(null),Fr=useRef(null),Tr=useRef(k),Dr=useRef(S);useEffect(()=>{Tr.current=k;},[k]),useEffect(()=>{Dr.current=S;},[S]),useEffect(()=>{Fr.current=Ir;},[Ir]);let Po=useCallback((r,p)=>{Tr.current?.(r,p);},[]),Eo=useCallback((r,p)=>{Dr.current?.(r,p);},[]),Ro=useCallback(()=>Fr.current,[]),$r=useRef({...Mn(Po,Eo,Ro),...h??{}});useEffect(()=>{$r.current={...Mn(Po,Eo,Ro),...h??{}};},[Po,Eo,Ro,h]);let oi=useMemo(()=>({...Ca,...g??{}}),[g]),Be=useRef(V);useEffect(()=>{Be.current=V;},[V]);let ee=useRef(Fe);useEffect(()=>{ee.current=Fe;},[Fe]),useEffect(()=>{O(Q);},[Q,O]),useEffect(()=>{G(J);},[J,G]),useEffect(()=>{if(z&&o){let r=A(o,e||[]);r.length!==o.length&&(i&&console.warn(`Controlled edges had ${o.length-r.length} duplicate(s) removed`),a?.(r));}},[z,o,e,A,a,i]),useEffect(()=>{z&&T.setState({nodes:e||[]});},[z,e,T]),useEffect(()=>{z&&T.setState({edges:o||[]});},[z,o,T]),useEffect(()=>{if(!D||!V||V.length===0)return;let r=V.filter(K=>K.type==="rack");if(r.length===0)return;let p=r.map(K=>{let ce=K.data?.uHeight||42,ve=60+ce*20;return (K.position?.y||0)+ve}),b=Math.min(...p),y=Math.max(...p);if(y-b<20)return;let P=y,$=V.map(K=>{if(K.type!=="rack")return K;let ce=K.data?.uHeight||42,ve=60+ce*20,me=(K.position?.y||0)+ve,pe=P-me;return Math.abs(pe)<5?K:{...K,position:{x:K.position?.x||0,y:(K.position?.y||0)+pe}}});$.some((K,be)=>K.position!==V[be].position)&&O($);},[D,V,O]);let Io=useRef(new Map);useEffect(()=>{let r=new Map;V.forEach(p=>{r.set(p.id,p);}),Io.current=r;},[V]);let fe=useCallback(r=>Io.current.get(r),[]),Pt=useCallback((r,p)=>{if(!r||!p)return;let b=fe(r);if(!b)return;let y=p.replace(/-(source|target)$/i,"");if(b.type==="fibre-split"&&y.startsWith("output-")){let P=ee.current.filter($=>$.target===r&&($.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(P.length>0){let $=P[0]?.data?.color;if($)return {color:$}}}if((b.type==="tube"||b.type==="cable")&&p.startsWith("fiber-")){let P=p.replace("fiber-",""),$=parseInt(P,10);if($>=1&&$<=24){let q=it($),K=$>12;return {color:q,striped:K}}}if((b.type==="multi-tube-cable"||b.type==="tube")&&p.startsWith("tube-")){let P=p.replace("tube-",""),$=parseInt(P,10);if($>=1&&$<=24){let q=xe($),K=$>12;return {color:q,striped:K}}}let v=b.data;if(v.color)return {color:v.color}},[fe]),_r=useRef(new Map);useEffect(()=>{G(r=>{let p=false,b=r.map(y=>{let v=ue(y);return _r.current.get(y.id)!==v?(p=true,_r.current.set(y.id,v),{...y,zIndex:v,style:{...y.style,zIndex:v}}):y});return p?b:r});},[V,G,ue]),useEffect(()=>{let r=V.map(b=>{if(b.type==="coupler"&&b.parentId){let y=fe(b.parentId);if(y&&(y.type==="patch-panel"||y.type==="closure")&&(!b.extent||b.extent!=="parent"))return {...b,extent:"parent"}}if(b.type==="splice"&&b.parentId&&b.data.holderPosition&&(!b.position||b.position.x===0&&b.position.y===0)){let y=fe(b.parentId);if(y&&y.type==="splice-tray"){let v=b.data.mode==="ribbon",P=At(y,b.data.holderPosition,v);return {...b,position:P}}}if(b.type==="device"&&b.parentId&&b.data.uPosition&&(!b.position||b.position.x===0&&b.position.y===0)){let y=fe(b.parentId);if(y){let v=bt(y,b.data.uPosition);return {...b,position:v}}}return b});r.some((b,y)=>{let v=V[y];return b.extent!==v.extent||b.position?.x!==v.position?.x||b.position?.y!==v.position?.y})&&O(r);},[V,O,fe]);let ri=useCallback(r=>{let p=r.map(b=>{if(b.type==="position"&&b.position){let y=fe(b.id);if(y&&y.type==="coupler"&&y.parentId){let v=fe(y.parentId);if(v&&(v.type==="patch-panel"||v.type==="closure")){if(!y.extent||y.extent!=="parent"){let P={...y,extent:"parent"};O($=>$.map(q=>q.id===y.id?P:q));}return {...b,position:y.position||{x:0,y:0}}}}if(y&&(y.type==="tube"||y.type==="splice-tray")&&y.parentId){let v=fe(y.parentId);if(v&&v.type==="closure"){if(!y.extent||y.extent!=="parent"){let P={...y,extent:"parent"};O($=>$.map(q=>q.id===y.id?P:q));}return {...b,position:y.position||{x:0,y:0}}}}if(y&&y.type==="splice"&&y.parentId){let v=fe(y.parentId);if(v&&v.type==="splice-tray"){let P=Qo(y,v,b.position,Be.current);if(P.holderPosition!==void 0){let $={...y,data:{...y.data,holderPosition:P.holderPosition}};O(q=>q.map(K=>K.id===y.id?$:K));}return {...b,position:{x:P.x,y:P.y}}}}if(y&&y.type==="device"&&y.parentId){let v=fe(y.parentId);if(v){let P=Mo(y,v,b.position,Be.current);if(P.uPosition!==void 0){let $={...y,data:{...y.data,uPosition:P.uPosition}};O(q=>q.map(K=>K.id===y.id?$:K));}return {...b,position:{x:P.x,y:P.y}}}}if(y&&y.type==="device"&&y.parentId){let v=fe(y.parentId);if(v){let P=v;if(!wo(b.position,P)){let $=b.position.x+P.position.x,q=b.position.y+P.position.y,K={...y,parentId:void 0,extent:void 0,data:{...y.data,uPosition:void 0}};return O(be=>be.map(ce=>ce.id===y.id?K:ce)),{...b,position:{x:$,y:q}}}}}}return b});we(p);},[we,O,fe]),ni=useCallback((r,p)=>{Yt(null);},[]),ii=useCallback((r,p,b)=>{if(p.type==="device"&&!p.parentId){let y=Be.current.filter(P=>P.type==="rack").map(P=>P),v=xo(p.position,y);Yt(v?.id??null);}else Yt(null);},[]),ai=useCallback((r,p,b)=>{if(p.type==="device"&&!p.parentId){let y=Be.current.filter(P=>P.type==="rack").map(P=>P),v=xo(p.position,y);if(v){let P=p.position.x-v.position.x,$=p.position.y-v.position.y,q={...p,parentId:v.id,extent:"parent",position:{x:P,y:$},data:{...p.data,uPosition:1}},K=Be.current.map(be=>be.id===p.id?q:be);O(K),z||T.setState({nodes:K});}}Yt(null);},[O,z,T]),si=useCallback(r=>{if(!r.source||!r.target||!r.sourceHandle||!r.targetHandle)return true;let p=fe(r.source),b=fe(r.target),y=ie(p,r.sourceHandle),v=ie(b,r.targetHandle),P=ee.current.some(U=>U.source===r.source?ie(p,U.sourceHandle)===y:U.target===r.source?ie(p,U.targetHandle)===y:false),$=ee.current.some(U=>U.target===r.target?ie(b,U.targetHandle)===v:U.source===r.target?ie(b,U.sourceHandle)===v:false);P&&i&&console.log("Connection will replace: Source handle already connected",{source:r.source,sourceHandle:r.sourceHandle,existingEdges:ee.current.filter(U=>U.source===r.source&&U.sourceHandle===r.sourceHandle||U.target===r.source&&U.targetHandle===r.sourceHandle)}),$&&i&&console.log("Connection will replace: Target handle already connected",{target:r.target,targetHandle:r.targetHandle,existingEdges:ee.current.filter(U=>U.target===r.target&&U.targetHandle===r.targetHandle||U.source===r.target&&U.sourceHandle===r.targetHandle)});let q=xt(p,b);if((P||$)&&!q)return i&&console.log("Connection rejected: Non-fiber handle already connected",r),false;if(!q)return true;if(p?.type==="splice"&&b?.type==="splice"){let U=p.data?.mode==="ribbon",ge=b.data?.mode==="ribbon";if(U!==ge)return i&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",r),false}let K=(U,ge)=>(U?.type==="tube"||U?.type==="cable")&&!!ge&&ge.startsWith("fiber-"),be=(U,ge)=>(U?.type==="tube"||U?.type==="multi-tube-cable")&&!!ge&&ge.startsWith("tube-"),ce=(U,ge)=>U?.type==="multi-tube-cable"&&!!ge&&ge.startsWith("tube-"),ve=(U,ge)=>U?.type==="tube"&&!!ge&&ge.startsWith("tube-"),me=(U,ge)=>(U?.type==="cable"||U?.type==="multi-tube-cable")&&ge==="cable-button",pe=(U,ge)=>U?.type==="splice"&&(ge==="left"||ge==="right"),te=(U,ge)=>U?.type==="coupler"&&!!ge&&(ge.startsWith("left-")||ge.startsWith("right-")),Pe=(U,ge)=>{if(U?.type!=="fibre-split"||!ge)return false;let zr=ge.replace(/-(source|target)$/i,"");return zr.startsWith("input-")||zr.startsWith("output-")},Me=K(p,r.sourceHandle),Qe=K(b,r.targetHandle),le=pe(p,r.sourceHandle),et=pe(b,r.targetHandle),tt=te(p,r.sourceHandle),Xt=te(b,r.targetHandle),Et=Pe(p,r.sourceHandle),Gt=Pe(b,r.targetHandle),Do=me(p,r.sourceHandle),Kt=me(b,r.targetHandle),$o=ce(p,r.sourceHandle),_o=ce(b,r.targetHandle),Wo=ve(p,r.sourceHandle),N=ve(b,r.targetHandle),B=be(p,r.sourceHandle),ne=be(b,r.targetHandle);return Me&&et||Qe&&le||(le&&(Xt||Gt)||et&&(tt||Et))||(tt&&(Xt||Gt||et)||Xt&&(tt||Et||le))||Do&&Kt||($o&&N||_o&&Wo)?true:B&&ne?(i&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",r),false):(i&&console.log("Connection rejected: Connection not allowed by fiber rules",r),false)},[fe,i]),di=useCallback(r=>{i&&console.log("onConnect called:",r);let p=fe(r.source),b=fe(r.target);i&&(console.log("onConnect: sourceNode type:",p?.type,"targetNode type:",b?.type),console.log("onConnect: sourceHandle:",r.sourceHandle,"targetHandle:",r.targetHandle));let y=T.validateConnection({source:r.source??null,target:r.target??null,sourceHandle:r.sourceHandle??null,targetHandle:r.targetHandle??null});if(!y.valid){i&&console.warn(`Connection rejected: ${y.reason}`);return}let v=p?.type==="vertical-pdu",P=p?.data,$=p?.type==="device"&&P?.deviceType==="switch",q=!!r.targetHandle&&(r.targetHandle.startsWith("pwr")||r.targetHandle.startsWith("power")),K=!!r.targetHandle&&(r.targetHandle.startsWith("net-")||r.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(r.targetHandle)),be=p?.type==="tube"&&b?.type==="multi-tube-cable",ce=p?.type==="multi-tube-cable"&&b?.type==="tube",ve=be||ce,me=r.sourceHandle==="cable-button"&&r.targetHandle==="cable-button",pe="fiber";v&&q?pe="power":me?pe="thick-cable":ve&&(pe=re?"smoothstep":"fiber");let te,Pe=Wn(b),Me=Wn(p);if(Pe||Me){let N=b?.data,B=p?.data,ne=Pe?N.ribbonFiberIds:B.ribbonFiberIds;ne&&Array.isArray(ne)&&ne.length>=6&&ne.length<=12&&(te={ribbonFiberIds:ne,isRibbon:true});}if(!te&&(pe==="fiber"||pe==="smoothstep")&&!v){let N;be?N=Pt(r.target,r.targetHandle):N=Pt(r.source,r.sourceHandle),N&&(te={color:N.color,striped:N.striped,isRibbon:false});}else if(pe==="thick-cable"&&me){let N=p?.data;te={color:N?.color||(N?.tubeStartIndex?xe(N.tubeStartIndex):"#6366f1")};}let Qe=ie(p,r.sourceHandle),le=ie(b,r.targetHandle),et=ee.current.some(N=>N.source===r.source?ie(p,N.sourceHandle)===Qe:N.target===r.source?ie(p,N.targetHandle)===Qe:false),tt=ee.current.some(N=>N.target===r.target?ie(b,N.targetHandle)===le:N.source===r.target?ie(b,N.sourceHandle)===le:false);if(xt(p,b)&&(et||tt)){let N=new Set;for(let B of ee.current){if(B.source===r.source&&ie(p,B.sourceHandle)===Qe){N.add(B.id);continue}if(B.target===r.source&&ie(p,B.targetHandle)===Qe){N.add(B.id);continue}if(B.source===r.target&&ie(b,B.sourceHandle)===le){N.add(B.id);continue}B.target===r.target&&ie(b,B.targetHandle)===le&&N.add(B.id);}if(N.size>0){let B=ee.current.filter(Ve=>!N.has(Ve.id)),ne=addEdge(r,B),Ee=ne[ne.length-1],Re=ue({...r,id:Ee.id,type:pe}),Ue={...Ee,type:pe,zIndex:Re,style:{...Ee.style,zIndex:Re},data:te!==void 0?te:Ee.data};G([...ne.slice(0,-1),Ue]),i&&console.log("Fiber handle replacement: Replaced",N.size,"edge(s)");return}}if(b?.type==="splice"&&(r.targetHandle==="left"||r.targetHandle==="right")&&r.target&&r.targetHandle){let N=ee.current.find(B=>B.target===r.target&&B.targetHandle===r.targetHandle||B.source===r.target&&B.sourceHandle===r.targetHandle);if(N){i&&(console.log("Splice target handle replacement: Found existing edge",N.id,"on splice handle",r.targetHandle),console.log("Existing edge details:",{id:N.id,source:N.source,target:N.target,sourceHandle:N.sourceHandle,targetHandle:N.targetHandle,data:N.data}));let B=r.source&&r.sourceHandle?ee.current.find(U=>U.source===r.source&&U.sourceHandle===r.sourceHandle):null;i&&B&&console.log("Splice target handle replacement: Also found existing source edge",B.id);let ne=new Set;N&&ne.add(N.id),B&&B.id!==N.id&&ne.add(B.id);let Ee=ee.current.filter(U=>!ne.has(U.id));i&&console.log("Splice target handle replacement: Removing",ne.size,"edge(s), creating new connection");let Re=`edge-${r.source}-${r.sourceHandle}-${r.target}-${r.targetHandle}-${Date.now()}`,Ue=ue({...r,id:Re,type:"fiber"}),Ve={id:Re,source:r.source,target:r.target,sourceHandle:r.sourceHandle,targetHandle:r.targetHandle,type:"fiber",zIndex:Ue,style:{zIndex:Ue},data:te!==void 0?te:{}},Zt=[...Ee,Ve];G(Zt),i&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Ve.id);return}}if(p?.type==="splice"&&r.sourceHandle==="right"&&r.source&&r.sourceHandle){let N=ee.current.find(B=>B.source===r.source&&B.sourceHandle===r.sourceHandle||B.target===r.source&&B.targetHandle===r.sourceHandle);if(N){i&&console.log("Splice source handle replacement: Found existing edge",N.id,"on splice handle",r.sourceHandle);let B=r.target&&r.targetHandle?ee.current.find(U=>U.target===r.target&&U.targetHandle===r.targetHandle):null;i&&B&&console.log("Splice source handle replacement: Also found existing target edge",B.id);let ne=new Set;N&&ne.add(N.id),B&&B.id!==N.id&&ne.add(B.id);let Ee=ee.current.filter(U=>!ne.has(U.id));i&&console.log("Splice source handle replacement: Removing",ne.size,"edge(s), creating new connection");let Re=`edge-${r.source}-${r.sourceHandle}-${r.target}-${r.targetHandle}-${Date.now()}`,Ue=ue({...r,id:Re,type:"fiber"}),Ve={id:Re,source:r.source,target:r.target,sourceHandle:r.sourceHandle,targetHandle:r.targetHandle,type:"fiber",zIndex:Ue,style:{zIndex:Ue},data:te!==void 0?te:{}},Zt=[...Ee,Ve];G(Zt),i&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Ve.id);return}}if((p?.type==="tube"||p?.type==="cable")&&r.sourceHandle?.startsWith("fiber-")&&r.source&&r.sourceHandle){let N=He({edges:ee.current,connection:r,edgeType:"fiber",selectEdgeZIndex:ue,findBy:"source",data:te});if(N){G(N);return}}if((b?.type==="tube"||b?.type==="cable")&&r.targetHandle?.startsWith("fiber-")&&r.target&&r.targetHandle){let N=He({edges:ee.current,connection:r,edgeType:"fiber",selectEdgeZIndex:ue,findBy:"target",data:te});if(N){G(N);return}}if((p?.type==="multi-tube-cable"||p?.type==="tube")&&r.sourceHandle?.startsWith("tube-")&&r.source&&r.sourceHandle){let N=He({edges:ee.current,connection:r,edgeType:pe,selectEdgeZIndex:ue,findBy:"source",data:te});if(N){G(N);return}}if((b?.type==="multi-tube-cable"||b?.type==="tube")&&r.targetHandle?.startsWith("tube-")&&r.target&&r.targetHandle){let N=He({edges:ee.current,connection:r,edgeType:pe,selectEdgeZIndex:ue,findBy:"target",data:te});if(N){G(N);return}}if(p?.type==="coupler"&&(r.sourceHandle?.startsWith("left-")||r.sourceHandle?.startsWith("right-"))){let N=He({edges:ee.current,connection:r,edgeType:"fiber",selectEdgeZIndex:ue,findBy:"source",data:te});if(N){G(N);return}}if(b?.type==="coupler"&&(r.targetHandle?.startsWith("left-")||r.targetHandle?.startsWith("right-"))){let N=He({edges:ee.current,connection:r,edgeType:"fiber",selectEdgeZIndex:ue,findBy:"target",data:te});if(N){G(N);return}}if(me&&r.source&&r.sourceHandle&&r.target&&r.targetHandle){let N=p?.data,B=N?.color||(N?.tubeStartIndex?xe(N.tubeStartIndex):"#6366f1"),ne=He({edges:ee.current,connection:r,edgeType:"thick-cable",selectEdgeZIndex:ue,findBy:"source",data:{color:B}});if(ne){G(ne);return}if(ne=He({edges:ee.current,connection:r,edgeType:"thick-cable",selectEdgeZIndex:ue,findBy:"target",data:{color:B}}),ne){G(ne);return}}if(v&&q&&r.target&&r.targetHandle){let N=He({edges:ee.current,connection:r,edgeType:"power",selectEdgeZIndex:ue,findBy:"target",data:te});if(N){G(N);return}}if($&&K&&r.target&&r.targetHandle){let N=He({edges:ee.current,connection:r,edgeType:"fiber",selectEdgeZIndex:ue,findBy:"target",data:te});if(N){G(N);return}}let Et=T.validateConnection({source:r.source??null,target:r.target??null,sourceHandle:r.sourceHandle??null,targetHandle:r.targetHandle??null});if(!Et.valid){if(v&&r.source&&r.sourceHandle){let N=He({edges:ee.current,connection:r,edgeType:q?"power":"fiber",selectEdgeZIndex:ue,findBy:"source",data:te});if(N){G(N);return}}if($&&r.source&&r.sourceHandle){let N=He({edges:ee.current,connection:r,edgeType:"fiber",selectEdgeZIndex:ue,findBy:"source",data:te});if(N){G(N);return}}i&&console.warn(`Connection rejected: ${Et.reason}`);return}let Gt=ee.current.some(N=>N.source===r.source&&N.sourceHandle===r.sourceHandle||N.target===r.source&&N.targetHandle===r.sourceHandle),Do=ee.current.some(N=>N.target===r.target&&N.targetHandle===r.targetHandle||N.source===r.target&&N.sourceHandle===r.targetHandle),Kt=(N,B)=>!N||!B?false:!!(N.startsWith("tube-")||B.type==="splice"&&(N==="left"||N==="right")||N==="cable-button"),$o=Kt(r.sourceHandle||"",p),_o=Kt(r.targetHandle||"",b);if(Gt&&!$o){i&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:r.source,sourceHandle:r.sourceHandle,existingEdges:ee.current.filter(N=>N.source===r.source&&N.sourceHandle===r.sourceHandle||N.target===r.source&&N.targetHandle===r.sourceHandle)});return}if(Do&&!_o){i&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:r.target,targetHandle:r.targetHandle,existingEdges:ee.current.filter(N=>N.target===r.target&&N.targetHandle===r.targetHandle||N.source===r.target&&N.sourceHandle===r.targetHandle)});return}let Wo={...r,type:pe,zIndex:ue({...r,id:"temp-id"}),data:te};G(N=>{let B=addEdge(Wo,N),ne=B[B.length-1];return ne&&(Mr(Ee=>new Set(Ee).add(ne.id)),setTimeout(()=>{Mr(Ee=>{let Re=new Set(Ee);return Re.delete(ne.id),Re});},1e3)),B});},[G,T,ue,fe,i,Pt,re]),li=useCallback((r,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let b=T.validateConnection({source:p.source??null,target:p.target??null,sourceHandle:p.sourceHandle??null,targetHandle:p.targetHandle??null});if(!b.valid){i&&console.warn(`Edge update rejected: ${b.reason}`);return}let y=fe(p.source),v=fe(p.target),P=y?.type==="vertical-pdu",$=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),q=y?.type==="tube"&&v?.type==="multi-tube-cable",K=y?.type==="multi-tube-cable"&&v?.type==="tube",be=q||K,ce;P&&$?ce="power":be?ce=re?"smoothstep":"fiber":ce="fiber";let ve;if((ce==="fiber"||ce==="smoothstep")&&!P){let me=Pt(p.source,p.sourceHandle);me&&(ve={color:me.color,striped:me.striped});}G(me=>{let pe=xt(y,v),te=ie(y,p.sourceHandle),Pe=ie(v,p.targetHandle);return (pe?me.filter(le=>{if(le.id===r.id)return true;let et=le.source===p.source&&ie(y,le.sourceHandle)===te||le.target===p.source&&ie(y,le.targetHandle)===te,tt=le.target===p.target&&ie(v,le.targetHandle)===Pe||le.source===p.target&&ie(v,le.sourceHandle)===Pe;return !(et||tt)}):me).map(le=>le.id===r.id?{...le,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:ce,data:ve!==void 0?{...le.data,...ve}:le.data,zIndex:ue({...p,id:le.id,type:ce}),style:{...le.style,zIndex:ue({...p,id:le.id,type:ce})}}:le)});},[G,fe,Pt,ue,re,i,T]),ci=useCallback((r,p)=>{if(ke){d&&d(p);return}let b=r.metaKey||r.ctrlKey;if(p.type==="tube"&&p.parentId&&!b){let v=$e().find(P=>P.id===p.parentId&&(P.type==="cable"||P.type==="multi-tube-cable"));if(v){O(P=>P.map($=>({...$,selected:$.id===v.id}))),d&&d(v);return}}if(b&&p.type==="device"){let y=p.data||{},v=y.view||(Array.isArray(y.rearPorts)&&y.rearPorts.length>0?"rear":"front"),P=v==="front"?"rear":"front";i&&console.log(`Command+click: Toggling device ${p.id} from ${v} to ${P}`),k&&k(p.id,P),d&&d(p);}else d&&d(p);},[k,d,i,$e,O,ke]),ui=useCallback(()=>{},[]),pi=useCallback((r,p)=>{u&&u(p);},[u]),[We,Fo]=useState(null),[Wr,Mr]=useState(new Set);useOnSelectionChange({onChange:({nodes:r,edges:p})=>{if(Lr(p||[]),!ke)if(r&&r.length===1){let b=r[0];if(b.type==="tube"&&b.parentId){let v=$e().find(P=>P.id===b.parentId&&(P.type==="cable"||P.type==="multi-tube-cable"));if(v){Fo(v),O(P=>P.map($=>({...$,selected:$.id===v.id}))),d&&d(v);return}}Fo(b),d&&d(b);}else Fo(null),d&&d(null);}});let[To,Lr]=useState([]);useEffect(()=>{let r=p=>{if((p.key==="Backspace"||p.key==="Delete")&&To.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let b=To.filter(y=>{let v=y.sourceHandle||"",P=y.targetHandle||"";return v.startsWith("tube-")||P.startsWith("tube-")?(i&&console.log("Cannot delete edge connected to tube handle",y),false):true});if(b.length>0){let y=new Set(b.map(v=>v.id));G(v=>v.filter(P=>!y.has(P.id))),Lr([]),i&&console.log("Deleted edges:",b.map(v=>v.id));}}};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[To,G,i]);let gi=useCallback((r,{nodeId:p,handleType:b})=>{i&&console.log("Connection started from",{nodeId:p,handleType:b});},[i]),fi=useCallback(r=>{i&&console.log("Connection ended",r);},[i]),bi=useCallback(()=>{if(!We)return;let r=fe(We.id);if(r){if(r.type==="rack"){let y=((r.data||{}).face||"front")==="front"?"rear":"front";S?(S(r.id,y),k&&$e().filter(P=>P.parentId===r.id).forEach(P=>{k(P.id,y);})):O(v=>v.map(P=>P.id===r.id?{...P,data:{...P.data,face:y}}:P.parentId===r.id?{...P,data:{...P.data,view:y}}:P));return}if(r.type==="device"){let p=r.data||{},b=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,y=Array.isArray(p.ports)&&p.ports.length>0,P=(p.view||(b&&!y?"rear":"front"))==="front"?"rear":"front";k?k(r.id,P):O($=>$.map(q=>q.id===r.id?{...q,data:{...q.data,view:P}}:q));}}},[We,fe,S,k,O,$e]),hi=useMemo(()=>{let r=Io.current;return Fe.map(p=>{let b=p,y=r.get(String(b.source)),v=r.get(String(b.target)),P=yo(b.sourceHandle||"",y),$=yo(b.targetHandle||"",v),q=y&&y.data?.view,K=v&&v.data?.view,be=y?.type==="device"&&q==="rear",ce=v?.type==="device"&&K==="rear",pe=be&&P!=="rear"||ce&&$!=="rear",te=p.style;if(pe)te={...p.style,opacity:0,pointerEvents:"none",zIndex:0};else if(p.style&&p.style.opacity===0&&p.style.pointerEvents==="none"&&p.style.zIndex===0){let Me={...p.style};delete Me.opacity,delete Me.pointerEvents,delete Me.zIndex,te=Object.keys(Me).length>0?Me:void 0;}return {...p,style:te,className:Wr.has(p.id)?"edge-connecting":p.className}})},[Fe,Wr]),mi=Or(m,I),yi=Ur(m,{touchAction:"none",...E});return jsxs("div",{ref:qe,className:mi,style:yi,children:[jsxs(ReactFlow,{nodes:V,edges:hi,onNodesChange:r=>{ri(r),z?s&&s(Be.current):T.setState({nodes:Be.current});},onEdgesChange:r=>{let p=r.filter(b=>{if(b.type==="remove"){let y=ee.current.find(v=>v.id===b.id);if(y){let v=y.sourceHandle||"",P=y.targetHandle||"";if(v.startsWith("tube-")||P.startsWith("tube-"))return i&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",y),false}}return true});if(p.length>0){let b=applyEdgeChanges(p,ee.current);he(p),z?a&&a(b):T.setState({edges:b});}},onConnect:c??di,onConnectStart:gi,onConnectEnd:fi,onEdgeUpdate:f??li,isValidConnection:x??si,connectionMode:C,onNodeClick:ci,onNodeDoubleClick:ui,onNodeDragStart:ni,onNodeDrag:ii,onNodeDragStop:ai,onEdgeClick:pi,onInit:w,nodeTypes:$r.current,edgeTypes:oi,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:!ke,nodesConnectable:true,elementsSelectable:!ke,edgesFocusable:!ke,selectNodesOnDrag:false,connectOnClick:ae,panOnDrag:se,panOnScroll:Z&&!ke,zoomOnScroll:M&&!ke,preventScrolling:ke,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:H,proOptions:{hideAttribution:true},children:[jsx(Background,{color:Br(m)}),jsx(Controls,{}),!ke&&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"})})]}),F&&jsx("button",{className:"download-button",onClick:ti,style:{position:"absolute",top:W.includes("top")?"10px":"auto",bottom:W.includes("bottom")?"10px":"auto",right:W.includes("right")?"10px":"auto",left:W.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:"pointer",transition:"all 0.2s ease",...j},children:L}),We&&(We.type==="rack"||We.type==="device")&&jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsx("button",{onClick:r=>{r.preventDefault(),bi();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let r=We.data;if(We.type==="rack")return (r?.face||"front")==="front"?"Switch to rear":"Switch to front";{let p=Array.isArray(r?.rearPorts)&&r.rearPorts.length>0,b=Array.isArray(r?.ports)&&r.ports.length>0;return (r?.view||(p&&!b?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let r=We.data;if(We.type==="rack")return (r?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let p=Array.isArray(r?.rearPorts)&&r.rearPorts.length>0,b=Array.isArray(r?.ports)&&r.ports.length>0;return (r?.view||(p&&!b?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},Sr=e=>jsx(ReactFlowProvider,{children:jsx(va,{...e})});var Hr=class extends Component{constructor(){super(...arguments);this.state={error:null};this.reset=()=>{this.setState({error:null});};}static getDerivedStateFromError(t){return {error:t}}componentDidCatch(t,n){this.props.onError?.(t,n);}render(){let{error:t}=this.state,{children:n,fallback:s}=this.props;return t?typeof s=="function"?s(t,this.reset):s??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"}),": ",t.message,jsx("button",{type:"button",onClick:this.reset,style:{marginLeft:12,padding:"4px 8px",cursor:"pointer"},children:"Try again"})]}):n}};function Ut(e,{rowHeight:o,tubeGap:t}){let n=[],s=[],a=e.kind??(e.tubeCount?"tube":"simple"),l=a==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,i=a==="tube"?Math.max(1,Math.min(24,e.fibersPerTube??12)):Math.max(1,Math.min(24,e.fiberCount??12)),d=Math.max(1,e.tubeStartIndex??1),u=Math.max(1,e.fiberStartIndex??1),h=0;for(let g=0;g<l;g+=1){let c=d+g,f=e.tubeColorMap?.[c];s.push({tubeIndex:c,y:h,label:`T${c}`,color:f??xe(c)});for(let x=0;x<i;x+=1){let C=u+x,k=ze(C);n.push({key:`${c}-${C}`,tubeIndex:a==="tube"?c:void 0,fiberIndex:C,y:h,color:it(C),striped:nt(C),backgroundImage:typeof k.backgroundImage=="string"?k.backgroundImage:void 0}),h+=o;}g<l-1&&(h+=t);}return {rows:n,tubeLabels:s,height:h}}var Un=e=>`fiber-${e.tube??1}-${e.fiber}`,Vn=e=>it(e.fiber),jn=e=>nt(e.fiber),Ra=(e,o)=>{if(o)return o;if(!(typeof e!="number"||Number.isNaN(e)))return e>=1e3?`${(e/1e3).toFixed(1)} km`:`${Math.round(e)} m`},Ia=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,data:i})=>{let[d,u,h]=getBezierPath({sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,curvature:.35}),g=typeof i?.lossDb=="number"?`${i.lossDb.toFixed(2)} dB`:"",c=i?.label??g,f=i?.sourceColor,x=i?.targetColor,C=i?.color??f??x??"#94a3b8",k=i?.sourceStriped??false,S=i?.targetStriped??false,I=i?.highlighted??true,E=i?.dimmed??false,D=i?.circuitId,m=i?.circuitLabel??D,w=i?.showCircuitId??false,R=f&&x&&f!==x,F=n-o,W=s-t,L=Math.sqrt(F*F+W*W),j=u-o,re=h-t,ae=Math.sqrt(j*j+re*re),se=L>0?ae/L*100:50,Z=`fibre-flow-gradient-${e}`,M=k&&!S,H=S&&!k,A=k&&S,z=L*1.25,X=z/2,oe=12,_=Math.ceil(X*1.2/oe),T=Array(_).fill("6 6").join(" "),Q=Math.ceil(X*1.2/oe),J=Array(Q).fill("6 6").join(" "),V=w&&m,O=Math.max(c?c.length*6.2+16:0,V?(m?.length||0)*5.5+16:0),we=V?32:16;return jsxs(Fragment,{children:[jsx("defs",{children:R&&jsxs("linearGradient",{id:Z,x1:o,y1:t,x2:n,y2:s,gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0%",stopColor:f}),jsx("stop",{offset:`${se}%`,stopColor:f}),jsx("stop",{offset:`${se}%`,stopColor:x}),jsx("stop",{offset:"100%",stopColor:x})]})}),R?jsx("path",{id:e,d,fill:"none",stroke:`url(#${Z})`,strokeWidth:I?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:E?.25:1,strokeOpacity:E?.25:1,style:{mixBlendMode:"normal"}}):jsx(BaseEdge,{id:e,path:d,style:{stroke:C,strokeWidth:I?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:E?.25:1,strokeOpacity:E?.25:1,mixBlendMode:"normal"}}),(A||M||H)&&jsx("path",{id:`${e}-stripe`,d,fill:"none",stroke:"#000",strokeWidth:I?1.6:1.3,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:M?`${T} ${z}`:H?`${X} ${J} ${z}`:"6 6",strokeDashoffset:0,opacity:E?.2:.9,style:{mixBlendMode:"normal"}}),(c||V)&&I&&jsx(EdgeLabelRenderer,{children:jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${u}px, ${h}px)`,width:O,height:we,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:[c&&jsx("div",{style:{lineHeight:1.2},children:c}),V&&jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:c?2:0},children:m})]})})]})},Fa=({id:e,sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,data:i})=>{let[d,u,h]=getBezierPath({sourceX:o,sourceY:t,targetX:n,targetY:s,sourcePosition:a,targetPosition:l,curvature:.2}),g=i?.label,c=i?.color??"#64748b";return jsxs(Fragment,{children:[jsx(BaseEdge,{id:e,path:d,style:{stroke:c,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),g&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${u}px, ${h}px)`,padding:"2px 8px",background:"rgba(30, 41, 59, 0.9)",border:`1px solid ${c}`,borderRadius:10,fontSize:10,fontFamily:"monospace",color:"#e2e8f0",letterSpacing:.2,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9999},children:g})})]})},Ta=({data:e})=>{let{cable:o,side:t,rowHeight:n,columnWidth:s,showTubeLabels:a,showFiberNumbers:l,layout:i,colorMode:d="dark"}=e,u=d==="light",h=8,g=12,c=-1,f=0,x=o.jacketColor??"#facc15",C=(o.kind??(o.tubeCount?"tube":"simple"))==="tube",k=a&&C,S=t==="left"?h+f:f,I=t==="right"?h+f:f,E=t==="left"?Position.Right:Position.Left,D={width:4,height:4,borderRadius:"50%",background:x,border:`1px solid ${x}`,boxShadow:"0 0 1px rgba(0,0,0,0.4)",top:"50%",position:"absolute",...t==="left"?{left:0,transform:"translate(-50%, -50%)"}:{right:0,transform:"translate(50%, -50%)"}};return jsxs("div",{style:{position:"relative",width:s,height:i.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[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:u?"rgba(248, 250, 252, 0.95)":"rgba(15, 23, 42, 0.9)",color:u?"#1a1a1a":"#f8fafc",padding:"2px 6px",borderRadius:4,whiteSpace:"nowrap",maxWidth:s,overflow:"hidden",textOverflow:"ellipsis",zIndex:10,...t==="right"?{textAlign:"right"}:{}},children:o.label}),jsx("div",{style:{position:"absolute",top:0,bottom:0,width:h,left:t==="left"?0:void 0,right:t==="right"?0:void 0,borderRadius:4,background:C?"transparent":x,border:`1px solid ${x}`,boxShadow:C?"none":"inset 0 0 3px rgba(0,0,0,0.3)",overflow:"hidden"},children:C&&i.tubeLabels.map((m,w)=>{let R=i.rows.filter(ae=>ae.tubeIndex===m.tubeIndex);if(R.length===0)return null;let F=R[0].y,W=R[R.length-1].y+n,L=W-F,j=i.tubeLabels[w+1],re=j&&j.y-W>0;return jsx("div",{style:{position:"absolute",top:F,left:0,right:0,height:L,background:m.color,borderLeft:`2px solid ${m.color}`,borderRight:`2px solid ${m.color}`,borderTop:w===0?`2px solid ${m.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:re?"1px solid rgba(0,0,0,0.15)":`2px solid ${m.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:w===0&&!re||w===0?"4px 4px 0 0":re?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${m.tubeIndex}`)})}),!k&&jsx("div",{style:{position:"absolute",top:0,bottom:0,left:S,right:I,...t==="left"?{borderRight:`1px solid ${x}`}:{borderLeft:`1px solid ${x}`},pointerEvents:"none",zIndex:0}}),C&&i.tubeLabels.map((m,w)=>{let R=i.rows.filter(j=>j.tubeIndex===m.tubeIndex);if(R.length===0)return null;let F=R[0].y,L=R[R.length-1].y+n-F;return jsx("div",{style:{position:"absolute",top:F,left:S,right:I,height:L,...t==="left"?{borderRight:`2px solid ${m.color}`}:{borderLeft:`2px solid ${m.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${m.tubeIndex}`)}),i.rows.map(m=>{let w=`fiber-${m.tubeIndex??1}-${m.fiberIndex}`,R=m.y+n/2,F={position:"absolute",width:g,height:g,borderRadius:"50%",top:R,background:m.backgroundImage?m.backgroundImage:m.color,backgroundColor:m.color,border:`2px solid ${m.color}`,boxShadow:"0 0 6px rgba(0,0,0,0.3)",...t==="left"?{right:-g/2}:{left:-g/2},transform:"translateY(-50%)",zIndex:1e3,cursor:"crosshair","--fiber-bg":m.color,minWidth:g,minHeight:g};m.backgroundImage&&(F["--fiber-bg-image"]=m.backgroundImage);let W=t==="left"?{right:g+c,textAlign:"right"}:{left:g+c,textAlign:"left"};return jsxs(ft.Fragment,{children:[jsx(Handle,{id:w,type:"source",position:E,className:"fibre-flow-handle",style:F,isConnectable:true,"data-fiber-idx":m.fiberIndex,"data-tube-idx":m.tubeIndex,"data-fiber-color":m.color}),jsx(Handle,{id:w,type:"target",position:E,className:"fibre-flow-handle",style:F,isConnectable:true,"data-fiber-idx":m.fiberIndex,"data-tube-idx":m.tubeIndex,"data-fiber-color":m.color}),l&&jsx("div",{style:{position:"absolute",top:m.y+n/2-6,...W,fontSize:8,fontWeight:600,color:u?"rgba(15, 23, 42, 0.7)":"rgba(148, 163, 184, 0.95)",whiteSpace:"nowrap",lineHeight:1},children:m.fiberIndex})]},m.key)}),jsx(Handle,{id:"cable-run",type:"source",position:t==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:D,isConnectable:true,"data-handle-type":"cable-run"}),jsx(Handle,{id:"cable-run",type:"target",position:t==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:D,isConnectable:true,"data-handle-type":"cable-run"})]})},Da=({data:e})=>{let o=e.colorMode==="light";return jsx("div",{style:{width:e.width,height:e.height,background:"transparent",border:o?"1px solid rgba(148, 163, 184, 0.3)":"1px solid rgba(148, 163, 184, 0.5)",borderRadius:12,boxShadow:o?"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:o?"rgba(15, 23, 42, 0.9)":"rgba(226, 232, 240, 0.9)",background:o?"rgba(241, 245, 249, 0.7)":"rgba(15, 23, 42, 0.6)",borderBottom:o?"1px solid rgba(148, 163, 184, 0.2)":"1px solid rgba(148, 163, 184, 0.35)",borderTopLeftRadius:12,borderTopRightRadius:12},children:e.label})})},$a=(e,o,t,n,s,a,l,i,d,u="dark")=>{let h=[],g=0;return e.forEach(c=>{let f=Ut(c.leftCable,{rowHeight:t,tubeGap:n}),x=Ut(c.rightCable,{rowHeight:t,tubeGap:n}),C=Math.max(f.height,x.height),k=a*2+l,S=32,I=16,E=k+I*2,D=C+S+I*2,m=`flow-closure-${c.id}`,w=`flow-cable-${c.id}-left`,R=`flow-cable-${c.id}-right`,F=o==="horizontal"?{x:g,y:0}:{x:0,y:g};g+=(o==="horizontal"?E:D)+s;let W=c.chamberId?`${c.id} - ${c.chamberId}`:c.id;h.push({id:m,type:"fibre-flow-closure",position:F,data:{label:W,width:E,height:D,headerHeight:S,colorMode:u},selectable:false,draggable:false,style:{width:E,height:D}});let L=S+I+(C-f.height)/2,j=S+I+(C-x.height)/2;h.push({id:w,type:"fibre-flow-cable",position:{x:I,y:L},parentId:m,extent:"parent",data:{label:c.leftCable.label,cable:c.leftCable,side:"left",rowHeight:t,columnWidth:a,showTubeLabels:i,showFiberNumbers:d,layout:f,colorMode:u},style:{width:a,height:f.height}}),h.push({id:R,type:"fibre-flow-cable",position:{x:I+k-a,y:j},parentId:m,extent:"parent",data:{label:c.rightCable.label,cable:c.rightCable,side:"right",rowHeight:t,columnWidth:a,showTubeLabels:i,showFiberNumbers:d,layout:x,colorMode:u},style:{width:a,height:x.height}});}),h},_a=(e,o,t,n=false)=>{let s=[],a=new Map,l=new Map,i=new Map;return (o??[]).forEach(d=>{d.color&&a.set(d.id,d.color),d.label&&l.set(d.id,d.label);}),e.forEach(d=>{let u=`flow-cable-${d.id}-left`,h=`flow-cable-${d.id}-right`;[{nodeId:u,cable:d.leftCable},{nodeId:h,cable:d.rightCable}].forEach(({nodeId:c,cable:f})=>{let x=i.get(f.id);if(x&&x.closureId!==d.id){let C=Ra(f.distanceMeters??x.distanceMeters,f.distanceLabel??x.distanceLabel),k=f.jacketColor??x.jacketColor??"#64748b";s.push({id:`flow-link-${x.nodeId}-${c}`,type:"fibre-flow-link",source:x.nodeId,target:c,sourceHandle:"cable-run",targetHandle:"cable-run",data:{label:C,color:k}});}i.set(f.id,{nodeId:c,closureId:d.id,jacketColor:f.jacketColor,distanceLabel:f.distanceLabel,distanceMeters:f.distanceMeters});}),d.splices.forEach(c=>{let f=t?c.circuitId===t:true,x=!!t&&!f,C=c.circuitId?a.get(c.circuitId):void 0,k=c.circuitId?l.get(c.circuitId):void 0,S=c.color??C,I=Vn(c.from),E=Vn(c.to),D=jn(c.from),m=jn(c.to);s.push({id:`flow-edge-${d.id}-${c.id}`,type:"fibre-flow",source:u,target:h,sourceHandle:Un(c.from),targetHandle:Un(c.to),data:{lossDb:c.lossDb,label:c.label,color:S,sourceColor:I,targetColor:E,sourceStriped:D,targetStriped:m,highlighted:f,dimmed:x,circuitId:c.circuitId,circuitLabel:k,showCircuitId:n}});});}),s},Wa=({closures:e,circuits:o,highlightedCircuitId:t,layout:n="horizontal",rowHeight:s=20,tubeGap:a=10,closureGap:l=140,cableColumnWidth:i=32,spliceAreaWidth:d=260,showTubeLabels:u=true,showFiberNumbers:h=true,colorMode:g="dark",showCircuitId:c=false,className:f,style:x,panOnDrag:C=true,panOnScroll:k=true,zoomOnScroll:S=true})=>{let I=useMemo(()=>$a(e,n,s,a,l,i,d,u,h,g),[e,n,s,a,l,i,d,u,h,g]),E=useMemo(()=>_a(e,o,t,c),[e,o,t,c]),[D,m]=useState(I),[w,R]=useState(E);useEffect(()=>{m(I);},[I,m]),useEffect(()=>{R(E);},[E,R]);let F=useCallback((H,A)=>{if(!H||!A||!A.startsWith("fiber-"))return;let z=D.find(J=>J.id===H);if(!z||z.type!=="fibre-flow-cable")return;let X=/^fiber-(\d+)-(\d+)$/.exec(A);if(!X)return;let oe=Number(X[1]),_=Number(X[2]),Q=z.data.layout.rows.find(J=>(J.tubeIndex??1)===oe&&J.fiberIndex===_);if(Q)return {color:Q.color,striped:Q.striped??false}},[D]),W=useCallback(H=>{if(!H.source||!H.target||!H.sourceHandle||!H.targetHandle)return false;let A=D.find(T=>T.id===H.source),z=D.find(T=>T.id===H.target);if(!A||!z)return false;let X=typeof H.sourceHandle=="string"&&H.sourceHandle.startsWith("fiber-"),oe=typeof H.targetHandle=="string"&&H.targetHandle.startsWith("fiber-");return H.sourceHandle==="cable-run"||H.targetHandle==="cable-run"?true:X&&oe?A.type==="fibre-flow-cable"&&z.type==="fibre-flow-cable":false},[D]),L=useCallback(H=>{let A=H.sourceHandle==="cable-run"||H.targetHandle==="cable-run",z=V=>typeof V=="string"&&V.startsWith("fiber-"),X=z(H.sourceHandle),oe=z(H.targetHandle),_=(V,O,we)=>V.source===O&&V.sourceHandle===we||V.target===O&&V.targetHandle===we,T=A?void 0:F(H.source,H.sourceHandle),Q=A?void 0:F(H.target,H.targetHandle),J=A?void 0:{sourceColor:T?.color,targetColor:Q?.color,color:T?.color??Q?.color,sourceStriped:T?.striped,targetStriped:Q?.striped};R(V=>{let O=V.filter(we=>{let Fe=X&&_(we,H.source,H.sourceHandle),G=oe&&_(we,H.target,H.targetHandle);return !(Fe||G)});return addEdge({...H,type:A?"fibre-flow-link":"fibre-flow",data:J},O)});},[F,R]),j=useCallback((H,A)=>{let z=A.sourceHandle==="cable-run"||A.targetHandle==="cable-run",X=z?void 0:F(A.source,A.sourceHandle),oe=z?void 0:F(A.target,A.targetHandle),_=z?void 0:{sourceColor:X?.color,targetColor:oe?.color,color:X?.color??oe?.color,sourceStriped:X?.striped,targetStriped:oe?.striped},T=J=>typeof J=="string"&&J.startsWith("fiber-"),Q=(J,V,O)=>J.source===V&&J.sourceHandle===O||J.target===V&&J.targetHandle===O;R(J=>{let V=J.filter(G=>G.id!==H.id),O=T(A.sourceHandle),we=T(A.targetHandle),Fe=V.filter(G=>{let he=O&&Q(G,A.source,A.sourceHandle),ue=we&&Q(G,A.target,A.targetHandle);return !(he||ue)});return addEdge({...A,type:z?"fibre-flow-link":"fibre-flow",data:_},Fe)});},[F,R]),re=useCallback(H=>{m(H);},[m]),ae=useCallback(H=>{R(H);},[R]),se=useMemo(()=>({"fibre-flow-cable":Ta,"fibre-flow-closure":Da}),[]),Z=useMemo(()=>({"fibre-flow":Ia,"fibre-flow-link":Fa}),[]),M={borderRadius:8,overflow:"hidden",...x};return jsx(Sr,{nodes:D,edges:w,onNodesChange:re,onEdgesChange:ae,onConnect:L,onEdgeUpdate:j,isValidConnection:W,connectionMode:ConnectionMode.Loose,nodeTypes:se,edgeTypes:Z,className:f,style:M,colorMode:g,panOnDrag:C,panOnScroll:k,zoomOnScroll:S,fitViewOptions:{padding:.2}})},Ma=e=>jsx(Wa,{...e});var Aa=({cable:e,side:o,rowHeight:t=22,tubeGap:n=10,columnWidth:s=150,layout:a,showTubeLabels:l,showFiberNumbers:i=true,showCableLabel:d=true})=>{let u=useMemo(()=>a??Ut(e,{rowHeight:t,tubeGap:n}),[a,e,t,n]),h=26,g=10,c=18,f=o==="left"?s-c:c,x=8,C=o==="left"?6:s-h-18,k=e.jacketColor??"#facc15",S=l??(e.kind??(e.tubeCount?"tube":"simple"))==="tube";return jsxs("div",{style:{position:"relative",width:s,height:u.height,fontFamily:"monospace",color:"inherit"},children:[d&&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:"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:h,left:o==="left"?0:void 0,right:o==="right"?0:void 0,borderRadius:14,background:`linear-gradient(90deg, ${k} 0%, ${k} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${k}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),S&&u.tubeLabels.map(I=>jsxs("div",{style:{position:"absolute",top:I.y+t/2-6,left:C,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:I.color,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 3px rgba(0,0,0,0.25)"}}),jsx("span",{children:I.label})]},`tube-${I.tubeIndex}`)),u.rows.map(I=>{let E=I.y+t/2-g/2,D=o==="left"?f-g/2-x:f+g/2+x;return jsxs(ft.Fragment,{children:[jsx("div",{style:{position:"absolute",top:E,left:f-g/2,width:g,height:g,borderRadius:"50%",backgroundColor:I.color,backgroundImage:I.backgroundImage,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 4px rgba(0,0,0,0.25)"}}),i&&jsx("div",{style:{position:"absolute",top:I.y+t/2-6,left:D,transform:o==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:I.fiberIndex})]},I.key)})]})};var Zn=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}}),qn=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}}),Jn=e=>{let o=s=>{if(!s)return;if(typeof s=="string")return s;let a=s.device;return typeof a=="object"&&a?a.id:a},t=o(e.termination_a),n=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${t}`,target:`device-${n}`,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}}},Oa=e=>{let o=[],t=[];return e.racks.forEach(n=>o.push(Zn(n))),e.devices.forEach(n=>o.push(qn(n))),e.cables.forEach(n=>t.push(Jn(n))),{nodes:o,edges:t}},Ba=e=>{let o=e.filter(s=>s.type==="rack"),t=e.filter(s=>s.type==="device"),n=e.filter(s=>!["rack","device"].includes(s.type));return o.forEach((s,a)=>{s.position={x:a*300,y:100};}),t.forEach(s=>{if(s.parentId){let a=o.find(l=>l.id===s.parentId);if(a){let l=s.data.uPosition||1,i=s.data.uHeight||1;s.position={x:a.position.x+50,y:a.position.y+l*20-i*10};}}else s.position={x:Math.random()*400+100,y:Math.random()*200+50};}),n.forEach((s,a)=>{s.position={x:a*150+100,y:300};}),e};function Co(e){let{items:o,checkOutOfBounds:t,checkConflicts:n}=e,s=[],a=[];for(let l of o){let i=t(l);i&&!i.isValid&&i.error&&a.push(i.error);}for(let l=0;l<o.length;l++){let i=o[l];for(let d=l+1;d<o.length;d++){let u=o[d],h=n(i,u);h&&h.hasConflict&&h.conflict&&s.push(h.conflict);}}return {isValid:s.length===0&&a.length===0,conflicts:s,outOfBounds:a}}var St=class extends Error{constructor(t,n,s,a,l){super(`Device placement conflict: ${n} at U${s}-${s+a-1} in rack ${t}${l?` conflicts with ${l}`:""}`);this.rackId=t;this.deviceId=n;this.uPosition=s;this.uHeight=a;this.conflictWith=l;this.name="DevicePlacementError";}};function Er(e,o={}){return Co({items:e.devices,checkOutOfBounds:t=>t.unit+t.height-1>e.units?{isValid:false,error:{deviceId:t.id,uPosition:t.unit,uHeight:t.height,rackUHeight:e.units}}:null,checkConflicts:(t,n)=>{let s=t.unit,a=t.unit+t.height-1,l=n.unit,i=n.unit+n.height-1;return s<=i&&a>=l?{hasConflict:true,conflict:{deviceId:t.id,uPosition:t.unit,uHeight:t.height,conflictWith:n.id}}:null}})}function Qn(e,o,t={}){let{deviceTypeMapping:n={}}=t,s=n[e.type]||"device",a=bt(o,e.unit,e.height);return {id:e.id,type:s,position:a,parentId:o.id,extent:"parent",data:{label:e.name,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:o.data.rackWidthPx}}}function Ua(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}}}function Va(e,o={}){let{conflictPolicy:t="strict",validatePlacements:n=true}=o,s=[],a=[];if(n)for(let l of e){let i=Er(l,o);if(!i.isValid&&t==="strict"){let d=[];throw i.conflicts.forEach(u=>{d.push(`Device ${u.deviceId} at U${u.uPosition}-${u.uPosition+u.uHeight-1} conflicts with ${u.conflictWith}`);}),i.outOfBounds.forEach(u=>{d.push(`Device ${u.deviceId} at U${u.uPosition}-${u.uPosition+u.uHeight-1} exceeds rack height (${u.rackUHeight}U)`);}),new St(l.id,i.conflicts[0]?.deviceId||i.outOfBounds[0]?.deviceId||"unknown",i.conflicts[0]?.uPosition||i.outOfBounds[0]?.uPosition||1,i.conflicts[0]?.uHeight||i.outOfBounds[0]?.uHeight||1)}}for(let l of e){let i=Ua(l);s.push(i);for(let d of l.devices)try{let u=Qn(d,i,o);a.push(u);}catch(u){if(t==="strict")throw u;if(t==="nearest"){let h=eo(i,{id:d.id,data:{label:d.name,uHeight:d.height}},a,d.unit);if(h!==d.unit){console.warn(`Device ${d.id} moved from U${d.unit} to U${h} due to conflict`);let g={...d,unit:h},c=Qn(g,i,o);a.push(c);}else throw new St(l.id,d.id,d.unit,d.height)}}}return s.push(...a),s}function ja(e){let o=[],t=e.filter(n=>n.type==="rack");for(let n of t){let a=e.filter(l=>l.type==="device"&&l.parentId===n.id).map(l=>({id:l.id,name:l.data.label,unit:l.data.uPosition||1,height:l.data.uHeight||1,type:l.data.deviceType||"server",width:l.data.width,ports:l.data.ports,connections:l.data.connections,frontImageUrl:l.data.frontImageUrl,rearImageUrl:l.data.rearImageUrl,frontImageAttribution:l.data.frontImageAttribution,rearImageAttribution:l.data.rearImageAttribution,imageFit:l.data.imageFit,imagePosition:l.data.imagePosition,imageRepeat:l.data.imageRepeat,stretchToFit:l.data.stretchToFit}));o.push({id:n.id,name:n.data.label,position:n.position,units:n.data.uHeight||42,uNumberingDirection:n.data.uNumberingDirection||"bottom-up",customHeaderText:n.data.customHeaderText,devices:a,rackWidthPx:n.data.rackWidthPx});}return o}function Ya(e,o,t,n){return e.map(s=>s.id!==o?s:{...s,devices:s.devices.map(a=>a.id!==t?a:{...a,unit:n})})}function Xa(e,o,t,n={}){let{conflictPolicy:s="strict"}=n;return e.map(a=>{if(a.id!==o)return a;if(s==="strict"&&!Er({...a,devices:[...a.devices,t]},n).isValid)throw new St(o,t.id,t.unit,t.height);return {...a,devices:[...a.devices,t]}})}function Ga(e,o,t){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.filter(s=>s.id!==t)})}var Ht=class extends Error{constructor(t,n,s,a){super(`Splice placement conflict: ${n} at holder ${s} in tray ${t}${a?` conflicts with ${a}`:""}`);this.trayId=t;this.spliceId=n;this.holder=s;this.conflictWith=a;this.name="SplicePlacementError";}};function Rr(e,o={}){return Co({items:e.splices,checkOutOfBounds:t=>t.holder<1||t.holder>Ge?{isValid:false,error:{spliceId:t.id,holder:t.holder,max:Ge}}:null,checkConflicts:(t,n)=>t.holder===n.holder?{hasConflict:true,conflict:{spliceId:t.id,holder:t.holder,conflictWith:n.id}}:null})}function ei(e,o){let t=e.mode==="ribbon",n=At(o,e.holder,t);return {id:e.id,type:"splice",position:n,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function Ka(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Za(e,o={}){let{conflictPolicy:t="strict",validatePlacements:n=true}=o,s=[],a=[];if(n)for(let l of e){let i=Rr(l,o);if(!i.isValid&&t==="strict"){let d=[];throw i.conflicts.forEach(u=>{d.push(`Splice ${u.spliceId} at holder ${u.holder} conflicts with ${u.conflictWith}`);}),i.outOfBounds.forEach(u=>{d.push(`Splice ${u.spliceId} at holder ${u.holder} is out of bounds (max: ${u.max})`);}),new Ht(l.id,i.conflicts[0]?.spliceId||i.outOfBounds[0]?.spliceId||"unknown",i.conflicts[0]?.holder||i.outOfBounds[0]?.holder||1)}}for(let l of e){let i=Ka(l);s.push(i);for(let d of l.splices)try{let u=d.holder;if(t==="nearest"){let c={id:d.id,type:"splice",position:{x:0,y:0},data:{label:d.name,holderPosition:d.holder}},f=[...s,...a];Mt(i,c,d.holder,f)||(u=zt(i,c,f,d.holder));}let h=u!==d.holder?{...d,holder:u}:d,g=ei(h,i);a.push(g);}catch(u){if(t==="strict")throw u;if(t==="nearest"){let h=[...s,...a],g=zt(i,{id:d.id,data:{label:d.name,holderPosition:d.holder}},h,d.holder);if(g!==d.holder){console.warn(`Splice ${d.id} moved from holder ${d.holder} to holder ${g} due to conflict`);let c={...d,holder:g},f=ei(c,i);a.push(f);}else throw new Ht(l.id,d.id,d.holder)}}}return s.push(...a),s}function qa(e){let o=[],t=e.filter(n=>n.type==="splice-tray");for(let n of t){let a=e.filter(l=>l.type==="splice"&&l.parentId===n.id).map(l=>({id:l.id,name:l.data.label,holder:l.data.holderPosition||1,lossDb:l.data.lossDb,mode:l.data.mode||"single",ribbonFiberIds:l.data.ribbonFiberIds}));o.push({id:n.id,name:n.data.label,position:n.position,splices:a});}return o}function Ja(e,o,t,n){return e.map(s=>s.id!==o?s:{...s,splices:s.splices.map(a=>a.id!==t?a:{...a,holder:n})})}function Qa(e,o,t,n={}){let{conflictPolicy:s="strict"}=n;return e.map(a=>{if(a.id!==o)return a;if(s==="strict"&&!Rr({...a,splices:[...a.splices,t]},n).isValid)throw new Ht(o,t.id,t.holder);return {...a,splices:[...a.splices,t]}})}function es(e,o,t){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.filter(s=>s.id!==t)})}
|
|
2
|
+
export{Zi as COUPLERS_PER_PANEL,fo as COUPLER_SLOT_HEIGHT_PX,qi as COUPLER_WIDTH_PX,ar as CableNode,yr as ClosureNode,lr as CouplerNode,mt as DeviceNode,St as DevicePlacementError,Hr as DiagramErrorBoundary,jr as FIBER_COLORS_12,ro as FiberEdge,Ao as FiberNode,Aa as FibreCableWithTubesExpanded,Ma as FibreFlowMap,xr as FibreSplitNode,Rt as HANDLE_EXTENSION_PX,dr as MultiTubeCableNode,Sr as NetworkDiagram,hn as PANEL_BORDER_WIDTH,gt as PANEL_HEADER_HEIGHT,go as PANEL_HEIGHT_PX,pt as PANEL_PADDING,mn as PANEL_TUBE_TRAY_SPACING,po as PANEL_WIDTH_PX,Uo as POWER_CONNECTORS,br as PatchPanelNode,Oo as PowerEdge,je as RACK_HEADER_HEIGHT,qt as RACK_WIDTH_PX,zo as RackNode,qo as SpliceNode,Ht as SplicePlacementError,or as SpliceTrayNode,rr as TubeNode,Se as U_HEIGHT_PX,Go as VerticalPDU,on as Width,Xa as addDeviceToRack,Qa as addSpliceToTray,xe as baseColorFor,Va as buildNodesFromRackConfig,Za as buildNodesFromSpliceConfig,Qi as calculateCouplerRightX,ta as calculateCouplerSlotSpacing,Sn as calculateCouplerSpacing,bt as calculateDevicePositionFromU,pr as calculatePanelDimensions,Cn as calculateSlotPositionFromY,Bi as calculateSplicePositionFromNumber,vn as calculateYFromSlotPosition,Nr as createNetworkDiagramStore,ja as createRackConfigFromNodes,qa as createSpliceConfigFromNodes,ze as fiberSolidOrStriped,xo as findNearestRack,zt as findNextAvailableHolderPosition,eo as findNextAvailableUPosition,Ba as generateLayout,rn as getConnectorConfig,ur as getCouplerDimensions,jo as getDeviceConnectorType,it as getFiberColor,kn as getInnerContentWidth,Vo as getPDUPortType,Ji as getPanelHeight,Nn as getPanelWidth,_t as getPowerPortStyle,Tn as getRackBounds,Te as getStatusColor,yn as getTrayDimensions,bo as getTubeDimensions,Jn as inventoryCableToNetworkEdge,qn as inventoryDeviceToNetworkNode,Zn as inventoryRackToNetworkNode,Oa as inventoryToNetworkDiagram,zi as isHighPowerConnector,wo as isPointInRack,nt as isStriped,Lo as isUPositionAvailable,Ga as removeDeviceFromRack,es as removeSpliceFromTray,He as replaceEdge,ea as snapToCouplerPosition,Qo as snapToSplicePosition,Mo as snapToUPosition,Vr as updateDeviceUPosition,Ya as updateDeviceUPositionInSchema,Ja as updateSpliceHolderPosition,vr as useDiagramEdges,Cr as useDiagramNodes,ca as useNetworkDiagram,xi as validateAndSnapDevice,Er as validateRackDevicePlacements,Rr as validateSplicePlacements};//# sourceMappingURL=index.mjs.map
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|