@mp70/react-networks 0.1.9-beta → 0.2.0-beta.1

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