@mp70/react-networks 0.1.6-alpha → 0.1.7-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- 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.d.mts
CHANGED
|
@@ -356,6 +356,8 @@ interface NetworkDiagramProps {
|
|
|
356
356
|
allowReconnectExisting?: boolean;
|
|
357
357
|
/** Use smoothstep edges for tube connections (both tube-to-cable and cable-to-tube). Default is fiber. */
|
|
358
358
|
useSmoothstepEdgesForTubes?: boolean;
|
|
359
|
+
/** Enable connecting edges by clicking on handles. When true, increases handle sizes for better touch targets. Default is true. */
|
|
360
|
+
connectOnClick?: boolean;
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
declare const NetworkDiagram: React$1.FC<NetworkDiagramProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -356,6 +356,8 @@ interface NetworkDiagramProps {
|
|
|
356
356
|
allowReconnectExisting?: boolean;
|
|
357
357
|
/** Use smoothstep edges for tube connections (both tube-to-cable and cable-to-tube). Default is fiber. */
|
|
358
358
|
useSmoothstepEdgesForTubes?: boolean;
|
|
359
|
+
/** Enable connecting edges by clicking on handles. When true, increases handle sizes for better touch targets. Default is true. */
|
|
360
|
+
connectOnClick?: boolean;
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
declare const NetworkDiagram: React$1.FC<NetworkDiagramProps>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var Br=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Br__default=/*#__PURE__*/_interopDefault(Br);var hr=()=>"bottom-up",Pe=e=>e.data.uNumberingDirection||hr(),je=(e,o,r)=>r==="bottom-up"?o-e+1:e,Ge=(e,o,r)=>r==="bottom-up"?o-e+1:e;var ht=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=e.data.uHeight||1,i=o.data.uHeight||42,d=Pe(o),s=60,c=r.y-s,l=Math.round(c/20)+1,b;d==="bottom-up"?b=je(l,i,d)-n+1:b=je(l,i,d);let f=i-n+1,h=Math.max(1,Math.min(f,b));if(d==="top-down"&&b<=1&&(h=1),!mt(o,e,h,a)){let N=Ze(o,e,a,h);N!==h&&(h=N);}let v;if(d==="bottom-up"){let N=h+n-1,T=Ge(N,i,d);v=s+(T-1)*20-1;}else {let N=Ge(h,i,d);v=s+(N-1)*20-1;}return {x:r.x,y:v,uPosition:h}},mt=(e,o,r,a)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;if(r<1||r+n-1>i)return false;let d=a.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,b=r,f=r+n-1,h=c,v=c+l-1;if(b<=v&&f>=h)return false}return true},Ze=(e,o,r,a=1)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;for(let d=a;d<=i-n+1;d++)if(mt(e,o,d,r))return d;return 1},De=(e,o,r=1)=>{let a=60,n=Pe(e),i=e.data.uHeight||42,d=Ge(o,i,n),s;if(n==="bottom-up"){let c=o+r-1,l=Ge(c,i,n);s=a+(l-1)*20-1;}else s=a+(d-1)*20-1;return {x:0,y:s}},uo=(e,o,r)=>{let a=e.data.uHeight||1,n=De(o,r,a);return {...e,position:n,data:{...e.data,uPosition:r}}},mr=(e,o)=>{let r=e.data.uPosition||1,a=e.data.uHeight||1,n=o.data.uHeight||42,i=Math.max(1,Math.min(n-a+1,r));return i!==r?uo(e,o,i):e};function se(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var yt=({data:e,selected:o,id:r,onViewChange:a,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:s=0,status:c="active",uHeight:l=42,face:b="front",customHeaderText:f}=e,{getNodes:h,setNodes:v}=reactflow.useReactFlow(),N=h(),[T,w]=Br.useState(true),I=()=>{let H=Pe({data:e})==="bottom-up"?"top-down":"bottom-up";v(y=>y.map(P=>P.id===r?{...P,data:{...P.data,uNumberingDirection:H}}:P));},F=()=>{let x=b==="front"?"rear":"front";n?(n(r,x),a&&N.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);})):a?N.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);}):v(H=>H.map(y=>y.id===r?{...y,data:{...y.data,face:x}}:y.parentId===r?{...y,data:{...y.data,view:x}}:y));},W=()=>{let x=[],H=60,y=Pe({data:e});for(let P=1;P<=l;P++){let $=H+(P-1)*20-4,C=je(P,l,y);x.push(jsxRuntime.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:C},P));}return x};return jsxRuntime.jsxs("div",{className:`rack-node ${o?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${se(c)}`,borderRadius:"8px",padding:0,width:`${300}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:[jsxRuntime.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:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxRuntime.jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",b]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),w(!T);},style:{background:T?"#10b981":"#374151",color:T?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${T?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.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 ${Pe({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Pe({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),F();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${b==="front"?"rear":"front"} view`,children:b==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"}}),T&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:W()})]})};var xt=({data:e,selected:o})=>{let{label:r,status:a="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${se(a)}`,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:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:r})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:se(a),borderRadius:"50%"}})]})};var Nt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},className:b})=>{let[f,h,v]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),{bandwidth:N,length:T,color:w="#00FFFF",striped:I=false}=s||{},F={...l,stroke:w,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:f,style:F}),I&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&s&&(N||T)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${h}px,${v}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[N&&jsxRuntime.jsx("div",{children:N}),T&&jsxRuntime.jsxs("div",{children:[T,"m"]})]})})]})};var kt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l})=>{let[b]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),f=c?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:b,markerEnd:l,style:(()=>{let v={stroke:c?.color||"#f59e0b",strokeWidth:f==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return f==="C19"?{...v,strokeDasharray:"none"}:{...v,strokeDasharray:"6,3"}})()})};var go=({data:e,selected:o,style:r={},...a})=>{let{color:n="#00FFFF"}=e||{},i={...r,stroke:n,strokeWidth:o?4:3};return jsxRuntime.jsx(reactflow.SmoothStepEdge,{...a,data:e,selected:o,style:i})};function Tr({sourceX:e,sourceY:o,targetX:r,targetY:a,sourcePosition:n,targetPosition:i}){let d=n===reactflow.Position.Left||n===reactflow.Position.Right,s;if(d){let c=(e+r)/2;s=`M ${e},${o} L ${c},${o} L ${c},${a} L ${r},${a}`;}else {let c=(o+a)/2;s=`M ${e},${o} L ${e},${c} L ${r},${c} L ${r},${a}`;}return s}var yo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...b})=>{let{color:f="#00FFFF",striped:h=false}=s||{},v=Tr({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),N={...l,stroke:f,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,style:N}),h&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var xo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l,selected:b})=>{let{color:f="#6366f1",label:h}=c||{},[v,N,T]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),w={...s,stroke:f,strokeWidth:8,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,markerEnd:l,style:w}),h&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${N}px,${T}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:h})})]})};var wo=(r=>(r.FULL="full",r.HALF="half",r))(wo||{});var Pt={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 Ie(e){let o=Pt[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let r=o.amperage===16,a=r?12:8,n=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:a,height:n,color:o.color,borderColor:o.borderColor,fontSize:r?"3px":"4px",...i}}function Qe(e){let o=Pt[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function zr(e){return Qe(e).amperage===16}function St(e){return e%10<8?"C13":"C19"}function et(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Ct=({data:e,selected:o})=>{let{label:r,status:a="active",deviceType:n="server",manufacturer:i,role:d,uHeight:s=1,width:c="full",ports:l=[],rearPorts:b=[],view:f}=e,h=f||(b.length>0&&l.length===0?"rear":"front"),v={};v["net-top"]="front",v["net-bottom"]="front",l.length>0&&l.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="front";});}),v["pwr-left-1"]="rear",v["pwr-left-2"]="rear",v["net-right-1"]="rear",v["net-right-2"]="rear",b.length>0&&b.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="rear";});});let N=s*20,T=c==="half"?"150px":"304px",w=c==="half"?"150px":void 0,I=(x,H)=>{let y=[];if(x.length===0)return y;let P=Math.max(4,Math.floor(N*.4)),$=Math.max(2,Math.floor(N*.2));return x.forEach((C,z)=>{C.ports.forEach((_,R)=>{let M=!!_.type&&_.type.includes("power");if(H==="front"&&M)return;let V=M?`${_.label}`:`${C.name}-${_.label}`,X=_.connected,E="#6b7280";if(X)if(_.type?.includes("power"))E=_.type==="power_c19"?"#fbbf24":"#f59e0b";else if(_.type==="console"||_.type==="mgmt")E="#8b5cf6";else if(_.type==="usb")E="#10b981";else switch(_.cableType){case "smf":E="#fbbf24";break;case "cat6":E="#8b5cf6";break;case "om3":E="#06b6d4";break;case "om4":E="#8b5cf6";break;case "om5":E="#84cc16";break;case "cat5e":E="#3b82f6";break;case "cat6a":E="#ef4444";break;case "cat7":E="#f97316";break;case "fiber":E="#3b82f6";break;case "ethernet":E="#10b981";break;default:E="#10b981";}let G=reactflow.Position.Top,D={width:`${P}px`,height:`${$}px`,background:X?E:"#6b7280",border:`1px solid ${X?E:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(H==="front")R%2===0?(G=reactflow.Position.Top,D.transform="translateY(50%)",D.left=`${R/2*(P+2)}px`):(G=reactflow.Position.Bottom,D.transform="translateY(-50%)",D.left=`${(R-1)/2*(P+2)}px`);else if((n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel")R%2===0?(G=reactflow.Position.Top,D.transform="translateY(50%)",D.left=`${R/2*(P+2)}px`):(G=reactflow.Position.Bottom,D.transform="translateY(-50%)",D.left=`${(R-1)/2*(P+2)}px`);else if(_.type?.includes("power")){G=reactflow.Position.Left,D.transform="translateX(50%)";let Ye=N<=20?10:20,ke=N<=20?30:50;D.top=`${Ye+R*ke}%`;let ft=et(r),me=Ie(ft);D={...D,width:`${me.width}px`,height:`${me.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:me.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:me.borderRadius,clipPath:me.clipPath};}else G=reactflow.Position.Right,D.transform="translateX(-50%)",D.top=`${25+R*50}%`;let be=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",ie;if(M)ie="target";else if(n==="switch"||n==="router")ie="source",y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${V}-target`,type:"target",position:G,style:D,title:`${C.name} - ${_.label} (input) ${X?"(connected)":"(disconnected)"}`},`${V}-target`));else if(be){ie=H==="rear"?"source":"target";let he=H==="rear"?"target":"source";y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${V}-${he}`,type:he,position:G,style:D,title:`${C.name} - ${_.label} (${he}) ${X?"(connected)":"(disconnected)"}`},`${V}-${he}`));}else ie=X?"source":"target";y.push(jsxRuntime.jsx(reactflow.Handle,{id:V,type:ie,position:G,style:D,title:`${C.name} - ${_.label} ${X?"(connected)":"(disconnected)"}`,children:M?R+1:void 0},V));});}),y},F=()=>{let x=[],H=Math.max(4,Math.floor(N*.4)),y=Math.max(2,Math.floor(N*.2));if(h==="front"){if(l.length>0)return I(l,"front");if(n==="switch"&&(r.toLowerCase().includes("agg")||r.toLowerCase().includes("core")||d==="agg"||d==="core"))return W();x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}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(b.length>0)return I(b,"rear");let P=n==="switch",C=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!C){let z=et(r),_=Qe(z),R=Ie(z),M=N<=20?"10%":"25%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:M,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`Power Port 1 (${_.type}) - ${_.voltage}V, ${_.amperage}A`,children:"1"},"pwr-1"));let V=N<=20?"50%":"75%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:V,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`Power Port 2 (${_.type}) - ${_.voltage}V, ${_.amperage}A`,children:"2"},"pwr-2"));}!P&&!C&&(x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}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")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}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 x},W=()=>{let x=[],H=Math.max(10,Math.floor(N*.45)),y=Math.max(5,Math.floor(N*.25));for(let P=1;P<=16;P++){let $=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(P-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push($);}for(let P=17;P<=32;P++){let $=P-16,C=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${($-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push(C);}for(let P=1;P<=4;P++){let $=Math.max(4,Math.floor(N*.3)),C=Math.max(3,Math.floor(N*.15));x.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${P}`,type:"source",position:reactflow.Position.Right,style:{width:`${$}px`,height:`${C}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${P}`},`uplink-${P}`));}return x};return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${se(a)}`,borderRadius:"2px",padding:"0px",width:T,...w&&{left:w},height:`${N}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:[jsxRuntime.jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r}),s>1&&jsxRuntime.jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:i})]}),s>1&&jsxRuntime.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"]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:se(a),borderRadius:"50%"}}),F()]})};var Et=({data:e,selected:o})=>{let{label:r,status:a="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:s}=e,c=n*4.2,l=()=>{let h=Math.ceil(i/10),v=Array(10).fill(0).map((y,P)=>P<8?"10A":"16A");for(let y=0,P=0;y<h;++y)for(let $=0;$<10&&P<i;++$,++P){v[$];}let I=[],F=15,H=(c-F-3)/(i-9)*.5;for(let y=0;y<i;y++){let P=F-2+H*y,$=`${y+1}`;if(s&&(s==="top"&&y===0||s==="middle"&&y===Math.floor(i/2)||s==="bottom"&&y===i-1)){I.push(b(P));continue}let z=St(y),_=Ie(z),R=Math.round((d-_.width)/2-1);I.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:$,style:{position:"absolute",left:`${R}px`,top:`${P-_.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 ${y+1} (${z})`,children:y+1},`handle-${$}`));}return I},b=f=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(d-16)/2}px`,top:`${f-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.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"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.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 jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${se(a)}`,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:[jsxRuntime.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:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:r})}),jsxRuntime.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 Dt=({data:e,selected:o,id:r})=>{let{lossDb:a}=e||{},n=reactflow.useEdges(),i=n.find(h=>h.target===r&&h.targetHandle==="left"),d=n.find(h=>h.source===r&&h.sourceHandle==="right"),s=n.find(h=>h.target===r&&h.targetHandle==="right"),c=d||s,l=i?.data?.color||"#555",b=c?.data?.color||"#555",f=!!i&&!!c;return jsxRuntime.jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:69,height:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:l}}),jsxRuntime.jsx("div",{style:{background:b}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1}}),f&&jsxRuntime.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}}),f&&typeof a=="number"&&jsxRuntime.jsx("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold"},children:`${a.toFixed(2)} dB`}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:l,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:b,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:b,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var we=20,He=32,So=4,Ne=12,Mr=69,Ce=80,It=(Ce-Mr)/2;var _t=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=He,i=r.y-n,d=Math.round(i/we)+1,c=Math.max(1,Math.min(Ne,d));if(!$t(o,e,c,a)){let f=tt(o,e,a,c);if(f!==c)return {x:It,y:n+(f-1)*we+5,holderPosition:f}}let b=n+(c-1)*we+5;return {x:It,y:b,holderPosition:c}},$t=(e,o,r,a)=>!a.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==o.id).some(i=>i.data.holderPosition===r),tt=(e,o,r,a=1)=>{for(let n=a;n<=Ne;n++)if($t(e,o,n,r))return n;for(let n=a-1;n>=1;n--)if($t(e,o,n,r))return n;return 1},Me=(e,o)=>{let n=He+(o-1)*we+5;return {x:It,y:n}};var Wt=({data:e,selected:o})=>{let{label:r="Splice Tray"}=e||{},[a,n]=Br.useState(false),i=()=>{if(!a)return null;let d=[],s=He;for(let c=1;c<=Ne;c++){let l=s+(c-1)*we;d.push(jsxRuntime.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:`${we}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${Ce}px`,height:`${He+Ne*we+So}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:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${He}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:r}),jsxRuntime.jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!a);},style:{background:a?"#10b981":"#374151",color:a?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${a?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:He,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Ho=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function te(e){let o=(e-1)%12;return Ho[o]}function Co(e){return e>12}function Ue(e){let o=te(e);return Co(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function zt(e){return te(e)}var Lt=({data:e,selected:o,id:r})=>{let{fibersPerTube:a=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=Math.max(1,Math.min(24,Number(a)||12)),s=14,c=4,l=1,b=2,f=20,h=d*s+(d-1)*c,v=Math.max(60,h+l*2+b*2),N=te((n-1)%12+1),T=`tube-${n}`,w=18,I={width:w,height:w,borderRadius:"50%",opacity:.25,pointerEvents:"auto",background:N,backgroundColor:N,border:`2px solid ${N}`,"--fiber-bg":N},F=()=>i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,W=()=>{let x=[],H=v-b*2-l*2,y,P,$=false;i==="left"?(y=l,P=reactflow.Position.Top):i==="right"?(y=l+H-h,P=reactflow.Position.Top,$=true):(y=l+(H-h)/2,P=reactflow.Position.Top);for(let C=0;C<d;C++){let z=$?d-C:C+1,_=Ue(z),R=te(z),M=y+C*(s+c),V=l,X=_.backgroundImage?_.backgroundImage:R,E={position:"absolute",left:`${M}px`,top:`${V}px`,width:s,height:s,borderRadius:"50%",border:"none",background:X,backgroundColor:R,zIndex:10,cursor:"pointer","--fiber-bg":R};_.backgroundImage&&(E["--fiber-bg-image"]=_.backgroundImage);let G=`fiber-${z}`;x.push(jsxRuntime.jsxs(Br__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:G,type:"target",position:P,className:"tube-fiber-handle",isConnectable:true,style:E,"data-fiber-idx":z,"data-fiber-color":R}),jsxRuntime.jsx(reactflow.Handle,{id:G,type:"source",position:P,className:"tube-fiber-handle",isConnectable:true,style:E,"data-fiber-idx":z,"data-fiber-color":R})]},`fiber-${z}`));}return x};return jsxRuntime.jsxs("div",{style:{width:v,height:f,borderRadius:4,background:"#111827",border:`${b}px solid ${o?"#3b82f6":N}`,position:"relative",boxShadow:o?`0 0 0 ${b}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:l,boxSizing:"border-box"},children:[W(),jsxRuntime.jsx(reactflow.Handle,{id:T,type:"target",position:F(),isConnectable:true,style:I,"data-tube-idx":n,"data-tube-color":N}),jsxRuntime.jsx(reactflow.Handle,{id:T,type:"source",position:F(),isConnectable:true,style:I,"data-tube-idx":n,"data-tube-color":N})]})};var Mt=({data:e,selected:o})=>{let{tubeCount:r=12,fibersPerTube:a=12,fiberCount:n,cableId:i="CBL-002",label:d,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(r)||12)),b=Math.max(1,Number(s)||1),f=8,h=2,v=6,N=v+f+4,T=60,w=Math.max(120,l*(f+h)+v*2),I=n??l*(Number(a)||12),F=d??`${I}f Cable`,W=i?`Cable ID ${i}`:void 0,x=te(b),H=c||x,y=o?"#3b82f6":H,P=()=>{let R=[];for(let M=0;M<l;M++){let V=b+M,X=Ue(V),E=te(V),G=v+M*(f+h),D=-4,ge=X.backgroundImage?X.backgroundImage:E,be={position:"absolute",left:`${G}px`,top:`${D}px`,width:f,height:f,borderRadius:"50%",border:"none",background:ge,backgroundColor:E,zIndex:10,cursor:"pointer","--fiber-bg":E};X.backgroundImage&&(be["--fiber-bg-image"]=X.backgroundImage);let ie=`tube-${V}`;R.push(jsxRuntime.jsxs(Br__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:ie,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:be,"data-fiber-idx":V,"data-tube-idx":V,"data-tube-color":E}),jsxRuntime.jsx(reactflow.Handle,{id:ie,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:be,"data-fiber-idx":V,"data-tube-idx":V,"data-tube-color":E})]},`tube-${V}`));}return R},$="cable-button",C=8,z={width:C,height:C,borderRadius:"50%",background:H,backgroundColor:H,border:`1px solid ${H}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:w,height:T,borderRadius:4,background:"#111827",border:`2px solid ${y}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:v,paddingTop:N,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[P(),jsxRuntime.jsx(reactflow.Handle,{id:$,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:z,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx(reactflow.Handle,{id:$,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:z,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:F}),W&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:W})]})};var Ut=({data:e,selected:o,id:r})=>{let{connector:a="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:s}=e||{},c=reactflow.useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,b=Math.max(1,Math.min(4,l)),f=7,h=3,v=3,N=60,T=30,w=b*f+(b-1)*h,I=Math.max(T,w+v*2),F=Math.max(N,80),W=(y,P)=>{let $=`${y}-${P+1}`;return c.find(z=>z.source===r&&z.sourceHandle===$||z.target===r&&z.targetHandle===$)?.data?.color||"#555"},x=y=>{let P=[],$=y==="left"?reactflow.Position.Left:reactflow.Position.Right,C=y==="left"?d:s;for(let z=0;z<b;z++){let _=z+1,R=`${y}-${_}`,M=W(y,z),E=v+(I-w)/2+z*(f+h),G={position:"absolute",left:y==="left"?-5:void 0,right:y==="right"?-5:void 0,top:`${E}px`,width:f,height:f,borderRadius:"50%",border:"none",background:M,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};P.push(jsxRuntime.jsxs(Br__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:R,type:"target",position:$,isConnectable:true,style:G}),jsxRuntime.jsx(reactflow.Handle,{id:R,type:"source",position:$,isConnectable:true,style:G})]},R)),C&&C[z]&&P.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:y==="left"?-30:void 0,right:y==="right"?-30:void 0,top:`${E}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:y==="left"?"right":"left",width:"25px"},children:C[z]},`${R}-label`));}return P},H=i||`${a}-${b}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:F,height:I,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:`${v}px`,boxSizing:"border-box"},children:[x("left"),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:H})}),x("right")]})};var Ee=32,dt=30,Xr=24,jr=80,at=400,st=300,Ao=2,fe=8,Wo=120;function Bt(e){let{couplerFiberCount:o}=e.data||{},r=typeof o=="number"&&[1,2,4].includes(o)?o:2,a=Math.max(1,Math.min(4,r)),n=7,i=3,d=3,s=60,c=30,l=a*n+(a-1)*i,b=Math.max(c,l+d*2);return {width:Math.max(s,80),height:b}}function ct(e){let{fibersPerTube:o=12}=e.data||{},r=Math.max(1,Math.min(24,Number(o)||12)),a=14,n=4,i=1,d=2,s=20,c=r*a+(r-1)*n;return {width:Math.max(60,c+i*2+d*2),height:s}}function zo(e){return {width:Ce,height:0}}function Oe(e){return e.type==="coupler"?Bt(e):e.type==="tube"?ct(e):e.type==="splice-tray"?zo():{width:80,height:30}}function Lo(e){return e.data?.panelWidth||at}function Gr(e){return e.data?.panelHeight||st}function Mo(e){return Lo(e)-Ao*2-fe*2}function Zr(e,o){return Mo(e)-o}function Uo(e,o=dt){return Math.floor(e/o)+1}function Bo(e,o=dt){return (e-1)*o}function Kr(e,o,r){let a=dt,n=Uo(r.y,a),i=Bo(n,a);return {x:r.x,y:i,slotPosition:n}}function Ot(e,o){if(o.length===0)return {width:e.data?.panelWidth||at,height:e.data?.panelHeight||st};let r=o.some(l=>l.type==="tube"),a=o.some(l=>l.type==="splice-tray"),n=o.some(l=>l.type==="coupler"),i,d=5;if(r&&a&&n){let l=0,b=0;for(let f of o)if(f.type==="tube"){let h=ct(f);h.width>l&&(l=h.width);}else if(f.type==="coupler"){let h=Bt(f);h.width>b&&(b=h.width);}i=fe+l+Wo+Ce+b+d;}else {let l=0;for(let b of o){let f=Oe(b),h=(b.position?.x||0)+f.width;h>l&&(l=h);}i=l+fe+d;}i=Math.max(e.data?.panelWidth||at,i);let s=Ee;for(let l of o){let b=Oe(l),f=(l.position?.y||0)+b.height;f>s&&(s=f);}let c=Math.max(e.data?.panelHeight||st,s+fe);return {width:i,height:c}}function Oo(e,o,r){if(e===0)return 0;if(e===1)return o;let a=e*o,n=r-a,i=Math.max(5,n/(e-1));return o+i}function qr(e,o,r){return Oo(e,o,r)}var $o=20,_o=400,Fo=300;function Yo(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||_o,height:e.data?.closureHeight||e.data?.panelHeight||Fo};let r=o.some(c=>c.type==="tube"),a=o.some(c=>c.type==="splice-tray"),n,i=5;if(r&&a){let c=0,l=0,b=0,f=o.filter(v=>v.type==="tube"),h=o.filter(v=>v.type==="splice-tray");if(f.length>0&&h.length>0){let v=f.map(F=>F.position?.x||0);Math.min(...v);Math.max(...v);let w=h.map(F=>F.position?.x||0),I=w.reduce((F,W)=>F+W,0)/w.length;for(let F of f){let W=ct(F);(F.position?.x||0)<I?W.width>c&&(c=W.width):W.width>l&&(l=W.width);}h.length>0&&(b=Ce),n=fe+c+$o+b+$o+l+i;}else {let v=0;for(let N of o){let T=Oe(N),w=(N.position?.x||0)+T.width;w>v&&(v=w);}n=v+fe+i;}}else {let c=0;for(let l of o){let b=Oe(l),f=(l.position?.x||0)+b.width;f>c&&(c=f);}n=c+fe+i;}n=Math.max(e.data?.closureWidth||e.data?.panelWidth||_o,n);let d=Ee;for(let c of o){let l=Oe(c),b=(c.position?.y||0)+l.height;b>d&&(d=b);}let s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Fo,d+fe);return {width:n,height:s}}var Xt=({data:e,selected:o,id:r})=>{let{label:a="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:s,setNodes:c}=reactflow.useReactFlow(),l=Br.useRef(false),b=Br.useMemo(()=>s().filter(F=>F.parentId===r),[s,r]),f=Br.useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),h=Br.useMemo(()=>i&&d?{width:i,height:d}:b.length===0?{width:i||400,height:d||300}:Ot(f,b),[b,f,i,d]);Br.useEffect(()=>{if(i&&d||l.current)return;let I=i,F=d,W=Math.abs((I||0)-h.width),x=Math.abs((F||0)-h.height);(W>1||x>1)&&(l.current=true,c(H=>H.map(y=>y.id===r?{...y,data:{...y.data,panelWidth:h.width,panelHeight:h.height}}:y)),setTimeout(()=>{l.current=false;},0));},[r,h.width,h.height,i,d,c]);let v=h.width,N=h.height,T=Ee,w=n||a;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${v}px`,height:`${N}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:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${T}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:w})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:T,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Zt=({data:e,selected:o,id:r})=>{let{label:a="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:b}=reactflow.useReactFlow(),f=Br.useRef(false),h=Br.useMemo(()=>l().filter(H=>H.parentId===r),[l,r]),v=Br.useMemo(()=>({id:r,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||s,closureHeight:d||c}}),[r,e,i,d,s,c]),N=Br.useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:h.length===0?{width:i||s||400,height:d||c||300}:Yo(v,h),[h,v,i,d,s,c]);Br.useEffect(()=>{if(i&&d||s&&c||f.current)return;let x=i||s,H=d||c,y=Math.abs((x||0)-N.width),P=Math.abs((H||0)-N.height);(y>1||P>1)&&(f.current=true,b($=>$.map(C=>C.id===r?{...C,data:{...C.data,closureWidth:N.width,closureHeight:N.height}}:C)),setTimeout(()=>{f.current=false;},0));},[r,N.width,N.height,i,d,s,c,b]);let T=N.width,w=N.height,I=Ee,F=n||a,W=T/2;return jsxRuntime.jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${W}px ${W}px 12px 12px`,padding:0,width:`${T}px`,height:`${w}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:[jsxRuntime.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:`${W}px ${W}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:F})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:I,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};function sn(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let r=o.edges.some(w=>w.source===e.source&&w.sourceHandle===e.sourceHandle),a=o.edges.some(w=>w.target===e.target&&w.targetHandle===e.targetHandle);if(r)return {valid:false,reason:"Source port is already connected"};if(a)return {valid:false,reason:"Target port is already connected"};let n=e.sourceHandle,i=e.targetHandle,d=o.nodes.find(w=>w.id===e.source),s=o.nodes.find(w=>w.id===e.target),c=(w,I)=>{if(!w)return false;let F=w.startsWith("pwr")||w.startsWith("power"),W=I?.type==="vertical-pdu"&&w!=="mgmt-net-1";return F||W},l=(w,I)=>{if(!w)return false;if(I?.type==="vertical-pdu"&&w==="mgmt-net-1"||I?.type==="tube"&&w.startsWith("fiber-")||(I?.type==="tube"||I?.type==="cable")&&w.startsWith("tube-")||I?.type==="splice"&&(w==="left"||w==="right"))return true;let F=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("Fiber")||w.includes("Ports"),W=/^[A-Z0-9]+-\d+$/.test(w)&&!w.startsWith("pwr")&&!w.startsWith("power");return F||W},b=c(n,d),f=c(i,s),h=l(n,d),v=l(i,s);if(b&&v||f&&h)return {valid:false,reason:"Cannot connect network cable to power port"};if(b&&!f||f&&!b)return {valid:false,reason:"Power ports must connect to power-compatible ports"};let N=d?.type==="vertical-pdu",T=s?.type==="vertical-pdu";if(b||f){let w=N?s:T?d:null,I=N?d:T?s:null;if(w&&I&&o.edges.filter(x=>{let H=c(x.sourceHandle||""),y=c(x.targetHandle||""),P=x.source===w.id||x.target===w.id;return (H||y)&&P}).some(x=>x.source===I.id||x.target===I.id))return {valid:false,reason:"Dual-feed required: connect second power to a different PDU"}}return {valid:true}}function lt(e,o){if(!o)return;let r=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,a=o.data??{},n=a.handleSideMap;if(n&&n[r])return n[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(a.ports)?a.ports:[],d=Array.isArray(a.rearPorts)?a.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 Kt(e={},o={}){let r={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},a=new Set;return {getState:()=>r,setState:f=>{r={...r,...f},a.forEach(h=>h(r));},subscribe:f=>(a.add(f),()=>a.delete(f)),selectEdgeZIndex:f=>{let h=r.nodes.find(H=>H.id===f.target);if(!h||h.type!=="device")return 1e3;let v=h.data?.view||"front",N=lt(f.targetHandle||"",h);if(N)return v===N?1e3:500;let T=(f.targetHandle||"").toString(),w=T.toLowerCase(),I=w.startsWith("pwr")||w.startsWith("power"),F=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),W=/^[A-Z0-9]+-\d+$/i.test(T)&&!w.startsWith("pwr")&&!w.startsWith("power"),x=F||W;return I?v==="rear"?1e3:500:x?v==="front"?1e3:500:1e3},validateConnection:f=>(o.validateConnection||sn)(f,r),selectNodeById:f=>r.nodes.find(h=>h.id===f),selectConnectedEdges:f=>r.edges.filter(h=>h.source===f||h.target===f)}}function dn(e){let o=n=>e.subscribe(n),r=()=>e.getState();return Br.useSyncExternalStore(o,r,r)}function Jt(e){let o=a=>e.subscribe(a),r=()=>e.getState().nodes;return Br.useSyncExternalStore(o,r,r)}function Qt(e){let o=a=>e.subscribe(a),r=()=>e.getState().edges;return Br.useSyncExternalStore(o,r,r)}function Vo(e){return e.selectEdgeZIndex}function Xo(e){let o=300,r=(e.data.uHeight||42)*20,a=e.position.x,n=e.position.x+o,i=e.position.y,d=e.position.y+r;return {left:a,right:n,top:i,bottom:d}}function pt(e,o){let r=Xo(o);return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom}function ut(e,o){let r=null,a=1/0;for(let n of o){if(!pt(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<a&&(a=i,r=n);}return r}function j(e){let{edges:o,connection:r,edgeType:a,selectEdgeZIndex:n,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(T=>i==="source"?T.source===c&&T.sourceHandle===s:T.target===c&&T.targetHandle===s);if(!l)return null;let b=o.filter(T=>T.id!==l.id),f=reactflow.addEdge(r,b),h=f[f.length-1],v=n({...r,id:h.id,type:a}),N={...h,type:a,zIndex:v,style:{...h.style,zIndex:v},data:d!==void 0?d:h.data};return [...f.slice(0,-1),N]}var kn=(e,o,r)=>({rack:a=>jsxRuntime.jsx(yt,{...a,onViewChange:e,onRackFaceChange:o,isDragOver:r?r()===a.id:false}),fiber:xt,device:Ct,"vertical-pdu":Et,splice:Dt,"splice-tray":Wt,tube:Lt,cable:Mt,coupler:Ut,"patch-panel":Xt,closure:Zt}),vn={fiber:Nt,power:kt,smoothstep:go,step:yo,"thick-cable":xo},Pn=({nodes:e,edges:o,initialNodes:r,initialEdges:a,onNodesChange:n,onEdgesChange:i,store:d,debug:s,onNodeClick:c,onEdgeClick:l,onViewChange:b,onRackFaceChange:f,className:h,style:v,alignRacksToBottom:N,colorMode:T="dark",onInit:w,onFlowMethods:I,showDownloadButton:F=false,downloadButtonPosition:W="top-right",downloadButtonText:x="Download Image",downloadButtonStyle:H,allowReconnectExisting:y=false,useSmoothstepEdgesForTubes:P=false})=>{let $=Array.isArray(e)&&Array.isArray(o),C=Br__default.default.useMemo(()=>d||Kt({nodes:$?e||[]:r||e||[],edges:$?o||[]:a||o||[],debug:s}),[d,$,s]),z=Jt(C),_=Qt(C),[R,M,V]=reactflow.useNodesState(z),[X,E,G]=reactflow.useEdgesState(_),D=Vo(C),ge=Br.useRef(null),{toObject:be,setViewport:ie,setNodes:he,setEdges:Ye,getNodes:ke}=reactflow.useReactFlow();Br.useEffect(()=>{I&&I({toObject:be,setViewport:ie,setNodes:t=>{he(t),C.setState({nodes:t});},setEdges:t=>{Ye(t),C.setState({edges:t});},toImage:t=>ge.current?htmlToImage.toPng(ge.current,t):Promise.reject(new Error("ReactFlow wrapper not available"))});},[I,be,ie,he,Ye,C]);let ft=Br.useCallback(()=>{if(!ge.current){s&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(ge.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:T==="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);});},[T,s]),[me,Ve]=Br.useState(null),no=Br.useRef(null),io=Br.useRef(b),ao=Br.useRef(f);Br.useEffect(()=>{io.current=b;},[b]),Br.useEffect(()=>{ao.current=f;},[f]),Br.useEffect(()=>{no.current=me;},[me]);let so=Br.useCallback(()=>no.current,[]),er=Br.useMemo(()=>kn((t,p)=>io.current?.(t,p),(t,p)=>ao.current?.(t,p),so),[so]),tr=Br.useMemo(()=>vn,[]),pe=Br.useRef(R);Br.useEffect(()=>{pe.current=R;},[R]);let L=Br.useRef(X);Br.useEffect(()=>{L.current=X;},[X]),Br.useEffect(()=>{M(z);},[z,M]),Br.useEffect(()=>{E(_);},[_,E]),Br.useEffect(()=>{$&&C.setState({nodes:e||[]});},[$,e,C]),Br.useEffect(()=>{$&&C.setState({edges:o||[]});},[$,o,C]),Br.useEffect(()=>{if(!N||!R||R.length===0)return;let t=R.filter(U=>U.type==="rack");if(t.length===0)return;let p=t.map(U=>{let ae=U.data?.uHeight||42,le=60+ae*20;return (U.position?.y||0)+le}),g=Math.min(...p),m=Math.max(...p);if(m-g<20)return;let u=m,A=R.map(U=>{if(U.type!=="rack")return U;let ae=U.data?.uHeight||42,le=60+ae*20,Z=(U.position?.y||0)+le,B=u-Z;return Math.abs(B)<5?U:{...U,position:{x:U.position?.x||0,y:(U.position?.y||0)+B}}});A.some((U,ee)=>U.position!==R[ee].position)&&M(A);},[N,R,M]);let Y=Br.useCallback(t=>pe.current.find(p=>p.id===t),[]),Xe=Br.useCallback((t,p)=>{if(!t||!p)return;let g=Y(t);if(!g)return;if(g.type==="tube"&&p.startsWith("fiber-")){let k=p.replace("fiber-",""),u=parseInt(k,10);if(u>=1&&u<=24){let A=zt(u),O=u>12;return {color:A,striped:O}}}if((g.type==="cable"||g.type==="tube")&&p.startsWith("tube-")){let k=p.replace("tube-",""),u=parseInt(k,10);if(u>=1&&u<=24){let A=te(u),O=u>12;return {color:A,striped:O}}}let m=g.data;if(m.color)return {color:m.color}},[Y]);Br.useEffect(()=>{E(t=>t.map(p=>{let g=D(p);return {...p,zIndex:g,style:{...p.style,zIndex:g}}}));},[R,E,D]),Br.useEffect(()=>{let t=R.map(g=>{if(g.type==="coupler"&&g.parentId){let m=Y(g.parentId);if(m&&(m.type==="patch-panel"||m.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 m=Y(g.parentId);if(m&&m.type==="splice-tray"){let k=Me(m,g.data.holderPosition);return {...g,position:k}}}if(g.type==="device"&&g.parentId&&g.data.uPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let m=Y(g.parentId);if(m){let k=De(m,g.data.uPosition);return {...g,position:k}}}return g});t.some((g,m)=>{let k=R[m];return g.extent!==k.extent||g.position?.x!==k.position?.x||g.position?.y!==k.position?.y})&&M(t);},[R,M,Y]);let or=Br.useCallback(t=>{let p=t.map(g=>{if(g.type==="position"&&g.position){let m=Y(g.id);if(m&&m.type==="coupler"&&m.parentId){let k=Y(m.parentId);if(k&&(k.type==="patch-panel"||k.type==="closure")){if(!m.extent||m.extent!=="parent"){let u={...m,extent:"parent"};M(A=>A.map(O=>O.id===m.id?u:O));}return {...g,position:m.position||{x:0,y:0}}}}if(m&&m.type==="splice"&&m.parentId){let k=Y(m.parentId);if(k&&k.type==="splice-tray"){let u=_t(m,k,g.position,pe.current);if(u.holderPosition!==void 0){let A={...m,data:{...m.data,holderPosition:u.holderPosition}};M(O=>O.map(U=>U.id===m.id?A:U));}return {...g,position:{x:u.x,y:u.y}}}}if(m&&m.type==="device"&&m.parentId){let k=Y(m.parentId);if(k){let u=ht(m,k,g.position,pe.current);if(u.uPosition!==void 0){let A={...m,data:{...m.data,uPosition:u.uPosition}};M(O=>O.map(U=>U.id===m.id?A:U));}return {...g,position:{x:u.x,y:u.y}}}}if(m&&m.type==="device"&&m.parentId){let k=Y(m.parentId);if(k){let u=k;if(!pt(g.position,u)){let A=g.position.x+u.position.x,O=g.position.y+u.position.y,U={...m,parentId:void 0,extent:void 0,data:{...m.data,uPosition:void 0}};return M(ee=>ee.map(ae=>ae.id===m.id?U:ae)),{...g,position:{x:A,y:O}}}}}}return g});V(p);},[V,M,Y]),rr=Br.useCallback((t,p)=>{Ve(null);},[]),nr=Br.useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let m=pe.current.filter(u=>u.type==="rack").map(u=>u),k=ut(p.position,m);Ve(k?.id??null);}else Ve(null);},[]),ir=Br.useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let m=pe.current.filter(u=>u.type==="rack").map(u=>u),k=ut(p.position,m);if(k){let u=p.position.x-k.position.x,A=p.position.y-k.position.y,O={...p,parentId:k.id,extent:"parent",position:{x:u,y:A},data:{...p.data,uPosition:1}},U=pe.current.map(ee=>ee.id===p.id?O:ee);M(U),$||C.setState({nodes:U});}}Ve(null);},[M,$,C]),ar=Br.useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let p=Y(t.source),g=Y(t.target);if(p?.type==="tube"&&g?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect fibres within tubes",t),false;if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&(g?.type==="cable"||g?.type==="tube")&&t.targetHandle.startsWith("tube-"))return s&&console.log("Connection rejected: Cannot connect individual fibre to cable/tube tube handle",t),false;if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-")&&g?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect cable/tube tube handle to individual fibre",t),false;if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")){if(L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle||u.source===t.target&&u.sourceHandle===t.targetHandle))return s&&console.log("Splice handle already connected, will replace",t),true;s&&console.log("Allowing connection to splice handle",t);}if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-"))return g?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect to splices",t),false):L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube fiber handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube fiber handle to splice",t),true);if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-"))return t.targetHandle.startsWith("tube-")?L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube-level handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube-level handle to tube handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect to other tube handles",t),false);if(p?.type==="splice"&&t.sourceHandle==="right"){if(L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle||u.target===t.source&&u.targetHandle===t.sourceHandle))return s&&console.log("Splice source handle already connected, will replace",t),true;s&&console.log("Allowing connection from splice source handle",t);}if(g?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return p?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect from splices",t),false):L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube fiber target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to tube fiber handle",t),true);if((g?.type==="cable"||g?.type==="tube")&&t.targetHandle.startsWith("tube-"))return t.sourceHandle.startsWith("tube-")?L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube-level target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube handle to tube-level handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect from other tube handles",t),false);if(p?.type==="coupler"&&(t.sourceHandle?.startsWith("left-")||t.sourceHandle?.startsWith("right-")))return g?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect to splices",t),false):t.targetHandle!=="left"&&t.targetHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect to splice left/right handles",t),false):L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Coupler handle already connected, will replace",t),true):(s&&console.log("Allowing connection from coupler handle to splice",t),true);if(g?.type==="coupler"&&(t.targetHandle?.startsWith("left-")||t.targetHandle?.startsWith("right-")))return p?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect from splices",t),false):t.sourceHandle!=="left"&&t.sourceHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect from splice left/right handles",t),false):L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Coupler target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to coupler handle",t),true);if(t.source&&t.sourceHandle&&L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle already connected, will replace",t),true;if(t.target&&t.targetHandle&&L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle already connected, will replace",t),true;if((p?.type==="cable"||g?.type==="cable")&&(t.sourceHandle==="cable-button"||t.targetHandle==="cable-button"))return t.sourceHandle!=="cable-button"||t.targetHandle!=="cable-button"?(s&&console.log("Connection rejected: Cable button handles can only connect to other cable button handles",t),false):L.current.find(A=>A.source===t.source&&A.sourceHandle===t.sourceHandle)?(s&&console.log("Cable button source handle already connected, will replace",t),true):L.current.find(A=>A.target===t.target&&A.targetHandle===t.targetHandle)?(s&&console.log("Cable button target handle already connected, will replace",t),true):(s&&console.log("Allowing connection between cable button handles",t),true);let m=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!m.valid&&y){if(t.source&&t.sourceHandle&&L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle has existing edge, will replace",t),true;if(t.target&&t.targetHandle&&L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle has existing edge, will replace",t),true}return s&&!m.valid&&console.log("Connection rejected by store validation:",m.reason,t),m.valid},[Y,C,s,y]),sr=Br.useCallback(t=>{let p=Y(t.source),g=Y(t.target),m=p?.type==="vertical-pdu",k=p?.data,u=p?.type==="device"&&k?.deviceType==="switch",A=!!t.targetHandle&&(t.targetHandle.startsWith("pwr")||t.targetHandle.startsWith("power")),O=!!t.targetHandle&&(t.targetHandle.startsWith("net-")||t.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(t.targetHandle)),U=p?.type==="tube"&&g?.type==="cable",ee=p?.type==="cable"&&g?.type==="tube",ae=U||ee,le=t.sourceHandle==="cable-button"&&t.targetHandle==="cable-button",Z="fiber";m&&A?Z="power":le?Z="thick-cable":ae&&(Z=P?"smoothstep":"fiber");let B;if((Z==="fiber"||Z==="smoothstep")&&!m){let S=Xe(t.source,t.sourceHandle);S&&(B={color:S.color,striped:S.striped});}else if(Z==="thick-cable"&&le){let S=p?.data;B={color:S?.color||(S?.tubeStartIndex?te(S.tubeStartIndex):"#6366f1")};}if(t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}if(t.targetHandle==="right"&&(S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B}),S)){E(S);return}}if(p?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}if(S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B}),S){E(S);return}}if(p?.type==="tube"&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(g?.type==="tube"&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if((g?.type==="cable"||g?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if(le&&t.source&&t.sourceHandle&&t.target&&t.targetHandle){let S=p?.data,q=S?.color||(S?.tubeStartIndex?te(S.tubeStartIndex):"#6366f1"),ue=j({edges:L.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:D,findBy:"source",data:{color:q}});if(ue){E(ue);return}if(ue=j({edges:L.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:D,findBy:"target",data:{color:q}}),ue){E(ue);return}}if(m&&A&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"power",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if(u&&O&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}let Re=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!Re.valid){if(y){if(t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}}if(m&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:A?"power":"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(u&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}s&&console.warn(`Connection rejected: ${Re.reason}`);return}let ve={...t,type:Z,zIndex:D({...t,id:"temp-id"}),data:B};E(S=>{let q=reactflow.addEdge(ve,S),ue=q[q.length-1];return ue&&(lo(bt=>new Set(bt).add(ue.id)),setTimeout(()=>{lo(bt=>{let po=new Set(bt);return po.delete(ue.id),po});},1e3)),q});},[E,C,D,Y,s,Xe,y,P]),dr=Br.useCallback((t,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let g=t.sourceHandle||"",m=t.targetHandle||"",k=p.sourceHandle||"",u=p.targetHandle||"";if(g.startsWith("tube-")&&k!==g){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}if(m.startsWith("tube-")&&u!==m){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}let A=Y(p.source),O=Y(p.target),U=A?.type==="vertical-pdu",ee=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),ae=A?.type==="tube"&&O?.type==="cable",le=A?.type==="cable"&&O?.type==="tube",Z=ae||le,B;U&&ee?B="power":Z?B=P?"smoothstep":"fiber":B="fiber";let Re;if((B==="fiber"||B==="smoothstep")&&!U){let ve=Xe(p.source,p.sourceHandle);ve&&(Re={color:ve.color,striped:ve.striped});}E(ve=>ve.map(q=>q.id===t.id?{...q,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:B,data:Re!==void 0?{...q.data,...Re}:q.data,zIndex:D({...p,id:q.id,type:B}),style:{...q.style,zIndex:D({...p,id:q.id,type:B})}}:q));},[E,Y,Xe,D,P,s]),cr=Br.useCallback((t,p)=>{let g=t.metaKey||t.ctrlKey;if(p.type==="tube"&&p.parentId&&!g){let k=ke().find(u=>u.id===p.parentId&&u.type==="cable");if(k){M(u=>u.map(A=>({...A,selected:A.id===k.id}))),c&&c(k);return}}if(g&&p.type==="device"){let m=p.data||{},k=m.view||(Array.isArray(m.rearPorts)&&m.rearPorts.length>0?"rear":"front"),u=k==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${p.id} from ${k} to ${u}`),b&&b(p.id,u),c&&c(p);}else c&&c(p);},[b,c,s,ke,M]),lr=Br.useCallback(()=>{},[]),pr=Br.useCallback((t,p)=>{l&&l(p);},[l]),[ce,gt]=Br.useState(null),[co,lo]=Br.useState(new Set);reactflow.useOnSelectionChange({onChange:({nodes:t})=>{if(t&&t.length===1){let p=t[0];if(p.type==="tube"&&p.parentId){let m=ke().find(k=>k.id===p.parentId&&k.type==="cable");if(m){gt(m),M(k=>k.map(u=>({...u,selected:u.id===m.id}))),c&&c(m);return}}gt(p),c&&c(p);}else gt(null),c&&c(null);}});let ur=Br.useCallback((t,{nodeId:p,handleType:g})=>{s&&console.log("Connection started from",{nodeId:p,handleType:g});},[s]),fr=Br.useCallback(t=>{s&&console.log("Connection ended",t);},[s]),gr=Br.useCallback(()=>{if(!ce)return;let t=Y(ce.id);if(t){if(t.type==="rack"){let m=((t.data||{}).face||"front")==="front"?"rear":"front";f?(f(t.id,m),b&&ke().filter(u=>u.parentId===t.id).forEach(u=>{b(u.id,m);})):M(k=>k.map(u=>u.id===t.id?{...u,data:{...u.data,face:m}}:u.parentId===t.id?{...u,data:{...u.data,view:m}}:u));return}if(t.type==="device"){let p=t.data||{},g=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,m=Array.isArray(p.ports)&&p.ports.length>0,u=(p.view||(g&&!m?"rear":"front"))==="front"?"rear":"front";b?b(t.id,u):M(A=>A.map(O=>O.id===t.id?{...O,data:{...O.data,view:u}}:O));}}},[ce,Y,f,b,M,ke]),br=Br.useMemo(()=>X.map(t=>{let p=t,g=Y(String(p.source)),m=Y(String(p.target)),k=lt(p.sourceHandle||"",g),u=lt(p.targetHandle||"",m),A=g&&g.data?.view,O=m&&m.data?.view,U=g?.type==="device"&&A==="rear",ee=m?.type==="device"&&O==="rear",B=U&&k!=="rear"&&(ee&&u!=="rear")?{...t.style,opacity:0,pointerEvents:"none",zIndex:0}:t.style;return {...t,style:B,className:co.has(t.id)?"edge-connecting":t.className}}),[X,co,Y]);return jsxRuntime.jsxs("div",{ref:ge,className:`${h||""} ${T==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",...v},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:R,edges:br,onNodesChange:t=>{or(t),$?n&&n(pe.current):C.setState({nodes:pe.current});},onEdgesChange:t=>{let p=t.filter(g=>{if(g.type==="remove"){let m=L.current.find(k=>k.id===g.id);if(m){let k=m.sourceHandle||"",u=m.targetHandle||"";if(k.startsWith("tube-")||u.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",m),false}}return true});p.length>0&&(G(p),$?i&&i(L.current):C.setState({edges:L.current}));},onConnect:sr,onConnectStart:ur,onConnectEnd:fr,onEdgeUpdate:dr,isValidConnection:ar,onNodeClick:cr,onNodeDoubleClick:lr,onNodeDragStart:rr,onNodeDrag:nr,onNodeDragStop:ir,onEdgeClick:pr,onInit:w,nodeTypes:er,edgeTypes:tr,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:true,nodesConnectable:true,elementsSelectable:true,selectNodesOnDrag:false,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:T==="light"?"#e5e5e5":"#2a2a2a"}),jsxRuntime.jsx(reactflow.Controls,{}),jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),F&&jsxRuntime.jsx("button",{className:"download-button",onClick:ft,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",...H},children:x}),ce&&(ce.type==="rack"||ce.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:t=>{t.preventDefault(),gr();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=ce.data;if(ce.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=ce.data;if(ce.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"}})()})})]})},Sn=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(Pn,{...e})});var Zo=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}}),Ko=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}}),qo=e=>{let o=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},r=o(e.termination_a),a=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${r}`,target:`device-${a}`,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}}},Hn=e=>{let o=[],r=[];return e.racks.forEach(a=>o.push(Zo(a))),e.devices.forEach(a=>o.push(Ko(a))),e.cables.forEach(a=>r.push(qo(a))),{nodes:o,edges:r}},Cn=e=>{let o=e.filter(n=>n.type==="rack"),r=e.filter(n=>n.type==="device"),a=e.filter(n=>!["rack","device"].includes(n.type));return o.forEach((n,i)=>{n.position={x:i*300,y:100};}),r.forEach(n=>{if(n.parentId){let i=o.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,s=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-s*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),a.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var We=class extends Error{constructor(r,a,n,i,d){super(`Device placement conflict: ${a} at U${n}-${n+i-1} in rack ${r}${d?` conflicts with ${d}`:""}`);this.rackId=r;this.deviceId=a;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function oo(e,o={}){let r=[],a=[];for(let n of e.devices)n.unit+n.height-1>e.units&&a.push({deviceId:n.id,uPosition:n.unit,uHeight:n.height,rackUHeight:e.units});for(let n=0;n<e.devices.length;n++){let i=e.devices[n],d=i.unit,s=i.unit+i.height-1;for(let c=n+1;c<e.devices.length;c++){let l=e.devices[c],b=l.unit,f=l.unit+l.height-1;d<=f&&s>=b&&r.push({deviceId:i.id,uPosition:i.unit,uHeight:i.height,conflictWith:l.id});}}return {isValid:r.length===0&&a.length===0,conflicts:r,outOfBounds:a}}function Jo(e,o,r={}){let{deviceTypeMapping:a={}}=r,n=a[e.type]||"device",i=De(o,e.unit,e.height);return {id:e.id,type:n,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}}}function En(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:[]}}}function Rn(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=oo(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 We(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=En(d);n.push(s);for(let c of d.devices)try{let l=Jo(c,s,o);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let b=Ze(s,{id:c.id,data:{label:c.name,uHeight:c.height}},i,c.unit);if(b!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${b} due to conflict`);let f={...c,unit:b},h=Jo(f,s,o);i.push(h);}else throw new We(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Tn(e){let o=[],r=e.filter(a=>a.type==="rack");for(let a of r){let i=e.filter(d=>d.type==="device"&&d.parentId===a.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:a.id,name:a.data.label,position:a.position,units:a.data.uHeight||42,uNumberingDirection:a.data.uNumberingDirection||"bottom-up",customHeaderText:a.data.customHeaderText,devices:i});}return o}function Dn(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.map(i=>i.id!==r?i:{...i,unit:a})})}function In(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!oo({...i,devices:[...i.devices,r]},a).isValid)throw new We(o,r.id,r.unit,r.height);return {...i,devices:[...i.devices,r]}})}function $n(e,o,r){return e.map(a=>a.id!==o?a:{...a,devices:a.devices.filter(n=>n.id!==r)})}var ze=class extends Error{constructor(r,a,n,i){super(`Splice placement conflict: ${a} at holder ${n} in tray ${r}${i?` conflicts with ${i}`:""}`);this.trayId=r;this.spliceId=a;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function ro(e,o={}){let r=[],a=[];for(let n of e.splices)(n.holder<1||n.holder>Ne)&&a.push({spliceId:n.id,holder:n.holder,max:Ne});for(let n=0;n<e.splices.length;n++){let i=e.splices[n];for(let d=n+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&&a.length===0,conflicts:r,outOfBounds:a}}function Qo(e,o){let r=Me(o,e.holder);return {id:e.id,type:"splice",position:r,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb}}}function _n(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Fn(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=ro(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 ze(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=_n(d);n.push(s);for(let c of d.splices)try{let l=Qo(c,s);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let b=[...n,...i],f=tt(s,{id:c.id,data:{label:c.name,holderPosition:c.holder}},b,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let h={...c,holder:f},v=Qo(h,s);i.push(v);}else throw new ze(d.id,c.id,c.holder)}}}return n.push(...i),n}function An(e){let o=[],r=e.filter(a=>a.type==="splice-tray");for(let a of r){let i=e.filter(d=>d.type==="splice"&&d.parentId===a.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb}));o.push({id:a.id,name:a.data.label,position:a.position,splices:i});}return o}function Wn(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.map(i=>i.id!==r?i:{...i,holder:a})})}function zn(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!ro({...i,splices:[...i.splices,r]},a).isValid)throw new ze(o,r.id,r.holder);return {...i,splices:[...i.splices,r]}})}function Ln(e,o,r){return e.map(a=>a.id!==o?a:{...a,splices:a.splices.filter(n=>n.id!==r)})}
|
|
2
|
-
exports.COUPLERS_PER_PANEL=
|
|
1
|
+
'use strict';var Or=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Or__default=/*#__PURE__*/_interopDefault(Or);var mr=()=>"bottom-up",Pe=e=>e.data.uNumberingDirection||mr(),Xe=(e,o,r)=>r==="bottom-up"?o-e+1:e,je=(e,o,r)=>r==="bottom-up"?o-e+1:e;var mt=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=e.data.uHeight||1,i=o.data.uHeight||42,d=Pe(o),s=60,c=r.y-s,l=Math.round(c/20)+1,h;d==="bottom-up"?h=Xe(l,i,d)-n+1:h=Xe(l,i,d);let f=i-n+1,m=Math.max(1,Math.min(f,h));if(d==="top-down"&&h<=1&&(m=1),!yt(o,e,m,a)){let k=Ge(o,e,a,m);k!==m&&(m=k);}let v;if(d==="bottom-up"){let k=m+n-1,E=je(k,i,d);v=s+(E-1)*20-1;}else {let k=je(m,i,d);v=s+(k-1)*20-1;}return {x:r.x,y:v,uPosition:m}},yt=(e,o,r,a)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;if(r<1||r+n-1>i)return false;let d=a.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,f=r+n-1,m=c,v=c+l-1;if(h<=v&&f>=m)return false}return true},Ge=(e,o,r,a=1)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;for(let d=a;d<=i-n+1;d++)if(yt(e,o,d,r))return d;return 1},De=(e,o,r=1)=>{let a=60,n=Pe(e),i=e.data.uHeight||42,d=je(o,i,n),s;if(n==="bottom-up"){let c=o+r-1,l=je(c,i,n);s=a+(l-1)*20-1;}else s=a+(d-1)*20-1;return {x:0,y:s}},fo=(e,o,r)=>{let a=e.data.uHeight||1,n=De(o,r,a);return {...e,position:n,data:{...e.data,uPosition:r}}},yr=(e,o)=>{let r=e.data.uPosition||1,a=e.data.uHeight||1,n=o.data.uHeight||42,i=Math.max(1,Math.min(n-a+1,r));return i!==r?fo(e,o,i):e};function ce(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var xt=({data:e,selected:o,id:r,onViewChange:a,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:s=0,status:c="active",uHeight:l=42,face:h="front",customHeaderText:f}=e,{getNodes:m,setNodes:v}=reactflow.useReactFlow(),k=m(),[E,w]=Or.useState(true),T=()=>{let H=Pe({data:e})==="bottom-up"?"top-down":"bottom-up";v(y=>y.map(P=>P.id===r?{...P,data:{...P.data,uNumberingDirection:H}}:P));},A=()=>{let x=h==="front"?"rear":"front";n?(n(r,x),a&&k.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);})):a?k.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);}):v(H=>H.map(y=>y.id===r?{...y,data:{...y.data,face:x}}:y.parentId===r?{...y,data:{...y.data,view:x}}:y));},W=()=>{let x=[],H=60,y=Pe({data:e});for(let P=1;P<=l;P++){let M=H+(P-1)*20-4,R=Xe(P,l,y);x.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${M}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:R},P));}return x};return jsxRuntime.jsxs("div",{className:`rack-node ${o?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${ce(c)}`,borderRadius:"8px",padding:0,width:`${300}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:[jsxRuntime.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:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxRuntime.jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",h]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),w(!E);},style:{background:E?"#10b981":"#374151",color:E?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${E?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),T();},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 ${Pe({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Pe({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),A();},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"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"}}),E&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:W()})]})};var wt=({data:e,selected:o})=>{let{label:r,status:a="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${ce(a)}`,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:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:r})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:ce(a),borderRadius:"50%"}})]})};var kt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},className:h})=>{let[f,m,v]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),{bandwidth:k,length:E,color:w="#00FFFF",striped:T=false}=s||{},A={...l,stroke:w,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:f,style:A}),T&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&s&&(k||E)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${v}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[k&&jsxRuntime.jsx("div",{children:k}),E&&jsxRuntime.jsxs("div",{children:[E,"m"]})]})})]})};var vt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l})=>{let[h]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),f=c?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:h,markerEnd:l,style:(()=>{let v={stroke:c?.color||"#f59e0b",strokeWidth:f==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return f==="C19"?{...v,strokeDasharray:"none"}:{...v,strokeDasharray:"6,3"}})()})};var bo=({data:e,selected:o,style:r={},...a})=>{let{color:n="#00FFFF"}=e||{},i={...r,stroke:n,strokeWidth:o?4:3};return jsxRuntime.jsx(reactflow.SmoothStepEdge,{...a,data:e,selected:o,style:i})};function Dr({sourceX:e,sourceY:o,targetX:r,targetY:a,sourcePosition:n,targetPosition:i}){let d=n===reactflow.Position.Left||n===reactflow.Position.Right,s;if(d){let c=(e+r)/2;s=`M ${e},${o} L ${c},${o} L ${c},${a} L ${r},${a}`;}else {let c=(o+a)/2;s=`M ${e},${o} L ${e},${c} L ${r},${c} L ${r},${a}`;}return s}var xo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...h})=>{let{color:f="#00FFFF",striped:m=false}=s||{},v=Dr({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),k={...l,stroke:f,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,style:k}),m&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var wo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l,selected:h})=>{let{color:f="#6366f1",label:m}=c||{},[v,k,E]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),w={...s,stroke:f,strokeWidth:8,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,markerEnd:l,style:w}),m&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${k}px,${E}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:m})})]})};var No=(r=>(r.FULL="full",r.HALF="half",r))(No||{});var St={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 Ie(e){let o=St[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let r=o.amperage===16,a=r?12:8,n=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:a,height:n,color:o.color,borderColor:o.borderColor,fontSize:r?"3px":"4px",...i}}function Je(e){let o=St[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function Lr(e){return Je(e).amperage===16}function Ht(e){return e%10<8?"C13":"C19"}function Qe(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Et=({data:e,selected:o})=>{let{label:r,status:a="active",deviceType:n="server",manufacturer:i,role:d,uHeight:s=1,width:c="full",ports:l=[],rearPorts:h=[],view:f}=e,m=f||(h.length>0&&l.length===0?"rear":"front"),v={};v["net-top"]="front",v["net-bottom"]="front",l.length>0&&l.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="front";});}),v["pwr-left-1"]="rear",v["pwr-left-2"]="rear",v["net-right-1"]="rear",v["net-right-2"]="rear",h.length>0&&h.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="rear";});});let k=s*20,E=c==="half"?"150px":"304px",w=c==="half"?"150px":void 0,T=(x,H)=>{let y=[];if(x.length===0)return y;let P=Math.max(4,Math.floor(k*.4)),M=Math.max(2,Math.floor(k*.2));return x.forEach((R,C)=>{R.ports.forEach((D,I)=>{let O=!!D.type&&D.type.includes("power");if(H==="front"&&O)return;let _=O?`${D.label}`:`${R.name}-${D.label}`,Z=D.connected,L="#6b7280";if(Z)if(D.type?.includes("power"))L=D.type==="power_c19"?"#fbbf24":"#f59e0b";else if(D.type==="console"||D.type==="mgmt")L="#8b5cf6";else if(D.type==="usb")L="#10b981";else switch(D.cableType){case "smf":L="#fbbf24";break;case "cat6":L="#8b5cf6";break;case "om3":L="#06b6d4";break;case "om4":L="#8b5cf6";break;case "om5":L="#84cc16";break;case "cat5e":L="#3b82f6";break;case "cat6a":L="#ef4444";break;case "cat7":L="#f97316";break;case "fiber":L="#3b82f6";break;case "ethernet":L="#10b981";break;default:L="#10b981";}let $=reactflow.Position.Top,j={width:`${P}px`,height:`${M}px`,background:Z?L:"#6b7280",border:`1px solid ${Z?L:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(H==="front")I%2===0?($=reactflow.Position.Top,j.transform="translateY(50%)",j.left=`${I/2*(P+2)}px`):($=reactflow.Position.Bottom,j.transform="translateY(-50%)",j.left=`${(I-1)/2*(P+2)}px`);else if((n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel"||n==="switch")I%2===0?($=reactflow.Position.Top,j.transform="translateY(50%)",j.left=`${I/2*(P+2)}px`):($=reactflow.Position.Bottom,j.transform="translateY(-50%)",j.left=`${(I-1)/2*(P+2)}px`);else if(D.type?.includes("power")){$=reactflow.Position.Left,j.transform="translateX(50%)";let ke=k<=20?10:20,gt=k<=20?30:50;j.top=`${ke+I*gt}%`;let Ye=Qe(r),pe=Ie(Ye);j={...j,width:`${pe.width}px`,height:`${pe.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:pe.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:pe.borderRadius,clipPath:pe.clipPath};}else $=reactflow.Position.Right,j.transform="translateX(-50%)",j.top=`${25+I*50}%`;let ae=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",se;if(O)se="target";else if(n==="switch"||n==="router")se="source",y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${_}-target`,type:"target",position:$,style:j,title:`${R.name} - ${D.label} (input) ${Z?"(connected)":"(disconnected)"}`},`${_}-target`));else if(ae){se=H==="rear"?"source":"target";let me=H==="rear"?"target":"source";y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${_}-${me}`,type:me,position:$,style:j,title:`${R.name} - ${D.label} (${me}) ${Z?"(connected)":"(disconnected)"}`},`${_}-${me}`));}else se=Z?"source":"target";y.push(jsxRuntime.jsx(reactflow.Handle,{id:_,type:se,position:$,style:j,title:`${R.name} - ${D.label} ${Z?"(connected)":"(disconnected)"}`,children:O?I+1:void 0},_));});}),y},A=()=>{let x=[],H=Math.max(4,Math.floor(k*.4)),y=Math.max(2,Math.floor(k*.2));if(m==="front"){if(l.length>0)return T(l,"front");if(n==="switch"&&(r.toLowerCase().includes("agg")||r.toLowerCase().includes("core")||d==="agg"||d==="core"))return W();x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(m==="rear"){if(h.length>0)return T(h,"rear");let P=n==="switch",R=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!R){let C=Qe(r),D=Je(C),I=Ie(C),O=k<=20?"10%":"25%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${I.width}px`,height:`${I.height}px`,background:I.color,border:`1px solid ${I.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:O,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:I.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:I.borderRadius,clipPath:I.clipPath},title:`Power Port 1 (${D.type}) - ${D.voltage}V, ${D.amperage}A`,children:"1"},"pwr-1"));let _=k<=20?"50%":"75%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${I.width}px`,height:`${I.height}px`,background:I.color,border:`1px solid ${I.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:_,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:I.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:I.borderRadius,clipPath:I.clipPath},title:`Power Port 2 (${D.type}) - ${D.voltage}V, ${D.amperage}A`,children:"2"},"pwr-2"));}!P&&!R&&(x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}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")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}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 x},W=()=>{let x=[],H=Math.max(10,Math.floor(k*.45)),y=Math.max(5,Math.floor(k*.25));for(let P=1;P<=16;P++){let M=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(P-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push(M);}for(let P=17;P<=32;P++){let M=P-16,R=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${(M-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push(R);}for(let P=1;P<=4;P++){let M=Math.max(4,Math.floor(k*.3)),R=Math.max(3,Math.floor(k*.15));x.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${P}`,type:"source",position:reactflow.Position.Right,style:{width:`${M}px`,height:`${R}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${P}`},`uplink-${P}`));}return x};return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${ce(a)}`,borderRadius:"2px",padding:"0px",width:E,...w&&{left:w},height:`${k}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:[jsxRuntime.jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r}),s>1&&jsxRuntime.jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:i})]}),s>1&&jsxRuntime.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"]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:ce(a),borderRadius:"50%"}}),A()]})};var Rt=({data:e,selected:o})=>{let{label:r,status:a="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:s}=e,c=n*4.2,l=()=>{let m=Math.ceil(i/10),v=Array(10).fill(0).map((y,P)=>P<8?"10A":"16A");for(let y=0,P=0;y<m;++y)for(let M=0;M<10&&P<i;++M,++P){v[M];}let T=[],A=15,H=(c-A-3)/(i-9)*.5;for(let y=0;y<i;y++){let P=A-2+H*y,M=`${y+1}`;if(s&&(s==="top"&&y===0||s==="middle"&&y===Math.floor(i/2)||s==="bottom"&&y===i-1)){T.push(h(P));continue}let C=Ht(y),D=Ie(C),I=Math.round((d-D.width)/2-1);T.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:M,style:{position:"absolute",left:`${I}px`,top:`${P-D.height/2}px`,width:`${D.width}px`,height:`${D.height}px`,background:D.color,border:`1px solid ${D.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:D.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:D.borderRadius,clipPath:D.clipPath},title:`Power Port ${y+1} (${C})`,children:y+1},`handle-${M}`));}return T},h=f=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(d-16)/2}px`,top:`${f-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.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"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.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 jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${ce(a)}`,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:[jsxRuntime.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:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:r})}),jsxRuntime.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 It=({data:e,selected:o,id:r})=>{let{lossDb:a}=e||{},n=reactflow.useEdges(),i=n.find(m=>m.target===r&&m.targetHandle==="left"),d=n.find(m=>m.source===r&&m.sourceHandle==="right"),s=n.find(m=>m.target===r&&m.targetHandle==="right"),c=d||s,l=i?.data?.color||"#555",h=c?.data?.color||"#555",f=!!i&&!!c;return jsxRuntime.jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:69,height:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:l}}),jsxRuntime.jsx("div",{style:{background:h}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1}}),f&&jsxRuntime.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}}),f&&typeof a=="number"&&jsxRuntime.jsx("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold"},children:`${a.toFixed(2)} dB`}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:l,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:h,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:h,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var we=20,He=32,Ho=4,Ne=12,Ur=69,Ce=80,$t=(Ce-Ur)/2;var Ft=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=He,i=r.y-n,d=Math.round(i/we)+1,c=Math.max(1,Math.min(Ne,d));if(!_t(o,e,c,a)){let f=et(o,e,a,c);if(f!==c)return {x:$t,y:n+(f-1)*we+5,holderPosition:f}}let h=n+(c-1)*we+5;return {x:$t,y:h,holderPosition:c}},_t=(e,o,r,a)=>!a.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==o.id).some(i=>i.data.holderPosition===r),et=(e,o,r,a=1)=>{for(let n=a;n<=Ne;n++)if(_t(e,o,n,r))return n;for(let n=a-1;n>=1;n--)if(_t(e,o,n,r))return n;return 1},Me=(e,o)=>{let n=He+(o-1)*we+5;return {x:$t,y:n}};var zt=({data:e,selected:o})=>{let{label:r="Splice Tray"}=e||{},[a,n]=Or.useState(false),i=()=>{if(!a)return null;let d=[],s=He;for(let c=1;c<=Ne;c++){let l=s+(c-1)*we;d.push(jsxRuntime.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:`${we}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${Ce}px`,height:`${He+Ne*we+Ho}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:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${He}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:r}),jsxRuntime.jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!a);},style:{background:a?"#10b981":"#374151",color:a?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${a?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:He,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Co=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function oe(e){let o=(e-1)%12;return Co[o]}function Eo(e){return e>12}function Ue(e){let o=oe(e);return Eo(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function Lt(e){return oe(e)}var Mt=({data:e,selected:o,id:r})=>{let{fibersPerTube:a=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=Math.max(1,Math.min(24,Number(a)||12)),s=14,c=4,l=1,h=2,f=20,m=d*s+(d-1)*c,v=Math.max(60,m+l*2+h*2),k=oe((n-1)%12+1),E=`tube-${n}`,w=18,T={width:w,height:w,borderRadius:"50%",opacity:.25,pointerEvents:"auto",background:k,backgroundColor:k,border:`2px solid ${k}`,"--fiber-bg":k},A=()=>i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,W=()=>{let x=[],H=v-h*2-l*2,y,P,M=false;i==="left"?(y=l,P=reactflow.Position.Top):i==="right"?(y=l+H-m,P=reactflow.Position.Top,M=true):(y=l+(H-m)/2,P=reactflow.Position.Top);for(let R=0;R<d;R++){let C=M?d-R:R+1,D=Ue(C),I=oe(C),O=y+R*(s+c),_=l,Z=D.backgroundImage?D.backgroundImage:I,L={position:"absolute",left:`${O}px`,top:`${_}px`,width:s,height:s,borderRadius:"50%",border:"none",background:Z,backgroundColor:I,zIndex:10,cursor:"pointer","--fiber-bg":I};D.backgroundImage&&(L["--fiber-bg-image"]=D.backgroundImage);let $=`fiber-${C}`;x.push(jsxRuntime.jsxs(Or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:$,type:"target",position:P,className:"tube-fiber-handle",isConnectable:true,style:L,"data-fiber-idx":C,"data-fiber-color":I}),jsxRuntime.jsx(reactflow.Handle,{id:$,type:"source",position:P,className:"tube-fiber-handle",isConnectable:true,style:L,"data-fiber-idx":C,"data-fiber-color":I})]},`fiber-${C}`));}return x};return jsxRuntime.jsxs("div",{style:{width:v,height:f,borderRadius:4,background:"#111827",border:`${h}px solid ${o?"#3b82f6":k}`,position:"relative",boxShadow:o?`0 0 0 ${h}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:l,boxSizing:"border-box"},children:[W(),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"target",position:A(),isConnectable:true,style:T,"data-tube-idx":n,"data-tube-color":k}),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"source",position:A(),isConnectable:true,style:T,"data-tube-idx":n,"data-tube-color":k})]})};var Ut=({data:e,selected:o})=>{let{tubeCount:r=12,fibersPerTube:a=12,fiberCount:n,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),f=8,m=2,v=6,k=v+f+4,E=60,w=Math.max(120,l*(f+m)+v*2),T=n??l*(Number(a)||12),A=d??`${T}f Cable`,W=i?`Cable ID ${i}`:void 0,x=oe(h),H=c||x,y=o?"#3b82f6":H,P=()=>{let I=[];for(let O=0;O<l;O++){let _=h+O,Z=Ue(_),L=oe(_),$=v+O*(f+m),j=-4,V=Z.backgroundImage?Z.backgroundImage:L,ae={position:"absolute",left:`${$}px`,top:`${j}px`,width:f,height:f,borderRadius:"50%",border:"none",background:V,backgroundColor:L,zIndex:10,cursor:"pointer","--fiber-bg":L};Z.backgroundImage&&(ae["--fiber-bg-image"]=Z.backgroundImage);let se=`tube-${_}`;I.push(jsxRuntime.jsxs(Or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:se,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":_,"data-tube-idx":_,"data-tube-color":L}),jsxRuntime.jsx(reactflow.Handle,{id:se,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":_,"data-tube-idx":_,"data-tube-color":L})]},`tube-${_}`));}return I},M="cable-button",R=8,C={width:R,height:R,borderRadius:"50%",background:H,backgroundColor:H,border:`1px solid ${H}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:w,height:E,borderRadius:4,background:"#111827",border:`2px solid ${y}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:v,paddingTop:k,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[P(),jsxRuntime.jsx(reactflow.Handle,{id:M,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:C,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx(reactflow.Handle,{id:M,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:C,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:A}),W&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:W})]})};var Bt=({data:e,selected:o,id:r})=>{let{connector:a="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:s}=e||{},c=reactflow.useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,h=Math.max(1,Math.min(4,l)),f=7,m=3,v=3,k=60,E=30,w=h*f+(h-1)*m,T=Math.max(E,w+v*2),A=Math.max(k,80),W=(y,P)=>{let M=`${y}-${P+1}`;return c.find(C=>C.source===r&&C.sourceHandle===M||C.target===r&&C.targetHandle===M)?.data?.color||"#555"},x=y=>{let P=[],M=y==="left"?reactflow.Position.Left:reactflow.Position.Right,R=y==="left"?d:s;for(let C=0;C<h;C++){let D=C+1,I=`${y}-${D}`,O=W(y,C),L=v+(T-w)/2+C*(f+m),$={position:"absolute",left:y==="left"?-5:void 0,right:y==="right"?-5:void 0,top:`${L}px`,width:f,height:f,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};P.push(jsxRuntime.jsxs(Or__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:I,type:"target",position:M,isConnectable:true,style:$}),jsxRuntime.jsx(reactflow.Handle,{id:I,type:"source",position:M,isConnectable:true,style:$})]},I)),R&&R[C]&&P.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:y==="left"?-30:void 0,right:y==="right"?-30:void 0,top:`${L}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:y==="left"?"right":"left",width:"25px"},children:R[C]},`${I}-label`));}return P},H=i||`${a}-${h}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:A,height:T,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:`${v}px`,boxSizing:"border-box"},children:[x("left"),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:H})}),x("right")]})};var Ee=32,st=30,jr=24,Gr=80,it=400,at=300,Wo=2,he=8,zo=120;function Ot(e){let{couplerFiberCount:o}=e.data||{},r=typeof o=="number"&&[1,2,4].includes(o)?o:2,a=Math.max(1,Math.min(4,r)),n=7,i=3,d=3,s=60,c=30,l=a*n+(a-1)*i,h=Math.max(c,l+d*2);return {width:Math.max(s,80),height:h}}function dt(e){let{fibersPerTube:o=12}=e.data||{},r=Math.max(1,Math.min(24,Number(o)||12)),a=14,n=4,i=1,d=2,s=20,c=r*a+(r-1)*n;return {width:Math.max(60,c+i*2+d*2),height:s}}function Lo(e){return {width:Ce,height:0}}function Oe(e){return e.type==="coupler"?Ot(e):e.type==="tube"?dt(e):e.type==="splice-tray"?Lo():{width:80,height:30}}function Mo(e){return e.data?.panelWidth||it}function Zr(e){return e.data?.panelHeight||at}function Uo(e){return Mo(e)-Wo*2-he*2}function Kr(e,o){return Uo(e)-o}function Bo(e,o=st){return Math.floor(e/o)+1}function Oo(e,o=st){return (e-1)*o}function qr(e,o,r){let a=st,n=Bo(r.y,a),i=Oo(n,a);return {x:r.x,y:i,slotPosition:n}}function Yt(e,o){if(o.length===0)return {width:e.data?.panelWidth||it,height:e.data?.panelHeight||at};let r=o.some(l=>l.type==="tube"),a=o.some(l=>l.type==="splice-tray"),n=o.some(l=>l.type==="coupler"),i,d=5;if(r&&a&&n){let l=0,h=0;for(let f of o)if(f.type==="tube"){let m=dt(f);m.width>l&&(l=m.width);}else if(f.type==="coupler"){let m=Ot(f);m.width>h&&(h=m.width);}i=he+l+zo+Ce+h+d;}else {let l=0;for(let h of o){let f=Oe(h),m=(h.position?.x||0)+f.width;m>l&&(l=m);}i=l+he+d;}i=Math.max(e.data?.panelWidth||it,i);let s=Ee;for(let l of o){let h=Oe(l),f=(l.position?.y||0)+h.height;f>s&&(s=f);}let c=Math.max(e.data?.panelHeight||at,s+he);return {width:i,height:c}}function Yo(e,o,r){if(e===0)return 0;if(e===1)return o;let a=e*o,n=r-a,i=Math.max(5,n/(e-1));return o+i}function Jr(e,o,r){return Yo(e,o,r)}var _o=20,Fo=400,Ao=300;function Vo(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||Fo,height:e.data?.closureHeight||e.data?.panelHeight||Ao};let r=o.some(c=>c.type==="tube"),a=o.some(c=>c.type==="splice-tray"),n,i=5;if(r&&a){let c=0,l=0,h=0,f=o.filter(v=>v.type==="tube"),m=o.filter(v=>v.type==="splice-tray");if(f.length>0&&m.length>0){let v=f.map(A=>A.position?.x||0);Math.min(...v);Math.max(...v);let w=m.map(A=>A.position?.x||0),T=w.reduce((A,W)=>A+W,0)/w.length;for(let A of f){let W=dt(A);(A.position?.x||0)<T?W.width>c&&(c=W.width):W.width>l&&(l=W.width);}m.length>0&&(h=Ce),n=he+c+_o+h+_o+l+i;}else {let v=0;for(let k of o){let E=Oe(k),w=(k.position?.x||0)+E.width;w>v&&(v=w);}n=v+he+i;}}else {let c=0;for(let l of o){let h=Oe(l),f=(l.position?.x||0)+h.width;f>c&&(c=f);}n=c+he+i;}n=Math.max(e.data?.closureWidth||e.data?.panelWidth||Fo,n);let d=Ee;for(let c of o){let l=Oe(c),h=(c.position?.y||0)+l.height;h>d&&(d=h);}let s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Ao,d+he);return {width:n,height:s}}var jt=({data:e,selected:o,id:r})=>{let{label:a="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:s,setNodes:c}=reactflow.useReactFlow(),l=Or.useRef(false),h=Or.useMemo(()=>s().filter(A=>A.parentId===r),[s,r]),f=Or.useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),m=Or.useMemo(()=>i&&d?{width:i,height:d}:h.length===0?{width:i||400,height:d||300}:Yt(f,h),[h,f,i,d]);Or.useEffect(()=>{if(i&&d||l.current)return;let T=i,A=d,W=Math.abs((T||0)-m.width),x=Math.abs((A||0)-m.height);(W>1||x>1)&&(l.current=true,c(H=>H.map(y=>y.id===r?{...y,data:{...y.data,panelWidth:m.width,panelHeight:m.height}}:y)),setTimeout(()=>{l.current=false;},0));},[r,m.width,m.height,i,d,c]);let v=m.width,k=m.height,E=Ee,w=n||a;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${v}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:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${E}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:w})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:E,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Kt=({data:e,selected:o,id:r})=>{let{label:a="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:h}=reactflow.useReactFlow(),f=Or.useRef(false),m=Or.useMemo(()=>l().filter(H=>H.parentId===r),[l,r]),v=Or.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=Or.useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:m.length===0?{width:i||s||400,height:d||c||300}:Vo(v,m),[m,v,i,d,s,c]);Or.useEffect(()=>{if(i&&d||s&&c||f.current)return;let x=i||s,H=d||c,y=Math.abs((x||0)-k.width),P=Math.abs((H||0)-k.height);(y>1||P>1)&&(f.current=true,h(M=>M.map(R=>R.id===r?{...R,data:{...R.data,closureWidth:k.width,closureHeight:k.height}}:R)),setTimeout(()=>{f.current=false;},0));},[r,k.width,k.height,i,d,s,c,h]);let E=k.width,w=k.height,T=Ee,A=n||a,W=E/2;return jsxRuntime.jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${W}px ${W}px 12px 12px`,padding:0,width:`${E}px`,height:`${w}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",transform:"translateX(-4px)"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${T}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${W}px ${W}px 0 0`,borderBottom:"1px solid #4b5563",transform:"translateX(4px)"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:A})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:T,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};function dn(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let r=o.edges.some(w=>w.source===e.source&&w.sourceHandle===e.sourceHandle),a=o.edges.some(w=>w.target===e.target&&w.targetHandle===e.targetHandle);if(r)return {valid:false,reason:"Source port is already connected"};if(a)return {valid:false,reason:"Target port is already connected"};let n=e.sourceHandle,i=e.targetHandle,d=o.nodes.find(w=>w.id===e.source),s=o.nodes.find(w=>w.id===e.target),c=(w,T)=>{if(!w)return false;let A=w.startsWith("pwr")||w.startsWith("power"),W=T?.type==="vertical-pdu"&&w!=="mgmt-net-1";return A||W},l=(w,T)=>{if(!w)return false;if(T?.type==="vertical-pdu"&&w==="mgmt-net-1"||T?.type==="tube"&&w.startsWith("fiber-")||(T?.type==="tube"||T?.type==="cable")&&w.startsWith("tube-")||T?.type==="splice"&&(w==="left"||w==="right"))return true;let A=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("Fiber")||w.includes("Ports"),W=/^[A-Z0-9]+-\d+$/.test(w)&&!w.startsWith("pwr")&&!w.startsWith("power");return A||W},h=c(n,d),f=c(i,s),m=l(n,d),v=l(i,s);if(h&&v||f&&m)return {valid:false,reason:"Cannot connect network cable to power port"};if(h&&!f||f&&!h)return {valid:false,reason:"Power ports must connect to power-compatible ports"};let k=d?.type==="vertical-pdu",E=s?.type==="vertical-pdu";if(h||f){let w=k?s:E?d:null,T=k?d:E?s:null;if(w&&T&&o.edges.filter(x=>{let H=c(x.sourceHandle||""),y=c(x.targetHandle||""),P=x.source===w.id||x.target===w.id;return (H||y)&&P}).some(x=>x.source===T.id||x.target===T.id))return {valid:false,reason:"Dual-feed required: connect second power to a different PDU"}}return {valid:true}}function ct(e,o){if(!o)return;let r=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,a=o.data??{},n=a.handleSideMap;if(n&&n[r])return n[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(a.ports)?a.ports:[],d=Array.isArray(a.rearPorts)?a.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 qt(e={},o={}){let r={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},a=new Set;return {getState:()=>r,setState:f=>{r={...r,...f},a.forEach(m=>m(r));},subscribe:f=>(a.add(f),()=>a.delete(f)),selectEdgeZIndex:f=>{let m=r.nodes.find(H=>H.id===f.target);if(!m||m.type!=="device")return 1e3;let v=m.data?.view||"front",k=ct(f.targetHandle||"",m);if(k)return v===k?1e3:500;let E=(f.targetHandle||"").toString(),w=E.toLowerCase(),T=w.startsWith("pwr")||w.startsWith("power"),A=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),W=/^[A-Z0-9]+-\d+$/i.test(E)&&!w.startsWith("pwr")&&!w.startsWith("power"),x=A||W;return T?v==="rear"?1e3:500:x?v==="front"?1e3:500:1e3},validateConnection:f=>(o.validateConnection||dn)(f,r),selectNodeById:f=>r.nodes.find(m=>m.id===f),selectConnectedEdges:f=>r.edges.filter(m=>m.source===f||m.target===f)}}function cn(e){let o=n=>e.subscribe(n),r=()=>e.getState();return Or.useSyncExternalStore(o,r,r)}function Qt(e){let o=a=>e.subscribe(a),r=()=>e.getState().nodes;return Or.useSyncExternalStore(o,r,r)}function eo(e){let o=a=>e.subscribe(a),r=()=>e.getState().edges;return Or.useSyncExternalStore(o,r,r)}function Xo(e){return e.selectEdgeZIndex}function jo(e){let o=300,r=(e.data.uHeight||42)*20,a=e.position.x,n=e.position.x+o,i=e.position.y,d=e.position.y+r;return {left:a,right:n,top:i,bottom:d}}function lt(e,o){let r=jo(o);return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom}function pt(e,o){let r=null,a=1/0;for(let n of o){if(!lt(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<a&&(a=i,r=n);}return r}function G(e){let{edges:o,connection:r,edgeType:a,selectEdgeZIndex:n,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(E=>i==="source"?E.source===c&&E.sourceHandle===s:E.target===c&&E.targetHandle===s);if(!l)return null;let h=o.filter(E=>E.id!==l.id),f=reactflow.addEdge(r,h),m=f[f.length-1],v=n({...r,id:m.id,type:a}),k={...m,type:a,zIndex:v,style:{...m.style,zIndex:v},data:d!==void 0?d:m.data};return [...f.slice(0,-1),k]}var vn=(e,o,r)=>({rack:a=>jsxRuntime.jsx(xt,{...a,onViewChange:e,onRackFaceChange:o,isDragOver:r?r()===a.id:false}),fiber:wt,device:Et,"vertical-pdu":Rt,splice:It,"splice-tray":zt,tube:Mt,cable:Ut,coupler:Bt,"patch-panel":jt,closure:Kt}),Pn={fiber:kt,power:vt,smoothstep:bo,step:xo,"thick-cable":wo},Sn=({nodes:e,edges:o,initialNodes:r,initialEdges:a,onNodesChange:n,onEdgesChange:i,store:d,debug:s,onNodeClick:c,onEdgeClick:l,onViewChange:h,onRackFaceChange:f,className:m,style:v,alignRacksToBottom:k,colorMode:E="dark",onInit:w,onFlowMethods:T,showDownloadButton:A=false,downloadButtonPosition:W="top-right",downloadButtonText:x="Download Image",downloadButtonStyle:H,allowReconnectExisting:y=false,useSmoothstepEdgesForTubes:P=false,connectOnClick:M=true})=>{let R=Array.isArray(e)&&Array.isArray(o),C=Or__default.default.useMemo(()=>d||qt({nodes:R?e||[]:r||e||[],edges:R?o||[]:a||o||[],debug:s}),[d,R,s]),D=Qt(C),I=eo(C),[O,_,Z]=reactflow.useNodesState(D),[L,$,j]=reactflow.useEdgesState(I),V=Xo(C),ae=Or.useRef(null),{toObject:se,setViewport:me,setNodes:ut,setEdges:ft,getNodes:ke}=reactflow.useReactFlow();Or.useEffect(()=>{T&&T({toObject:se,setViewport:me,setNodes:t=>{ut(t),C.setState({nodes:t});},setEdges:t=>{ft(t),C.setState({edges:t});},toImage:t=>ae.current?htmlToImage.toPng(ae.current,t):Promise.reject(new Error("ReactFlow wrapper not available"))});},[T,se,me,ut,ft,C]);let gt=Or.useCallback(()=>{if(!ae.current){s&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(ae.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:E==="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);});},[E,s]),[Ye,pe]=Or.useState(null),io=Or.useRef(null),ao=Or.useRef(h),so=Or.useRef(f);Or.useEffect(()=>{ao.current=h;},[h]),Or.useEffect(()=>{so.current=f;},[f]),Or.useEffect(()=>{io.current=Ye;},[Ye]);let co=Or.useCallback(()=>io.current,[]),tr=Or.useMemo(()=>vn((t,p)=>ao.current?.(t,p),(t,p)=>so.current?.(t,p),co),[co]),or=Or.useMemo(()=>Pn,[]),ge=Or.useRef(O);Or.useEffect(()=>{ge.current=O;},[O]);let z=Or.useRef(L);Or.useEffect(()=>{z.current=L;},[L]),Or.useEffect(()=>{_(D);},[D,_]),Or.useEffect(()=>{$(I);},[I,$]),Or.useEffect(()=>{R&&C.setState({nodes:e||[]});},[R,e,C]),Or.useEffect(()=>{R&&C.setState({edges:o||[]});},[R,o,C]),Or.useEffect(()=>{if(!k||!O||O.length===0)return;let t=O.filter(U=>U.type==="rack");if(t.length===0)return;let p=t.map(U=>{let de=U.data?.uHeight||42,fe=60+de*20;return (U.position?.y||0)+fe}),b=Math.min(...p),g=Math.max(...p);if(g-b<20)return;let u=g,F=O.map(U=>{if(U.type!=="rack")return U;let de=U.data?.uHeight||42,fe=60+de*20,K=(U.position?.y||0)+fe,B=u-K;return Math.abs(B)<5?U:{...U,position:{x:U.position?.x||0,y:(U.position?.y||0)+B}}});F.some((U,te)=>U.position!==O[te].position)&&_(F);},[k,O,_]);let X=Or.useCallback(t=>ge.current.find(p=>p.id===t),[]),Ve=Or.useCallback((t,p)=>{if(!t||!p)return;let b=X(t);if(!b)return;if(b.type==="tube"&&p.startsWith("fiber-")){let N=p.replace("fiber-",""),u=parseInt(N,10);if(u>=1&&u<=24){let F=Lt(u),Y=u>12;return {color:F,striped:Y}}}if((b.type==="cable"||b.type==="tube")&&p.startsWith("tube-")){let N=p.replace("tube-",""),u=parseInt(N,10);if(u>=1&&u<=24){let F=oe(u),Y=u>12;return {color:F,striped:Y}}}let g=b.data;if(g.color)return {color:g.color}},[X]);Or.useEffect(()=>{$(t=>t.map(p=>{let b=V(p);return {...p,zIndex:b,style:{...p.style,zIndex:b}}}));},[O,$,V]),Or.useEffect(()=>{let t=O.map(b=>{if(b.type==="coupler"&&b.parentId){let g=X(b.parentId);if(g&&(g.type==="patch-panel"||g.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 g=X(b.parentId);if(g&&g.type==="splice-tray"){let N=Me(g,b.data.holderPosition);return {...b,position:N}}}if(b.type==="device"&&b.parentId&&b.data.uPosition&&(!b.position||b.position.x===0&&b.position.y===0)){let g=X(b.parentId);if(g){let N=De(g,b.data.uPosition);return {...b,position:N}}}return b});t.some((b,g)=>{let N=O[g];return b.extent!==N.extent||b.position?.x!==N.position?.x||b.position?.y!==N.position?.y})&&_(t);},[O,_,X]);let rr=Or.useCallback(t=>{let p=t.map(b=>{if(b.type==="position"&&b.position){let g=X(b.id);if(g&&g.type==="coupler"&&g.parentId){let N=X(g.parentId);if(N&&(N.type==="patch-panel"||N.type==="closure")){if(!g.extent||g.extent!=="parent"){let u={...g,extent:"parent"};_(F=>F.map(Y=>Y.id===g.id?u:Y));}return {...b,position:g.position||{x:0,y:0}}}}if(g&&(g.type==="tube"||g.type==="splice-tray")&&g.parentId){let N=X(g.parentId);if(N&&N.type==="closure"){if(!g.extent||g.extent!=="parent"){let u={...g,extent:"parent"};_(F=>F.map(Y=>Y.id===g.id?u:Y));}return {...b,position:g.position||{x:0,y:0}}}}if(g&&g.type==="splice"&&g.parentId){let N=X(g.parentId);if(N&&N.type==="splice-tray"){let u=Ft(g,N,b.position,ge.current);if(u.holderPosition!==void 0){let F={...g,data:{...g.data,holderPosition:u.holderPosition}};_(Y=>Y.map(U=>U.id===g.id?F:U));}return {...b,position:{x:u.x,y:u.y}}}}if(g&&g.type==="device"&&g.parentId){let N=X(g.parentId);if(N){let u=mt(g,N,b.position,ge.current);if(u.uPosition!==void 0){let F={...g,data:{...g.data,uPosition:u.uPosition}};_(Y=>Y.map(U=>U.id===g.id?F:U));}return {...b,position:{x:u.x,y:u.y}}}}if(g&&g.type==="device"&&g.parentId){let N=X(g.parentId);if(N){let u=N;if(!lt(b.position,u)){let F=b.position.x+u.position.x,Y=b.position.y+u.position.y,U={...g,parentId:void 0,extent:void 0,data:{...g.data,uPosition:void 0}};return _(te=>te.map(de=>de.id===g.id?U:de)),{...b,position:{x:F,y:Y}}}}}}return b});Z(p);},[Z,_,X]),nr=Or.useCallback((t,p)=>{pe(null);},[]),ir=Or.useCallback((t,p,b)=>{if(p.type==="device"&&!p.parentId){let g=ge.current.filter(u=>u.type==="rack").map(u=>u),N=pt(p.position,g);pe(N?.id??null);}else pe(null);},[]),ar=Or.useCallback((t,p,b)=>{if(p.type==="device"&&!p.parentId){let g=ge.current.filter(u=>u.type==="rack").map(u=>u),N=pt(p.position,g);if(N){let u=p.position.x-N.position.x,F=p.position.y-N.position.y,Y={...p,parentId:N.id,extent:"parent",position:{x:u,y:F},data:{...p.data,uPosition:1}},U=ge.current.map(te=>te.id===p.id?Y:te);_(U),R||C.setState({nodes:U});}}pe(null);},[_,R,C]),sr=Or.useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let p=X(t.source),b=X(t.target);if(p?.type==="tube"&&b?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect fibres within tubes",t),false;if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&(b?.type==="cable"||b?.type==="tube")&&t.targetHandle.startsWith("tube-"))return s&&console.log("Connection rejected: Cannot connect individual fibre to cable/tube tube handle",t),false;if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-")&&b?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect cable/tube tube handle to individual fibre",t),false;if(b?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")){if(z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle||u.source===t.target&&u.sourceHandle===t.targetHandle))return s&&console.log("Splice handle already connected, will replace",t),true;s&&console.log("Allowing connection to splice handle",t);}if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-"))return b?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect to splices",t),false):z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube fiber handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube fiber handle to splice",t),true);if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-"))return t.targetHandle.startsWith("tube-")?z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube-level handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube-level handle to tube handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect to other tube handles",t),false);if(p?.type==="splice"&&t.sourceHandle==="right"){if(z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle||u.target===t.source&&u.targetHandle===t.sourceHandle))return s&&console.log("Splice source handle already connected, will replace",t),true;s&&console.log("Allowing connection from splice source handle",t);}if(b?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return p?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect from splices",t),false):z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube fiber target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to tube fiber handle",t),true);if((b?.type==="cable"||b?.type==="tube")&&t.targetHandle.startsWith("tube-"))return t.sourceHandle.startsWith("tube-")?z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube-level target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube handle to tube-level handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect from other tube handles",t),false);if(p?.type==="coupler"&&(t.sourceHandle?.startsWith("left-")||t.sourceHandle?.startsWith("right-")))return b?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect to splices",t),false):t.targetHandle!=="left"&&t.targetHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect to splice left/right handles",t),false):z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Coupler handle already connected, will replace",t),true):(s&&console.log("Allowing connection from coupler handle to splice",t),true);if(b?.type==="coupler"&&(t.targetHandle?.startsWith("left-")||t.targetHandle?.startsWith("right-")))return p?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect from splices",t),false):t.sourceHandle!=="left"&&t.sourceHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect from splice left/right handles",t),false):z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Coupler target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to coupler handle",t),true);if(t.source&&t.sourceHandle&&z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle already connected, will replace",t),true;if(t.target&&t.targetHandle&&z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle already connected, will replace",t),true;if((p?.type==="cable"||b?.type==="cable")&&(t.sourceHandle==="cable-button"||t.targetHandle==="cable-button"))return t.sourceHandle!=="cable-button"||t.targetHandle!=="cable-button"?(s&&console.log("Connection rejected: Cable button handles can only connect to other cable button handles",t),false):z.current.find(F=>F.source===t.source&&F.sourceHandle===t.sourceHandle)?(s&&console.log("Cable button source handle already connected, will replace",t),true):z.current.find(F=>F.target===t.target&&F.targetHandle===t.targetHandle)?(s&&console.log("Cable button target handle already connected, will replace",t),true):(s&&console.log("Allowing connection between cable button handles",t),true);let g=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!g.valid&&y){if(t.source&&t.sourceHandle&&z.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle has existing edge, will replace",t),true;if(t.target&&t.targetHandle&&z.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle has existing edge, will replace",t),true}return s&&!g.valid&&console.log("Connection rejected by store validation:",g.reason,t),g.valid},[X,C,s,y]),dr=Or.useCallback(t=>{let p=X(t.source),b=X(t.target),g=p?.type==="vertical-pdu",N=p?.data,u=p?.type==="device"&&N?.deviceType==="switch",F=!!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)),U=p?.type==="tube"&&b?.type==="cable",te=p?.type==="cable"&&b?.type==="tube",de=U||te,fe=t.sourceHandle==="cable-button"&&t.targetHandle==="cable-button",K="fiber";g&&F?K="power":fe?K="thick-cable":de&&(K=P?"smoothstep":"fiber");let B;if((K==="fiber"||K==="smoothstep")&&!g){let S=Ve(t.source,t.sourceHandle);S&&(B={color:S.color,striped:S.striped});}else if(K==="thick-cable"&&fe){let S=p?.data;B={color:S?.color||(S?.tubeStartIndex?oe(S.tubeStartIndex):"#6366f1")};}if(t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if(b?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}if(t.targetHandle==="right"&&(S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B}),S)){$(S);return}}if(p?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}if(S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B}),S){$(S);return}}if(p?.type==="tube"&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(b?.type==="tube"&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if((b?.type==="cable"||b?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if(fe&&t.source&&t.sourceHandle&&t.target&&t.targetHandle){let S=p?.data,J=S?.color||(S?.tubeStartIndex?oe(S.tubeStartIndex):"#6366f1"),be=G({edges:z.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:V,findBy:"source",data:{color:J}});if(be){$(be);return}if(be=G({edges:z.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:V,findBy:"target",data:{color:J}}),be){$(be);return}}if(g&&F&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"power",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}if(u&&Y&&t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}let Re=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!Re.valid){if(y){if(t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:K,selectEdgeZIndex:V,findBy:"target",data:B});if(S){$(S);return}}}if(g&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:F?"power":"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(u&&t.source&&t.sourceHandle){let S=G({edges:z.current,connection:t,edgeType:"fiber",selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}s&&console.warn(`Connection rejected: ${Re.reason}`);return}let ve={...t,type:K,zIndex:V({...t,id:"temp-id"}),data:B};$(S=>{let J=reactflow.addEdge(ve,S),be=J[J.length-1];return be&&(po(ht=>new Set(ht).add(be.id)),setTimeout(()=>{po(ht=>{let uo=new Set(ht);return uo.delete(be.id),uo});},1e3)),J});},[$,C,V,X,s,Ve,y,P]),cr=Or.useCallback((t,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let b=t.sourceHandle||"",g=t.targetHandle||"",N=p.sourceHandle||"",u=p.targetHandle||"";if(b.startsWith("tube-")&&N!==b){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}if(g.startsWith("tube-")&&u!==g){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}let F=X(p.source),Y=X(p.target),U=F?.type==="vertical-pdu",te=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),de=F?.type==="tube"&&Y?.type==="cable",fe=F?.type==="cable"&&Y?.type==="tube",K=de||fe,B;U&&te?B="power":K?B=P?"smoothstep":"fiber":B="fiber";let Re;if((B==="fiber"||B==="smoothstep")&&!U){let ve=Ve(p.source,p.sourceHandle);ve&&(Re={color:ve.color,striped:ve.striped});}$(ve=>ve.map(J=>J.id===t.id?{...J,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:B,data:Re!==void 0?{...J.data,...Re}:J.data,zIndex:V({...p,id:J.id,type:B}),style:{...J.style,zIndex:V({...p,id:J.id,type:B})}}:J));},[$,X,Ve,V,P,s]),lr=Or.useCallback((t,p)=>{let b=t.metaKey||t.ctrlKey;if(p.type==="tube"&&p.parentId&&!b){let N=ke().find(u=>u.id===p.parentId&&u.type==="cable");if(N){_(u=>u.map(F=>({...F,selected:F.id===N.id}))),c&&c(N);return}}if(b&&p.type==="device"){let g=p.data||{},N=g.view||(Array.isArray(g.rearPorts)&&g.rearPorts.length>0?"rear":"front"),u=N==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${p.id} from ${N} to ${u}`),h&&h(p.id,u),c&&c(p);}else c&&c(p);},[h,c,s,ke,_]),pr=Or.useCallback(()=>{},[]),ur=Or.useCallback((t,p)=>{l&&l(p);},[l]),[ue,bt]=Or.useState(null),[lo,po]=Or.useState(new Set);reactflow.useOnSelectionChange({onChange:({nodes:t})=>{if(t&&t.length===1){let p=t[0];if(p.type==="tube"&&p.parentId){let g=ke().find(N=>N.id===p.parentId&&N.type==="cable");if(g){bt(g),_(N=>N.map(u=>({...u,selected:u.id===g.id}))),c&&c(g);return}}bt(p),c&&c(p);}else bt(null),c&&c(null);}});let fr=Or.useCallback((t,{nodeId:p,handleType:b})=>{s&&console.log("Connection started from",{nodeId:p,handleType:b});},[s]),gr=Or.useCallback(t=>{s&&console.log("Connection ended",t);},[s]),br=Or.useCallback(()=>{if(!ue)return;let t=X(ue.id);if(t){if(t.type==="rack"){let g=((t.data||{}).face||"front")==="front"?"rear":"front";f?(f(t.id,g),h&&ke().filter(u=>u.parentId===t.id).forEach(u=>{h(u.id,g);})):_(N=>N.map(u=>u.id===t.id?{...u,data:{...u.data,face:g}}:u.parentId===t.id?{...u,data:{...u.data,view:g}}:u));return}if(t.type==="device"){let p=t.data||{},b=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,g=Array.isArray(p.ports)&&p.ports.length>0,u=(p.view||(b&&!g?"rear":"front"))==="front"?"rear":"front";h?h(t.id,u):_(F=>F.map(Y=>Y.id===t.id?{...Y,data:{...Y.data,view:u}}:Y));}}},[ue,X,f,h,_,ke]),hr=Or.useMemo(()=>L.map(t=>{let p=t,b=X(String(p.source)),g=X(String(p.target)),N=ct(p.sourceHandle||"",b),u=ct(p.targetHandle||"",g),F=b&&b.data?.view,Y=g&&g.data?.view,U=b?.type==="device"&&F==="rear",te=g?.type==="device"&&Y==="rear",B=U&&N!=="rear"&&(te&&u!=="rear")?{...t.style,opacity:0,pointerEvents:"none",zIndex:0}:t.style;return {...t,style:B,className:lo.has(t.id)?"edge-connecting":t.className}}),[L,lo,X]);return jsxRuntime.jsxs("div",{ref:ae,className:`${m||""} ${E==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",...v},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:O,edges:hr,onNodesChange:t=>{rr(t),R?n&&n(ge.current):C.setState({nodes:ge.current});},onEdgesChange:t=>{let p=t.filter(b=>{if(b.type==="remove"){let g=z.current.find(N=>N.id===b.id);if(g){let N=g.sourceHandle||"",u=g.targetHandle||"";if(N.startsWith("tube-")||u.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",g),false}}return true});p.length>0&&(j(p),R?i&&i(z.current):C.setState({edges:z.current}));},onConnect:dr,onConnectStart:fr,onConnectEnd:gr,onEdgeUpdate:cr,isValidConnection:sr,onNodeClick:lr,onNodeDoubleClick:pr,onNodeDragStart:nr,onNodeDrag:ir,onNodeDragStop:ar,onEdgeClick:ur,onInit:w,nodeTypes:tr,edgeTypes:or,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:true,nodesConnectable:true,elementsSelectable:true,selectNodesOnDrag:false,connectOnClick:M,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:E==="light"?"#e5e5e5":"#2a2a2a"}),jsxRuntime.jsx(reactflow.Controls,{}),jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&jsxRuntime.jsx("button",{className:"download-button",onClick:gt,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",...H},children:x}),ue&&(ue.type==="rack"||ue.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:t=>{t.preventDefault(),br();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=ue.data;if(ue.type==="rack")return (t?.face||"front")==="front"?"Switch to rear":"Switch to front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,b=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!b?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let t=ue.data;if(ue.type==="rack")return (t?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,b=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!b?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},Hn=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(Sn,{...e})});var Ko=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}}),qo=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}}),Jo=e=>{let o=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},r=o(e.termination_a),a=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${r}`,target:`device-${a}`,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}}},Cn=e=>{let o=[],r=[];return e.racks.forEach(a=>o.push(Ko(a))),e.devices.forEach(a=>o.push(qo(a))),e.cables.forEach(a=>r.push(Jo(a))),{nodes:o,edges:r}},En=e=>{let o=e.filter(n=>n.type==="rack"),r=e.filter(n=>n.type==="device"),a=e.filter(n=>!["rack","device"].includes(n.type));return o.forEach((n,i)=>{n.position={x:i*300,y:100};}),r.forEach(n=>{if(n.parentId){let i=o.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,s=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-s*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),a.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var We=class extends Error{constructor(r,a,n,i,d){super(`Device placement conflict: ${a} at U${n}-${n+i-1} in rack ${r}${d?` conflicts with ${d}`:""}`);this.rackId=r;this.deviceId=a;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function ro(e,o={}){let r=[],a=[];for(let n of e.devices)n.unit+n.height-1>e.units&&a.push({deviceId:n.id,uPosition:n.unit,uHeight:n.height,rackUHeight:e.units});for(let n=0;n<e.devices.length;n++){let i=e.devices[n],d=i.unit,s=i.unit+i.height-1;for(let c=n+1;c<e.devices.length;c++){let l=e.devices[c],h=l.unit,f=l.unit+l.height-1;d<=f&&s>=h&&r.push({deviceId:i.id,uPosition:i.unit,uHeight:i.height,conflictWith:l.id});}}return {isValid:r.length===0&&a.length===0,conflicts:r,outOfBounds:a}}function Qo(e,o,r={}){let{deviceTypeMapping:a={}}=r,n=a[e.type]||"device",i=De(o,e.unit,e.height);return {id:e.id,type:n,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}}}function Rn(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:[]}}}function Tn(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=ro(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 We(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=Rn(d);n.push(s);for(let c of d.devices)try{let l=Qo(c,s,o);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=Ge(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 f={...c,unit:h},m=Qo(f,s,o);i.push(m);}else throw new We(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Dn(e){let o=[],r=e.filter(a=>a.type==="rack");for(let a of r){let i=e.filter(d=>d.type==="device"&&d.parentId===a.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:a.id,name:a.data.label,position:a.position,units:a.data.uHeight||42,uNumberingDirection:a.data.uNumberingDirection||"bottom-up",customHeaderText:a.data.customHeaderText,devices:i});}return o}function In(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.map(i=>i.id!==r?i:{...i,unit:a})})}function $n(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!ro({...i,devices:[...i.devices,r]},a).isValid)throw new We(o,r.id,r.unit,r.height);return {...i,devices:[...i.devices,r]}})}function _n(e,o,r){return e.map(a=>a.id!==o?a:{...a,devices:a.devices.filter(n=>n.id!==r)})}var ze=class extends Error{constructor(r,a,n,i){super(`Splice placement conflict: ${a} at holder ${n} in tray ${r}${i?` conflicts with ${i}`:""}`);this.trayId=r;this.spliceId=a;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function no(e,o={}){let r=[],a=[];for(let n of e.splices)(n.holder<1||n.holder>Ne)&&a.push({spliceId:n.id,holder:n.holder,max:Ne});for(let n=0;n<e.splices.length;n++){let i=e.splices[n];for(let d=n+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&&a.length===0,conflicts:r,outOfBounds:a}}function er(e,o){let r=Me(o,e.holder);return {id:e.id,type:"splice",position:r,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb}}}function Fn(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function An(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=no(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 ze(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=Fn(d);n.push(s);for(let c of d.splices)try{let l=er(c,s);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=[...n,...i],f=et(s,{id:c.id,data:{label:c.name,holderPosition:c.holder}},h,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let m={...c,holder:f},v=er(m,s);i.push(v);}else throw new ze(d.id,c.id,c.holder)}}}return n.push(...i),n}function Wn(e){let o=[],r=e.filter(a=>a.type==="splice-tray");for(let a of r){let i=e.filter(d=>d.type==="splice"&&d.parentId===a.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb}));o.push({id:a.id,name:a.data.label,position:a.position,splices:i});}return o}function zn(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.map(i=>i.id!==r?i:{...i,holder:a})})}function Ln(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!no({...i,splices:[...i.splices,r]},a).isValid)throw new ze(o,r.id,r.holder);return {...i,splices:[...i.splices,r]}})}function Mn(e,o,r){return e.map(a=>a.id!==o?a:{...a,splices:a.splices.filter(n=>n.id!==r)})}
|
|
2
|
+
exports.COUPLERS_PER_PANEL=jr;exports.COUPLER_SLOT_HEIGHT_PX=st;exports.COUPLER_WIDTH_PX=Gr;exports.CableNode=Ut;exports.ClosureNode=Kt;exports.CouplerNode=Bt;exports.DeviceNode=Et;exports.DevicePlacementError=We;exports.FIBER_COLORS_12=Co;exports.FiberEdge=kt;exports.FiberNode=wt;exports.NetworkDiagram=Hn;exports.PANEL_BORDER_WIDTH=Wo;exports.PANEL_HEADER_HEIGHT=Ee;exports.PANEL_HEIGHT_PX=at;exports.PANEL_PADDING=he;exports.PANEL_TUBE_TRAY_SPACING=zo;exports.PANEL_WIDTH_PX=it;exports.POWER_CONNECTORS=St;exports.PatchPanelNode=jt;exports.PowerEdge=vt;exports.RackNode=xt;exports.SpliceNode=It;exports.SplicePlacementError=ze;exports.SpliceTrayNode=zt;exports.TubeNode=Mt;exports.VerticalPDU=Rt;exports.Width=No;exports.addDeviceToRack=$n;exports.addSpliceToTray=Ln;exports.baseColorFor=oe;exports.buildNodesFromRackConfig=Tn;exports.buildNodesFromSpliceConfig=An;exports.calculateCouplerRightX=Kr;exports.calculateCouplerSlotSpacing=Jr;exports.calculateCouplerSpacing=Yo;exports.calculateDevicePositionFromU=De;exports.calculatePanelDimensions=Yt;exports.calculateSlotPositionFromY=Bo;exports.calculateSplicePositionFromNumber=Me;exports.calculateYFromSlotPosition=Oo;exports.createNetworkDiagramStore=qt;exports.createRackConfigFromNodes=Dn;exports.createSpliceConfigFromNodes=Wn;exports.fiberSolidOrStriped=Ue;exports.findNearestRack=pt;exports.findNextAvailableHolderPosition=et;exports.findNextAvailableUPosition=Ge;exports.generateLayout=En;exports.getConnectorConfig=Je;exports.getCouplerDimensions=Ot;exports.getDeviceConnectorType=Qe;exports.getFiberColor=Lt;exports.getInnerContentWidth=Uo;exports.getPDUPortType=Ht;exports.getPanelHeight=Zr;exports.getPanelWidth=Mo;exports.getPowerPortStyle=Ie;exports.getRackBounds=jo;exports.getStatusColor=ce;exports.getTrayDimensions=Lo;exports.getTubeDimensions=dt;exports.inventoryCableToNetworkEdge=Jo;exports.inventoryDeviceToNetworkNode=qo;exports.inventoryRackToNetworkNode=Ko;exports.inventoryToNetworkDiagram=Cn;exports.isHighPowerConnector=Lr;exports.isPointInRack=lt;exports.isStriped=Eo;exports.isUPositionAvailable=yt;exports.removeDeviceFromRack=_n;exports.removeSpliceFromTray=Mn;exports.replaceEdge=G;exports.snapToCouplerPosition=qr;exports.snapToSplicePosition=Ft;exports.snapToUPosition=mt;exports.updateDeviceUPosition=fo;exports.updateDeviceUPositionInSchema=In;exports.updateSpliceHolderPosition=zn;exports.useDiagramEdges=eo;exports.useDiagramNodes=Qt;exports.useNetworkDiagram=cn;exports.validateAndSnapDevice=yr;exports.validateRackDevicePlacements=ro;exports.validateSplicePlacements=no;//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|