@mp70/react-networks 0.3.0-alpha.1 → 0.3.0-alpha.3

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.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var Je=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Je__default=/*#__PURE__*/_interopDefault(Je);var Ze=20,ht=60,Xr=300,Eo=5;function ri(e){return e==="system"?typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e}function ni(e,t){let r=ri(e)==="light"?"react-flow-light":"react-flow-dark";return t?`${r} ${t}`:r}function ii(e){return ri(e)==="light"?"#e5e5e5":"#2a2a2a"}function ai(e,t){return {width:"100%",height:"100%",...t}}var ns=["device","server","switch","router"],is=new Set(ns);function Ho(e){return typeof e=="string"&&is.has(e)}function Ye(e){return !!e&&Ho(e.type)}var as=24;function ss(e){return e?.rackLayout==="split-face"?"split-face":"single-face"}function De(e){return ss(e)==="split-face"}function Ft(e){return typeof e?.rackFaceGapPx=="number"&&Number.isFinite(e.rackFaceGapPx)&&e.rackFaceGapPx>=0?e.rackFaceGapPx:as}function Et(e){return e?.rackWidthPx||300}function Fo(e){let t=Et(e);return De(e)?t*2+Ft(e):t}function Be(e){return e?.mountMode==="front"||e?.mountMode==="rear"||e?.mountMode==="both"?e.mountMode:"both"}function Ht(e){return e==="front"?["front"]:e==="rear"?["rear"]:["front","rear"]}function Zo(e,t){let o=new Set(Ht(e));return Ht(t).some(n=>o.has(n))}function jr(e,t){return De(e)&&Be(t)==="front"?Et(e)+Ft(e):0}function si(e,t){return De(e)&&Be(t)==="both"?Fo(e):Et(e)}var ds=()=>"bottom-up",Wt=e=>e.data.uNumberingDirection||ds(),qo=(e,t,o)=>o==="bottom-up"?t-e+1:e,Jo=(e,t,o)=>o==="bottom-up"?t-e+1:e;var Qo=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data.uHeight||1,i=t.data.uHeight||42,d=Wt(t),a=60,c=o.y-a,l=Math.round(c/20)+1,b;d==="bottom-up"?b=qo(l,i,d)-n+1:b=qo(l,i,d);let f=i-n+1,u=Math.max(1,Math.min(f,b));if(d==="top-down"&&b<=1&&(u=1),!Yr(t,e,u,r)){let m=er(t,e,r,u);m!==u&&(u=m);}let p;if(d==="bottom-up"){let m=u+n-1,x=Jo(m,i,d);p=a+(x-1)*20-1;}else {let m=Jo(u,i,d);p=a+(m-1)*20-1;}return {x:jr(t.data,e.data),y:p,uPosition:u}},Yr=(e,t,o,r)=>{let n=t.data.uHeight||1,i=e.data.uHeight||42;if(o<1||o+n-1>i)return false;let d=r.filter(l=>Ho(l.type)&&l.parentId===e.id&&l.id!==t.id),a=De(e.data),c=Be(t.data);for(let l of d){let b=l.data.uPosition||1,f=l.data.uHeight||1,u=o,p=o+n-1,m=b,x=b+f-1;if(u<=x&&p>=m){if(a){let P=Be(l.data);if(!Zo(c,P))continue}return false}}return true},er=(e,t,o,r=1)=>{let n=t.data.uHeight||1,i=e.data.uHeight||42;for(let d=r;d<=i-n+1;d++)if(Yr(e,t,d,o))return d;return 1},lo=(e,t,o=1,r)=>{let n=60,i=Wt(e),d=e.data.uHeight||42,a=Jo(t,d,i),c;if(i==="bottom-up"){let l=t+o-1,b=Jo(l,d,i);c=n+(b-1)*20-1;}else c=n+(a-1)*20-1;return {x:jr(e.data,r),y:c}},di=(e,t,o)=>{let r=e.data.uHeight||1,n=lo(t,o,r,e.data),i=Array.isArray(e.data.ports)?e.data.ports:void 0;return {...e,position:n,data:{...e.data,ports:i,uPosition:o}}},cs=(e,t)=>{let o=e.data.uPosition||1,r=e.data.uHeight||1,n=t.data.uHeight||42,i=Math.max(1,Math.min(n-r+1,o));return i!==o?di(e,t,i):e};function dt(e){switch(e){case "active":return "#10b981";case "inactive":return "#ef4444";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var Kr=({data:e,selected:t,id:o,onViewChange:r,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:a=0,status:c="active",uHeight:l=42,face:b="front",customHeaderText:f}=e,u=De(e),p=Fo(e),m=Et(e),x=Ft(e),{getNodes:P,setNodes:N}=reactflow.useReactFlow(),v=P(),[C,H]=Je.useState(e.showUMarkers!==void 0?e.showUMarkers:true),w=()=>{let A=Wt({data:e})==="bottom-up"?"top-down":"bottom-up";N(_=>_.map(U=>U.id===o?{...U,data:{...U.data,uNumberingDirection:A}}:U));},R=()=>{if(u)return;let I=b==="front"?"rear":"front";n?n(o,I):r?v.filter(_=>_.parentId===o).forEach(_=>{r(_.id,I);}):N(A=>A.map(_=>_.id===o?{..._,data:{..._.data,face:I}}:_.parentId===o?{..._,data:{..._.data,view:I}}:_));},D=()=>{let I=[],A=60,_=Wt({data:e});for(let U=1;U<=l;U++){let se=A+(U-1)*20-4,Y=qo(U,l,_);I.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${se}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:Y},U));}return I};return jsxRuntime.jsxs("div",{className:`rack-node ${t?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${dt(c)}`,borderRadius:"8px",padding:0,width:`${p}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxRuntime.jsxs("span",{children:[typeof a=="number"?a:0," ports"]})," \u2022 ",l,"U \u2022 ",u?"rear|front":b]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:I=>{I.stopPropagation();},onMouseDown:I=>{I.stopPropagation();},onClick:I=>{I.stopPropagation(),I.preventDefault(),H(!C);},style:{background:C?"#10b981":"#374151",color:C?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${C?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:I=>{I.stopPropagation();},onMouseDown:I=>{I.stopPropagation();},onClick:I=>{I.stopPropagation(),I.preventDefault(),w();},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 ${Wt({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Wt({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),!u&&jsxRuntime.jsx("button",{onPointerDown:I=>{I.stopPropagation();},onMouseDown:I=>{I.stopPropagation();},onClick:I=>{I.stopPropagation(),I.preventDefault(),R();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${b==="front"?"rear":"front"} view`,children:b==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"},children:u&&jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[jsxRuntime.jsx("div",{style:{width:`${m}px`,borderRight:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.15)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Rear"}),jsxRuntime.jsx("div",{style:{width:`${x}px`}}),jsxRuntime.jsx("div",{style:{width:`${m}px`,borderLeft:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.25)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Front"})]})}),C&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:D()})]})};var Zr=({data:e,selected:t})=>{let{label:o,status:r="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${t?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${dt(r)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:dt(r),borderRadius:"50%"}})]})};var ci=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function Ue(e){let t=(e-1)%12;return ci[t]}function Ut(e){return e>12}function yt(e,t){let o=t?.base??Ue(e),r=t?.striped??Ut(e),n=r?`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`:void 0;return {base:o,striped:r,backgroundImage:n}}function qr(e){let t=yt(e);return t.backgroundImage?{background:t.base,backgroundImage:t.backgroundImage}:{background:t.base}}function Vt(e){return Ue(e)}function wt(e){return e.map(t=>({base:Ue(t),striped:Ut(t)}))}function gs(e,t,o,r,n,i,d,a){let c=wt(o),l=c.length,b=r?1.2:1,f=!!a?.highlight,u=r?2:1.5,p=a?.highlightWidth??u*3,m=a?.highlightColor??c[0]?.base??"#22d3ee";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[f&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:m,strokeWidth:p,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${u}px`,"--rn-edge-highlight-to":`${p}px`}}),c.map((x,P)=>{let v=(l-P)*b;return jsxRuntime.jsx("path",{d:t,stroke:x.base,strokeWidth:v,fill:"none",strokeLinecap:"butt",opacity:x.striped?.9:1,style:n},`${e}-ribbon-${P}`)}),c.some(x=>x.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:r&&a&&(a.bandwidth||a.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${d}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[a.bandwidth&&jsxRuntime.jsx("div",{children:a.bandwidth}),a.length&&jsxRuntime.jsxs("div",{children:[a.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var rr=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},className:b})=>{let[f,u,p]=reactflow.getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),{bandwidth:m,length:x,color:P="#00FFFF",striped:N=false,ribbonFiberIds:v,isRibbon:C,highlight:H,highlightColor:w,highlightWidth:R}=a||{},D=!!H;if((C||v&&v.length>=6&&v.length<=12)&&v)return gs(e,f,v,c??false,l??{},u,p,a);let A=c?3:2,_=R??A*3,U={...l,stroke:P,strokeWidth:A,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[D&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:f,style:{...l,stroke:w??P,strokeWidth:_,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${A}px`,"--rn-edge-highlight-to":`${_}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:f,style:U}),N&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&a&&(m||x)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${u}px,${p}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${P}`,pointerEvents:"none",zIndex:9999},children:[m&&jsxRuntime.jsx("div",{children:m}),x&&jsxRuntime.jsxs("div",{children:[x,"m"]})]})})]})};var Jr=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,style:a={},data:c,markerEnd:l})=>{let[b]=reactflow.getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),f=c?.connectorType||"C13",u=c?.metadata??{},p=typeof c?.powerStrokeWidth=="number"?c.powerStrokeWidth:typeof u.strokeWidth=="number"?u.strokeWidth:void 0,m=typeof c?.powerStrokeDasharray=="string"?c.powerStrokeDasharray:typeof u.strokeDasharray=="string"?u.strokeDasharray:void 0,x=typeof c?.powerOpacity=="number"?c.powerOpacity:typeof u.opacity=="number"?u.opacity:void 0;return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:b,markerEnd:l,style:(()=>{let v=p??(f==="C19"?5:3),C=m??(f==="C19"?"none":"6,3");return {...{stroke:c?.color||"#f59e0b",strokeWidth:v,strokeLinecap:"round",strokeLinejoin:"round",...x!==void 0?{opacity:x}:{}},strokeDasharray:C,...a}})()})};function xs(e,t,o,r,n,i,d,a,c,l,b){let f=wt(a),u=f.length,p=c?1.8:1.5,m=!!b?.highlight,x=c?3:2.5,P=b?.highlightWidth??x*3,N=b?.highlightColor??f[0]?.base??"#22d3ee",[v,C,H]=reactflow.getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[m&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:v,style:{...l,stroke:N,strokeWidth:P,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${x}px`,"--rn-edge-highlight-to":`${P}px`}}),f.map((w,R)=>{let I=(u-R)*p;return jsxRuntime.jsx("path",{d:v,stroke:w.base,strokeWidth:I,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:l},`${e}-ribbon-${R}`)}),f.some(w=>w.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&b&&(b.bandwidth||b.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${C}px,${H}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[b.bandwidth&&jsxRuntime.jsx("div",{children:b.bandwidth}),b.length&&jsxRuntime.jsxs("div",{children:[b.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[a.length,"F"]})]})})]})}var fi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},...b})=>{let{color:f="#00FFFF",ribbonFiberIds:u,isRibbon:p,highlight:m,highlightColor:x,highlightWidth:P}=a||{},N=!!m;if((p||u&&u.length>=6&&u.length<=12)&&u)return xs(e,t,o,r,n,i,d,u,c??false,l??{},a);let C=c?4:3,H=P??C*3,w={...l,stroke:f,strokeWidth:C};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[N&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:reactflow.getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d})[0],style:{...l,stroke:x??f,strokeWidth:H,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${H}px`}}),jsxRuntime.jsx(reactflow.SmoothStepEdge,{...b,id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:w})]})};function ks({sourceX:e,sourceY:t,targetX:o,targetY:r,sourcePosition:n,targetPosition:i}){let d=n===reactflow.Position.Left||n===reactflow.Position.Right,a;if(d){let c=(e+o)/2;a=`M ${e},${t} L ${c},${t} L ${c},${r} L ${o},${r}`;}else {let c=(t+r)/2;a=`M ${e},${t} L ${e},${c} L ${o},${c} L ${o},${r}`;}return a}function Ps(e,t,o,r,n,i){let d=wt(o),a=d.length,c=r?1.2:1,l=!!i?.highlight,b=r?2:1.5,f=i?.highlightWidth??b*3,u=i?.highlightColor??d[0]?.base??"#22d3ee",p=t.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),m=p?(parseFloat(p[1])+parseFloat(p[3]))/2:0,x=p?(parseFloat(p[2])+parseFloat(p[4]))/2:0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:u,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${b}px`,"--rn-edge-highlight-to":`${f}px`}}),d.map((P,N)=>{let C=(a-N)*c;return jsxRuntime.jsx("path",{d:t,stroke:P.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:P.striped?.9:1,style:n},`${e}-ribbon-${N}`)}),d.some(P=>P.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:r&&i&&(i.bandwidth||i.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${x}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${d[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsxRuntime.jsx("div",{children:i.bandwidth}),i.length&&jsxRuntime.jsxs("div",{children:[i.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var mi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},...b})=>{let{color:f="#00FFFF",striped:u=false,ribbonFiberIds:p,isRibbon:m,highlight:x,highlightColor:P,highlightWidth:N}=a||{},v=!!x,C=ks({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d});if((m||p&&p.length>=6&&p.length<=12)&&p)return Ps(e,C,p,c??false,l??{},a);let w=c?3:2,R=N??w*3,D={...l,stroke:f,strokeWidth:w,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[v&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:C,style:{...l,stroke:P??f,strokeWidth:R,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${w}px`,"--rn-edge-highlight-to":`${R}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:C,style:D}),u&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:C,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var wi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,style:a={},data:c,markerEnd:l,selected:b})=>{let{color:f="#6366f1",label:u,highlight:p,highlightColor:m,highlightWidth:x}=c||{},P=!!p,N=8,v=x??N*1.8,[C,H,w]=reactflow.getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),R={...a,stroke:f,strokeWidth:N,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[P&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:C,style:{...a,stroke:m??f,strokeWidth:v,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${m??f}) drop-shadow(0 0 16px ${m??f})`,"--rn-edge-highlight-from":`${N}px`,"--rn-edge-highlight-to":`${v}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:C,markerEnd:l,style:R}),u&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${w}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:u})})]})};var xi=(o=>(o.FULL="full",o.HALF="half",o))(xi||{});var en={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},AC:{type:"AC",color:"#60a5fa",borderColor:"#2563eb",amperage:15,voltage:120,phases:1}};function jt(e){let t=en[e];if(!t)throw new Error(`Unknown connector type: ${e}`);let o=t.amperage===16,r=t.type==="AC",n=o?12:r?10:8*1.3,i=o?10:r?7:5*1.3,d=o||r?{borderRadius:r?"2px":"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:i,color:t.color,borderColor:t.borderColor,fontSize:o?"3px":r?"3.5px":"4px",...d}}function Ni(e){let t=en[e];if(!t)throw new Error(`Unknown connector type: ${e}`);return t}function Ss(e){return Ni(e).amperage===16}function ir(e){return e%10<8?"C13":"C19"}function Ao(e){let t=e.toLowerCase();return t.includes("mx304")||t.includes("mx480")||t.includes("mx960")?"C20":"C14"}var Is=/-(source|target)$/i;function Oe(e){return e?e.replace(Is,""):""}function xt(e){return typeof e=="string"&&e.includes("power")}function Nt(e,t){return typeof t.id=="string"&&t.id.length>0?t.id:xt(t.type)?t.label:`${e}-${t.label}`}function ar(e){let t=Oe(e).toLowerCase();return t.startsWith("pwr")||t.includes("power")}var Hs="#6b7280",Fs="#374151",tn="#10b981",Ds="100% 100%",_s={smf:"#fbbf24",cat6:"#8b5cf6",om3:"#06b6d4",om4:"#8b5cf6",om5:"#84cc16",cat5e:"#3b82f6",cat6a:"#ef4444",cat7:"#f97316",fiber:"#3b82f6",ethernet:"#10b981"},Ms=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,$s=/^data:image\//i,As=typeof window<"u"?Je__default.default.useLayoutEffect:Je__default.default.useEffect;function Ls(e){return (e??"").toLowerCase().replace(/_/g,"-")}function Bs(e){return !Ms.test(e)&&!e.startsWith("//")}function Os(e){if(!e)return;let t=e.trim();if(t){if(Bs(t))return t;try{let o=new URL(t),r=o.protocol.toLowerCase();return r==="https:"||r==="blob:"?o.href:r==="data:"&&$s.test(t)?t:void 0}catch{return}}}function Ws(e){return `url(${JSON.stringify(e)})`}function rn(e){return xt(e.type)}function Pi(e,t){return Nt(e,t)}function zs(e,t,o,r,n){let i=t.length>0||!!r,d=o.length>0||!!n;return e||(i?"front":d?"rear":"front")}function Us(e,t){return t===true||e==="fill"?Ds:e==="none"?"auto":e==="scale-down"?"contain":e??"cover"}function Vs(e){return rn(e)?e.type==="power_c19"?"#fbbf24":"#f59e0b":e.type==="console"||e.type==="mgmt"?"#8b5cf6":e.type==="usb"?tn:e.cableType?_s[e.cableType]??tn:tn}function Gs(e){return e.connected?Vs(e):Hs}function Ci(e){return e.map(t=>{let o=t.ports.map(r=>{let n=r.position?[r.position.side??"",r.position.offsetPercent??"",r.position.offsetPx??"",r.position.xPercent??"",r.position.yPercent??""].join(":"):"";return [r.id??"",r.label,r.type??"",r.connected?"1":"0",r.cableType??"",r.connectorType??"",n].join(":")}).join(",");return `${t.name}[${o}]`}).join("|")}function Xs(e,t,o,r,n=false){return {width:`${e}px`,height:`${t}px`,minWidth:n?`${e}px`:void 0,minHeight:n?`${t}px`:void 0,background:o,border:`0.5px solid ${r}`,borderRadius:"1px",cursor:"pointer",zIndex:2}}function js(e){let t=Math.max(6,Math.min(10,Math.round(e*.025))),o=Math.max(3,Math.min(5,Math.round(t*.55)));return {width:t,height:o}}function on(e){return Math.max(0,Math.min(100,e))}function Pt(e,t,o){return Math.max(t,Math.min(o,e))}function Ys(e){switch(e){case "top":return reactflow.Position.Top;case "right":return reactflow.Position.Right;case "bottom":return reactflow.Position.Bottom;case "left":return reactflow.Position.Left;default:return reactflow.Position.Top}}function Ks(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function Zs(e,t,o,r,n,i){if(!e.position)return;if(typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number"){let m=on(e.position.xPercent),x=on(e.position.yPercent),P=e.position.side??Ks(m,x),N=Pt(r*m/100,t/2,Math.max(t/2,r-t/2)),v=Pt(n*x/100,o/2,Math.max(o/2,n-o/2));return {position:Ys(P),style:{left:`${N-t/2}px`,top:`${v-o/2}px`,right:void 0,bottom:void 0,transform:"none"}}}if(!e.position.side)return;let a=e.position.side,c=typeof e.position.offsetPercent=="number"?on(e.position.offsetPercent):void 0,l=typeof e.position.offsetPx=="number"?e.position.offsetPx:void 0,b=t/2,f=Math.max(b,r-t/2),u=o/2,p=Math.max(u,n-o/2);switch(a){case "top":{let m=l!==void 0?l:r*(c??50)/100,x=Pt(m,b,f);return {position:reactflow.Position.Top,style:{top:"0px",left:`${x}px`,right:void 0,bottom:void 0,transform:"translate(-50%, 50%)"}}}case "bottom":{let m=l!==void 0?l:r*(c??50)/100,x=Pt(m,b,f);return {position:reactflow.Position.Bottom,style:{bottom:"0px",left:`${x}px`,right:void 0,top:void 0,transform:"translate(-50%, -50%)"}}}case "left":{let m=l!==void 0?l:n*(c??50)/100,x=Pt(m,u,p);return {position:reactflow.Position.Left,style:{left:"0px",top:`${x}px`,right:void 0,bottom:void 0,transform:"translate(50%, -50%)"}}}case "right":{let m=l!==void 0?l:n*(c??50)/100,x=Pt(m,u,p);return {position:reactflow.Position.Right,style:{right:"0px",top:`${x}px`,left:void 0,bottom:void 0,transform:"translate(-50%, -50%)"}}}default:return}}function Ti(e,t,o,r){let n=o/2,i=Math.max(n,r-o/2),d=n,a=i;if(t>1){let c=i-n,l=c/(t-1),b=t>=20?2:t>=12?3:void 0;if(b!==void 0){let f=o+b;if(l>f){let u=f*(t-1);if(u<c){let p=(c-u)/2;d=n+p,a=i-p;}}}}return t===1?(d+a)/2:d+e*(a-d)/(t-1)}function Ri(e,t,o,r){let n=e%2===0,i=Math.ceil(t/2),d=Math.floor(t/2),a=Math.max(n?i:d,1),c=Math.floor(n?e/2:(e-1)/2),l=Ti(c,a,o,r);return n?{position:reactflow.Position.Top,style:{transform:"translateY(50%)",left:`${l-o/2}px`}}:{position:reactflow.Position.Bottom,style:{transform:"translateY(-50%)",left:`${l-o/2}px`}}}function vi(e,t,o,r,n,i){let d=e%2===0,a=Math.ceil(t/2),c=Math.floor(t/2),l=Math.max(d?a:c,1),b=Math.floor(d?e/2:(e-1)/2),f=Ti(b,l,o,n),u=1,p=Pt(Math.round(r*.75),1,4),m=Math.max(u,i-r-1),x=Pt(u+r+p,u,m),P=d?u:x;return {position:reactflow.Position.Top,style:{transform:"none",left:`${f-o/2}px`,top:`${P}px`,right:void 0,bottom:void 0}}}function qs(e,t,o,r,n){let i=e.connectorType??(e.type==="power_ac"?"AC":Ao(n)),d=jt(i),a;if(r<=20){let b=Math.max(2,r-d.height-2);a=`${o<=1?(2+b)/2:2+t*(b-2)/(o-1)}px`;}else a=`${25+t*50}%`;return {position:reactflow.Position.Right,style:{transform:"translateX(-50%)",top:a,width:`${d.width}px`,height:`${d.height}px`,background:d.color,border:`1px solid ${d.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:d.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:d.borderRadius,clipPath:d.clipPath}}}function Js(e,t,o,r){if(t===1){let n=Math.max(6,Math.round(r*.04)),i=Math.max(o/2,r-n-o/2);return {position:reactflow.Position.Top,style:{transform:"translateY(50%)",left:`${i}px`,right:void 0}}}return Ri(e,t,o,r)}function Qs(e,t,o,r,n,i,d,a,c){if(a==="patch-panel"||a==="switch")return Ri(t,o,r,i);if(rn(e)){let f=e.connectorType??(e.type==="power_ac"?"AC":Ao(c)),u=jt(f),p;if(d<=20){let P=Math.max(2,d-u.height-2);p=`${o<=1?(2+P)/2:2+t*(P-2)/(o-1)}px`;}else p=`${25+t*50}%`;return {position:reactflow.Position.Left,style:{transform:"translateX(50%)",top:p,width:`${u.width}px`,height:`${u.height}px`,background:u.color,border:`1px solid ${u.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:u.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:u.borderRadius,clipPath:u.clipPath}}}return {position:reactflow.Position.Right,style:{transform:"translate(-50%, -50%)",top:`${Pt(o<=1?d/2:n/2+t*Math.max(d-n,0)/Math.max(o-1,1),n/2,Math.max(n/2,d-n/2))}px`}}}function ed(e,t,o,r){if(e)return {primary:"target"};let n=t==="patch-panel";return t==="switch"||t==="router"?{primary:"source",secondary:"target"}:n?o==="rear"?{primary:"source",secondary:"target"}:{primary:"target",secondary:"source"}:{primary:r?"source":"target"}}var po=({id:e,data:t,selected:o})=>{let r=reactflow.useUpdateNodeInternals(),{label:n,status:i="active",deviceType:d="server",manufacturer:a,uHeight:c=1,width:l="full",ports:b,rearPorts:f,view:u,rackWidthPx:p,frontImageUrl:m,rearImageUrl:x,imageFit:P,imagePosition:N,imageRepeat:v,stretchToFit:C}=t,H=Je__default.default.useMemo(()=>Array.isArray(b)?b:[],[b]),w=Je__default.default.useMemo(()=>Array.isArray(f)?f:[],[f]),R=Ls(d),D=p??300,I=De(t),A=Be(t),_=zs(u,H,w,m,x),U=Je__default.default.useMemo(()=>I?Ht(A):[_],[I,A,_]),se=U[0]??_,Y=I&&A==="both",ee=c*20,ie=Ft(t),z=D+ie,V=Je__default.default.useMemo(()=>[I?"split":"single",A,U.join(","),se,R,n,ee.toString(),D.toString(),z.toString(),Ci(H),Ci(w)].join("|"),[I,A,U,se,R,n,ee,D,z,H,w]);As(()=>{r(e);},[V,e,r]);let B=Je__default.default.useCallback(j=>{let Pe=Os(j==="rear"?x:m);return Pe?{backgroundImage:Ws(Pe),backgroundSize:Us(P,C),backgroundPosition:N??"center",backgroundRepeat:v??"no-repeat"}:{}},[x,m,P,C,N,v]),O=Je__default.default.useMemo(()=>B("front"),[B]),X=Je__default.default.useMemo(()=>B("rear"),[B]),te=se==="rear"?X:O,M,L;if(I)M=`${si(t,t)+4}px`,L=void 0;else {let j=D+4,we=Math.floor(D/2);M=l==="half"?`${we}px`:`${j}px`,L=l==="half"?`${we}px`:void 0;}let de=R==="server"&&c===1,ae=dt(i),ce={"--rn-device-bg-image":Y?"none":String(te.backgroundImage??"none"),"--rn-device-bg-position":String(te.backgroundPosition??"center"),"--rn-device-bg-repeat":String(te.backgroundRepeat??"no-repeat"),"--rn-device-bg-size":String(te.backgroundSize??"cover"),"--rn-device-border-color":ae,"--rn-device-box-shadow":o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)","--rn-device-height":`${ee}px`,"--rn-device-left":L??"auto","--rn-device-status-color":ae,"--rn-device-translate-y":de?"-1px":"0px","--rn-device-width":M},q=Je__default.default.useMemo(()=>{let j=new Set;for(let we of H)for(let Pe of we.ports)j.add(Pi(we.name,Pe));return j},[H]),Ne=Je__default.default.useCallback((j,we)=>we==="rear"&&Y&&q.has(j)?`${j}--rear`:j,[q,Y]),ve=Je__default.default.useCallback((j,we,Pe=0,pt=D)=>{let le=[];if(j.length===0)return le;let{width:qe,height:We}=js(pt),Fr=j.reduce((ge,ze)=>ge+ze.ports.length,0),Ce=(R==="switch"||R==="patch-panel")&&Fr>=24;for(let ge of j)for(let ze=0;ze<ge.ports.length;ze+=1){let Ee=ge.ports[ze],ft=rn(Ee),oo=qe,ro=We;if(ft){let no=Ee.connectorType??(Ee.type==="power_ac"?"AC":Ao(n)),Rt=jt(no);oo=Rt.width,ro=Rt.height;}let gt=Pi(ge.name,Ee),ko=Gs(Ee),Po=Ee.connected?ko:Fs,Co=Xs(oo,ro,ko,Po),it=we==="front"?ft?qs(Ee,ze,ge.ports.length,ee,n):Ce?vi(ze,ge.ports.length,qe,We,pt,ee):Js(ze,ge.ports.length,qe,pt):!ft&&Ce?vi(ze,ge.ports.length,qe,We,pt,ee):Qs(Ee,ze,ge.ports.length,qe,We,pt,ee,R,n),At=Zs(Ee,oo,ro,pt,ee),Lt=At?ft?{position:At.position,style:{...it.style,...At.style}}:At:it,He={...{...Co,...Lt.style}};He.left!==void 0&&Pe!==0&&(typeof He.left=="number"?He.left=`${He.left+Pe}px`:He.left=`calc(${He.left} + ${Pe}px)`),Y&&He.left===void 0&&(Lt.position===reactflow.Position.Left?(He.left=`${Pe}px`,He.right=void 0):Lt.position===reactflow.Position.Right&&(He.left=`${Pe+pt}px`,He.right=void 0));let Bt=Ne(gt,we),bt=ed(ft,R,we,Ee.connected);if(bt.secondary){let no=R==="switch"||R==="router"?{...He,background:"transparent",border:"none",opacity:0}:He,Rt=R==="switch"||R==="router"?`${ge.name} - ${Ee.label} (input) ${Ee.connected?"(connected)":"(disconnected)"}`:`${ge.name} - ${Ee.label} (${bt.secondary}) ${Ee.connected?"(connected)":"(disconnected)"}`;le.push(jsxRuntime.jsx(reactflow.Handle,{id:`${Bt}-${bt.secondary}`,type:bt.secondary,position:Lt.position,style:no,title:Rt},`${Bt}-${bt.secondary}`));}le.push(jsxRuntime.jsx(reactflow.Handle,{id:Bt,type:bt.primary,position:Lt.position,style:He,title:`${ge.name} - ${Ee.label} ${Ee.connected?"(connected)":"(disconnected)"}`,children:ft?ze+1:void 0},Bt));}return le},[ee,D,n,R,Ne,Y]),ke=Je__default.default.useMemo(()=>{let j=[];for(let we of U){if(we==="front"&&H.length>0){let Pe=Y?z:0;j.push(...ve(H,"front",Pe,D));}we==="rear"&&w.length>0&&j.push(...ve(w,"rear",0,D));}return j},[U,H,w,ve,D,Y,z]);return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""} ${Y?"device-node--split-both":""}`,style:ce,children:[Y&&jsxRuntime.jsxs("div",{className:"device-node__split-face-layer",style:{position:"absolute",inset:0,display:"flex",pointerEvents:"none",zIndex:0},children:[jsxRuntime.jsx("div",{className:"device-node__split-face device-node__split-face--rear",style:{width:`${D}px`,backgroundImage:String(X.backgroundImage??"none"),backgroundPosition:String(X.backgroundPosition??"center"),backgroundRepeat:String(X.backgroundRepeat??"no-repeat"),backgroundSize:String(X.backgroundSize??"cover")}}),jsxRuntime.jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${ie}px`},children:jsxRuntime.jsx("div",{className:"device-node__face-bridge-line"})}),jsxRuntime.jsx("div",{className:"device-node__split-face device-node__split-face--front",style:{width:`${D}px`,backgroundImage:String(O.backgroundImage??"none"),backgroundPosition:String(O.backgroundPosition??"center"),backgroundRepeat:String(O.backgroundRepeat??"no-repeat"),backgroundSize:String(O.backgroundSize??"cover")}})]}),jsxRuntime.jsxs("div",{className:"device-node__content",style:{position:"relative",zIndex:1},children:[jsxRuntime.jsx("div",{className:"device-node__label",children:n}),c>1&&jsxRuntime.jsx("div",{className:"device-node__manufacturer",children:a})]}),c>1&&jsxRuntime.jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),jsxRuntime.jsx("div",{className:"device-node__status-indicator"}),ke]})};var et=20,dr=3,nn=2,td=1.2;function an(e){return Math.max(0,Math.min(100,e))}function od(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function cr(e){if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13")return "C13";if(t==="C19")return "C19";if(t==="AC")return "AC"}function rd(e,t){let o=cr(e.connectorType);if(o)return o;let r=String(e.type??"").toLowerCase();return r.includes("c19")?"C19":r.includes("c13")?"C13":r.includes("power_ac")?"AC":t}function nd(e){return Array.isArray(e.pduPortGroups)&&e.pduPortGroups.length>0?e.pduPortGroups:Array.isArray(e.rearPorts)&&e.rearPorts.length>0?e.rearPorts:Array.isArray(e.ports)&&e.ports.length>0?e.ports:[]}function id(e,t){return !Array.isArray(e.portTypes)||e.portTypes.length===0?Array.from({length:t},(o,r)=>cr(ir(r))??"C13"):Array.from({length:t},(o,r)=>{let n=cr(e.portTypes?.[r]);return n||(cr(ir(r))??"C13")})}function ad(e,t){let o=nd(e),r=id(e,t);if(o.length===0)return Array.from({length:t},(d,a)=>({id:`${a+1}`,label:`${a+1}`,connectorType:r[a]??"C13",groupName:"Power"}));let n=[],i=0;return o.forEach(d=>{d.ports.forEach(a=>{let c=r[i]??"C13";n.push({id:Nt(d.name,a),label:a.label,connectorType:rd(a,c),groupName:d.name,position:a.position}),i+=1;});}),n}function sd(e,t){if(e.length===0)return [];let o=Math.max(t-nn-dr,1);if(e.length===1)return [et+nn+o/2];let r=[],n=0;for(let a=0;a<e.length;a+=1)r.push(n),n+=1,a<e.length-1&&e[a].groupName!==e[a+1].groupName&&(n+=td);let i=r[r.length-1]||1,d=i>0?o/i:0;return r.map(a=>et+nn+a*d)}function dd(e,t,o,r,n,i){if(!e)return {position:reactflow.Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let d=e.side,a=d==="left"?reactflow.Position.Left:d==="top"?reactflow.Position.Top:d==="bottom"?reactflow.Position.Bottom:reactflow.Position.Right,c=typeof e.offsetPercent=="number"?an(e.offsetPercent):void 0,l=typeof e.offsetPx=="number"?e.offsetPx:void 0,b=typeof e.xPercent=="number"?an(e.xPercent):void 0,f=typeof e.yPercent=="number"?an(e.yPercent):void 0;if(b!==void 0&&f!==void 0){let m=d??od(b,f),x=m==="left"?reactflow.Position.Left:m==="top"?reactflow.Position.Top:m==="bottom"?reactflow.Position.Bottom:reactflow.Position.Right,P=Math.max(o-dr,1),N=r*b/100,v=et+P*f/100;return {position:x,leftPx:N-n/2,topPx:v-i/2}}let u=b!==void 0?r*b/100:r-n/2-1,p=f!==void 0?et+Math.max(o-dr,1)*f/100:t;return d==="top"||d==="bottom"?(l!==void 0?u=l:c!==void 0&&(u=r*c/100),p=d==="top"?et+i/2:et+o-i/2):(l!==void 0?p=et+l:c!==void 0&&(p=et+Math.max(o-dr,1)*c/100),d==="left"?u=n/2:d==="right"&&(u=r-n/2-1)),{position:a,leftPx:u-n/2,topPx:p-i/2}}function cd(e,t){return !e||t<=0?-1:e==="top"?0:e==="bottom"?t-1:Math.floor(t/2)}function ld(e,t){return jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(t-16)/2}px`,top:`${e-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit")}var sn=({data:e,selected:t})=>{let{label:o,status:r="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:a}=e,c=Math.max(0,i),l=ad(e,c),b=n*4.2,f=Math.max(b-et,1),u=sd(l,f),p=cd(a,l.length);return jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${t?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${dt(r)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${b}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:`${et}px`,display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsxRuntime.jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${b-et}px`,overflow:"hidden"},children:l.map((m,x)=>{let P=u[x]??et+f/2;if(p===x)return ld(P,d);let N=jt(m.connectorType),v=dd(m.position,P,f,d,N.width,N.height);return jsxRuntime.jsx(reactflow.Handle,{type:"source",position:v.position,id:m.id,style:{position:"absolute",left:`${v.leftPx}px`,top:`${v.topPx}px`,width:`${N.width}px`,height:`${N.height}px`,background:N.color,border:`1px solid ${N.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:N.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:N.borderRadius,clipPath:N.clipPath},title:`${m.groupName} - ${m.label} (${m.connectorType})`,children:m.label},`handle-${m.id}`)})})]})};var ln=({data:e,selected:t,id:o})=>{let{lossDb:r,mode:n="single",ribbonFiberIds:i}=e||{},d=reactflow.useEdges(),a=d.find(w=>w.target===o&&w.targetHandle==="left"),c=d.find(w=>w.source===o&&w.sourceHandle==="right"),l=d.find(w=>w.target===o&&w.targetHandle==="right"),b=c||l,f=a?.data?.color||"#555",u=b?.data?.color||"#555",p=n==="ribbon",m=a?.data?.ribbonFiberIds||i,x=b?.data?.ribbonFiberIds||i,P=p&&m?wt(m):null,N=p&&x?wt(x):null,v=!!a&&!!b;return jsxRuntime.jsxs("div",{className:`splice-node ${t?"selected":""}`,style:{width:p?85:69,height:p?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"none"},children:[p&&P&&N?jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:P.map((w,R)=>jsxRuntime.jsx("div",{style:{flex:1,background:w.base,opacity:w.striped?.9:1}},`left-${R}`))}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:N.map((w,R)=>jsxRuntime.jsx("div",{style:{flex:1,background:w.base,opacity:w.striped?.9:1}},`right-${R}`))})]}):jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:f}}),jsxRuntime.jsx("div",{style:{background:u}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),v&&jsxRuntime.jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),v&&typeof r=="number"&&jsxRuntime.jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:p?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsxRuntime.jsx("div",{children:`${r.toFixed(2)} dB`}),p&&i&&jsxRuntime.jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:p&&P?20:12,borderRadius:p&&P?"6px":"50%",border:"none",background:p&&P?`linear-gradient(to bottom, ${P.map(w=>w.base).join(", ")})`:f,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:p&&N?20:12,borderRadius:p&&N?"6px":"50%",border:"none",background:p&&N?`linear-gradient(to bottom, ${N.map(w=>w.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:p&&N?20:12,borderRadius:p&&N?"6px":"50%",border:"none",background:p&&N?`linear-gradient(to bottom, ${N.map(w=>w.base).join(", ")})`:u,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Oo=20,lr=36;var Yt=32,Ei=4,_t=12,pd=69,Kt=80,un=(Kt-pd)/2;var pn=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data?.mode==="ribbon",i=n?lr:Oo,d=n?32:16,a=Yt,c=o.y-a,l=Math.round(c/i)+1,f=Math.max(1,Math.min(_t,l));if(!Bo(t,e,f,r)){let m=Wo(t,e,r,f);if(m!==f){let x=(i-d)/2;return {x:un,y:a+(m-1)*i+x,holderPosition:m}}}let u=(i-d)/2,p=a+(f-1)*i+u;return {x:un,y:p,holderPosition:f}},Bo=(e,t,o,r)=>!r.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==t.id).some(i=>i.data.holderPosition===o),Wo=(e,t,o,r=1)=>{for(let n=r;n<=_t;n++)if(Bo(e,t,n,o))return n;for(let n=r-1;n>=1;n--)if(Bo(e,t,n,o))return n;return 1},fd=(e,t)=>zo(e,t,false),zo=(e,t,o=false)=>{let r=Yt,n=o?lr:Oo,d=(n-(o?32:16))/2,a=r+(t-1)*n+d;return {x:un,y:a}};var bn=({data:e,selected:t})=>{let{label:o="Splice Tray"}=e||{},[r,n]=Je.useState(false),i=()=>{if(!r)return null;let d=[],a=Yt;for(let c=1;c<=_t;c++){let l=a+(c-1)*Oo;d.push(jsxRuntime.jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${Oo}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${Kt}px`,height:`${Yt+_t*lr+Ei}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${Yt}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),jsxRuntime.jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!r);},style:{background:r?"#10b981":"#374151",color:r?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${r?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:Yt,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var mn=({data:e,selected:t,id:o})=>{let{fibersPerTube:r=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=e?.mode==="ribbon"||e?.ribbon===true,a=reactflow.useEdges(),c=`tube-${n}`,l=a.find(Y=>Y.source===o&&Y.sourceHandle===c||Y.target===o&&Y.targetHandle===c),b=l?.data?.color,f=Ue((n-1)%12+1),u=b||f,p=Math.max(1,Math.min(24,Number(r)||12)),m=14,x=4,P=1,N=2,v=20,C=p*m+(p-1)*x,H=Math.max(60,C+P*2+N*2),w=i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,R=w!==reactflow.Position.Bottom,D=R?14:20,I=R?8:20,A=R?`inset ${w===reactflow.Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",_=l?u:R?`linear-gradient(${w===reactflow.Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${u}`:`radial-gradient(circle, ${u} 40%, transparent 70%)`,U={width:D,height:I,borderRadius:R?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:_,backgroundColor:u,border:l?`2px solid ${u}`:`3px dashed ${u}`,cursor:"crosshair","--fiber-bg":u,boxShadow:l?A:`${A}${A!=="none"?", ":""}0 0 8px ${u}`,transition:"opacity 0.2s, box-shadow 0.2s",...w===reactflow.Position.Left?{left:-(D-4)}:w===reactflow.Position.Right?{right:-(D-4)}:{}},se=Je.useMemo(()=>{let Y=[],ee=H-N*2-P*2,ie,z,V=false;i==="left"?(ie=P,z=reactflow.Position.Top):i==="right"?(ie=P+ee-C,z=reactflow.Position.Top,V=true):(ie=P+(ee-C)/2,z=reactflow.Position.Top);for(let B=0;B<p;B++){let O=V?p-B:B+1,X=`fiber-${O}`,te=a.find(ve=>ve.source===o&&ve.sourceHandle===X||ve.target===o&&ve.targetHandle===X),M=!!te&&(te.data?.isRibbon||te.data?.ribbonFiberIds&&Array.isArray(te.data.ribbonFiberIds)),L=te?.data?.color,de=typeof te?.data?.striped=="boolean"?te.data.striped:void 0,ae=yt(O);d||M?ae=yt(O,{base:"#808080",striped:false}):(L||de!==void 0)&&(ae=yt(O,{...L?{base:L}:{},...de!==void 0?{striped:de}:{}}));let ce=ie+B*(m+x),q=P,Ne={position:"absolute",left:`${ce}px`,top:`${q}px`,width:m,height:m,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":ae.base,backgroundColor:ae.base};ae.backgroundImage&&(Ne["--fiber-bg-image"]=ae.backgroundImage),Y.push(jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:Ne,"data-fiber-idx":O,"data-fiber-color":ae.base}),jsxRuntime.jsx(reactflow.Handle,{id:X,type:"source",position:z,className:"tube-fiber-handle",isConnectable:true,style:Ne,"data-fiber-idx":O,"data-fiber-color":ae.base})]},`fiber-${O}`));}return Y},[p,i,H,a,o,m,x,P,N,C,d]);return jsxRuntime.jsxs("div",{style:{width:H,height:v,borderRadius:4,background:"#111827",border:`${N}px solid ${t?"#3b82f6":u}`,position:"relative",boxShadow:t?`0 0 0 ${N}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:P,boxSizing:"border-box",overflow:"visible"},children:[se,jsxRuntime.jsx(reactflow.Handle,{id:c,type:"target",position:w,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":u,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsxRuntime.jsx(reactflow.Handle,{id:c,type:"source",position:w,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":u,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var wn=({data:e,selected:t})=>{let{fiberCount:o,cableId:r="CBL-002",label:n,color:i,rotation:d}=e||{},a=Je__default.default.useRef(null);Je__default.default.useEffect(()=>{if(a.current){let z=typeof d=="number"?d:0;a.current.style.transform=`rotate(${z}deg)`,a.current.style.transformOrigin="center center";}},[d]);let c=Math.max(1,Math.min(24,Number(o)||12)),l=10,b=2,f=6,u=f+l+4,p=60,m=Math.max(120,c*(l+b)+f*2),P=n??`${c}f Cable`,N=r?`Cable ID ${r}`:void 0,v=Ue(1),C=i||v,H=t?"#3b82f6":C,w=typeof d=="number"?d:0,R=z=>{let V=(z%360+360)%360;return V>=315||V<45?reactflow.Position.Top:V>=45&&V<135?reactflow.Position.Right:V>=135&&V<225?reactflow.Position.Bottom:reactflow.Position.Left},D=()=>{let z=[],V=R(w);for(let B=0;B<c;B++){let O=B+1,X=yt(O),te=X.base,M=f+B*(l+b),L=-5,de=X.backgroundImage?X.backgroundImage:te,ae={position:"absolute",left:`${M}px`,top:`${L}px`,width:l,height:l,borderRadius:"50%",border:"none",background:de,backgroundColor:te,zIndex:10,cursor:"pointer","--fiber-bg":te};X.backgroundImage&&(ae["--fiber-bg-image"]=X.backgroundImage);let ce=`fiber-${O}`;z.push(jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:ce,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te}),jsxRuntime.jsx(reactflow.Handle,{id:ce,type:"source",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te})]},`fiber-${O}`));}return z},I="cable-button",A=8,_={width:A,height:A,borderRadius:"50%",background:C,backgroundColor:C,border:`1px solid ${C}`,cursor:"pointer",zIndex:10},U=2,Y=(z=>{let V=(z%360+360)%360;return V>=315||V<45?reactflow.Position.Bottom:V>=45&&V<135?reactflow.Position.Left:V>=135&&V<225?reactflow.Position.Top:reactflow.Position.Right})(w),ee={width:m,height:p,position:"relative",transform:`rotate(${w}deg)`,transformOrigin:"center center","--rotation":`${w}deg`},ie={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${U}px solid ${H}`,boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:f,paddingTop:u,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsxRuntime.jsx("div",{ref:a,style:ee,children:jsxRuntime.jsxs("div",{style:ie,children:[D(),jsxRuntime.jsx(reactflow.Handle,{id:I,type:"source",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxRuntime.jsx(reactflow.Handle,{id:I,type:"target",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:P}),N&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:N})]})]})})};var Nn=({data:e,selected:t})=>{let{tubeCount:o=12,fibersPerTube:r=12,fiberCount:n,cableId:i="CBL-002",label:d,tubeStartIndex:a=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(o)||12)),b=Math.max(1,Number(a)||1),f=14,u=10,p=3,m=6,x=m+u+4,P=60,N=Math.max(120,l*(f+p)+m*2),v=n??l*(Number(r)||12),C=d??`${v}f Cable`,H=i?`Cable ID ${i}`:void 0,w=Ue(b),R=c||w,D=t?"#3b82f6":R,I=()=>{let Y=[];for(let ee=0;ee<l;ee++){let ie=b+ee,z=yt(ie),V=z.base,B=m+ee*(f+p),O=-5,X=z.backgroundImage?z.backgroundImage:V,te={position:"absolute",left:`${B}px`,top:`${O}px`,width:f,height:u,borderRadius:6,border:"none",background:X,backgroundColor:V,zIndex:10,cursor:"pointer","--fiber-bg":V};z.backgroundImage&&(te["--fiber-bg-image"]=z.backgroundImage);let M=`tube-${ie}`;Y.push(jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:M,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V}),jsxRuntime.jsx(reactflow.Handle,{id:M,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V})]},`tube-${ie}`));}return Y},A="cable-button",_=8,U={width:_,height:_,borderRadius:"50%",background:R,backgroundColor:R,border:`1px solid ${R}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:N,height:P,borderRadius:4,background:"#111827",border:`2px solid ${D}`,position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:m,paddingTop:x,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[I(),jsxRuntime.jsx(reactflow.Handle,{id:A,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsxRuntime.jsx(reactflow.Handle,{id:A,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:C}),H&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:H})]})]})};var kn=({data:e,selected:t,id:o})=>{let{connector:r="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:a}=e||{},c=reactflow.useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,b=Math.max(1,Math.min(4,l)),f=9,u=3,p=3,m=60,x=30,P=b*f+(b-1)*u,N=Math.max(x,P+p*2),v=Math.max(m,80),C=(R,D)=>{let I=`${R}-${D+1}`;return c.find(_=>_.source===o&&_.sourceHandle===I||_.target===o&&_.targetHandle===I)?.data?.color||"#555"},H=R=>{let D=[],I=R==="left"?reactflow.Position.Left:reactflow.Position.Right,A=R==="left"?d:a;for(let _=0;_<b;_++){let U=_+1,se=`${R}-${U}`,Y=C(R,_),z=p+(N-P)/2+_*(f+u),V={position:"absolute",left:R==="left"?-5:void 0,right:R==="right"?-5:void 0,top:`${z}px`,width:f,height:f,borderRadius:"50%",border:"none",background:Y,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};D.push(jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:se,type:"target",position:I,isConnectable:true,style:V}),jsxRuntime.jsx(reactflow.Handle,{id:se,type:"source",position:I,isConnectable:true,style:V})]},se)),A&&A[_]&&D.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:R==="left"?-30:void 0,right:R==="right"?-30:void 0,top:`${z}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:R==="left"?"right":"left",width:"25px"},children:A[_]},`${se}-label`));}return D},w=i||`${r}-${b}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${t?"selected":""}`,style:{width:v,height:N,borderRadius:4,border:`2px solid ${t?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:t?"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:`${p}px`,boxSizing:"border-box"},children:[H("left"),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:w})}),H("right")]})};var Jt=32,yr=30,Nd=24,kd=80,mr=400,hr=300,Li=2,qt=8,Bi=120;function Cn(e){let{couplerFiberCount:t}=e.data||{},o=typeof t=="number"&&[1,2,4].includes(t)?t:2,r=Math.max(1,Math.min(4,o)),n=7,i=3,d=3,a=60,c=30,l=r*n+(r-1)*i,b=Math.max(c,l+d*2);return {width:Math.max(a,80),height:b}}function wr(e){let{fibersPerTube:t=12}=e.data||{},o=Math.max(1,Math.min(24,Number(t)||12)),r=14,n=4,i=1,d=2,a=20,c=o*r+(o-1)*n;return {width:Math.max(60,c+i*2+d*2),height:a}}function Oi(e){return {width:Kt,height:0}}function Wi(e){return e.type==="coupler"?Cn(e):e.type==="tube"?wr(e):e.type==="splice-tray"?Oi():{width:80,height:30}}function Pn(e){let t=0;for(let o of e){let r=Wi(o),n=(o.position?.x||0)+r.width;n>t&&(t=n);}return t}function zi(e,t=0){let o=t;for(let r of e){let n=Wi(r),i=(r.position?.y||0)+n.height;i>o&&(o=i);}return o}function Ui(e){return e.data?.panelWidth||mr}function Pd(e){return e.data?.panelHeight||hr}function Vi(e){return Ui(e)-Li*2-qt*2}function Cd(e,t){return Vi(e)-t}function Gi(e,t=yr){return Math.floor(e/t)+1}function Xi(e,t=yr){return (e-1)*t}function vd(e,t,o){let r=yr,n=Gi(o.y,r),i=Xi(n,r);return {x:o.x,y:i,slotPosition:n}}function vn(e,t){if(t.length===0)return {width:e.data?.panelWidth||mr,height:e.data?.panelHeight||hr};let o=t.some(c=>c.type==="tube"),r=t.some(c=>c.type==="splice-tray"),n=t.some(c=>c.type==="coupler"),i;if(o&&r&&n){let c=0,l=0;for(let u of t)if(u.type==="tube"){let p=wr(u);p.width>c&&(c=p.width);}else if(u.type==="coupler"){let p=Cn(u);p.width>l&&(l=p.width);}let b=c+Bi+Kt+l+5,f=0;i=f+b+f;}else i=Pn(t)+4;i=Math.max(e.data?.panelWidth||mr,i);let d=zi(t,Jt),a=Math.max(e.data?.panelHeight||hr,d+qt);return {width:i,height:a}}function ji(e,t,o){if(e===0)return 0;if(e===1)return t;let r=e*t,n=o-r,i=Math.max(5,n/(e-1));return t+i}function Td(e,t,o){return ji(e,t,o)}var Mi=20,$i=400,Ai=300;function Tn(e,t){if(t.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||$i,height:e.data?.closureHeight||e.data?.panelHeight||Ai};let o=t.some(a=>a.type==="tube"),r=t.some(a=>a.type==="splice-tray"),n;if(o&&r){let a=0,c=0,l=0,b=t.filter(u=>u.type==="tube"),f=t.filter(u=>u.type==="splice-tray");if(b.length>0&&f.length>0){let u=f.map(m=>m.position?.x||0),p=u.reduce((m,x)=>m+x,0)/u.length;for(let m of b){let x=wr(m);(m.position?.x||0)<p?x.width>a&&(a=x.width):x.width>c&&(c=x.width);}f.length>0&&(l=Kt),n=qt+a+Mi+l+Mi+c+5;}else n=Pn(t)+qt+5;}else n=Pn(t)+qt+5;n=Math.max(e.data?.closureWidth||e.data?.panelWidth||$i,n);let i=zi(t,Jt),d=Math.max(e.data?.closureHeight||e.data?.panelHeight||Ai,i+qt);return {width:n,height:d}}var In=({data:e,selected:t,id:o})=>{let{label:r="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:a,setNodes:c}=reactflow.useReactFlow(),l=Je.useRef(false),b=Je.useRef([]),f=Je.useMemo(()=>{let C=a().filter(H=>H.parentId===o);return (C.length!==b.current.length||C.some((H,w)=>H.id!==b.current[w]?.id))&&(b.current=C),b.current},[a,o]),u=Je.useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[o,e,i,d]),p=Je.useMemo(()=>i&&d?{width:i,height:d}:f.length===0?{width:i||400,height:d||300}:vn(u,f),[f,u,i,d]);Je.useEffect(()=>{if(i&&d||l.current)return;let v=i,C=d,H=Math.abs((v||0)-p.width),w=Math.abs((C||0)-p.height);(H>1||w>1)&&(l.current=true,c(R=>R.map(D=>D.id===o?{...D,data:{...D.data,panelWidth:p.width,panelHeight:p.height}}:D)),setTimeout(()=>{l.current=false;},0));},[o,p.width,p.height,i,d,c]);let m=p.width,x=p.height,P=Jt,N=n||r;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${m}px`,height:`${x}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${P}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:N})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:P,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Fn=({data:e,selected:t,id:o})=>{let{label:r="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:a,panelHeight:c}=e||{},{getNodes:l,setNodes:b}=reactflow.useReactFlow(),f=Je.useRef(false),u=Je.useRef([]),p=Je.useMemo(()=>{let R=l().filter(D=>D.parentId===o);return (R.length!==u.current.length||R.some((D,I)=>D.id!==u.current[I]?.id))&&(u.current=R),u.current},[l,o]),m=Je.useMemo(()=>({id:o,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||a,closureHeight:d||c}}),[o,e,i,d,a,c]),x=Je.useMemo(()=>i&&d?{width:i,height:d}:a&&c?{width:a,height:c}:p.length===0?{width:i||a||400,height:d||c||300}:Tn(m,p),[p,m,i,d,a,c]);Je.useEffect(()=>{if(i&&d||a&&c||f.current)return;let w=i||a,R=d||c,D=Math.abs((w||0)-x.width),I=Math.abs((R||0)-x.height);(D>1||I>1)&&(f.current=true,b(A=>A.map(_=>_.id===o?{..._,data:{..._.data,closureWidth:x.width,closureHeight:x.height}}:_)),setTimeout(()=>{f.current=false;},0));},[o,x.width,x.height,i,d,a,c,b]);let P=x.width,N=x.height,v=Jt,C=n||r,H=P/2;return jsxRuntime.jsxs("div",{className:`closure-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${H}px ${H}px 12px 12px`,padding:0,width:`${P}px`,height:`${N}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${v}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${H}px ${H}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:C})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:v,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var _n=({data:e,selected:t,id:o})=>{let{label:r,splitterType:n="splitter",inputCount:i=1,outputCount:d=8}=e||{},a=reactflow.useEdges(),c=r||(n==="WDM"?"WDM":"Splitter"),l=9,b=3,f=3,u=50,p=30,m=Math.min(Math.max(i||1,1),2),x=m*l+(m-1)*b,P=Math.min(d||8,48),N=P*l+(P-1)*b,v=Math.max(x,N),C=Math.max(p,v+f*2),H=Math.max(u,50),w=ee=>a.find(z=>z.source===o&&z.sourceHandle===ee||z.target===o&&z.targetHandle===ee)?.data?.color||"#555",R=()=>{let ee=[],ie=f+(C-x)/2;for(let z=0;z<m;z++){let V=`input-${z+1}`,B=ie+z*(l+b),O=w(V),X={position:"absolute",left:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};ee.push(jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:`${V}-target`,type:"target",position:reactflow.Position.Left,isConnectable:true,style:X}),jsxRuntime.jsx(reactflow.Handle,{id:`${V}-source`,type:"source",position:reactflow.Position.Left,isConnectable:true,style:X})]},V));}return ee},D=()=>{let ee=[],ie=f+(C-N)/2;for(let z=0;z<P;z++){let V=`output-${z+1}`,B=ie+z*(l+b),O=w(V),X={position:"absolute",right:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};ee.push(jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:`${V}-target`,type:"target",position:reactflow.Position.Right,isConnectable:true,style:X}),jsxRuntime.jsx(reactflow.Handle,{id:`${V}-source`,type:"source",position:reactflow.Position.Right,isConnectable:true,style:X})]},V));}return ee},I=Math.max(x+f*4,p*.6),A=(C-I)/2,_=A+I,U=0,se=C,Y=t?"#3b82f6":"#4b5563";return jsxRuntime.jsxs("div",{className:`trapezoid-node ${t?"selected":""}`,style:{width:H,height:C,position:"relative",background:"transparent",boxShadow:t?"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:[jsxRuntime.jsx("svg",{width:H,height:C,viewBox:`0 0 ${H} ${C}`,style:{position:"absolute",top:0,left:0,width:`${H}px`,height:`${C}px`,pointerEvents:"none",zIndex:0},children:jsxRuntime.jsx("polygon",{points:`0,${A} 0,${_} ${H},${se} ${H},${U}`,fill:"#1f2937",stroke:Y,strokeWidth:"2"})}),R(),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:c})}),D()]})};var qi=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",kr=(e,t)=>qi(e)||qi(t),re=(e,t)=>t?e?.type==="fibre-split"?Oe(t):Oe(t):t||"";function Pr(e,t){if(!e||!t)return "unknown";let o=Oe(t);if(!o)return "unknown";if(e.type==="vertical-pdu")return "power";let r=e.data??{},n=Array.isArray(r.ports)?r.ports:[],i=Array.isArray(r.rearPorts)?r.rearPorts:[];for(let l of [...n,...i])for(let b of l.ports||[])if(Nt(l.name,{id:b.id,label:b.label,type:xt(b.type)?b.type:void 0})===o)return xt(b.type)?"power":"network";if(ar(o)||/^\d+$/.test(o))return "power";let d=o.toLowerCase(),a=d.startsWith("net-")||d.startsWith("port-")||d.startsWith("uplink-")||d.includes("fiber")||d.includes("ports"),c=/^[A-Z0-9]+-\d+$/i.test(o)&&!d.startsWith("pwr")&&!d.startsWith("power");return a||c?"network":"unknown"}function Qt(e,t){return Pr(e,t)==="power"}function _d(e,t){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=t.nodes.find(M=>M.id===e.source),r=t.nodes.find(M=>M.id===e.target),n=kr(o,r);if(!n){let M=Pr(o,e.sourceHandle),L=Pr(r,e.targetHandle);if(M!=="unknown"&&L!=="unknown"&&M!==L)return {valid:false,reason:`Cannot connect ${M} handle to ${L} handle`};let de=M==="power"&&L==="power",ae=o?.type==="vertical-pdu"||r?.type==="vertical-pdu";if(de&&!ae)return {valid:false,reason:"Power connections must include a PDU endpoint"}}let i=re(o,e.sourceHandle),d=re(r,e.targetHandle),a=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.source===e.source?re(o,M.sourceHandle)===i:M.target===e.source?re(o,M.targetHandle)===i:false),c=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.target===e.target?re(r,M.targetHandle)===d:M.source===e.target?re(r,M.sourceHandle)===d:false);if((a||c)&&!n)return a?{valid:false,reason:`Source handle ${e.sourceHandle} on node ${e.source} is already connected`}:{valid:false,reason:`Target handle ${e.targetHandle} on node ${e.target} is already connected`};let l=(M,L)=>(M?.type==="tube"||M?.type==="cable")&&!!L&&L.startsWith("fiber-"),b=(M,L)=>(M?.type==="tube"||M?.type==="multi-tube-cable")&&!!L&&L.startsWith("tube-"),f=(M,L)=>M?.type==="multi-tube-cable"&&!!L&&L.startsWith("tube-"),u=(M,L)=>M?.type==="tube"&&!!L&&L.startsWith("tube-"),p=(M,L)=>(M?.type==="cable"||M?.type==="multi-tube-cable")&&L==="cable-button",m=(M,L)=>M?.type==="splice"&&(L==="left"||L==="right"),x=(M,L)=>M?.type==="coupler"&&!!L&&(L.startsWith("left-")||L.startsWith("right-")),P=(M,L)=>{if(M?.type!=="fibre-split"||!L)return false;let de=re(M,L);return de.startsWith("input-")||de.startsWith("output-")};if(!n)return {valid:true};if(o?.type==="splice"&&r?.type==="splice"){let M=o.data?.mode==="ribbon",L=r.data?.mode==="ribbon";if(M!==L)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let N=l(o,e.sourceHandle),v=l(r,e.targetHandle),C=m(o,e.sourceHandle),H=m(r,e.targetHandle),w=x(o,e.sourceHandle),R=x(r,e.targetHandle),D=P(o,e.sourceHandle),I=P(r,e.targetHandle),A=p(o,e.sourceHandle),_=p(r,e.targetHandle),U=f(o,e.sourceHandle),se=f(r,e.targetHandle),Y=u(o,e.sourceHandle),ee=u(r,e.targetHandle),ie=b(o,e.sourceHandle),z=b(r,e.targetHandle);return N&&H||v&&C||(C&&(R||I)||H&&(w||D))||(w&&(R||I||H)||R&&(w||D||C))||A&&_||(U&&ee||se&&Y)?{valid:true}:ie&&z?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function Cr(e,t){if(!t)return;let o="--rear",r=Oe(e),n=r.endsWith(o);n&&(r=r.slice(0,-o.length));let i=t.data??{},d=i.handleSideMap;if(d&&d[r])return d[r];if(n)return "rear";if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let a=Array.isArray(i.ports)?i.ports:[],c=Array.isArray(i.rearPorts)?i.rearPorts:[];if(ar(r))return "rear";for(let l of a)for(let b of l.ports||[])if(Nt(l.name,{id:b.id,label:b.label,type:xt(b.type)?b.type:void 0})===r)return "front";for(let l of c)for(let b of l.ports||[])if(Nt(l.name,{id:b.id,label:b.label,type:xt(b.type)?b.type:void 0})===r)return "rear"}function Mn(e={},t={}){let o={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},r=new Set;return {getState:()=>o,setState:f=>{o={...o,...f},r.forEach(u=>u(o));},subscribe:f=>(r.add(f),()=>r.delete(f)),selectEdgeZIndex:f=>{let u=N=>{if(typeof N.parentId=="string")return N.parentId;let v=N.parentNode;if(typeof v=="string")return v},p=N=>{let v=u(N),C=v?o.nodes.find(D=>D.id===v&&D.type==="rack"):void 0;if(C&&De(C.data))return Ht(Be(N.data));let H=Array.isArray(N.data?.rearPorts)&&N.data.rearPorts.length>0,w=Array.isArray(N.data?.ports)&&N.data.ports.length>0;return [N.data?.view||(H&&!w?"rear":"front")]},m=(N,v)=>{let C=o.nodes.find(ee=>ee.id===N);if(!(!!C&&(C.type==="device"||C.type==="server"||C.type==="switch"||C.type==="router"))||!C||C.data?.deviceType?.toLowerCase().replace(/_/g,"-")==="patch-panel")return;let R=p(C),D=Cr(v||"",C);if(D)return R.includes(D)?1e3:500;let I=(v||"").toString().replace(/-(source|target)$/i,""),A=I.toLowerCase(),_=A.startsWith("pwr")||A.startsWith("power"),U=A.startsWith("net-")||A.startsWith("port-")||A.startsWith("uplink-")||A.includes("fiber")||A.includes("ports"),se=/^[A-Z0-9]+-\d+$/i.test(I)&&!A.startsWith("pwr")&&!A.startsWith("power"),Y=U||se;if(_)return R.includes("rear")?1e3:500;if(Y)return R.includes("front")?1e3:500},x=m(f.target,f.targetHandle);if(x!==void 0)return x;let P=m(f.source,f.sourceHandle);return P!==void 0?P:1e3},validateConnection:f=>(t.validateConnection||_d)(f,o),selectNodeById:f=>o.nodes.find(u=>u.id===f),selectConnectedEdges:f=>o.edges.filter(u=>u.source===f||u.target===f)}}function Md(e){let t=n=>e.subscribe(i=>n()),o=()=>e.getState();return Je.useSyncExternalStore(t,o,o)}function An(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return Je.useSyncExternalStore(t,o,o)}function Ln(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return Je.useSyncExternalStore(t,o,o)}function Ji(e){return e.selectEdgeZIndex}function Qi(e){let t=Fo(e.data),o=60+(e.data.uHeight||42)*20,r=e.position.x,n=e.position.x+t,i=e.position.y,d=e.position.y+o;return {left:r,right:n,top:i,bottom:d}}function ea(e,t){let o=Qi(t);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function vr(e,t){let o=null,r=1/0;for(let n of t){if(!ea(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<r&&(r=i,o=n);}return o}function $e(e){let{edges:t,connection:o,edgeType:r,selectEdgeZIndex:n,findBy:i,matchOn:d=i,data:a}=e,c=i==="source"?o.sourceHandle:o.targetHandle,l=i==="source"?o.source:o.target;if(!c||!l)return null;let b=Oe(c),f=t.find(N=>d==="source"?N.source===l&&Oe(N.sourceHandle)===b:N.target===l&&Oe(N.targetHandle)===b);if(!f)return null;let u=t.filter(N=>N.id!==f.id),p=reactflow.addEdge(o,u),m=p[p.length-1],x=n({...o,id:m.id,type:r}),P={...m,type:r,zIndex:x,style:{...m.style,zIndex:x},data:a!==void 0?a:m.data};return [...p.slice(0,-1),P]}function ta(e){return Array.isArray(e)?e.reduce((t,o)=>t+(Array.isArray(o.ports)?o.ports.length:0),0):0}function oa(e){return typeof e=="string"&&e.trim().length>0}function Ad(e){let t=ta(e.ports)>0||oa(e.frontImageUrl),o=ta(e.rearPorts)>0||oa(e.rearImageUrl);if(t&&o)return "both";if(t)return "front";if(o)return "rear"}function ra(e,t,o,r){let n=e.mountMode;if(n==="front"||n==="rear"||n==="both")return n;let i=Ad(e);if(i)return i;if(e.view==="front"||e.view==="rear")return e.view;let d=o+r/2;return t>=d?"front":"rear"}function aa(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var Ve=({type:e,children:t})=>{let o=Je__default.default.useRef(null),r=Je__default.default.useCallback(n=>{if(o.current=n,n){let i=n.parentElement,d=0;for(;i&&!i.classList.contains("react-flow__node")&&d<10;)i=i.parentElement,d++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return Je__default.default.useEffect(()=>{if(o.current){let n=o.current.parentElement,i=0;for(;n&&!n.classList.contains("react-flow__node")&&i<10;)n=n.parentElement,i++;n&&n.classList.contains("react-flow__node")&&n.setAttribute("data-type",e);}},[e]),jsxRuntime.jsx("div",{ref:r,style:{width:"100%",height:"100%"},children:t})},sa=(e,t,o)=>({rack:r=>jsxRuntime.jsx(Ve,{type:"rack",children:jsxRuntime.jsx(Kr,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsxRuntime.jsx(Ve,{type:"fiber",children:jsxRuntime.jsx(Zr,{...r})}),device:r=>jsxRuntime.jsx(Ve,{type:"device",children:jsxRuntime.jsx(po,{...r})}),server:r=>jsxRuntime.jsx(Ve,{type:"server",children:jsxRuntime.jsx(po,{...r})}),switch:r=>jsxRuntime.jsx(Ve,{type:"switch",children:jsxRuntime.jsx(po,{...r})}),router:r=>jsxRuntime.jsx(Ve,{type:"router",children:jsxRuntime.jsx(po,{...r})}),"vertical-pdu":r=>jsxRuntime.jsx(Ve,{type:"vertical-pdu",children:jsxRuntime.jsx(sn,{...r})}),splice:r=>jsxRuntime.jsx(Ve,{type:"splice",children:jsxRuntime.jsx(ln,{...r})}),"splice-tray":r=>jsxRuntime.jsx(Ve,{type:"splice-tray",children:jsxRuntime.jsx(bn,{...r})}),tube:r=>jsxRuntime.jsx(Ve,{type:"tube",children:jsxRuntime.jsx(mn,{...r})}),cable:r=>jsxRuntime.jsx(Ve,{type:"cable",children:jsxRuntime.jsx(wn,{...r})}),"multi-tube-cable":r=>jsxRuntime.jsx(Ve,{type:"multi-tube-cable",children:jsxRuntime.jsx(Nn,{...r})}),coupler:r=>jsxRuntime.jsx(Ve,{type:"coupler",children:jsxRuntime.jsx(kn,{...r})}),"patch-panel":r=>jsxRuntime.jsx(Ve,{type:"patch-panel",children:jsxRuntime.jsx(In,{...r})}),closure:r=>jsxRuntime.jsx(Ve,{type:"closure",children:jsxRuntime.jsx(Fn,{...r})}),"fibre-split":r=>jsxRuntime.jsx(Ve,{type:"fibre-split",children:jsxRuntime.jsx(_n,{...r})})});function da(e){if(!e)return false;if(e.type==="switch")return true;if(e.type!=="device")return false;let t=e.data?.deviceType;return typeof t=="string"&&t.toLowerCase().replace(/_/g,"-")==="switch"}function ca(e,t,o){let r=e.sourceHandle,n=e.targetHandle;return da(t)&&r&&!Qt(t,r)&&(r=Oe(r)),da(o)&&n&&!Qt(o,n)&&(n=`${Oe(n)}-target`),r===e.sourceHandle&&n===e.targetHandle?e:{...e,sourceHandle:r,targetHandle:n}}var Zd={fiber:rr,ethernet:rr,power:Jr,smoothstep:fi,step:mi,"thick-cable":wi},qd=8192,Jd=8192,Qd=2048,ec=4;function Vo(e,t,o){if(!(typeof e!="number"||Number.isNaN(e)))return Math.min(o,Math.max(t,e))}function tc(e){if(e)return {...e,width:Vo(e.width,1,qd),height:Vo(e.height,1,Jd),padding:Vo(e.padding,0,Qd),pixelRatio:Vo(e.pixelRatio,.1,ec),quality:Vo(e.quality,0,1)}}var oc=({nodes:e,edges:t,initialNodes:o,initialEdges:r,onNodesChange:n,onEdgesChange:i,store:d,debug:a,onNodeClick:c,onEdgeClick:l,nodeTypes:b,edgeTypes:f,onConnect:u,onEdgeUpdate:p,isValidConnection:m,connectionMode:x,onViewChange:P,onRackFaceChange:N,className:v,style:C,alignRacksToBottom:H,reAssignable:w=true,colorMode:R="dark",onInit:D,onFlowMethods:I,showDownloadButton:A=false,downloadButtonPosition:_="top-right",downloadButtonText:U="Download Image",downloadButtonStyle:se,useSmoothstepEdgesForTubes:Y=false,readOnly:ee=false,interaction:ie,actionPanel:z,connectOnClick:V=true,panOnDrag:B=true,panOnScroll:O=true,zoomOnScroll:X=true,fitViewOptions:te})=>{let M=Je.useCallback((s,g)=>{let y=new Map,h=[],T=[],E=(F,$)=>!F||!$?false:!!(F.startsWith("tube-")||$.type==="splice"&&(F==="left"||F==="right")||F==="cable-button");for(let F of s){if(!F.source||!F.target||!F.sourceHandle||!F.targetHandle){a&&console.warn("Invalid edge skipped (missing source/target/handles):",F);continue}let $=g.find(Ke=>Ke.id===F.source),S=g.find(Ke=>Ke.id===F.target),K=`${F.source}:${F.sourceHandle}`,oe=y.get(K),Te=E(F.sourceHandle,$),Re=`${F.target}:${F.targetHandle}`,Se=y.get(Re),Xe=E(F.targetHandle,S);if(oe&&!Te){a&&console.warn("Duplicate connection detected on source handle, removing:",{handle:K,existingEdge:oe.id,duplicateEdge:F.id}),T.push(F);continue}if(Se&&!Xe){a&&console.warn("Duplicate connection detected on target handle, removing:",{handle:Re,existingEdge:Se.id,duplicateEdge:F.id}),T.push(F);continue}h.push(F),oe||y.set(K,F),Se||y.set(Re,F);}return a&&T.length>0&&console.log(`Filtered ${T.length} duplicate edge(s) from initial edges`),h},[a]),L=Array.isArray(e)&&Array.isArray(t),de=Je__default.default.useMemo(()=>L?e||[]:o||e||[],[L,e,o]),ae=Je__default.default.useMemo(()=>L?t||[]:r||t||[],[L,t,r]),ce=Je__default.default.useMemo(()=>M(ae,de),[ae,de,M]),q=Je__default.default.useMemo(()=>d||Mn({nodes:de,edges:ce,debug:a}),[d,L,a,ce]),Ne=An(q),ve=Ln(q),[ke,j]=reactflow.useNodesState(Ne),[we,Pe,pt]=reactflow.useEdgesState(ve),le=Ji(q),qe=Je.useRef(null),[We,Fr]=Je.useState(false);Je.useEffect(()=>{let s=()=>{Fr(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[]);let Ce=ee===true,ge=Je.useMemo(()=>{let g={...{nodesDraggable:true,nodesConnectable:true,elementsSelectable:!We,edgesFocusable:!We,edgesReconnectable:true,connectOnClick:V,panOnDrag:B,panOnScroll:O&&!We,zoomOnScroll:X&&!We,zoomOnPinch:!We,zoomOnDoubleClick:!We,allowKeyboardDelete:true,showControls:true,showMiniMap:!We,showInteractiveControl:true},...ie??{}};return Ce?{...g,nodesDraggable:false,nodesConnectable:false,elementsSelectable:false,edgesFocusable:false,edgesReconnectable:false,connectOnClick:false,panOnDrag:false,panOnScroll:false,zoomOnScroll:false,zoomOnPinch:false,zoomOnDoubleClick:false,allowKeyboardDelete:false,showInteractiveControl:false}:g},[We,V,B,O,X,ie,Ce]),ze=Je.useMemo(()=>({enabled:z?.enabled??true,showRearToggle:z?.showRearToggle??true,showDeRack:z?.showDeRack??true}),[z]),{toObject:Ee,setViewport:ft,setNodes:oo,setEdges:ro,getNodes:gt,getEdges:ko,fitView:Po,flowToScreenPosition:Co}=reactflow.useReactFlow();Je.useEffect(()=>{I&&I({toObject:()=>Ee(),setViewport:ft,setNodes:s=>{oo(s),q.setState({nodes:s});},setEdges:s=>{ro(s),q.setState({edges:s});},toImage:s=>qe.current?htmlToImage.toPng(qe.current,tc(s)):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>gt(),getEdges:()=>ko(),fitView:s=>{if(s?.nodes&&Array.isArray(s.nodes)&&s.nodes.length>0){let g=s.nodes.map(T=>gt().find(E=>E.id===T)).filter(T=>T!==void 0),{nodes:y,...h}=s;Po({...h,nodes:g});}else {let{nodes:g,...y}=s||{};Po(y);}}});},[I,Ee,ft,oo,ro,q,Po,gt,ko]);let[it,At]=Je.useState(false),Lt=Je.useCallback(()=>{if(!it){if(!qe.current){a&&console.error("ReactFlow wrapper ref is not available");return}At(true),htmlToImage.toPng(qe.current,{filter:s=>!(s?.classList?.contains("react-flow__minimap")||s?.classList?.contains("react-flow__controls")||s?.classList?.contains("react-flow__attribution")||s?.classList?.contains("download-button")||s?.tagName==="BUTTON"),backgroundColor:R==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(s=>{let g=document.createElement("a");g.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,g.href=s,g.click();}).catch(s=>{a&&console.error("Error downloading image:",s);}).finally(()=>{At(false);});}},[R,a,it]),[Dr,He]=Je.useState(null),Bt=Je.useRef(null),bt=Je.useRef(P),no=Je.useRef(N);Je.useEffect(()=>{bt.current=P;},[P]),Je.useEffect(()=>{no.current=N;},[N]),Je.useEffect(()=>{Bt.current=Dr;},[Dr]);let Rt=Je.useCallback((s,g)=>{bt.current?.(s,g);},[]),_r=Je.useCallback((s,g)=>{no.current?.(s,g);},[]),Mr=Je.useCallback(()=>Bt.current,[]),jn=Je.useRef({...sa(Rt,_r,Mr),...b??{}});Je.useEffect(()=>{jn.current={...sa(Rt,_r,Mr),...b??{}};},[Rt,_r,Mr,b]);let Ba=Je.useMemo(()=>({...Zd,...f??{}}),[f]),at=Je.useRef(ke);Je.useEffect(()=>{at.current=ke;},[ke]);let J=Je.useRef(we);Je.useEffect(()=>{J.current=we;},[we]),Je.useEffect(()=>{j(Ne);},[Ne,j]),Je.useEffect(()=>{Pe(ve);},[ve,Pe]),Je.useEffect(()=>{if(L&&t){let s=M(t,e||[]);s.length!==t.length&&(a&&console.warn(`Controlled edges had ${t.length-s.length} duplicate(s) removed`),i?.(s));}},[L,t,e,M,i,a]),Je.useEffect(()=>{L&&q.setState({nodes:e||[]});},[L,e,q]),Je.useEffect(()=>{L&&q.setState({edges:t||[]});},[L,t,q]),Je.useEffect(()=>{if(!H||!ke||ke.length===0)return;let s=ke.filter(S=>S.type==="rack");if(s.length===0)return;let g=s.map(S=>{let oe=S.data?.uHeight||42,Te=60+oe*20;return (S.position?.y||0)+Te}),y=Math.min(...g),h=Math.max(...g);if(h-y<20)return;let E=h,F=ke.map(S=>{if(S.type!=="rack")return S;let oe=S.data?.uHeight||42,Te=60+oe*20,Re=(S.position?.y||0)+Te,Se=E-Re;return Math.abs(Se)<5?S:{...S,position:{x:S.position?.x||0,y:(S.position?.y||0)+Se}}});F.some((S,K)=>S.position!==ke[K].position)&&j(F);},[H,ke,j]);let vo=Je.useRef(new Map);Je.useEffect(()=>{let s=new Map;ke.forEach(g=>{s.set(g.id,g);}),vo.current=s;},[ke]);let ue=Je.useCallback(s=>vo.current.get(s),[]),Ge=Je.useCallback(s=>{if(!s)return;if(typeof s.parentId=="string")return s.parentId;let g=s.parentNode;if(typeof g=="string")return g},[]),Yn=Je.useCallback(s=>{let g=Ge(s);if(!g)return;let y=ue(g);if(!(!y||y.type!=="rack"))return y},[ue,Ge]),Kn=Je.useCallback(s=>!s||s.type!=="rack"?false:De(s.data),[]),io=Je.useCallback(s=>{if(!s||!Ye(s))return false;let g=Yn(s);return g?De(g.data):false},[Yn]),$r=Je.useCallback(s=>{if(!s||s.type!=="device")return false;let g=s.data?.deviceType;return typeof g=="string"&&g.toLowerCase().replace(/_/g,"-")==="patch-panel"},[]),jo=Je.useCallback(s=>{at.current=s;let g=new Map;s.forEach(y=>{g.set(y.id,y);}),vo.current=g,j(s),L?n?.(s):q.setState({nodes:s});},[L,q,j,n]),ye=Je.useCallback(s=>{J.current=s,Pe(s),L?i?.(s):q.setState({edges:s});},[L,q,Pe,i]),St=Je.useCallback(s=>{if(s.positionAbsolute)return s.positionAbsolute;let g=s.position?.x||0,y=s.position?.y||0,h=Ge(s),T=new Set;for(;h&&!T.has(h);){T.add(h);let E=ue(h);if(!E)break;if(E.positionAbsolute){g+=E.positionAbsolute.x,y+=E.positionAbsolute.y;break}g+=E.position?.x||0,y+=E.position?.y||0,h=Ge(E);}return {x:g,y}},[ue,Ge]),Yo=Je.useCallback(s=>{let g=St(s),y=s.width||0,h=s.height||0;return {x:g.x+y/2,y:g.y+h/2}},[St]),To=Je.useCallback((s,g)=>{if(!s||!g)return;let y=ue(s);if(!y)return;let h=g.replace(/-(source|target)$/i,"");if(y.type==="fibre-split"&&h.startsWith("output-")){let E=J.current.filter(F=>F.target===s&&(F.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(E.length>0){let F=E[0]?.data?.color;if(F)return {color:F}}}if((y.type==="tube"||y.type==="cable")&&g.startsWith("fiber-")){let E=g.replace("fiber-",""),F=parseInt(E,10);if(F>=1&&F<=24){let $=Vt(F),S=F>12;return {color:$,striped:S}}}if((y.type==="multi-tube-cable"||y.type==="tube")&&g.startsWith("tube-")){let E=g.replace("tube-",""),F=parseInt(E,10);if(F>=1&&F<=24){let $=Ue(F),S=F>12;return {color:$,striped:S}}}let T=y.data;if(T.color)return {color:T.color}},[ue]),Zn=Je.useRef(new Map);Je.useEffect(()=>{Pe(s=>{let g=false,y=s.map(h=>{let T=le(h);return Zn.current.get(h.id)!==T?(g=true,Zn.current.set(h.id,T),{...h,zIndex:T,style:{...h.style,zIndex:T}}):h});return g?y:s});},[ke,Pe,le]),Je.useEffect(()=>{let s=ke.map(y=>{if(y.type==="coupler"&&y.parentId){let h=ue(y.parentId);if(h&&(h.type==="patch-panel"||h.type==="closure")&&(!y.extent||y.extent!=="parent"))return {...y,extent:"parent"}}if(y.type==="splice"&&y.parentId&&y.data.holderPosition&&(!y.position||y.position.x===0&&y.position.y===0)){let h=ue(y.parentId);if(h&&h.type==="splice-tray"){let T=y.data.mode==="ribbon",E=zo(h,y.data.holderPosition,T);return {...y,position:E}}}if(Ye(y)&&y.parentId&&y.data.uPosition&&(!y.position||y.position.x===0&&y.position.y===0)){let h=ue(y.parentId);if(h){let T=y.data.uHeight||1,E=lo(h,y.data.uPosition,T,y.data);return {...y,position:E}}}return y});s.some((y,h)=>{let T=ke[h];return y.extent!==T.extent||y.position?.x!==T.position?.x||y.position?.y!==T.position?.y})&&j(s);},[ke,j,ue]);let Oa=Je.useCallback(s=>{if(Ce)return null;let g=new Map,y=new Map,h=new Set,T=s.map($=>{if($.type==="position"&&$.position){let S=ue($.id);if(S&&S.type==="coupler"&&S.parentId){let K=ue(S.parentId);if(K&&(K.type==="patch-panel"||K.type==="closure"))return (!S.extent||S.extent!=="parent")&&h.add(S.id),{...$,position:S.position||{x:0,y:0}}}if(S&&(S.type==="tube"||S.type==="splice-tray")&&S.parentId){let K=ue(S.parentId);if(K&&K.type==="closure")return (!S.extent||S.extent!=="parent")&&h.add(S.id),{...$,position:S.position||{x:0,y:0}}}if(S&&S.type==="splice"&&S.parentId){let K=ue(S.parentId);if(K&&K.type==="splice-tray"){let oe=pn(S,K,$.position,at.current);return oe.holderPosition!==void 0&&g.set(S.id,oe.holderPosition),{...$,position:{x:oe.x,y:oe.y}}}}if(S&&Ye(S)&&S.parentId){let K=ue(S.parentId);if(K&&K.type==="rack"){let oe=Qo(S,K,$.position,at.current);return oe.uPosition!==void 0&&y.set(S.id,oe.uPosition),{...$,position:{x:oe.x,y:oe.y}}}}}return $}),E=reactflow.applyNodeChanges(T,at.current).map($=>{let S=$;h.has($.id)&&(S={...S,extent:"parent"});let K=g.get($.id);K!==void 0&&(S={...S,data:{...S.data,holderPosition:K}});let oe=y.get($.id);return oe!==void 0&&(S={...S,data:{...S.data,uPosition:oe}}),S});at.current=E;let F=new Map;return E.forEach($=>{F.set($.id,$);}),vo.current=F,j(E),E},[j,ue,Ce]),Wa=Je.useCallback((s,g)=>{He(null);},[]),za=Je.useCallback((s,g,y)=>{let h=Ge(g);if(!w||!Ye(g)||h){He(null);return}let T=at.current.filter(S=>S.type==="rack").map(S=>S),E=Yo(g),$=vr(E,T)?.id??null;He(S=>S===$?S:$);},[w,Yo,Ge]),Ua=Je.useCallback((s,g,y)=>{He(null);let h=Ge(g);if(!w||!Ye(g)||h)return;let T=St(g),E=at.current.filter(W=>W.type==="rack").map(W=>W),F=Yo(g),$=vr(F,E),S=at.current;if(!$)return;let K={x:T.x-$.position.x,y:T.y-$.position.y},oe=S.find(W=>W.id===g.id)||g,Te=De($.data),Re=Et($.data),Se=Ft($.data),Xe=Te?ra(oe.data,K.x,Re,Se):"both",Ke=Te&&Xe==="front"?Re+Se:0,_e=Xe==="rear"?"rear":Xe==="front"?"front":oe.data.view==="front"||oe.data.view==="rear"?oe.data.view:void 0,je={...oe,parentId:$.id,extent:"parent",position:{x:Ke,y:K.y},data:{...oe.data,rackLayout:Te?"split-face":"single-face",rackWidthPx:Re,rackFaceGapPx:Se,mountMode:Xe,view:_e}},Le=S.filter(W=>W.id!==g.id).concat(je),xe=Qo(je,$,je.position,Le),Qe=S.map(W=>W.id!==g.id?W:{...W,parentId:$.id,extent:"parent",position:{x:xe.x,y:xe.y},data:{...W.data,rackLayout:Te?"split-face":"single-face",rackWidthPx:Re,rackFaceGapPx:Se,mountMode:Xe,view:_e,uPosition:xe.uPosition??W.data.uPosition}});jo(Qe);},[w,St,Yo,jo,Ge]),Va=Je.useCallback(s=>{if(!s.source||!s.target||!s.sourceHandle||!s.targetHandle)return true;let g=ue(s.source),y=ue(s.target),h=re(g,s.sourceHandle),T=re(y,s.targetHandle),E=J.current.some(Z=>Z.source===s.source?re(g,Z.sourceHandle)===h:Z.target===s.source?re(g,Z.targetHandle)===h:false),F=J.current.some(Z=>Z.target===s.target?re(y,Z.targetHandle)===T:Z.source===s.target?re(y,Z.sourceHandle)===T:false);if(E&&a&&console.log("Connection will replace: Source handle already connected",{source:s.source,sourceHandle:s.sourceHandle,existingEdges:J.current.filter(Z=>Z.source===s.source&&Z.sourceHandle===s.sourceHandle||Z.target===s.source&&Z.targetHandle===s.sourceHandle)}),F&&a&&console.log("Connection will replace: Target handle already connected",{target:s.target,targetHandle:s.targetHandle,existingEdges:J.current.filter(Z=>Z.target===s.target&&Z.targetHandle===s.targetHandle||Z.source===s.target&&Z.sourceHandle===s.targetHandle)}),!kr(g,y))return true;if(g?.type==="splice"&&y?.type==="splice"){let Z=g.data?.mode==="ribbon",be=y.data?.mode==="ribbon";if(Z!==be)return a&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",s),false}let S=(Z,be)=>(Z?.type==="tube"||Z?.type==="cable")&&!!be&&be.startsWith("fiber-"),K=(Z,be)=>(Z?.type==="tube"||Z?.type==="multi-tube-cable")&&!!be&&be.startsWith("tube-"),oe=(Z,be)=>Z?.type==="multi-tube-cable"&&!!be&&be.startsWith("tube-"),Te=(Z,be)=>Z?.type==="tube"&&!!be&&be.startsWith("tube-"),Re=(Z,be)=>(Z?.type==="cable"||Z?.type==="multi-tube-cable")&&be==="cable-button",Se=(Z,be)=>Z?.type==="splice"&&(be==="left"||be==="right"),Xe=(Z,be)=>Z?.type==="coupler"&&!!be&&(be.startsWith("left-")||be.startsWith("right-")),Ke=(Z,be)=>{if(Z?.type!=="fibre-split"||!be)return false;let k=be.replace(/-(source|target)$/i,"");return k.startsWith("input-")||k.startsWith("output-")},_e=S(g,s.sourceHandle),je=S(y,s.targetHandle),Le=Se(g,s.sourceHandle),xe=Se(y,s.targetHandle),Qe=Xe(g,s.sourceHandle),W=Xe(y,s.targetHandle),Ie=Ke(g,s.sourceHandle),ne=Ke(y,s.targetHandle),So=Re(g,s.sourceHandle),Or=Re(y,s.targetHandle),so=oe(g,s.sourceHandle),co=oe(y,s.targetHandle),Wr=Te(g,s.sourceHandle),zr=Te(y,s.targetHandle),Ko=K(g,s.sourceHandle),Ur=K(y,s.targetHandle);return _e&&xe||je&&Le||(Le&&(W||ne)||xe&&(Qe||Ie))||(Qe&&(W||ne||xe)||W&&(Qe||Ie||Le))||So&&Or||(so&&zr||co&&Wr)?true:Ko&&Ur?(a&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",s),false):(a&&console.log("Connection rejected: Connection not allowed by fiber rules",s),false)},[ue,a]),Ga=Je.useCallback(s=>{if(Ce)return;a&&console.log("onConnect called:",s);let g=ue(s.source),y=ue(s.target);a&&(console.log("onConnect: sourceNode type:",g?.type,"targetNode type:",y?.type),console.log("onConnect: sourceHandle:",s.sourceHandle,"targetHandle:",s.targetHandle));let h=ca(s,g,y),T=q.validateConnection({source:h.source??null,target:h.target??null,sourceHandle:h.sourceHandle,targetHandle:h.targetHandle});if(!T.valid&&!(T.reason??"").includes("already connected")){a&&console.warn(`Connection rejected: ${T.reason}`);return}let E=g?.type==="vertical-pdu",F=g?.type==="vertical-pdu"||y?.type==="vertical-pdu",$=Qt(g,h.sourceHandle),S=Qt(y,h.targetHandle),K=$&&S&&F,oe=g?.data,Te=g?.type==="switch"||g?.type==="device"&&oe?.deviceType==="switch",Re=S,Se=!!h.targetHandle&&(h.targetHandle.startsWith("net-")||h.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Oe(h.targetHandle))),Xe=!!h.sourceHandle&&(h.sourceHandle.startsWith("net-")||h.sourceHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Oe(h.sourceHandle))),Ke=y?.type==="switch"||y?.type==="device"&&y.data?.deviceType==="switch",_e=y?.type==="vertical-pdu",je=$,Le=g?.type==="tube"&&y?.type==="multi-tube-cable",xe=g?.type==="multi-tube-cable"&&y?.type==="tube",Qe=Le||xe,W=h.sourceHandle==="cable-button"&&h.targetHandle==="cable-button",Ie="fiber";K?Ie="power":W?Ie="thick-cable":Qe&&(Ie=Y?"smoothstep":"fiber");let ne,So=aa(y),Or=aa(g);if(So||Or){let k=y?.data,G=g?.data,he=So?k.ribbonFiberIds:G.ribbonFiberIds;he&&Array.isArray(he)&&he.length>=6&&he.length<=12&&(ne={ribbonFiberIds:he,isRibbon:true});}if(!ne&&(Ie==="fiber"||Ie==="smoothstep")&&!E){let k;Le?k=To(h.target,h.targetHandle):k=To(h.source,h.sourceHandle),k&&(ne={color:k.color,striped:k.striped,isRibbon:false});}else if(Ie==="thick-cable"&&W){let k=g?.data;ne={color:k?.color||(k?.tubeStartIndex?Ue(k.tubeStartIndex):"#6366f1")};}let so=re(g,h.sourceHandle),co=re(y,h.targetHandle),Wr=J.current.some(k=>k.source===h.source?re(g,k.sourceHandle)===so:k.target===h.source?re(g,k.targetHandle)===so:false),zr=J.current.some(k=>k.target===h.target?re(y,k.targetHandle)===co:k.source===h.target?re(y,k.sourceHandle)===co:false);if(Wr||zr){let k=new Set;for(let G of J.current){if(G.source===h.source&&re(g,G.sourceHandle)===so){k.add(G.id);continue}if(G.target===h.source&&re(g,G.targetHandle)===so){k.add(G.id);continue}if(G.source===h.target&&re(y,G.sourceHandle)===co){k.add(G.id);continue}G.target===h.target&&re(y,G.targetHandle)===co&&k.add(G.id);}if(k.size>0){let G=J.current.filter(st=>!k.has(st.id)),he=reactflow.addEdge(h,G);if(he.length===G.length)a&&console.warn("Handle replacement skipped: addEdge did not create a new edge",h);else {let st=he[he.length-1],It=le({...h,id:st.id,type:Ie}),Ot={...st,type:Ie,zIndex:It,style:{...st.style,zIndex:It},data:ne!==void 0?ne:st.data};ye([...he.slice(0,-1),Ot]),a&&console.log("Handle replacement: Replaced",k.size,"edge(s)");return}}}if(y?.type==="splice"&&(s.targetHandle==="left"||s.targetHandle==="right")&&s.target&&s.targetHandle){let k=J.current.find(G=>G.target===s.target&&G.targetHandle===s.targetHandle||G.source===s.target&&G.sourceHandle===s.targetHandle);if(k){a&&(console.log("Splice target handle replacement: Found existing edge",k.id,"on splice handle",s.targetHandle),console.log("Existing edge details:",{id:k.id,source:k.source,target:k.target,sourceHandle:k.sourceHandle,targetHandle:k.targetHandle,data:k.data}));let G=s.source&&s.sourceHandle?J.current.find(mt=>mt.source===s.source&&mt.sourceHandle===s.sourceHandle):null;a&&G&&console.log("Splice target handle replacement: Also found existing source edge",G.id);let he=new Set;k&&he.add(k.id),G&&G.id!==k.id&&he.add(G.id);let st=J.current.filter(mt=>!he.has(mt.id));a&&console.log("Splice target handle replacement: Removing",he.size,"edge(s), creating new connection");let It=`edge-${s.source}-${s.sourceHandle}-${s.target}-${s.targetHandle}-${Date.now()}`,Ot=le({...s,id:It,type:"fiber"}),Io={id:It,source:s.source,target:s.target,sourceHandle:s.sourceHandle,targetHandle:s.targetHandle,type:"fiber",zIndex:Ot,style:{zIndex:Ot},data:ne!==void 0?ne:{}},Gr=[...st,Io];ye(Gr),a&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Io.id);return}}if(g?.type==="splice"&&s.sourceHandle==="right"&&s.source&&s.sourceHandle){let k=J.current.find(G=>G.source===s.source&&G.sourceHandle===s.sourceHandle||G.target===s.source&&G.targetHandle===s.sourceHandle);if(k){a&&console.log("Splice source handle replacement: Found existing edge",k.id,"on splice handle",s.sourceHandle);let G=s.target&&s.targetHandle?J.current.find(mt=>mt.target===s.target&&mt.targetHandle===s.targetHandle):null;a&&G&&console.log("Splice source handle replacement: Also found existing target edge",G.id);let he=new Set;k&&he.add(k.id),G&&G.id!==k.id&&he.add(G.id);let st=J.current.filter(mt=>!he.has(mt.id));a&&console.log("Splice source handle replacement: Removing",he.size,"edge(s), creating new connection");let It=`edge-${s.source}-${s.sourceHandle}-${s.target}-${s.targetHandle}-${Date.now()}`,Ot=le({...s,id:It,type:"fiber"}),Io={id:It,source:s.source,target:s.target,sourceHandle:s.sourceHandle,targetHandle:s.targetHandle,type:"fiber",zIndex:Ot,style:{zIndex:Ot},data:ne!==void 0?ne:{}},Gr=[...st,Io];ye(Gr),a&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Io.id);return}}if((g?.type==="tube"||g?.type==="cable")&&s.sourceHandle?.startsWith("fiber-")&&s.source&&s.sourceHandle){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(k){ye(k);return}}if((y?.type==="tube"||y?.type==="cable")&&s.targetHandle?.startsWith("fiber-")&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(k){ye(k);return}}if((g?.type==="multi-tube-cable"||g?.type==="tube")&&s.sourceHandle?.startsWith("tube-")&&s.source&&s.sourceHandle){let k=$e({edges:J.current,connection:h,edgeType:Ie,selectEdgeZIndex:le,findBy:"source",data:ne});if(k){ye(k);return}}if((y?.type==="multi-tube-cable"||y?.type==="tube")&&s.targetHandle?.startsWith("tube-")&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:Ie,selectEdgeZIndex:le,findBy:"target",data:ne});if(k){ye(k);return}}if(g?.type==="coupler"&&(s.sourceHandle?.startsWith("left-")||s.sourceHandle?.startsWith("right-"))){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(k){ye(k);return}}if(y?.type==="coupler"&&(s.targetHandle?.startsWith("left-")||s.targetHandle?.startsWith("right-"))){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(k){ye(k);return}}if(W&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let k=g?.data,G=k?.color||(k?.tubeStartIndex?Ue(k.tubeStartIndex):"#6366f1"),he=$e({edges:J.current,connection:h,edgeType:"thick-cable",selectEdgeZIndex:le,findBy:"source",data:{color:G}});if(he){ye(he);return}if(he=$e({edges:J.current,connection:h,edgeType:"thick-cable",selectEdgeZIndex:le,findBy:"target",data:{color:G}}),he){ye(he);return}}if(E&&Re&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:le,findBy:"target",data:ne});if(k){ye(k);return}}if(_e&&je&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:le,findBy:"source",matchOn:"target",data:ne});if(k){ye(k);return}}if(Te&&Se&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(k){ye(k);return}}if(Ke&&Xe&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",matchOn:"source",data:ne});if(k){ye(k);return}}let Ko=q.validateConnection({source:h.source??null,target:h.target??null,sourceHandle:h.sourceHandle,targetHandle:h.targetHandle});if(!Ko.valid){if(E&&s.source&&s.sourceHandle){let k=$e({edges:J.current,connection:h,edgeType:Re?"power":"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(k){ye(k);return}}if(_e&&s.source&&s.sourceHandle){let k=$e({edges:J.current,connection:h,edgeType:"power",selectEdgeZIndex:le,findBy:"source",matchOn:"target",data:ne});if(k){ye(k);return}}if(Te&&s.source&&s.sourceHandle){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(k){ye(k);return}}if(Ke&&s.target&&s.targetHandle){let k=$e({edges:J.current,connection:h,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",matchOn:"source",data:ne});if(k){ye(k);return}}a&&console.warn(`Connection rejected: ${Ko.reason}`);return}let Ur=J.current.some(k=>k.source===h.source&&k.sourceHandle===h.sourceHandle||k.target===h.source&&k.targetHandle===h.sourceHandle),Qn=J.current.some(k=>k.target===h.target&&k.targetHandle===h.targetHandle||k.source===h.target&&k.sourceHandle===h.targetHandle),Vr=(k,G)=>!k||!G?false:!!(k.startsWith("tube-")||G.type==="splice"&&(k==="left"||k==="right")||k==="cable-button"),ei=Vr(h.sourceHandle||"",g),ti=Vr(h.targetHandle||"",y);if(Ur&&!ei){a&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:s.source,sourceHandle:h.sourceHandle,existingEdges:J.current.filter(k=>k.source===h.source&&k.sourceHandle===h.sourceHandle||k.target===h.source&&k.targetHandle===h.sourceHandle)});return}if(Qn&&!ti){a&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:h.target,targetHandle:h.targetHandle,existingEdges:J.current.filter(k=>k.target===h.target&&k.targetHandle===h.targetHandle||k.source===h.target&&k.sourceHandle===h.targetHandle)});return}let oi={...h,type:Ie,zIndex:le({...h,id:"temp-id"}),data:ne},Z=reactflow.addEdge(oi,J.current),be=Z[Z.length-1];be&&(Jn(k=>new Set(k).add(be.id)),setTimeout(()=>{Jn(k=>{let G=new Set(k);return G.delete(be.id),G});},1e3)),ye(Z);},[ye,q,le,ue,a,To,Y,Ce]),Xa=Je.useCallback((s,g)=>{if(Ce||!g.source||!g.target||!g.sourceHandle||!g.targetHandle)return;let y=ue(g.source),h=ue(g.target),T=ca(g,y,h),E=re(y,T.sourceHandle),F=re(h,T.targetHandle),$=J.current.some(W=>{if(W.id===s.id)return false;let Ie=W.source===T.source&&re(y,W.sourceHandle)===E||W.target===T.source&&re(y,W.targetHandle)===E,ne=W.target===T.target&&re(h,W.targetHandle)===F||W.source===T.target&&re(h,W.sourceHandle)===F;return Ie||ne}),S=q.validateConnection({source:T.source??null,target:T.target??null,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,ignoreEdgeId:s.id});if(!S.valid&&!((S.reason??"").includes("already connected")&&$)){a&&console.warn(`Edge update rejected: ${S.reason}`);return}let K=y?.type==="vertical-pdu"||h?.type==="vertical-pdu",oe=Qt(y,T.sourceHandle),Te=Qt(h,T.targetHandle),Re=oe&&Te&&K,Se=y?.type==="tube"&&h?.type==="multi-tube-cable",Xe=y?.type==="multi-tube-cable"&&h?.type==="tube",Ke=Se||Xe,_e;Re?_e="power":Ke?_e=Y?"smoothstep":"fiber":_e="fiber";let je;if(_e==="fiber"||_e==="smoothstep"){let W=To(T.source,T.sourceHandle);W&&(je={color:W.color,striped:W.striped});}let Qe=J.current.filter(W=>{if(W.id===s.id)return true;let Ie=W.source===T.source&&re(y,W.sourceHandle)===E||W.target===T.source&&re(y,W.targetHandle)===E,ne=W.target===T.target&&re(h,W.targetHandle)===F||W.source===T.target&&re(h,W.sourceHandle)===F;return !(Ie||ne)}).map(W=>W.id===s.id?{...W,source:T.source,target:T.target,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,type:_e,data:je!==void 0?{...W.data,...je}:W.data,zIndex:le({...T,id:W.id,type:_e}),style:{...W.style,zIndex:le({...T,id:W.id,type:_e})}}:W);ye(Qe);},[ye,ue,To,le,Y,a,q,Ce]),ja=Je.useCallback((s,g)=>{if(We){c&&c(g);return}let y=s.metaKey||s.ctrlKey,h=gt(),T=g,E=Ge(g);if(g.type==="tube"&&E&&!y){let F=h.find($=>$.id===E&&($.type==="cable"||$.type==="multi-tube-cable"));F&&(T=F);}if(Ar(T),Ro([]),j(F=>F.map($=>{let S=$.id===T.id;return $.selected===S?$:{...$,selected:S}})),y&&Ye(T)&&!io(T)){let F=T.data||{},$=F.view||(Array.isArray(F.rearPorts)&&F.rearPorts.length>0?"rear":"front"),S=$==="front"?"rear":"front";a&&console.log(`Command+click: Toggling device ${T.id} from ${$} to ${S}`),P&&P(T.id,S);}c&&c(T);},[P,c,a,gt,j,We,Ge,io]),Ya=Je.useCallback(()=>{},[]),Ka=Je.useCallback((s,g)=>{Ar(null),Ro([g]),j(y=>y.map(h=>h.selected?{...h,selected:false}:h)),c?.(null),l&&l(g);},[l,c,j]),Za=Je.useCallback(()=>{Ar(null),Ro([]),j(s=>s.map(g=>g.selected?{...g,selected:false}:g)),c?.(null);},[c,j]),[ot,Ar]=Je.useState(null),[qn,Jn]=Je.useState(new Set);reactflow.useOnSelectionChange({onChange:({edges:s})=>{Ro(s||[]);}});let[Lr,Ro]=Je.useState([]);Je.useEffect(()=>{let s=g=>{if(ge.allowKeyboardDelete&&(g.key==="Backspace"||g.key==="Delete")&&Lr.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let y=Lr.filter(h=>{let T=h.sourceHandle||"",E=h.targetHandle||"";return T.startsWith("tube-")||E.startsWith("tube-")?(a&&console.log("Cannot delete edge connected to tube handle",h),false):true});if(y.length>0){let h=new Set(y.map(E=>E.id)),T=J.current.filter(E=>!h.has(E.id));ye(T),Ro([]),a&&console.log("Deleted edges:",y.map(E=>E.id));}}};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[Lr,ye,a,ge.allowKeyboardDelete]);let qa=Je.useCallback((s,{nodeId:g,handleType:y})=>{a&&console.log("Connection started from",{nodeId:g,handleType:y});},[a]),Ja=Je.useCallback(s=>{a&&console.log("Connection ended",s);},[a]),Qa=Je.useCallback(()=>{if(Ce||!ot)return;let s=ue(ot.id);if(s){if(s.type==="rack"){let g=s.data||{};if(De(g))return;let h=(g.face||"front")==="front"?"rear":"front";N?(N(s.id,h),P&&gt().filter(E=>E.parentId===s.id).forEach(E=>{P(E.id,h);})):j(T=>T.map(E=>E.id===s.id?{...E,data:{...E.data,face:h}}:E.parentId===s.id?{...E,data:{...E.data,view:h}}:E));return}if(Ye(s)){if(io(s))return;let g=s.data||{},y=Array.isArray(g.rearPorts)&&g.rearPorts.length>0,h=Array.isArray(g.ports)&&g.ports.length>0,E=(g.view||(y&&!h?"rear":"front"))==="front"?"rear":"front";P?P(s.id,E):j(F=>F.map($=>$.id===s.id?{...$,data:{...$.data,view:E}}:$));}}},[ot,ue,N,P,j,gt,Ce,io]),es=Je.useCallback(()=>{if(Ce||!w||!ot||!Ye(ot))return;let s=ue(ot.id),g=Ge(s);if(!s||!Ye(s)||!g)return;let y=St(s),T=at.current.map(E=>E.id!==s.id?E:{...E,parentId:void 0,parentNode:void 0,extent:void 0,position:y,data:{...E.data,uPosition:void 0}});jo(T);},[Ce,w,ot,ue,St,jo,Ge]),ts=Je.useMemo(()=>{let s=vo.current;return we.map(g=>{let y=g,h=s.get(String(y.source)),T=s.get(String(y.target)),E=Cr(y.sourceHandle||"",h),F=Cr(y.targetHandle||"",T),$=Le=>{if(!Le||!Ye(Le))return;let xe=Le.data??{},Qe=typeof Le.parentId=="string"?Le.parentId:Le.parentNode,W=Qe?s.get(Qe):void 0;if(W&&W.type==="rack"&&De(W.data))return Ht(Be(xe));let Ie=Array.isArray(xe.rearPorts)&&xe.rearPorts.length>0,ne=Array.isArray(xe.ports)&&xe.ports.length>0;return [xe.view||(Ie&&!ne?"rear":"front")]},S=$(h),K=$(T),oe=$r(h),Te=$r(T),Re=Ye(h)&&!oe&&!!S&&!!E&&!S.includes(E),Se=Ye(T)&&!Te&&!!K&&!!F&&!K.includes(F),_e=Re||Se,je=g.style;if(_e)je={...g.style,opacity:0,pointerEvents:"none",zIndex:0};else if(g.style&&g.style.opacity===0&&g.style.pointerEvents==="none"&&g.style.zIndex===0){let xe={...g.style};delete xe.opacity,delete xe.pointerEvents,delete xe.zIndex,je=Object.keys(xe).length>0?xe:void 0;}return {...g,style:je,className:qn.has(g.id)?"edge-connecting":g.className}})},[we,qn,$r]),Fe=Je.useMemo(()=>ot?ue(ot.id)??ot:null,[ot,ue]),ao=Je.useMemo(()=>{if(!Fe||!ze.enabled||Ce)return {showRearToggle:false,showDeRack:false,count:0};let s=Fe.type==="rack"?!Kn(Fe):Ye(Fe)?!io(Fe):false,g=ze.showRearToggle&&s,y=ze.showDeRack&&w&&!Ce&&Ye(Fe)&&!!Ge(Fe);return {showRearToggle:g,showDeRack:y,count:(g?1:0)+(y?1:0)}},[Fe,ze,w,Ce,Ge,io,Kn]),Br=Je.useMemo(()=>{if(!Fe||ao.count===0||!qe.current)return null;let s=qe.current.getBoundingClientRect();if(s.width<=0||s.height<=0)return null;let g=Fe.positionAbsolute??St(Fe),y=Fe.width||0,h=Fe.height||0,T=ao.count>1?220:110,E=34;try{let F=Co({x:g.x+y/2,y:g.y}),$=Co({x:g.x+y/2,y:g.y+h}),S=F.x-s.left-T/2,K=F.y-s.top-E-10;return K<8&&(K=$.y-s.top+10),S=Math.max(8,Math.min(S,s.width-T-8)),K=Math.max(8,Math.min(K,s.height-E-8)),{left:S,top:K}}catch{return null}},[Fe,ao,St,Co]),os=ni(R,v),rs=ai(R,{touchAction:"none",...C});return jsxRuntime.jsxs("div",{ref:qe,className:os,style:rs,children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:ke,edges:ts,onNodesChange:s=>{if(Ce)return;let g=Oa(s);g&&(L?n&&n(g):q.setState({nodes:g}));},onEdgesChange:s=>{if(Ce)return;let g=s.filter(y=>{if(y.type==="remove"){let h=J.current.find(T=>T.id===y.id);if(h){let T=h.sourceHandle||"",E=h.targetHandle||"";if(T.startsWith("tube-")||E.startsWith("tube-"))return a&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",h),false}}return true});if(g.length>0){let y=reactflow.applyEdgeChanges(g,J.current);pt(g),L?i&&i(y):q.setState({edges:y});}},onConnect:Ce?void 0:u??Ga,onConnectStart:qa,onConnectEnd:Ja,onEdgeUpdate:Ce?void 0:p??Xa,isValidConnection:m??Va,connectionMode:x,onNodeClick:ja,onNodeDoubleClick:Ya,onPaneClick:Za,onNodeDragStart:Wa,onNodeDrag:za,onNodeDragStop:Ua,onEdgeClick:Ka,onInit:D,nodeTypes:jn.current,edgeTypes:Ba,defaultEdgeOptions:{zIndex:1e3,reconnectable:ge.edgesReconnectable},nodesDraggable:ge.nodesDraggable,nodesConnectable:ge.nodesConnectable,elementsSelectable:ge.elementsSelectable,edgesFocusable:ge.edgesFocusable,elevateNodesOnSelect:false,selectNodesOnDrag:false,connectOnClick:ge.connectOnClick,panOnDrag:ge.panOnDrag,panOnScroll:ge.panOnScroll,zoomOnScroll:ge.zoomOnScroll,zoomOnPinch:ge.zoomOnPinch,zoomOnDoubleClick:ge.zoomOnDoubleClick,preventScrolling:We,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:te,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:ii(R)}),ge.showControls&&jsxRuntime.jsx(reactflow.Controls,{showInteractive:ge.showInteractiveControl}),ge.showMiniMap&&jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&jsxRuntime.jsx("button",{className:"download-button",onClick:Lt,disabled:it,"aria-busy":it,style:{position:"absolute",top:_.includes("top")?"10px":"auto",bottom:_.includes("bottom")?"10px":"auto",right:_.includes("right")?"10px":"auto",left:_.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:it?"not-allowed":"pointer",opacity:it?.7:1,transition:"all 0.2s ease",...se},children:it?`${U}...`:U}),Fe&&Br&&ao.count>0&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:Br.top,left:Br.left,display:"flex",gap:8,zIndex:2e3},children:[ao.showRearToggle&&jsxRuntime.jsx("button",{onClick:s=>{s.preventDefault(),Qa();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let s=Fe.data;if(Fe.type==="rack")return (s?.face||"front")==="front"?"Switch to rear":"Switch to front";{let g=Array.isArray(s?.rearPorts)&&s.rearPorts.length>0,y=Array.isArray(s?.ports)&&s.ports.length>0;return (s?.view||(g&&!y?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let s=Fe.data;if(Fe.type==="rack")return (s?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let g=Array.isArray(s?.rearPorts)&&s.rearPorts.length>0,y=Array.isArray(s?.ports)&&s.ports.length>0;return (s?.view||(g&&!y?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()}),ao.showDeRack&&jsxRuntime.jsx("button",{onClick:s=>{s.preventDefault(),es();},style:{background:"#7f1d1d",color:"#fee2e2",border:"1px solid #b91c1c",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:"Remove device from rack so it can be moved/reassigned",children:"De-rack"})]})]})},On=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(oc,{...e})});var Wn=class extends Je.Component{constructor(){super(...arguments);this.state={error:null};this.reset=()=>{this.setState({error:null});};}static getDerivedStateFromError(o){return {error:o}}componentDidCatch(o,r){this.props.onError?.(o,r);}render(){let{error:o}=this.state,{children:r,fallback:n}=this.props;return o?typeof n=="function"?n(o,this.reset):n??jsxRuntime.jsxs("div",{role:"alert",style:{padding:16,margin:8,border:"1px solid #e53e3e",borderRadius:4,backgroundColor:"#fff5f5",color:"#c53030"},children:[jsxRuntime.jsx("strong",{children:"Diagram error"}),": ",o.message,jsxRuntime.jsx("button",{type:"button",onClick:this.reset,style:{marginLeft:12,padding:"4px 8px",cursor:"pointer"},children:"Try again"})]}):r}};function Go(e,{rowHeight:t,tubeGap:o}){let r=[],n=[],i=e.kind??(e.tubeCount?"tube":"simple"),d=i==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,a=i==="tube"?Math.max(1,Math.min(24,e.fibersPerTube??12)):Math.max(1,Math.min(24,e.fiberCount??12)),c=Math.max(1,e.tubeStartIndex??1),l=Math.max(1,e.fiberStartIndex??1),b=0;for(let f=0;f<d;f+=1){let u=c+f,p=e.tubeColorMap?.[u];n.push({tubeIndex:u,y:b,label:`T${u}`,color:p??Ue(u)});for(let m=0;m<a;m+=1){let x=l+m,P=qr(x);r.push({key:`${u}-${x}`,tubeIndex:i==="tube"?u:void 0,fiberIndex:x,y:b,color:Vt(x),striped:Ut(x),backgroundImage:typeof P.backgroundImage=="string"?P.backgroundImage:void 0}),b+=t;}f<d-1&&(b+=o);}return {rows:r,tubeLabels:n,height:b}}var zn=e=>typeof e=="object"&&e!==null,sc=e=>{if(!zn(e.data))return false;if(e.type==="fibre-flow-cable"){let t=e.data;return typeof t.label=="string"&&zn(t.cable)&&(t.side==="left"||t.side==="right")&&typeof t.rowHeight=="number"&&typeof t.columnWidth=="number"&&typeof t.showTubeLabels=="boolean"&&typeof t.showFiberNumbers=="boolean"&&zn(t.layout)}if(e.type==="fibre-flow-closure"){let t=e.data;return typeof t.label=="string"&&typeof t.width=="number"&&typeof t.height=="number"&&typeof t.headerHeight=="number"}return false},dc=e=>e==="fibre-flow"||e==="fibre-flow-link",cc=e=>typeof e.id=="string"&&e.id.length>0&&typeof e.source=="string"&&e.source.length>0&&typeof e.target=="string"&&e.target.length>0,lc=e=>e.sourceHandle==="cable-run"||e.targetHandle==="cable-run"?"fibre-flow-link":"fibre-flow",uc=(e,t=[])=>{let o=new Map(t.map(n=>[n.id,n])),r=[];return e.forEach(n=>{if(!cc(n))return;let i=o.get(n.id),d=dc(n.type)?n.type:i?.type??lc(n);r.push({...i??{},...n,type:d});}),r},ga=e=>`fiber-${e.tube??1}-${e.fiber}`,ba=e=>Vt(e.fiber),ma=e=>Ut(e.fiber),pc=(e,t)=>{if(t)return t;if(!(typeof e!="number"||Number.isNaN(e)))return e>=1e3?`${(e/1e3).toFixed(1)} km`:`${Math.round(e)} m`},fc=(e,t,o,r,n,i)=>e?`${o} ${i}`:t?`0 ${n} ${r} ${i}`:"6 6",gc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a})=>{let[c,l,b]=reactflow.getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.35}),f=typeof a?.lossDb=="number"?`${a.lossDb.toFixed(2)} dB`:"",u=a?.label??f,p=a?.sourceColor,m=a?.targetColor,x=a?.color??p??m??"#94a3b8",P=a?.sourceStriped??false,N=a?.targetStriped??false,v=a?.highlighted??true,C=a?.dimmed??false,H=a?.circuitId,w=a?.circuitLabel??H,R=a?.showCircuitId??false,D=p&&m&&p!==m,I=r-t,A=n-o,_=Math.sqrt(I*I+A*A),U=l-t,se=b-o,Y=Math.sqrt(U*U+se*se),ee=_>0?Y/_*100:50,ie=`fibre-flow-gradient-${e}`,z=P&&!N,V=N&&!P,B=P&&N,O=_*1.25,X=O/2,te=12,M=Math.ceil(X*1.2/te),L=Array(M).fill("6 6").join(" "),de=Math.ceil(X*1.2/te),ae=Array(de).fill("6 6").join(" "),ce=R&&w,q=Math.max(u?u.length*6.2+16:0,ce?(w?.length||0)*5.5+16:0),Ne=ce?32:16;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("defs",{children:D&&jsxRuntime.jsxs("linearGradient",{id:ie,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0%",stopColor:p}),jsxRuntime.jsx("stop",{offset:`${ee}%`,stopColor:p}),jsxRuntime.jsx("stop",{offset:`${ee}%`,stopColor:m}),jsxRuntime.jsx("stop",{offset:"100%",stopColor:m})]})}),D?jsxRuntime.jsx("path",{id:e,d:c,fill:"none",stroke:`url(#${ie})`,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,style:{mixBlendMode:"normal"}}):jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:c,style:{stroke:x,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,mixBlendMode:"normal"}}),(B||z||V)&&jsxRuntime.jsx("path",{id:`${e}-stripe`,d:c,fill:"none",stroke:"#000",strokeWidth:v?1.6:1.3,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:fc(z,V,L,ae,X,O),strokeDashoffset:0,opacity:C?.2:.9,style:{mixBlendMode:"normal"}}),(u||ce)&&v&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${b}px)`,width:q,height:Ne,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:[u&&jsxRuntime.jsx("div",{style:{lineHeight:1.2},children:u}),ce&&jsxRuntime.jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:u?2:0},children:w})]})})]})},bc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a})=>{let[c,l,b]=reactflow.getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.2}),f=a?.label,u=a?.color??"#64748b";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:c,style:{stroke:u,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),f&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${b}px)`,padding:"2px 8px",background:"rgba(30, 41, 59, 0.9)",border:`1px solid ${u}`,borderRadius:10,fontSize:10,fontFamily:"monospace",color:"#e2e8f0",letterSpacing:.2,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9999},children:f})})]})},mc=({data:e})=>{let{cable:t,side:o,rowHeight:r,columnWidth:n,showTubeLabels:i,showFiberNumbers:d,layout:a,colorMode:c="dark"}=e,l=c==="light",b=8,f=12,u=-1,p=0,m=t.jacketColor??"#facc15",x=(t.kind??(t.tubeCount?"tube":"simple"))==="tube",P=i&&x,N=o==="left"?b+p:p,v=o==="right"?b+p:p,C=o==="left"?reactflow.Position.Right:reactflow.Position.Left,H={width:4,height:4,borderRadius:"50%",background:m,border:`1px solid ${m}`,boxShadow:"0 0 1px rgba(0,0,0,0.4)",top:"50%",position:"absolute",...o==="left"?{left:0,transform:"translate(-50%, -50%)"}:{right:0,transform:"translate(50%, -50%)"}};return jsxRuntime.jsxs("div",{style:{position:"relative",width:n,height:a.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[jsxRuntime.jsx("div",{style:{position:"absolute",top:-18,left:o==="left"?0:void 0,right:o==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:l?"rgba(248, 250, 252, 0.95)":"rgba(15, 23, 42, 0.9)",color:l?"#1a1a1a":"#f8fafc",padding:"2px 6px",borderRadius:4,whiteSpace:"nowrap",maxWidth:n,overflow:"hidden",textOverflow:"ellipsis",zIndex:10,...o==="right"?{textAlign:"right"}:{}},children:t.label}),jsxRuntime.jsx("div",{style:{position:"absolute",top:0,bottom:0,width:b,left:o==="left"?0:void 0,right:o==="right"?0:void 0,borderRadius:4,background:x?"transparent":m,border:`1px solid ${m}`,boxShadow:x?"none":"inset 0 0 3px rgba(0,0,0,0.3)",overflow:"hidden"},children:x&&a.tubeLabels.map((w,R)=>{let D=a.rows.filter(Y=>Y.tubeIndex===w.tubeIndex);if(D.length===0)return null;let I=D[0].y,A=D[D.length-1].y+r,_=A-I,U=a.tubeLabels[R+1],se=U&&U.y-A>0;return jsxRuntime.jsx("div",{style:{position:"absolute",top:I,left:0,right:0,height:_,background:w.color,borderLeft:`2px solid ${w.color}`,borderRight:`2px solid ${w.color}`,borderTop:R===0?`2px solid ${w.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:se?"1px solid rgba(0,0,0,0.15)":`2px solid ${w.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:R===0&&!se||R===0?"4px 4px 0 0":se?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${w.tubeIndex}`)})}),!P&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,bottom:0,left:N,right:v,...o==="left"?{borderRight:`1px solid ${m}`}:{borderLeft:`1px solid ${m}`},pointerEvents:"none",zIndex:0}}),x&&a.tubeLabels.map((w,R)=>{let D=a.rows.filter(U=>U.tubeIndex===w.tubeIndex);if(D.length===0)return null;let I=D[0].y,_=D[D.length-1].y+r-I;return jsxRuntime.jsx("div",{style:{position:"absolute",top:I,left:N,right:v,height:_,...o==="left"?{borderRight:`2px solid ${w.color}`}:{borderLeft:`2px solid ${w.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${w.tubeIndex}`)}),a.rows.map(w=>{let R=`fiber-${w.tubeIndex??1}-${w.fiberIndex}`,D=w.y+r/2,I={position:"absolute",width:f,height:f,borderRadius:"50%",top:D,background:w.backgroundImage?w.backgroundImage:w.color,backgroundColor:w.color,border:`2px solid ${w.color}`,boxShadow:"0 0 6px rgba(0,0,0,0.3)",...o==="left"?{right:-f/2}:{left:-f/2},transform:"translateY(-50%)",zIndex:1e3,cursor:"crosshair","--fiber-bg":w.color,minWidth:f,minHeight:f};w.backgroundImage&&(I["--fiber-bg-image"]=w.backgroundImage);let A=o==="left"?{right:f+u,textAlign:"right"}:{left:f+u,textAlign:"left"};return jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:R,type:"source",position:C,className:"fibre-flow-handle",style:I,isConnectable:true,"data-fiber-idx":w.fiberIndex,"data-tube-idx":w.tubeIndex,"data-fiber-color":w.color}),jsxRuntime.jsx(reactflow.Handle,{id:R,type:"target",position:C,className:"fibre-flow-handle",style:I,isConnectable:true,"data-fiber-idx":w.fiberIndex,"data-tube-idx":w.tubeIndex,"data-fiber-color":w.color}),d&&jsxRuntime.jsx("div",{style:{position:"absolute",top:w.y+r/2-6,...A,fontSize:8,fontWeight:600,color:l?"rgba(15, 23, 42, 0.7)":"rgba(148, 163, 184, 0.95)",whiteSpace:"nowrap",lineHeight:1},children:w.fiberIndex})]},w.key)}),jsxRuntime.jsx(reactflow.Handle,{id:"cable-run",type:"source",position:o==="left"?reactflow.Position.Left:reactflow.Position.Right,className:"cable-run-handle",style:H,isConnectable:true,"data-handle-type":"cable-run"}),jsxRuntime.jsx(reactflow.Handle,{id:"cable-run",type:"target",position:o==="left"?reactflow.Position.Left:reactflow.Position.Right,className:"cable-run-handle",style:H,isConnectable:true,"data-handle-type":"cable-run"})]})},hc=({data:e})=>{let t=e.colorMode==="light";return jsxRuntime.jsx("div",{style:{width:e.width,height:e.height,background:"transparent",border:t?"1px solid rgba(148, 163, 184, 0.3)":"1px solid rgba(148, 163, 184, 0.5)",borderRadius:12,boxShadow:t?"0 12px 24px rgba(0, 0, 0, 0.1)":"0 12px 24px rgba(15, 23, 42, 0.2)",position:"relative",pointerEvents:"none"},children:jsxRuntime.jsx("div",{style:{height:e.headerHeight,display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"monospace",fontWeight:700,fontSize:12,letterSpacing:.6,textTransform:"uppercase",color:t?"rgba(15, 23, 42, 0.9)":"rgba(226, 232, 240, 0.9)",background:t?"rgba(241, 245, 249, 0.7)":"rgba(15, 23, 42, 0.6)",borderBottom:t?"1px solid rgba(148, 163, 184, 0.2)":"1px solid rgba(148, 163, 184, 0.35)",borderTopLeftRadius:12,borderTopRightRadius:12},children:e.label})})},yc=(e,t,o,r,n,i,d,a,c,l="dark")=>{let b=[],f=0;return e.forEach(u=>{let p=Go(u.leftCable,{rowHeight:o,tubeGap:r}),m=Go(u.rightCable,{rowHeight:o,tubeGap:r}),x=Math.max(p.height,m.height),P=i*2+d,N=32,v=16,C=P+v*2,H=x+N+v*2,w=`flow-closure-${u.id}`,R=`flow-cable-${u.id}-left`,D=`flow-cable-${u.id}-right`,I=t==="horizontal"?{x:f,y:0}:{x:0,y:f};f+=(t==="horizontal"?C:H)+n;let A=u.chamberId?`${u.id} - ${u.chamberId}`:u.id;b.push({id:w,type:"fibre-flow-closure",position:I,data:{label:A,width:C,height:H,headerHeight:N,colorMode:l},selectable:false,draggable:false,style:{width:C,height:H}});let _=N+v+(x-p.height)/2,U=N+v+(x-m.height)/2;b.push({id:R,type:"fibre-flow-cable",position:{x:v,y:_},parentId:w,extent:"parent",data:{label:u.leftCable.label,cable:u.leftCable,side:"left",rowHeight:o,columnWidth:i,showTubeLabels:a,showFiberNumbers:c,layout:p,colorMode:l},style:{width:i,height:p.height}}),b.push({id:D,type:"fibre-flow-cable",position:{x:v+P-i,y:U},parentId:w,extent:"parent",data:{label:u.rightCable.label,cable:u.rightCable,side:"right",rowHeight:o,columnWidth:i,showTubeLabels:a,showFiberNumbers:c,layout:m,colorMode:l},style:{width:i,height:m.height}});}),b},wc=(e,t,o,r=false)=>{let n=[],i=new Map,d=new Map,a=new Map;return (t??[]).forEach(c=>{c.color&&i.set(c.id,c.color),c.label&&d.set(c.id,c.label);}),e.forEach(c=>{let l=`flow-cable-${c.id}-left`,b=`flow-cable-${c.id}-right`;[{nodeId:l,cable:c.leftCable},{nodeId:b,cable:c.rightCable}].forEach(({nodeId:u,cable:p})=>{let m=a.get(p.id);if(m&&m.closureId!==c.id){let x=pc(p.distanceMeters??m.distanceMeters,p.distanceLabel??m.distanceLabel),P=p.jacketColor??m.jacketColor??"#64748b";n.push({id:`flow-link-${m.nodeId}-${u}`,type:"fibre-flow-link",source:m.nodeId,target:u,sourceHandle:"cable-run",targetHandle:"cable-run",data:{label:x,color:P}});}a.set(p.id,{nodeId:u,closureId:c.id,jacketColor:p.jacketColor,distanceLabel:p.distanceLabel,distanceMeters:p.distanceMeters});}),c.splices.forEach(u=>{let p=o?u.circuitId===o:true,m=!!o&&!p,x=u.circuitId?i.get(u.circuitId):void 0,P=u.circuitId?d.get(u.circuitId):void 0,N=u.color??x,v=ba(u.from),C=ba(u.to),H=ma(u.from),w=ma(u.to);n.push({id:`flow-edge-${c.id}-${u.id}`,type:"fibre-flow",source:l,target:b,sourceHandle:ga(u.from),targetHandle:ga(u.to),data:{lossDb:u.lossDb,label:u.label,color:N,sourceColor:v,targetColor:C,sourceStriped:H,targetStriped:w,highlighted:p,dimmed:m,circuitId:u.circuitId,circuitLabel:P,showCircuitId:r}});});}),n},xc=({closures:e,circuits:t,highlightedCircuitId:o,layout:r="horizontal",rowHeight:n=20,tubeGap:i=10,closureGap:d=140,cableColumnWidth:a=32,spliceAreaWidth:c=260,showTubeLabels:l=true,showFiberNumbers:b=true,colorMode:f="dark",showCircuitId:u=false,className:p,style:m,readOnly:x=false,panOnDrag:P=true,panOnScroll:N=true,zoomOnScroll:v=true})=>{let C=Je.useMemo(()=>yc(e,r,n,i,d,a,c,l,b,f),[e,r,n,i,d,a,c,l,b,f]),H=Je.useMemo(()=>wc(e,t,o,u),[e,t,o,u]),[w,R]=Je.useState(C),[D,I]=Je.useState(H);Je.useEffect(()=>{R(C);},[C,R]),Je.useEffect(()=>{I(H);},[H,I]);let A=Je.useCallback((B,O)=>{if(!B||!O||!O.startsWith("fiber-"))return;let X=w.find(ce=>ce.id===B);if(!X||X.type!=="fibre-flow-cable")return;let te=/^fiber-(\d+)-(\d+)$/.exec(O);if(!te)return;let M=Number(te[1]),L=Number(te[2]),ae=X.data.layout.rows.find(ce=>(ce.tubeIndex??1)===M&&ce.fiberIndex===L);if(ae)return {color:ae.color,striped:ae.striped??false}},[w]),_=Je.useCallback(B=>{if(x||!B.source||!B.target||!B.sourceHandle||!B.targetHandle)return false;let O=w.find(de=>de.id===B.source),X=w.find(de=>de.id===B.target);if(!O||!X)return false;let te=typeof B.sourceHandle=="string"&&B.sourceHandle.startsWith("fiber-"),M=typeof B.targetHandle=="string"&&B.targetHandle.startsWith("fiber-");return B.sourceHandle==="cable-run"||B.targetHandle==="cable-run"?true:te&&M?O.type==="fibre-flow-cable"&&X.type==="fibre-flow-cable":false},[w,x]),U=Je.useCallback(B=>{if(x)return;let O=B.sourceHandle==="cable-run"||B.targetHandle==="cable-run",X=q=>typeof q=="string"&&q.startsWith("fiber-"),te=X(B.sourceHandle),M=X(B.targetHandle),L=(q,Ne,ve)=>q.source===Ne&&q.sourceHandle===ve||q.target===Ne&&q.targetHandle===ve,de=O?void 0:A(B.source,B.sourceHandle),ae=O?void 0:A(B.target,B.targetHandle),ce=O?void 0:{sourceColor:de?.color,targetColor:ae?.color,color:de?.color??ae?.color,sourceStriped:de?.striped,targetStriped:ae?.striped};I(q=>{let Ne=q.filter(ve=>{let ke=te&&L(ve,B.source,B.sourceHandle),j=M&&L(ve,B.target,B.targetHandle);return !(ke||j)});return reactflow.addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:ce},Ne)});},[A,x,I]),se=Je.useCallback((B,O)=>{if(x)return;let X=O.sourceHandle==="cable-run"||O.targetHandle==="cable-run",te=X?void 0:A(O.source,O.sourceHandle),M=X?void 0:A(O.target,O.targetHandle),L=X?void 0:{sourceColor:te?.color,targetColor:M?.color,color:te?.color??M?.color,sourceStriped:te?.striped,targetStriped:M?.striped},de=ce=>typeof ce=="string"&&ce.startsWith("fiber-"),ae=(ce,q,Ne)=>ce.source===q&&ce.sourceHandle===Ne||ce.target===q&&ce.targetHandle===Ne;I(ce=>{let q=ce.filter(j=>j.id!==B.id),Ne=de(O.sourceHandle),ve=de(O.targetHandle),ke=q.filter(j=>{let we=Ne&&ae(j,O.source,O.sourceHandle),Pe=ve&&ae(j,O.target,O.targetHandle);return !(we||Pe)});return reactflow.addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:L},ke)});},[A,x,I]),Y=Je.useCallback(B=>{x||R(B.filter(sc));},[x,R]),ee=Je.useCallback(B=>{x||I(O=>uc(B,O));},[x,I]),ie=Je.useMemo(()=>({"fibre-flow-cable":mc,"fibre-flow-closure":hc}),[]),z=Je.useMemo(()=>({"fibre-flow":gc,"fibre-flow-link":bc}),[]),V={borderRadius:8,overflow:"hidden",...m};return jsxRuntime.jsx(On,{nodes:w,edges:D,onNodesChange:Y,onEdgesChange:ee,onConnect:U,onEdgeUpdate:se,isValidConnection:_,connectionMode:reactflow.ConnectionMode.Loose,nodeTypes:ie,edgeTypes:z,className:p,style:V,colorMode:f,readOnly:x,panOnDrag:P,panOnScroll:N,zoomOnScroll:v,fitViewOptions:{padding:.2}})},Nc=e=>jsxRuntime.jsx(xc,{...e});var Cc=({cable:e,side:t,rowHeight:o=22,tubeGap:r=10,columnWidth:n=150,layout:i,showTubeLabels:d,showFiberNumbers:a=true,showCableLabel:c=true})=>{let l=Je.useMemo(()=>i??Go(e,{rowHeight:o,tubeGap:r}),[i,e,o,r]),b=26,f=10,u=18,p=t==="left"?n-u:u,m=8,x=t==="left"?6:n-b-18,P=e.jacketColor??"#facc15",N=d??(e.kind??(e.tubeCount?"tube":"simple"))==="tube";return jsxRuntime.jsxs("div",{style:{position:"relative",width:n,height:l.height,fontFamily:"monospace",color:"inherit"},children:[c&&jsxRuntime.jsx("div",{style:{position:"absolute",top:-18,left:t==="left"?0:void 0,right:t==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:"rgba(15, 23, 42, 0.85)",color:"#f8fafc",padding:"2px 6px",borderRadius:4},children:e.label}),jsxRuntime.jsx("div",{style:{position:"absolute",top:0,bottom:0,width:b,left:t==="left"?0:void 0,right:t==="right"?0:void 0,borderRadius:14,background:`linear-gradient(90deg, ${P} 0%, ${P} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${P}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),N&&l.tubeLabels.map(v=>jsxRuntime.jsxs("div",{style:{position:"absolute",top:v.y+o/2-6,left:x,fontSize:9,fontWeight:700,textTransform:"uppercase",color:"rgba(15, 23, 42, 0.75)",background:"rgba(255, 255, 255, 0.6)",padding:"1px 6px 1px 4px",borderRadius:10,display:"flex",alignItems:"center",gap:4},children:[jsxRuntime.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:v.color,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 3px rgba(0,0,0,0.25)"}}),jsxRuntime.jsx("span",{children:v.label})]},`tube-${v.tubeIndex}`)),l.rows.map(v=>{let C=v.y+o/2-f/2,H=t==="left"?p-f/2-m:p+f/2+m;return jsxRuntime.jsxs(Je__default.default.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"absolute",top:C,left:p-f/2,width:f,height:f,borderRadius:"50%",backgroundColor:v.color,backgroundImage:v.backgroundImage,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 4px rgba(0,0,0,0.25)"}}),a&&jsxRuntime.jsx("div",{style:{position:"absolute",top:v.y+o/2-6,left:H,transform:t==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:v.fiberIndex})]},v.key)})]})};var Na=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}}),ka=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}}),Pa=e=>{let t=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},o=t(e.termination_a),r=t(e.termination_b);return {id:`cable-${e.id}`,source:`device-${o}`,target:`device-${r}`,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}}},vc=e=>{let t=[],o=[];return e.racks.forEach(r=>t.push(Na(r))),e.devices.forEach(r=>t.push(ka(r))),e.cables.forEach(r=>o.push(Pa(r))),{nodes:t,edges:o}},Tc=e=>{let t=e.filter(n=>n.type==="rack"),o=e.filter(n=>n.type==="device"),r=e.filter(n=>!["rack","device"].includes(n.type));return t.forEach((n,i)=>{n.position={x:i*300,y:100};}),o.forEach(n=>{if(n.parentId){let i=t.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,a=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-a*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),r.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var Ca=e=>typeof e.id=="number"?`device-${e.id}`:`device-${e.name}`,Rc="Interfaces",Sc="Management",Ic="Power",Vn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),vt=e=>{if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0},Sr=e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim().length>0){let t=Number(e);if(Number.isFinite(t))return t}},Tt=e=>{if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20")return t},Ec=e=>typeof e=="string"&&e.toLowerCase()==="rear"?"rear":"front",Ir=e=>Vn(e.custom_fields)?e.custom_fields:void 0,Er=e=>Vn(e)?e:void 0,va=(e,t)=>{let o=Ir(e),r=Er(o?.layout);return Ec(t??e.layout?.face??e.face??r?.face??o?.port_face??o?.portFace??o?.face)},Ta=(e,t,o)=>{let r=Ir(e),n=Er(r?.layout),i=vt(o)??vt(e.layout?.group)??vt(e.port_group)??vt(n?.group)??vt(r?.port_group)??vt(r?.portGroup)??vt(r?.interface_group)??vt(r?.interfaceGroup)??vt(r?.group);return i||(t==="power_ac"||t==="power_c13"||t==="power_c19"?Ic:t==="console"||t==="mgmt"?Sc:Rc)},Ra=(e,t,o)=>{let r=Ir(e),n=Er(r?.layout);return Tt(o)??Tt(e.layout?.connectorType)??Tt(e.layout?.connector_type)??Tt(e.connector_type)??Tt(n?.connectorType)??Tt(n?.connector_type)??Tt(r?.connectorType)??Tt(r?.connector_type)??Tt(t)},Sa=(e,t)=>{if(t==="C13")return "power_c13";if(t==="C19")return "power_c19";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")||o.includes("dac")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")||o.includes("oob")?"mgmt":o.includes("usb")?"usb":"ethernet"},Ia=e=>{let t=(e??"").toLowerCase();if(t){if(t.includes("om3"))return "om3";if(t.includes("om4"))return "om4";if(t.includes("om5"))return "om5";if(t.includes("smf")||t.includes("singlemode"))return "smf";if(t.includes("cat5e"))return "cat5e";if(t.includes("cat6a"))return "cat6a";if(t.includes("cat6"))return "cat6";if(t.includes("cat7"))return "cat7";if(t.includes("fiber")||t.includes("sfp")||t.includes("qsfp"))return "fiber";if(t.includes("ethernet")||t.includes("rj45")||t.includes("1000base")||t.includes("10gbase")||t.includes("base-t"))return "ethernet"}},Hc=e=>{if(!Vn(e))return;let t=e.side??e.port_side??e.portSide,o=typeof t=="string"&&["top","right","bottom","left"].includes(t.toLowerCase())?t.toLowerCase():void 0,r=Sr(e.offsetPercent??e.offset_percent??e.offsetPct??e.offset_pct),n=Sr(e.offsetPx??e.offset_px??e.offsetPixels??e.offset_pixels),i=Sr(e.xPercent??e.x_percent??e.xPct??e.x_pct??e.horizontalPercent??e.horizontal_percent??e.x),d=Sr(e.yPercent??e.y_percent??e.yPct??e.y_pct??e.verticalPercent??e.vertical_percent??e.y);if(!(o===void 0&&r===void 0&&n===void 0&&i===void 0&&d===void 0))return {side:o,offsetPercent:r,offsetPx:n,xPercent:i,yPercent:d}},Ea=(e,t,o)=>{if(!o)return;let r=Ir(e),n=Er(r?.layout),i=[t?.position,t,e.layout?.position,e.layout,n?.position,n,r?.port_position,r?.portPosition,r?.position,r,e];for(let d of i){let a=Hc(d);if(a)return a}},Fc=(e,t)=>{let o=e.type?.value??e.type?.label??e.layout?.type??void 0,r=Ra(e,o),n=Sa(o,r),i=Ta(e,n);return {label:e.name,face:va(e),group:i,type:n,cableType:Ia(o),connected:!!(e.connected_endpoint||e.cable),connectorType:r,position:Ea(e,void 0,t)}},Dc=e=>[...e].sort((t,o)=>{let r=typeof t.position=="number"?t.position:Number.MAX_SAFE_INTEGER,n=typeof o.position=="number"?o.position:Number.MAX_SAFE_INTEGER;return r!==n?r-n:t.name.localeCompare(o.name)}),_c=(e,t)=>{let o=e.find(n=>n.name===t);if(o)return o;let r={name:t,ports:[]};return e.push(r),r},Mc=(e,t)=>{let{includePortPositions:o=false,mapInterfaceToPort:r}=t,n=[],i=[];return Dc(e.interfaces??[]).forEach((a,c)=>{let l=r?r({device:e,iface:a,index:c}):Fc(a,o);if(!l)return;let b=l.type??a.type?.value??a.type?.label??void 0,f=Ra(a,b,l.connectorType),u=Sa(b,f),p=va(a,l.face),m=Ta(a,u,l.group);_c(p==="rear"?i:n,m).ports.push({id:l.id,label:l.label??a.name,connected:l.connected??!!(a.connected_endpoint||a.cable),type:u,cableType:Ia(l.cableType??a.type?.value??a.type?.label??void 0),connectorType:f,position:Ea(a,l,o)});}),{front:n,rear:i}},Ha=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:e.status.value,uHeight:e.u_height,netboxId:e.id,netboxType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:e.site.name,role:e.role?.name,tenant:e.tenant?.name}}),Fa=(e,t={})=>{let o={label:e.name,status:e.status.value,deviceType:e.device_type.model,manufacturer:e.device_type.manufacturer.name,role:e.device_role.name,uHeight:1,uPosition:e.position||1,face:e.face||"front",netboxId:e.id,netboxType:"device",primaryIp4:e.primary_ip4?.address,primaryIp6:e.primary_ip6?.address,site:e.site.name,rack:e.rack?.name};if(t.includeInterfacePorts&&Array.isArray(e.interfaces)&&e.interfaces.length>0){let{front:r,rear:n}=Mc(e,t);r.length>0&&(o.ports=r),n.length>0&&(o.rearPorts=n);}return {id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${e.rack.id}`:void 0,extent:e.rack?"parent":void 0,data:o}},Da=e=>({id:`cable-${e.id}`,source:Ca(e.termination_a.device),target:Ca(e.termination_b.device),type:"fiber",data:{bandwidth:e.type.label,length:e.length||0,color:e.color,netboxId:e.id,netboxType:"cable",status:e.status.value,terminationA:e.termination_a.name,terminationB:e.termination_b.name}}),$c=(e,t={})=>{let o=[],r=[],n=new Map;return e.racks.forEach(i=>{o.push(Ha(i));}),e.devices.forEach(i=>{let d=Fa(i,t);o.push(d),n.set(i.name,d.id);}),e.cables.forEach(i=>{let d=Da(i),a=(typeof i.termination_a.device.id=="number"?`device-${i.termination_a.device.id}`:void 0)??n.get(i.termination_a.device.name)??d.source,c=(typeof i.termination_b.device.id=="number"?`device-${i.termination_b.device.id}`:void 0)??n.get(i.termination_b.device.name)??d.target;r.push({...d,source:a,target:c});}),{nodes:o,edges:r}},Ac=(e,t)=>{let o=new Map,r=new Set;return e.filter(i=>i.position!==null).sort((i,d)=>(i.position||0)-(d.position||0)).forEach(i=>{i.position&&(o.set(i.id,i.position),r.add(i.position));}),o};function Hr(e){let{items:t,checkOutOfBounds:o,checkConflicts:r}=e,n=[],i=[];for(let d of t){let a=o(d);a&&!a.isValid&&a.error&&i.push(a.error);}for(let d=0;d<t.length;d++){let a=t[d];for(let c=d+1;c<t.length;c++){let l=t[c],b=r(a,l);b&&b.hasConflict&&b.conflict&&n.push(b.conflict);}}return {isValid:n.length===0&&i.length===0,conflicts:n,outOfBounds:i}}var xo=class extends Error{constructor(o,r,n,i,d){super(`Device placement conflict: ${r} at U${n}-${n+i-1} in rack ${o}${d?` conflicts with ${d}`:""}`);this.rackId=o;this.deviceId=r;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function Gn(e,t={}){let o=De(e);return Hr({items:e.devices,checkOutOfBounds:r=>r.unit+r.height-1>e.units?{isValid:false,error:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,rackUHeight:e.units}}:null,checkConflicts:(r,n)=>{let i=r.unit,d=r.unit+r.height-1,a=n.unit,c=n.unit+n.height-1;if(i<=c&&d>=a){if(o){let l=Be(r),b=Be(n);if(!Zo(l,b))return null}return {hasConflict:true,conflict:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,conflictWith:n.id}}}return null}})}function _a(e,t,o={}){let{deviceTypeMapping:r={}}=o,n=r[e.type]||"device",i=lo(t,e.unit,e.height,e);return {id:e.id,type:n,position:i,parentId:t.id,extent:"parent",data:{label:e.name,status:e.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:t.data.rackWidthPx,rackLayout:t.data.rackLayout,rackFaceGapPx:t.data.rackFaceGapPx,mountMode:Be(e)}}}function Lc(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,rackLayout:e.rackLayout,rackFaceGapPx:e.rackFaceGapPx}}}function Bc(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let d of e){let a=Gn(d,t);if(!a.isValid&&o==="strict"){let c=[];throw a.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),a.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new xo(d.id,a.conflicts[0]?.deviceId||a.outOfBounds[0]?.deviceId||"unknown",a.conflicts[0]?.uPosition||a.outOfBounds[0]?.uPosition||1,a.conflicts[0]?.uHeight||a.outOfBounds[0]?.uHeight||1)}}for(let d of e){let a=Lc(d);n.push(a);for(let c of d.devices)try{let l=_a(c,a,t);i.push(l);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let b=er(a,{id:c.id,data:{label:c.name,uHeight:c.height,mountMode:Be(c)}},i,c.unit);if(b!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${b} due to conflict`);let f={...c,unit:b},u=_a(f,a,t);i.push(u);}else throw new xo(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Oc(e){let t=[],o=e.filter(r=>r.type==="rack");for(let r of o){let i=e.filter(d=>Ho(d.type)&&d.parentId===r.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width==="full"||d.data.width==="half"?d.data.width:void 0,ports:Array.isArray(d.data.ports)?d.data.ports:void 0,connections:d.data.connections,frontImageUrl:d.data.frontImageUrl,rearImageUrl:d.data.rearImageUrl,frontImageAttribution:d.data.frontImageAttribution,rearImageAttribution:d.data.rearImageAttribution,imageFit:d.data.imageFit,imagePosition:d.data.imagePosition,imageRepeat:d.data.imageRepeat,stretchToFit:d.data.stretchToFit,mountMode:Be(d.data)}));t.push({id:r.id,name:r.data.label,position:r.position,units:r.data.uHeight||42,uNumberingDirection:r.data.uNumberingDirection||"bottom-up",customHeaderText:r.data.customHeaderText,rackLayout:r.data.rackLayout,rackFaceGapPx:r.data.rackFaceGapPx,devices:i,rackWidthPx:r.data.rackWidthPx});}return t}function Wc(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,devices:n.devices.map(i=>i.id!==o?i:{...i,unit:r})})}function zc(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!Gn({...i,devices:[...i.devices,o]},r).isValid)throw new xo(t,o.id,o.unit,o.height);return {...i,devices:[...i.devices,o]}})}function Uc(e,t,o){return e.map(r=>r.id!==t?r:{...r,devices:r.devices.filter(n=>n.id!==o)})}var No=class extends Error{constructor(o,r,n,i){super(`Splice placement conflict: ${r} at holder ${n} in tray ${o}${i?` conflicts with ${i}`:""}`);this.trayId=o;this.spliceId=r;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function Xn(e,t={}){return Hr({items:e.splices,checkOutOfBounds:o=>o.holder<1||o.holder>_t?{isValid:false,error:{spliceId:o.id,holder:o.holder,max:_t}}:null,checkConflicts:(o,r)=>o.holder===r.holder?{hasConflict:true,conflict:{spliceId:o.id,holder:o.holder,conflictWith:r.id}}:null})}function Ma(e,t){let o=e.mode==="ribbon",r=zo(t,e.holder,o);return {id:e.id,type:"splice",position:r,parentId:t.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function Vc(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Gc(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let d of e){let a=Xn(d,t);if(!a.isValid&&o==="strict"){let c=[];throw a.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),a.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new No(d.id,a.conflicts[0]?.spliceId||a.outOfBounds[0]?.spliceId||"unknown",a.conflicts[0]?.holder||a.outOfBounds[0]?.holder||1)}}for(let d of e){let a=Vc(d);n.push(a);for(let c of d.splices)try{let l=c.holder;if(o==="nearest"){let u={id:c.id,type:"splice",position:{x:0,y:0},data:{label:c.name,holderPosition:c.holder}},p=[...n,...i];Bo(a,u,c.holder,p)||(l=Wo(a,u,p,c.holder));}let b=l!==c.holder?{...c,holder:l}:c,f=Ma(b,a);i.push(f);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let b=[...n,...i],f=Wo(a,{id:c.id,data:{label:c.name,holderPosition:c.holder}},b,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let u={...c,holder:f},p=Ma(u,a);i.push(p);}else throw new No(d.id,c.id,c.holder)}}}return n.push(...i),n}function Xc(e){let t=[],o=e.filter(r=>r.type==="splice-tray");for(let r of o){let i=e.filter(d=>d.type==="splice"&&d.parentId===r.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb,mode:d.data.mode||"single",ribbonFiberIds:d.data.ribbonFiberIds}));t.push({id:r.id,name:r.data.label,position:r.position,splices:i});}return t}function jc(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,splices:n.splices.map(i=>i.id!==o?i:{...i,holder:r})})}function Yc(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!Xn({...i,splices:[...i.splices,o]},r).isValid)throw new No(t,o.id,o.holder);return {...i,splices:[...i.splices,o]}})}function Kc(e,t,o){return e.map(r=>r.id!==t?r:{...r,splices:r.splices.filter(n=>n.id!==o)})}var $a=2;var fe=e=>typeof e=="string"?e.trim():"",ut=e=>{if(typeof e=="number"&&Number.isFinite(e))return e},Zc=e=>{let t=fe(e).toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20"||t==="AC")return t},qc=(e,t)=>{if(t==="C13"||t==="C14")return "power_c13";if(t==="C19"||t==="C20")return "power_c19";if(t==="AC")return "power_ac";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")?"mgmt":o.includes("usb")?"usb":"ethernet"},Jc=e=>{if(e==="power_c13")return "C13";if(e==="power_c19")return "C19";if(e==="power_ac")return "AC"},Qc=e=>e.toLowerCase().replace(/_/g,"-").trim(),el=e=>e>=1?"rackable":"zero-u",tl=e=>(e??"").toLowerCase()==="half"?"half":"full",ol=(e,t,o,r)=>{let n=r.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase();return `${e}-b${t}-${n||`p${o}`}`},Aa=(e,t)=>`${e}-${t}`.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function rl(e){let t=[],o=fe(e.manufacturer),r=fe(e.model),n=fe(e.role)||fe(e.deviceType)||fe(e.device_type)||"device",i=ut(e.uHeight)??ut(e.u_height)??0;o||t.push({severity:"warning",code:"MISSING_MANUFACTURER",message:"Template is missing manufacturer",path:"manufacturer"}),r||t.push({severity:"warning",code:"MISSING_MODEL",message:"Template is missing model",path:"model"});let d=fe(e.id)||fe(e.slug)||Aa(o,r)||"unknown",a=fe(e.slug)||Aa(o,r)||d,c=Array.isArray(e.ports)?e.ports:[],l=Array.isArray(e.rearPorts)?e.rearPorts:Array.isArray(e.rear_ports)?e.rear_ports:[],f=(Array.isArray(e.frontRearPortLinks)?e.frontRearPortLinks:Array.isArray(e.front_rear_port_links)?e.front_rear_port_links:[]).map(u=>({frontPortId:fe(u.frontPortId)||fe(u.front_port_id),rearPortId:fe(u.rearPortId)||fe(u.rear_port_id)}));return {id:d,slug:a,manufacturer:o,model:r,role:n,uHeight:i,width:fe(e.width)||void 0,frontBlocks:c,rearBlocks:l,rawLinks:f,frontImageUrl:fe(e.frontImageUrl)||fe(e.front_image_url)||void 0,rearImageUrl:fe(e.rearImageUrl)||fe(e.rear_image_url)||void 0,frontImageAttribution:fe(e.frontImageAttribution)||void 0,rearImageAttribution:fe(e.rearImageAttribution)||void 0,tags:Array.isArray(e.tags)?e.tags.map(fe).filter(Boolean):[],sourceRepository:fe(e.sourceRepository)||fe(e.source_repository)||void 0,sourcePath:fe(e.sourcePath)||fe(e.source_path)||void 0,issues:t}}function La(e,t,o){let r=fe(e.name)||`Block ${o+1}`,i=(Array.isArray(e.ports)?e.ports:[]).map((d,a)=>{let c=fe(d.label)||fe(d.name)||`Port ${a+1}`,l=Zc(d.connectorType??d.connector_type),b=qc(fe(d.type),l),f=l??Jc(b),p={id:fe(d.id)||ol(t,o,a,c),label:c,type:b,connectorType:f};if(d.position){let m=d.position,x=fe(m.side),P={},N=false;x&&["top","right","bottom","left"].includes(x)&&(P.side=x,N=true);let v=ut(m.offsetPercent)??ut(m.offset_percent);v!==void 0&&(P.offsetPercent=v,N=true);let C=ut(m.offsetPx)??ut(m.offset_px);C!==void 0&&(P.offsetPx=C,N=true);let H=ut(m.xPercent)??ut(m.x_percent);H!==void 0&&(P.xPercent=H,N=true);let w=ut(m.yPercent)??ut(m.y_percent);w!==void 0&&(P.yPercent=w,N=true),N&&(p.position=P);}return p});return {name:r,ports:i}}function nl(e){let t=[],o=Qc(e.role),r=e.uHeight,n=el(r),i=tl(e.width),d=e.frontBlocks.map((c,l)=>La(c,"front",l)),a=e.rearBlocks.map((c,l)=>La(c,"rear",l));return {role:o,mountClass:n,uHeight:r,width:i,frontFace:{portBlocks:d,imageUrl:e.frontImageUrl,imageAttribution:e.frontImageAttribution},rearFace:{portBlocks:a,imageUrl:e.rearImageUrl,imageAttribution:e.rearImageAttribution},issues:t}}function il(e,t){let o=new Set(e.portBlocks.map(i=>i.name)),r=new Set(t.portBlocks.map(i=>i.name)),n=[...o].filter(i=>r.has(i));return n.length===0?{front:e,rear:t}:{front:{...e,portBlocks:e.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Front \xB7 ${i.name}`}:i)},rear:{...t,portBlocks:t.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Rear \xB7 ${i.name}`}:i)}}}function al(e){let t=[],{front:o,rear:r}=il(e.frontFace,e.rearFace),n=e.role;return (!n||n==="device")&&[...o.portBlocks,...r.portBlocks].some(d=>d.ports.some(a=>a.type&&a.type.startsWith("power")))&&e.mountClass==="zero-u"&&(n="pdu"),{frontFace:o,rearFace:r,mountClass:e.mountClass,role:n,issues:t}}function Xo(e){return e.portBlocks.reduce((t,o)=>t+o.ports.length,0)}function sl(e,t){let o=[],r=[];for(let p of t.frontFace.portBlocks)for(let m of p.ports)r.push({id:m.id,face:"front"});for(let p of t.rearFace.portBlocks)for(let m of p.ports)r.push({id:m.id,face:"rear"});let n=new Map;for(let{id:p}of r)n.set(p,(n.get(p)??0)+1);for(let[p,m]of n)m>1&&o.push({severity:"error",code:"DUPLICATE_PORT_ID",message:`Duplicate port id "${p}" found ${m} times`,path:`ports.${p}`});let i=e.frontBlocks.reduce((p,m)=>p+(Array.isArray(m.ports)?m.ports.length:0),0),d=e.rearBlocks.reduce((p,m)=>p+(Array.isArray(m.ports)?m.ports.length:0),0),a=Xo(t.frontFace),c=Xo(t.rearFace);a!==i&&o.push({severity:"error",code:"FRONT_PORT_COUNT_MISMATCH",message:`Front port count mismatch: raw=${i}, parsed=${a}`,path:"faces.front"}),c!==d&&o.push({severity:"error",code:"REAR_PORT_COUNT_MISMATCH",message:`Rear port count mismatch: raw=${d}, parsed=${c}`,path:"faces.rear"});let l=new Set(r.map(p=>p.id)),b=new Set(r.filter(p=>p.face==="front").map(p=>p.id)),f=new Set(r.filter(p=>p.face==="rear").map(p=>p.id));for(let p of e.rawLinks)p.frontPortId&&!b.has(p.frontPortId)&&!l.has(p.frontPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_FRONT_PORT_MISSING",message:`Pass-through link references unknown front port "${p.frontPortId}"`,path:"frontRearPortLinks"}),p.rearPortId&&!f.has(p.rearPortId)&&!l.has(p.rearPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_REAR_PORT_MISSING",message:`Pass-through link references unknown rear port "${p.rearPortId}"`,path:"frontRearPortLinks"});return {valid:!o.some(p=>p.severity==="error"),issues:o,portCounts:{front:a,rear:c}}}function dl(e,t,o){let r=e.rawLinks.filter(i=>!!i.frontPortId&&!!i.rearPortId).map(i=>({frontPortId:i.frontPortId,rearPortId:i.rearPortId})),n=e.sourceRepository?{kind:"netbox",repository:e.sourceRepository,path:e.sourcePath}:void 0;return {templateSchemaVersion:2,id:e.id,slug:e.slug,manufacturer:e.manufacturer,model:e.model,role:o.role,mountClass:o.mountClass,uHeight:t.uHeight,width:t.width,faces:{front:o.frontFace,rear:o.rearFace},frontRearPortLinks:r,images:{front:o.frontFace.imageUrl??null,rear:o.rearFace.imageUrl??null},source:n,tags:e.tags.length>0?e.tags:void 0}}function cl(e){let t=rl(e),o=nl(t),r=al(o),n=sl(t,r);return n.issues.push(...t.issues,...o.issues,...r.issues),n.valid?{template:dl(t,o,r),report:n}:{template:null,report:n}}function ll(e){return Xo(e)}function ul(e,t,o){let r=[],n=Xo(e.faces.front),i=Xo(e.faces.rear);return t!==n&&r.push({severity:"error",code:"RENDER_FRONT_COUNT_MISMATCH",message:`Rendered front handle count (${t}) does not match template (${n})`,path:"faces.front"}),o!==i&&r.push({severity:"error",code:"RENDER_REAR_COUNT_MISMATCH",message:`Rendered rear handle count (${o}) does not match template (${i})`,path:"faces.rear"}),r}
2
- exports.COUPLERS_PER_PANEL=Nd;exports.COUPLER_SLOT_HEIGHT_PX=yr;exports.COUPLER_WIDTH_PX=kd;exports.CableNode=wn;exports.ClosureNode=Fn;exports.CouplerNode=kn;exports.DeviceNode=po;exports.DevicePlacementError=xo;exports.DiagramErrorBoundary=Wn;exports.FIBER_COLORS_12=ci;exports.FiberEdge=rr;exports.FiberNode=Zr;exports.FibreCableWithTubesExpanded=Cc;exports.FibreFlowMap=Nc;exports.FibreSplitNode=_n;exports.HANDLE_EXTENSION_PX=Eo;exports.MultiTubeCableNode=Nn;exports.NetworkDiagram=On;exports.PANEL_BORDER_WIDTH=Li;exports.PANEL_HEADER_HEIGHT=Jt;exports.PANEL_HEIGHT_PX=hr;exports.PANEL_PADDING=qt;exports.PANEL_TUBE_TRAY_SPACING=Bi;exports.PANEL_WIDTH_PX=mr;exports.POWER_CONNECTORS=en;exports.PatchPanelNode=In;exports.PowerEdge=Jr;exports.RACK_HEADER_HEIGHT=ht;exports.RACK_WIDTH_PX=Xr;exports.RackNode=Kr;exports.SpliceNode=ln;exports.SplicePlacementError=No;exports.SpliceTrayNode=bn;exports.TEMPLATE_SCHEMA_VERSION=$a;exports.TubeNode=mn;exports.U_HEIGHT_PX=Ze;exports.VerticalPDU=sn;exports.Width=xi;exports.addDeviceToRack=zc;exports.addSpliceToTray=Yc;exports.baseColorFor=Ue;exports.buildNodesFromRackConfig=Bc;exports.buildNodesFromSpliceConfig=Gc;exports.calculateClosureDimensions=Tn;exports.calculateCouplerRightX=Cd;exports.calculateCouplerSlotSpacing=Td;exports.calculateCouplerSpacing=ji;exports.calculateDevicePositionFromU=lo;exports.calculatePanelDimensions=vn;exports.calculateSlotPositionFromY=Gi;exports.calculateSplicePositionFromNumber=fd;exports.calculateUPositions=Ac;exports.calculateYFromSlotPosition=Xi;exports.countTemplateFacePorts=ll;exports.createNetworkDiagramStore=Mn;exports.createRackConfigFromNodes=Oc;exports.createSpliceConfigFromNodes=Xc;exports.fiberSolidOrStriped=qr;exports.findNearestRack=vr;exports.findNextAvailableHolderPosition=Wo;exports.findNextAvailableUPosition=er;exports.generateLayout=Tc;exports.getConnectorConfig=Ni;exports.getCouplerDimensions=Cn;exports.getDeviceConnectorType=Ao;exports.getFiberColor=Vt;exports.getInnerContentWidth=Vi;exports.getPDUPortType=ir;exports.getPanelHeight=Pd;exports.getPanelWidth=Ui;exports.getPowerPortStyle=jt;exports.getRackBounds=Qi;exports.getStatusColor=dt;exports.getTrayDimensions=Oi;exports.getTubeDimensions=wr;exports.inventoryCableToNetworkEdge=Pa;exports.inventoryDeviceToNetworkNode=ka;exports.inventoryRackToNetworkNode=Na;exports.inventoryToNetworkDiagram=vc;exports.isHighPowerConnector=Ss;exports.isPointInRack=ea;exports.isStriped=Ut;exports.isUPositionAvailable=Yr;exports.netboxCableToNetworkEdge=Da;exports.netboxDeviceToNetworkNode=Fa;exports.netboxRackToNetworkNode=Ha;exports.netboxToNetworkDiagram=$c;exports.parseNetboxTemplate=cl;exports.removeDeviceFromRack=Uc;exports.removeSpliceFromTray=Kc;exports.replaceEdge=$e;exports.snapToCouplerPosition=vd;exports.snapToSplicePosition=pn;exports.snapToUPosition=Qo;exports.updateDeviceUPosition=di;exports.updateDeviceUPositionInSchema=Wc;exports.updateSpliceHolderPosition=jc;exports.useDiagramEdges=Ln;exports.useDiagramNodes=An;exports.useNetworkDiagram=Md;exports.validateAndSnapDevice=cs;exports.validateRackDevicePlacements=Gn;exports.validateRenderFidelity=ul;exports.validateSplicePlacements=Xn;//# sourceMappingURL=index.js.map
1
+ 'use strict';var Qe=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Qe__default=/*#__PURE__*/_interopDefault(Qe);var Je=20,xt=60,Qr=300,Ho=5;function pi(e){return e==="system"?typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark":e}function fi(e,t){let r=pi(e)==="light"?"react-flow-light":"react-flow-dark";return t?`${r} ${t}`:r}function gi(e){return pi(e)==="light"?"#e5e5e5":"#2a2a2a"}function bi(e,t){return {width:"100%",height:"100%",...t}}var gs=["device","server","switch","router"],bs=new Set(gs);function Fo(e){return typeof e=="string"&&bs.has(e)}function Ke(e){return !!e&&Fo(e.type)}var ms=24;function hs(e){return e?.rackLayout==="split-face"?"split-face":"single-face"}function He(e){return hs(e)==="split-face"}function At(e){return typeof e?.rackFaceGapPx=="number"&&Number.isFinite(e.rackFaceGapPx)&&e.rackFaceGapPx>=0?e.rackFaceGapPx:ms}function Mt(e){return e?.rackWidthPx||300}function Do(e){let t=Mt(e);return He(e)?t*2+At(e):t}function Oe(e){return e?.mountMode==="front"||e?.mountMode==="rear"||e?.mountMode==="both"?e.mountMode:"both"}function $t(e){return e==="front"?["front"]:e==="rear"?["rear"]:["front","rear"]}function tr(e,t){let o=new Set($t(e));return $t(t).some(n=>o.has(n))}function or(e,t){return He(e)&&Oe(t)==="front"?Mt(e)+At(e):0}function mi(e,t){return He(e)&&Oe(t)==="both"?Do(e):Mt(e)}var hi=e=>{if(typeof e.parentId=="string")return e.parentId;if(typeof e.parentNode=="string")return e.parentNode},Nt=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):t,ys=()=>"bottom-up",Yt=e=>e.data.uNumberingDirection||ys(),rr=(e,t,o)=>o==="bottom-up"?t-e+1:e,nr=(e,t,o)=>o==="bottom-up"?t-e+1:e;var ir=(e,t,o,r)=>{let n=hi(e);if(!n||n!==t.id)return o;let i=Nt(e.data.uHeight,1),d=Nt(t.data.uHeight,42),a=Yt(t),c=60,l=o.y-c,g=Math.round(l/20)+1,f;a==="bottom-up"?f=rr(g,d,a)-i+1:f=rr(g,d,a);let p=d-i+1,u=Math.max(1,Math.min(p,f));if(a==="top-down"&&f<=1&&(u=1),!jt(t,e,u,r)){let h=ar(t,e,r,u);if(h!==void 0)u=h;else {let x=Nt(e.data.uPosition,0);if(x>0&&jt(t,e,x,r))u=x;else return {x:or(t.data,e.data),y:e.position?.y??o.y,uPosition:x>0?x:void 0}}}let y;if(a==="bottom-up"){let h=u+i-1,x=nr(h,d,a);y=c+(x-1)*20-1;}else {let h=nr(u,d,a);y=c+(h-1)*20-1;}return {x:or(t.data,e.data),y,uPosition:u}},jt=(e,t,o,r)=>{let n=Nt(t.data.uHeight,1),i=Nt(e.data.uHeight,42);if(o<1||o+n-1>i)return false;let d=r.filter(l=>Fo(l.type)&&hi(l)===e.id&&l.id!==t.id),a=He(e.data),c=Oe(t.data);for(let l of d){let g=Nt(l.data.uPosition,1),f=Nt(l.data.uHeight,1),p=o,u=o+n-1,y=g,h=g+f-1;if(p<=h&&u>=y){if(a){let x=Oe(l.data);if(!tr(c,x))continue}return false}}return true},ar=(e,t,o,r=1)=>{let n=Nt(t.data.uHeight,1),d=Nt(e.data.uHeight,42)-n+1;if(d<1)return;let a=Number.isFinite(r)?Math.floor(r):1,c=Math.max(1,Math.min(d,a));for(let l=c;l<=d;l++)if(jt(e,t,l,o))return l;for(let l=1;l<c;l++)if(jt(e,t,l,o))return l},go=(e,t,o=1,r)=>{let n=60,i=Yt(e),d=e.data.uHeight||42,a=nr(t,d,i),c;if(i==="bottom-up"){let l=t+o-1,g=nr(l,d,i);c=n+(g-1)*20-1;}else c=n+(a-1)*20-1;return {x:or(e.data,r),y:c}},yi=(e,t,o)=>{let r=e.data.uHeight||1,n=go(t,o,r,e.data),i=Array.isArray(e.data.ports)?e.data.ports:void 0;return {...e,position:n,data:{...e.data,ports:i,uPosition:o}}},ws=(e,t)=>{let o=e.data.uPosition||1,r=e.data.uHeight||1,n=t.data.uHeight||42,i=Math.max(1,Math.min(n-r+1,o));return i!==o?yi(e,t,i):e};function gt(e){switch(e){case "active":return "#10b981";case "inactive":return "#ef4444";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var en=({data:e,selected:t,id:o,onViewChange:r,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:a=0,status:c="active",uHeight:l=42,face:g="front",customHeaderText:f}=e,p=He(e),u=Do(e),y=Mt(e),h=At(e),{getNodes:x,setNodes:k}=reactflow.useReactFlow(),v=x(),[C,S]=Qe.useState(e.showUMarkers!==void 0?e.showUMarkers:true),N=()=>{let A=Yt({data:e})==="bottom-up"?"top-down":"bottom-up";k(_=>_.map(U=>U.id===o?{...U,data:{...U.data,uNumberingDirection:A}}:U));},R=()=>{if(p)return;let E=g==="front"?"rear":"front";n?n(o,E):r?v.filter(_=>_.parentId===o).forEach(_=>{r(_.id,E);}):k(A=>A.map(_=>_.id===o?{..._,data:{..._.data,face:E}}:_.parentId===o?{..._,data:{..._.data,view:E}}:_));},D=()=>{let E=[],A=60,_=Yt({data:e});for(let U=1;U<=l;U++){let se=A+(U-1)*20-4,Y=rr(U,l,_);E.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${se}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:Y},U));}return E};return jsxRuntime.jsxs("div",{className:`rack-node ${t?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${gt(c)}`,borderRadius:"8px",padding:0,width:`${u}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxRuntime.jsxs("span",{children:[typeof a=="number"?a:0," ports"]})," \u2022 ",l,"U \u2022 ",p?"rear|front":g]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),S(!C);},style:{background:C?"#10b981":"#374151",color:C?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${C?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),N();},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 ${Yt({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Yt({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),!p&&jsxRuntime.jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),R();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${g==="front"?"rear":"front"} view`,children:g==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"},children:p&&jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[jsxRuntime.jsx("div",{style:{width:`${y}px`,borderRight:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.15)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Rear"}),jsxRuntime.jsx("div",{style:{width:`${h}px`}}),jsxRuntime.jsx("div",{style:{width:`${y}px`,borderLeft:"1px dashed rgba(156,163,175,0.35)",background:"rgba(17,24,39,0.25)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"4px",fontSize:"8px",color:"#9ca3af",fontWeight:"bold",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Front"})]})}),C&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:D()})]})};var tn=({data:e,selected:t})=>{let{label:o,status:r="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${t?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${gt(r)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:gt(r),borderRadius:"50%"}})]})};var wi=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function Ve(e){let t=(e-1)%12;return wi[t]}function Zt(e){return e>12}function kt(e,t){let o=t?.base??Ve(e),r=t?.striped??Zt(e),n=r?`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`:void 0;return {base:o,striped:r,backgroundImage:n}}function on(e){let t=kt(e);return t.backgroundImage?{background:t.base,backgroundImage:t.backgroundImage}:{background:t.base}}function qt(e){return Ve(e)}function Pt(e){return e.map(t=>({base:Ve(t),striped:Zt(t)}))}function Cs(e,t,o,r,n,i,d,a){let c=Pt(o),l=c.length,g=r?1.2:1,f=!!a?.highlight,p=r?2:1.5,u=a?.highlightWidth??p*3,y=a?.highlightColor??c[0]?.base??"#22d3ee";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[f&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:y,strokeWidth:u,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${p}px`,"--rn-edge-highlight-to":`${u}px`}}),c.map((h,x)=>{let v=(l-x)*g;return jsxRuntime.jsx("path",{d:t,stroke:h.base,strokeWidth:v,fill:"none",strokeLinecap:"butt",opacity:h.striped?.9:1,style:n},`${e}-ribbon-${x}`)}),c.some(h=>h.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:r&&a&&(a.bandwidth||a.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${d}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[a.bandwidth&&jsxRuntime.jsx("div",{children:a.bandwidth}),a.length&&jsxRuntime.jsxs("div",{children:[a.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var cr=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},className:g})=>{let[f,p,u]=reactflow.getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),{bandwidth:y,length:h,color:x="#00FFFF",striped:k=false,ribbonFiberIds:v,isRibbon:C,highlight:S,highlightColor:N,highlightWidth:R}=a||{},D=!!S;if((C||v&&v.length>=6&&v.length<=12)&&v)return Cs(e,f,v,c??false,l??{},p,u,a);let A=c?3:2,_=R??A*3,U={...l,stroke:x,strokeWidth:A,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[D&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:f,style:{...l,stroke:N??x,strokeWidth:_,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${A}px`,"--rn-edge-highlight-to":`${_}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:f,style:U}),k&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&a&&(y||h)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${p}px,${u}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${x}`,pointerEvents:"none",zIndex:9999},children:[y&&jsxRuntime.jsx("div",{children:y}),h&&jsxRuntime.jsxs("div",{children:[h,"m"]})]})})]})};var rn=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,style:a={},data:c,markerEnd:l})=>{let[g]=reactflow.getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),f=c?.connectorType||"C13",p=c?.metadata??{},u=typeof c?.powerStrokeWidth=="number"?c.powerStrokeWidth:typeof p.strokeWidth=="number"?p.strokeWidth:void 0,y=typeof c?.powerStrokeDasharray=="string"?c.powerStrokeDasharray:typeof p.strokeDasharray=="string"?p.strokeDasharray:void 0,h=typeof c?.powerOpacity=="number"?c.powerOpacity:typeof p.opacity=="number"?p.opacity:void 0;return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:g,markerEnd:l,style:(()=>{let v=u??(f==="C19"?5:3),C=y??(f==="C19"?"none":"6,3");return {...{stroke:c?.color||"#f59e0b",strokeWidth:v,strokeLinecap:"round",strokeLinejoin:"round",...h!==void 0?{opacity:h}:{}},strokeDasharray:C,...a}})()})};function Es(e,t,o,r,n,i,d,a,c,l,g){let f=Pt(a),p=f.length,u=c?1.8:1.5,y=!!g?.highlight,h=c?3:2.5,x=g?.highlightWidth??h*3,k=g?.highlightColor??f[0]?.base??"#22d3ee",[v,C,S]=reactflow.getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[y&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:v,style:{...l,stroke:k,strokeWidth:x,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${h}px`,"--rn-edge-highlight-to":`${x}px`}}),f.map((N,R)=>{let E=(p-R)*u;return jsxRuntime.jsx("path",{d:v,stroke:N.base,strokeWidth:E,fill:"none",strokeLinecap:"butt",opacity:N.striped?.9:1,style:l},`${e}-ribbon-${R}`)}),f.some(N=>N.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&g&&(g.bandwidth||g.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${C}px,${S}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[g.bandwidth&&jsxRuntime.jsx("div",{children:g.bandwidth}),g.length&&jsxRuntime.jsxs("div",{children:[g.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[a.length,"F"]})]})})]})}var Pi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",ribbonFiberIds:p,isRibbon:u,highlight:y,highlightColor:h,highlightWidth:x}=a||{},k=!!y;if((u||p&&p.length>=6&&p.length<=12)&&p)return Es(e,t,o,r,n,i,d,p,c??false,l??{},a);let C=c?4:3,S=x??C*3,N={...l,stroke:f,strokeWidth:C};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[k&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:reactflow.getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d})[0],style:{...l,stroke:h??f,strokeWidth:S,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${S}px`}}),jsxRuntime.jsx(reactflow.SmoothStepEdge,{...g,id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:N})]})};function Fs({sourceX:e,sourceY:t,targetX:o,targetY:r,sourcePosition:n,targetPosition:i}){let d=n===reactflow.Position.Left||n===reactflow.Position.Right,a;if(d){let c=(e+o)/2;a=`M ${e},${t} L ${c},${t} L ${c},${r} L ${o},${r}`;}else {let c=(t+r)/2;a=`M ${e},${t} L ${e},${c} L ${o},${c} L ${o},${r}`;}return a}function Ds(e,t,o,r,n,i){let d=Pt(o),a=d.length,c=r?1.2:1,l=!!i?.highlight,g=r?2:1.5,f=i?.highlightWidth??g*3,p=i?.highlightColor??d[0]?.base??"#22d3ee",u=t.match(/M\s+([\d.]+),([\d.]+).*L\s+([\d.]+),([\d.]+)/),y=u?(parseFloat(u[1])+parseFloat(u[3]))/2:0,h=u?(parseFloat(u[2])+parseFloat(u[4]))/2:0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:t,style:{...n,stroke:p,strokeWidth:f,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${g}px`,"--rn-edge-highlight-to":`${f}px`}}),d.map((x,k)=>{let C=(a-k)*c;return jsxRuntime.jsx("path",{d:t,stroke:x.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:x.striped?.9:1,style:n},`${e}-ribbon-${k}`)}),d.some(x=>x.striped)&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:r&&i&&(i.bandwidth||i.length)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${y}px,${h}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${d[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsxRuntime.jsx("div",{children:i.bandwidth}),i.length&&jsxRuntime.jsxs("div",{children:[i.length,"m"]}),jsxRuntime.jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var Ri=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",striped:p=false,ribbonFiberIds:u,isRibbon:y,highlight:h,highlightColor:x,highlightWidth:k}=a||{},v=!!h,C=Fs({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d});if((y||u&&u.length>=6&&u.length<=12)&&u)return Ds(e,C,u,c??false,l??{},a);let N=c?3:2,R=k??N*3,D={...l,stroke:f,strokeWidth:N,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[v&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:C,style:{...l,stroke:x??f,strokeWidth:R,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${N}px`,"--rn-edge-highlight-to":`${R}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:C,style:D}),p&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:C,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var Ii=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,style:a={},data:c,markerEnd:l,selected:g})=>{let{color:f="#6366f1",label:p,highlight:u,highlightColor:y,highlightWidth:h}=c||{},x=!!u,k=8,v=h??k*1.8,[C,S,N]=reactflow.getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:d}),R={...a,stroke:f,strokeWidth:k,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[x&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-highlight`,path:C,style:{...a,stroke:y??f,strokeWidth:v,opacity:.85,strokeDasharray:"18 12",filter:`drop-shadow(0 0 8px ${y??f}) drop-shadow(0 0 16px ${y??f})`,"--rn-edge-highlight-from":`${k}px`,"--rn-edge-highlight-to":`${v}px`}}),jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:C,markerEnd:l,style:R}),p&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${S}px,${N}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:p})})]})};var Ei=(o=>(o.FULL="full",o.HALF="half",o))(Ei||{});var an={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},AC:{type:"AC",color:"#60a5fa",borderColor:"#2563eb",amperage:15,voltage:120,phases:1}};function Bt(e){let t=an[e];if(!t)throw new Error(`Unknown connector type: ${e}`);let o=t.amperage===16,r=t.type==="AC",n=o?12:r?10:8*1.3,i=o?10:r?7:5*1.3,d=o||r?{borderRadius:r?"2px":"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:n,height:i,color:t.color,borderColor:t.borderColor,fontSize:o?"3px":r?"3.5px":"4px",...d}}function Hi(e){let t=an[e];if(!t)throw new Error(`Unknown connector type: ${e}`);return t}function Ls(e){return Hi(e).amperage===16}function ur(e){return e%10<8?"C13":"C19"}function sn(e){let t=e.toLowerCase();return t.includes("mx304")||t.includes("mx480")||t.includes("mx960")?"C20":"C14"}var Bs=/-(source|target)$/i;function We(e){return e?e.replace(Bs,""):""}function Ct(e){return typeof e=="string"&&e.includes("power")}function vt(e,t){return typeof t.id=="string"&&t.id.length>0?t.id:Ct(t.type)?t.label:`${e}-${t.label}`}function pr(e){let t=We(e).toLowerCase();return t.startsWith("pwr")||t.includes("power")}var Ws="#6b7280",zs="#374151",dn="#10b981",Us="100% 100%",fr=1,Vs={smf:"#fbbf24",cat6:"#8b5cf6",om3:"#06b6d4",om4:"#8b5cf6",om5:"#84cc16",cat5e:"#3b82f6",cat6a:"#ef4444",cat7:"#f97316",fiber:"#3b82f6",ethernet:"#10b981"},Gs=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,Xs=/^data:image\//i,js=typeof window<"u"?Qe__default.default.useLayoutEffect:Qe__default.default.useEffect;function Ys(e){return (e??"").toLowerCase().replace(/_/g,"-")}function Ks(e){return !Gs.test(e)&&!e.startsWith("//")}function Zs(e){if(!e)return;let t=e.trim();if(t){if(Ks(t))return t;try{let o=new URL(t),r=o.protocol.toLowerCase();return r==="https:"||r==="blob:"?o.href:r==="data:"&&Xs.test(t)?t:void 0}catch{return}}}function qs(e){return `url(${JSON.stringify(e)})`}function un(e){return Ct(e.type)}function pn(e,t){if(typeof e.connectorType=="string"&&e.connectorType.trim().length>0)return e.connectorType;let o=String(e.type??"").toLowerCase();return o.includes("c19")||o.includes("c20")?"C19":o.includes("c13")||o.includes("c14")?"C13":o.includes("power_ac")?"AC":sn(t)}function cn(e,t){return vt(e,t)}function Js(e,t,o,r,n){let i=t.length>0||!!r,d=o.length>0||!!n;return e||(i?"front":d?"rear":"front")}function Qs(e,t){return t===true||e==="fill"?Us:e==="none"?"auto":e==="scale-down"?"contain":e??"cover"}function ed(e){return un(e)?e.type==="power_c19"?"#fbbf24":"#f59e0b":e.type==="console"||e.type==="mgmt"?"#8b5cf6":e.type==="usb"?dn:e.cableType?Vs[e.cableType]??dn:dn}function td(e){return e.connected?ed(e):Ws}function Di(e){return e.map(t=>{let o=t.ports.map(r=>{let n=r.position?[r.position.side??"",r.position.offsetPercent??"",r.position.offsetPx??"",r.position.xPercent??"",r.position.yPercent??""].join(":"):"";return [r.id??"",r.label,r.type??"",r.connected?"1":"0",r.cableType??"",r.connectorType??"",n].join(":")}).join(",");return `${t.name}[${o}]`}).join("|")}function od(e,t,o,r,n=false){return {width:`${e}px`,height:`${t}px`,minWidth:n?`${e}px`:void 0,minHeight:n?`${t}px`:void 0,background:o,border:`0.5px solid ${r}`,boxSizing:"border-box",borderRadius:"1px",cursor:"pointer",zIndex:2}}function rd(e){let t=Math.max(5,Math.min(7,Math.round(e*.02))),o=Math.max(8,Math.min(10,Math.round(t*1.45)));return {width:t,height:o}}function Lo(e){return Math.max(0,Math.min(100,e))}function it(e,t,o){return Math.max(t,Math.min(o,e))}function ln(e){return typeof e.position?.xPercent=="number"&&typeof e.position?.yPercent=="number"}function nd(e,t,o,r,n){let i=[];for(let g of e)for(let f of g.ports)ln(f)&&i.push({handleId:cn(g.name,f),xPercent:Lo(f.position.xPercent),yPercent:Lo(f.position.yPercent),side:f.position?.side});if(i.length===0)return {heightByHandleId:new Map,bottomAnchoredHandleIds:new Set};let d=new Set,a=[...new Set(i.map(g=>Number(g.yPercent.toFixed(2))))].sort((g,f)=>g-f);if(a.length>=2){let g=a[a.length-1];for(let f of i)f.side==="top"&&Math.abs(f.yPercent-g)<=.15&&d.add(f.handleId);}let c=new Map,l=Math.max(1.75,(r+1)/Math.max(t,1)*100+.2);for(let g of i){let f=Number.POSITIVE_INFINITY;for(let h of i){if(h.handleId===g.handleId||Math.abs(h.xPercent-g.xPercent)>l)continue;let k=Math.abs(h.yPercent-g.yPercent);k<=0||(f=Math.min(f,k));}if(!Number.isFinite(f))continue;let p=o*f/100,u=Math.floor(p-.25),y=it(u,1,n);y<n&&c.set(g.handleId,y);}return {heightByHandleId:c,bottomAnchoredHandleIds:d}}function id(e){switch(e){case "top":return reactflow.Position.Top;case "right":return reactflow.Position.Right;case "bottom":return reactflow.Position.Bottom;case "left":return reactflow.Position.Left;default:return reactflow.Position.Top}}function ad(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function sd(e,t,o,r,n,i,d){if(!e.position)return;if(typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number"){let h=Lo(e.position.xPercent),x=Lo(e.position.yPercent),k=d??e.position.side??ad(h,x),v=t/2+fr,C=Math.max(v,r-t/2),S=o/2+fr,N=Math.max(S,n-o/2),R=it(r*h/100,v,C),D=it(n*x/100,S,N);return {position:id(k),style:{left:`${R-t/2-fr}px`,top:`${D-o/2-fr}px`,right:"initial",bottom:"initial",transform:"none"}}}if(!e.position.side)return;let c=e.position.side,l=typeof e.position.offsetPercent=="number"?Lo(e.position.offsetPercent):void 0,g=typeof e.position.offsetPx=="number"?e.position.offsetPx:void 0,f=t/2,p=Math.max(f,r-t/2),u=o/2,y=Math.max(u,n-o/2);switch(c){case "top":{let h=g!==void 0?g:r*(l??50)/100,x=it(h,f,p);return {position:reactflow.Position.Top,style:{top:"0px",left:`${x}px`,right:void 0,bottom:void 0,transform:"translate(-50%, 50%)"}}}case "bottom":{let h=g!==void 0?g:r*(l??50)/100,x=it(h,f,p);return {position:reactflow.Position.Bottom,style:{bottom:"0px",left:`${x}px`,right:void 0,top:void 0,transform:"translate(-50%, -50%)"}}}case "left":{let h=g!==void 0?g:n*(l??50)/100,x=it(h,u,y);return {position:reactflow.Position.Left,style:{left:"0px",top:`${x}px`,right:void 0,bottom:void 0,transform:"translate(50%, -50%)"}}}case "right":{let h=g!==void 0?g:n*(l??50)/100,x=it(h,u,y);return {position:reactflow.Position.Right,style:{right:"0px",top:`${x}px`,left:void 0,bottom:void 0,transform:"translate(-50%, -50%)"}}}default:return}}function Mi(e,t,o,r){let n=o/2,i=Math.max(n,r-o/2);return t===1?(n+i)/2:n+e*(i-n)/(t-1)}function $i(e,t,o,r){let n=e%2===0,i=Math.ceil(t/2),d=Math.floor(t/2),a=Math.max(n?i:d,1),c=Math.floor(n?e/2:(e-1)/2),l=Mi(c,a,o,r);return n?{position:reactflow.Position.Top,style:{transform:"translateY(50%)",left:`${l-o/2}px`}}:{position:reactflow.Position.Bottom,style:{transform:"translateY(-50%)",left:`${l-o/2}px`}}}function _i(e,t,o,r,n,i){let d=e%2===0,a=Math.ceil(t/2),c=Math.floor(t/2),l=Math.max(d?a:c,1),g=Math.floor(d?e/2:(e-1)/2),f=Mi(g,l,o,n),p=1,u=it(Math.round(r*.75),1,4),y=Math.max(p,i-r-1),h=it(p+r+u,p,y),x=d?p:h;return {position:reactflow.Position.Top,style:{transform:"none",left:`${f-o/2}px`,top:`${x}px`,right:void 0,bottom:void 0}}}function dd(e,t,o,r,n){let i=pn(e,n),d=Bt(i),a;if(r<=20){let g=Math.max(2,r-d.height-2);a=`${o<=1?(2+g)/2:2+t*(g-2)/(o-1)}px`;}else a=`${25+t*50}%`;return {position:reactflow.Position.Right,style:{transform:"translateX(-50%)",top:a,width:`${d.width}px`,height:`${d.height}px`,background:d.color,border:`1px solid ${d.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:d.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:d.borderRadius,clipPath:d.clipPath}}}function cd(e,t,o,r){if(t===1){let n=Math.max(6,Math.round(r*.04)),i=Math.max(o/2,r-n-o/2);return {position:reactflow.Position.Top,style:{transform:"translateY(50%)",left:`${i}px`,right:void 0}}}return $i(e,t,o,r)}function ld(e,t,o,r,n,i,d,a,c){if(a==="patch-panel"||a==="switch")return $i(t,o,r,i);if(un(e)){let f=pn(e,c),p=Bt(f),u;if(d<=20){let x=Math.max(2,d-p.height-2);u=`${o<=1?(2+x)/2:2+t*(x-2)/(o-1)}px`;}else u=`${25+t*50}%`;return {position:reactflow.Position.Left,style:{transform:"translateX(50%)",top:u,width:`${p.width}px`,height:`${p.height}px`,background:p.color,border:`1px solid ${p.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:p.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:p.borderRadius,clipPath:p.clipPath}}}return {position:reactflow.Position.Right,style:{transform:"translate(-50%, -50%)",top:`${it(o<=1?d/2:n/2+t*Math.max(d-n,0)/Math.max(o-1,1),n/2,Math.max(n/2,d-n/2))}px`}}}function ud(e,t,o,r){if(e)return {primary:"target"};let n=t==="patch-panel";return t==="switch"||t==="router"?{primary:"source",secondary:"target"}:n?o==="rear"?{primary:"source",secondary:"target"}:{primary:"target",secondary:"source"}:{primary:r?"source":"target"}}var mo=({id:e,data:t,selected:o})=>{let r=reactflow.useUpdateNodeInternals(),{label:n,status:i="active",deviceType:d="server",manufacturer:a,uHeight:c=1,width:l="full",ports:g,rearPorts:f,view:p,rackWidthPx:u,frontImageUrl:y,rearImageUrl:h,imageFit:x,imagePosition:k,imageRepeat:v,stretchToFit:C}=t,S=Qe__default.default.useMemo(()=>Array.isArray(g)?g:[],[g]),N=Qe__default.default.useMemo(()=>Array.isArray(f)?f:[],[f]),R=Ys(d),D=u??300,E=He(t),A=Oe(t),_=Js(p,S,N,y,h),U=Qe__default.default.useMemo(()=>E?$t(A):[_],[E,A,_]),se=U[0]??_,Y=E&&A==="both",ee=c*20,ie=At(t),z=D+ie,V=Qe__default.default.useMemo(()=>[E?"split":"single",A,U.join(","),se,R,n,ee.toString(),D.toString(),z.toString(),Di(S),Di(N)].join("|"),[E,A,U,se,R,n,ee,D,z,S,N]);js(()=>{r(e);},[V,e,r]);let B=Qe__default.default.useCallback(j=>{let ke=Zs(j==="rear"?h:y);return ke?{backgroundImage:qs(ke),backgroundSize:Qs(x,C),backgroundPosition:k??"center",backgroundRepeat:v??"no-repeat"}:{}},[h,y,x,C,k,v]),O=Qe__default.default.useMemo(()=>B("front"),[B]),X=Qe__default.default.useMemo(()=>B("rear"),[B]),te=se==="rear"?X:O,M,L;if(E)M=`${mi(t,t)+4}px`,L=void 0;else {let j=D+4,we=Math.floor(D/2);M=l==="half"?`${we}px`:`${j}px`,L=l==="half"?`${we}px`:void 0;}let de=R==="server"&&c===1,ae=gt(i),ce={"--rn-device-bg-image":Y?"none":String(te.backgroundImage??"none"),"--rn-device-bg-position":String(te.backgroundPosition??"center"),"--rn-device-bg-repeat":String(te.backgroundRepeat??"no-repeat"),"--rn-device-bg-size":String(te.backgroundSize??"cover"),"--rn-device-border-color":ae,"--rn-device-box-shadow":o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)","--rn-device-height":`${ee}px`,"--rn-device-left":L??"auto","--rn-device-status-color":ae,"--rn-device-translate-y":de?"-1px":"0px","--rn-device-width":M},q=Qe__default.default.useMemo(()=>{let j=new Set;for(let we of S)for(let ke of we.ports)j.add(cn(we.name,ke));return j},[S]),xe=Qe__default.default.useCallback((j,we)=>we==="rear"&&Y&&q.has(j)?`${j}--rear`:j,[q,Y]),Ce=Qe__default.default.useCallback((j,we,ke=0,st=D)=>{let le=[];if(j.length===0)return le;let{width:Xe,height:Fe}=rd(st),{heightByHandleId:Or,bottomAnchoredHandleIds:Pe}=nd(j,st,ee,Xe,Fe),De=j.reduce((ze,Ze)=>ze+Ze.ports.length,0),Ut=(R==="switch"||R==="patch-panel")&&De>=24,Ko=R==="switch"||R==="patch-panel";for(let ze of j)for(let Ze=0;Ze<ze.ports.length;Ze+=1){let ve=ze.ports[Ze],ot=cn(ze.name,ve),dt=un(ve),Et=Xe,ct=Fe;if(dt){let yt=pn(ve,n),co=Bt(yt);Et=co.width,ct=co.height;}else if(ln(ve)){let yt=Or.get(ot);yt!==void 0&&(ct=yt,Et=it(Math.round(ct*1.2),3,Xe));}let lt=td(ve),Zo=ve.connected?lt:zs,Wr=!dt&&ln(ve)&&ct<Fe,qo=od(Et,ct,lt,Zo,Wr),Vt=we==="front"?dt?dd(ve,Ze,ze.ports.length,ee,n):Ut?_i(Ze,ze.ports.length,Xe,Fe,st,ee):cd(Ze,ze.ports.length,Xe,st):!dt&&Ut?_i(Ze,ze.ports.length,Xe,Fe,st,ee):ld(ve,Ze,ze.ports.length,Xe,Fe,st,ee,R,n),Gt=sd(ve,Et,ct,st,ee,void 0,Ko&&Pe.has(ot)?"bottom":void 0),Ht=Gt?dt?{position:Gt.position,style:{...Vt.style,...Gt.style}}:Gt:Vt,_e={...{...qo,...Ht.style}};_e.left!==void 0&&ke!==0&&(typeof _e.left=="number"?_e.left=`${_e.left+ke}px`:_e.left=`calc(${_e.left} + ${ke}px)`),Y&&_e.left===void 0&&(Ht.position===reactflow.Position.Left?(_e.left=`${ke}px`,_e.right=void 0):Ht.position===reactflow.Position.Right&&(_e.left=`${ke+st}px`,_e.right=void 0));let Ft=xe(ot,we),ut=ud(dt,R,we,ve.connected);if(ut.secondary){let yt=R==="switch"||R==="router"?{..._e,background:"transparent",border:"none",opacity:0}:_e,co=R==="switch"||R==="router"?`${ze.name} - ${ve.label} (input) ${ve.connected?"(connected)":"(disconnected)"}`:`${ze.name} - ${ve.label} (${ut.secondary}) ${ve.connected?"(connected)":"(disconnected)"}`;le.push(jsxRuntime.jsx(reactflow.Handle,{id:`${Ft}-${ut.secondary}`,type:ut.secondary,position:Ht.position,style:yt,title:co},`${Ft}-${ut.secondary}`));}le.push(jsxRuntime.jsx(reactflow.Handle,{id:Ft,type:ut.primary,position:Ht.position,style:_e,title:`${ze.name} - ${ve.label} ${ve.connected?"(connected)":"(disconnected)"}`,children:dt?Ze+1:void 0},Ft));}return le},[ee,D,n,R,xe,Y]),Ne=Qe__default.default.useMemo(()=>{let j=[];for(let we of U){if(we==="front"&&S.length>0){let ke=Y?z:0;j.push(...Ce(S,"front",ke,D));}we==="rear"&&N.length>0&&j.push(...Ce(N,"rear",0,D));}return j},[U,S,N,Ce,D,Y,z]);return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""} ${Y?"device-node--split-both":""}`,style:ce,children:[Y&&jsxRuntime.jsxs("div",{className:"device-node__split-face-layer",style:{position:"absolute",inset:0,display:"flex",pointerEvents:"none",zIndex:0},children:[jsxRuntime.jsx("div",{className:"device-node__split-face device-node__split-face--rear",style:{width:`${D}px`,backgroundImage:String(X.backgroundImage??"none"),backgroundPosition:String(X.backgroundPosition??"center"),backgroundRepeat:String(X.backgroundRepeat??"no-repeat"),backgroundSize:String(X.backgroundSize??"cover")}}),jsxRuntime.jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${ie}px`},children:jsxRuntime.jsx("div",{className:"device-node__face-bridge-line"})}),jsxRuntime.jsx("div",{className:"device-node__split-face device-node__split-face--front",style:{width:`${D}px`,backgroundImage:String(O.backgroundImage??"none"),backgroundPosition:String(O.backgroundPosition??"center"),backgroundRepeat:String(O.backgroundRepeat??"no-repeat"),backgroundSize:String(O.backgroundSize??"cover")}})]}),jsxRuntime.jsxs("div",{className:"device-node__content",style:{position:"relative",zIndex:1},children:[jsxRuntime.jsx("div",{className:"device-node__label",children:n}),c>1&&jsxRuntime.jsx("div",{className:"device-node__manufacturer",children:a})]}),c>1&&jsxRuntime.jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),jsxRuntime.jsx("div",{className:"device-node__status-indicator"}),Ne]})};var br=20,ho=3,hr=2,pd=1,gn=2,Li=6,fd=12;function fn(e){return Math.max(0,Math.min(100,e))}function bn(e,t,o){return Math.max(t,Math.min(o,e))}function gd(e,t){let o=[{side:"left",distance:e},{side:"right",distance:100-e},{side:"top",distance:t},{side:"bottom",distance:100-t}];return o.sort((r,n)=>r.distance-n.distance),o[0].side}function mr(e){if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13")return "C13";if(t==="C19")return "C19";if(t==="AC")return "AC"}function bd(e,t){let o=mr(e.connectorType);if(o)return o;let r=String(e.type??"").toLowerCase();return r.includes("c19")?"C19":r.includes("c13")?"C13":r.includes("power_ac")?"AC":t}function md(e){return Array.isArray(e.pduPortGroups)&&e.pduPortGroups.length>0?e.pduPortGroups:Array.isArray(e.rearPorts)&&e.rearPorts.length>0?e.rearPorts:Array.isArray(e.ports)&&e.ports.length>0?e.ports:[]}function hd(e,t){return !Array.isArray(e.portTypes)||e.portTypes.length===0?Array.from({length:t},(o,r)=>mr(ur(r))??"C13"):Array.from({length:t},(o,r)=>{let n=mr(e.portTypes?.[r]);return n||(mr(ur(r))??"C13")})}function yd(e,t){let o=md(e),r=hd(e,t);if(o.length===0)return Array.from({length:t},(d,a)=>({id:`${a+1}`,label:`${a+1}`,connectorType:r[a]??"C13",groupName:"Power"}));let n=[],i=0;return o.forEach(d=>{d.ports.forEach(a=>{let c=r[i]??"C13";n.push({id:vt(d.name,a),label:a.label,connectorType:bd(a,c),groupName:d.name,position:a.position}),i+=1;});}),n}function wd(e){return Bt(e.connectorType).height}function xd(e,t){return !e||t<=0?-1:e==="top"?0:e==="bottom"?t:Math.floor(t/2)}function Bi(e,t){let o=[],r=t>=0,n=r?bn(t,0,e.length):-1;for(let i=0;i<=e.length;i+=1)r&&i===n&&o.push({kind:"mgmt",height:fd}),i<e.length&&o.push({kind:"port",portIndex:i,height:wd(e[i]),groupName:e[i].groupName});return o}function Oi(e,t){return e.kind==="port"&&t.kind==="port"?e.groupName===t.groupName?gn:Li:gn}function Nd(e,t){let o=Bi(e,t);if(o.length===0)return Math.max(hr+ho+1,1);let r=0;for(let n=0;n<o.length;n+=1)r+=o[n].height,n<o.length-1&&(r+=Oi(o[n],o[n+1]));return hr+r+ho}function kd(e,t,o){let r=Bi(e,o);if(r.length===0)return {portCenters:[]};let n=[];for(let h=0;h<r.length-1;h+=1)n.push(Oi(r[h],r[h+1]));let i=r.reduce((h,x)=>h+x.height,0),d=n.reduce((h,x)=>h+x,0),a=i+d,c=Math.max(t-hr-ho,1),l=0,g=n,f=Math.max(0,c-a);if(f>0)if(n.length===0)l=f/2;else {let h=n.map(k=>k===Li?1.2:1),x=h.reduce((k,v)=>k+v,0);g=n.map((k,v)=>x<=0?k:k+f*h[v]/x);}let p=[],u,y=hr+l;for(let h=0;h<r.length;h+=1){let x=r[h],k=y+x.height/2;x.kind==="mgmt"?u=k:p[x.portIndex]=k,y+=x.height,h<r.length-1&&(y+=g[h]??gn);}return {portCenters:p,mgmtCenterY:u}}function Pd(e,t,o,r,n,i){if(!e)return {position:reactflow.Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let d=e.side,a=d==="left"?reactflow.Position.Left:d==="top"?reactflow.Position.Top:d==="bottom"?reactflow.Position.Bottom:reactflow.Position.Right,c=typeof e.offsetPercent=="number"?fn(e.offsetPercent):void 0,l=typeof e.offsetPx=="number"?e.offsetPx:void 0,g=typeof e.xPercent=="number"?fn(e.xPercent):void 0,f=typeof e.yPercent=="number"?fn(e.yPercent):void 0;if(g!==void 0&&f!==void 0){let y=d??gd(g,f),h=y==="left"?reactflow.Position.Left:y==="top"?reactflow.Position.Top:y==="bottom"?reactflow.Position.Bottom:reactflow.Position.Right,x=Math.max(o-ho,1),k=r*g/100,v=bn(x*f/100,i/2,Math.max(i/2,o-i/2));return {position:h,leftPx:k-n/2,topPx:v-i/2}}let p=g!==void 0?r*g/100:r-n/2-1,u=f!==void 0?Math.max(o-ho,1)*f/100:t;return d==="top"||d==="bottom"?(l!==void 0?p=l:c!==void 0&&(p=r*c/100),u=d==="top"?i/2:o-i/2):(l!==void 0?u=l:c!==void 0&&(u=Math.max(o-ho,1)*c/100),d==="left"?p=n/2:d==="right"&&(p=r-n/2-1)),u=bn(u,i/2,Math.max(i/2,o-i/2)),{position:a,leftPx:p-n/2,topPx:u-i/2}}function Cd(e,t){return jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(t-16)/2}px`,top:`${e-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit")}var hn=({data:e,selected:t})=>{let{label:o,status:r="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:a}=e,c=Math.max(0,i),l=yd(e,c),g=xd(a,l.length),f=n*4.2,p=Nd(l,g),u=Math.max(f-br,p),y=Math.max(d-pd*2,1),h=br+u,x=kd(l,u,g);return jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${t?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${gt(r)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${h}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",boxSizing:"border-box",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:`${br}px`,display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsxRuntime.jsxs("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${h-br}px`,overflow:"hidden"},children:[typeof x.mgmtCenterY=="number"?Cd(x.mgmtCenterY,y):null,l.map((k,v)=>{let C=x.portCenters[v]??u/2,S=Bt(k.connectorType),N=Pd(k.position,C,u,y,S.width,S.height);return jsxRuntime.jsx(reactflow.Handle,{type:"source",position:N.position,id:k.id,style:{position:"absolute",left:`${N.leftPx}px`,top:`${N.topPx}px`,right:"initial",bottom:"initial",width:`${S.width}px`,height:`${S.height}px`,background:S.color,border:`1px solid ${S.borderColor}`,boxSizing:"border-box",transform:"none",cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:S.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:S.borderRadius,clipPath:S.clipPath},title:`${k.groupName} - ${k.label} (${k.connectorType})`,children:k.label},`handle-${k.id}`)})]})]})};var xn=({data:e,selected:t,id:o})=>{let{lossDb:r,mode:n="single",ribbonFiberIds:i}=e||{},d=reactflow.useEdges(),a=d.find(N=>N.target===o&&N.targetHandle==="left"),c=d.find(N=>N.source===o&&N.sourceHandle==="right"),l=d.find(N=>N.target===o&&N.targetHandle==="right"),g=c||l,f=a?.data?.color||"#555",p=g?.data?.color||"#555",u=n==="ribbon",y=a?.data?.ribbonFiberIds||i,h=g?.data?.ribbonFiberIds||i,x=u&&y?Pt(y):null,k=u&&h?Pt(h):null,v=!!a&&!!g;return jsxRuntime.jsxs("div",{className:`splice-node ${t?"selected":""}`,style:{width:u?85:69,height:u?20:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:t?"0 0 0 2px #3b82f6":"none"},children:[u&&x&&k?jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:x.map((N,R)=>jsxRuntime.jsx("div",{style:{flex:1,background:N.base,opacity:N.striped?.9:1}},`left-${R}`))}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:k.map((N,R)=>jsxRuntime.jsx("div",{style:{flex:1,background:N.base,opacity:N.striped?.9:1}},`right-${R}`))})]}):jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:f}}),jsxRuntime.jsx("div",{style:{background:p}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),v&&jsxRuntime.jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),v&&typeof r=="number"&&jsxRuntime.jsxs("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",fontSize:u?8:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold",gap:"2px"},children:[jsxRuntime.jsx("div",{children:`${r.toFixed(2)} dB`}),u&&i&&jsxRuntime.jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:u&&x?20:12,borderRadius:u&&x?"6px":"50%",border:"none",background:u&&x?`linear-gradient(to bottom, ${x.map(N=>N.base).join(", ")})`:f,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:u&&k?20:12,borderRadius:u&&k?"6px":"50%",border:"none",background:u&&k?`linear-gradient(to bottom, ${k.map(N=>N.base).join(", ")})`:p,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:u&&k?20:12,borderRadius:u&&k?"6px":"50%",border:"none",background:u&&k?`linear-gradient(to bottom, ${k.map(N=>N.base).join(", ")})`:p,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var zo=20,yr=36;var eo=32,Wi=4,Ot=12,Rd=69,to=80,Nn=(to-Rd)/2;var kn=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data?.mode==="ribbon",i=n?yr:zo,d=n?32:16,a=eo,c=o.y-a,l=Math.round(c/i)+1,f=Math.max(1,Math.min(Ot,l));if(!Wo(t,e,f,r)){let y=Uo(t,e,r,f);if(y!==f){let h=(i-d)/2;return {x:Nn,y:a+(y-1)*i+h,holderPosition:y}}}let p=(i-d)/2,u=a+(f-1)*i+p;return {x:Nn,y:u,holderPosition:f}},Wo=(e,t,o,r)=>!r.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==t.id).some(i=>i.data.holderPosition===o),Uo=(e,t,o,r=1)=>{for(let n=r;n<=Ot;n++)if(Wo(e,t,n,o))return n;for(let n=r-1;n>=1;n--)if(Wo(e,t,n,o))return n;return 1},Td=(e,t)=>Vo(e,t,false),Vo=(e,t,o=false)=>{let r=eo,n=o?yr:zo,d=(n-(o?32:16))/2,a=r+(t-1)*n+d;return {x:Nn,y:a}};var vn=({data:e,selected:t})=>{let{label:o="Splice Tray"}=e||{},[r,n]=Qe.useState(false),i=()=>{if(!r)return null;let d=[],a=eo;for(let c=1;c<=Ot;c++){let l=a+(c-1)*zo;d.push(jsxRuntime.jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${zo}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${to}px`,height:`${eo+Ot*yr+Wi}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${eo}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),jsxRuntime.jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!r);},style:{background:r?"#10b981":"#374151",color:r?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${r?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:eo,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Rn=({data:e,selected:t,id:o})=>{let{fibersPerTube:r=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=e?.mode==="ribbon"||e?.ribbon===true,a=reactflow.useEdges(),c=`tube-${n}`,l=a.find(Y=>Y.source===o&&Y.sourceHandle===c||Y.target===o&&Y.targetHandle===c),g=l?.data?.color,f=Ve((n-1)%12+1),p=g||f,u=Math.max(1,Math.min(24,Number(r)||12)),y=14,h=4,x=1,k=2,v=20,C=u*y+(u-1)*h,S=Math.max(60,C+x*2+k*2),N=i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,R=N!==reactflow.Position.Bottom,D=R?14:20,E=R?8:20,A=R?`inset ${N===reactflow.Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",_=l?p:R?`linear-gradient(${N===reactflow.Position.Left?"to right":"to left"}, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0)), ${p}`:`radial-gradient(circle, ${p} 40%, transparent 70%)`,U={width:D,height:E,borderRadius:R?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:_,backgroundColor:p,border:l?`2px solid ${p}`:`3px dashed ${p}`,cursor:"crosshair","--fiber-bg":p,boxShadow:l?A:`${A}${A!=="none"?", ":""}0 0 8px ${p}`,transition:"opacity 0.2s, box-shadow 0.2s",...N===reactflow.Position.Left?{left:-(D-4)}:N===reactflow.Position.Right?{right:-(D-4)}:{}},se=Qe.useMemo(()=>{let Y=[],ee=S-k*2-x*2,ie,z,V=false;i==="left"?(ie=x,z=reactflow.Position.Top):i==="right"?(ie=x+ee-C,z=reactflow.Position.Top,V=true):(ie=x+(ee-C)/2,z=reactflow.Position.Top);for(let B=0;B<u;B++){let O=V?u-B:B+1,X=`fiber-${O}`,te=a.find(Ce=>Ce.source===o&&Ce.sourceHandle===X||Ce.target===o&&Ce.targetHandle===X),M=!!te&&(te.data?.isRibbon||te.data?.ribbonFiberIds&&Array.isArray(te.data.ribbonFiberIds)),L=te?.data?.color,de=typeof te?.data?.striped=="boolean"?te.data.striped:void 0,ae=kt(O);d||M?ae=kt(O,{base:"#808080",striped:false}):(L||de!==void 0)&&(ae=kt(O,{...L?{base:L}:{},...de!==void 0?{striped:de}:{}}));let ce=ie+B*(y+h),q=x,xe={position:"absolute",left:`${ce}px`,top:`${q}px`,width:y,height:y,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":ae.base,backgroundColor:ae.base};ae.backgroundImage&&(xe["--fiber-bg-image"]=ae.backgroundImage),Y.push(jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:xe,"data-fiber-idx":O,"data-fiber-color":ae.base}),jsxRuntime.jsx(reactflow.Handle,{id:X,type:"source",position:z,className:"tube-fiber-handle",isConnectable:true,style:xe,"data-fiber-idx":O,"data-fiber-color":ae.base})]},`fiber-${O}`));}return Y},[u,i,S,a,o,y,h,x,k,C,d]);return jsxRuntime.jsxs("div",{style:{width:S,height:v,borderRadius:4,background:"#111827",border:`${k}px solid ${t?"#3b82f6":p}`,position:"relative",boxShadow:t?`0 0 0 ${k}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:x,boxSizing:"border-box",overflow:"visible"},children:[se,jsxRuntime.jsx(reactflow.Handle,{id:c,type:"target",position:N,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":p,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"}),jsxRuntime.jsx(reactflow.Handle,{id:c,type:"source",position:N,isConnectable:true,className:"tube-connection-handle",style:U,"data-tube-idx":n,"data-tube-color":p,title:l?"Connected - drag to reconnect":"Drag to connect cable tube"})]})};var In=({data:e,selected:t})=>{let{fiberCount:o,cableId:r="CBL-002",label:n,color:i,rotation:d}=e||{},a=Qe__default.default.useRef(null);Qe__default.default.useEffect(()=>{if(a.current){let z=typeof d=="number"?d:0;a.current.style.transform=`rotate(${z}deg)`,a.current.style.transformOrigin="center center";}},[d]);let c=Math.max(1,Math.min(24,Number(o)||12)),l=10,g=2,f=6,p=f+l+4,u=60,y=Math.max(120,c*(l+g)+f*2),x=n??`${c}f Cable`,k=r?`Cable ID ${r}`:void 0,v=Ve(1),C=i||v,S=t?"#3b82f6":C,N=typeof d=="number"?d:0,R=z=>{let V=(z%360+360)%360;return V>=315||V<45?reactflow.Position.Top:V>=45&&V<135?reactflow.Position.Right:V>=135&&V<225?reactflow.Position.Bottom:reactflow.Position.Left},D=()=>{let z=[],V=R(N);for(let B=0;B<c;B++){let O=B+1,X=kt(O),te=X.base,M=f+B*(l+g),L=-5,de=X.backgroundImage?X.backgroundImage:te,ae={position:"absolute",left:`${M}px`,top:`${L}px`,width:l,height:l,borderRadius:"50%",border:"none",background:de,backgroundColor:te,zIndex:10,cursor:"pointer","--fiber-bg":te};X.backgroundImage&&(ae["--fiber-bg-image"]=X.backgroundImage);let ce=`fiber-${O}`;z.push(jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:ce,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te}),jsxRuntime.jsx(reactflow.Handle,{id:ce,type:"source",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te})]},`fiber-${O}`));}return z},E="cable-button",A=8,_={width:A,height:A,borderRadius:"50%",background:C,backgroundColor:C,border:`1px solid ${C}`,cursor:"pointer",zIndex:10},U=2,Y=(z=>{let V=(z%360+360)%360;return V>=315||V<45?reactflow.Position.Bottom:V>=45&&V<135?reactflow.Position.Left:V>=135&&V<225?reactflow.Position.Top:reactflow.Position.Right})(N),ee={width:y,height:u,position:"relative",transform:`rotate(${N}deg)`,transformOrigin:"center center","--rotation":`${N}deg`},ie={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${U}px solid ${S}`,boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:f,paddingTop:p,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2};return jsxRuntime.jsx("div",{ref:a,style:ee,children:jsxRuntime.jsxs("div",{style:ie,children:[D(),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"source",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxRuntime.jsx(reactflow.Handle,{id:E,type:"target",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:x}),k&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:k})]})]})})};var Hn=({data:e,selected:t})=>{let{tubeCount:o=12,fibersPerTube:r=12,fiberCount:n,cableId:i="CBL-002",label:d,tubeStartIndex:a=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(o)||12)),g=Math.max(1,Number(a)||1),f=14,p=10,u=3,y=6,h=y+p+4,x=60,k=Math.max(120,l*(f+u)+y*2),v=n??l*(Number(r)||12),C=d??`${v}f Cable`,S=i?`Cable ID ${i}`:void 0,N=Ve(g),R=c||N,D=t?"#3b82f6":R,E=()=>{let Y=[];for(let ee=0;ee<l;ee++){let ie=g+ee,z=kt(ie),V=z.base,B=y+ee*(f+u),O=-5,X=z.backgroundImage?z.backgroundImage:V,te={position:"absolute",left:`${B}px`,top:`${O}px`,width:f,height:p,borderRadius:6,border:"none",background:X,backgroundColor:V,zIndex:10,cursor:"pointer","--fiber-bg":V};z.backgroundImage&&(te["--fiber-bg-image"]=z.backgroundImage);let M=`tube-${ie}`;Y.push(jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:M,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V}),jsxRuntime.jsx(reactflow.Handle,{id:M,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V})]},`tube-${ie}`));}return Y},A="cable-button",_=8,U={width:_,height:_,borderRadius:"50%",background:R,backgroundColor:R,border:`1px solid ${R}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:k,height:x,borderRadius:4,background:"#111827",border:`2px solid ${D}`,position:"relative",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:y,paddingTop:h,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[E(),jsxRuntime.jsx(reactflow.Handle,{id:A,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsxRuntime.jsx(reactflow.Handle,{id:A,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:C}),S&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:S})]})]})};var Fn=({data:e,selected:t,id:o})=>{let{connector:r="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:a}=e||{},c=reactflow.useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,g=Math.max(1,Math.min(4,l)),f=9,p=3,u=3,y=60,h=30,x=g*f+(g-1)*p,k=Math.max(h,x+u*2),v=Math.max(y,80),C=(R,D)=>{let E=`${R}-${D+1}`;return c.find(_=>_.source===o&&_.sourceHandle===E||_.target===o&&_.targetHandle===E)?.data?.color||"#555"},S=R=>{let D=[],E=R==="left"?reactflow.Position.Left:reactflow.Position.Right,A=R==="left"?d:a;for(let _=0;_<g;_++){let U=_+1,se=`${R}-${U}`,Y=C(R,_),z=u+(k-x)/2+_*(f+p),V={position:"absolute",left:R==="left"?-5:void 0,right:R==="right"?-5:void 0,top:`${z}px`,width:f,height:f,borderRadius:"50%",border:"none",background:Y,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};D.push(jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:se,type:"target",position:E,isConnectable:true,style:V}),jsxRuntime.jsx(reactflow.Handle,{id:se,type:"source",position:E,isConnectable:true,style:V})]},se)),A&&A[_]&&D.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:R==="left"?-30:void 0,right:R==="right"?-30:void 0,top:`${z}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:R==="left"?"right":"left",width:"25px"},children:A[_]},`${se}-label`));}return D},N=i||`${r}-${g}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${t?"selected":""}`,style:{width:v,height:k,borderRadius:4,border:`2px solid ${t?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:t?"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:[S("left"),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:N})}),S("right")]})};var no=32,Rr=30,Md=24,$d=80,Cr=400,vr=300,Ki=2,ro=8,Zi=120;function _n(e){let{couplerFiberCount:t}=e.data||{},o=typeof t=="number"&&[1,2,4].includes(t)?t:2,r=Math.max(1,Math.min(4,o)),n=7,i=3,d=3,a=60,c=30,l=r*n+(r-1)*i,g=Math.max(c,l+d*2);return {width:Math.max(a,80),height:g}}function Tr(e){let{fibersPerTube:t=12}=e.data||{},o=Math.max(1,Math.min(24,Number(t)||12)),r=14,n=4,i=1,d=2,a=20,c=o*r+(o-1)*n;return {width:Math.max(60,c+i*2+d*2),height:a}}function qi(e){return {width:to,height:0}}function Ji(e){return e.type==="coupler"?_n(e):e.type==="tube"?Tr(e):e.type==="splice-tray"?qi():{width:80,height:30}}function Dn(e){let t=0;for(let o of e){let r=Ji(o),n=(o.position?.x||0)+r.width;n>t&&(t=n);}return t}function Qi(e,t=0){let o=t;for(let r of e){let n=Ji(r),i=(r.position?.y||0)+n.height;i>o&&(o=i);}return o}function ea(e){return e.data?.panelWidth||Cr}function Ad(e){return e.data?.panelHeight||vr}function ta(e){return ea(e)-Ki*2-ro*2}function Ld(e,t){return ta(e)-t}function oa(e,t=Rr){return Math.floor(e/t)+1}function ra(e,t=Rr){return (e-1)*t}function Bd(e,t,o){let r=Rr,n=oa(o.y,r),i=ra(n,r);return {x:o.x,y:i,slotPosition:n}}function Mn(e,t){if(t.length===0)return {width:e.data?.panelWidth||Cr,height:e.data?.panelHeight||vr};let o=t.some(c=>c.type==="tube"),r=t.some(c=>c.type==="splice-tray"),n=t.some(c=>c.type==="coupler"),i;if(o&&r&&n){let c=0,l=0;for(let p of t)if(p.type==="tube"){let u=Tr(p);u.width>c&&(c=u.width);}else if(p.type==="coupler"){let u=_n(p);u.width>l&&(l=u.width);}let g=c+Zi+to+l+5,f=0;i=f+g+f;}else i=Dn(t)+4;i=Math.max(e.data?.panelWidth||Cr,i);let d=Qi(t,no),a=Math.max(e.data?.panelHeight||vr,d+ro);return {width:i,height:a}}function na(e,t,o){if(e===0)return 0;if(e===1)return t;let r=e*t,n=o-r,i=Math.max(5,n/(e-1));return t+i}function Od(e,t,o){return na(e,t,o)}var Xi=20,ji=400,Yi=300;function $n(e,t){if(t.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||ji,height:e.data?.closureHeight||e.data?.panelHeight||Yi};let o=t.some(a=>a.type==="tube"),r=t.some(a=>a.type==="splice-tray"),n;if(o&&r){let a=0,c=0,l=0,g=t.filter(p=>p.type==="tube"),f=t.filter(p=>p.type==="splice-tray");if(g.length>0&&f.length>0){let p=f.map(y=>y.position?.x||0),u=p.reduce((y,h)=>y+h,0)/p.length;for(let y of g){let h=Tr(y);(y.position?.x||0)<u?h.width>a&&(a=h.width):h.width>c&&(c=h.width);}f.length>0&&(l=to),n=ro+a+Xi+l+Xi+c+5;}else n=Dn(t)+ro+5;}else n=Dn(t)+ro+5;n=Math.max(e.data?.closureWidth||e.data?.panelWidth||ji,n);let i=Qi(t,no),d=Math.max(e.data?.closureHeight||e.data?.panelHeight||Yi,i+ro);return {width:n,height:d}}var Bn=({data:e,selected:t,id:o})=>{let{label:r="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:a,setNodes:c}=reactflow.useReactFlow(),l=Qe.useRef(false),g=Qe.useRef([]),f=Qe.useMemo(()=>{let C=a().filter(S=>S.parentId===o);return (C.length!==g.current.length||C.some((S,N)=>S.id!==g.current[N]?.id))&&(g.current=C),g.current},[a,o]),p=Qe.useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[o,e,i,d]),u=Qe.useMemo(()=>i&&d?{width:i,height:d}:f.length===0?{width:i||400,height:d||300}:Mn(p,f),[f,p,i,d]);Qe.useEffect(()=>{if(i&&d||l.current)return;let v=i,C=d,S=Math.abs((v||0)-u.width),N=Math.abs((C||0)-u.height);(S>1||N>1)&&(l.current=true,c(R=>R.map(D=>D.id===o?{...D,data:{...D.data,panelWidth:u.width,panelHeight:u.height}}:D)),setTimeout(()=>{l.current=false;},0));},[o,u.width,u.height,i,d,c]);let y=u.width,h=u.height,x=no,k=n||r;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${y}px`,height:`${h}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${x}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:k})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:x,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var zn=({data:e,selected:t,id:o})=>{let{label:r="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:a,panelHeight:c}=e||{},{getNodes:l,setNodes:g}=reactflow.useReactFlow(),f=Qe.useRef(false),p=Qe.useRef([]),u=Qe.useMemo(()=>{let R=l().filter(D=>D.parentId===o);return (R.length!==p.current.length||R.some((D,E)=>D.id!==p.current[E]?.id))&&(p.current=R),p.current},[l,o]),y=Qe.useMemo(()=>({id:o,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||a,closureHeight:d||c}}),[o,e,i,d,a,c]),h=Qe.useMemo(()=>i&&d?{width:i,height:d}:a&&c?{width:a,height:c}:u.length===0?{width:i||a||400,height:d||c||300}:$n(y,u),[u,y,i,d,a,c]);Qe.useEffect(()=>{if(i&&d||a&&c||f.current)return;let N=i||a,R=d||c,D=Math.abs((N||0)-h.width),E=Math.abs((R||0)-h.height);(D>1||E>1)&&(f.current=true,g(A=>A.map(_=>_.id===o?{..._,data:{..._.data,closureWidth:h.width,closureHeight:h.height}}:_)),setTimeout(()=>{f.current=false;},0));},[o,h.width,h.height,i,d,a,c,g]);let x=h.width,k=h.height,v=no,C=n||r,S=x/2;return jsxRuntime.jsxs("div",{className:`closure-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${S}px ${S}px 12px 12px`,padding:0,width:`${x}px`,height:`${k}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:t?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${v}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${S}px ${S}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:C})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:v,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Vn=({data:e,selected:t,id:o})=>{let{label:r,splitterType:n="splitter",inputCount:i=1,outputCount:d=8}=e||{},a=reactflow.useEdges(),c=r||(n==="WDM"?"WDM":"Splitter"),l=9,g=3,f=3,p=50,u=30,y=Math.min(Math.max(i||1,1),2),h=y*l+(y-1)*g,x=Math.min(d||8,48),k=x*l+(x-1)*g,v=Math.max(h,k),C=Math.max(u,v+f*2),S=Math.max(p,50),N=ee=>a.find(z=>z.source===o&&z.sourceHandle===ee||z.target===o&&z.targetHandle===ee)?.data?.color||"#555",R=()=>{let ee=[],ie=f+(C-h)/2;for(let z=0;z<y;z++){let V=`input-${z+1}`,B=ie+z*(l+g),O=N(V),X={position:"absolute",left:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};ee.push(jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:`${V}-target`,type:"target",position:reactflow.Position.Left,isConnectable:true,style:X}),jsxRuntime.jsx(reactflow.Handle,{id:`${V}-source`,type:"source",position:reactflow.Position.Left,isConnectable:true,style:X})]},V));}return ee},D=()=>{let ee=[],ie=f+(C-k)/2;for(let z=0;z<x;z++){let V=`output-${z+1}`,B=ie+z*(l+g),O=N(V),X={position:"absolute",right:-5,top:`${B}px`,width:l,height:l,borderRadius:"50%",border:"none",background:O,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};ee.push(jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:`${V}-target`,type:"target",position:reactflow.Position.Right,isConnectable:true,style:X}),jsxRuntime.jsx(reactflow.Handle,{id:`${V}-source`,type:"source",position:reactflow.Position.Right,isConnectable:true,style:X})]},V));}return ee},E=Math.max(h+f*4,u*.6),A=(C-E)/2,_=A+E,U=0,se=C,Y=t?"#3b82f6":"#4b5563";return jsxRuntime.jsxs("div",{className:`trapezoid-node ${t?"selected":""}`,style:{width:S,height:C,position:"relative",background:"transparent",boxShadow:t?"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:[jsxRuntime.jsx("svg",{width:S,height:C,viewBox:`0 0 ${S} ${C}`,style:{position:"absolute",top:0,left:0,width:`${S}px`,height:`${C}px`,pointerEvents:"none",zIndex:0},children:jsxRuntime.jsx("polygon",{points:`0,${A} 0,${_} ${S},${se} ${S},${U}`,fill:"#1f2937",stroke:Y,strokeWidth:"2"})}),R(),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:c})}),D()]})};var da=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",Er=(e,t)=>da(e)||da(t),re=(e,t)=>t?e?.type==="fibre-split"?We(t):We(t):t||"";function Hr(e,t){if(!e||!t)return "unknown";let o=We(t);if(!o)return "unknown";if(e.type==="vertical-pdu")return "power";let r=e.data??{},n=Array.isArray(r.ports)?r.ports:[],i=Array.isArray(r.rearPorts)?r.rearPorts:[];for(let l of [...n,...i])for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:Ct(g.type)?g.type:void 0})===o)return Ct(g.type)?"power":"network";if(pr(o)||/^\d+$/.test(o))return "power";let d=o.toLowerCase(),a=d.startsWith("net-")||d.startsWith("port-")||d.startsWith("uplink-")||d.includes("fiber")||d.includes("ports"),c=/^[A-Z0-9]+-\d+$/i.test(o)&&!d.startsWith("pwr")&&!d.startsWith("power");return a||c?"network":"unknown"}function io(e,t){return Hr(e,t)==="power"}function Yd(e,t){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=t.nodes.find(M=>M.id===e.source),r=t.nodes.find(M=>M.id===e.target),n=Er(o,r);if(!n){let M=Hr(o,e.sourceHandle),L=Hr(r,e.targetHandle);if(M!=="unknown"&&L!=="unknown"&&M!==L)return {valid:false,reason:`Cannot connect ${M} handle to ${L} handle`};let de=M==="power"&&L==="power",ae=o?.type==="vertical-pdu"||r?.type==="vertical-pdu";if(de&&!ae)return {valid:false,reason:"Power connections must include a PDU endpoint"}}let i=re(o,e.sourceHandle),d=re(r,e.targetHandle),a=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.source===e.source?re(o,M.sourceHandle)===i:M.target===e.source?re(o,M.targetHandle)===i:false),c=t.edges.some(M=>e.ignoreEdgeId&&M.id===e.ignoreEdgeId?false:M.target===e.target?re(r,M.targetHandle)===d:M.source===e.target?re(r,M.sourceHandle)===d:false);if((a||c)&&!n)return a?{valid:false,reason:`Source handle ${e.sourceHandle} on node ${e.source} is already connected`}:{valid:false,reason:`Target handle ${e.targetHandle} on node ${e.target} is already connected`};let l=(M,L)=>(M?.type==="tube"||M?.type==="cable")&&!!L&&L.startsWith("fiber-"),g=(M,L)=>(M?.type==="tube"||M?.type==="multi-tube-cable")&&!!L&&L.startsWith("tube-"),f=(M,L)=>M?.type==="multi-tube-cable"&&!!L&&L.startsWith("tube-"),p=(M,L)=>M?.type==="tube"&&!!L&&L.startsWith("tube-"),u=(M,L)=>(M?.type==="cable"||M?.type==="multi-tube-cable")&&L==="cable-button",y=(M,L)=>M?.type==="splice"&&(L==="left"||L==="right"),h=(M,L)=>M?.type==="coupler"&&!!L&&(L.startsWith("left-")||L.startsWith("right-")),x=(M,L)=>{if(M?.type!=="fibre-split"||!L)return false;let de=re(M,L);return de.startsWith("input-")||de.startsWith("output-")};if(!n)return {valid:true};if(o?.type==="splice"&&r?.type==="splice"){let M=o.data?.mode==="ribbon",L=r.data?.mode==="ribbon";if(M!==L)return {valid:false,reason:"Ribbon splices can only connect to other ribbon splices"}}let k=l(o,e.sourceHandle),v=l(r,e.targetHandle),C=y(o,e.sourceHandle),S=y(r,e.targetHandle),N=h(o,e.sourceHandle),R=h(r,e.targetHandle),D=x(o,e.sourceHandle),E=x(r,e.targetHandle),A=u(o,e.sourceHandle),_=u(r,e.targetHandle),U=f(o,e.sourceHandle),se=f(r,e.targetHandle),Y=p(o,e.sourceHandle),ee=p(r,e.targetHandle),ie=g(o,e.sourceHandle),z=g(r,e.targetHandle);return k&&S||v&&C||(C&&(R||E)||S&&(N||D))||(N&&(R||E||S)||R&&(N||D||C))||A&&_||(U&&ee||se&&Y)?{valid:true}:ie&&z?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function Fr(e,t){if(!t)return;let o="--rear",r=We(e),n=r.endsWith(o);n&&(r=r.slice(0,-o.length));let i=t.data??{},d=i.handleSideMap;if(d&&d[r])return d[r];if(n)return "rear";if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let a=Array.isArray(i.ports)?i.ports:[],c=Array.isArray(i.rearPorts)?i.rearPorts:[];if(pr(r))return "rear";for(let l of a)for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:Ct(g.type)?g.type:void 0})===r)return "front";for(let l of c)for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:Ct(g.type)?g.type:void 0})===r)return "rear"}function Gn(e={},t={}){let o={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},r=new Set;return {getState:()=>o,setState:f=>{o={...o,...f},r.forEach(p=>p(o));},subscribe:f=>(r.add(f),()=>r.delete(f)),selectEdgeZIndex:f=>{let p=k=>{if(typeof k.parentId=="string")return k.parentId;let v=k.parentNode;if(typeof v=="string")return v},u=k=>{let v=p(k),C=v?o.nodes.find(D=>D.id===v&&D.type==="rack"):void 0;if(C&&He(C.data))return $t(Oe(k.data));let S=Array.isArray(k.data?.rearPorts)&&k.data.rearPorts.length>0,N=Array.isArray(k.data?.ports)&&k.data.ports.length>0;return [k.data?.view||(S&&!N?"rear":"front")]},y=(k,v)=>{let C=o.nodes.find(ee=>ee.id===k);if(!(!!C&&(C.type==="device"||C.type==="server"||C.type==="switch"||C.type==="router"))||!C||C.data?.deviceType?.toLowerCase().replace(/_/g,"-")==="patch-panel")return;let R=u(C),D=Fr(v||"",C);if(D)return R.includes(D)?1e3:500;let E=(v||"").toString().replace(/-(source|target)$/i,""),A=E.toLowerCase(),_=A.startsWith("pwr")||A.startsWith("power"),U=A.startsWith("net-")||A.startsWith("port-")||A.startsWith("uplink-")||A.includes("fiber")||A.includes("ports"),se=/^[A-Z0-9]+-\d+$/i.test(E)&&!A.startsWith("pwr")&&!A.startsWith("power"),Y=U||se;if(_)return R.includes("rear")?1e3:500;if(Y)return R.includes("front")?1e3:500},h=y(f.target,f.targetHandle);if(h!==void 0)return h;let x=y(f.source,f.sourceHandle);return x!==void 0?x:1e3},validateConnection:f=>(t.validateConnection||Yd)(f,o),selectNodeById:f=>o.nodes.find(p=>p.id===f),selectConnectedEdges:f=>o.edges.filter(p=>p.source===f||p.target===f)}}function Kd(e){let t=n=>e.subscribe(i=>n()),o=()=>e.getState();return Qe.useSyncExternalStore(t,o,o)}function jn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return Qe.useSyncExternalStore(t,o,o)}function Yn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return Qe.useSyncExternalStore(t,o,o)}function ca(e){return e.selectEdgeZIndex}function la(e){let t=Do(e.data),o=60+(e.data.uHeight||42)*20,r=e.position.x,n=e.position.x+t,i=e.position.y,d=e.position.y+o;return {left:r,right:n,top:i,bottom:d}}function ua(e,t){let o=la(t);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function Dr(e,t){let o=null,r=1/0;for(let n of t){if(!ua(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<r&&(r=i,o=n);}return o}function Le(e){let{edges:t,connection:o,edgeType:r,selectEdgeZIndex:n,findBy:i,matchOn:d=i,data:a}=e,c=i==="source"?o.sourceHandle:o.targetHandle,l=i==="source"?o.source:o.target;if(!c||!l)return null;let g=We(c),f=t.find(k=>d==="source"?k.source===l&&We(k.sourceHandle)===g:k.target===l&&We(k.targetHandle)===g);if(!f)return null;let p=t.filter(k=>k.id!==f.id),u=reactflow.addEdge(o,p),y=u[u.length-1],h=n({...o,id:y.id,type:r}),x={...y,type:r,zIndex:h,style:{...y.style,zIndex:h},data:a!==void 0?a:y.data};return [...u.slice(0,-1),x]}function pa(e){return Array.isArray(e)?e.reduce((t,o)=>t+(Array.isArray(o.ports)?o.ports.length:0),0):0}function fa(e){return typeof e=="string"&&e.trim().length>0}function qd(e){let t=pa(e.ports)>0||fa(e.frontImageUrl),o=pa(e.rearPorts)>0||fa(e.rearImageUrl);if(t&&o)return "both";if(t)return "front";if(o)return "rear"}function ga(e,t,o,r){let n=e.mountMode;if(n==="front"||n==="rear"||n==="both")return n;let i=qd(e);if(i)return i;if(e.view==="front"||e.view==="rear")return e.view;let d=o+r/2;return t>=d?"front":"rear"}function ha(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var Ge=({type:e,children:t})=>{let o=Qe__default.default.useRef(null),r=Qe__default.default.useCallback(n=>{if(o.current=n,n){let i=n.parentElement,d=0;for(;i&&!i.classList.contains("react-flow__node")&&d<10;)i=i.parentElement,d++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return Qe__default.default.useEffect(()=>{if(o.current){let n=o.current.parentElement,i=0;for(;n&&!n.classList.contains("react-flow__node")&&i<10;)n=n.parentElement,i++;n&&n.classList.contains("react-flow__node")&&n.setAttribute("data-type",e);}},[e]),jsxRuntime.jsx("div",{ref:r,style:{width:"100%",height:"100%"},children:t})},ya=(e,t,o)=>({rack:r=>jsxRuntime.jsx(Ge,{type:"rack",children:jsxRuntime.jsx(en,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsxRuntime.jsx(Ge,{type:"fiber",children:jsxRuntime.jsx(tn,{...r})}),device:r=>jsxRuntime.jsx(Ge,{type:"device",children:jsxRuntime.jsx(mo,{...r})}),server:r=>jsxRuntime.jsx(Ge,{type:"server",children:jsxRuntime.jsx(mo,{...r})}),switch:r=>jsxRuntime.jsx(Ge,{type:"switch",children:jsxRuntime.jsx(mo,{...r})}),router:r=>jsxRuntime.jsx(Ge,{type:"router",children:jsxRuntime.jsx(mo,{...r})}),"vertical-pdu":r=>jsxRuntime.jsx(Ge,{type:"vertical-pdu",children:jsxRuntime.jsx(hn,{...r})}),splice:r=>jsxRuntime.jsx(Ge,{type:"splice",children:jsxRuntime.jsx(xn,{...r})}),"splice-tray":r=>jsxRuntime.jsx(Ge,{type:"splice-tray",children:jsxRuntime.jsx(vn,{...r})}),tube:r=>jsxRuntime.jsx(Ge,{type:"tube",children:jsxRuntime.jsx(Rn,{...r})}),cable:r=>jsxRuntime.jsx(Ge,{type:"cable",children:jsxRuntime.jsx(In,{...r})}),"multi-tube-cable":r=>jsxRuntime.jsx(Ge,{type:"multi-tube-cable",children:jsxRuntime.jsx(Hn,{...r})}),coupler:r=>jsxRuntime.jsx(Ge,{type:"coupler",children:jsxRuntime.jsx(Fn,{...r})}),"patch-panel":r=>jsxRuntime.jsx(Ge,{type:"patch-panel",children:jsxRuntime.jsx(Bn,{...r})}),closure:r=>jsxRuntime.jsx(Ge,{type:"closure",children:jsxRuntime.jsx(zn,{...r})}),"fibre-split":r=>jsxRuntime.jsx(Ge,{type:"fibre-split",children:jsxRuntime.jsx(Vn,{...r})})});function wa(e){if(!e)return false;if(e.type==="switch")return true;if(e.type!=="device")return false;let t=e.data?.deviceType;return typeof t=="string"&&t.toLowerCase().replace(/_/g,"-")==="switch"}function xa(e,t,o){let r=e.sourceHandle,n=e.targetHandle;return wa(t)&&r&&!io(t,r)&&(r=We(r)),wa(o)&&n&&!io(o,n)&&(n=`${We(n)}-target`),r===e.sourceHandle&&n===e.targetHandle?e:{...e,sourceHandle:r,targetHandle:n}}var lc={fiber:cr,ethernet:cr,power:rn,smoothstep:Pi,step:Ri,"thick-cable":Ii},uc=8192,pc=8192,fc=2048,gc=4;function Xo(e,t,o){if(!(typeof e!="number"||Number.isNaN(e)))return Math.min(o,Math.max(t,e))}function bc(e){if(e)return {...e,width:Xo(e.width,1,uc),height:Xo(e.height,1,pc),padding:Xo(e.padding,0,fc),pixelRatio:Xo(e.pixelRatio,.1,gc),quality:Xo(e.quality,0,1)}}var mc=({nodes:e,edges:t,initialNodes:o,initialEdges:r,onNodesChange:n,onEdgesChange:i,store:d,debug:a,onNodeClick:c,onEdgeClick:l,nodeTypes:g,edgeTypes:f,onConnect:p,onEdgeUpdate:u,isValidConnection:y,connectionMode:h,onViewChange:x,onRackFaceChange:k,className:v,style:C,alignRacksToBottom:S,reAssignable:N=true,colorMode:R="dark",onInit:D,onFlowMethods:E,showDownloadButton:A=false,downloadButtonPosition:_="top-right",downloadButtonText:U="Download Image",downloadButtonStyle:se,useSmoothstepEdgesForTubes:Y=false,readOnly:ee=false,interaction:ie,actionPanel:z,connectOnClick:V=true,panOnDrag:B=true,panOnScroll:O=true,zoomOnScroll:X=true,fitViewOptions:te})=>{let M=Qe.useCallback((s,b)=>{let w=new Map,m=[],T=[],H=(F,$)=>!F||!$?false:!!(F.startsWith("tube-")||$.type==="splice"&&(F==="left"||F==="right")||F==="cable-button");for(let F of s){if(!F.source||!F.target||!F.sourceHandle||!F.targetHandle){a&&console.warn("Invalid edge skipped (missing source/target/handles):",F);continue}let $=b.find(qe=>qe.id===F.source),I=b.find(qe=>qe.id===F.target),K=`${F.source}:${F.sourceHandle}`,oe=w.get(K),Re=H(F.sourceHandle,$),Te=`${F.target}:${F.targetHandle}`,Se=w.get(Te),Ye=H(F.targetHandle,I);if(oe&&!Re){a&&console.warn("Duplicate connection detected on source handle, removing:",{handle:K,existingEdge:oe.id,duplicateEdge:F.id}),T.push(F);continue}if(Se&&!Ye){a&&console.warn("Duplicate connection detected on target handle, removing:",{handle:Te,existingEdge:Se.id,duplicateEdge:F.id}),T.push(F);continue}m.push(F),oe||w.set(K,F),Se||w.set(Te,F);}return a&&T.length>0&&console.log(`Filtered ${T.length} duplicate edge(s) from initial edges`),m},[a]),L=Array.isArray(e)&&Array.isArray(t),de=Qe__default.default.useMemo(()=>L?e||[]:o||e||[],[L,e,o]),ae=Qe__default.default.useMemo(()=>L?t||[]:r||t||[],[L,t,r]),ce=Qe__default.default.useMemo(()=>M(ae,de),[ae,de,M]),q=Qe__default.default.useMemo(()=>d||Gn({nodes:de,edges:ce,debug:a}),[d,L,a,ce]),xe=jn(q),Ce=Yn(q),[Ne,j]=reactflow.useNodesState(xe),[we,ke,st]=reactflow.useEdgesState(Ce),le=ca(q),Xe=Qe.useRef(null),[Fe,Or]=Qe.useState(false);Qe.useEffect(()=>{let s=()=>{Or(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[]);let Pe=ee===true,De=Qe.useMemo(()=>{let b={...{nodesDraggable:true,nodesConnectable:true,elementsSelectable:!Fe,edgesFocusable:!Fe,edgesReconnectable:true,connectOnClick:V,panOnDrag:B,panOnScroll:O&&!Fe,zoomOnScroll:X&&!Fe,zoomOnPinch:!Fe,zoomOnDoubleClick:!Fe,allowKeyboardDelete:true,showControls:true,showMiniMap:!Fe,showInteractiveControl:true},...ie??{}};return Pe?{...b,nodesDraggable:false,nodesConnectable:false,elementsSelectable:false,edgesFocusable:false,edgesReconnectable:false,connectOnClick:false,panOnDrag:false,panOnScroll:false,zoomOnScroll:false,zoomOnPinch:false,zoomOnDoubleClick:false,allowKeyboardDelete:false,showInteractiveControl:false}:b},[Fe,V,B,O,X,ie,Pe]),Ut=Qe.useMemo(()=>({enabled:z?.enabled??true,showRearToggle:z?.showRearToggle??true,showDeRack:z?.showDeRack??true}),[z]),{toObject:Ko,setViewport:ze,setNodes:Ze,setEdges:ve,getNodes:ot,getEdges:dt,fitView:Et,flowToScreenPosition:ct}=reactflow.useReactFlow();Qe.useEffect(()=>{E&&E({toObject:()=>Ko(),setViewport:ze,setNodes:s=>{Ze(s),q.setState({nodes:s});},setEdges:s=>{ve(s),q.setState({edges:s});},toImage:s=>Xe.current?htmlToImage.toPng(Xe.current,bc(s)):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>ot(),getEdges:()=>dt(),fitView:s=>{if(s?.nodes&&Array.isArray(s.nodes)&&s.nodes.length>0){let b=s.nodes.map(T=>ot().find(H=>H.id===T)).filter(T=>T!==void 0),{nodes:w,...m}=s;Et({...m,nodes:b});}else {let{nodes:b,...w}=s||{};Et(w);}}});},[E,Ko,ze,Ze,ve,q,Et,ot,dt]);let[lt,Zo]=Qe.useState(false),Wr=Qe.useCallback(()=>{if(!lt){if(!Xe.current){a&&console.error("ReactFlow wrapper ref is not available");return}Zo(true),htmlToImage.toPng(Xe.current,{filter:s=>!(s?.classList?.contains("react-flow__minimap")||s?.classList?.contains("react-flow__controls")||s?.classList?.contains("react-flow__attribution")||s?.classList?.contains("download-button")||s?.tagName==="BUTTON"),backgroundColor:R==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(s=>{let b=document.createElement("a");b.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,b.href=s,b.click();}).catch(s=>{a&&console.error("Error downloading image:",s);}).finally(()=>{Zo(false);});}},[R,a,lt]),[qo,Vt]=Qe.useState(null),Gt=Qe.useRef(null),Ht=Qe.useRef(x),zr=Qe.useRef(k);Qe.useEffect(()=>{Ht.current=x;},[x]),Qe.useEffect(()=>{zr.current=k;},[k]),Qe.useEffect(()=>{Gt.current=qo;},[qo]);let _e=Qe.useCallback((s,b)=>{Ht.current?.(s,b);},[]),Ft=Qe.useCallback((s,b)=>{zr.current?.(s,b);},[]),ut=Qe.useCallback(()=>Gt.current,[]),yt=Qe.useRef({...ya(_e,Ft,ut),...g??{}});Qe.useEffect(()=>{yt.current={...ya(_e,Ft,ut),...g??{}};},[_e,Ft,ut,g]);let co=Qe.useMemo(()=>({...lc,...f??{}}),[f]),pt=Qe.useRef(Ne);Qe.useEffect(()=>{pt.current=Ne;},[Ne]);let J=Qe.useRef(we);Qe.useEffect(()=>{J.current=we;},[we]),Qe.useEffect(()=>{j(xe);},[xe,j]),Qe.useEffect(()=>{ke(Ce);},[Ce,ke]),Qe.useEffect(()=>{if(L&&t){let s=M(t,e||[]);s.length!==t.length&&(a&&console.warn(`Controlled edges had ${t.length-s.length} duplicate(s) removed`),i?.(s));}},[L,t,e,M,i,a]),Qe.useEffect(()=>{L&&q.setState({nodes:e||[]});},[L,e,q]),Qe.useEffect(()=>{L&&q.setState({edges:t||[]});},[L,t,q]),Qe.useEffect(()=>{if(!S||!Ne||Ne.length===0)return;let s=Ne.filter(I=>I.type==="rack");if(s.length===0)return;let b=s.map(I=>{let oe=I.data?.uHeight||42,Re=60+oe*20;return (I.position?.y||0)+Re}),w=Math.min(...b),m=Math.max(...b);if(m-w<20)return;let H=m,F=Ne.map(I=>{if(I.type!=="rack")return I;let oe=I.data?.uHeight||42,Re=60+oe*20,Te=(I.position?.y||0)+Re,Se=H-Te;return Math.abs(Se)<5?I:{...I,position:{x:I.position?.x||0,y:(I.position?.y||0)+Se}}});F.some((I,K)=>I.position!==Ne[K].position)&&j(F);},[S,Ne,j]);let Ro=Qe.useRef(new Map);Qe.useEffect(()=>{let s=new Map;Ne.forEach(b=>{s.set(b.id,b);}),Ro.current=s;},[Ne]);let ue=Qe.useCallback(s=>Ro.current.get(s),[]),je=Qe.useCallback(s=>{if(!s)return;if(typeof s.parentId=="string")return s.parentId;let b=s.parentNode;if(typeof b=="string")return b},[]),ri=Qe.useCallback(s=>{let b=je(s);if(!b)return;let w=ue(b);if(!(!w||w.type!=="rack"))return w},[ue,je]),ni=Qe.useCallback(s=>!s||s.type!=="rack"?false:He(s.data),[]),lo=Qe.useCallback(s=>{if(!s||!Ke(s))return false;let b=ri(s);return b?He(b.data):false},[ri]),Ur=Qe.useCallback(s=>{if(!s||s.type!=="device")return false;let b=s.data?.deviceType;return typeof b=="string"&&b.toLowerCase().replace(/_/g,"-")==="patch-panel"},[]),Jo=Qe.useCallback(s=>{pt.current=s;let b=new Map;s.forEach(w=>{b.set(w.id,w);}),Ro.current=b,j(s),L?n?.(s):q.setState({nodes:s});},[L,q,j,n]),he=Qe.useCallback(s=>{J.current=s,ke(s),L?i?.(s):q.setState({edges:s});},[L,q,ke,i]),Dt=Qe.useCallback(s=>{if(s.positionAbsolute)return s.positionAbsolute;let b=s.position?.x||0,w=s.position?.y||0,m=je(s),T=new Set;for(;m&&!T.has(m);){T.add(m);let H=ue(m);if(!H)break;if(H.positionAbsolute){b+=H.positionAbsolute.x,w+=H.positionAbsolute.y;break}b+=H.position?.x||0,w+=H.position?.y||0,m=je(H);}return {x:b,y:w}},[ue,je]),Qo=Qe.useCallback(s=>{let b=Dt(s),w=s.width||0,m=s.height||0;return {x:b.x+w/2,y:b.y+m/2}},[Dt]),To=Qe.useCallback((s,b)=>{if(!s||!b)return;let w=ue(s);if(!w)return;let m=b.replace(/-(source|target)$/i,"");if(w.type==="fibre-split"&&m.startsWith("output-")){let H=J.current.filter(F=>F.target===s&&(F.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(H.length>0){let F=H[0]?.data?.color;if(F)return {color:F}}}if((w.type==="tube"||w.type==="cable")&&b.startsWith("fiber-")){let H=b.replace("fiber-",""),F=parseInt(H,10);if(F>=1&&F<=24){let $=qt(F),I=F>12;return {color:$,striped:I}}}if((w.type==="multi-tube-cable"||w.type==="tube")&&b.startsWith("tube-")){let H=b.replace("tube-",""),F=parseInt(H,10);if(F>=1&&F<=24){let $=Ve(F),I=F>12;return {color:$,striped:I}}}let T=w.data;if(T.color)return {color:T.color}},[ue]),ii=Qe.useRef(new Map);Qe.useEffect(()=>{ke(s=>{let b=false,w=s.map(m=>{let T=le(m);return ii.current.get(m.id)!==T?(b=true,ii.current.set(m.id,T),{...m,zIndex:T,style:{...m.style,zIndex:T}}):m});return b?w:s});},[Ne,ke,le]),Qe.useEffect(()=>{let s=Ne.map(w=>{if(w.type==="coupler"&&w.parentId){let m=ue(w.parentId);if(m&&(m.type==="patch-panel"||m.type==="closure")&&(!w.extent||w.extent!=="parent"))return {...w,extent:"parent"}}if(w.type==="splice"&&w.parentId&&w.data.holderPosition&&(!w.position||w.position.x===0&&w.position.y===0)){let m=ue(w.parentId);if(m&&m.type==="splice-tray"){let T=w.data.mode==="ribbon",H=Vo(m,w.data.holderPosition,T);return {...w,position:H}}}if(Ke(w)&&w.parentId&&w.data.uPosition&&(!w.position||w.position.x===0&&w.position.y===0)){let m=ue(w.parentId);if(m){let T=w.data.uHeight||1,H=go(m,w.data.uPosition,T,w.data);return {...w,position:H}}}return w});s.some((w,m)=>{let T=Ne[m];return w.extent!==T.extent||w.position?.x!==T.position?.x||w.position?.y!==T.position?.y})&&j(s);},[Ne,j,ue]);let Za=Qe.useCallback(s=>{if(Pe)return null;let b=new Map,w=new Map,m=new Set,T=s.map($=>{if($.type==="position"&&$.position){let I=ue($.id);if(I&&I.type==="coupler"&&I.parentId){let K=ue(I.parentId);if(K&&(K.type==="patch-panel"||K.type==="closure"))return (!I.extent||I.extent!=="parent")&&m.add(I.id),{...$,position:I.position||{x:0,y:0}}}if(I&&(I.type==="tube"||I.type==="splice-tray")&&I.parentId){let K=ue(I.parentId);if(K&&K.type==="closure")return (!I.extent||I.extent!=="parent")&&m.add(I.id),{...$,position:I.position||{x:0,y:0}}}if(I&&I.type==="splice"&&I.parentId){let K=ue(I.parentId);if(K&&K.type==="splice-tray"){let oe=kn(I,K,$.position,pt.current);return oe.holderPosition!==void 0&&b.set(I.id,oe.holderPosition),{...$,position:{x:oe.x,y:oe.y}}}}if(I&&Ke(I)&&I.parentId){let K=ue(I.parentId);if(K&&K.type==="rack"){let oe=ir(I,K,$.position,pt.current);return oe.uPosition!==void 0&&w.set(I.id,oe.uPosition),{...$,position:{x:oe.x,y:oe.y}}}}}return $}),H=reactflow.applyNodeChanges(T,pt.current).map($=>{let I=$;m.has($.id)&&(I={...I,extent:"parent"});let K=b.get($.id);K!==void 0&&(I={...I,data:{...I.data,holderPosition:K}});let oe=w.get($.id);return oe!==void 0&&(I={...I,data:{...I.data,uPosition:oe}}),I});pt.current=H;let F=new Map;return H.forEach($=>{F.set($.id,$);}),Ro.current=F,j(H),H},[j,ue,Pe]),qa=Qe.useCallback((s,b)=>{Vt(null);},[]),Ja=Qe.useCallback((s,b,w)=>{let m=je(b);if(!N||!Ke(b)||m){Vt(null);return}let T=pt.current.filter(I=>I.type==="rack").map(I=>I),H=Qo(b),$=Dr(H,T)?.id??null;Vt(I=>I===$?I:$);},[N,Qo,je]),Qa=Qe.useCallback((s,b,w)=>{Vt(null);let m=je(b);if(!N||!Ke(b)||m)return;let T=Dt(b),H=pt.current.filter(W=>W.type==="rack").map(W=>W),F=Qo(b),$=Dr(F,H),I=pt.current;if(!$)return;let K={x:T.x-$.position.x,y:T.y-$.position.y},oe=I.find(W=>W.id===b.id)||b,Re=He($.data),Te=Mt($.data),Se=At($.data),Ye=Re?ga(oe.data,K.x,Te,Se):"both",qe=Re&&Ye==="front"?Te+Se:0,Me=Ye==="rear"?"rear":Ye==="front"?"front":oe.data.view==="front"||oe.data.view==="rear"?oe.data.view:void 0,Ue={...oe,parentId:$.id,extent:"parent",position:{x:qe,y:K.y},data:{...oe.data,rackLayout:Re?"split-face":"single-face",rackWidthPx:Te,rackFaceGapPx:Se,mountMode:Ye,view:Me}},$e=I.filter(W=>W.id!==b.id).concat(Ue),ye=ir(Ue,$,Ue.position,$e);if(ye.uPosition===void 0||!jt($,Ue,ye.uPosition,$e))return;let et=I.map(W=>W.id!==b.id?W:{...W,parentId:$.id,extent:"parent",position:{x:ye.x,y:ye.y},data:{...W.data,rackLayout:Re?"split-face":"single-face",rackWidthPx:Te,rackFaceGapPx:Se,mountMode:Ye,view:Me,uPosition:ye.uPosition??W.data.uPosition}});Jo(et);},[N,Dt,Qo,Jo,je]),es=Qe.useCallback(s=>{if(!s.source||!s.target||!s.sourceHandle||!s.targetHandle)return true;let b=ue(s.source),w=ue(s.target),m=re(b,s.sourceHandle),T=re(w,s.targetHandle),H=J.current.some(Z=>Z.source===s.source?re(b,Z.sourceHandle)===m:Z.target===s.source?re(b,Z.targetHandle)===m:false),F=J.current.some(Z=>Z.target===s.target?re(w,Z.targetHandle)===T:Z.source===s.target?re(w,Z.sourceHandle)===T:false);if(H&&a&&console.log("Connection will replace: Source handle already connected",{source:s.source,sourceHandle:s.sourceHandle,existingEdges:J.current.filter(Z=>Z.source===s.source&&Z.sourceHandle===s.sourceHandle||Z.target===s.source&&Z.targetHandle===s.sourceHandle)}),F&&a&&console.log("Connection will replace: Target handle already connected",{target:s.target,targetHandle:s.targetHandle,existingEdges:J.current.filter(Z=>Z.target===s.target&&Z.targetHandle===s.targetHandle||Z.source===s.target&&Z.sourceHandle===s.targetHandle)}),!Er(b,w))return true;if(b?.type==="splice"&&w?.type==="splice"){let Z=b.data?.mode==="ribbon",ge=w.data?.mode==="ribbon";if(Z!==ge)return a&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",s),false}let I=(Z,ge)=>(Z?.type==="tube"||Z?.type==="cable")&&!!ge&&ge.startsWith("fiber-"),K=(Z,ge)=>(Z?.type==="tube"||Z?.type==="multi-tube-cable")&&!!ge&&ge.startsWith("tube-"),oe=(Z,ge)=>Z?.type==="multi-tube-cable"&&!!ge&&ge.startsWith("tube-"),Re=(Z,ge)=>Z?.type==="tube"&&!!ge&&ge.startsWith("tube-"),Te=(Z,ge)=>(Z?.type==="cable"||Z?.type==="multi-tube-cable")&&ge==="cable-button",Se=(Z,ge)=>Z?.type==="splice"&&(ge==="left"||ge==="right"),Ye=(Z,ge)=>Z?.type==="coupler"&&!!ge&&(ge.startsWith("left-")||ge.startsWith("right-")),qe=(Z,ge)=>{if(Z?.type!=="fibre-split"||!ge)return false;let P=ge.replace(/-(source|target)$/i,"");return P.startsWith("input-")||P.startsWith("output-")},Me=I(b,s.sourceHandle),Ue=I(w,s.targetHandle),$e=Se(b,s.sourceHandle),ye=Se(w,s.targetHandle),et=Ye(b,s.sourceHandle),W=Ye(w,s.targetHandle),Ie=qe(b,s.sourceHandle),ne=qe(w,s.targetHandle),Io=Te(b,s.sourceHandle),jr=Te(w,s.targetHandle),po=oe(b,s.sourceHandle),fo=oe(w,s.targetHandle),Yr=Re(b,s.sourceHandle),Kr=Re(w,s.targetHandle),er=K(b,s.sourceHandle),Zr=K(w,s.targetHandle);return Me&&ye||Ue&&$e||($e&&(W||ne)||ye&&(et||Ie))||(et&&(W||ne||ye)||W&&(et||Ie||$e))||Io&&jr||(po&&Kr||fo&&Yr)?true:er&&Zr?(a&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",s),false):(a&&console.log("Connection rejected: Connection not allowed by fiber rules",s),false)},[ue,a]),ts=Qe.useCallback(s=>{if(Pe)return;a&&console.log("onConnect called:",s);let b=ue(s.source),w=ue(s.target);a&&(console.log("onConnect: sourceNode type:",b?.type,"targetNode type:",w?.type),console.log("onConnect: sourceHandle:",s.sourceHandle,"targetHandle:",s.targetHandle));let m=xa(s,b,w),T=q.validateConnection({source:m.source??null,target:m.target??null,sourceHandle:m.sourceHandle,targetHandle:m.targetHandle});if(!T.valid&&!(T.reason??"").includes("already connected")){a&&console.warn(`Connection rejected: ${T.reason}`);return}let H=b?.type==="vertical-pdu",F=b?.type==="vertical-pdu"||w?.type==="vertical-pdu",$=io(b,m.sourceHandle),I=io(w,m.targetHandle),K=$&&I&&F,oe=b?.data,Re=b?.type==="switch"||b?.type==="device"&&oe?.deviceType==="switch",Te=I,Se=!!m.targetHandle&&(m.targetHandle.startsWith("net-")||m.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(We(m.targetHandle))),Ye=!!m.sourceHandle&&(m.sourceHandle.startsWith("net-")||m.sourceHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(We(m.sourceHandle))),qe=w?.type==="switch"||w?.type==="device"&&w.data?.deviceType==="switch",Me=w?.type==="vertical-pdu",Ue=$,$e=b?.type==="tube"&&w?.type==="multi-tube-cable",ye=b?.type==="multi-tube-cable"&&w?.type==="tube",et=$e||ye,W=m.sourceHandle==="cable-button"&&m.targetHandle==="cable-button",Ie="fiber";K?Ie="power":W?Ie="thick-cable":et&&(Ie=Y?"smoothstep":"fiber");let ne,Io=ha(w),jr=ha(b);if(Io||jr){let P=w?.data,G=b?.data,me=Io?P.ribbonFiberIds:G.ribbonFiberIds;me&&Array.isArray(me)&&me.length>=6&&me.length<=12&&(ne={ribbonFiberIds:me,isRibbon:true});}if(!ne&&(Ie==="fiber"||Ie==="smoothstep")&&!H){let P;$e?P=To(m.target,m.targetHandle):P=To(m.source,m.sourceHandle),P&&(ne={color:P.color,striped:P.striped,isRibbon:false});}else if(Ie==="thick-cable"&&W){let P=b?.data;ne={color:P?.color||(P?.tubeStartIndex?Ve(P.tubeStartIndex):"#6366f1")};}let po=re(b,m.sourceHandle),fo=re(w,m.targetHandle),Yr=J.current.some(P=>P.source===m.source?re(b,P.sourceHandle)===po:P.target===m.source?re(b,P.targetHandle)===po:false),Kr=J.current.some(P=>P.target===m.target?re(w,P.targetHandle)===fo:P.source===m.target?re(w,P.sourceHandle)===fo:false);if(Yr||Kr){let P=new Set;for(let G of J.current){if(G.source===m.source&&re(b,G.sourceHandle)===po){P.add(G.id);continue}if(G.target===m.source&&re(b,G.targetHandle)===po){P.add(G.id);continue}if(G.source===m.target&&re(w,G.sourceHandle)===fo){P.add(G.id);continue}G.target===m.target&&re(w,G.targetHandle)===fo&&P.add(G.id);}if(P.size>0){let G=J.current.filter(ft=>!P.has(ft.id)),me=reactflow.addEdge(m,G);if(me.length===G.length)a&&console.warn("Handle replacement skipped: addEdge did not create a new edge",m);else {let ft=me[me.length-1],_t=le({...m,id:ft.id,type:Ie}),Xt={...ft,type:Ie,zIndex:_t,style:{...ft.style,zIndex:_t},data:ne!==void 0?ne:ft.data};he([...me.slice(0,-1),Xt]),a&&console.log("Handle replacement: Replaced",P.size,"edge(s)");return}}}if(w?.type==="splice"&&(s.targetHandle==="left"||s.targetHandle==="right")&&s.target&&s.targetHandle){let P=J.current.find(G=>G.target===s.target&&G.targetHandle===s.targetHandle||G.source===s.target&&G.sourceHandle===s.targetHandle);if(P){a&&(console.log("Splice target handle replacement: Found existing edge",P.id,"on splice handle",s.targetHandle),console.log("Existing edge details:",{id:P.id,source:P.source,target:P.target,sourceHandle:P.sourceHandle,targetHandle:P.targetHandle,data:P.data}));let G=s.source&&s.sourceHandle?J.current.find(wt=>wt.source===s.source&&wt.sourceHandle===s.sourceHandle):null;a&&G&&console.log("Splice target handle replacement: Also found existing source edge",G.id);let me=new Set;P&&me.add(P.id),G&&G.id!==P.id&&me.add(G.id);let ft=J.current.filter(wt=>!me.has(wt.id));a&&console.log("Splice target handle replacement: Removing",me.size,"edge(s), creating new connection");let _t=`edge-${s.source}-${s.sourceHandle}-${s.target}-${s.targetHandle}-${Date.now()}`,Xt=le({...s,id:_t,type:"fiber"}),Eo={id:_t,source:s.source,target:s.target,sourceHandle:s.sourceHandle,targetHandle:s.targetHandle,type:"fiber",zIndex:Xt,style:{zIndex:Xt},data:ne!==void 0?ne:{}},Jr=[...ft,Eo];he(Jr),a&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Eo.id);return}}if(b?.type==="splice"&&s.sourceHandle==="right"&&s.source&&s.sourceHandle){let P=J.current.find(G=>G.source===s.source&&G.sourceHandle===s.sourceHandle||G.target===s.source&&G.targetHandle===s.sourceHandle);if(P){a&&console.log("Splice source handle replacement: Found existing edge",P.id,"on splice handle",s.sourceHandle);let G=s.target&&s.targetHandle?J.current.find(wt=>wt.target===s.target&&wt.targetHandle===s.targetHandle):null;a&&G&&console.log("Splice source handle replacement: Also found existing target edge",G.id);let me=new Set;P&&me.add(P.id),G&&G.id!==P.id&&me.add(G.id);let ft=J.current.filter(wt=>!me.has(wt.id));a&&console.log("Splice source handle replacement: Removing",me.size,"edge(s), creating new connection");let _t=`edge-${s.source}-${s.sourceHandle}-${s.target}-${s.targetHandle}-${Date.now()}`,Xt=le({...s,id:_t,type:"fiber"}),Eo={id:_t,source:s.source,target:s.target,sourceHandle:s.sourceHandle,targetHandle:s.targetHandle,type:"fiber",zIndex:Xt,style:{zIndex:Xt},data:ne!==void 0?ne:{}},Jr=[...ft,Eo];he(Jr),a&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Eo.id);return}}if((b?.type==="tube"||b?.type==="cable")&&s.sourceHandle?.startsWith("fiber-")&&s.source&&s.sourceHandle){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if((w?.type==="tube"||w?.type==="cable")&&s.targetHandle?.startsWith("fiber-")&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if((b?.type==="multi-tube-cable"||b?.type==="tube")&&s.sourceHandle?.startsWith("tube-")&&s.source&&s.sourceHandle){let P=Le({edges:J.current,connection:m,edgeType:Ie,selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if((w?.type==="multi-tube-cable"||w?.type==="tube")&&s.targetHandle?.startsWith("tube-")&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:Ie,selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(b?.type==="coupler"&&(s.sourceHandle?.startsWith("left-")||s.sourceHandle?.startsWith("right-"))){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if(w?.type==="coupler"&&(s.targetHandle?.startsWith("left-")||s.targetHandle?.startsWith("right-"))){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(W&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let P=b?.data,G=P?.color||(P?.tubeStartIndex?Ve(P.tubeStartIndex):"#6366f1"),me=Le({edges:J.current,connection:m,edgeType:"thick-cable",selectEdgeZIndex:le,findBy:"source",data:{color:G}});if(me){he(me);return}if(me=Le({edges:J.current,connection:m,edgeType:"thick-cable",selectEdgeZIndex:le,findBy:"target",data:{color:G}}),me){he(me);return}}if(H&&Te&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:"power",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(Me&&Ue&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:"power",selectEdgeZIndex:le,findBy:"source",matchOn:"target",data:ne});if(P){he(P);return}}if(Re&&Se&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",data:ne});if(P){he(P);return}}if(qe&&Ye&&s.source&&s.sourceHandle&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",matchOn:"source",data:ne});if(P){he(P);return}}let er=q.validateConnection({source:m.source??null,target:m.target??null,sourceHandle:m.sourceHandle,targetHandle:m.targetHandle});if(!er.valid){if(H&&s.source&&s.sourceHandle){let P=Le({edges:J.current,connection:m,edgeType:Te?"power":"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if(Me&&s.source&&s.sourceHandle){let P=Le({edges:J.current,connection:m,edgeType:"power",selectEdgeZIndex:le,findBy:"source",matchOn:"target",data:ne});if(P){he(P);return}}if(Re&&s.source&&s.sourceHandle){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"source",data:ne});if(P){he(P);return}}if(qe&&s.target&&s.targetHandle){let P=Le({edges:J.current,connection:m,edgeType:"fiber",selectEdgeZIndex:le,findBy:"target",matchOn:"source",data:ne});if(P){he(P);return}}a&&console.warn(`Connection rejected: ${er.reason}`);return}let Zr=J.current.some(P=>P.source===m.source&&P.sourceHandle===m.sourceHandle||P.target===m.source&&P.targetHandle===m.sourceHandle),di=J.current.some(P=>P.target===m.target&&P.targetHandle===m.targetHandle||P.source===m.target&&P.sourceHandle===m.targetHandle),qr=(P,G)=>!P||!G?false:!!(P.startsWith("tube-")||G.type==="splice"&&(P==="left"||P==="right")||P==="cable-button"),ci=qr(m.sourceHandle||"",b),li=qr(m.targetHandle||"",w);if(Zr&&!ci){a&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:s.source,sourceHandle:m.sourceHandle,existingEdges:J.current.filter(P=>P.source===m.source&&P.sourceHandle===m.sourceHandle||P.target===m.source&&P.targetHandle===m.sourceHandle)});return}if(di&&!li){a&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:m.target,targetHandle:m.targetHandle,existingEdges:J.current.filter(P=>P.target===m.target&&P.targetHandle===m.targetHandle||P.source===m.target&&P.sourceHandle===m.targetHandle)});return}let ui={...m,type:Ie,zIndex:le({...m,id:"temp-id"}),data:ne},Z=reactflow.addEdge(ui,J.current),ge=Z[Z.length-1];ge&&(si(P=>new Set(P).add(ge.id)),setTimeout(()=>{si(P=>{let G=new Set(P);return G.delete(ge.id),G});},1e3)),he(Z);},[he,q,le,ue,a,To,Y,Pe]),os=Qe.useCallback((s,b)=>{if(Pe||!b.source||!b.target||!b.sourceHandle||!b.targetHandle)return;let w=ue(b.source),m=ue(b.target),T=xa(b,w,m),H=re(w,T.sourceHandle),F=re(m,T.targetHandle),$=J.current.some(W=>{if(W.id===s.id)return false;let Ie=W.source===T.source&&re(w,W.sourceHandle)===H||W.target===T.source&&re(w,W.targetHandle)===H,ne=W.target===T.target&&re(m,W.targetHandle)===F||W.source===T.target&&re(m,W.sourceHandle)===F;return Ie||ne}),I=q.validateConnection({source:T.source??null,target:T.target??null,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,ignoreEdgeId:s.id});if(!I.valid&&!((I.reason??"").includes("already connected")&&$)){a&&console.warn(`Edge update rejected: ${I.reason}`);return}let K=w?.type==="vertical-pdu"||m?.type==="vertical-pdu",oe=io(w,T.sourceHandle),Re=io(m,T.targetHandle),Te=oe&&Re&&K,Se=w?.type==="tube"&&m?.type==="multi-tube-cable",Ye=w?.type==="multi-tube-cable"&&m?.type==="tube",qe=Se||Ye,Me;Te?Me="power":qe?Me=Y?"smoothstep":"fiber":Me="fiber";let Ue;if(Me==="fiber"||Me==="smoothstep"){let W=To(T.source,T.sourceHandle);W&&(Ue={color:W.color,striped:W.striped});}let et=J.current.filter(W=>{if(W.id===s.id)return true;let Ie=W.source===T.source&&re(w,W.sourceHandle)===H||W.target===T.source&&re(w,W.targetHandle)===H,ne=W.target===T.target&&re(m,W.targetHandle)===F||W.source===T.target&&re(m,W.sourceHandle)===F;return !(Ie||ne)}).map(W=>W.id===s.id?{...W,source:T.source,target:T.target,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,type:Me,data:Ue!==void 0?{...W.data,...Ue}:W.data,zIndex:le({...T,id:W.id,type:Me}),style:{...W.style,zIndex:le({...T,id:W.id,type:Me})}}:W);he(et);},[he,ue,To,le,Y,a,q,Pe]),rs=Qe.useCallback((s,b)=>{if(Fe){c&&c(b);return}let w=s.metaKey||s.ctrlKey,m=ot(),T=b,H=je(b);if(b.type==="tube"&&H&&!w){let F=m.find($=>$.id===H&&($.type==="cable"||$.type==="multi-tube-cable"));F&&(T=F);}if(Vr(T),So([]),j(F=>F.map($=>{let I=$.id===T.id;return $.selected===I?$:{...$,selected:I}})),w&&Ke(T)&&!lo(T)){let F=T.data||{},$=F.view||(Array.isArray(F.rearPorts)&&F.rearPorts.length>0?"rear":"front"),I=$==="front"?"rear":"front";a&&console.log(`Command+click: Toggling device ${T.id} from ${$} to ${I}`),x&&x(T.id,I);}c&&c(T);},[x,c,a,ot,j,Fe,je,lo]),ns=Qe.useCallback(()=>{},[]),is=Qe.useCallback((s,b)=>{Vr(null),So([b]),j(w=>w.map(m=>m.selected?{...m,selected:false}:m)),c?.(null),l&&l(b);},[l,c,j]),as=Qe.useCallback(()=>{Vr(null),So([]),j(s=>s.map(b=>b.selected?{...b,selected:false}:b)),c?.(null);},[c,j]),[rt,Vr]=Qe.useState(null),[ai,si]=Qe.useState(new Set);reactflow.useOnSelectionChange({onChange:({edges:s})=>{So(s||[]);}});let[Gr,So]=Qe.useState([]);Qe.useEffect(()=>{let s=b=>{if(De.allowKeyboardDelete&&(b.key==="Backspace"||b.key==="Delete")&&Gr.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let w=Gr.filter(m=>{let T=m.sourceHandle||"",H=m.targetHandle||"";return T.startsWith("tube-")||H.startsWith("tube-")?(a&&console.log("Cannot delete edge connected to tube handle",m),false):true});if(w.length>0){let m=new Set(w.map(H=>H.id)),T=J.current.filter(H=>!m.has(H.id));he(T),So([]),a&&console.log("Deleted edges:",w.map(H=>H.id));}}};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[Gr,he,a,De.allowKeyboardDelete]);let ss=Qe.useCallback((s,{nodeId:b,handleType:w})=>{a&&console.log("Connection started from",{nodeId:b,handleType:w});},[a]),ds=Qe.useCallback(s=>{a&&console.log("Connection ended",s);},[a]),cs=Qe.useCallback(()=>{if(Pe||!rt)return;let s=ue(rt.id);if(s){if(s.type==="rack"){let b=s.data||{};if(He(b))return;let m=(b.face||"front")==="front"?"rear":"front";k?(k(s.id,m),x&&ot().filter(H=>H.parentId===s.id).forEach(H=>{x(H.id,m);})):j(T=>T.map(H=>H.id===s.id?{...H,data:{...H.data,face:m}}:H.parentId===s.id?{...H,data:{...H.data,view:m}}:H));return}if(Ke(s)){if(lo(s))return;let b=s.data||{},w=Array.isArray(b.rearPorts)&&b.rearPorts.length>0,m=Array.isArray(b.ports)&&b.ports.length>0,H=(b.view||(w&&!m?"rear":"front"))==="front"?"rear":"front";x?x(s.id,H):j(F=>F.map($=>$.id===s.id?{...$,data:{...$.data,view:H}}:$));}}},[rt,ue,k,x,j,ot,Pe,lo]),ls=Qe.useCallback(()=>{if(Pe||!N||!rt||!Ke(rt))return;let s=ue(rt.id),b=je(s);if(!s||!Ke(s)||!b)return;let w=Dt(s),T=pt.current.map(H=>H.id!==s.id?H:{...H,parentId:void 0,parentNode:void 0,extent:void 0,position:w,data:{...H.data,uPosition:void 0}});Jo(T);},[Pe,N,rt,ue,Dt,Jo,je]),us=Qe.useMemo(()=>{let s=Ro.current;return we.map(b=>{let w=b,m=s.get(String(w.source)),T=s.get(String(w.target)),H=Fr(w.sourceHandle||"",m),F=Fr(w.targetHandle||"",T),$=$e=>{if(!$e||!Ke($e))return;let ye=$e.data??{},et=typeof $e.parentId=="string"?$e.parentId:$e.parentNode,W=et?s.get(et):void 0;if(W&&W.type==="rack"&&He(W.data))return $t(Oe(ye));let Ie=Array.isArray(ye.rearPorts)&&ye.rearPorts.length>0,ne=Array.isArray(ye.ports)&&ye.ports.length>0;return [ye.view||(Ie&&!ne?"rear":"front")]},I=$(m),K=$(T),oe=Ur(m),Re=Ur(T),Te=Ke(m)&&!oe&&!!I&&!!H&&!I.includes(H),Se=Ke(T)&&!Re&&!!K&&!!F&&!K.includes(F),Me=Te||Se,Ue=b.style;if(Me)Ue={...b.style,opacity:0,pointerEvents:"none",zIndex:0};else if(b.style&&b.style.opacity===0&&b.style.pointerEvents==="none"&&b.style.zIndex===0){let ye={...b.style};delete ye.opacity,delete ye.pointerEvents,delete ye.zIndex,Ue=Object.keys(ye).length>0?ye:void 0;}return {...b,style:Ue,className:ai.has(b.id)?"edge-connecting":b.className}})},[we,ai,Ur]),Ee=Qe.useMemo(()=>rt?ue(rt.id)??rt:null,[rt,ue]),uo=Qe.useMemo(()=>{if(!Ee||!Ut.enabled||Pe)return {showRearToggle:false,showDeRack:false,count:0};let s=Ee.type==="rack"?!ni(Ee):Ke(Ee)?!lo(Ee):false,b=Ut.showRearToggle&&s,w=Ut.showDeRack&&N&&!Pe&&Ke(Ee)&&!!je(Ee);return {showRearToggle:b,showDeRack:w,count:(b?1:0)+(w?1:0)}},[Ee,Ut,N,Pe,je,lo,ni]),Xr=Qe.useMemo(()=>{if(!Ee||uo.count===0||!Xe.current)return null;let s=Xe.current.getBoundingClientRect();if(s.width<=0||s.height<=0)return null;let b=Ee.positionAbsolute??Dt(Ee),w=Ee.width||0,m=Ee.height||0,T=uo.count>1?220:110,H=34;try{let F=ct({x:b.x+w/2,y:b.y}),$=ct({x:b.x+w/2,y:b.y+m}),I=F.x-s.left-T/2,K=F.y-s.top-H-10;return K<8&&(K=$.y-s.top+10),I=Math.max(8,Math.min(I,s.width-T-8)),K=Math.max(8,Math.min(K,s.height-H-8)),{left:I,top:K}}catch{return null}},[Ee,uo,Dt,ct]),ps=fi(R,v),fs=bi(R,{touchAction:"none",...C});return jsxRuntime.jsxs("div",{ref:Xe,className:ps,style:fs,children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:Ne,edges:us,onNodesChange:s=>{if(Pe)return;let b=Za(s);b&&(L?n&&n(b):q.setState({nodes:b}));},onEdgesChange:s=>{if(Pe)return;let b=s.filter(w=>{if(w.type==="remove"){let m=J.current.find(T=>T.id===w.id);if(m){let T=m.sourceHandle||"",H=m.targetHandle||"";if(T.startsWith("tube-")||H.startsWith("tube-"))return a&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",m),false}}return true});if(b.length>0){let w=reactflow.applyEdgeChanges(b,J.current);st(b),L?i&&i(w):q.setState({edges:w});}},onConnect:Pe?void 0:p??ts,onConnectStart:ss,onConnectEnd:ds,onEdgeUpdate:Pe?void 0:u??os,isValidConnection:y??es,connectionMode:h,onNodeClick:rs,onNodeDoubleClick:ns,onPaneClick:as,onNodeDragStart:qa,onNodeDrag:Ja,onNodeDragStop:Qa,onEdgeClick:is,onInit:D,nodeTypes:yt.current,edgeTypes:co,defaultEdgeOptions:{zIndex:1e3,reconnectable:De.edgesReconnectable},nodesDraggable:De.nodesDraggable,nodesConnectable:De.nodesConnectable,elementsSelectable:De.elementsSelectable,edgesFocusable:De.edgesFocusable,elevateNodesOnSelect:false,selectNodesOnDrag:false,connectOnClick:De.connectOnClick,panOnDrag:De.panOnDrag,panOnScroll:De.panOnScroll,zoomOnScroll:De.zoomOnScroll,zoomOnPinch:De.zoomOnPinch,zoomOnDoubleClick:De.zoomOnDoubleClick,preventScrolling:Fe,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:te,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:gi(R)}),De.showControls&&jsxRuntime.jsx(reactflow.Controls,{showInteractive:De.showInteractiveControl}),De.showMiniMap&&jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&jsxRuntime.jsx("button",{className:"download-button",onClick:Wr,disabled:lt,"aria-busy":lt,style:{position:"absolute",top:_.includes("top")?"10px":"auto",bottom:_.includes("bottom")?"10px":"auto",right:_.includes("right")?"10px":"auto",left:_.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:lt?"not-allowed":"pointer",opacity:lt?.7:1,transition:"all 0.2s ease",...se},children:lt?`${U}...`:U}),Ee&&Xr&&uo.count>0&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:Xr.top,left:Xr.left,display:"flex",gap:8,zIndex:2e3},children:[uo.showRearToggle&&jsxRuntime.jsx("button",{onClick:s=>{s.preventDefault(),cs();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let s=Ee.data;if(Ee.type==="rack")return (s?.face||"front")==="front"?"Switch to rear":"Switch to front";{let b=Array.isArray(s?.rearPorts)&&s.rearPorts.length>0,w=Array.isArray(s?.ports)&&s.ports.length>0;return (s?.view||(b&&!w?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let s=Ee.data;if(Ee.type==="rack")return (s?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let b=Array.isArray(s?.rearPorts)&&s.rearPorts.length>0,w=Array.isArray(s?.ports)&&s.ports.length>0;return (s?.view||(b&&!w?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()}),uo.showDeRack&&jsxRuntime.jsx("button",{onClick:s=>{s.preventDefault(),ls();},style:{background:"#7f1d1d",color:"#fee2e2",border:"1px solid #b91c1c",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:"Remove device from rack so it can be moved/reassigned",children:"De-rack"})]})]})},Zn=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(mc,{...e})});var qn=class extends Qe.Component{constructor(){super(...arguments);this.state={error:null};this.reset=()=>{this.setState({error:null});};}static getDerivedStateFromError(o){return {error:o}}componentDidCatch(o,r){this.props.onError?.(o,r);}render(){let{error:o}=this.state,{children:r,fallback:n}=this.props;return o?typeof n=="function"?n(o,this.reset):n??jsxRuntime.jsxs("div",{role:"alert",style:{padding:16,margin:8,border:"1px solid #e53e3e",borderRadius:4,backgroundColor:"#fff5f5",color:"#c53030"},children:[jsxRuntime.jsx("strong",{children:"Diagram error"}),": ",o.message,jsxRuntime.jsx("button",{type:"button",onClick:this.reset,style:{marginLeft:12,padding:"4px 8px",cursor:"pointer"},children:"Try again"})]}):r}};function jo(e,{rowHeight:t,tubeGap:o}){let r=[],n=[],i=e.kind??(e.tubeCount?"tube":"simple"),d=i==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,a=i==="tube"?Math.max(1,Math.min(24,e.fibersPerTube??12)):Math.max(1,Math.min(24,e.fiberCount??12)),c=Math.max(1,e.tubeStartIndex??1),l=Math.max(1,e.fiberStartIndex??1),g=0;for(let f=0;f<d;f+=1){let p=c+f,u=e.tubeColorMap?.[p];n.push({tubeIndex:p,y:g,label:`T${p}`,color:u??Ve(p)});for(let y=0;y<a;y+=1){let h=l+y,x=on(h);r.push({key:`${p}-${h}`,tubeIndex:i==="tube"?p:void 0,fiberIndex:h,y:g,color:qt(h),striped:Zt(h),backgroundImage:typeof x.backgroundImage=="string"?x.backgroundImage:void 0}),g+=t;}f<d-1&&(g+=o);}return {rows:r,tubeLabels:n,height:g}}var Jn=e=>typeof e=="object"&&e!==null,Nc=e=>{if(!Jn(e.data))return false;if(e.type==="fibre-flow-cable"){let t=e.data;return typeof t.label=="string"&&Jn(t.cable)&&(t.side==="left"||t.side==="right")&&typeof t.rowHeight=="number"&&typeof t.columnWidth=="number"&&typeof t.showTubeLabels=="boolean"&&typeof t.showFiberNumbers=="boolean"&&Jn(t.layout)}if(e.type==="fibre-flow-closure"){let t=e.data;return typeof t.label=="string"&&typeof t.width=="number"&&typeof t.height=="number"&&typeof t.headerHeight=="number"}return false},kc=e=>e==="fibre-flow"||e==="fibre-flow-link",Pc=e=>typeof e.id=="string"&&e.id.length>0&&typeof e.source=="string"&&e.source.length>0&&typeof e.target=="string"&&e.target.length>0,Cc=e=>e.sourceHandle==="cable-run"||e.targetHandle==="cable-run"?"fibre-flow-link":"fibre-flow",vc=(e,t=[])=>{let o=new Map(t.map(n=>[n.id,n])),r=[];return e.forEach(n=>{if(!Pc(n))return;let i=o.get(n.id),d=kc(n.type)?n.type:i?.type??Cc(n);r.push({...i??{},...n,type:d});}),r},va=e=>`fiber-${e.tube??1}-${e.fiber}`,Ra=e=>qt(e.fiber),Ta=e=>Zt(e.fiber),Rc=(e,t)=>{if(t)return t;if(!(typeof e!="number"||Number.isNaN(e)))return e>=1e3?`${(e/1e3).toFixed(1)} km`:`${Math.round(e)} m`},Tc=(e,t,o,r,n,i)=>e?`${o} ${i}`:t?`0 ${n} ${r} ${i}`:"6 6",Sc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a})=>{let[c,l,g]=reactflow.getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.35}),f=typeof a?.lossDb=="number"?`${a.lossDb.toFixed(2)} dB`:"",p=a?.label??f,u=a?.sourceColor,y=a?.targetColor,h=a?.color??u??y??"#94a3b8",x=a?.sourceStriped??false,k=a?.targetStriped??false,v=a?.highlighted??true,C=a?.dimmed??false,S=a?.circuitId,N=a?.circuitLabel??S,R=a?.showCircuitId??false,D=u&&y&&u!==y,E=r-t,A=n-o,_=Math.sqrt(E*E+A*A),U=l-t,se=g-o,Y=Math.sqrt(U*U+se*se),ee=_>0?Y/_*100:50,ie=`fibre-flow-gradient-${e}`,z=x&&!k,V=k&&!x,B=x&&k,O=_*1.25,X=O/2,te=12,M=Math.ceil(X*1.2/te),L=Array(M).fill("6 6").join(" "),de=Math.ceil(X*1.2/te),ae=Array(de).fill("6 6").join(" "),ce=R&&N,q=Math.max(p?p.length*6.2+16:0,ce?(N?.length||0)*5.5+16:0),xe=ce?32:16;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("defs",{children:D&&jsxRuntime.jsxs("linearGradient",{id:ie,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0%",stopColor:u}),jsxRuntime.jsx("stop",{offset:`${ee}%`,stopColor:u}),jsxRuntime.jsx("stop",{offset:`${ee}%`,stopColor:y}),jsxRuntime.jsx("stop",{offset:"100%",stopColor:y})]})}),D?jsxRuntime.jsx("path",{id:e,d:c,fill:"none",stroke:`url(#${ie})`,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,style:{mixBlendMode:"normal"}}):jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:c,style:{stroke:h,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,mixBlendMode:"normal"}}),(B||z||V)&&jsxRuntime.jsx("path",{id:`${e}-stripe`,d:c,fill:"none",stroke:"#000",strokeWidth:v?1.6:1.3,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:Tc(z,V,L,ae,X,O),strokeDashoffset:0,opacity:C?.2:.9,style:{mixBlendMode:"normal"}}),(p||ce)&&v&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${g}px)`,width:q,height:xe,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:[p&&jsxRuntime.jsx("div",{style:{lineHeight:1.2},children:p}),ce&&jsxRuntime.jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:p?2:0},children:N})]})})]})},Ic=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,data:a})=>{let[c,l,g]=reactflow.getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.2}),f=a?.label,p=a?.color??"#64748b";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:c,style:{stroke:p,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),f&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${g}px)`,padding:"2px 8px",background:"rgba(30, 41, 59, 0.9)",border:`1px solid ${p}`,borderRadius:10,fontSize:10,fontFamily:"monospace",color:"#e2e8f0",letterSpacing:.2,whiteSpace:"nowrap",pointerEvents:"none",zIndex:9999},children:f})})]})},Ec=({data:e})=>{let{cable:t,side:o,rowHeight:r,columnWidth:n,showTubeLabels:i,showFiberNumbers:d,layout:a,colorMode:c="dark"}=e,l=c==="light",g=8,f=12,p=-1,u=0,y=t.jacketColor??"#facc15",h=(t.kind??(t.tubeCount?"tube":"simple"))==="tube",x=i&&h,k=o==="left"?g+u:u,v=o==="right"?g+u:u,C=o==="left"?reactflow.Position.Right:reactflow.Position.Left,S={width:4,height:4,borderRadius:"50%",background:y,border:`1px solid ${y}`,boxShadow:"0 0 1px rgba(0,0,0,0.4)",top:"50%",position:"absolute",...o==="left"?{left:0,transform:"translate(-50%, -50%)"}:{right:0,transform:"translate(50%, -50%)"}};return jsxRuntime.jsxs("div",{style:{position:"relative",width:n,height:a.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[jsxRuntime.jsx("div",{style:{position:"absolute",top:-18,left:o==="left"?0:void 0,right:o==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:l?"rgba(248, 250, 252, 0.95)":"rgba(15, 23, 42, 0.9)",color:l?"#1a1a1a":"#f8fafc",padding:"2px 6px",borderRadius:4,whiteSpace:"nowrap",maxWidth:n,overflow:"hidden",textOverflow:"ellipsis",zIndex:10,...o==="right"?{textAlign:"right"}:{}},children:t.label}),jsxRuntime.jsx("div",{style:{position:"absolute",top:0,bottom:0,width:g,left:o==="left"?0:void 0,right:o==="right"?0:void 0,borderRadius:4,background:h?"transparent":y,border:`1px solid ${y}`,boxShadow:h?"none":"inset 0 0 3px rgba(0,0,0,0.3)",overflow:"hidden"},children:h&&a.tubeLabels.map((N,R)=>{let D=a.rows.filter(Y=>Y.tubeIndex===N.tubeIndex);if(D.length===0)return null;let E=D[0].y,A=D[D.length-1].y+r,_=A-E,U=a.tubeLabels[R+1],se=U&&U.y-A>0;return jsxRuntime.jsx("div",{style:{position:"absolute",top:E,left:0,right:0,height:_,background:N.color,borderLeft:`2px solid ${N.color}`,borderRight:`2px solid ${N.color}`,borderTop:R===0?`2px solid ${N.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:se?"1px solid rgba(0,0,0,0.15)":`2px solid ${N.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:R===0&&!se||R===0?"4px 4px 0 0":se?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${N.tubeIndex}`)})}),!x&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,bottom:0,left:k,right:v,...o==="left"?{borderRight:`1px solid ${y}`}:{borderLeft:`1px solid ${y}`},pointerEvents:"none",zIndex:0}}),h&&a.tubeLabels.map((N,R)=>{let D=a.rows.filter(U=>U.tubeIndex===N.tubeIndex);if(D.length===0)return null;let E=D[0].y,_=D[D.length-1].y+r-E;return jsxRuntime.jsx("div",{style:{position:"absolute",top:E,left:k,right:v,height:_,...o==="left"?{borderRight:`2px solid ${N.color}`}:{borderLeft:`2px solid ${N.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${N.tubeIndex}`)}),a.rows.map(N=>{let R=`fiber-${N.tubeIndex??1}-${N.fiberIndex}`,D=N.y+r/2,E={position:"absolute",width:f,height:f,borderRadius:"50%",top:D,background:N.backgroundImage?N.backgroundImage:N.color,backgroundColor:N.color,border:`2px solid ${N.color}`,boxShadow:"0 0 6px rgba(0,0,0,0.3)",...o==="left"?{right:-f/2}:{left:-f/2},transform:"translateY(-50%)",zIndex:1e3,cursor:"crosshair","--fiber-bg":N.color,minWidth:f,minHeight:f};N.backgroundImage&&(E["--fiber-bg-image"]=N.backgroundImage);let A=o==="left"?{right:f+p,textAlign:"right"}:{left:f+p,textAlign:"left"};return jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:R,type:"source",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":N.fiberIndex,"data-tube-idx":N.tubeIndex,"data-fiber-color":N.color}),jsxRuntime.jsx(reactflow.Handle,{id:R,type:"target",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":N.fiberIndex,"data-tube-idx":N.tubeIndex,"data-fiber-color":N.color}),d&&jsxRuntime.jsx("div",{style:{position:"absolute",top:N.y+r/2-6,...A,fontSize:8,fontWeight:600,color:l?"rgba(15, 23, 42, 0.7)":"rgba(148, 163, 184, 0.95)",whiteSpace:"nowrap",lineHeight:1},children:N.fiberIndex})]},N.key)}),jsxRuntime.jsx(reactflow.Handle,{id:"cable-run",type:"source",position:o==="left"?reactflow.Position.Left:reactflow.Position.Right,className:"cable-run-handle",style:S,isConnectable:true,"data-handle-type":"cable-run"}),jsxRuntime.jsx(reactflow.Handle,{id:"cable-run",type:"target",position:o==="left"?reactflow.Position.Left:reactflow.Position.Right,className:"cable-run-handle",style:S,isConnectable:true,"data-handle-type":"cable-run"})]})},Hc=({data:e})=>{let t=e.colorMode==="light";return jsxRuntime.jsx("div",{style:{width:e.width,height:e.height,background:"transparent",border:t?"1px solid rgba(148, 163, 184, 0.3)":"1px solid rgba(148, 163, 184, 0.5)",borderRadius:12,boxShadow:t?"0 12px 24px rgba(0, 0, 0, 0.1)":"0 12px 24px rgba(15, 23, 42, 0.2)",position:"relative",pointerEvents:"none"},children:jsxRuntime.jsx("div",{style:{height:e.headerHeight,display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"monospace",fontWeight:700,fontSize:12,letterSpacing:.6,textTransform:"uppercase",color:t?"rgba(15, 23, 42, 0.9)":"rgba(226, 232, 240, 0.9)",background:t?"rgba(241, 245, 249, 0.7)":"rgba(15, 23, 42, 0.6)",borderBottom:t?"1px solid rgba(148, 163, 184, 0.2)":"1px solid rgba(148, 163, 184, 0.35)",borderTopLeftRadius:12,borderTopRightRadius:12},children:e.label})})},Fc=(e,t,o,r,n,i,d,a,c,l="dark")=>{let g=[],f=0;return e.forEach(p=>{let u=jo(p.leftCable,{rowHeight:o,tubeGap:r}),y=jo(p.rightCable,{rowHeight:o,tubeGap:r}),h=Math.max(u.height,y.height),x=i*2+d,k=32,v=16,C=x+v*2,S=h+k+v*2,N=`flow-closure-${p.id}`,R=`flow-cable-${p.id}-left`,D=`flow-cable-${p.id}-right`,E=t==="horizontal"?{x:f,y:0}:{x:0,y:f};f+=(t==="horizontal"?C:S)+n;let A=p.chamberId?`${p.id} - ${p.chamberId}`:p.id;g.push({id:N,type:"fibre-flow-closure",position:E,data:{label:A,width:C,height:S,headerHeight:k,colorMode:l},selectable:false,draggable:false,style:{width:C,height:S}});let _=k+v+(h-u.height)/2,U=k+v+(h-y.height)/2;g.push({id:R,type:"fibre-flow-cable",position:{x:v,y:_},parentId:N,extent:"parent",data:{label:p.leftCable.label,cable:p.leftCable,side:"left",rowHeight:o,columnWidth:i,showTubeLabels:a,showFiberNumbers:c,layout:u,colorMode:l},style:{width:i,height:u.height}}),g.push({id:D,type:"fibre-flow-cable",position:{x:v+x-i,y:U},parentId:N,extent:"parent",data:{label:p.rightCable.label,cable:p.rightCable,side:"right",rowHeight:o,columnWidth:i,showTubeLabels:a,showFiberNumbers:c,layout:y,colorMode:l},style:{width:i,height:y.height}});}),g},Dc=(e,t,o,r=false)=>{let n=[],i=new Map,d=new Map,a=new Map;return (t??[]).forEach(c=>{c.color&&i.set(c.id,c.color),c.label&&d.set(c.id,c.label);}),e.forEach(c=>{let l=`flow-cable-${c.id}-left`,g=`flow-cable-${c.id}-right`;[{nodeId:l,cable:c.leftCable},{nodeId:g,cable:c.rightCable}].forEach(({nodeId:p,cable:u})=>{let y=a.get(u.id);if(y&&y.closureId!==c.id){let h=Rc(u.distanceMeters??y.distanceMeters,u.distanceLabel??y.distanceLabel),x=u.jacketColor??y.jacketColor??"#64748b";n.push({id:`flow-link-${y.nodeId}-${p}`,type:"fibre-flow-link",source:y.nodeId,target:p,sourceHandle:"cable-run",targetHandle:"cable-run",data:{label:h,color:x}});}a.set(u.id,{nodeId:p,closureId:c.id,jacketColor:u.jacketColor,distanceLabel:u.distanceLabel,distanceMeters:u.distanceMeters});}),c.splices.forEach(p=>{let u=o?p.circuitId===o:true,y=!!o&&!u,h=p.circuitId?i.get(p.circuitId):void 0,x=p.circuitId?d.get(p.circuitId):void 0,k=p.color??h,v=Ra(p.from),C=Ra(p.to),S=Ta(p.from),N=Ta(p.to);n.push({id:`flow-edge-${c.id}-${p.id}`,type:"fibre-flow",source:l,target:g,sourceHandle:va(p.from),targetHandle:va(p.to),data:{lossDb:p.lossDb,label:p.label,color:k,sourceColor:v,targetColor:C,sourceStriped:S,targetStriped:N,highlighted:u,dimmed:y,circuitId:p.circuitId,circuitLabel:x,showCircuitId:r}});});}),n},_c=({closures:e,circuits:t,highlightedCircuitId:o,layout:r="horizontal",rowHeight:n=20,tubeGap:i=10,closureGap:d=140,cableColumnWidth:a=32,spliceAreaWidth:c=260,showTubeLabels:l=true,showFiberNumbers:g=true,colorMode:f="dark",showCircuitId:p=false,className:u,style:y,readOnly:h=false,panOnDrag:x=true,panOnScroll:k=true,zoomOnScroll:v=true})=>{let C=Qe.useMemo(()=>Fc(e,r,n,i,d,a,c,l,g,f),[e,r,n,i,d,a,c,l,g,f]),S=Qe.useMemo(()=>Dc(e,t,o,p),[e,t,o,p]),[N,R]=Qe.useState(C),[D,E]=Qe.useState(S);Qe.useEffect(()=>{R(C);},[C,R]),Qe.useEffect(()=>{E(S);},[S,E]);let A=Qe.useCallback((B,O)=>{if(!B||!O||!O.startsWith("fiber-"))return;let X=N.find(ce=>ce.id===B);if(!X||X.type!=="fibre-flow-cable")return;let te=/^fiber-(\d+)-(\d+)$/.exec(O);if(!te)return;let M=Number(te[1]),L=Number(te[2]),ae=X.data.layout.rows.find(ce=>(ce.tubeIndex??1)===M&&ce.fiberIndex===L);if(ae)return {color:ae.color,striped:ae.striped??false}},[N]),_=Qe.useCallback(B=>{if(h||!B.source||!B.target||!B.sourceHandle||!B.targetHandle)return false;let O=N.find(de=>de.id===B.source),X=N.find(de=>de.id===B.target);if(!O||!X)return false;let te=typeof B.sourceHandle=="string"&&B.sourceHandle.startsWith("fiber-"),M=typeof B.targetHandle=="string"&&B.targetHandle.startsWith("fiber-");return B.sourceHandle==="cable-run"||B.targetHandle==="cable-run"?true:te&&M?O.type==="fibre-flow-cable"&&X.type==="fibre-flow-cable":false},[N,h]),U=Qe.useCallback(B=>{if(h)return;let O=B.sourceHandle==="cable-run"||B.targetHandle==="cable-run",X=q=>typeof q=="string"&&q.startsWith("fiber-"),te=X(B.sourceHandle),M=X(B.targetHandle),L=(q,xe,Ce)=>q.source===xe&&q.sourceHandle===Ce||q.target===xe&&q.targetHandle===Ce,de=O?void 0:A(B.source,B.sourceHandle),ae=O?void 0:A(B.target,B.targetHandle),ce=O?void 0:{sourceColor:de?.color,targetColor:ae?.color,color:de?.color??ae?.color,sourceStriped:de?.striped,targetStriped:ae?.striped};E(q=>{let xe=q.filter(Ce=>{let Ne=te&&L(Ce,B.source,B.sourceHandle),j=M&&L(Ce,B.target,B.targetHandle);return !(Ne||j)});return reactflow.addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:ce},xe)});},[A,h,E]),se=Qe.useCallback((B,O)=>{if(h)return;let X=O.sourceHandle==="cable-run"||O.targetHandle==="cable-run",te=X?void 0:A(O.source,O.sourceHandle),M=X?void 0:A(O.target,O.targetHandle),L=X?void 0:{sourceColor:te?.color,targetColor:M?.color,color:te?.color??M?.color,sourceStriped:te?.striped,targetStriped:M?.striped},de=ce=>typeof ce=="string"&&ce.startsWith("fiber-"),ae=(ce,q,xe)=>ce.source===q&&ce.sourceHandle===xe||ce.target===q&&ce.targetHandle===xe;E(ce=>{let q=ce.filter(j=>j.id!==B.id),xe=de(O.sourceHandle),Ce=de(O.targetHandle),Ne=q.filter(j=>{let we=xe&&ae(j,O.source,O.sourceHandle),ke=Ce&&ae(j,O.target,O.targetHandle);return !(we||ke)});return reactflow.addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:L},Ne)});},[A,h,E]),Y=Qe.useCallback(B=>{h||R(B.filter(Nc));},[h,R]),ee=Qe.useCallback(B=>{h||E(O=>vc(B,O));},[h,E]),ie=Qe.useMemo(()=>({"fibre-flow-cable":Ec,"fibre-flow-closure":Hc}),[]),z=Qe.useMemo(()=>({"fibre-flow":Sc,"fibre-flow-link":Ic}),[]),V={borderRadius:8,overflow:"hidden",...y};return jsxRuntime.jsx(Zn,{nodes:N,edges:D,onNodesChange:Y,onEdgesChange:ee,onConnect:U,onEdgeUpdate:se,isValidConnection:_,connectionMode:reactflow.ConnectionMode.Loose,nodeTypes:ie,edgeTypes:z,className:u,style:V,colorMode:f,readOnly:h,panOnDrag:x,panOnScroll:k,zoomOnScroll:v,fitViewOptions:{padding:.2}})},Mc=e=>jsxRuntime.jsx(_c,{...e});var Lc=({cable:e,side:t,rowHeight:o=22,tubeGap:r=10,columnWidth:n=150,layout:i,showTubeLabels:d,showFiberNumbers:a=true,showCableLabel:c=true})=>{let l=Qe.useMemo(()=>i??jo(e,{rowHeight:o,tubeGap:r}),[i,e,o,r]),g=26,f=10,p=18,u=t==="left"?n-p:p,y=8,h=t==="left"?6:n-g-18,x=e.jacketColor??"#facc15",k=d??(e.kind??(e.tubeCount?"tube":"simple"))==="tube";return jsxRuntime.jsxs("div",{style:{position:"relative",width:n,height:l.height,fontFamily:"monospace",color:"inherit"},children:[c&&jsxRuntime.jsx("div",{style:{position:"absolute",top:-18,left:t==="left"?0:void 0,right:t==="right"?0:void 0,fontSize:10,fontWeight:700,letterSpacing:.4,textTransform:"uppercase",background:"rgba(15, 23, 42, 0.85)",color:"#f8fafc",padding:"2px 6px",borderRadius:4},children:e.label}),jsxRuntime.jsx("div",{style:{position:"absolute",top:0,bottom:0,width:g,left:t==="left"?0:void 0,right:t==="right"?0:void 0,borderRadius:14,background:`linear-gradient(90deg, ${x} 0%, ${x} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${x}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),k&&l.tubeLabels.map(v=>jsxRuntime.jsxs("div",{style:{position:"absolute",top:v.y+o/2-6,left:h,fontSize:9,fontWeight:700,textTransform:"uppercase",color:"rgba(15, 23, 42, 0.75)",background:"rgba(255, 255, 255, 0.6)",padding:"1px 6px 1px 4px",borderRadius:10,display:"flex",alignItems:"center",gap:4},children:[jsxRuntime.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:v.color,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 3px rgba(0,0,0,0.25)"}}),jsxRuntime.jsx("span",{children:v.label})]},`tube-${v.tubeIndex}`)),l.rows.map(v=>{let C=v.y+o/2-f/2,S=t==="left"?u-f/2-y:u+f/2+y;return jsxRuntime.jsxs(Qe__default.default.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"absolute",top:C,left:u-f/2,width:f,height:f,borderRadius:"50%",backgroundColor:v.color,backgroundImage:v.backgroundImage,border:"1px solid rgba(0, 0, 0, 0.4)",boxShadow:"0 0 4px rgba(0,0,0,0.25)"}}),a&&jsxRuntime.jsx("div",{style:{position:"absolute",top:v.y+o/2-6,left:S,transform:t==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:v.fiberIndex})]},v.key)})]})};var Fa=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}}),Da=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}}),_a=e=>{let t=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},o=t(e.termination_a),r=t(e.termination_b);return {id:`cable-${e.id}`,source:`device-${o}`,target:`device-${r}`,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}}},Bc=e=>{let t=[],o=[];return e.racks.forEach(r=>t.push(Fa(r))),e.devices.forEach(r=>t.push(Da(r))),e.cables.forEach(r=>o.push(_a(r))),{nodes:t,edges:o}},Oc=e=>{let t=e.filter(n=>n.type==="rack"),o=e.filter(n=>n.type==="device"),r=e.filter(n=>!["rack","device"].includes(n.type));return t.forEach((n,i)=>{n.position={x:i*300,y:100};}),o.forEach(n=>{if(n.parentId){let i=t.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,a=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-a*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),r.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var Ma=e=>typeof e.id=="number"?`device-${e.id}`:`device-${e.name}`,Wc="Interfaces",zc="Management",Uc="Power",ei=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),St=e=>{if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0},$r=e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim().length>0){let t=Number(e);if(Number.isFinite(t))return t}},It=e=>{if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20")return t},Vc=e=>typeof e=="string"&&e.toLowerCase()==="rear"?"rear":"front",Ar=e=>ei(e.custom_fields)?e.custom_fields:void 0,Lr=e=>ei(e)?e:void 0,$a=(e,t)=>{let o=Ar(e),r=Lr(o?.layout);return Vc(t??e.layout?.face??e.face??r?.face??o?.port_face??o?.portFace??o?.face)},Aa=(e,t,o)=>{let r=Ar(e),n=Lr(r?.layout),i=St(o)??St(e.layout?.group)??St(e.port_group)??St(n?.group)??St(r?.port_group)??St(r?.portGroup)??St(r?.interface_group)??St(r?.interfaceGroup)??St(r?.group);return i||(t==="power_ac"||t==="power_c13"||t==="power_c19"?Uc:t==="console"||t==="mgmt"?zc:Wc)},La=(e,t,o)=>{let r=Ar(e),n=Lr(r?.layout);return It(o)??It(e.layout?.connectorType)??It(e.layout?.connector_type)??It(e.connector_type)??It(n?.connectorType)??It(n?.connector_type)??It(r?.connectorType)??It(r?.connector_type)??It(t)},Ba=(e,t)=>{if(t==="C13")return "power_c13";if(t==="C19")return "power_c19";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")||o.includes("dac")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")||o.includes("oob")?"mgmt":o.includes("usb")?"usb":"ethernet"},Oa=e=>{let t=(e??"").toLowerCase();if(t){if(t.includes("om3"))return "om3";if(t.includes("om4"))return "om4";if(t.includes("om5"))return "om5";if(t.includes("smf")||t.includes("singlemode"))return "smf";if(t.includes("cat5e"))return "cat5e";if(t.includes("cat6a"))return "cat6a";if(t.includes("cat6"))return "cat6";if(t.includes("cat7"))return "cat7";if(t.includes("fiber")||t.includes("sfp")||t.includes("qsfp"))return "fiber";if(t.includes("ethernet")||t.includes("rj45")||t.includes("1000base")||t.includes("10gbase")||t.includes("base-t"))return "ethernet"}},Gc=e=>{if(!ei(e))return;let t=e.side??e.port_side??e.portSide,o=typeof t=="string"&&["top","right","bottom","left"].includes(t.toLowerCase())?t.toLowerCase():void 0,r=$r(e.offsetPercent??e.offset_percent??e.offsetPct??e.offset_pct),n=$r(e.offsetPx??e.offset_px??e.offsetPixels??e.offset_pixels),i=$r(e.xPercent??e.x_percent??e.xPct??e.x_pct??e.horizontalPercent??e.horizontal_percent??e.x),d=$r(e.yPercent??e.y_percent??e.yPct??e.y_pct??e.verticalPercent??e.vertical_percent??e.y);if(!(o===void 0&&r===void 0&&n===void 0&&i===void 0&&d===void 0))return {side:o,offsetPercent:r,offsetPx:n,xPercent:i,yPercent:d}},Wa=(e,t,o)=>{if(!o)return;let r=Ar(e),n=Lr(r?.layout),i=[t?.position,t,e.layout?.position,e.layout,n?.position,n,r?.port_position,r?.portPosition,r?.position,r,e];for(let d of i){let a=Gc(d);if(a)return a}},Xc=(e,t)=>{let o=e.type?.value??e.type?.label??e.layout?.type??void 0,r=La(e,o),n=Ba(o,r),i=Aa(e,n);return {label:e.name,face:$a(e),group:i,type:n,cableType:Oa(o),connected:!!(e.connected_endpoint||e.cable),connectorType:r,position:Wa(e,void 0,t)}},jc=e=>[...e].sort((t,o)=>{let r=typeof t.position=="number"?t.position:Number.MAX_SAFE_INTEGER,n=typeof o.position=="number"?o.position:Number.MAX_SAFE_INTEGER;return r!==n?r-n:t.name.localeCompare(o.name)}),Yc=(e,t)=>{let o=e.find(n=>n.name===t);if(o)return o;let r={name:t,ports:[]};return e.push(r),r},Kc=(e,t)=>{let{includePortPositions:o=false,mapInterfaceToPort:r}=t,n=[],i=[];return jc(e.interfaces??[]).forEach((a,c)=>{let l=r?r({device:e,iface:a,index:c}):Xc(a,o);if(!l)return;let g=l.type??a.type?.value??a.type?.label??void 0,f=La(a,g,l.connectorType),p=Ba(g,f),u=$a(a,l.face),y=Aa(a,p,l.group);Yc(u==="rear"?i:n,y).ports.push({id:l.id,label:l.label??a.name,connected:l.connected??!!(a.connected_endpoint||a.cable),type:p,cableType:Oa(l.cableType??a.type?.value??a.type?.label??void 0),connectorType:f,position:Wa(a,l,o)});}),{front:n,rear:i}},za=e=>({id:`rack-${e.id}`,type:"rack",position:{x:0,y:0},data:{label:e.name,status:e.status.value,uHeight:e.u_height,netboxId:e.id,netboxType:"rack",facilityId:e.facility_id,serial:e.serial,assetTag:e.asset_tag,site:e.site.name,role:e.role?.name,tenant:e.tenant?.name}}),Ua=(e,t={})=>{let o={label:e.name,status:e.status.value,deviceType:e.device_type.model,manufacturer:e.device_type.manufacturer.name,role:e.device_role.name,uHeight:1,uPosition:e.position||1,face:e.face||"front",netboxId:e.id,netboxType:"device",primaryIp4:e.primary_ip4?.address,primaryIp6:e.primary_ip6?.address,site:e.site.name,rack:e.rack?.name};if(t.includeInterfacePorts&&Array.isArray(e.interfaces)&&e.interfaces.length>0){let{front:r,rear:n}=Kc(e,t);r.length>0&&(o.ports=r),n.length>0&&(o.rearPorts=n);}return {id:`device-${e.id}`,type:"device",position:{x:0,y:0},parentId:e.rack?`rack-${e.rack.id}`:void 0,extent:e.rack?"parent":void 0,data:o}},Va=e=>({id:`cable-${e.id}`,source:Ma(e.termination_a.device),target:Ma(e.termination_b.device),type:"fiber",data:{bandwidth:e.type.label,length:e.length||0,color:e.color,netboxId:e.id,netboxType:"cable",status:e.status.value,terminationA:e.termination_a.name,terminationB:e.termination_b.name}}),Zc=(e,t={})=>{let o=[],r=[],n=new Map;return e.racks.forEach(i=>{o.push(za(i));}),e.devices.forEach(i=>{let d=Ua(i,t);o.push(d),n.set(i.name,d.id);}),e.cables.forEach(i=>{let d=Va(i),a=(typeof i.termination_a.device.id=="number"?`device-${i.termination_a.device.id}`:void 0)??n.get(i.termination_a.device.name)??d.source,c=(typeof i.termination_b.device.id=="number"?`device-${i.termination_b.device.id}`:void 0)??n.get(i.termination_b.device.name)??d.target;r.push({...d,source:a,target:c});}),{nodes:o,edges:r}},qc=(e,t)=>{let o=new Map,r=new Set;return e.filter(i=>i.position!==null).sort((i,d)=>(i.position||0)-(d.position||0)).forEach(i=>{i.position&&(o.set(i.id,i.position),r.add(i.position));}),o};function Br(e){let{items:t,checkOutOfBounds:o,checkConflicts:r}=e,n=[],i=[];for(let d of t){let a=o(d);a&&!a.isValid&&a.error&&i.push(a.error);}for(let d=0;d<t.length;d++){let a=t[d];for(let c=d+1;c<t.length;c++){let l=t[c],g=r(a,l);g&&g.hasConflict&&g.conflict&&n.push(g.conflict);}}return {isValid:n.length===0&&i.length===0,conflicts:n,outOfBounds:i}}var Co=class extends Error{constructor(o,r,n,i,d){super(`Device placement conflict: ${r} at U${n}-${n+i-1} in rack ${o}${d?` conflicts with ${d}`:""}`);this.rackId=o;this.deviceId=r;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function ti(e,t={}){let o=He(e);return Br({items:e.devices,checkOutOfBounds:r=>r.unit+r.height-1>e.units?{isValid:false,error:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,rackUHeight:e.units}}:null,checkConflicts:(r,n)=>{let i=r.unit,d=r.unit+r.height-1,a=n.unit,c=n.unit+n.height-1;if(i<=c&&d>=a){if(o){let l=Oe(r),g=Oe(n);if(!tr(l,g))return null}return {hasConflict:true,conflict:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,conflictWith:n.id}}}return null}})}function Ga(e,t,o={}){let{deviceTypeMapping:r={}}=o,n=r[e.type]||"device",i=go(t,e.unit,e.height,e);return {id:e.id,type:n,position:i,parentId:t.id,extent:"parent",data:{label:e.name,status:e.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:t.data.rackWidthPx,rackLayout:t.data.rackLayout,rackFaceGapPx:t.data.rackFaceGapPx,mountMode:Oe(e)}}}function Jc(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,rackLayout:e.rackLayout,rackFaceGapPx:e.rackFaceGapPx}}}function Qc(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let d of e){let a=ti(d,t);if(!a.isValid&&o==="strict"){let c=[];throw a.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),a.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new Co(d.id,a.conflicts[0]?.deviceId||a.outOfBounds[0]?.deviceId||"unknown",a.conflicts[0]?.uPosition||a.outOfBounds[0]?.uPosition||1,a.conflicts[0]?.uHeight||a.outOfBounds[0]?.uHeight||1)}}for(let d of e){let a=Jc(d);n.push(a);for(let c of d.devices)try{let l=Ga(c,a,t);i.push(l);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=ar(a,{id:c.id,data:{label:c.name,uHeight:c.height,mountMode:Oe(c)}},i,c.unit);if(g!==void 0&&g!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${g} due to conflict`);let f={...c,unit:g},p=Ga(f,a,t);i.push(p);}else throw new Co(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function el(e){let t=[],o=e.filter(r=>r.type==="rack");for(let r of o){let i=e.filter(d=>Fo(d.type)&&d.parentId===r.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width==="full"||d.data.width==="half"?d.data.width:void 0,ports:Array.isArray(d.data.ports)?d.data.ports:void 0,connections:d.data.connections,frontImageUrl:d.data.frontImageUrl,rearImageUrl:d.data.rearImageUrl,frontImageAttribution:d.data.frontImageAttribution,rearImageAttribution:d.data.rearImageAttribution,imageFit:d.data.imageFit,imagePosition:d.data.imagePosition,imageRepeat:d.data.imageRepeat,stretchToFit:d.data.stretchToFit,mountMode:Oe(d.data)}));t.push({id:r.id,name:r.data.label,position:r.position,units:r.data.uHeight||42,uNumberingDirection:r.data.uNumberingDirection||"bottom-up",customHeaderText:r.data.customHeaderText,rackLayout:r.data.rackLayout,rackFaceGapPx:r.data.rackFaceGapPx,devices:i,rackWidthPx:r.data.rackWidthPx});}return t}function tl(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,devices:n.devices.map(i=>i.id!==o?i:{...i,unit:r})})}function ol(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!ti({...i,devices:[...i.devices,o]},r).isValid)throw new Co(t,o.id,o.unit,o.height);return {...i,devices:[...i.devices,o]}})}function rl(e,t,o){return e.map(r=>r.id!==t?r:{...r,devices:r.devices.filter(n=>n.id!==o)})}var vo=class extends Error{constructor(o,r,n,i){super(`Splice placement conflict: ${r} at holder ${n} in tray ${o}${i?` conflicts with ${i}`:""}`);this.trayId=o;this.spliceId=r;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function oi(e,t={}){return Br({items:e.splices,checkOutOfBounds:o=>o.holder<1||o.holder>Ot?{isValid:false,error:{spliceId:o.id,holder:o.holder,max:Ot}}:null,checkConflicts:(o,r)=>o.holder===r.holder?{hasConflict:true,conflict:{spliceId:o.id,holder:o.holder,conflictWith:r.id}}:null})}function Xa(e,t){let o=e.mode==="ribbon",r=Vo(t,e.holder,o);return {id:e.id,type:"splice",position:r,parentId:t.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb,mode:e.mode||"single",ribbonFiberIds:e.ribbonFiberIds}}}function nl(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function il(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let d of e){let a=oi(d,t);if(!a.isValid&&o==="strict"){let c=[];throw a.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),a.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new vo(d.id,a.conflicts[0]?.spliceId||a.outOfBounds[0]?.spliceId||"unknown",a.conflicts[0]?.holder||a.outOfBounds[0]?.holder||1)}}for(let d of e){let a=nl(d);n.push(a);for(let c of d.splices)try{let l=c.holder;if(o==="nearest"){let p={id:c.id,type:"splice",position:{x:0,y:0},data:{label:c.name,holderPosition:c.holder}},u=[...n,...i];Wo(a,p,c.holder,u)||(l=Uo(a,p,u,c.holder));}let g=l!==c.holder?{...c,holder:l}:c,f=Xa(g,a);i.push(f);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=[...n,...i],f=Uo(a,{id:c.id,data:{label:c.name,holderPosition:c.holder}},g,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let p={...c,holder:f},u=Xa(p,a);i.push(u);}else throw new vo(d.id,c.id,c.holder)}}}return n.push(...i),n}function al(e){let t=[],o=e.filter(r=>r.type==="splice-tray");for(let r of o){let i=e.filter(d=>d.type==="splice"&&d.parentId===r.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb,mode:d.data.mode||"single",ribbonFiberIds:d.data.ribbonFiberIds}));t.push({id:r.id,name:r.data.label,position:r.position,splices:i});}return t}function sl(e,t,o,r){return e.map(n=>n.id!==t?n:{...n,splices:n.splices.map(i=>i.id!==o?i:{...i,holder:r})})}function dl(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!oi({...i,splices:[...i.splices,o]},r).isValid)throw new vo(t,o.id,o.holder);return {...i,splices:[...i.splices,o]}})}function cl(e,t,o){return e.map(r=>r.id!==t?r:{...r,splices:r.splices.filter(n=>n.id!==o)})}var ja=2;var fe=e=>typeof e=="string"?e.trim():"",ht=e=>{if(typeof e=="number"&&Number.isFinite(e))return e},ll=e=>{let t=fe(e).toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20"||t==="AC")return t},ul=(e,t)=>{if(t==="C13"||t==="C14")return "power_c13";if(t==="C19"||t==="C20")return "power_c19";if(t==="AC")return "power_ac";let o=(e??"").toLowerCase();return o.includes("c13")?"power_c13":o.includes("c19")?"power_c19":o.includes("power")||o.includes("pdu")?"power_ac":o.includes("fiber")||o.includes("sfp")||o.includes("qsfp")?"fiber":o.includes("console")?"console":o.includes("mgmt")||o.includes("management")?"mgmt":o.includes("usb")?"usb":"ethernet"},pl=e=>{if(e==="power_c13")return "C13";if(e==="power_c19")return "C19";if(e==="power_ac")return "AC"},fl=e=>e.toLowerCase().replace(/_/g,"-").trim(),gl=e=>e>=1?"rackable":"zero-u",bl=e=>(e??"").toLowerCase()==="half"?"half":"full",ml=(e,t,o,r)=>{let n=r.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase();return `${e}-b${t}-${n||`p${o}`}`},Ya=(e,t)=>`${e}-${t}`.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function hl(e){let t=[],o=fe(e.manufacturer),r=fe(e.model),n=fe(e.role)||fe(e.deviceType)||fe(e.device_type)||"device",i=ht(e.uHeight)??ht(e.u_height)??0;o||t.push({severity:"warning",code:"MISSING_MANUFACTURER",message:"Template is missing manufacturer",path:"manufacturer"}),r||t.push({severity:"warning",code:"MISSING_MODEL",message:"Template is missing model",path:"model"});let d=fe(e.id)||fe(e.slug)||Ya(o,r)||"unknown",a=fe(e.slug)||Ya(o,r)||d,c=Array.isArray(e.ports)?e.ports:[],l=Array.isArray(e.rearPorts)?e.rearPorts:Array.isArray(e.rear_ports)?e.rear_ports:[],f=(Array.isArray(e.frontRearPortLinks)?e.frontRearPortLinks:Array.isArray(e.front_rear_port_links)?e.front_rear_port_links:[]).map(p=>({frontPortId:fe(p.frontPortId)||fe(p.front_port_id),rearPortId:fe(p.rearPortId)||fe(p.rear_port_id)}));return {id:d,slug:a,manufacturer:o,model:r,role:n,uHeight:i,width:fe(e.width)||void 0,frontBlocks:c,rearBlocks:l,rawLinks:f,frontImageUrl:fe(e.frontImageUrl)||fe(e.front_image_url)||void 0,rearImageUrl:fe(e.rearImageUrl)||fe(e.rear_image_url)||void 0,frontImageAttribution:fe(e.frontImageAttribution)||void 0,rearImageAttribution:fe(e.rearImageAttribution)||void 0,tags:Array.isArray(e.tags)?e.tags.map(fe).filter(Boolean):[],sourceRepository:fe(e.sourceRepository)||fe(e.source_repository)||void 0,sourcePath:fe(e.sourcePath)||fe(e.source_path)||void 0,issues:t}}function Ka(e,t,o){let r=fe(e.name)||`Block ${o+1}`,i=(Array.isArray(e.ports)?e.ports:[]).map((d,a)=>{let c=fe(d.label)||fe(d.name)||`Port ${a+1}`,l=ll(d.connectorType??d.connector_type),g=ul(fe(d.type),l),f=l??pl(g),u={id:fe(d.id)||ml(t,o,a,c),label:c,type:g,connectorType:f};if(d.position){let y=d.position,h=fe(y.side),x={},k=false;h&&["top","right","bottom","left"].includes(h)&&(x.side=h,k=true);let v=ht(y.offsetPercent)??ht(y.offset_percent);v!==void 0&&(x.offsetPercent=v,k=true);let C=ht(y.offsetPx)??ht(y.offset_px);C!==void 0&&(x.offsetPx=C,k=true);let S=ht(y.xPercent)??ht(y.x_percent);S!==void 0&&(x.xPercent=S,k=true);let N=ht(y.yPercent)??ht(y.y_percent);N!==void 0&&(x.yPercent=N,k=true),k&&(u.position=x);}return u});return {name:r,ports:i}}function yl(e){let t=[],o=fl(e.role),r=e.uHeight,n=gl(r),i=bl(e.width),d=e.frontBlocks.map((c,l)=>Ka(c,"front",l)),a=e.rearBlocks.map((c,l)=>Ka(c,"rear",l));return {role:o,mountClass:n,uHeight:r,width:i,frontFace:{portBlocks:d,imageUrl:e.frontImageUrl,imageAttribution:e.frontImageAttribution},rearFace:{portBlocks:a,imageUrl:e.rearImageUrl,imageAttribution:e.rearImageAttribution},issues:t}}function wl(e,t){let o=new Set(e.portBlocks.map(i=>i.name)),r=new Set(t.portBlocks.map(i=>i.name)),n=[...o].filter(i=>r.has(i));return n.length===0?{front:e,rear:t}:{front:{...e,portBlocks:e.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Front \xB7 ${i.name}`}:i)},rear:{...t,portBlocks:t.portBlocks.map(i=>n.includes(i.name)?{...i,name:`Rear \xB7 ${i.name}`}:i)}}}function xl(e){let t=[],{front:o,rear:r}=wl(e.frontFace,e.rearFace),n=e.role;return (!n||n==="device")&&[...o.portBlocks,...r.portBlocks].some(d=>d.ports.some(a=>a.type&&a.type.startsWith("power")))&&e.mountClass==="zero-u"&&(n="pdu"),{frontFace:o,rearFace:r,mountClass:e.mountClass,role:n,issues:t}}function Yo(e){return e.portBlocks.reduce((t,o)=>t+o.ports.length,0)}function Nl(e,t){let o=[],r=[];for(let u of t.frontFace.portBlocks)for(let y of u.ports)r.push({id:y.id,face:"front"});for(let u of t.rearFace.portBlocks)for(let y of u.ports)r.push({id:y.id,face:"rear"});let n=new Map;for(let{id:u}of r)n.set(u,(n.get(u)??0)+1);for(let[u,y]of n)y>1&&o.push({severity:"error",code:"DUPLICATE_PORT_ID",message:`Duplicate port id "${u}" found ${y} times`,path:`ports.${u}`});let i=e.frontBlocks.reduce((u,y)=>u+(Array.isArray(y.ports)?y.ports.length:0),0),d=e.rearBlocks.reduce((u,y)=>u+(Array.isArray(y.ports)?y.ports.length:0),0),a=Yo(t.frontFace),c=Yo(t.rearFace);a!==i&&o.push({severity:"error",code:"FRONT_PORT_COUNT_MISMATCH",message:`Front port count mismatch: raw=${i}, parsed=${a}`,path:"faces.front"}),c!==d&&o.push({severity:"error",code:"REAR_PORT_COUNT_MISMATCH",message:`Rear port count mismatch: raw=${d}, parsed=${c}`,path:"faces.rear"});let l=new Set(r.map(u=>u.id)),g=new Set(r.filter(u=>u.face==="front").map(u=>u.id)),f=new Set(r.filter(u=>u.face==="rear").map(u=>u.id));for(let u of e.rawLinks)u.frontPortId&&!g.has(u.frontPortId)&&!l.has(u.frontPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_FRONT_PORT_MISSING",message:`Pass-through link references unknown front port "${u.frontPortId}"`,path:"frontRearPortLinks"}),u.rearPortId&&!f.has(u.rearPortId)&&!l.has(u.rearPortId)&&o.push({severity:"warning",code:"PASS_THROUGH_REAR_PORT_MISSING",message:`Pass-through link references unknown rear port "${u.rearPortId}"`,path:"frontRearPortLinks"});return {valid:!o.some(u=>u.severity==="error"),issues:o,portCounts:{front:a,rear:c}}}function kl(e,t,o){let r=e.rawLinks.filter(i=>!!i.frontPortId&&!!i.rearPortId).map(i=>({frontPortId:i.frontPortId,rearPortId:i.rearPortId})),n=e.sourceRepository?{kind:"netbox",repository:e.sourceRepository,path:e.sourcePath}:void 0;return {templateSchemaVersion:2,id:e.id,slug:e.slug,manufacturer:e.manufacturer,model:e.model,role:o.role,mountClass:o.mountClass,uHeight:t.uHeight,width:t.width,faces:{front:o.frontFace,rear:o.rearFace},frontRearPortLinks:r,images:{front:o.frontFace.imageUrl??null,rear:o.rearFace.imageUrl??null},source:n,tags:e.tags.length>0?e.tags:void 0}}function Pl(e){let t=hl(e),o=yl(t),r=xl(o),n=Nl(t,r);return n.issues.push(...t.issues,...o.issues,...r.issues),n.valid?{template:kl(t,o,r),report:n}:{template:null,report:n}}function Cl(e){return Yo(e)}function vl(e,t,o){let r=[],n=Yo(e.faces.front),i=Yo(e.faces.rear);return t!==n&&r.push({severity:"error",code:"RENDER_FRONT_COUNT_MISMATCH",message:`Rendered front handle count (${t}) does not match template (${n})`,path:"faces.front"}),o!==i&&r.push({severity:"error",code:"RENDER_REAR_COUNT_MISMATCH",message:`Rendered rear handle count (${o}) does not match template (${i})`,path:"faces.rear"}),r}
2
+ exports.COUPLERS_PER_PANEL=Md;exports.COUPLER_SLOT_HEIGHT_PX=Rr;exports.COUPLER_WIDTH_PX=$d;exports.CableNode=In;exports.ClosureNode=zn;exports.CouplerNode=Fn;exports.DeviceNode=mo;exports.DevicePlacementError=Co;exports.DiagramErrorBoundary=qn;exports.FIBER_COLORS_12=wi;exports.FiberEdge=cr;exports.FiberNode=tn;exports.FibreCableWithTubesExpanded=Lc;exports.FibreFlowMap=Mc;exports.FibreSplitNode=Vn;exports.HANDLE_EXTENSION_PX=Ho;exports.MultiTubeCableNode=Hn;exports.NetworkDiagram=Zn;exports.PANEL_BORDER_WIDTH=Ki;exports.PANEL_HEADER_HEIGHT=no;exports.PANEL_HEIGHT_PX=vr;exports.PANEL_PADDING=ro;exports.PANEL_TUBE_TRAY_SPACING=Zi;exports.PANEL_WIDTH_PX=Cr;exports.POWER_CONNECTORS=an;exports.PatchPanelNode=Bn;exports.PowerEdge=rn;exports.RACK_HEADER_HEIGHT=xt;exports.RACK_WIDTH_PX=Qr;exports.RackNode=en;exports.SpliceNode=xn;exports.SplicePlacementError=vo;exports.SpliceTrayNode=vn;exports.TEMPLATE_SCHEMA_VERSION=ja;exports.TubeNode=Rn;exports.U_HEIGHT_PX=Je;exports.VerticalPDU=hn;exports.Width=Ei;exports.addDeviceToRack=ol;exports.addSpliceToTray=dl;exports.baseColorFor=Ve;exports.buildNodesFromRackConfig=Qc;exports.buildNodesFromSpliceConfig=il;exports.calculateClosureDimensions=$n;exports.calculateCouplerRightX=Ld;exports.calculateCouplerSlotSpacing=Od;exports.calculateCouplerSpacing=na;exports.calculateDevicePositionFromU=go;exports.calculatePanelDimensions=Mn;exports.calculateSlotPositionFromY=oa;exports.calculateSplicePositionFromNumber=Td;exports.calculateUPositions=qc;exports.calculateYFromSlotPosition=ra;exports.countTemplateFacePorts=Cl;exports.createNetworkDiagramStore=Gn;exports.createRackConfigFromNodes=el;exports.createSpliceConfigFromNodes=al;exports.fiberSolidOrStriped=on;exports.findNearestRack=Dr;exports.findNextAvailableHolderPosition=Uo;exports.findNextAvailableUPosition=ar;exports.generateLayout=Oc;exports.getConnectorConfig=Hi;exports.getCouplerDimensions=_n;exports.getDeviceConnectorType=sn;exports.getFiberColor=qt;exports.getInnerContentWidth=ta;exports.getPDUPortType=ur;exports.getPanelHeight=Ad;exports.getPanelWidth=ea;exports.getPowerPortStyle=Bt;exports.getRackBounds=la;exports.getStatusColor=gt;exports.getTrayDimensions=qi;exports.getTubeDimensions=Tr;exports.inventoryCableToNetworkEdge=_a;exports.inventoryDeviceToNetworkNode=Da;exports.inventoryRackToNetworkNode=Fa;exports.inventoryToNetworkDiagram=Bc;exports.isHighPowerConnector=Ls;exports.isPointInRack=ua;exports.isStriped=Zt;exports.isUPositionAvailable=jt;exports.netboxCableToNetworkEdge=Va;exports.netboxDeviceToNetworkNode=Ua;exports.netboxRackToNetworkNode=za;exports.netboxToNetworkDiagram=Zc;exports.parseNetboxTemplate=Pl;exports.removeDeviceFromRack=rl;exports.removeSpliceFromTray=cl;exports.replaceEdge=Le;exports.snapToCouplerPosition=Bd;exports.snapToSplicePosition=kn;exports.snapToUPosition=ir;exports.updateDeviceUPosition=yi;exports.updateDeviceUPositionInSchema=tl;exports.updateSpliceHolderPosition=sl;exports.useDiagramEdges=Yn;exports.useDiagramNodes=jn;exports.useNetworkDiagram=Kd;exports.validateAndSnapDevice=ws;exports.validateRackDevicePlacements=ti;exports.validateRenderFidelity=vl;exports.validateSplicePlacements=oi;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map