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