@mp70/react-networks 0.1.8-alpha → 0.1.8-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -27
- package/dist/index.css +114 -8
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +63 -7
- package/dist/index.d.ts +63 -7
- 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 +2 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var Yr=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 Yr__default=/*#__PURE__*/_interopDefault(Yr);var yr=()=>"bottom-up",Pe=e=>e.data.uNumberingDirection||yr(),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}},go=(e,o,r)=>{let a=e.data.uHeight||1,n=De(o,r,a);return {...e,position:n,data:{...e.data,uPosition:r}}},xr=(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?go(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]=Yr.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 ho=({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 Ir({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 wo=({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=Ir({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 No=({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 ko=(r=>(r.FULL="full",r.HALF="half",r))(ko||{});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 Mr(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}`,K=D.connected,L="#6b7280";if(K)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:K?L:"#6b7280",border:`1px solid ${K?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) ${K?"(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}) ${K?"(connected)":"(disconnected)"}`},`${_}-${me}`));}else se=K?"source":"target";y.push(jsxRuntime.jsx(reactflow.Handle,{id:_,type:se,position:$,style:j,title:`${R.name} - ${D.label} ${K?"(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,Co=4,Ne=12,Br=69,Ce=80,$t=(Ce-Br)/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]=Yr.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+Co}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 Eo=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function oe(e){let o=(e-1)%12;return Eo[o]}function Ro(e){return e>12}function Ue(e){let o=oe(e);return Ro(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,K=D.backgroundImage?D.backgroundImage:I,L={position:"absolute",left:`${O}px`,top:`${_}px`,width:s,height:s,borderRadius:"50%",border:"none",background:K,backgroundColor:I,zIndex:10,cursor:"pointer","--fiber-bg":I};D.backgroundImage&&(L["--fiber-bg-image"]=D.backgroundImage);let $=`fiber-${C}`;x.push(jsxRuntime.jsxs(Yr__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,K=Ue(_),L=oe(_),$=v+O*(f+m),j=-4,V=K.backgroundImage?K.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};K.backgroundImage&&(ae["--fiber-bg-image"]=K.backgroundImage);let se=`tube-${_}`;I.push(jsxRuntime.jsxs(Yr__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(Yr__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,Gr=24,Zr=80,it=400,at=300,zo=2,he=8,Lo=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 Mo(e){return {width:Ce,height:0}}function Oe(e){return e.type==="coupler"?Ot(e):e.type==="tube"?dt(e):e.type==="splice-tray"?Mo():{width:80,height:30}}function Uo(e){return e.data?.panelWidth||it}function Kr(e){return e.data?.panelHeight||at}function Bo(e){return Uo(e)-zo*2-he*2}function qr(e,o){return Bo(e)-o}function Oo(e,o=st){return Math.floor(e/o)+1}function Yo(e,o=st){return (e-1)*o}function Jr(e,o,r){let a=st,n=Oo(r.y,a),i=Yo(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+Lo+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 Vo(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 Vo(e,o,r)}var Fo=20,Ao=400,Wo=300;function Xo(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||Ao,height:e.data?.closureHeight||e.data?.panelHeight||Wo};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+Fo+h+Fo+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||Ao,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||Wo,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=Yr.useRef(false),h=Yr.useMemo(()=>s().filter(A=>A.parentId===r),[s,r]),f=Yr.useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),m=Yr.useMemo(()=>i&&d?{width:i,height:d}:h.length===0?{width:i||400,height:d||300}:Yt(f,h),[h,f,i,d]);Yr.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=Yr.useRef(false),m=Yr.useMemo(()=>l().filter(H=>H.parentId===r),[l,r]),v=Yr.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=Yr.useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:m.length===0?{width:i||s||400,height:d||c||300}:Xo(v,m),[m,v,i,d,s,c]);Yr.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 cn(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||cn)(f,r),selectNodeById:f=>r.nodes.find(m=>m.id===f),selectConnectedEdges:f=>r.edges.filter(m=>m.source===f||m.target===f)}}function ln(e){let o=n=>e.subscribe(n),r=()=>e.getState();return Yr.useSyncExternalStore(o,r,r)}function Qt(e){let o=a=>e.subscribe(a),r=()=>e.getState().nodes;return Yr.useSyncExternalStore(o,r,r)}function eo(e){let o=a=>e.subscribe(a),r=()=>e.getState().edges;return Yr.useSyncExternalStore(o,r,r)}function jo(e){return e.selectEdgeZIndex}function Go(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=Go(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 Pn=(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}),Sn={fiber:kt,power:vt,smoothstep:ho,step:wo,"thick-cable":No},Hn=({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=Yr__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,_,K]=reactflow.useNodesState(D),[L,$,j]=reactflow.useEdgesState(I),V=jo(C),ae=Yr.useRef(null),{toObject:se,setViewport:me,setNodes:ut,setEdges:ft,getNodes:ke}=reactflow.useReactFlow();Yr.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=Yr.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]=Yr.useState(null),no=Yr.useRef(null),io=Yr.useRef(h),ao=Yr.useRef(f);Yr.useEffect(()=>{io.current=h;},[h]),Yr.useEffect(()=>{ao.current=f;},[f]),Yr.useEffect(()=>{no.current=Ye;},[Ye]);let so=Yr.useCallback((t,p)=>{io.current?.(t,p);},[]),co=Yr.useCallback((t,p)=>{ao.current?.(t,p);},[]),lo=Yr.useCallback(()=>no.current,[]),rr=Yr.useMemo(()=>Pn(so,co,lo),[so,co,lo]),ge=Yr.useRef(O);Yr.useEffect(()=>{ge.current=O;},[O]);let z=Yr.useRef(L);Yr.useEffect(()=>{z.current=L;},[L]),Yr.useEffect(()=>{_(D);},[D,_]),Yr.useEffect(()=>{$(I);},[I,$]),Yr.useEffect(()=>{R&&C.setState({nodes:e||[]});},[R,e,C]),Yr.useEffect(()=>{R&&C.setState({edges:o||[]});},[R,o,C]),Yr.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,q=(U.position?.y||0)+fe,B=u-q;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=Yr.useCallback(t=>ge.current.find(p=>p.id===t),[]),Ve=Yr.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]);Yr.useEffect(()=>{$(t=>t.map(p=>{let b=V(p);return {...p,zIndex:b,style:{...p.style,zIndex:b}}}));},[O,$,V]),Yr.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 nr=Yr.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});K(p);},[K,_,X]),ir=Yr.useCallback((t,p)=>{pe(null);},[]),ar=Yr.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);},[]),sr=Yr.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]),dr=Yr.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]),cr=Yr.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",q="fiber";g&&F?q="power":fe?q="thick-cable":de&&(q=P?"smoothstep":"fiber");let B;if((q==="fiber"||q==="smoothstep")&&!g){let S=Ve(t.source,t.sourceHandle);S&&(B={color:S.color,striped:S.striped});}else if(q==="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:q,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:q,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:q,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:q,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:q,selectEdgeZIndex:V,findBy:"source",data:B});if(S){$(S);return}}if(t.target&&t.targetHandle){let S=G({edges:z.current,connection:t,edgeType:q,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:q,zIndex:V({...t,id:"temp-id"}),data:B};$(S=>{let J=reactflow.addEdge(ve,S),be=J[J.length-1];return be&&(uo(ht=>new Set(ht).add(be.id)),setTimeout(()=>{uo(ht=>{let fo=new Set(ht);return fo.delete(be.id),fo});},1e3)),J});},[$,C,V,X,s,Ve,y,P]),lr=Yr.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",q=de||fe,B;U&&te?B="power":q?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]),pr=Yr.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,_]),ur=Yr.useCallback(()=>{},[]),fr=Yr.useCallback((t,p)=>{l&&l(p);},[l]),[ue,bt]=Yr.useState(null),[po,uo]=Yr.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 gr=Yr.useCallback((t,{nodeId:p,handleType:b})=>{s&&console.log("Connection started from",{nodeId:p,handleType:b});},[s]),br=Yr.useCallback(t=>{s&&console.log("Connection ended",t);},[s]),hr=Yr.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]),mr=Yr.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:po.has(t.id)?"edge-connecting":t.className}}),[L,po,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:mr,onNodesChange:t=>{nr(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:cr,onConnectStart:gr,onConnectEnd:br,onEdgeUpdate:lr,isValidConnection:dr,onNodeClick:pr,onNodeDoubleClick:ur,onNodeDragStart:ir,onNodeDrag:ar,onNodeDragStop:sr,onEdgeClick:fr,onInit:w,nodeTypes:rr,edgeTypes:Sn,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(),hr();},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"}})()})})]})},Cn=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(Hn,{...e})});var Jo=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}}),er=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}}},En=e=>{let o=[],r=[];return e.racks.forEach(a=>o.push(Jo(a))),e.devices.forEach(a=>o.push(Qo(a))),e.cables.forEach(a=>r.push(er(a))),{nodes:o,edges:r}},Rn=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],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 tr(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 Tn(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 Dn(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=Tn(d);n.push(s);for(let c of d.devices)try{let l=tr(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=tr(f,s,o);i.push(m);}else throw new We(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function In(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 $n(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"&&!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 Fn(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 or(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 An(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Wn(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=An(d);n.push(s);for(let c of d.splices)try{let l=or(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=or(m,s);i.push(v);}else throw new ze(d.id,c.id,c.holder)}}}return n.push(...i),n}function zn(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 Ln(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 Mn(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 Un(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 nt=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 nt__default=/*#__PURE__*/_interopDefault(nt);var Dn=()=>"bottom-up",Ge=e=>e.data.uNumberingDirection||Dn(),Ft=(e,o,r)=>r==="bottom-up"?o-e+1:e,Wt=(e,o,r)=>r==="bottom-up"?o-e+1:e;var mo=(e,o,r,n)=>{if(!e.parentId||e.parentId!==o.id)return r;let a=e.data.uHeight||1,i=o.data.uHeight||42,d=Ge(o),s=60,c=r.y-s,l=Math.round(c/20)+1,h;d==="bottom-up"?h=Ft(l,i,d)-a+1:h=Ft(l,i,d);let u=i-a+1,m=Math.max(1,Math.min(u,h));if(d==="top-down"&&h<=1&&(m=1),!yo(o,e,m,n)){let H=zt(o,e,n,m);H!==m&&(m=H);}let f;if(d==="bottom-up"){let H=m+a-1,k=Wt(H,i,d);f=s+(k-1)*20-1;}else {let H=Wt(m,i,d);f=s+(H-1)*20-1;}return {x:r.x,y:f,uPosition:m}},yo=(e,o,r,n)=>{let a=o.data.uHeight||1,i=e.data.uHeight||42;if(r<1||r+a-1>i)return false;let d=n.filter(s=>s.type==="device"&&s.parentId===e.id&&s.id!==o.id);for(let s of d){let c=s.data.uPosition||1,l=s.data.uHeight||1,h=r,u=r+a-1,m=c,f=c+l-1;if(h<=f&&u>=m)return false}return true},zt=(e,o,r,n=1)=>{let a=o.data.uHeight||1,i=e.data.uHeight||42;for(let d=n;d<=i-a+1;d++)if(yo(e,o,d,r))return d;return 1},at=(e,o,r=1)=>{let n=60,a=Ge(e),i=e.data.uHeight||42,d=Wt(o,i,a),s;if(a==="bottom-up"){let c=o+r-1,l=Wt(c,i,a);s=n+(l-1)*20-1;}else s=n+(d-1)*20-1;return {x:0,y:s}},wr=(e,o,r)=>{let n=e.data.uHeight||1,a=at(o,r,n);return {...e,position:a,data:{...e.data,uPosition:r}}},$n=(e,o)=>{let r=e.data.uPosition||1,n=e.data.uHeight||1,a=o.data.uHeight||42,i=Math.max(1,Math.min(a-n+1,r));return i!==r?wr(e,o,i):e};function Ee(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var xo=({data:e,selected:o,id:r,onViewChange:n,onRackFaceChange:a,isDragOver:i=false})=>{let{label:d,ports:s=0,status:c="active",uHeight:l=42,face:h="front",customHeaderText:u,rackWidthPx:m}=e,f=m||300,{getNodes:H,setNodes:k}=reactflow.useReactFlow(),w=H(),[R,M]=nt.useState(e.showUMarkers!==void 0?e.showUMarkers:true),I=()=>{let W=Ge({data:e})==="bottom-up"?"top-down":"bottom-up";k(C=>C.map(D=>D.id===r?{...D,data:{...D.data,uNumberingDirection:W}}:D));},z=()=>{let x=h==="front"?"rear":"front";a?(a(r,x),n&&w.filter(C=>C.parentId===r).forEach(C=>{n(C.id,x);})):n?w.filter(C=>C.parentId===r).forEach(C=>{n(C.id,x);}):k(W=>W.map(C=>C.id===r?{...C,data:{...C.data,face:x}}:C.parentId===r?{...C,data:{...C.data,view:x}}:C));},P=()=>{let x=[],W=60,C=Ge({data:e});for(let D=1;D<=l;D++){let $=W+(D-1)*20-4,_=Ft(D,l,C);x.push(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:_},D));}return x};return jsxRuntime.jsxs("div",{className:`rack-node ${o?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${Ee(c)}`,borderRadius:"8px",padding:0,width:`${f}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[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:[u?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:u}):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(),M(!R);},style:{background:R?"#10b981":"#374151",color:R?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${R?"Hide":"Show"} U markers`,children:"U"}),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 ${Ge({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Ge({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(),z();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${h==="front"?"rear":"front"} view`,children:h==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"}}),R&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:P()})]})};var wo=({data:e,selected:o})=>{let{label:r,status:n="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${Ee(n)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[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:Ee(n),borderRadius:"50%"}})]})};var kr=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function fe(e){let o=(e-1)%12;return kr[o]}function No(e){return e>12}function Ke(e){let o=fe(e);return No(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function ko(e){return fe(e)}function De(e){return e.map(o=>({base:fe(o),striped:No(o)}))}function An(e,o,r,n,a,i,d,s){let c=De(r),l=c.length,h=n?1.2:1,u=!!s?.highlight,m=n?2:1.5,f=s?.highlightWidth??m*3,H=s?.highlightColor??c[0]?.base??"#22d3ee";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[u&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:o,style:{...a,stroke:H,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${m}px`,"--rn-edge-highlight-to":`${f}px`}}),c.map((k,w)=>{let M=(l-w)*h;return jsxRuntime.jsx("path",{d:o,stroke:k.base,strokeWidth:M,fill:"none",strokeLinecap:"butt",opacity:k.striped?.9:1,style:a},`${e}-ribbon-${w}`)}),c.some(k=>k.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:o,style:{...a,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:n&&s&&(s.bandwidth||s.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${d}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[s.bandwidth&&jsxRuntime.jsx("div",{children:s.bandwidth}),s.length&&jsxRuntime.jsxs("div",{children:[s.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[r.length,"F"]})]})})]})}var vo=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},className:h})=>{let[u,m,f]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d}),{bandwidth:H,length:k,color:w="#00FFFF",striped:R=false,ribbonFiberIds:M,isRibbon:I,highlight:z,highlightColor:P,highlightWidth:x}=s||{},W=!!z;if((I||M&&M.length>=6&&M.length<=12)&&M)return An(e,u,M,c??false,l??{},m,f,s);let D=c?3:2,$=x??D*3,_={...l,stroke:w,strokeWidth:D,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[W&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:u,style:{...l,stroke:P??w,strokeWidth:$,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${D}px`,"--rn-edge-highlight-to":`${$}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:u,style:_}),R&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:u,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&s&&(H||k)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${f}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[H&&jsxRuntime.jsx("div",{children:H}),k&&jsxRuntime.jsxs("div",{children:[k,"m"]})]})})]})};var Ho=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l})=>{let[h]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d}),u=c?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:h,markerEnd:l,style:(()=>{let f={stroke:c?.color||"#f59e0b",strokeWidth:u==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return u==="C19"?{...f,strokeDasharray:"none"}:{...f,strokeDasharray:"6,3"}})()})};function Vn(e,o,r,n,a,i,d,s,c,l,h){let u=De(s),m=u.length,f=c?1.8:1.5,H=!!h?.highlight,k=c?3:2.5,w=h?.highlightWidth??k*3,R=h?.highlightColor??u[0]?.base??"#22d3ee",[M,I,z]=reactflow.getSmoothStepPath({sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[H&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:M,style:{...l,stroke:R,strokeWidth:w,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${k}px`,"--rn-edge-highlight-to":`${w}px`}}),u.map((P,x)=>{let C=(m-x)*f;return jsxRuntime.jsx("path",{d:M,stroke:P.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:P.striped?.9:1,style:l},`${e}-ribbon-${x}`)}),u.some(P=>P.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:M,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&h&&(h.bandwidth||h.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${I}px,${z}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${u[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[h.bandwidth&&jsxRuntime.jsx("div",{children:h.bandwidth}),h.length&&jsxRuntime.jsxs("div",{children:[h.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[s.length,"F"]})]})})]})}var Pr=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...h})=>{let{color:u="#00FFFF",ribbonFiberIds:m,isRibbon:f,highlight:H,highlightColor:k,highlightWidth:w}=s||{},R=!!H;if((f||m&&m.length>=6&&m.length<=12)&&m)return Vn(e,o,r,n,a,i,d,m,c??false,l??{},s);let I=c?4:3,z=w??I*3,P={...l,stroke:u,strokeWidth:I};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[R&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:reactflow.getSmoothStepPath({sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d})[0],style:{...l,stroke:k??u,strokeWidth:z,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${I}px`,"--rn-edge-highlight-to":`${z}px`}}),jsxRuntime.jsx(reactflow.SmoothStepEdge,{...h,id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:P})]})};function Xn({sourceX:e,sourceY:o,targetX:r,targetY:n,sourcePosition:a,targetPosition:i}){let d=a===reactflow.Position.Left||a===reactflow.Position.Right,s;if(d){let c=(e+r)/2;s=`M ${e},${o} L ${c},${o} L ${c},${n} L ${r},${n}`;}else {let c=(o+n)/2;s=`M ${e},${o} L ${e},${c} L ${r},${c} L ${r},${n}`;}return s}function jn(e,o,r,n,a,i){let d=De(r),s=d.length,c=n?1.2:1,l=!!i?.highlight,h=n?2:1.5,u=i?.highlightWidth??h*3,m=i?.highlightColor??d[0]?.base??"#22d3ee",f=o.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),H=f?(parseFloat(f[1])+parseFloat(f[3]))/2:0,k=f?(parseFloat(f[2])+parseFloat(f[4]))/2:0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:o,style:{...a,stroke:m,strokeWidth:u,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${h}px`,"--rn-edge-highlight-to":`${u}px`}}),d.map((w,R)=>{let I=(s-R)*c;return jsxRuntime.jsx("path",{d:o,stroke:w.base,strokeWidth:I,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:a},`${e}-ribbon-${R}`)}),d.some(w=>w.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:o,style:{...a,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:n&&i&&(i.bandwidth||i.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${k}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${d[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsxRuntime.jsx("div",{children:i.bandwidth}),i.length&&jsxRuntime.jsxs("div",{children:[i.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[r.length,"F"]})]})})]})}var Rr=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...h})=>{let{color:u="#00FFFF",striped:m=false,ribbonFiberIds:f,isRibbon:H,highlight:k,highlightColor:w,highlightWidth:R}=s||{},M=!!k,I=Xn({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d});if((H||f&&f.length>=6&&f.length<=12)&&f)return jn(e,I,f,c??false,l??{},s);let P=c?3:2,x=R??P*3,W={...l,stroke:u,strokeWidth:P,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[M&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:I,style:{...l,stroke:w??u,strokeWidth:x,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${P}px`,"--rn-edge-highlight-to":`${x}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:I,style:W}),m&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:I,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var Dr=({id:e,sourceX:o,sourceY:r,targetX:n,targetY:a,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l,selected:h})=>{let{color:u="#6366f1",label:m,highlight:f,highlightColor:H,highlightWidth:k}=c||{},w=!!f,R=8,M=k??R*1.8,[I,z,P]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:n,targetY:a,targetPosition:d}),x={...s,stroke:u,strokeWidth:R,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[w&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:I,style:{...s,stroke:H??u,strokeWidth:M,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${H??u}) drop-shadow(0 0 16px ${H??u})`,"--rn-edge-highlight-from":`${R}px`,"--rn-edge-highlight-to":`${M}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:I,markerEnd:l,style:x}),m&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${z}px,${P}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${u}`,pointerEvents:"none",zIndex:9999},children:m})})]})};var $r=(r=>(r.FULL="full",r.HALF="half",r))($r||{});var Po={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1}};function st(e){let o=Po[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let r=o.amperage===16,n=r?12:8,a=r?10:5,i=r?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:a,color:o.color,borderColor:o.borderColor,fontSize:r?"3px":"4px",...i}}function Ot(e){let o=Po[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function Jn(e){return Ot(e).amperage===16}function Co(e){return e%10<8?"C13":"C19"}function Bt(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Ro=({data:e,selected:o})=>{let{label:r,status:n="active",deviceType:a="server",manufacturer:i,role:d,uHeight:s=1,width:c="full",ports:l=[],rearPorts:h=[],view:u,rackWidthPx:m}=e,f=m||300,H=u||(h.length>0&&l.length===0?"rear":"front"),k={};k["net-top"]="front",k["net-bottom"]="front",l.length>0&&l.forEach(C=>{C.ports.forEach(D=>{let $=D.type?.includes("power")?D.label:`${C.name}-${D.label}`;k[$]="front";});}),k["pwr-left-1"]="rear",k["pwr-left-2"]="rear",k["net-right-1"]="rear",k["net-right-2"]="rear",h.length>0&&h.forEach(C=>{C.ports.forEach(D=>{let $=D.type?.includes("power")?D.label:`${C.name}-${D.label}`;k[$]="rear";});});let w=s*20,R=f+4,M=Math.floor(f/2),I=c==="half"?`${M}px`:`${R}px`,z=c==="half"?`${M}px`:void 0,P=(C,D)=>{let $=[];if(C.length===0)return $;let _=Math.max(4,Math.floor(w*.4)),X=Math.max(2,Math.floor(w*.2));return C.forEach((Z,oe)=>{Z.ports.forEach((U,S)=>{let O=!!U.type&&U.type.includes("power");if(D==="front"&&O)return;let te=O?`${U.label}`:`${Z.name}-${U.label}`,V=U.connected,A="#6b7280";if(V)if(U.type?.includes("power"))A=U.type==="power_c19"?"#fbbf24":"#f59e0b";else if(U.type==="console"||U.type==="mgmt")A="#8b5cf6";else if(U.type==="usb")A="#10b981";else switch(U.cableType){case "smf":A="#fbbf24";break;case "cat6":A="#8b5cf6";break;case "om3":A="#06b6d4";break;case "om4":A="#8b5cf6";break;case "om5":A="#84cc16";break;case "cat5e":A="#3b82f6";break;case "cat6a":A="#ef4444";break;case "cat7":A="#f97316";break;case "fiber":A="#3b82f6";break;case "ethernet":A="#10b981";break;default:A="#10b981";}let re=reactflow.Position.Top,T={width:`${_}px`,height:`${X}px`,background:V?A:"#6b7280",border:`1px solid ${V?A:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(D==="front")S%2===0?(re=reactflow.Position.Top,T.transform="translateY(50%)",T.left=`${S/2*(_+2)}px`):(re=reactflow.Position.Bottom,T.transform="translateY(-50%)",T.left=`${(S-1)/2*(_+2)}px`);else if((a?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel"||a==="switch")S%2===0?(re=reactflow.Position.Top,T.transform="translateY(50%)",T.left=`${S/2*(_+2)}px`):(re=reactflow.Position.Bottom,T.transform="translateY(-50%)",T.left=`${(S-1)/2*(_+2)}px`);else if(U.type?.includes("power")){re=reactflow.Position.Left,T.transform="translateX(50%)";let Pt=w<=20?10:20,Ct=w<=20?30:50;T.top=`${Pt+S*Ct}%`;let Et=Bt(r),_e=st(Et);T={...T,width:`${_e.width}px`,height:`${_e.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:_e.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:_e.borderRadius,clipPath:_e.clipPath};}else re=reactflow.Position.Right,T.transform="translateX(-50%)",T.top=`${25+S*50}%`;let be=(a?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",q;if(O)q="target";else if(a==="switch"||a==="router")q="source",$.push(jsxRuntime.jsx(reactflow.Handle,{id:`${te}-target`,type:"target",position:re,style:T,title:`${Z.name} - ${U.label} (input) ${V?"(connected)":"(disconnected)"}`},`${te}-target`));else if(be){q=D==="rear"?"source":"target";let he=D==="rear"?"target":"source";$.push(jsxRuntime.jsx(reactflow.Handle,{id:`${te}-${he}`,type:he,position:re,style:T,title:`${Z.name} - ${U.label} (${he}) ${V?"(connected)":"(disconnected)"}`},`${te}-${he}`));}else q=V?"source":"target";$.push(jsxRuntime.jsx(reactflow.Handle,{id:te,type:q,position:re,style:T,title:`${Z.name} - ${U.label} ${V?"(connected)":"(disconnected)"}`,children:O?S+1:void 0},te));});}),$},x=()=>{let C=[],D=Math.max(4,Math.floor(w*.4)),$=Math.max(2,Math.floor(w*.2));if(H==="front"){if(l.length>0)return P(l,"front");if(a==="switch"&&(r.toLowerCase().includes("agg")||r.toLowerCase().includes("core")||d==="agg"||d==="core"))return W();C.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),C.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(H==="rear"){if(h.length>0)return P(h,"rear");let _=a==="switch",Z=(a?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!Z){let oe=Bt(r),U=Ot(oe),S=st(oe),O=w<=20?"10%":"25%";C.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${S.width}px`,height:`${S.height}px`,background:S.color,border:`1px solid ${S.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:O,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:S.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:S.borderRadius,clipPath:S.clipPath},title:`Power Port 1 (${U.type}) - ${U.voltage}V, ${U.amperage}A`,children:"1"},"pwr-1"));let te=w<=20?"50%":"75%";C.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${S.width}px`,height:`${S.height}px`,background:S.color,border:`1px solid ${S.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:te,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:S.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:S.borderRadius,clipPath:S.clipPath},title:`Power Port 2 (${U.type}) - ${U.voltage}V, ${U.amperage}A`,children:"2"},"pwr-2"));}!_&&!Z&&(C.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"25%"},title:"Network Port 1 (Right)"},"net-right-1")),C.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"75%"},title:"Network Port 2 (Right)"},"net-right-2")));}return C},W=()=>{let C=[],D=Math.max(10,Math.floor(w*.45)),$=Math.max(5,Math.floor(w*.25));for(let _=1;_<=16;_++){let X=jsxRuntime.jsx(reactflow.Handle,{id:`port-${_}`,type:"source",position:reactflow.Position.Top,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(_-1)*(D+2)}px`},title:`Port ${_}`},`port-${_}`);C.push(X);}for(let _=17;_<=32;_++){let X=_-16,Z=jsxRuntime.jsx(reactflow.Handle,{id:`port-${_}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${D}px`,height:`${$}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${(X-1)*(D+2)}px`},title:`Port ${_}`},`port-${_}`);C.push(Z);}for(let _=1;_<=4;_++){let X=Math.max(4,Math.floor(w*.3)),Z=Math.max(3,Math.floor(w*.15));C.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${_}`,type:"source",position:reactflow.Position.Right,style:{width:`${X}px`,height:`${Z}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${_}`},`uplink-${_}`));}return C};return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${Ee(n)}`,borderRadius:"2px",padding:"0px",width:I,...z&&{left:z},height:`${w}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[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:Ee(n),borderRadius:"50%"}}),x()]})};var To=({data:e,selected:o})=>{let{label:r,status:n="active",heightCm:a=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:s}=e,c=a*4.2,l=()=>{let m=Math.ceil(i/10),f=Array(10).fill(0).map((x,W)=>W<8?"10A":"16A");for(let x=0,W=0;x<m;++x)for(let C=0;C<10&&W<i;++C,++W){f[C];}let R=[],M=15,P=(c-M-3)/(i-9)*.5;for(let x=0;x<i;x++){let W=M-2+P*x,C=`${x+1}`;if(s&&(s==="top"&&x===0||s==="middle"&&x===Math.floor(i/2)||s==="bottom"&&x===i-1)){R.push(h(W));continue}let $=Co(x),_=st($),X=Math.round((d-_.width)/2-1);R.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:C,style:{position:"absolute",left:`${X}px`,top:`${W-_.height/2}px`,width:`${_.width}px`,height:`${_.height}px`,background:_.color,border:`1px solid ${_.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:_.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:_.borderRadius,clipPath:_.clipPath},title:`Power Port ${x+1} (${$})`,children:x+1},`handle-${C}`));}return R},h=u=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(d-16)/2}px`,top:`${u-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[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 ${Ee(n)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${c}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[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 $o=({data:e,selected:o,id:r})=>{let{lossDb:n,mode:a="single",ribbonFiberIds:i}=e||{},d=reactflow.useEdges(),s=d.find(P=>P.target===r&&P.targetHandle==="left"),c=d.find(P=>P.source===r&&P.sourceHandle==="right"),l=d.find(P=>P.target===r&&P.targetHandle==="right"),h=c||l,u=s?.data?.color||"#555",m=h?.data?.color||"#555",f=a==="ribbon",H=s?.data?.ribbonFiberIds||i,k=h?.data?.ribbonFiberIds||i,w=f&&H?De(H):null,R=f&&k?De(k):null,M=!!s&&!!h;return jsxRuntime.jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:f?85:69,height:f?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[f&&w&&R?jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:w.map((P,x)=>jsxRuntime.jsx("div",{style:{flex:1,background:P.base,opacity:P.striped?.9:1}},`left-${x}`))}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:R.map((P,x)=>jsxRuntime.jsx("div",{style:{flex:1,background:P.base,opacity:P.striped?.9:1}},`right-${x}`))})]}):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:u}}),jsxRuntime.jsx("div",{style:{background:m}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),M&&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}}),M&&typeof n=="number"&&jsxRuntime.jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:f?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsxRuntime.jsx("div",{children:`${n.toFixed(2)} dB`}),f&&i&&jsxRuntime.jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:f&&w?20:12,borderRadius:f&&w?"6px":"50%",border:"none",background:f&&w?`linear-gradient(to bottom, ${w.map(P=>P.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:f&&R?20:12,borderRadius:f&&R?"6px":"50%",border:"none",background:f&&R?`linear-gradient(to bottom, ${R.map(P=>P.base).join(", ")})`:m,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:f&&R?20:12,borderRadius:f&&R?"6px":"50%",border:"none",background:f&&R?`linear-gradient(to bottom, ${R.map(P=>P.base).join(", ")})`:m,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Nt=20,Ut=36;var Qe=32,zr=4,Oe=12,ei=69,et=80,_o=(et-ei)/2;var Wo=(e,o,r,n)=>{if(!e.parentId||e.parentId!==o.id)return r;let a=e.data?.mode==="ribbon",i=a?Ut:Nt,d=a?32:16,s=Qe,c=r.y-s,l=Math.round(c/i)+1,u=Math.max(1,Math.min(Oe,l));if(!Fo(o,e,u,n)){let H=Vt(o,e,n,u);if(H!==u){let k=(i-d)/2;return {x:_o,y:s+(H-1)*i+k,holderPosition:H}}}let m=(i-d)/2,f=s+(u-1)*i+m;return {x:_o,y:f,holderPosition:u}},Fo=(e,o,r,n)=>!n.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==o.id).some(i=>i.data.holderPosition===r),Vt=(e,o,r,n=1)=>{for(let a=n;a<=Oe;a++)if(Fo(e,o,a,r))return a;for(let a=n-1;a>=1;a--)if(Fo(e,o,a,r))return a;return 1},ti=(e,o)=>kt(e,o,false),kt=(e,o,r=false)=>{let n=Qe,a=r?Ut:Nt,d=(a-(r?32:16))/2,s=n+(o-1)*a+d;return {x:_o,y:s}};var Mo=({data:e,selected:o})=>{let{label:r="Splice Tray"}=e||{},[n,a]=nt.useState(false),i=()=>{if(!n)return null;let d=[],s=Qe;for(let c=1;c<=Oe;c++){let l=s+(c-1)*Nt;d.push(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:`${Nt}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:`${et}px`,height:`${Qe+Oe*Ut+zr}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${Qe}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[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(),a(!n);},style:{background:n?"#10b981":"#374151",color:n?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${n?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:Qe,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Lo=({data:e,selected:o,id:r})=>{let{fibersPerTube:n=12,tubeIndex:a=1,startOn:i="left-center"}=e||{},d=e?.mode==="ribbon"||e?.ribbon===true,s=reactflow.useEdges(),c=`tube-${a}`,l=s.find(Z=>Z.source===r&&Z.sourceHandle===c||Z.target===r&&Z.targetHandle===c),h=l?.data?.color,u=fe((a-1)%12+1),m=h||u,f=Math.max(1,Math.min(24,Number(n)||12)),H=14,k=4,w=1,R=2,M=20,I=f*H+(f-1)*k,z=Math.max(60,I+w*2+R*2),P=i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,x=P!==reactflow.Position.Bottom,W=x?14:20,C=x?8:20,D=x?`inset ${P===reactflow.Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",$=l?m:x?`linear-gradient(${P===reactflow.Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${m}`:`radial-gradient(circle, ${m} 40%, transparent 70%)`,_={width:W,height:C,borderRadius:x?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:$,backgroundColor:m,border:l?`2px solid ${m}`:`3px dashed ${m}`,cursor:"crosshair","--fiber-bg":m,boxShadow:l?D:`${D}${D!=="none"?", ":""}0 0 8px ${m}`,transition:"opacity 0.2s, box-shadow 0.2s",...P===reactflow.Position.Left?{left:-(W-4)}:P===reactflow.Position.Right?{right:-(W-4)}:{}},X=nt.useMemo(()=>{let Z=[],oe=z-R*2-w*2,U,S,O=false;i==="left"?(U=w,S=reactflow.Position.Top):i==="right"?(U=w+oe-I,S=reactflow.Position.Top,O=true):(U=w+(oe-I)/2,S=reactflow.Position.Top);for(let te=0;te<f;te++){let V=O?f-te:te+1,A=Ke(V),re=fe(V),T=`fiber-${V}`,F=s.find(Ve=>Ve.source===r&&Ve.sourceHandle===T||Ve.target===r&&Ve.targetHandle===T),be=null;F&&(F.data?.isRibbon||F.data?.ribbonFiberIds&&Array.isArray(F.data.ribbonFiberIds)?be="#808080":be=F.data?.color||null);let q=U+te*(H+k),he=w,ue={position:"absolute",left:`${q}px`,top:`${he}px`,width:H,height:H,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":be||(d?"#808080":re)};be?ue.backgroundColor=be:d?ue.backgroundColor="#808080":A.backgroundImage?ue["--fiber-bg-image"]=A.backgroundImage:ue.backgroundColor=re,Z.push(jsxRuntime.jsxs(nt__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:T,type:"target",position:S,className:"tube-fiber-handle",isConnectable:true,style:ue,"data-fiber-idx":V,"data-fiber-color":be||(d?"#808080":re)}),jsxRuntime.jsx(reactflow.Handle,{id:T,type:"source",position:S,className:"tube-fiber-handle",isConnectable:true,style:ue,"data-fiber-idx":V,"data-fiber-color":be||(d?"#808080":re)})]},`fiber-${V}`));}return Z},[f,i,z,s,r,H,k,w,R,I,d]);return jsxRuntime.jsxs("div",{style:{width:z,height:M,borderRadius:4,background:"#111827",border:`${R}px solid ${o?"#3b82f6":m}`,position:"relative",boxShadow:o?`0 0 0 ${R}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:w,boxSizing:"border-box",overflow:"visible"},children:[X,jsxRuntime.jsx(reactflow.Handle,{id:c,type:"target",position:P,isConnectable:true,className:"tube-connection-handle",style:_,"data-tube-idx":a,"data-tube-color":m,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsxRuntime.jsx(reactflow.Handle,{id:c,type:"source",position:P,isConnectable:true,className:"tube-connection-handle",style:_,"data-tube-idx":a,"data-tube-color":m,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var Uo=({data:e,selected:o})=>{let{fiberCount:r,cableId:n="CBL-002",label:a,color:i,rotation:d}=e||{},s=nt__default.default.useRef(null);nt__default.default.useEffect(()=>{if(s.current){let S=typeof d=="number"?d:0;s.current.style.transform=`rotate(${S}deg)`,s.current.style.transformOrigin="center center";}},[d]);let c=Math.max(1,Math.min(24,Number(r)||12)),l=10,h=2,u=6,m=u+l+4,f=60,H=Math.max(120,c*(l+h)+u*2),w=a??`${c}f Cable`,R=n?`Cable ID ${n}`:void 0,M=fe(1),I=i||M,z=o?"#3b82f6":I,P=typeof d=="number"?d:0,x=S=>{let O=(S%360+360)%360;return O>=315||O<45?reactflow.Position.Top:O>=45&&O<135?reactflow.Position.Right:O>=135&&O<225?reactflow.Position.Bottom:reactflow.Position.Left},W=()=>{let S=[],O=x(P);for(let te=0;te<c;te++){let V=te+1,A=Ke(V),re=fe(V),T=u+te*(l+h),F=-5,be=A.backgroundImage?A.backgroundImage:re,q={position:"absolute",left:`${T}px`,top:`${F}px`,width:l,height:l,borderRadius:"50%",border:"none",background:be,backgroundColor:re,zIndex:10,cursor:"pointer","--fiber-bg":re};A.backgroundImage&&(q["--fiber-bg-image"]=A.backgroundImage);let he=`fiber-${V}`;S.push(jsxRuntime.jsxs(nt__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:he,type:"target",position:O,className:"tube-fiber-handle",isConnectable:true,style:q,"data-fiber-idx":V,"data-fiber-color":re}),jsxRuntime.jsx(reactflow.Handle,{id:he,type:"source",position:O,className:"tube-fiber-handle",isConnectable:true,style:q,"data-fiber-idx":V,"data-fiber-color":re})]},`fiber-${V}`));}return S},C="cable-button",D=8,$={width:D,height:D,borderRadius:"50%",background:I,backgroundColor:I,border:`1px solid ${I}`,cursor:"pointer",zIndex:10},_=2,Z=(S=>{let O=(S%360+360)%360;return O>=315||O<45?reactflow.Position.Bottom:O>=45&&O<135?reactflow.Position.Left:O>=135&&O<225?reactflow.Position.Top:reactflow.Position.Right})(P),oe={width:H,height:f,position:"relative",transform:`rotate(${P}deg)`,transformOrigin:"center center","--rotation":`${P}deg`},U={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${_}px solid ${z}`,boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:u,paddingTop:m,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsxRuntime.jsx("div",{ref:s,style:oe,children:jsxRuntime.jsxs("div",{style:U,children:[W(),jsxRuntime.jsx(reactflow.Handle,{id:C,type:"source",position:Z,className:"cable-button-handle",isConnectable:true,style:$,"data-handle-type":"cable-button","data-cable-color":I}),jsxRuntime.jsx(reactflow.Handle,{id:C,type:"target",position:Z,className:"cable-button-handle",isConnectable:true,style:$,"data-handle-type":"cable-button","data-cable-color":I}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:w}),R&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:R})]})]})})};var Yo=({data:e,selected:o})=>{let{tubeCount:r=12,fibersPerTube:n=12,fiberCount:a,cableId:i="CBL-002",label:d,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(r)||12)),h=Math.max(1,Number(s)||1),u=14,m=10,f=3,H=6,k=H+m+4,w=60,R=Math.max(120,l*(u+f)+H*2),M=a??l*(Number(n)||12),I=d??`${M}f Cable`,z=i?`Cable ID ${i}`:void 0,P=fe(h),x=c||P,W=o?"#3b82f6":x,C=()=>{let Z=[];for(let oe=0;oe<l;oe++){let U=h+oe,S=Ke(U),O=fe(U),te=H+oe*(u+f),V=-5,A=S.backgroundImage?S.backgroundImage:O,re={position:"absolute",left:`${te}px`,top:`${V}px`,width:u,height:m,borderRadius:6,border:"none",background:A,backgroundColor:O,zIndex:10,cursor:"pointer","--fiber-bg":O};S.backgroundImage&&(re["--fiber-bg-image"]=S.backgroundImage);let T=`tube-${U}`;Z.push(jsxRuntime.jsxs(nt__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:T,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:re,"data-fiber-idx":U,"data-tube-idx":U,"data-tube-color":O}),jsxRuntime.jsx(reactflow.Handle,{id:T,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:re,"data-fiber-idx":U,"data-tube-idx":U,"data-tube-color":O})]},`tube-${U}`));}return Z},D="cable-button",$=8,_={width:$,height:$,borderRadius:"50%",background:x,backgroundColor:x,border:`1px solid ${x}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:R,height:w,borderRadius:4,background:"#111827",border:`2px solid ${W}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:H,paddingTop:k,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[C(),jsxRuntime.jsx(reactflow.Handle,{id:D,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":x}),jsxRuntime.jsx(reactflow.Handle,{id:D,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":x}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:I}),z&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:z})]})]})};var Xo=({data:e,selected:o,id:r})=>{let{connector:n="LC",couplerFiberCount:a,label:i,portLabelsLeft:d,portLabelsRight:s}=e||{},c=reactflow.useEdges(),l=typeof a=="number"&&[1,2,4].includes(a)?a:2,h=Math.max(1,Math.min(4,l)),u=9,m=3,f=3,H=60,k=30,w=h*u+(h-1)*m,R=Math.max(k,w+f*2),M=Math.max(H,80),I=(x,W)=>{let C=`${x}-${W+1}`;return c.find($=>$.source===r&&$.sourceHandle===C||$.target===r&&$.targetHandle===C)?.data?.color||"#555"},z=x=>{let W=[],C=x==="left"?reactflow.Position.Left:reactflow.Position.Right,D=x==="left"?d:s;for(let $=0;$<h;$++){let _=$+1,X=`${x}-${_}`,Z=I(x,$),S=f+(R-w)/2+$*(u+m),O={position:"absolute",left:x==="left"?-5:void 0,right:x==="right"?-5:void 0,top:`${S}px`,width:u,height:u,borderRadius:"50%",border:"none",background:Z,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};W.push(jsxRuntime.jsxs(nt__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:X,type:"target",position:C,isConnectable:true,style:O}),jsxRuntime.jsx(reactflow.Handle,{id:X,type:"source",position:C,isConnectable:true,style:O})]},X)),D&&D[$]&&W.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:x==="left"?-30:void 0,right:x==="right"?-30:void 0,top:`${S}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:x==="left"?"right":"left",width:"25px"},children:D[$]},`${X}-label`));}return W},P=i||`${n}-${h}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:M,height:R,borderRadius:4,border:`2px solid ${o?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${f}px`,boxSizing:"border-box"},children:[z("left"),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:P})}),z("right")]})};var rt=32,Jt=30,ci=24,li=80,Kt=400,qt=300,Yr=2,ot=8,Xr=120;function jo(e){let{couplerFiberCount:o}=e.data||{},r=typeof o=="number"&&[1,2,4].includes(o)?o:2,n=Math.max(1,Math.min(4,r)),a=7,i=3,d=3,s=60,c=30,l=n*a+(n-1)*i,h=Math.max(c,l+d*2);return {width:Math.max(s,80),height:h}}function Qt(e){let{fibersPerTube:o=12}=e.data||{},r=Math.max(1,Math.min(24,Number(o)||12)),n=14,a=4,i=1,d=2,s=20,c=r*n+(r-1)*a;return {width:Math.max(60,c+i*2+d*2),height:s}}function jr(e){return {width:et,height:0}}function Ht(e){return e.type==="coupler"?jo(e):e.type==="tube"?Qt(e):e.type==="splice-tray"?jr():{width:80,height:30}}function Gr(e){return e.data?.panelWidth||Kt}function pi(e){return e.data?.panelHeight||qt}function Zr(e){return Gr(e)-Yr*2-ot*2}function ui(e,o){return Zr(e)-o}function Kr(e,o=Jt){return Math.floor(e/o)+1}function qr(e,o=Jt){return (e-1)*o}function gi(e,o,r){let n=Jt,a=Kr(r.y,n),i=qr(a,n);return {x:r.x,y:i,slotPosition:a}}function Go(e,o){if(o.length===0)return {width:e.data?.panelWidth||Kt,height:e.data?.panelHeight||qt};let r=o.some(l=>l.type==="tube"),n=o.some(l=>l.type==="splice-tray"),a=o.some(l=>l.type==="coupler"),i,d=5;if(r&&n&&a){let l=0,h=0;for(let f of o)if(f.type==="tube"){let H=Qt(f);H.width>l&&(l=H.width);}else if(f.type==="coupler"){let H=jo(f);H.width>h&&(h=H.width);}let u=l+Xr+et+h+d,m=0;i=m+u+m;}else {let l=0;for(let u of o){let m=Ht(u),f=(u.position?.x||0)+m.width;f>l&&(l=f);}i=l+4;}i=Math.max(e.data?.panelWidth||Kt,i);let s=rt;for(let l of o){let h=Ht(l),u=(l.position?.y||0)+h.height;u>s&&(s=u);}let c=Math.max(e.data?.panelHeight||qt,s+ot);return {width:i,height:c}}function Jr(e,o,r){if(e===0)return 0;if(e===1)return o;let n=e*o,a=r-n,i=Math.max(5,a/(e-1));return o+i}function fi(e,o,r){return Jr(e,o,r)}var Br=20,Ur=400,Vr=300;function Qr(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||Ur,height:e.data?.closureHeight||e.data?.panelHeight||Vr};let r=o.some(c=>c.type==="tube"),n=o.some(c=>c.type==="splice-tray"),a,i=5;if(r&&n){let c=0,l=0,h=0,u=o.filter(f=>f.type==="tube"),m=o.filter(f=>f.type==="splice-tray");if(u.length>0&&m.length>0){let f=m.map(k=>k.position?.x||0),H=f.reduce((k,w)=>k+w,0)/f.length;for(let k of u){let w=Qt(k);(k.position?.x||0)<H?w.width>c&&(c=w.width):w.width>l&&(l=w.width);}m.length>0&&(h=et),a=ot+c+Br+h+Br+l+i;}else {let f=0;for(let H of o){let k=Ht(H),w=(H.position?.x||0)+k.width;w>f&&(f=w);}a=f+ot+i;}}else {let c=0;for(let l of o){let h=Ht(l),u=(l.position?.x||0)+h.width;u>c&&(c=u);}a=c+ot+i;}a=Math.max(e.data?.closureWidth||e.data?.panelWidth||Ur,a);let d=rt;for(let c of o){let l=Ht(c),h=(c.position?.y||0)+l.height;h>d&&(d=h);}let s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Vr,d+ot);return {width:a,height:s}}var qo=({data:e,selected:o,id:r})=>{let{label:n="Patch Panel",header:a,panelWidth:i,panelHeight:d}=e||{},{getNodes:s,setNodes:c}=reactflow.useReactFlow(),l=nt.useRef(false),h=nt.useRef([]),u=nt.useMemo(()=>{let I=s().filter(z=>z.parentId===r);return (I.length!==h.current.length||I.some((z,P)=>z.id!==h.current[P]?.id))&&(h.current=I),h.current},[s,r]),m=nt.useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),f=nt.useMemo(()=>i&&d?{width:i,height:d}:u.length===0?{width:i||400,height:d||300}:Go(m,u),[u,m,i,d]);nt.useEffect(()=>{if(i&&d||l.current)return;let M=i,I=d,z=Math.abs((M||0)-f.width),P=Math.abs((I||0)-f.height);(z>1||P>1)&&(l.current=true,c(x=>x.map(W=>W.id===r?{...W,data:{...W.data,panelWidth:f.width,panelHeight:f.height}}:W)),setTimeout(()=>{l.current=false;},0));},[r,f.width,f.height,i,d,c]);let H=f.width,k=f.height,w=rt,R=a||n;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${H}px`,height:`${k}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${w}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:R})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:w,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var er=({data:e,selected:o,id:r})=>{let{label:n="Closure",header:a,closureWidth:i,closureHeight:d,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:h}=reactflow.useReactFlow(),u=nt.useRef(false),m=nt.useRef([]),f=nt.useMemo(()=>{let x=l().filter(W=>W.parentId===r);return (x.length!==m.current.length||x.some((W,C)=>W.id!==m.current[C]?.id))&&(m.current=x),m.current},[l,r]),H=nt.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=nt.useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:f.length===0?{width:i||s||400,height:d||c||300}:Qr(H,f),[f,H,i,d,s,c]);nt.useEffect(()=>{if(i&&d||s&&c||u.current)return;let P=i||s,x=d||c,W=Math.abs((P||0)-k.width),C=Math.abs((x||0)-k.height);(W>1||C>1)&&(u.current=true,h(D=>D.map($=>$.id===r?{...$,data:{...$.data,closureWidth:k.width,closureHeight:k.height}}:$)),setTimeout(()=>{u.current=false;},0));},[r,k.width,k.height,i,d,s,c,h]);let w=k.width,R=k.height,M=rt,I=a||n,z=w/2;return jsxRuntime.jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${z}px ${z}px 12px 12px`,padding:0,width:`${w}px`,height:`${R}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${M}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${z}px ${z}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:I})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:M,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var or=({data:e,selected:o,id:r})=>{let{label:n,splitterType:a="splitter",inputCount:i=1,outputCount:d=8}=e||{},s=reactflow.useEdges(),c=n||(a==="WDM"?"WDM":"Splitter"),l=9,h=3,u=3,m=50,f=30,H=Math.min(Math.max(i||1,1),2),k=H*l+(H-1)*h,w=Math.min(d||8,48),R=w*l+(w-1)*h,M=Math.max(k,R),I=Math.max(f,M+u*2),z=Math.max(m,50),P=oe=>s.find(S=>S.source===r&&S.sourceHandle===oe||S.target===r&&S.targetHandle===oe)?.data?.color||"#555",x=()=>{let oe=[],U=u+(I-k)/2;for(let S=0;S<H;S++){let O=`input-${S+1}`,te=U+S*(l+h),V=P(O),A={position:"absolute",left:-5,top:`${te}px`,width:l,height:l,borderRadius:"50%",border:"none",background:V,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};oe.push(jsxRuntime.jsxs(nt__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:`${O}-target`,type:"target",position:reactflow.Position.Left,isConnectable:true,style:A}),jsxRuntime.jsx(reactflow.Handle,{id:`${O}-source`,type:"source",position:reactflow.Position.Left,isConnectable:true,style:A})]},O));}return oe},W=()=>{let oe=[],U=u+(I-R)/2;for(let S=0;S<w;S++){let O=`output-${S+1}`,te=U+S*(l+h),V=P(O),A={position:"absolute",right:-5,top:`${te}px`,width:l,height:l,borderRadius:"50%",border:"none",background:V,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};oe.push(jsxRuntime.jsxs(nt__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:`${O}-target`,type:"target",position:reactflow.Position.Right,isConnectable:true,style:A}),jsxRuntime.jsx(reactflow.Handle,{id:`${O}-source`,type:"source",position:reactflow.Position.Right,isConnectable:true,style:A})]},O));}return oe},C=Math.max(k+u*4,f*.6),D=(I-C)/2,$=D+C,_=0,X=I,Z=o?"#3b82f6":"#4b5563";return jsxRuntime.jsxs("div",{className:`trapezoid-node ${o?"selected":""}`,style:{width:z,height:I,position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${u}px`,boxSizing:"border-box"},children:[jsxRuntime.jsx("svg",{width:z,height:I,viewBox:`0 0 ${z} ${I}`,style:{position:"absolute",top:0,left:0,width:`${z}px`,height:`${I}px`,pointerEvents:"none",zIndex:0},children:jsxRuntime.jsx("polygon",{points:`0,${D} 0,${$} ${z},${X} ${z},${_}`,fill:"#1f2937",stroke:Z,strokeWidth:"2"})}),x(),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:c})}),W()]})};var rn=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",lt=(e,o)=>rn(e)||rn(o),ee=(e,o)=>o?e?.type==="fibre-split"?o.replace(/-(source|target)$/i,""):o:o||"";function ki(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let r=o.nodes.find(T=>T.id===e.source),n=o.nodes.find(T=>T.id===e.target),a=ee(r,e.sourceHandle),i=ee(n,e.targetHandle),d=o.edges.some(T=>T.source===e.source?ee(r,T.sourceHandle)===a:T.target===e.source?ee(r,T.targetHandle)===a:false),s=o.edges.some(T=>T.target===e.target?ee(n,T.targetHandle)===i:T.source===e.target?ee(n,T.sourceHandle)===i:false),c=lt(r,n);if((d||s)&&!c)return d?{valid:false,reason:`Source handle ${e.sourceHandle} on node ${e.source} is already connected`}:{valid:false,reason:`Target handle ${e.targetHandle} on node ${e.target} is already connected`};let l=(T,F)=>(T?.type==="tube"||T?.type==="cable")&&!!F&&F.startsWith("fiber-"),h=(T,F)=>(T?.type==="tube"||T?.type==="multi-tube-cable")&&!!F&&F.startsWith("tube-"),u=(T,F)=>T?.type==="multi-tube-cable"&&!!F&&F.startsWith("tube-"),m=(T,F)=>T?.type==="tube"&&!!F&&F.startsWith("tube-"),f=(T,F)=>(T?.type==="cable"||T?.type==="multi-tube-cable")&&F==="cable-button",H=(T,F)=>T?.type==="splice"&&(F==="left"||F==="right"),k=(T,F)=>T?.type==="coupler"&&!!F&&(F.startsWith("left-")||F.startsWith("right-")),w=(T,F)=>{if(T?.type!=="fibre-split"||!F)return false;let be=ee(T,F);return be.startsWith("input-")||be.startsWith("output-")};if(!c)return {valid:true};if(r?.type==="splice"&&n?.type==="splice"){let T=r.data?.mode==="ribbon",F=n.data?.mode==="ribbon";if(T!==F)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let R=l(r,e.sourceHandle),M=l(n,e.targetHandle),I=H(r,e.sourceHandle),z=H(n,e.targetHandle),P=k(r,e.sourceHandle),x=k(n,e.targetHandle),W=w(r,e.sourceHandle),C=w(n,e.targetHandle),D=f(r,e.sourceHandle),$=f(n,e.targetHandle),_=u(r,e.sourceHandle),X=u(n,e.targetHandle),Z=m(r,e.sourceHandle),oe=m(n,e.targetHandle),U=h(r,e.sourceHandle),S=h(n,e.targetHandle);return R&&z||M&&I||(I&&(x||C)||z&&(P||W))||(P&&(x||C||z)||x&&(P||W||I))||D&&$||(_&&oe||X&&Z)?{valid:true}:U&&S?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function oo(e,o){if(!o)return;let r=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,n=o.data??{},a=n.handleSideMap;if(a&&a[r])return a[r];if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let i=Array.isArray(n.ports)?n.ports:[],d=Array.isArray(n.rearPorts)?n.rearPorts:[];if(r.startsWith("pwr")||r.includes("power"))return "rear";for(let c of i)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "front";for(let c of d)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "rear"}function rr(e={},o={}){let r={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},n=new Set;return {getState:()=>r,setState:u=>{r={...r,...u},n.forEach(m=>m(r));},subscribe:u=>(n.add(u),()=>n.delete(u)),selectEdgeZIndex:u=>{let m=r.nodes.find(P=>P.id===u.target);if(!m||m.type!=="device")return 1e3;let f=m.data?.view||"front",H=oo(u.targetHandle||"",m);if(H)return f===H?1e3:500;let k=(u.targetHandle||"").toString(),w=k.toLowerCase(),R=w.startsWith("pwr")||w.startsWith("power"),M=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),I=/^[A-Z0-9]+-\d+$/i.test(k)&&!w.startsWith("pwr")&&!w.startsWith("power"),z=M||I;return R?f==="rear"?1e3:500:z?f==="front"?1e3:500:1e3},validateConnection:u=>(o.validateConnection||ki)(u,r),selectNodeById:u=>r.nodes.find(m=>m.id===u),selectConnectedEdges:u=>r.edges.filter(m=>m.source===u||m.target===u)}}function vi(e){let o=a=>e.subscribe(a),r=()=>e.getState();return nt.useSyncExternalStore(o,r,r)}function ir(e){let o=n=>e.subscribe(n),r=()=>e.getState().nodes;return nt.useSyncExternalStore(o,r,r)}function ar(e){let o=n=>e.subscribe(n),r=()=>e.getState().edges;return nt.useSyncExternalStore(o,r,r)}function nn(e){return e.selectEdgeZIndex}function an(e){let o=e.data.rackWidthPx||300,r=(e.data.uHeight||42)*20,n=e.position.x,a=e.position.x+o,i=e.position.y,d=e.position.y+r;return {left:n,right:a,top:i,bottom:d}}function ro(e,o){let r=an(o);return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom}function no(e,o){let r=null,n=1/0;for(let a of o){if(!ro(e,a))continue;let i=Math.sqrt(Math.pow(e.x-a.position.x,2)+Math.pow(e.y-a.position.y,2));i<n&&(n=i,r=a);}return r}function we(e){let{edges:o,connection:r,edgeType:n,selectEdgeZIndex:a,findBy:i,data:d}=e,s=i==="source"?r.sourceHandle:r.targetHandle,c=i==="source"?r.source:r.target;if(!s||!c)return null;let l=o.find(k=>i==="source"?k.source===c&&k.sourceHandle===s:k.target===c&&k.targetHandle===s);if(!l)return null;let h=o.filter(k=>k.id!==l.id),u=reactflow.addEdge(r,h),m=u[u.length-1],f=a({...r,id:m.id,type:n}),H={...m,type:n,zIndex:f,style:{...m.style,zIndex:f},data:d!==void 0?d:m.data};return [...u.slice(0,-1),H]}function cn(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var ke=({type:e,children:o})=>{let r=nt__default.default.useRef(null),n=nt__default.default.useCallback(a=>{if(r.current=a,a){let i=a.parentElement,d=0;for(;i&&!i.classList.contains("react-flow__node")&&d<10;)i=i.parentElement,d++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return nt__default.default.useEffect(()=>{if(r.current){let a=r.current.parentElement,i=0;for(;a&&!a.classList.contains("react-flow__node")&&i<10;)a=a.parentElement,i++;a&&a.classList.contains("react-flow__node")&&a.setAttribute("data-type",e);}},[e]),jsxRuntime.jsx("div",{ref:n,style:{width:"100%",height:"100%"},children:o})},ln=(e,o,r)=>({rack:n=>jsxRuntime.jsx(ke,{type:"rack",children:jsxRuntime.jsx(xo,{...n,onViewChange:e,onRackFaceChange:o,isDragOver:r?r()===n.id:false})}),fiber:n=>jsxRuntime.jsx(ke,{type:"fiber",children:jsxRuntime.jsx(wo,{...n})}),device:n=>jsxRuntime.jsx(ke,{type:"device",children:jsxRuntime.jsx(Ro,{...n})}),"vertical-pdu":n=>jsxRuntime.jsx(ke,{type:"vertical-pdu",children:jsxRuntime.jsx(To,{...n})}),splice:n=>jsxRuntime.jsx(ke,{type:"splice",children:jsxRuntime.jsx($o,{...n})}),"splice-tray":n=>jsxRuntime.jsx(ke,{type:"splice-tray",children:jsxRuntime.jsx(Mo,{...n})}),tube:n=>jsxRuntime.jsx(ke,{type:"tube",children:jsxRuntime.jsx(Lo,{...n})}),cable:n=>jsxRuntime.jsx(ke,{type:"cable",children:jsxRuntime.jsx(Uo,{...n})}),"multi-tube-cable":n=>jsxRuntime.jsx(ke,{type:"multi-tube-cable",children:jsxRuntime.jsx(Yo,{...n})}),coupler:n=>jsxRuntime.jsx(ke,{type:"coupler",children:jsxRuntime.jsx(Xo,{...n})}),"patch-panel":n=>jsxRuntime.jsx(ke,{type:"patch-panel",children:jsxRuntime.jsx(qo,{...n})}),closure:n=>jsxRuntime.jsx(ke,{type:"closure",children:jsxRuntime.jsx(er,{...n})}),"fibre-split":n=>jsxRuntime.jsx(ke,{type:"fibre-split",children:jsxRuntime.jsx(or,{...n})})}),Wi={fiber:vo,power:Ho,smoothstep:Pr,step:Rr,"thick-cable":Dr},zi=({nodes:e,edges:o,initialNodes:r,initialEdges:n,onNodesChange:a,onEdgesChange:i,store:d,debug:s,onNodeClick:c,onEdgeClick:l,onViewChange:h,onRackFaceChange:u,className:m,style:f,alignRacksToBottom:H,colorMode:k="dark",onInit:w,onFlowMethods:R,showDownloadButton:M=false,downloadButtonPosition:I="top-right",downloadButtonText:z="Download Image",downloadButtonStyle:P,useSmoothstepEdgesForTubes:x=false,connectOnClick:W=true,panOnDrag:C=true,panOnScroll:D=true,zoomOnScroll:$=true})=>{let _=nt.useCallback((t,p)=>{let g=new Map,b=[],N=[],v=(E,j)=>!E||!j?false:!!(E.startsWith("tube-")||j.type==="splice"&&(E==="left"||E==="right")||E==="cable-button");for(let E of t){if(!E.source||!E.target||!E.sourceHandle||!E.targetHandle){s&&console.warn("Invalid edge skipped (missing source/target/handles):",E);continue}let j=p.find(ve=>ve.id===E.source),Y=p.find(ve=>ve.id===E.target),ce=`${E.source}:${E.sourceHandle}`,ie=g.get(ce),ye=v(E.sourceHandle,j),le=`${E.target}:${E.targetHandle}`,de=g.get(le),J=v(E.targetHandle,Y);if(ie&&!ye){s&&console.warn("Duplicate connection detected on source handle, removing:",{handle:ce,existingEdge:ie.id,duplicateEdge:E.id}),N.push(E);continue}if(de&&!J){s&&console.warn("Duplicate connection detected on target handle, removing:",{handle:le,existingEdge:de.id,duplicateEdge:E.id}),N.push(E);continue}b.push(E),ie||g.set(ce,E),de||g.set(le,E);}return s&&N.length>0&&console.log(`Filtered ${N.length} duplicate edge(s) from initial edges`),b},[s]),X=Array.isArray(e)&&Array.isArray(o),Z=nt__default.default.useMemo(()=>X?e||[]:r||e||[],[X,e,r]),oe=nt__default.default.useMemo(()=>X?o||[]:n||o||[],[X,o,n]),U=nt__default.default.useMemo(()=>_(oe,Z),[oe,Z,_]),S=nt__default.default.useMemo(()=>d||rr({nodes:Z,edges:U,debug:s}),[d,X,s,U]),O=ir(S),te=ar(S),[V,A,re]=reactflow.useNodesState(O),[T,F,be]=reactflow.useEdgesState(te),q=nn(S),he=nt.useRef(null),[ue,Ve]=nt.useState(false);nt.useEffect(()=>{let t=()=>{Ve(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]);let{toObject:Pt,setViewport:Ct,setNodes:Et,setEdges:_e,getNodes:Fe,getEdges:cr,fitView:io}=reactflow.useReactFlow();nt.useEffect(()=>{R&&R({toObject:Pt,setViewport:Ct,setNodes:t=>{Et(t),S.setState({nodes:t});},setEdges:t=>{_e(t),S.setState({edges:t});},toImage:t=>he.current?htmlToImage.toPng(he.current,t):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>Fe(),getEdges:()=>cr(),fitView:t=>{if(t?.nodes&&Array.isArray(t.nodes)&&t.nodes.length>0){let p=t.nodes.map(N=>Fe().find(v=>v.id===N)).filter(N=>N!==void 0),{nodes:g,...b}=t;io({...b,nodes:p});}else {let{nodes:p,...g}=t||{};io(g);}}});},[R,Pt,Ct,Et,_e,S,io,Fe,cr]);let mn=nt.useCallback(()=>{if(!he.current){s&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(he.current,{filter:t=>!(t?.classList?.contains("react-flow__minimap")||t?.classList?.contains("react-flow__controls")||t?.classList?.contains("react-flow__attribution")||t?.classList?.contains("download-button")||t?.tagName==="BUTTON"),backgroundColor:k==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(t=>{let p=document.createElement("a");p.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,p.href=t,p.click();}).catch(t=>{s&&console.error("Error downloading image:",t);});},[k,s]),[lr,Rt]=nt.useState(null),pr=nt.useRef(null),ur=nt.useRef(h),gr=nt.useRef(u);nt.useEffect(()=>{ur.current=h;},[h]),nt.useEffect(()=>{gr.current=u;},[u]),nt.useEffect(()=>{pr.current=lr;},[lr]);let ao=nt.useCallback((t,p)=>{ur.current?.(t,p);},[]),so=nt.useCallback((t,p)=>{gr.current?.(t,p);},[]),co=nt.useCallback(()=>pr.current,[]),fr=nt.useRef(ln(ao,so,co));nt.useEffect(()=>{fr.current=ln(ao,so,co);},[ao,so,co]);let We=nt.useRef(V);nt.useEffect(()=>{We.current=V;},[V]);let K=nt.useRef(T);nt.useEffect(()=>{K.current=T;},[T]),nt.useEffect(()=>{A(O);},[O,A]),nt.useEffect(()=>{F(te);},[te,F]),nt.useEffect(()=>{if(X&&o){let t=_(o,e||[]);t.length!==o.length&&(s&&console.warn(`Controlled edges had ${o.length-t.length} duplicate(s) removed`),i?.(t));}},[X,o,e,_,i,s]),nt.useEffect(()=>{X&&S.setState({nodes:e||[]});},[X,e,S]),nt.useEffect(()=>{X&&S.setState({edges:o||[]});},[X,o,S]),nt.useEffect(()=>{if(!H||!V||V.length===0)return;let t=V.filter(Y=>Y.type==="rack");if(t.length===0)return;let p=t.map(Y=>{let ie=Y.data?.uHeight||42,ye=60+ie*20;return (Y.position?.y||0)+ye}),g=Math.min(...p),b=Math.max(...p);if(b-g<20)return;let v=b,E=V.map(Y=>{if(Y.type!=="rack")return Y;let ie=Y.data?.uHeight||42,ye=60+ie*20,le=(Y.position?.y||0)+ye,de=v-le;return Math.abs(de)<5?Y:{...Y,position:{x:Y.position?.x||0,y:(Y.position?.y||0)+de}}});E.some((Y,ce)=>Y.position!==V[ce].position)&&A(E);},[H,V,A]);let lo=nt.useRef(new Map);nt.useEffect(()=>{let t=new Map;V.forEach(p=>{t.set(p.id,p);}),lo.current=t;},[V]);let se=nt.useCallback(t=>lo.current.get(t),[]),gt=nt.useCallback((t,p)=>{if(!t||!p)return;let g=se(t);if(!g)return;let b=p.replace(/-(source|target)$/i,"");if(g.type==="fibre-split"&&b.startsWith("output-")){let v=K.current.filter(E=>E.target===t&&(E.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(v.length>0){let E=v[0]?.data?.color;if(E)return {color:E}}}if((g.type==="tube"||g.type==="cable")&&p.startsWith("fiber-")){let v=p.replace("fiber-",""),E=parseInt(v,10);if(E>=1&&E<=24){let j=ko(E),Y=E>12;return {color:j,striped:Y}}}if((g.type==="multi-tube-cable"||g.type==="tube")&&p.startsWith("tube-")){let v=p.replace("tube-",""),E=parseInt(v,10);if(E>=1&&E<=24){let j=fe(E),Y=E>12;return {color:j,striped:Y}}}let N=g.data;if(N.color)return {color:N.color}},[se]),br=nt.useRef(new Map);nt.useEffect(()=>{F(t=>{let p=false,g=t.map(b=>{let N=q(b);return br.current.get(b.id)!==N?(p=true,br.current.set(b.id,N),{...b,zIndex:N,style:{...b.style,zIndex:N}}):b});return p?g:t});},[V,F,q]),nt.useEffect(()=>{let t=V.map(g=>{if(g.type==="coupler"&&g.parentId){let b=se(g.parentId);if(b&&(b.type==="patch-panel"||b.type==="closure")&&(!g.extent||g.extent!=="parent"))return {...g,extent:"parent"}}if(g.type==="splice"&&g.parentId&&g.data.holderPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let b=se(g.parentId);if(b&&b.type==="splice-tray"){let N=g.data.mode==="ribbon",v=kt(b,g.data.holderPosition,N);return {...g,position:v}}}if(g.type==="device"&&g.parentId&&g.data.uPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let b=se(g.parentId);if(b){let N=at(b,g.data.uPosition);return {...g,position:N}}}return g});t.some((g,b)=>{let N=V[b];return g.extent!==N.extent||g.position?.x!==N.position?.x||g.position?.y!==N.position?.y})&&A(t);},[V,A,se]);let yn=nt.useCallback(t=>{let p=t.map(g=>{if(g.type==="position"&&g.position){let b=se(g.id);if(b&&b.type==="coupler"&&b.parentId){let N=se(b.parentId);if(N&&(N.type==="patch-panel"||N.type==="closure")){if(!b.extent||b.extent!=="parent"){let v={...b,extent:"parent"};A(E=>E.map(j=>j.id===b.id?v:j));}return {...g,position:b.position||{x:0,y:0}}}}if(b&&(b.type==="tube"||b.type==="splice-tray")&&b.parentId){let N=se(b.parentId);if(N&&N.type==="closure"){if(!b.extent||b.extent!=="parent"){let v={...b,extent:"parent"};A(E=>E.map(j=>j.id===b.id?v:j));}return {...g,position:b.position||{x:0,y:0}}}}if(b&&b.type==="splice"&&b.parentId){let N=se(b.parentId);if(N&&N.type==="splice-tray"){let v=Wo(b,N,g.position,We.current);if(v.holderPosition!==void 0){let E={...b,data:{...b.data,holderPosition:v.holderPosition}};A(j=>j.map(Y=>Y.id===b.id?E:Y));}return {...g,position:{x:v.x,y:v.y}}}}if(b&&b.type==="device"&&b.parentId){let N=se(b.parentId);if(N){let v=mo(b,N,g.position,We.current);if(v.uPosition!==void 0){let E={...b,data:{...b.data,uPosition:v.uPosition}};A(j=>j.map(Y=>Y.id===b.id?E:Y));}return {...g,position:{x:v.x,y:v.y}}}}if(b&&b.type==="device"&&b.parentId){let N=se(b.parentId);if(N){let v=N;if(!ro(g.position,v)){let E=g.position.x+v.position.x,j=g.position.y+v.position.y,Y={...b,parentId:void 0,extent:void 0,data:{...b.data,uPosition:void 0}};return A(ce=>ce.map(ie=>ie.id===b.id?Y:ie)),{...g,position:{x:E,y:j}}}}}}return g});re(p);},[re,A,se]),xn=nt.useCallback((t,p)=>{Rt(null);},[]),wn=nt.useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let b=We.current.filter(v=>v.type==="rack").map(v=>v),N=no(p.position,b);Rt(N?.id??null);}else Rt(null);},[]),Nn=nt.useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let b=We.current.filter(v=>v.type==="rack").map(v=>v),N=no(p.position,b);if(N){let v=p.position.x-N.position.x,E=p.position.y-N.position.y,j={...p,parentId:N.id,extent:"parent",position:{x:v,y:E},data:{...p.data,uPosition:1}},Y=We.current.map(ce=>ce.id===p.id?j:ce);A(Y),X||S.setState({nodes:Y});}}Rt(null);},[A,X,S]),kn=nt.useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let p=se(t.source),g=se(t.target),b=ee(p,t.sourceHandle),N=ee(g,t.targetHandle),v=K.current.some(B=>B.source===t.source?ee(p,B.sourceHandle)===b:B.target===t.source?ee(p,B.targetHandle)===b:false),E=K.current.some(B=>B.target===t.target?ee(g,B.targetHandle)===N:B.source===t.target?ee(g,B.sourceHandle)===N:false);v&&s&&console.log("Connection will replace: Source handle already connected",{source:t.source,sourceHandle:t.sourceHandle,existingEdges:K.current.filter(B=>B.source===t.source&&B.sourceHandle===t.sourceHandle||B.target===t.source&&B.targetHandle===t.sourceHandle)}),E&&s&&console.log("Connection will replace: Target handle already connected",{target:t.target,targetHandle:t.targetHandle,existingEdges:K.current.filter(B=>B.target===t.target&&B.targetHandle===t.targetHandle||B.source===t.target&&B.sourceHandle===t.targetHandle)});let j=lt(p,g);if((v||E)&&!j)return s&&console.log("Connection rejected: Non-fiber handle already connected",t),false;if(!j)return true;if(p?.type==="splice"&&g?.type==="splice"){let B=p.data?.mode==="ribbon",ae=g.data?.mode==="ribbon";if(B!==ae)return s&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",t),false}let Y=(B,ae)=>(B?.type==="tube"||B?.type==="cable")&&!!ae&&ae.startsWith("fiber-"),ce=(B,ae)=>(B?.type==="tube"||B?.type==="multi-tube-cable")&&!!ae&&ae.startsWith("tube-"),ie=(B,ae)=>B?.type==="multi-tube-cable"&&!!ae&&ae.startsWith("tube-"),ye=(B,ae)=>B?.type==="tube"&&!!ae&&ae.startsWith("tube-"),le=(B,ae)=>(B?.type==="cable"||B?.type==="multi-tube-cable")&&ae==="cable-button",de=(B,ae)=>B?.type==="splice"&&(ae==="left"||ae==="right"),J=(B,ae)=>B?.type==="coupler"&&!!ae&&(ae.startsWith("left-")||ae.startsWith("right-")),ve=(B,ae)=>{if(B?.type!=="fibre-split"||!ae)return false;let xr=ae.replace(/-(source|target)$/i,"");return xr.startsWith("input-")||xr.startsWith("output-")},Tt=Y(p,t.sourceHandle),Ye=Y(g,t.targetHandle),ne=de(p,t.sourceHandle),Xe=de(g,t.targetHandle),je=J(p,t.sourceHandle),It=J(g,t.targetHandle),ft=ve(p,t.sourceHandle),Dt=ve(g,t.targetHandle),go=le(p,t.sourceHandle),$t=le(g,t.targetHandle),fo=ie(p,t.sourceHandle),bo=ie(g,t.targetHandle),ho=ye(p,t.sourceHandle),y=ye(g,t.targetHandle),L=ce(p,t.sourceHandle),Q=ce(g,t.targetHandle);return Tt&&Xe||Ye&&ne||(ne&&(It||Dt)||Xe&&(je||ft))||(je&&(It||Dt||Xe)||It&&(je||ft||ne))||go&&$t||(fo&&y||bo&&ho)?true:L&&Q?(s&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",t),false):(s&&console.log("Connection rejected: Connection not allowed by fiber rules",t),false)},[se,s]),vn=nt.useCallback(t=>{s&&console.log("onConnect called:",t);let p=se(t.source),g=se(t.target);s&&(console.log("onConnect: sourceNode type:",p?.type,"targetNode type:",g?.type),console.log("onConnect: sourceHandle:",t.sourceHandle,"targetHandle:",t.targetHandle));let b=S.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!b.valid){s&&console.warn(`Connection rejected: ${b.reason}`);return}let N=p?.type==="vertical-pdu",v=p?.data,E=p?.type==="device"&&v?.deviceType==="switch",j=!!t.targetHandle&&(t.targetHandle.startsWith("pwr")||t.targetHandle.startsWith("power")),Y=!!t.targetHandle&&(t.targetHandle.startsWith("net-")||t.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(t.targetHandle)),ce=p?.type==="tube"&&g?.type==="multi-tube-cable",ie=p?.type==="multi-tube-cable"&&g?.type==="tube",ye=ce||ie,le=t.sourceHandle==="cable-button"&&t.targetHandle==="cable-button",de="fiber";N&&j?de="power":le?de="thick-cable":ye&&(de=x?"smoothstep":"fiber");let J,ve=cn(g),Tt=cn(p);if(ve||Tt){let y=g?.data,L=p?.data,Q=ve?y.ribbonFiberIds:L.ribbonFiberIds;Q&&Array.isArray(Q)&&Q.length>=6&&Q.length<=12&&(J={ribbonFiberIds:Q,isRibbon:true});}if(!J&&(de==="fiber"||de==="smoothstep")&&!N){let y;ce?y=gt(t.target,t.targetHandle):y=gt(t.source,t.sourceHandle),y&&(J={color:y.color,striped:y.striped,isRibbon:false});}else if(de==="thick-cable"&&le){let y=p?.data;J={color:y?.color||(y?.tubeStartIndex?fe(y.tubeStartIndex):"#6366f1")};}let Ye=ee(p,t.sourceHandle),ne=ee(g,t.targetHandle),Xe=K.current.some(y=>y.source===t.source?ee(p,y.sourceHandle)===Ye:y.target===t.source?ee(p,y.targetHandle)===Ye:false),je=K.current.some(y=>y.target===t.target?ee(g,y.targetHandle)===ne:y.source===t.target?ee(g,y.sourceHandle)===ne:false);if(lt(p,g)&&(Xe||je)){let y=new Set;for(let L of K.current){if(L.source===t.source&&ee(p,L.sourceHandle)===Ye){y.add(L.id);continue}if(L.target===t.source&&ee(p,L.targetHandle)===Ye){y.add(L.id);continue}if(L.source===t.target&&ee(g,L.sourceHandle)===ne){y.add(L.id);continue}L.target===t.target&&ee(g,L.targetHandle)===ne&&y.add(L.id);}if(y.size>0){let L=K.current.filter(Ae=>!y.has(Ae.id)),Q=reactflow.addEdge(t,L),Ne=Q[Q.length-1],He=q({...t,id:Ne.id,type:de}),ze={...Ne,type:de,zIndex:He,style:{...Ne.style,zIndex:He},data:J!==void 0?J:Ne.data};F([...Q.slice(0,-1),ze]),s&&console.log("Fiber handle replacement: Replaced",y.size,"edge(s)");return}}if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let y=K.current.find(L=>L.target===t.target&&L.targetHandle===t.targetHandle||L.source===t.target&&L.sourceHandle===t.targetHandle);if(y){s&&(console.log("Splice target handle replacement: Found existing edge",y.id,"on splice handle",t.targetHandle),console.log("Existing edge details:",{id:y.id,source:y.source,target:y.target,sourceHandle:y.sourceHandle,targetHandle:y.targetHandle,data:y.data}));let L=t.source&&t.sourceHandle?K.current.find(B=>B.source===t.source&&B.sourceHandle===t.sourceHandle):null;s&&L&&console.log("Splice target handle replacement: Also found existing source edge",L.id);let Q=new Set;y&&Q.add(y.id),L&&L.id!==y.id&&Q.add(L.id);let Ne=K.current.filter(B=>!Q.has(B.id));s&&console.log("Splice target handle replacement: Removing",Q.size,"edge(s), creating new connection");let He=`edge-${t.source}-${t.sourceHandle}-${t.target}-${t.targetHandle}-${Date.now()}`,ze=q({...t,id:He,type:"fiber"}),Ae={id:He,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle,type:"fiber",zIndex:ze,style:{zIndex:ze},data:J!==void 0?J:{}},_t=[...Ne,Ae];F(_t),s&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Ae.id);return}}if(p?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let y=K.current.find(L=>L.source===t.source&&L.sourceHandle===t.sourceHandle||L.target===t.source&&L.targetHandle===t.sourceHandle);if(y){s&&console.log("Splice source handle replacement: Found existing edge",y.id,"on splice handle",t.sourceHandle);let L=t.target&&t.targetHandle?K.current.find(B=>B.target===t.target&&B.targetHandle===t.targetHandle):null;s&&L&&console.log("Splice source handle replacement: Also found existing target edge",L.id);let Q=new Set;y&&Q.add(y.id),L&&L.id!==y.id&&Q.add(L.id);let Ne=K.current.filter(B=>!Q.has(B.id));s&&console.log("Splice source handle replacement: Removing",Q.size,"edge(s), creating new connection");let He=`edge-${t.source}-${t.sourceHandle}-${t.target}-${t.targetHandle}-${Date.now()}`,ze=q({...t,id:He,type:"fiber"}),Ae={id:He,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle,type:"fiber",zIndex:ze,style:{zIndex:ze},data:J!==void 0?J:{}},_t=[...Ne,Ae];F(_t),s&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Ae.id);return}}if((p?.type==="tube"||p?.type==="cable")&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if((g?.type==="tube"||g?.type==="cable")&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if((p?.type==="multi-tube-cable"||p?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:de,selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if((g?.type==="multi-tube-cable"||g?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:de,selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if(p?.type==="coupler"&&(t.sourceHandle?.startsWith("left-")||t.sourceHandle?.startsWith("right-"))){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if(g?.type==="coupler"&&(t.targetHandle?.startsWith("left-")||t.targetHandle?.startsWith("right-"))){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if(le&&t.source&&t.sourceHandle&&t.target&&t.targetHandle){let y=p?.data,L=y?.color||(y?.tubeStartIndex?fe(y.tubeStartIndex):"#6366f1"),Q=we({edges:K.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:q,findBy:"source",data:{color:L}});if(Q){F(Q);return}if(Q=we({edges:K.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:q,findBy:"target",data:{color:L}}),Q){F(Q);return}}if(N&&j&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:"power",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}if(E&&Y&&t.target&&t.targetHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"target",data:J});if(y){F(y);return}}let ft=S.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!ft.valid){if(N&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:j?"power":"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}if(E&&t.source&&t.sourceHandle){let y=we({edges:K.current,connection:t,edgeType:"fiber",selectEdgeZIndex:q,findBy:"source",data:J});if(y){F(y);return}}s&&console.warn(`Connection rejected: ${ft.reason}`);return}let Dt=K.current.some(y=>y.source===t.source&&y.sourceHandle===t.sourceHandle||y.target===t.source&&y.targetHandle===t.sourceHandle),go=K.current.some(y=>y.target===t.target&&y.targetHandle===t.targetHandle||y.source===t.target&&y.sourceHandle===t.targetHandle),$t=(y,L)=>!y||!L?false:!!(y.startsWith("tube-")||L.type==="splice"&&(y==="left"||y==="right")||y==="cable-button"),fo=$t(t.sourceHandle||"",p),bo=$t(t.targetHandle||"",g);if(Dt&&!fo){s&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:t.source,sourceHandle:t.sourceHandle,existingEdges:K.current.filter(y=>y.source===t.source&&y.sourceHandle===t.sourceHandle||y.target===t.source&&y.targetHandle===t.sourceHandle)});return}if(go&&!bo){s&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:t.target,targetHandle:t.targetHandle,existingEdges:K.current.filter(y=>y.target===t.target&&y.targetHandle===t.targetHandle||y.source===t.target&&y.sourceHandle===t.targetHandle)});return}let ho={...t,type:de,zIndex:q({...t,id:"temp-id"}),data:J};F(y=>{let L=reactflow.addEdge(ho,y),Q=L[L.length-1];return Q&&(mr(Ne=>new Set(Ne).add(Q.id)),setTimeout(()=>{mr(Ne=>{let He=new Set(Ne);return He.delete(Q.id),He});},1e3)),L});},[F,S,q,se,s,gt,x]),Hn=nt.useCallback((t,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let g=S.validateConnection({source:p.source??null,target:p.target??null,sourceHandle:p.sourceHandle??null,targetHandle:p.targetHandle??null});if(!g.valid){s&&console.warn(`Edge update rejected: ${g.reason}`);return}let b=se(p.source),N=se(p.target),v=b?.type==="vertical-pdu",E=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),j=b?.type==="tube"&&N?.type==="multi-tube-cable",Y=b?.type==="multi-tube-cable"&&N?.type==="tube",ce=j||Y,ie;v&&E?ie="power":ce?ie=x?"smoothstep":"fiber":ie="fiber";let ye;if((ie==="fiber"||ie==="smoothstep")&&!v){let le=gt(p.source,p.sourceHandle);le&&(ye={color:le.color,striped:le.striped});}F(le=>{let de=lt(b,N),J=ee(b,p.sourceHandle),ve=ee(N,p.targetHandle);return (de?le.filter(ne=>{if(ne.id===t.id)return true;let Xe=ne.source===p.source&&ee(b,ne.sourceHandle)===J||ne.target===p.source&&ee(b,ne.targetHandle)===J,je=ne.target===p.target&&ee(N,ne.targetHandle)===ve||ne.source===p.target&&ee(N,ne.sourceHandle)===ve;return !(Xe||je)}):le).map(ne=>ne.id===t.id?{...ne,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:ie,data:ye!==void 0?{...ne.data,...ye}:ne.data,zIndex:q({...p,id:ne.id,type:ie}),style:{...ne.style,zIndex:q({...p,id:ne.id,type:ie})}}:ne)});},[F,se,gt,q,x,s,S]),Sn=nt.useCallback((t,p)=>{if(ue){c&&c(p);return}let g=t.metaKey||t.ctrlKey;if(p.type==="tube"&&p.parentId&&!g){let N=Fe().find(v=>v.id===p.parentId&&(v.type==="cable"||v.type==="multi-tube-cable"));if(N){A(v=>v.map(E=>({...E,selected:E.id===N.id}))),c&&c(N);return}}if(g&&p.type==="device"){let b=p.data||{},N=b.view||(Array.isArray(b.rearPorts)&&b.rearPorts.length>0?"rear":"front"),v=N==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${p.id} from ${N} to ${v}`),h&&h(p.id,v),c&&c(p);}else c&&c(p);},[h,c,s,Fe,A,ue]),Pn=nt.useCallback(()=>{},[]),Cn=nt.useCallback((t,p)=>{l&&l(p);},[l]),[Te,po]=nt.useState(null),[hr,mr]=nt.useState(new Set);reactflow.useOnSelectionChange({onChange:({nodes:t,edges:p})=>{if(yr(p||[]),!ue)if(t&&t.length===1){let g=t[0];if(g.type==="tube"&&g.parentId){let N=Fe().find(v=>v.id===g.parentId&&(v.type==="cable"||v.type==="multi-tube-cable"));if(N){po(N),A(v=>v.map(E=>({...E,selected:E.id===N.id}))),c&&c(N);return}}po(g),c&&c(g);}else po(null),c&&c(null);}});let[uo,yr]=nt.useState([]);nt.useEffect(()=>{let t=p=>{if((p.key==="Backspace"||p.key==="Delete")&&uo.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let g=uo.filter(b=>{let N=b.sourceHandle||"",v=b.targetHandle||"";return N.startsWith("tube-")||v.startsWith("tube-")?(s&&console.log("Cannot delete edge connected to tube handle",b),false):true});if(g.length>0){let b=new Set(g.map(N=>N.id));F(N=>N.filter(v=>!b.has(v.id))),yr([]),s&&console.log("Deleted edges:",g.map(N=>N.id));}}};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[uo,F,s]);let En=nt.useCallback((t,{nodeId:p,handleType:g})=>{s&&console.log("Connection started from",{nodeId:p,handleType:g});},[s]),Rn=nt.useCallback(t=>{s&&console.log("Connection ended",t);},[s]),Tn=nt.useCallback(()=>{if(!Te)return;let t=se(Te.id);if(t){if(t.type==="rack"){let b=((t.data||{}).face||"front")==="front"?"rear":"front";u?(u(t.id,b),h&&Fe().filter(v=>v.parentId===t.id).forEach(v=>{h(v.id,b);})):A(N=>N.map(v=>v.id===t.id?{...v,data:{...v.data,face:b}}:v.parentId===t.id?{...v,data:{...v.data,view:b}}:v));return}if(t.type==="device"){let p=t.data||{},g=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,b=Array.isArray(p.ports)&&p.ports.length>0,v=(p.view||(g&&!b?"rear":"front"))==="front"?"rear":"front";h?h(t.id,v):A(E=>E.map(j=>j.id===t.id?{...j,data:{...j.data,view:v}}:j));}}},[Te,se,u,h,A,Fe]),In=nt.useMemo(()=>{let t=lo.current;return T.map(p=>{let g=p,b=t.get(String(g.source)),N=t.get(String(g.target)),v=oo(g.sourceHandle||"",b),E=oo(g.targetHandle||"",N),j=b&&b.data?.view,Y=N&&N.data?.view,ce=b?.type==="device"&&j==="rear",ie=N?.type==="device"&&Y==="rear",J=ce&&v!=="rear"||ie&&E!=="rear"?{...p.style,opacity:0,pointerEvents:"none",zIndex:0}:p.style;return {...p,style:J,className:hr.has(p.id)?"edge-connecting":p.className}})},[T,hr]);return jsxRuntime.jsxs("div",{ref:he,className:`${m||""} ${k==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",touchAction:"none",...f},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:V,edges:In,onNodesChange:t=>{yn(t),X?a&&a(We.current):S.setState({nodes:We.current});},onEdgesChange:t=>{let p=t.filter(g=>{if(g.type==="remove"){let b=K.current.find(N=>N.id===g.id);if(b){let N=b.sourceHandle||"",v=b.targetHandle||"";if(N.startsWith("tube-")||v.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",b),false}}return true});p.length>0&&(be(p),X?i&&i(K.current):S.setState({edges:K.current}));},onConnect:vn,onConnectStart:En,onConnectEnd:Rn,onEdgeUpdate:Hn,isValidConnection:kn,onNodeClick:Sn,onNodeDoubleClick:Pn,onNodeDragStart:xn,onNodeDrag:wn,onNodeDragStop:Nn,onEdgeClick:Cn,onInit:w,nodeTypes:fr.current,edgeTypes:Wi,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:!ue,nodesConnectable:true,elementsSelectable:!ue,edgesFocusable:!ue,selectNodesOnDrag:false,connectOnClick:W,panOnDrag:C,panOnScroll:D&&!ue,zoomOnScroll:$&&!ue,preventScrolling:ue,onlyRenderVisibleElements:true,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:k==="light"?"#e5e5e5":"#2a2a2a"}),jsxRuntime.jsx(reactflow.Controls,{}),!ue&&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"})})]}),M&&jsxRuntime.jsx("button",{className:"download-button",onClick:mn,style:{position:"absolute",top:I.includes("top")?"10px":"auto",bottom:I.includes("bottom")?"10px":"auto",right:I.includes("right")?"10px":"auto",left:I.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:"pointer",transition:"all 0.2s ease",...P},children:z}),Te&&(Te.type==="rack"||Te.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:t=>{t.preventDefault(),Tn();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=Te.data;if(Te.type==="rack")return (t?.face||"front")==="front"?"Switch to rear":"Switch to front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!g?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let t=Te.data;if(Te.type==="rack")return (t?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!g?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},Ai=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(zi,{...e})});var un=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,uHeight:e.u_height??e.units??42,inventoryId:e.id,inventoryType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:typeof e.site=="object"&&e.site?e.site.name:e.site,role:typeof e.role=="object"&&e.role?e.role.name:e.role,tenant:typeof e.tenant=="object"&&e.tenant?e.tenant.name:e.tenant}}),gn=e=>({id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${typeof e.rack=="object"&&e.rack?e.rack.id:e.rack}`:void 0,extent:e.rack?"parent":void 0,data:{label:e.name,status:typeof e.status=="object"&&e.status?e.status.value:e.status,deviceType:e.device_type?.model??e.model,manufacturer:e.device_type?.manufacturer?.name??e.manufacturer,role:typeof e.device_role=="object"&&e.device_role?e.device_role.name:e.role,uHeight:e.device_type?.u_height??e.u_height??1,uPosition:e.position||1,view:e.face||"front",inventoryId:e.id,inventoryType:"device",primaryIp4:typeof e.primary_ip4=="object"&&e.primary_ip4?e.primary_ip4.address:e.primary_ip4,primaryIp6:typeof e.primary_ip6=="object"&&e.primary_ip6?e.primary_ip6.address:e.primary_ip6,site:typeof e.site=="object"&&e.site?e.site.name:e.site,rack:typeof e.rack=="object"&&e.rack?e.rack.name:e.rack}}),fn=e=>{let o=a=>{if(!a)return;if(typeof a=="string")return a;let i=a.device;return typeof i=="object"&&i?i.id:i},r=o(e.termination_a),n=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${r}`,target:`device-${n}`,type:"fiber",data:{bandwidth:e.type?.label??e.bandwidth,length:e.length||0,color:e.color,inventoryId:e.id,inventoryType:"cable",status:typeof e.status=="object"&&e.status?e.status.value:e.status,terminationA:typeof e.termination_a=="object"&&e.termination_a?e.termination_a.name:e.termination_a,terminationB:typeof e.termination_b=="object"&&e.termination_b?e.termination_b.name:e.termination_b}}},Mi=e=>{let o=[],r=[];return e.racks.forEach(n=>o.push(un(n))),e.devices.forEach(n=>o.push(gn(n))),e.cables.forEach(n=>r.push(fn(n))),{nodes:o,edges:r}},Li=e=>{let o=e.filter(a=>a.type==="rack"),r=e.filter(a=>a.type==="device"),n=e.filter(a=>!["rack","device"].includes(a.type));return o.forEach((a,i)=>{a.position={x:i*300,y:100};}),r.forEach(a=>{if(a.parentId){let i=o.find(d=>d.id===a.parentId);if(i){let d=a.data.uPosition||1,s=a.data.uHeight||1;a.position={x:i.position.x+50,y:i.position.y+d*20-s*10};}}else a.position={x:Math.random()*400+100,y:Math.random()*200+50};}),n.forEach((a,i)=>{a.position={x:i*150+100,y:300};}),e};var pt=class extends Error{constructor(r,n,a,i,d){super(`Device placement conflict: ${n} at U${a}-${a+i-1} in rack ${r}${d?` conflicts with ${d}`:""}`);this.rackId=r;this.deviceId=n;this.uPosition=a;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function sr(e,o={}){let r=[],n=[];for(let a of e.devices)a.unit+a.height-1>e.units&&n.push({deviceId:a.id,uPosition:a.unit,uHeight:a.height,rackUHeight:e.units});for(let a=0;a<e.devices.length;a++){let i=e.devices[a],d=i.unit,s=i.unit+i.height-1;for(let c=a+1;c<e.devices.length;c++){let l=e.devices[c],h=l.unit,u=l.unit+l.height-1;d<=u&&s>=h&&r.push({deviceId:i.id,uPosition:i.unit,uHeight:i.height,conflictWith:l.id});}}return {isValid:r.length===0&&n.length===0,conflicts:r,outOfBounds:n}}function bn(e,o,r={}){let{deviceTypeMapping:n={}}=r,a=n[e.type]||"device",i=at(o,e.unit,e.height);return {id:e.id,type:a,position:i,parentId:o.id,extent:"parent",data:{label:e.name,status:"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections,rackWidthPx:o.data.rackWidthPx}}}function Oi(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[],rackWidthPx:e.rackWidthPx}}}function Bi(e,o={}){let{conflictPolicy:r="strict",validatePlacements:n=true}=o,a=[],i=[];if(n)for(let d of e){let s=sr(d,o);if(!s.isValid&&r==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new pt(d.id,s.conflicts[0]?.deviceId||s.outOfBounds[0]?.deviceId||"unknown",s.conflicts[0]?.uPosition||s.outOfBounds[0]?.uPosition||1,s.conflicts[0]?.uHeight||s.outOfBounds[0]?.uHeight||1)}}for(let d of e){let s=Oi(d);a.push(s);for(let c of d.devices)try{let l=bn(c,s,o);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=zt(s,{id:c.id,data:{label:c.name,uHeight:c.height}},i,c.unit);if(h!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${h} due to conflict`);let u={...c,unit:h},m=bn(u,s,o);i.push(m);}else throw new pt(d.id,c.id,c.unit,c.height)}}}return a.push(...i),a}function Ui(e){let o=[],r=e.filter(n=>n.type==="rack");for(let n of r){let i=e.filter(d=>d.type==="device"&&d.parentId===n.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width,ports:d.data.ports,connections:d.data.connections}));o.push({id:n.id,name:n.data.label,position:n.position,units:n.data.uHeight||42,uNumberingDirection:n.data.uNumberingDirection||"bottom-up",customHeaderText:n.data.customHeaderText,devices:i,rackWidthPx:n.data.rackWidthPx});}return o}function Vi(e,o,r,n){return e.map(a=>a.id!==o?a:{...a,devices:a.devices.map(i=>i.id!==r?i:{...i,unit:n})})}function Yi(e,o,r,n={}){let{conflictPolicy:a="strict"}=n;return e.map(i=>{if(i.id!==o)return i;if(a==="strict"&&!sr({...i,devices:[...i.devices,r]},n).isValid)throw new pt(o,r.id,r.unit,r.height);return {...i,devices:[...i.devices,r]}})}function Xi(e,o,r){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.filter(a=>a.id!==r)})}var ut=class extends Error{constructor(r,n,a,i){super(`Splice placement conflict: ${n} at holder ${a} in tray ${r}${i?` conflicts with ${i}`:""}`);this.trayId=r;this.spliceId=n;this.holder=a;this.conflictWith=i;this.name="SplicePlacementError";}};function dr(e,o={}){let r=[],n=[];for(let a of e.splices)(a.holder<1||a.holder>Oe)&&n.push({spliceId:a.id,holder:a.holder,max:Oe});for(let a=0;a<e.splices.length;a++){let i=e.splices[a];for(let d=a+1;d<e.splices.length;d++){let s=e.splices[d];i.holder===s.holder&&r.push({spliceId:i.id,holder:i.holder,conflictWith:s.id});}}return {isValid:r.length===0&&n.length===0,conflicts:r,outOfBounds:n}}function hn(e,o){let r=e.mode==="ribbon",n=kt(o,e.holder,r);return {id:e.id,type:"splice",position:n,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function ji(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Gi(e,o={}){let{conflictPolicy:r="strict",validatePlacements:n=true}=o,a=[],i=[];if(n)for(let d of e){let s=dr(d,o);if(!s.isValid&&r==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new ut(d.id,s.conflicts[0]?.spliceId||s.outOfBounds[0]?.spliceId||"unknown",s.conflicts[0]?.holder||s.outOfBounds[0]?.holder||1)}}for(let d of e){let s=ji(d);a.push(s);for(let c of d.splices)try{let l=hn(c,s);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let h=[...a,...i],u=Vt(s,{id:c.id,data:{label:c.name,holderPosition:c.holder}},h,c.holder);if(u!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${u} due to conflict`);let m={...c,holder:u},f=hn(m,s);i.push(f);}else throw new ut(d.id,c.id,c.holder)}}}return a.push(...i),a}function Zi(e){let o=[],r=e.filter(n=>n.type==="splice-tray");for(let n of r){let i=e.filter(d=>d.type==="splice"&&d.parentId===n.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb,mode:d.data.mode||"single",ribbonFiberIds:d.data.ribbonFiberIds}));o.push({id:n.id,name:n.data.label,position:n.position,splices:i});}return o}function Ki(e,o,r,n){return e.map(a=>a.id!==o?a:{...a,splices:a.splices.map(i=>i.id!==r?i:{...i,holder:n})})}function qi(e,o,r,n={}){let{conflictPolicy:a="strict"}=n;return e.map(i=>{if(i.id!==o)return i;if(a==="strict"&&!dr({...i,splices:[...i.splices,r]},n).isValid)throw new ut(o,r.id,r.holder);return {...i,splices:[...i.splices,r]}})}function Ji(e,o,r){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.filter(a=>a.id!==r)})}
|
|
2
|
+
exports.COUPLERS_PER_PANEL=ci;exports.COUPLER_SLOT_HEIGHT_PX=Jt;exports.COUPLER_WIDTH_PX=li;exports.CableNode=Uo;exports.ClosureNode=er;exports.CouplerNode=Xo;exports.DeviceNode=Ro;exports.DevicePlacementError=pt;exports.FIBER_COLORS_12=kr;exports.FiberEdge=vo;exports.FiberNode=wo;exports.FibreSplitNode=or;exports.MultiTubeCableNode=Yo;exports.NetworkDiagram=Ai;exports.PANEL_BORDER_WIDTH=Yr;exports.PANEL_HEADER_HEIGHT=rt;exports.PANEL_HEIGHT_PX=qt;exports.PANEL_PADDING=ot;exports.PANEL_TUBE_TRAY_SPACING=Xr;exports.PANEL_WIDTH_PX=Kt;exports.POWER_CONNECTORS=Po;exports.PatchPanelNode=qo;exports.PowerEdge=Ho;exports.RackNode=xo;exports.SpliceNode=$o;exports.SplicePlacementError=ut;exports.SpliceTrayNode=Mo;exports.TubeNode=Lo;exports.VerticalPDU=To;exports.Width=$r;exports.addDeviceToRack=Yi;exports.addSpliceToTray=qi;exports.baseColorFor=fe;exports.buildNodesFromRackConfig=Bi;exports.buildNodesFromSpliceConfig=Gi;exports.calculateCouplerRightX=ui;exports.calculateCouplerSlotSpacing=fi;exports.calculateCouplerSpacing=Jr;exports.calculateDevicePositionFromU=at;exports.calculatePanelDimensions=Go;exports.calculateSlotPositionFromY=Kr;exports.calculateSplicePositionFromNumber=ti;exports.calculateYFromSlotPosition=qr;exports.createNetworkDiagramStore=rr;exports.createRackConfigFromNodes=Ui;exports.createSpliceConfigFromNodes=Zi;exports.fiberSolidOrStriped=Ke;exports.findNearestRack=no;exports.findNextAvailableHolderPosition=Vt;exports.findNextAvailableUPosition=zt;exports.generateLayout=Li;exports.getConnectorConfig=Ot;exports.getCouplerDimensions=jo;exports.getDeviceConnectorType=Bt;exports.getFiberColor=ko;exports.getInnerContentWidth=Zr;exports.getPDUPortType=Co;exports.getPanelHeight=pi;exports.getPanelWidth=Gr;exports.getPowerPortStyle=st;exports.getRackBounds=an;exports.getStatusColor=Ee;exports.getTrayDimensions=jr;exports.getTubeDimensions=Qt;exports.inventoryCableToNetworkEdge=fn;exports.inventoryDeviceToNetworkNode=gn;exports.inventoryRackToNetworkNode=un;exports.inventoryToNetworkDiagram=Mi;exports.isHighPowerConnector=Jn;exports.isPointInRack=ro;exports.isStriped=No;exports.isUPositionAvailable=yo;exports.removeDeviceFromRack=Xi;exports.removeSpliceFromTray=Ji;exports.replaceEdge=we;exports.snapToCouplerPosition=gi;exports.snapToSplicePosition=Wo;exports.snapToUPosition=mo;exports.updateDeviceUPosition=wr;exports.updateDeviceUPositionInSchema=Vi;exports.updateSpliceHolderPosition=Ki;exports.useDiagramEdges=ar;exports.useDiagramNodes=ir;exports.useNetworkDiagram=vi;exports.validateAndSnapDevice=$n;exports.validateRackDevicePlacements=sr;exports.validateSplicePlacements=dr;//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|