@mp70/react-networks 0.3.0-alpha.3 → 0.3.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import Qe,{useState,useMemo,useRef,useEffect,useSyncExternalStore,Component,useCallback}from'react';import {useReactFlow,Handle,Position,getBezierPath,BaseEdge,EdgeLabelRenderer,useUpdateNodeInternals,useEdges,addEdge,ReactFlowProvider,useNodesState,useEdgesState,applyNodeChanges,useOnSelectionChange,ReactFlow,Background,Controls,MiniMap,Panel,applyEdgeChanges,ConnectionMode,getSmoothStepPath,SmoothStepEdge}from'reactflow';import {toPng}from'html-to-image';import {jsxs,jsx,Fragment}from'react/jsx-runtime';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}=useReactFlow(),v=x(),[C,S]=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(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 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:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxs("span",{children:[typeof a=="number"?a:0," ports"]})," \u2022 ",l,"U \u2022 ",p?"rear|front":g]}),jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[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"}),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&&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"})]})]}),jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"},children:p&&jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[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"}),jsx("div",{style:{width:`${h}px`}}),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&&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 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:[jsx(Handle,{type:"target",position:Position.Top}),jsx(Handle,{type:"source",position:Position.Bottom}),jsx(Handle,{type:"target",position:Position.Left}),jsx(Handle,{type:"source",position:Position.Right}),jsx("div",{style:{textAlign:"center"},children:jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),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 jsxs(Fragment,{children:[f&&jsx(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 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)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&a&&(a.bandwidth||a.length)&&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&&jsx("div",{children:a.bandwidth}),a.length&&jsxs("div",{children:[a.length,"m"]}),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]=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 jsxs(Fragment,{children:[D&&jsx(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`}}),jsx(BaseEdge,{id:e,path:f,style:U}),k&&jsx(BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsx(EdgeLabelRenderer,{children:c&&a&&(y||h)&&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&&jsx("div",{children:y}),h&&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]=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 jsx(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]=getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d});return jsxs(Fragment,{children:[y&&jsx(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 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)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:c&&g&&(g.bandwidth||g.length)&&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&&jsx("div",{children:g.bandwidth}),g.length&&jsxs("div",{children:[g.length,"m"]}),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 jsxs(Fragment,{children:[k&&jsx(BaseEdge,{id:`${e}-highlight`,path: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`}}),jsx(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===Position.Left||n===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 jsxs(Fragment,{children:[l&&jsx(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 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)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&i&&(i.bandwidth||i.length)&&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&&jsx("div",{children:i.bandwidth}),i.length&&jsxs("div",{children:[i.length,"m"]}),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 jsxs(Fragment,{children:[v&&jsx(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`}}),jsx(BaseEdge,{id:e,path:C,style:D}),p&&jsx(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]=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 jsxs(Fragment,{children:[x&&jsx(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`}}),jsx(BaseEdge,{id:e,path:C,markerEnd:l,style:R}),p&&jsx(EdgeLabelRenderer,{children: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.useLayoutEffect:Qe.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 Position.Top;case "right":return Position.Right;case "bottom":return Position.Bottom;case "left":return Position.Left;default:return 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: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: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: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: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:Position.Top,style:{transform:"translateY(50%)",left:`${l-o/2}px`}}:{position: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: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: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: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: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: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=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.useMemo(()=>Array.isArray(g)?g:[],[g]),N=Qe.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.useMemo(()=>E?$t(A):[_],[E,A,_]),se=U[0]??_,Y=E&&A==="both",ee=c*20,ie=At(t),z=D+ie,V=Qe.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.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.useMemo(()=>B("front"),[B]),X=Qe.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.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.useCallback((j,we)=>we==="rear"&&Y&&q.has(j)?`${j}--rear`:j,[q,Y]),Ce=Qe.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===Position.Left?(_e.left=`${ke}px`,_e.right=void 0):Ht.position===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(jsx(Handle,{id:`${Ft}-${ut.secondary}`,type:ut.secondary,position:Ht.position,style:yt,title:co},`${Ft}-${ut.secondary}`));}le.push(jsx(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.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 jsxs("div",{className:`device-node ${o?"selected":""} ${Y?"device-node--split-both":""}`,style:ce,children:[Y&&jsxs("div",{className:"device-node__split-face-layer",style:{position:"absolute",inset:0,display:"flex",pointerEvents:"none",zIndex:0},children:[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")}}),jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${ie}px`},children:jsx("div",{className:"device-node__face-bridge-line"})}),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")}})]}),jsxs("div",{className:"device-node__content",style:{position:"relative",zIndex:1},children:[jsx("div",{className:"device-node__label",children:n}),c>1&&jsx("div",{className:"device-node__manufacturer",children:a})]}),c>1&&jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),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:Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let d=e.side,a=d==="left"?Position.Left:d==="top"?Position.Top:d==="bottom"?Position.Bottom: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"?Position.Left:y==="top"?Position.Top:y==="bottom"?Position.Bottom: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 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:[jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsx(Handle,{type:"source",position:Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit")}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 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:[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:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),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 jsx(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=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 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?jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:x.map((N,R)=>jsx("div",{style:{flex:1,background:N.base,opacity:N.striped?.9:1}},`left-${R}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:k.map((N,R)=>jsx("div",{style:{flex:1,background:N.base,opacity:N.striped?.9:1}},`right-${R}`))})]}):jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsx("div",{style:{background:f}}),jsx("div",{style:{background:p}})]}),jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),v&&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"&&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:[jsx("div",{children:`${r.toFixed(2)} dB`}),u&&i&&jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsx(Handle,{type:"target",position: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%)"}}),jsx(Handle,{type:"source",position: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%)"}}),jsx(Handle,{type:"target",position: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]=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(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 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:[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:[jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),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(),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=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"?Position.Left:i==="right"?Position.Right:Position.Bottom,R=N!==Position.Bottom,D=R?14:20,E=R?8:20,A=R?`inset ${N===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",_=l?p:R?`linear-gradient(${N===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===Position.Left?{left:-(D-4)}:N===Position.Right?{right:-(D-4)}:{}},se=useMemo(()=>{let Y=[],ee=S-k*2-x*2,ie,z,V=false;i==="left"?(ie=x,z=Position.Top):i==="right"?(ie=x+ee-C,z=Position.Top,V=true):(ie=x+(ee-C)/2,z=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(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:xe,"data-fiber-idx":O,"data-fiber-color":ae.base}),jsx(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 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,jsx(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"}),jsx(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.useRef(null);Qe.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?Position.Top:V>=45&&V<135?Position.Right:V>=135&&V<225?Position.Bottom: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(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:ce,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:ae,"data-fiber-idx":O,"data-fiber-color":te}),jsx(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?Position.Bottom:V>=45&&V<135?Position.Left:V>=135&&V<225?Position.Top: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 jsx("div",{ref:a,style:ee,children:jsxs("div",{style:ie,children:[D(),jsx(Handle,{id:E,type:"source",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsx(Handle,{id:E,type:"target",position:Y,className:"cable-button-handle",isConnectable:true,style:_,"data-handle-type":"cable-button","data-cable-color":C}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:x}),k&&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(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:M,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:te,"data-fiber-idx":ie,"data-tube-idx":ie,"data-tube-color":V}),jsx(Handle,{id:M,type:"source",position: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 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(),jsx(Handle,{id:A,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsx(Handle,{id:A,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":R}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:C}),S&&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=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"?Position.Left: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(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:se,type:"target",position:E,isConnectable:true,style:V}),jsx(Handle,{id:se,type:"source",position:E,isConnectable:true,style:V})]},se)),A&&A[_]&&D.push(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 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"),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children: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}=useReactFlow(),l=useRef(false),g=useRef([]),f=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=useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[o,e,i,d]),u=useMemo(()=>i&&d?{width:i,height:d}:f.length===0?{width:i||400,height:d||300}:Mn(p,f),[f,p,i,d]);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 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:[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:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:k})}),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}=useReactFlow(),f=useRef(false),p=useRef([]),u=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=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=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]);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 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:[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:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:C})}),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=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(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Left,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position: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(jsxs(Qe.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Right,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position: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 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:[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:jsx("polygon",{points:`0,${A} 0,${_} ${S},${se} ${S},${U}`,fill:"#1f2937",stroke:Y,strokeWidth:"2"})}),R(),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children: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 useSyncExternalStore(t,o,o)}function jn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return useSyncExternalStore(t,o,o)}function Yn(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return 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=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.useRef(null),r=Qe.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.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]),jsx("div",{ref:r,style:{width:"100%",height:"100%"},children:t})},ya=(e,t,o)=>({rack:r=>jsx(Ge,{type:"rack",children:jsx(en,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsx(Ge,{type:"fiber",children:jsx(tn,{...r})}),device:r=>jsx(Ge,{type:"device",children:jsx(mo,{...r})}),server:r=>jsx(Ge,{type:"server",children:jsx(mo,{...r})}),switch:r=>jsx(Ge,{type:"switch",children:jsx(mo,{...r})}),router:r=>jsx(Ge,{type:"router",children:jsx(mo,{...r})}),"vertical-pdu":r=>jsx(Ge,{type:"vertical-pdu",children:jsx(hn,{...r})}),splice:r=>jsx(Ge,{type:"splice",children:jsx(xn,{...r})}),"splice-tray":r=>jsx(Ge,{type:"splice-tray",children:jsx(vn,{...r})}),tube:r=>jsx(Ge,{type:"tube",children:jsx(Rn,{...r})}),cable:r=>jsx(Ge,{type:"cable",children:jsx(In,{...r})}),"multi-tube-cable":r=>jsx(Ge,{type:"multi-tube-cable",children:jsx(Hn,{...r})}),coupler:r=>jsx(Ge,{type:"coupler",children:jsx(Fn,{...r})}),"patch-panel":r=>jsx(Ge,{type:"patch-panel",children:jsx(Bn,{...r})}),closure:r=>jsx(Ge,{type:"closure",children:jsx(zn,{...r})}),"fibre-split":r=>jsx(Ge,{type:"fibre-split",children: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=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.useMemo(()=>L?e||[]:o||e||[],[L,e,o]),ae=Qe.useMemo(()=>L?t||[]:r||t||[],[L,t,r]),ce=Qe.useMemo(()=>M(ae,de),[ae,de,M]),q=Qe.useMemo(()=>d||Gn({nodes:de,edges:ce,debug:a}),[d,L,a,ce]),xe=jn(q),Ce=Yn(q),[Ne,j]=useNodesState(xe),[we,ke,st]=useEdgesState(Ce),le=ca(q),Xe=useRef(null),[Fe,Or]=useState(false);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=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=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}=useReactFlow();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?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]=useState(false),Wr=useCallback(()=>{if(!lt){if(!Xe.current){a&&console.error("ReactFlow wrapper ref is not available");return}Zo(true),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]=useState(null),Gt=useRef(null),Ht=useRef(x),zr=useRef(k);useEffect(()=>{Ht.current=x;},[x]),useEffect(()=>{zr.current=k;},[k]),useEffect(()=>{Gt.current=qo;},[qo]);let _e=useCallback((s,b)=>{Ht.current?.(s,b);},[]),Ft=useCallback((s,b)=>{zr.current?.(s,b);},[]),ut=useCallback(()=>Gt.current,[]),yt=useRef({...ya(_e,Ft,ut),...g??{}});useEffect(()=>{yt.current={...ya(_e,Ft,ut),...g??{}};},[_e,Ft,ut,g]);let co=useMemo(()=>({...lc,...f??{}}),[f]),pt=useRef(Ne);useEffect(()=>{pt.current=Ne;},[Ne]);let J=useRef(we);useEffect(()=>{J.current=we;},[we]),useEffect(()=>{j(xe);},[xe,j]),useEffect(()=>{ke(Ce);},[Ce,ke]),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]),useEffect(()=>{L&&q.setState({nodes:e||[]});},[L,e,q]),useEffect(()=>{L&&q.setState({edges:t||[]});},[L,t,q]),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=useRef(new Map);useEffect(()=>{let s=new Map;Ne.forEach(b=>{s.set(b.id,b);}),Ro.current=s;},[Ne]);let ue=useCallback(s=>Ro.current.get(s),[]),je=useCallback(s=>{if(!s)return;if(typeof s.parentId=="string")return s.parentId;let b=s.parentNode;if(typeof b=="string")return b},[]),ri=useCallback(s=>{let b=je(s);if(!b)return;let w=ue(b);if(!(!w||w.type!=="rack"))return w},[ue,je]),ni=useCallback(s=>!s||s.type!=="rack"?false:He(s.data),[]),lo=useCallback(s=>{if(!s||!Ke(s))return false;let b=ri(s);return b?He(b.data):false},[ri]),Ur=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=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=useCallback(s=>{J.current=s,ke(s),L?i?.(s):q.setState({edges:s});},[L,q,ke,i]),Dt=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=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=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=useRef(new Map);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]),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=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=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=useCallback((s,b)=>{Vt(null);},[]),Ja=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=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=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=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=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=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=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=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=useCallback(()=>{},[]),is=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=useCallback(()=>{Vr(null),So([]),j(s=>s.map(b=>b.selected?{...b,selected:false}:b)),c?.(null);},[c,j]),[rt,Vr]=useState(null),[ai,si]=useState(new Set);useOnSelectionChange({onChange:({edges:s})=>{So(s||[]);}});let[Gr,So]=useState([]);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=useCallback((s,{nodeId:b,handleType:w})=>{a&&console.log("Connection started from",{nodeId:b,handleType:w});},[a]),ds=useCallback(s=>{a&&console.log("Connection ended",s);},[a]),cs=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=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=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=useMemo(()=>rt?ue(rt.id)??rt:null,[rt,ue]),uo=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=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 jsxs("div",{ref:Xe,className:ps,style:fs,children:[jsxs(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=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:[jsx(Background,{color:gi(R)}),De.showControls&&jsx(Controls,{showInteractive:De.showInteractiveControl}),De.showMiniMap&&jsx(MiniMap,{}),jsx(Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),A&&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&&jsxs("div",{style:{position:"absolute",top:Xr.top,left:Xr.left,display:"flex",gap:8,zIndex:2e3},children:[uo.showRearToggle&&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&&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=>jsx(ReactFlowProvider,{children:jsx(mc,{...e})});var qn=class extends 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??jsxs("div",{role:"alert",style:{padding:16,margin:8,border:"1px solid #e53e3e",borderRadius:4,backgroundColor:"#fff5f5",color:"#c53030"},children:[jsx("strong",{children:"Diagram error"}),": ",o.message,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]=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 jsxs(Fragment,{children:[jsx("defs",{children:D&&jsxs("linearGradient",{id:ie,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0%",stopColor:u}),jsx("stop",{offset:`${ee}%`,stopColor:u}),jsx("stop",{offset:`${ee}%`,stopColor:y}),jsx("stop",{offset:"100%",stopColor:y})]})}),D?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"}}):jsx(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)&&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&&jsx(EdgeLabelRenderer,{children: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&&jsx("div",{style:{lineHeight:1.2},children:p}),ce&&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]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:d,curvature:.2}),f=a?.label,p=a?.color??"#64748b";return jsxs(Fragment,{children:[jsx(BaseEdge,{id:e,path:c,style:{stroke:p,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),f&&jsx(EdgeLabelRenderer,{children: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"?Position.Right: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 jsxs("div",{style:{position:"relative",width:n,height:a.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[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}),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 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&&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 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 jsxs(Qe.Fragment,{children:[jsx(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}),jsx(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&&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)}),jsx(Handle,{id:"cable-run",type:"source",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:S,isConnectable:true,"data-handle-type":"cable-run"}),jsx(Handle,{id:"cable-run",type:"target",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:S,isConnectable:true,"data-handle-type":"cable-run"})]})},Hc=({data:e})=>{let t=e.colorMode==="light";return 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: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=useMemo(()=>Fc(e,r,n,i,d,a,c,l,g,f),[e,r,n,i,d,a,c,l,g,f]),S=useMemo(()=>Dc(e,t,o,p),[e,t,o,p]),[N,R]=useState(C),[D,E]=useState(S);useEffect(()=>{R(C);},[C,R]),useEffect(()=>{E(S);},[S,E]);let A=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]),_=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=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 addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:ce},xe)});},[A,h,E]),se=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 addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:L},Ne)});},[A,h,E]),Y=useCallback(B=>{h||R(B.filter(Nc));},[h,R]),ee=useCallback(B=>{h||E(O=>vc(B,O));},[h,E]),ie=useMemo(()=>({"fibre-flow-cable":Ec,"fibre-flow-closure":Hc}),[]),z=useMemo(()=>({"fibre-flow":Sc,"fibre-flow-link":Ic}),[]),V={borderRadius:8,overflow:"hidden",...y};return jsx(Zn,{nodes:N,edges:D,onNodesChange:Y,onEdgesChange:ee,onConnect:U,onEdgeUpdate:se,isValidConnection:_,connectionMode: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=>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=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 jsxs("div",{style:{position:"relative",width:n,height:l.height,fontFamily:"monospace",color:"inherit"},children:[c&&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}),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=>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:[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)"}}),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 jsxs(Qe.Fragment,{children:[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&&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
- export{Md as COUPLERS_PER_PANEL,Rr as COUPLER_SLOT_HEIGHT_PX,$d as COUPLER_WIDTH_PX,In as CableNode,zn as ClosureNode,Fn as CouplerNode,mo as DeviceNode,Co as DevicePlacementError,qn as DiagramErrorBoundary,wi as FIBER_COLORS_12,cr as FiberEdge,tn as FiberNode,Lc as FibreCableWithTubesExpanded,Mc as FibreFlowMap,Vn as FibreSplitNode,Ho as HANDLE_EXTENSION_PX,Hn as MultiTubeCableNode,Zn as NetworkDiagram,Ki as PANEL_BORDER_WIDTH,no as PANEL_HEADER_HEIGHT,vr as PANEL_HEIGHT_PX,ro as PANEL_PADDING,Zi as PANEL_TUBE_TRAY_SPACING,Cr as PANEL_WIDTH_PX,an as POWER_CONNECTORS,Bn as PatchPanelNode,rn as PowerEdge,xt as RACK_HEADER_HEIGHT,Qr as RACK_WIDTH_PX,en as RackNode,xn as SpliceNode,vo as SplicePlacementError,vn as SpliceTrayNode,ja as TEMPLATE_SCHEMA_VERSION,Rn as TubeNode,Je as U_HEIGHT_PX,hn as VerticalPDU,Ei as Width,ol as addDeviceToRack,dl as addSpliceToTray,Ve as baseColorFor,Qc as buildNodesFromRackConfig,il as buildNodesFromSpliceConfig,$n as calculateClosureDimensions,Ld as calculateCouplerRightX,Od as calculateCouplerSlotSpacing,na as calculateCouplerSpacing,go as calculateDevicePositionFromU,Mn as calculatePanelDimensions,oa as calculateSlotPositionFromY,Td as calculateSplicePositionFromNumber,qc as calculateUPositions,ra as calculateYFromSlotPosition,Cl as countTemplateFacePorts,Gn as createNetworkDiagramStore,el as createRackConfigFromNodes,al as createSpliceConfigFromNodes,on as fiberSolidOrStriped,Dr as findNearestRack,Uo as findNextAvailableHolderPosition,ar as findNextAvailableUPosition,Oc as generateLayout,Hi as getConnectorConfig,_n as getCouplerDimensions,sn as getDeviceConnectorType,qt as getFiberColor,ta as getInnerContentWidth,ur as getPDUPortType,Ad as getPanelHeight,ea as getPanelWidth,Bt as getPowerPortStyle,la as getRackBounds,gt as getStatusColor,qi as getTrayDimensions,Tr as getTubeDimensions,_a as inventoryCableToNetworkEdge,Da as inventoryDeviceToNetworkNode,Fa as inventoryRackToNetworkNode,Bc as inventoryToNetworkDiagram,Ls as isHighPowerConnector,ua as isPointInRack,Zt as isStriped,jt as isUPositionAvailable,Va as netboxCableToNetworkEdge,Ua as netboxDeviceToNetworkNode,za as netboxRackToNetworkNode,Zc as netboxToNetworkDiagram,Pl as parseNetboxTemplate,rl as removeDeviceFromRack,cl as removeSpliceFromTray,Le as replaceEdge,Bd as snapToCouplerPosition,kn as snapToSplicePosition,ir as snapToUPosition,yi as updateDeviceUPosition,tl as updateDeviceUPositionInSchema,sl as updateSpliceHolderPosition,Yn as useDiagramEdges,jn as useDiagramNodes,Kd as useNetworkDiagram,ws as validateAndSnapDevice,ti as validateRackDevicePlacements,vl as validateRenderFidelity,oi as validateSplicePlacements};//# sourceMappingURL=index.mjs.map
1
+ import ot,{useState,useMemo,useRef,useEffect,useSyncExternalStore,Component,useCallback}from'react';import {useReactFlow,Handle,Position,getBezierPath,BaseEdge,EdgeLabelRenderer,useUpdateNodeInternals,useEdges,addEdge,ReactFlowProvider,useNodesState,useEdgesState,applyNodeChanges,useOnSelectionChange,ReactFlow,Background,Controls,MiniMap,Panel,applyEdgeChanges,ConnectionMode,getSmoothStepPath,SmoothStepEdge}from'reactflow';import {toPng}from'html-to-image';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var Ke=20,Ct=60,on=300,Ho=5;function xi(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=xi(e)==="light"?"react-flow-light":"react-flow-dark";return t?`${r} ${t}`:r}function ki(e){return xi(e)==="light"?"#e5e5e5":"#2a2a2a"}function Pi(e,t){return {width:"100%",height:"100%",...t}}var Ts=["device","server","switch","router"],Ss=new Set(Ts);function Do(e){return typeof e=="string"&&Ss.has(e)}function Xe(e){return !!e&&Do(e.type)}var Is=/-(source|target)$/i;function Le(e){return e?e.replace(Is,""):""}function tt(e){return typeof e=="string"&&e.includes("power")}function vt(e,t){return typeof t.id=="string"&&t.id.length>0?t.id:tt(t.type)?t.label:`${e}-${t.label}`}function rr(e){let t=Le(e).toLowerCase();return t.startsWith("pwr")||t.includes("power")}var Es="Network Ports",Fs="Rear Network Ports",Hs="Power Ports",Ci=8,Ds=92;function nr(e){return Math.max(0,Math.min(100,e))}function rn(e){if(e==="top"||e==="right"||e==="bottom"||e==="left")return e}function vi(e){return typeof e.position?.xPercent=="number"&&typeof e.position?.yPercent=="number"}function _s(e){return typeof e.position?.offsetPercent=="number"||typeof e.position?.offsetPx=="number"}function Ms(e){return e.face==="rear"||e.face==="back"?"rear":e.face==="front"?"front":tt(e.type)?"rear":"front"}function $s(e,t){return typeof e.group=="string"&&e.group.trim().length>0?e.group.trim():tt(e.type)?Hs:t==="rear"?Fs:Es}function ir(e){return typeof e.port.order=="number"&&Number.isFinite(e.port.order)?e.port.order:e.index}function As(e,t){return t<=1?50:Ci+e*(Ds-Ci)/(t-1)}function Ls(e){let t=e.filter(n=>!!rn(n.port.position?.side)&&!vi(n.port)&&!_s(n.port)),o=new Map,r=new Map;return t.forEach(n=>{let i=rn(n.port.position?.side);if(!i)return;let a=r.get(i);if(a){a.push(n);return}r.set(i,[n]);}),r.forEach(n=>{let i=[...n].sort((a,s)=>{let c=ir(a)-ir(s);return c!==0?c:a.index-s.index});i.forEach((a,s)=>{o.set(a.index,As(s,i.length));});}),o}function Bs(e,t){let o=rn(e.position?.side);if(vi(e)){let a={xPercent:nr(e.position?.xPercent),yPercent:nr(e.position?.yPercent)};return o&&(a.side=o),a}if(!o)return;let r={side:o};if(typeof e.position?.offsetPx=="number"&&Number.isFinite(e.position.offsetPx))return r.offsetPx=e.position.offsetPx,r;let i=(typeof e.position?.offsetPercent=="number"&&Number.isFinite(e.position.offsetPercent)?nr(e.position.offsetPercent):void 0)??(typeof t=="number"?nr(t):void 0);return typeof i=="number"&&(r.offsetPercent=i),r}function Os(e,t){let o=Bs(e.port,t);return {id:e.port.id,label:e.port.label,connected:e.port.connected??false,type:e.port.type,cableType:e.port.cableType,connectorType:e.port.connectorType,...o?{position:o}:{}}}function Ri(e){let t=new Map;e.forEach((n,i)=>{if(typeof n.label!="string"||n.label.trim().length===0)return;let a=Ms(n),s=$s(n,a),c=`${a}:${s}`,l=t.get(c);if(l){l.entries.push({index:i,port:{...n,label:n.label.trim()}});return}t.set(c,{face:a,groupName:s,entries:[{index:i,port:{...n,label:n.label.trim()}}]});});let o=[],r=[];return t.forEach(n=>{let i=[...n.entries].sort((c,l)=>{let g=ir(c)-ir(l);return g!==0?g:c.index-l.index}),a=Ls(i),s={name:n.groupName,ports:i.map(c=>Os(c,a.get(c.index)))};if(n.face==="rear"){r.push(s);return}o.push(s);}),{ports:o,rearPorts:r}}function Je(e){return Array.isArray(e?.ports)?Ri(e.ports):{ports:Array.isArray(e?.portGroups)?e.portGroups:[],rearPorts:Array.isArray(e?.rearPortGroups)?e.rearPortGroups:[]}}function nn(e){return Je(e).ports}function an(e){return Je(e).rearPorts}function _o(e){return Array.isArray(e)?e.reduce((t,o)=>t+(Array.isArray(o.ports)?o.ports.length:0),0):0}function Ti(e){return _o(Je(e).ports)>0}function Si(e){return _o(Je(e).rearPorts)>0}function it(e){let t=Ti(e);return Si(e)&&!t?"rear":"front"}function Ii(e){return typeof e=="string"&&e.trim().length>0}function sn(e){let{ports:t,rearPorts:o}=Je(e),r=_o(t)>0||Ii(e.frontImageUrl),n=_o(o)>0||Ii(e.rearImageUrl);if(r&&n)return "both";if(r)return "front";if(n)return "rear"}function Ei(e,t,o,r){let n=e.mountMode;if(n==="front"||n==="rear"||n==="both")return n;let i=sn(e);if(i)return i;if(e.view==="front"||e.view==="rear")return e.view;let a=o+r/2;return t>=a?"front":"rear"}var Ws=24;function zs(e){return e?.rackLayout==="split-face"?"split-face":"single-face"}function Ie(e){return zs(e)==="split-face"}function Lt(e){return typeof e?.rackFaceGapPx=="number"&&Number.isFinite(e.rackFaceGapPx)&&e.rackFaceGapPx>=0?e.rackFaceGapPx:Ws}function $t(e){return e?.rackWidthPx||300}function Mo(e){let t=$t(e);return Ie(e)?t*2+Lt(e):t}function Be(e){if(e?.mountMode==="front"||e?.mountMode==="rear"||e?.mountMode==="both")return e.mountMode;let t=sn(e??{});return t||"both"}function At(e){return e==="front"?["front"]:e==="rear"?["rear"]:["front","rear"]}function ar(e,t){let o=new Set(At(e));return At(t).some(n=>o.has(n))}function sr(e,t){return Ie(e)&&Be(t)==="front"?$t(e)+Lt(e):0}function Fi(e,t){return Ie(e)&&Be(t)==="both"?Mo(e):$t(e)}var Hi=e=>{if(typeof e.parentId=="string")return e.parentId;if(typeof e.parentNode=="string")return e.parentNode},Rt=(e,t)=>typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):t,Us=()=>"bottom-up",Yt=e=>e.data.uNumberingDirection||Us(),dr=(e,t,o)=>o==="bottom-up"?t-e+1:e,cr=(e,t,o)=>o==="bottom-up"?t-e+1:e;var lr=(e,t,o,r)=>{let n=Hi(e);if(!n||n!==t.id)return o;let i=Rt(e.data.uHeight,1),a=Rt(t.data.uHeight,42),s=Yt(t),c=60,l=o.y-c,g=Math.round(l/20)+1,f;s==="bottom-up"?f=dr(g,a,s)-i+1:f=dr(g,a,s);let p=a-i+1,u=Math.max(1,Math.min(p,f));if(s==="top-down"&&f<=1&&(u=1),!jt(t,e,u,r)){let h=ur(t,e,r,u);if(h!==void 0)u=h;else {let w=Rt(e.data.uPosition,0);if(w>0&&jt(t,e,w,r))u=w;else return {x:sr(t.data,e.data),y:e.position?.y??o.y,uPosition:w>0?w:void 0}}}let y;if(s==="bottom-up"){let h=u+i-1,w=cr(h,a,s);y=c+(w-1)*20-1;}else {let h=cr(u,a,s);y=c+(h-1)*20-1;}return {x:sr(t.data,e.data),y,uPosition:u}},jt=(e,t,o,r)=>{let n=Rt(t.data.uHeight,1),i=Rt(e.data.uHeight,42);if(o<1||o+n-1>i)return false;let a=r.filter(l=>Do(l.type)&&Hi(l)===e.id&&l.id!==t.id),s=Ie(e.data),c=Be(t.data);for(let l of a){let g=Rt(l.data.uPosition,1),f=Rt(l.data.uHeight,1),p=o,u=o+n-1,y=g,h=g+f-1;if(p<=h&&u>=y){if(s){let w=Be(l.data);if(!ar(c,w))continue}return false}}return true},ur=(e,t,o,r=1)=>{let n=Rt(t.data.uHeight,1),a=Rt(e.data.uHeight,42)-n+1;if(a<1)return;let s=Number.isFinite(r)?Math.floor(r):1,c=Math.max(1,Math.min(a,s));for(let l=c;l<=a;l++)if(jt(e,t,l,o))return l;for(let l=1;l<c;l++)if(jt(e,t,l,o))return l},bo=(e,t,o=1,r)=>{let n=60,i=Yt(e),a=e.data.uHeight||42,s=cr(t,a,i),c;if(i==="bottom-up"){let l=t+o-1,g=cr(l,a,i);c=n+(g-1)*20-1;}else c=n+(s-1)*20-1;return {x:sr(e.data,r),y:c}},Di=(e,t,o)=>{let r=e.data.uHeight||1,n=bo(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}}},Vs=(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 bt(e){switch(e){case "active":return "#10b981";case "inactive":return "#ef4444";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var dn=({data:e,selected:t,id:o,onViewChange:r,onRackFaceChange:n,isDragOver:i=false})=>{let{label:a,ports:s=0,status:c="active",uHeight:l=42,face:g="front",customHeaderText:f}=e,p=Ie(e),u=Mo(e),y=$t(e),h=Lt(e),{getNodes:w,setNodes:k}=useReactFlow(),v=w(),[C,R]=useState(e.showUMarkers!==void 0?e.showUMarkers:true),x=()=>{let M=Yt({data:e})==="bottom-up"?"top-down":"bottom-up";k(D=>D.map(U=>U.id===o?{...U,data:{...U.data,uNumberingDirection:M}}:U));},I=()=>{if(p)return;let E=g==="front"?"rear":"front";n?n(o,E):r?v.filter(D=>D.parentId===o).forEach(D=>{r(D.id,E);}):k(M=>M.map(D=>D.id===o?{...D,data:{...D.data,face:E}}:D.parentId===o?{...D,data:{...D.data,view:E}}:D));},_=()=>{let E=[],M=60,D=Yt({data:e});for(let U=1;U<=l;U++){let ee=M+(U-1)*20-4,te=dr(U,l,D);E.push(jsx("div",{style:{position:"absolute",left:"-35px",top:`${ee}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:te},U));}return E};return jsxs("div",{className:`rack-node ${t?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${bt(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:[jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:a}),jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",p?"rear|front":g]}),jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),R(!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"}),jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),x();},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&&jsx("button",{onPointerDown:E=>{E.stopPropagation();},onMouseDown:E=>{E.stopPropagation();},onClick:E=>{E.stopPropagation(),E.preventDefault(),I();},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"})]})]}),jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"},children:p&&jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex"},children:[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"}),jsx("div",{style:{width:`${h}px`}}),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&&jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:_()})]})};var cn=({data:e,selected:t})=>{let{label:o,status:r="active"}=e;return jsxs("div",{className:`fiber-node ${t?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${bt(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:[jsx(Handle,{type:"target",position:Position.Top}),jsx(Handle,{type:"source",position:Position.Bottom}),jsx(Handle,{type:"target",position:Position.Left}),jsx(Handle,{type:"source",position:Position.Right}),jsx("div",{style:{textAlign:"center"},children:jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:o})}),jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:bt(r),borderRadius:"50%"}})]})};var _i=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function ze(e){let t=(e-1)%12;return _i[t]}function Zt(e){return e>12}function Tt(e,t){let o=t?.base??ze(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 ln(e){let t=Tt(e);return t.backgroundImage?{background:t.base,backgroundImage:t.backgroundImage}:{background:t.base}}function qt(e){return ze(e)}function St(e){return e.map(t=>({base:ze(t),striped:Zt(t)}))}function Ks(e,t,o,r,n,i,a,s){let c=St(o),l=c.length,g=r?1.2:1,f=!!s?.highlight,p=r?2:1.5,u=s?.highlightWidth??p*3,y=s?.highlightColor??c[0]?.base??"#22d3ee";return jsxs(Fragment,{children:[f&&jsx(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,w)=>{let v=(l-w)*g;return jsx("path",{d:t,stroke:h.base,strokeWidth:v,fill:"none",strokeLinecap:"butt",opacity:h.striped?.9:1,style:n},`${e}-ribbon-${w}`)}),c.some(h=>h.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&s&&(s.bandwidth||s.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${i}px,${a}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${c[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[s.bandwidth&&jsx("div",{children:s.bandwidth}),s.length&&jsxs("div",{children:[s.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var gr=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:l={},className:g})=>{let[f,p,u]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a}),{bandwidth:y,length:h,color:w="#00FFFF",striped:k=false,ribbonFiberIds:v,isRibbon:C,highlight:R,highlightColor:x,highlightWidth:I}=s||{},_=!!R;if((C||v&&v.length>=6&&v.length<=12)&&v)return Ks(e,f,v,c??false,l??{},p,u,s);let M=c?3:2,D=I??M*3,U={...l,stroke:w,strokeWidth:M,strokeDasharray:"none"};return jsxs(Fragment,{children:[_&&jsx(BaseEdge,{id:`${e}-highlight`,path:f,style:{...l,stroke:x??w,strokeWidth:D,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${M}px`,"--rn-edge-highlight-to":`${D}px`}}),jsx(BaseEdge,{id:e,path:f,style:U}),k&&jsx(BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsx(EdgeLabelRenderer,{children:c&&s&&(y||h)&&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 ${w}`,pointerEvents:"none",zIndex:9999},children:[y&&jsx("div",{children:y}),h&&jsxs("div",{children:[h,"m"]})]})})]})};var un=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,style:s={},data:c,markerEnd:l})=>{let[g]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a}),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 jsx(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,...s}})()})};function td(e,t,o,r,n,i,a,s,c,l,g){let f=St(s),p=f.length,u=c?1.8:1.5,y=!!g?.highlight,h=c?3:2.5,w=g?.highlightWidth??h*3,k=g?.highlightColor??f[0]?.base??"#22d3ee",[v,C,R]=getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a});return jsxs(Fragment,{children:[y&&jsx(BaseEdge,{id:`${e}-highlight`,path:v,style:{...l,stroke:k,strokeWidth:w,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${h}px`,"--rn-edge-highlight-to":`${w}px`}}),f.map((x,I)=>{let E=(p-I)*u;return jsx("path",{d:v,stroke:x.base,strokeWidth:E,fill:"none",strokeLinecap:"butt",opacity:x.striped?.9:1,style:l},`${e}-ribbon-${I}`)}),f.some(x=>x.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:c&&g&&(g.bandwidth||g.length)&&jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${C}px,${R}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&&jsx("div",{children:g.bandwidth}),g.length&&jsxs("div",{children:[g.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[s.length,"F"]})]})})]})}var Li=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",ribbonFiberIds:p,isRibbon:u,highlight:y,highlightColor:h,highlightWidth:w}=s||{},k=!!y;if((u||p&&p.length>=6&&p.length<=12)&&p)return td(e,t,o,r,n,i,a,p,c??false,l??{},s);let C=c?4:3,R=w??C*3,x={...l,stroke:f,strokeWidth:C};return jsxs(Fragment,{children:[k&&jsx(BaseEdge,{id:`${e}-highlight`,path:getSmoothStepPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a})[0],style:{...l,stroke:h??f,strokeWidth:R,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${C}px`,"--rn-edge-highlight-to":`${R}px`}}),jsx(SmoothStepEdge,{...g,id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:x})]})};function rd({sourceX:e,sourceY:t,targetX:o,targetY:r,sourcePosition:n,targetPosition:i}){let a=n===Position.Left||n===Position.Right,s;if(a){let c=(e+o)/2;s=`M ${e},${t} L ${c},${t} L ${c},${r} L ${o},${r}`;}else {let c=(t+r)/2;s=`M ${e},${t} L ${e},${c} L ${o},${c} L ${o},${r}`;}return s}function nd(e,t,o,r,n,i){let a=St(o),s=a.length,c=r?1.2:1,l=!!i?.highlight,g=r?2:1.5,f=i?.highlightWidth??g*3,p=i?.highlightColor??a[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 jsxs(Fragment,{children:[l&&jsx(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`}}),a.map((w,k)=>{let C=(s-k)*c;return jsx("path",{d:t,stroke:w.base,strokeWidth:C,fill:"none",strokeLinecap:"butt",opacity:w.striped?.9:1,style:n},`${e}-ribbon-${k}`)}),a.some(w=>w.striped)&&jsx(BaseEdge,{id:`${e}-ribbon-stripe`,path:t,style:{...n,stroke:"#000",strokeWidth:1,strokeDasharray:"3 3",opacity:.4}}),jsx(EdgeLabelRenderer,{children:r&&i&&(i.bandwidth||i.length)&&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 ${a[0]?.base||"#00FFFF"}`,pointerEvents:"none",zIndex:9999},children:[i.bandwidth&&jsx("div",{children:i.bandwidth}),i.length&&jsxs("div",{children:[i.length,"m"]}),jsxs("div",{style:{fontSize:"8px",opacity:.8},children:[o.length,"F"]})]})})]})}var Wi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s,selected:c,style:l={},...g})=>{let{color:f="#00FFFF",striped:p=false,ribbonFiberIds:u,isRibbon:y,highlight:h,highlightColor:w,highlightWidth:k}=s||{},v=!!h,C=rd({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a});if((y||u&&u.length>=6&&u.length<=12)&&u)return nd(e,C,u,c??false,l??{},s);let x=c?3:2,I=k??x*3,_={...l,stroke:f,strokeWidth:x,strokeDasharray:"none"};return jsxs(Fragment,{children:[v&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...l,stroke:w??f,strokeWidth:I,opacity:.7,strokeDasharray:"14 10","--rn-edge-highlight-from":`${x}px`,"--rn-edge-highlight-to":`${I}px`}}),jsx(BaseEdge,{id:e,path:C,style:_}),p&&jsx(BaseEdge,{id:`${e}-stripe`,path:C,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var Vi=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,style:s={},data:c,markerEnd:l,selected:g})=>{let{color:f="#6366f1",label:p,highlight:u,highlightColor:y,highlightWidth:h}=c||{},w=!!u,k=8,v=h??k*1.8,[C,R,x]=getBezierPath({sourceX:t,sourceY:o,sourcePosition:i,targetX:r,targetY:n,targetPosition:a}),I={...s,stroke:f,strokeWidth:k,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxs(Fragment,{children:[w&&jsx(BaseEdge,{id:`${e}-highlight`,path:C,style:{...s,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`}}),jsx(BaseEdge,{id:e,path:C,markerEnd:l,style:I}),p&&jsx(EdgeLabelRenderer,{children:jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${R}px,${x}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 Gi=(o=>(o.FULL="full",o.HALF="half",o))(Gi||{});var fn={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 Ot(e){let t=fn[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,a=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",...a}}function Xi(e){let t=fn[e];if(!t)throw new Error(`Unknown connector type: ${e}`);return t}function cd(e){return Xi(e).amperage===16}function mr(e){return e%10<8?"C13":"C19"}function gn(e){let t=e.toLowerCase();return t.includes("mx304")||t.includes("mx480")||t.includes("mx960")?"C20":"C14"}var ud="#6b7280",pd="#374151",bn="#10b981",fd="100% 100%",hr=1,gd={smf:"#fbbf24",cat6:"#8b5cf6",om3:"#06b6d4",om4:"#8b5cf6",om5:"#84cc16",cat5e:"#3b82f6",cat6a:"#ef4444",cat7:"#f97316",fiber:"#3b82f6",ethernet:"#10b981"},bd=/^[a-zA-Z][a-zA-Z\d+\-.]*:/,md=/^data:image\//i,hd=typeof window<"u"?ot.useLayoutEffect:ot.useEffect;function yd(e){return (e??"").toLowerCase().replace(/_/g,"-")}function wd(e){return !bd.test(e)&&!e.startsWith("//")}function xd(e){if(!e)return;let t=e.trim();if(t){if(wd(t))return t;try{let o=new URL(t),r=o.protocol.toLowerCase();return r==="https:"||r==="blob:"?o.href:r==="data:"&&md.test(t)?t:void 0}catch{return}}}function Nd(e){return `url(${JSON.stringify(e)})`}function yn(e){return tt(e.type)}function wn(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":gn(t)}function mn(e,t){return vt(e,t)}function kd(e,t,o,r,n){let i=t.length>0||!!r,a=o.length>0||!!n;return e||(i?"front":a?"rear":"front")}function Pd(e,t){return t===true||e==="fill"?fd:e==="none"?"auto":e==="scale-down"?"contain":e??"cover"}function Cd(e){return yn(e)?e.type==="power_c19"?"#fbbf24":"#f59e0b":e.type==="console"||e.type==="mgmt"?"#8b5cf6":e.type==="usb"?bn:e.cableType?gd[e.cableType]??bn:bn}function vd(e){return e.connected?Cd(e):ud}function Yi(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 Rd(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 Td(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 Oo(e){return Math.max(0,Math.min(100,e))}function st(e,t,o){return Math.max(t,Math.min(o,e))}function hn(e){return typeof e.position?.xPercent=="number"&&typeof e.position?.yPercent=="number"}function Sd(e,t,o,r,n){let i=[];for(let g of e)for(let f of g.ports)hn(f)&&i.push({handleId:mn(g.name,f),xPercent:Oo(f.position.xPercent),yPercent:Oo(f.position.yPercent),side:f.position?.side});if(i.length===0)return {heightByHandleId:new Map,bottomAnchoredHandleIds:new Set};let a=new Set,s=[...new Set(i.map(g=>Number(g.yPercent.toFixed(2))))].sort((g,f)=>g-f);if(s.length>=2){let g=s[s.length-1];for(let f of i)f.side==="top"&&Math.abs(f.yPercent-g)<=.15&&a.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=st(u,1,n);y<n&&c.set(g.handleId,y);}return {heightByHandleId:c,bottomAnchoredHandleIds:a}}function Id(e){switch(e){case "top":return Position.Top;case "right":return Position.Right;case "bottom":return Position.Bottom;case "left":return Position.Left;default:return Position.Top}}function Ed(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 Fd(e,t,o,r,n,i,a){if(!e.position)return;if(typeof e.position.xPercent=="number"&&typeof e.position.yPercent=="number"){let h=Oo(e.position.xPercent),w=Oo(e.position.yPercent),k=a??e.position.side??Ed(h,w),v=t/2+hr,C=Math.max(v,r-t/2),R=o/2+hr,x=Math.max(R,n-o/2),I=st(r*h/100,v,C),_=st(n*w/100,R,x);return {position:Id(k),style:{left:`${I-t/2-hr}px`,top:`${_-o/2-hr}px`,right:"initial",bottom:"initial",transform:"none"}}}if(!e.position.side)return;let c=e.position.side,l=typeof e.position.offsetPercent=="number"?Oo(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,w=st(h,f,p);return {position:Position.Top,style:{top:"0px",left:`${w}px`,right:void 0,bottom:void 0,transform:"translate(-50%, 50%)"}}}case "bottom":{let h=g!==void 0?g:r*(l??50)/100,w=st(h,f,p);return {position:Position.Bottom,style:{bottom:"0px",left:`${w}px`,right:void 0,top:void 0,transform:"translate(-50%, -50%)"}}}case "left":{let h=g!==void 0?g:n*(l??50)/100,w=st(h,u,y);return {position:Position.Left,style:{left:"0px",top:`${w}px`,right:void 0,bottom:void 0,transform:"translate(50%, -50%)"}}}case "right":{let h=g!==void 0?g:n*(l??50)/100,w=st(h,u,y);return {position:Position.Right,style:{right:"0px",top:`${w}px`,left:void 0,bottom:void 0,transform:"translate(-50%, -50%)"}}}default:return}}function Zi(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 qi(e,t,o,r){let n=e%2===0,i=Math.ceil(t/2),a=Math.floor(t/2),s=Math.max(n?i:a,1),c=Math.floor(n?e/2:(e-1)/2),l=Zi(c,s,o,r);return n?{position:Position.Top,style:{transform:"translateY(50%)",left:`${l-o/2}px`}}:{position:Position.Bottom,style:{transform:"translateY(-50%)",left:`${l-o/2}px`}}}function Ki(e,t,o,r,n,i){let a=e%2===0,s=Math.ceil(t/2),c=Math.floor(t/2),l=Math.max(a?s:c,1),g=Math.floor(a?e/2:(e-1)/2),f=Zi(g,l,o,n),p=1,u=st(Math.round(r*.75),1,4),y=Math.max(p,i-r-1),h=st(p+r+u,p,y),w=a?p:h;return {position:Position.Top,style:{transform:"none",left:`${f-o/2}px`,top:`${w}px`,right:void 0,bottom:void 0}}}function Hd(e,t,o,r,n){let i=wn(e,n),a=Ot(i),s;if(r<=20){let g=Math.max(2,r-a.height-2);s=`${o<=1?(2+g)/2:2+t*(g-2)/(o-1)}px`;}else s=`${25+t*50}%`;return {position:Position.Right,style:{transform:"translateX(-50%)",top:s,width:`${a.width}px`,height:`${a.height}px`,background:a.color,border:`1px solid ${a.borderColor}`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:a.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:a.borderRadius,clipPath:a.clipPath}}}function Dd(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:Position.Top,style:{transform:"translateY(50%)",left:`${i}px`,right:void 0}}}return qi(e,t,o,r)}function _d(e,t,o,r,n,i,a,s,c){if(s==="patch-panel"||s==="switch")return qi(t,o,r,i);if(yn(e)){let f=wn(e,c),p=Ot(f),u;if(a<=20){let w=Math.max(2,a-p.height-2);u=`${o<=1?(2+w)/2:2+t*(w-2)/(o-1)}px`;}else u=`${25+t*50}%`;return {position: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:Position.Right,style:{transform:"translate(-50%, -50%)",top:`${st(o<=1?a/2:n/2+t*Math.max(a-n,0)/Math.max(o-1,1),n/2,Math.max(n/2,a-n/2))}px`}}}function Md(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 ho=({id:e,data:t,selected:o})=>{let r=useUpdateNodeInternals(),{label:n,status:i="active",deviceType:a="server",manufacturer:s,uHeight:c=1,width:l="full",view:g,rackWidthPx:f,frontImageUrl:p,rearImageUrl:u,imageFit:y,imagePosition:h,imageRepeat:w,stretchToFit:k}=t,{ports:v,rearPorts:C}=ot.useMemo(()=>Je(t),[t]),R=yd(a),x=f??300,I=Ie(t),_=Be(t),E=kd(g??it(t),v,C,p,u),M=ot.useMemo(()=>I?At(_):[E],[I,_,E]),D=M[0]??E,U=I&&_==="both",ee=c*20,te=Lt(t),ie=x+te,ce=ot.useMemo(()=>[I?"split":"single",_,M.join(","),D,R,n,ee.toString(),x.toString(),ie.toString(),Yi(v),Yi(C)].join("|"),[I,_,M,D,R,n,ee,x,ie,v,C]);hd(()=>{r(e);},[ce,e,r]);let z=ot.useCallback(oe=>{let J=xd(oe==="rear"?u:p);return J?{backgroundImage:Nd(J),backgroundSize:Pd(y,k),backgroundPosition:h??"center",backgroundRepeat:w??"no-repeat"}:{}},[u,p,y,k,h,w]),V=ot.useMemo(()=>z("front"),[z]),B=ot.useMemo(()=>z("rear"),[z]),O=D==="rear"?B:V,X,Q;if(I)X=`${Fi(t,t)+4}px`,Q=void 0;else {let oe=x+4,re=Math.floor(x/2);X=l==="half"?`${re}px`:`${oe}px`,Q=l==="half"?`${re}px`:void 0;}let $=R==="server"&&c===1,A=bt(i),pe={"--rn-device-bg-image":U?"none":String(O.backgroundImage??"none"),"--rn-device-bg-position":String(O.backgroundPosition??"center"),"--rn-device-bg-repeat":String(O.backgroundRepeat??"no-repeat"),"--rn-device-bg-size":String(O.backgroundSize??"cover"),"--rn-device-border-color":A,"--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":Q??"auto","--rn-device-status-color":A,"--rn-device-translate-y":$?"-1px":"0px","--rn-device-width":X},se=ot.useMemo(()=>{let oe=new Set;for(let re of v)for(let J of re.ports)oe.add(mn(re.name,J));return oe},[v]),le=ot.useCallback((oe,re)=>re==="rear"&&U&&se.has(oe)?`${oe}--rear`:oe,[se,U]),j=ot.useCallback((oe,re,J=0,Oe=x)=>{let Ze=[];if(oe.length===0)return Ze;let{width:wt,height:de}=Td(Oe),{heightByHandleId:xt,bottomAnchoredHandleIds:qe}=Sd(oe,Oe,ee,wt,de),Vr=oe.reduce((Fe,je)=>Fe+je.ports.length,0),xe=(R==="switch"||R==="patch-panel")&&Vr>=24,Ee=R==="switch"||R==="patch-panel";for(let Fe of oe)for(let je=0;je<Fe.ports.length;je+=1){let Pe=Fe.ports[je],co=mn(Fe.name,Pe),ct=yn(Pe),Qe=wt,Nt=de;if(ct){let pt=wn(Pe,n),Dt=Ot(pt);Qe=Dt.width,Nt=Dt.height;}else if(hn(Pe)){let pt=xt.get(co);pt!==void 0&&(Nt=pt,Qe=st(Math.round(Nt*1.2),3,wt));}let lo=vd(Pe),To=Pe.connected?lo:pd,kt=!ct&&hn(Pe)&&Nt<de,qo=Rd(Qe,Nt,lo,To,kt),Jo=re==="front"?ct?Hd(Pe,je,Fe.ports.length,ee,n):xe?Ki(je,Fe.ports.length,wt,de,Oe,ee):Dd(je,Fe.ports.length,wt,Oe):!ct&&xe?Ki(je,Fe.ports.length,wt,de,Oe,ee):_d(Pe,je,Fe.ports.length,wt,de,Oe,ee,R,n),Vt=Fd(Pe,Qe,Nt,Oe,ee,void 0,Ee&&qe.has(co)?"bottom":void 0),lt=Vt?ct?{position:Vt.position,style:{...Jo.style,...Vt.style}}:Vt:Jo,Ae={...{...qo,...lt.style}};Ae.left!==void 0&&J!==0&&(typeof Ae.left=="number"?Ae.left=`${Ae.left+J}px`:Ae.left=`calc(${Ae.left} + ${J}px)`),U&&Ae.left===void 0&&(lt.position===Position.Left?(Ae.left=`${J}px`,Ae.right=void 0):lt.position===Position.Right&&(Ae.left=`${J+Oe}px`,Ae.right=void 0));let Gt=le(co,re),ut=Md(ct,R,re,Pe.connected);if(ut.secondary){let pt=R==="switch"||R==="router"?{...Ae,background:"transparent",border:"none",opacity:0}:Ae,Dt=R==="switch"||R==="router"?`${Fe.name} - ${Pe.label} (input) ${Pe.connected?"(connected)":"(disconnected)"}`:`${Fe.name} - ${Pe.label} (${ut.secondary}) ${Pe.connected?"(connected)":"(disconnected)"}`;Ze.push(jsx(Handle,{id:`${Gt}-${ut.secondary}`,type:ut.secondary,position:lt.position,style:pt,title:Dt},`${Gt}-${ut.secondary}`));}Ze.push(jsx(Handle,{id:Gt,type:ut.primary,position:lt.position,style:Ae,title:`${Fe.name} - ${Pe.label} ${Pe.connected?"(connected)":"(disconnected)"}`,children:ct?je+1:void 0},Gt));}return Ze},[ee,x,n,R,le,U]),ke=ot.useMemo(()=>{let oe=[];for(let re of M){if(re==="front"&&v.length>0){let J=U?ie:0;oe.push(...j(v,"front",J,x));}re==="rear"&&C.length>0&&oe.push(...j(C,"rear",0,x));}return oe},[M,v,C,j,x,U,ie]);return jsxs("div",{className:`device-node ${o?"selected":""} ${U?"device-node--split-both":""}`,style:pe,children:[U&&jsxs("div",{className:"device-node__split-face-layer",style:{position:"absolute",inset:0,display:"flex",pointerEvents:"none",zIndex:0},children:[jsx("div",{className:"device-node__split-face device-node__split-face--rear",style:{width:`${x}px`,backgroundImage:String(B.backgroundImage??"none"),backgroundPosition:String(B.backgroundPosition??"center"),backgroundRepeat:String(B.backgroundRepeat??"no-repeat"),backgroundSize:String(B.backgroundSize??"cover")}}),jsx("div",{className:"device-node__face-bridge","data-testid":"device-face-bridge",style:{width:`${te}px`},children:jsx("div",{className:"device-node__face-bridge-line"})}),jsx("div",{className:"device-node__split-face device-node__split-face--front",style:{width:`${x}px`,backgroundImage:String(V.backgroundImage??"none"),backgroundPosition:String(V.backgroundPosition??"center"),backgroundRepeat:String(V.backgroundRepeat??"no-repeat"),backgroundSize:String(V.backgroundSize??"cover")}})]}),jsxs("div",{className:"device-node__content",style:{position:"relative",zIndex:1},children:[jsx("div",{className:"device-node__label",children:n}),c>1&&jsx("div",{className:"device-node__manufacturer",children:s})]}),c>1&&jsxs("div",{className:"device-node__u-indicator",children:[c,"U"]}),jsx("div",{className:"device-node__status-indicator"}),ke]})};var wr=20,yo=3,Nr=2,$d=1,Nn=2,Qi=6,Ad=12;function xn(e){return Math.max(0,Math.min(100,e))}function kn(e,t,o){return Math.max(t,Math.min(o,e))}function Ld(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 xr(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=xr(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 Od(e){if(Array.isArray(e.pduPortGroups)&&e.pduPortGroups.length>0)return e.pduPortGroups;let t=an(e);if(t.length>0)return t;let o=nn(e);return o.length>0?o:[]}function Wd(e,t){return !Array.isArray(e.portTypes)||e.portTypes.length===0?Array.from({length:t},(o,r)=>xr(mr(r))??"C13"):Array.from({length:t},(o,r)=>{let n=xr(e.portTypes?.[r]);return n||(xr(mr(r))??"C13")})}function zd(e,t){let o=Od(e),r=Wd(e,t);if(o.length===0)return Array.from({length:t},(a,s)=>({id:`${s+1}`,label:`${s+1}`,connectorType:r[s]??"C13",groupName:"Power"}));let n=[],i=0;return o.forEach(a=>{a.ports.forEach(s=>{let c=r[i]??"C13";n.push({id:vt(a.name,s),label:s.label,connectorType:Bd(s,c),groupName:a.name,position:s.position}),i+=1;});}),n}function Ud(e){return Ot(e.connectorType).height}function Vd(e,t){return !e||t<=0?-1:e==="top"?0:e==="bottom"?t:Math.floor(t/2)}function ea(e,t){let o=[],r=t>=0,n=r?kn(t,0,e.length):-1;for(let i=0;i<=e.length;i+=1)r&&i===n&&o.push({kind:"mgmt",height:Ad}),i<e.length&&o.push({kind:"port",portIndex:i,height:Ud(e[i]),groupName:e[i].groupName});return o}function ta(e,t){return e.kind==="port"&&t.kind==="port"?e.groupName===t.groupName?Nn:Qi:Nn}function Gd(e,t){let o=ea(e,t);if(o.length===0)return Math.max(Nr+yo+1,1);let r=0;for(let n=0;n<o.length;n+=1)r+=o[n].height,n<o.length-1&&(r+=ta(o[n],o[n+1]));return Nr+r+yo}function Xd(e,t,o){let r=ea(e,o);if(r.length===0)return {portCenters:[]};let n=[];for(let h=0;h<r.length-1;h+=1)n.push(ta(r[h],r[h+1]));let i=r.reduce((h,w)=>h+w.height,0),a=n.reduce((h,w)=>h+w,0),s=i+a,c=Math.max(t-Nr-yo,1),l=0,g=n,f=Math.max(0,c-s);if(f>0)if(n.length===0)l=f/2;else {let h=n.map(k=>k===Qi?1.2:1),w=h.reduce((k,v)=>k+v,0);g=n.map((k,v)=>w<=0?k:k+f*h[v]/w);}let p=[],u,y=Nr+l;for(let h=0;h<r.length;h+=1){let w=r[h],k=y+w.height/2;w.kind==="mgmt"?u=k:p[w.portIndex]=k,y+=w.height,h<r.length-1&&(y+=g[h]??Nn);}return {portCenters:p,mgmtCenterY:u}}function jd(e,t,o,r,n,i){if(!e)return {position:Position.Right,leftPx:Math.round((r-n)/2)-1,topPx:t-i/2};let a=e.side,s=a==="left"?Position.Left:a==="top"?Position.Top:a==="bottom"?Position.Bottom:Position.Right,c=typeof e.offsetPercent=="number"?xn(e.offsetPercent):void 0,l=typeof e.offsetPx=="number"?e.offsetPx:void 0,g=typeof e.xPercent=="number"?xn(e.xPercent):void 0,f=typeof e.yPercent=="number"?xn(e.yPercent):void 0;if(g!==void 0&&f!==void 0){let y=a??Ld(g,f),h=y==="left"?Position.Left:y==="top"?Position.Top:y==="bottom"?Position.Bottom:Position.Right,w=Math.max(o-yo,1),k=r*g/100,v=kn(w*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-yo,1)*f/100:t;return a==="top"||a==="bottom"?(l!==void 0?p=l:c!==void 0&&(p=r*c/100),u=a==="top"?i/2:o-i/2):(l!==void 0?u=l:c!==void 0&&(u=Math.max(o-yo,1)*c/100),a==="left"?p=n/2:a==="right"&&(p=r-n/2-1)),u=kn(u,i/2,Math.max(i/2,o-i/2)),{position:s,leftPx:p-n/2,topPx:u-i/2}}function Yd(e,t){return 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:[jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsx(Handle,{type:"source",position:Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit")}var Cn=({data:e,selected:t})=>{let{label:o,status:r="active",heightCm:n=100,powerPorts:i=36,widthPx:a=15,mgmt_unit:s}=e,c=Math.max(0,i),l=zd(e,c),g=Vd(s,l.length),f=n*4.2,p=Gd(l,g),u=Math.max(f-wr,p),y=Math.max(a-$d*2,1),h=wr+u,w=Xd(l,u,g);return jsxs("div",{className:`vertical-pdu-node ${t?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${bt(r)}`,borderRadius:"2px",padding:0,width:`${a}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:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:`${wr}px`,display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:o})}),jsxs("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${h-wr}px`,overflow:"hidden"},children:[typeof w.mgmtCenterY=="number"?Yd(w.mgmtCenterY,y):null,l.map((k,v)=>{let C=w.portCenters[v]??u/2,R=Ot(k.connectorType),x=jd(k.position,C,u,y,R.width,R.height);return jsx(Handle,{type:"source",position:x.position,id:k.id,style:{position:"absolute",left:`${x.leftPx}px`,top:`${x.topPx}px`,right:"initial",bottom:"initial",width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,boxSizing:"border-box",transform:"none",cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`${k.groupName} - ${k.label} (${k.connectorType})`,children:k.label},`handle-${k.id}`)})]})]})};var Tn=({data:e,selected:t,id:o})=>{let{lossDb:r,mode:n="single",ribbonFiberIds:i}=e||{},a=useEdges(),s=a.find(x=>x.target===o&&x.targetHandle==="left"),c=a.find(x=>x.source===o&&x.sourceHandle==="right"),l=a.find(x=>x.target===o&&x.targetHandle==="right"),g=c||l,f=s?.data?.color||"#555",p=g?.data?.color||"#555",u=n==="ribbon",y=s?.data?.ribbonFiberIds||i,h=g?.data?.ribbonFiberIds||i,w=u&&y?St(y):null,k=u&&h?St(h):null,v=!!s&&!!g;return 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&&w&&k?jsxs("div",{style:{position:"absolute",inset:0,borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none",display:"grid",gridTemplateColumns:"1fr 1fr"},children:[jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:w.map((x,I)=>jsx("div",{style:{flex:1,background:x.base,opacity:x.striped?.9:1}},`left-${I}`))}),jsx("div",{style:{display:"flex",flexDirection:"column",width:"100%",height:"100%"},children:k.map((x,I)=>jsx("div",{style:{flex:1,background:x.base,opacity:x.striped?.9:1}},`right-${I}`))})]}):jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsx("div",{style:{background:f}}),jsx("div",{style:{background:p}})]}),jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1,background:"transparent"}}),v&&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"&&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:[jsx("div",{children:`${r.toFixed(2)} dB`}),u&&i&&jsxs("div",{style:{fontSize:"7px",opacity:.8},children:[i.length,"F"]})]}),jsx(Handle,{type:"target",position:Position.Left,id:"left",isConnectable:true,style:{width:12,height:u&&w?20:12,borderRadius:u&&w?"6px":"50%",border:"none",background:u&&w?`linear-gradient(to bottom, ${w.map(x=>x.base).join(", ")})`:f,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsx(Handle,{type:"source",position:Position.Right,id:"right",isConnectable:true,style:{width:12,height:u&&k?20:12,borderRadius:u&&k?"6px":"50%",border:"none",background:u&&k?`linear-gradient(to bottom, ${k.map(x=>x.base).join(", ")})`:p,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsx(Handle,{type:"target",position:Position.Right,id:"right",isConnectable:true,style:{width:12,height:u&&k?20:12,borderRadius:u&&k?"6px":"50%",border:"none",background:u&&k?`linear-gradient(to bottom, ${k.map(x=>x.base).join(", ")})`:p,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var Vo=20,kr=36;var eo=32,oa=4,Wt=12,Zd=69,to=80,Sn=(to-Zd)/2;var In=(e,t,o,r)=>{if(!e.parentId||e.parentId!==t.id)return o;let n=e.data?.mode==="ribbon",i=n?kr:Vo,a=n?32:16,s=eo,c=o.y-s,l=Math.round(c/i)+1,f=Math.max(1,Math.min(Wt,l));if(!Uo(t,e,f,r)){let y=Go(t,e,r,f);if(y!==f){let h=(i-a)/2;return {x:Sn,y:s+(y-1)*i+h,holderPosition:y}}}let p=(i-a)/2,u=s+(f-1)*i+p;return {x:Sn,y:u,holderPosition:f}},Uo=(e,t,o,r)=>!r.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==t.id).some(i=>i.data.holderPosition===o),Go=(e,t,o,r=1)=>{for(let n=r;n<=Wt;n++)if(Uo(e,t,n,o))return n;for(let n=r-1;n>=1;n--)if(Uo(e,t,n,o))return n;return 1},qd=(e,t)=>Xo(e,t,false),Xo=(e,t,o=false)=>{let r=eo,n=o?kr:Vo,a=(n-(o?32:16))/2,s=r+(t-1)*n+a;return {x:Sn,y:s}};var Hn=({data:e,selected:t})=>{let{label:o="Splice Tray"}=e||{},[r,n]=useState(false),i=()=>{if(!r)return null;let a=[],s=eo;for(let c=1;c<=Wt;c++){let l=s+(c-1)*Vo;a.push(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:`${Vo}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return a};return jsxs("div",{className:`splice-tray-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${to}px`,height:`${eo+Wt*kr+oa}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:[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:[jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:o}),jsx("button",{onPointerDown:a=>{a.stopPropagation();},onMouseDown:a=>{a.stopPropagation();},onClick:a=>{a.stopPropagation(),a.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(),jsx("div",{style:{position:"absolute",top:eo,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Dn=({data:e,selected:t,id:o})=>{let{fibersPerTube:r=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},a=e?.mode==="ribbon"||e?.ribbon===true,s=useEdges(),c=`tube-${n}`,l=s.find(te=>te.source===o&&te.sourceHandle===c||te.target===o&&te.targetHandle===c),g=l?.data?.color,f=ze((n-1)%12+1),p=g||f,u=Math.max(1,Math.min(24,Number(r)||12)),y=14,h=4,w=1,k=2,v=20,C=u*y+(u-1)*h,R=Math.max(60,C+w*2+k*2),x=i==="left"?Position.Left:i==="right"?Position.Right:Position.Bottom,I=x!==Position.Bottom,_=I?14:20,E=I?8:20,M=I?`inset ${x===Position.Left?"-4px":"4px"} 0 0 rgba(0, 0, 0, 0.35)`:"none",D=l?p:I?`linear-gradient(${x===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:_,height:E,borderRadius:I?6:"50%",opacity:l?.3:.9,pointerEvents:"auto",background:D,backgroundColor:p,border:l?`2px solid ${p}`:`3px dashed ${p}`,cursor:"crosshair","--fiber-bg":p,boxShadow:l?M:`${M}${M!=="none"?", ":""}0 0 8px ${p}`,transition:"opacity 0.2s, box-shadow 0.2s",...x===Position.Left?{left:-(_-4)}:x===Position.Right?{right:-(_-4)}:{}},ee=useMemo(()=>{let te=[],ie=R-k*2-w*2,ce,z,V=false;i==="left"?(ce=w,z=Position.Top):i==="right"?(ce=w+ie-C,z=Position.Top,V=true):(ce=w+(ie-C)/2,z=Position.Top);for(let B=0;B<u;B++){let O=V?u-B:B+1,X=`fiber-${O}`,Q=s.find(oe=>oe.source===o&&oe.sourceHandle===X||oe.target===o&&oe.targetHandle===X),$=!!Q&&(Q.data?.isRibbon||Q.data?.ribbonFiberIds&&Array.isArray(Q.data.ribbonFiberIds)),A=Q?.data?.color,pe=typeof Q?.data?.striped=="boolean"?Q.data.striped:void 0,se=Tt(O);a||$?se=Tt(O,{base:"#808080",striped:false}):(A||pe!==void 0)&&(se=Tt(O,{...A?{base:A}:{},...pe!==void 0?{striped:pe}:{}}));let le=ce+B*(y+h),j=w,ke={position:"absolute",left:`${le}px`,top:`${j}px`,width:y,height:y,borderRadius:"50%",border:"none",zIndex:10,cursor:"pointer","--fiber-bg":se.base,backgroundColor:se.base};se.backgroundImage&&(ke["--fiber-bg-image"]=se.backgroundImage),te.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:X,type:"target",position:z,className:"tube-fiber-handle",isConnectable:true,style:ke,"data-fiber-idx":O,"data-fiber-color":se.base}),jsx(Handle,{id:X,type:"source",position:z,className:"tube-fiber-handle",isConnectable:true,style:ke,"data-fiber-idx":O,"data-fiber-color":se.base})]},`fiber-${O}`));}return te},[u,i,R,s,o,y,h,w,k,C,a]);return jsxs("div",{style:{width:R,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:w,boxSizing:"border-box",overflow:"visible"},children:[ee,jsx(Handle,{id:c,type:"target",position:x,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"}),jsx(Handle,{id:c,type:"source",position:x,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 $n=({data:e,selected:t})=>{let{fiberCount:o,cableId:r="CBL-002",label:n,color:i,rotation:a}=e||{},s=ot.useRef(null);ot.useEffect(()=>{if(s.current){let z=typeof a=="number"?a:0;s.current.style.transform=`rotate(${z}deg)`,s.current.style.transformOrigin="center center";}},[a]);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),w=n??`${c}f Cable`,k=r?`Cable ID ${r}`:void 0,v=ze(1),C=i||v,R=t?"#3b82f6":C,x=typeof a=="number"?a:0,I=z=>{let V=(z%360+360)%360;return V>=315||V<45?Position.Top:V>=45&&V<135?Position.Right:V>=135&&V<225?Position.Bottom:Position.Left},_=()=>{let z=[],V=I(x);for(let B=0;B<c;B++){let O=B+1,X=Tt(O),Q=X.base,$=f+B*(l+g),A=-5,pe=X.backgroundImage?X.backgroundImage:Q,se={position:"absolute",left:`${$}px`,top:`${A}px`,width:l,height:l,borderRadius:"50%",border:"none",background:pe,backgroundColor:Q,zIndex:10,cursor:"pointer","--fiber-bg":Q};X.backgroundImage&&(se["--fiber-bg-image"]=X.backgroundImage);let le=`fiber-${O}`;z.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:le,type:"target",position:V,className:"tube-fiber-handle",isConnectable:true,style:se,"data-fiber-idx":O,"data-fiber-color":Q}),jsx(Handle,{id:le,type:"source",position:V,className:"tube-fiber-handle",isConnectable:true,style:se,"data-fiber-idx":O,"data-fiber-color":Q})]},`fiber-${O}`));}return z},E="cable-button",M=8,D={width:M,height:M,borderRadius:"50%",background:C,backgroundColor:C,border:`1px solid ${C}`,cursor:"pointer",zIndex:10},U=2,te=(z=>{let V=(z%360+360)%360;return V>=315||V<45?Position.Bottom:V>=45&&V<135?Position.Left:V>=135&&V<225?Position.Top:Position.Right})(x),ie={width:y,height:u,position:"relative",transform:`rotate(${x}deg)`,transformOrigin:"center center","--rotation":`${x}deg`},ce={width:"100%",height:"100%",borderRadius:4,background:"#111827",border:`${U}px solid ${R}`,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 jsx("div",{ref:s,style:ie,children:jsxs("div",{style:ce,children:[_(),jsx(Handle,{id:E,type:"source",position:te,className:"cable-button-handle",isConnectable:true,style:D,"data-handle-type":"cable-button","data-cable-color":C}),jsx(Handle,{id:E,type:"target",position:te,className:"cable-button-handle",isConnectable:true,style:D,"data-handle-type":"cable-button","data-cable-color":C}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,transform:"translateX(2px)"},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:w}),k&&jsx("div",{style:{fontSize:10,opacity:.8},children:k})]})]})})};var Ln=({data:e,selected:t})=>{let{tubeCount:o=12,fibersPerTube:r=12,fiberCount:n,cableId:i="CBL-002",label:a,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(o)||12)),g=Math.max(1,Number(s)||1),f=14,p=10,u=3,y=6,h=y+p+4,w=60,k=Math.max(120,l*(f+u)+y*2),v=n??l*(Number(r)||12),C=a??`${v}f Cable`,R=i?`Cable ID ${i}`:void 0,x=ze(g),I=c||x,_=t?"#3b82f6":I,E=()=>{let te=[];for(let ie=0;ie<l;ie++){let ce=g+ie,z=Tt(ce),V=z.base,B=y+ie*(f+u),O=-5,X=z.backgroundImage?z.backgroundImage:V,Q={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&&(Q["--fiber-bg-image"]=z.backgroundImage);let $=`tube-${ce}`;te.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:$,type:"target",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:Q,"data-fiber-idx":ce,"data-tube-idx":ce,"data-tube-color":V}),jsx(Handle,{id:$,type:"source",position:Position.Top,className:"tube-fiber-handle",isConnectable:true,style:Q,"data-fiber-idx":ce,"data-tube-idx":ce,"data-tube-color":V})]},`tube-${ce}`));}return te},M="cable-button",D=8,U={width:D,height:D,borderRadius:"50%",background:I,backgroundColor:I,border:`1px solid ${I}`,cursor:"pointer",zIndex:10};return jsxs("div",{style:{width:k,height:w,borderRadius:4,background:"#111827",border:`2px solid ${_}`,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(),jsx(Handle,{id:M,type:"source",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":I}),jsx(Handle,{id:M,type:"target",position:Position.Bottom,className:"cable-button-handle",isConnectable:true,style:U,"data-handle-type":"cable-button","data-cable-color":I}),jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:C}),R&&jsx("div",{style:{fontSize:10,opacity:.8},children:R})]})]})};var Bn=({data:e,selected:t,id:o})=>{let{connector:r="LC",couplerFiberCount:n,label:i,portLabelsLeft:a,portLabelsRight:s}=e||{},c=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,w=g*f+(g-1)*p,k=Math.max(h,w+u*2),v=Math.max(y,80),C=(I,_)=>{let E=`${I}-${_+1}`;return c.find(D=>D.source===o&&D.sourceHandle===E||D.target===o&&D.targetHandle===E)?.data?.color||"#555"},R=I=>{let _=[],E=I==="left"?Position.Left:Position.Right,M=I==="left"?a:s;for(let D=0;D<g;D++){let U=D+1,ee=`${I}-${U}`,te=C(I,D),z=u+(k-w)/2+D*(f+p),V={position:"absolute",left:I==="left"?-5:void 0,right:I==="right"?-5:void 0,top:`${z}px`,width:f,height:f,borderRadius:"50%",border:"none",background:te,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};_.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:ee,type:"target",position:E,isConnectable:true,style:V}),jsx(Handle,{id:ee,type:"source",position:E,isConnectable:true,style:V})]},ee)),M&&M[D]&&_.push(jsx("div",{style:{position:"absolute",left:I==="left"?-30:void 0,right:I==="right"?-30:void 0,top:`${z}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:I==="left"?"right":"left",width:"25px"},children:M[D]},`${ee}-label`));}return _},x=i||`${r}-${g}f`;return 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:[R("left"),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:x})}),R("right")]})};var no=32,Er=30,ic=24,ac=80,Sr=400,Ir=300,la=2,ro=8,ua=120;function Wn(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,a=3,s=60,c=30,l=r*n+(r-1)*i,g=Math.max(c,l+a*2);return {width:Math.max(s,80),height:g}}function Fr(e){let{fibersPerTube:t=12}=e.data||{},o=Math.max(1,Math.min(24,Number(t)||12)),r=14,n=4,i=1,a=2,s=20,c=o*r+(o-1)*n;return {width:Math.max(60,c+i*2+a*2),height:s}}function pa(e){return {width:to,height:0}}function fa(e){return e.type==="coupler"?Wn(e):e.type==="tube"?Fr(e):e.type==="splice-tray"?pa():{width:80,height:30}}function On(e){let t=0;for(let o of e){let r=fa(o),n=(o.position?.x||0)+r.width;n>t&&(t=n);}return t}function ga(e,t=0){let o=t;for(let r of e){let n=fa(r),i=(r.position?.y||0)+n.height;i>o&&(o=i);}return o}function ba(e){return e.data?.panelWidth||Sr}function sc(e){return e.data?.panelHeight||Ir}function ma(e){return ba(e)-la*2-ro*2}function dc(e,t){return ma(e)-t}function ha(e,t=Er){return Math.floor(e/t)+1}function ya(e,t=Er){return (e-1)*t}function cc(e,t,o){let r=Er,n=ha(o.y,r),i=ya(n,r);return {x:o.x,y:i,slotPosition:n}}function zn(e,t){if(t.length===0)return {width:e.data?.panelWidth||Sr,height:e.data?.panelHeight||Ir};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=Fr(p);u.width>c&&(c=u.width);}else if(p.type==="coupler"){let u=Wn(p);u.width>l&&(l=u.width);}let g=c+ua+to+l+5,f=0;i=f+g+f;}else i=On(t)+4;i=Math.max(e.data?.panelWidth||Sr,i);let a=ga(t,no),s=Math.max(e.data?.panelHeight||Ir,a+ro);return {width:i,height:s}}function wa(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 lc(e,t,o){return wa(e,t,o)}var sa=20,da=400,ca=300;function Un(e,t){if(t.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||da,height:e.data?.closureHeight||e.data?.panelHeight||ca};let o=t.some(s=>s.type==="tube"),r=t.some(s=>s.type==="splice-tray"),n;if(o&&r){let s=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=Fr(y);(y.position?.x||0)<u?h.width>s&&(s=h.width):h.width>c&&(c=h.width);}f.length>0&&(l=to),n=ro+s+sa+l+sa+c+5;}else n=On(t)+ro+5;}else n=On(t)+ro+5;n=Math.max(e.data?.closureWidth||e.data?.panelWidth||da,n);let i=ga(t,no),a=Math.max(e.data?.closureHeight||e.data?.panelHeight||ca,i+ro);return {width:n,height:a}}var Xn=({data:e,selected:t,id:o})=>{let{label:r="Patch Panel",header:n,panelWidth:i,panelHeight:a}=e||{},{getNodes:s,setNodes:c}=useReactFlow(),l=useRef(false),g=useRef([]),f=useMemo(()=>{let C=s().filter(R=>R.parentId===o);return (C.length!==g.current.length||C.some((R,x)=>R.id!==g.current[x]?.id))&&(g.current=C),g.current},[s,o]),p=useMemo(()=>({id:o,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:a}}),[o,e,i,a]),u=useMemo(()=>i&&a?{width:i,height:a}:f.length===0?{width:i||400,height:a||300}:zn(p,f),[f,p,i,a]);useEffect(()=>{if(i&&a||l.current)return;let v=i,C=a,R=Math.abs((v||0)-u.width),x=Math.abs((C||0)-u.height);(R>1||x>1)&&(l.current=true,c(I=>I.map(_=>_.id===o?{..._,data:{..._.data,panelWidth:u.width,panelHeight:u.height}}:_)),setTimeout(()=>{l.current=false;},0));},[o,u.width,u.height,i,a,c]);let y=u.width,h=u.height,w=no,k=n||r;return 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:[jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${w}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:k})}),jsx("div",{style:{position:"absolute",top:w,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Kn=({data:e,selected:t,id:o})=>{let{label:r="Closure",header:n,closureWidth:i,closureHeight:a,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:g}=useReactFlow(),f=useRef(false),p=useRef([]),u=useMemo(()=>{let I=l().filter(_=>_.parentId===o);return (I.length!==p.current.length||I.some((_,E)=>_.id!==p.current[E]?.id))&&(p.current=I),p.current},[l,o]),y=useMemo(()=>({id:o,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||s,closureHeight:a||c}}),[o,e,i,a,s,c]),h=useMemo(()=>i&&a?{width:i,height:a}:s&&c?{width:s,height:c}:u.length===0?{width:i||s||400,height:a||c||300}:Un(y,u),[u,y,i,a,s,c]);useEffect(()=>{if(i&&a||s&&c||f.current)return;let x=i||s,I=a||c,_=Math.abs((x||0)-h.width),E=Math.abs((I||0)-h.height);(_>1||E>1)&&(f.current=true,g(M=>M.map(D=>D.id===o?{...D,data:{...D.data,closureWidth:h.width,closureHeight:h.height}}:D)),setTimeout(()=>{f.current=false;},0));},[o,h.width,h.height,i,a,s,c,g]);let w=h.width,k=h.height,v=no,C=n||r,R=w/2;return jsxs("div",{className:`closure-node ${t?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${R}px ${R}px 12px 12px`,padding:0,width:`${w}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:[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:`${R}px ${R}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:C})}),jsx("div",{style:{position:"absolute",top:v,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var qn=({data:e,selected:t,id:o})=>{let{label:r,splitterType:n="splitter",inputCount:i=1,outputCount:a=8}=e||{},s=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,w=Math.min(a||8,48),k=w*l+(w-1)*g,v=Math.max(h,k),C=Math.max(u,v+f*2),R=Math.max(p,50),x=ie=>s.find(z=>z.source===o&&z.sourceHandle===ie||z.target===o&&z.targetHandle===ie)?.data?.color||"#555",I=()=>{let ie=[],ce=f+(C-h)/2;for(let z=0;z<y;z++){let V=`input-${z+1}`,B=ce+z*(l+g),O=x(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%)"};ie.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Left,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position:Position.Left,isConnectable:true,style:X})]},V));}return ie},_=()=>{let ie=[],ce=f+(C-k)/2;for(let z=0;z<w;z++){let V=`output-${z+1}`,B=ce+z*(l+g),O=x(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%)"};ie.push(jsxs(ot.Fragment,{children:[jsx(Handle,{id:`${V}-target`,type:"target",position:Position.Right,isConnectable:true,style:X}),jsx(Handle,{id:`${V}-source`,type:"source",position:Position.Right,isConnectable:true,style:X})]},V));}return ie},E=Math.max(h+f*4,u*.6),M=(C-E)/2,D=M+E,U=0,ee=C,te=t?"#3b82f6":"#4b5563";return jsxs("div",{className:`trapezoid-node ${t?"selected":""}`,style:{width:R,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:[jsx("svg",{width:R,height:C,viewBox:`0 0 ${R} ${C}`,style:{position:"absolute",top:0,left:0,width:`${R}px`,height:`${C}px`,pointerEvents:"none",zIndex:0},children:jsx("polygon",{points:`0,${M} 0,${D} ${R},${ee} ${R},${U}`,fill:"#1f2937",stroke:te,strokeWidth:"2"})}),I(),jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:c})}),_()]})};var Pa=e=>e?.type==="tube"||e?.type==="splice"||e?.type==="coupler"||e?.type==="fibre-split"||e?.type==="cable"||e?.type==="multi-tube-cable",_r=(e,t)=>Pa(e)||Pa(t),ae=(e,t)=>t?e?.type==="fibre-split"?Le(t):Le(t):t||"";function Mr(e,t){if(!e||!t)return "unknown";let o=Le(t);if(!o)return "unknown";if(e.type==="vertical-pdu")return "power";let r=e.data??{},{ports:n,rearPorts:i}=Je(r);for(let l of [...n,...i])for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:tt(g.type)?g.type:void 0})===o)return tt(g.type)?"power":"network";if(rr(o)||/^\d+$/.test(o))return "power";let a=o.toLowerCase(),s=a.startsWith("net-")||a.startsWith("port-")||a.startsWith("uplink-")||a.includes("fiber")||a.includes("ports"),c=/^[A-Z0-9]+-\d+$/i.test(o)&&!a.startsWith("pwr")&&!a.startsWith("power");return s||c?"network":"unknown"}function io(e,t){return Mr(e,t)==="power"}function yc(e,t){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let o=t.nodes.find($=>$.id===e.source),r=t.nodes.find($=>$.id===e.target),n=_r(o,r);if(!n){let $=Mr(o,e.sourceHandle),A=Mr(r,e.targetHandle);if($!=="unknown"&&A!=="unknown"&&$!==A)return {valid:false,reason:`Cannot connect ${$} handle to ${A} handle`};let pe=$==="power"&&A==="power",se=o?.type==="vertical-pdu"||r?.type==="vertical-pdu";if(pe&&!se)return {valid:false,reason:"Power connections must include a PDU endpoint"}}let i=ae(o,e.sourceHandle),a=ae(r,e.targetHandle),s=t.edges.some($=>e.ignoreEdgeId&&$.id===e.ignoreEdgeId?false:$.source===e.source?ae(o,$.sourceHandle)===i:$.target===e.source?ae(o,$.targetHandle)===i:false),c=t.edges.some($=>e.ignoreEdgeId&&$.id===e.ignoreEdgeId?false:$.target===e.target?ae(r,$.targetHandle)===a:$.source===e.target?ae(r,$.sourceHandle)===a:false);if((s||c)&&!n)return s?{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=($,A)=>($?.type==="tube"||$?.type==="cable")&&!!A&&A.startsWith("fiber-"),g=($,A)=>($?.type==="tube"||$?.type==="multi-tube-cable")&&!!A&&A.startsWith("tube-"),f=($,A)=>$?.type==="multi-tube-cable"&&!!A&&A.startsWith("tube-"),p=($,A)=>$?.type==="tube"&&!!A&&A.startsWith("tube-"),u=($,A)=>($?.type==="cable"||$?.type==="multi-tube-cable")&&A==="cable-button",y=($,A)=>$?.type==="splice"&&(A==="left"||A==="right"),h=($,A)=>$?.type==="coupler"&&!!A&&(A.startsWith("left-")||A.startsWith("right-")),w=($,A)=>{if($?.type!=="fibre-split"||!A)return false;let pe=ae($,A);return pe.startsWith("input-")||pe.startsWith("output-")};if(!n)return {valid:true};if(o?.type==="splice"&&r?.type==="splice"){let $=o.data?.mode==="ribbon",A=r.data?.mode==="ribbon";if($!==A)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),R=y(r,e.targetHandle),x=h(o,e.sourceHandle),I=h(r,e.targetHandle),_=w(o,e.sourceHandle),E=w(r,e.targetHandle),M=u(o,e.sourceHandle),D=u(r,e.targetHandle),U=f(o,e.sourceHandle),ee=f(r,e.targetHandle),te=p(o,e.sourceHandle),ie=p(r,e.targetHandle),ce=g(o,e.sourceHandle),z=g(r,e.targetHandle);return k&&R||v&&C||(C&&(I||E)||R&&(x||_))||(x&&(I||E||R)||I&&(x||_||C))||M&&D||(U&&ie||ee&&te)?{valid:true}:ce&&z?{valid:false,reason:"Tube handles can only connect between cable and tube nodes"}:{valid:false,reason:"Connection not allowed by fiber rules"}}function $r(e,t){if(!t)return;let o="--rear",r=Le(e),n=r.endsWith(o);n&&(r=r.slice(0,-o.length));let i=t.data??{},a=i.handleSideMap;if(a&&a[r])return a[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{ports:s,rearPorts:c}=Je(i);if(rr(r))return "rear";for(let l of s)for(let g of l.ports||[])if(vt(l.name,{id:g.id,label:g.label,type:tt(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:tt(g.type)?g.type:void 0})===r)return "rear"}function Jn(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(x=>x.id===v&&x.type==="rack"):void 0;return C&&Ie(C.data)?At(Be(k.data)):[k.data?.view||it(k.data)]},y=(k,v)=>{let C=o.nodes.find(ie=>ie.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 I=u(C),_=$r(v||"",C);if(_)return I.includes(_)?1e3:500;let E=(v||"").toString().replace(/-(source|target)$/i,""),M=E.toLowerCase(),D=M.startsWith("pwr")||M.startsWith("power"),U=M.startsWith("net-")||M.startsWith("port-")||M.startsWith("uplink-")||M.includes("fiber")||M.includes("ports"),ee=/^[A-Z0-9]+-\d+$/i.test(E)&&!M.startsWith("pwr")&&!M.startsWith("power"),te=U||ee;if(D)return I.includes("rear")?1e3:500;if(te)return I.includes("front")?1e3:500},h=y(f.target,f.targetHandle);if(h!==void 0)return h;let w=y(f.source,f.sourceHandle);return w!==void 0?w:1e3},validateConnection:f=>(t.validateConnection||yc)(f,o),selectNodeById:f=>o.nodes.find(p=>p.id===f),selectConnectedEdges:f=>o.edges.filter(p=>p.source===f||p.target===f)}}function wc(e){let t=n=>e.subscribe(i=>n()),o=()=>e.getState();return useSyncExternalStore(t,o,o)}function ei(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().nodes;return useSyncExternalStore(t,o,o)}function ti(e){let t=r=>e.subscribe(n=>r()),o=()=>e.getState().edges;return useSyncExternalStore(t,o,o)}function Ca(e){return e.selectEdgeZIndex}function va(e){let t=Mo(e.data),o=60+(e.data.uHeight||42)*20,r=e.position.x,n=e.position.x+t,i=e.position.y,a=e.position.y+o;return {left:r,right:n,top:i,bottom:a}}function Ra(e,t){let o=va(t);return e.x>=o.left&&e.x<=o.right&&e.y>=o.top&&e.y<=o.bottom}function Ar(e,t){let o=null,r=1/0;for(let n of t){if(!Ra(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 Me(e){let{edges:t,connection:o,edgeType:r,selectEdgeZIndex:n,findBy:i,matchOn:a=i,data:s}=e,c=i==="source"?o.sourceHandle:o.targetHandle,l=i==="source"?o.source:o.target;if(!c||!l)return null;let g=Le(c),f=t.find(k=>a==="source"?k.source===l&&Le(k.sourceHandle)===g:k.target===l&&Le(k.targetHandle)===g);if(!f)return null;let p=t.filter(k=>k.id!==f.id),u=addEdge(o,p),y=u[u.length-1],h=n({...o,id:y.id,type:r}),w={...y,type:r,zIndex:h,style:{...y.style,zIndex:h},data:s!==void 0?s:y.data};return [...u.slice(0,-1),w]}function Ia(e){return !e||e.type!=="splice"?false:e.data?.mode==="ribbon"}var Ue=({type:e,children:t})=>{let o=ot.useRef(null),r=ot.useCallback(n=>{if(o.current=n,n){let i=n.parentElement,a=0;for(;i&&!i.classList.contains("react-flow__node")&&a<10;)i=i.parentElement,a++;i&&i.classList.contains("react-flow__node")&&i.setAttribute("data-type",e);}},[e]);return ot.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]),jsx("div",{ref:r,style:{width:"100%",height:"100%"},children:t})},Ea=(e,t,o)=>({rack:r=>jsx(Ue,{type:"rack",children:jsx(dn,{...r,onViewChange:e,onRackFaceChange:t,isDragOver:o?o()===r.id:false})}),fiber:r=>jsx(Ue,{type:"fiber",children:jsx(cn,{...r})}),device:r=>jsx(Ue,{type:"device",children:jsx(ho,{...r})}),server:r=>jsx(Ue,{type:"server",children:jsx(ho,{...r})}),switch:r=>jsx(Ue,{type:"switch",children:jsx(ho,{...r})}),router:r=>jsx(Ue,{type:"router",children:jsx(ho,{...r})}),"vertical-pdu":r=>jsx(Ue,{type:"vertical-pdu",children:jsx(Cn,{...r})}),splice:r=>jsx(Ue,{type:"splice",children:jsx(Tn,{...r})}),"splice-tray":r=>jsx(Ue,{type:"splice-tray",children:jsx(Hn,{...r})}),tube:r=>jsx(Ue,{type:"tube",children:jsx(Dn,{...r})}),cable:r=>jsx(Ue,{type:"cable",children:jsx($n,{...r})}),"multi-tube-cable":r=>jsx(Ue,{type:"multi-tube-cable",children:jsx(Ln,{...r})}),coupler:r=>jsx(Ue,{type:"coupler",children:jsx(Bn,{...r})}),"patch-panel":r=>jsx(Ue,{type:"patch-panel",children:jsx(Xn,{...r})}),closure:r=>jsx(Ue,{type:"closure",children:jsx(Kn,{...r})}),"fibre-split":r=>jsx(Ue,{type:"fibre-split",children:jsx(qn,{...r})})});function Fa(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 Ha(e,t,o){let r=e.sourceHandle,n=e.targetHandle;return Fa(t)&&r&&!io(t,r)&&(r=Le(r)),Fa(o)&&n&&!io(o,n)&&(n=`${Le(n)}-target`),r===e.sourceHandle&&n===e.targetHandle?e:{...e,sourceHandle:r,targetHandle:n}}var Dc={fiber:gr,ethernet:gr,power:un,smoothstep:Li,step:Wi,"thick-cable":Vi},_c=8192,Mc=8192,$c=2048,Ac=4;function Yo(e,t,o){if(!(typeof e!="number"||Number.isNaN(e)))return Math.min(o,Math.max(t,e))}function Lc(e){if(e)return {...e,width:Yo(e.width,1,_c),height:Yo(e.height,1,Mc),padding:Yo(e.padding,0,$c),pixelRatio:Yo(e.pixelRatio,.1,Ac),quality:Yo(e.quality,0,1)}}var Bc=({nodes:e,edges:t,initialNodes:o,initialEdges:r,onNodesChange:n,onEdgesChange:i,store:a,debug:s,onNodeClick:c,onEdgeClick:l,nodeTypes:g,edgeTypes:f,onConnect:p,onEdgeUpdate:u,isValidConnection:y,connectionMode:h,onViewChange:w,onRackFaceChange:k,className:v,style:C,alignRacksToBottom:R,reAssignable:x=true,colorMode:I="dark",onInit:_,onFlowMethods:E,showDownloadButton:M=false,downloadButtonPosition:D="top-right",downloadButtonText:U="Download Image",downloadButtonStyle:ee,useSmoothstepEdgesForTubes:te=false,readOnly:ie=false,interaction:ce,actionPanel:z,connectOnClick:V=true,panOnDrag:B=true,panOnScroll:O=true,zoomOnScroll:X=true,fitViewOptions:Q})=>{let $=useCallback((d,b)=>{let N=new Map,m=[],T=[],F=(H,L)=>!H||!L?false:!!(H.startsWith("tube-")||L.type==="splice"&&(H==="left"||H==="right")||H==="cable-button");for(let H of d){if(!H.source||!H.target||!H.sourceHandle||!H.targetHandle){s&&console.warn("Invalid edge skipped (missing source/target/handles):",H);continue}let L=b.find(Ye=>Ye.id===H.source),S=b.find(Ye=>Ye.id===H.target),Y=`${H.source}:${H.sourceHandle}`,ne=N.get(Y),Ce=F(H.sourceHandle,L),ve=`${H.target}:${H.targetHandle}`,Re=N.get(ve),Ge=F(H.targetHandle,S);if(ne&&!Ce){s&&console.warn("Duplicate connection detected on source handle, removing:",{handle:Y,existingEdge:ne.id,duplicateEdge:H.id}),T.push(H);continue}if(Re&&!Ge){s&&console.warn("Duplicate connection detected on target handle, removing:",{handle:ve,existingEdge:Re.id,duplicateEdge:H.id}),T.push(H);continue}m.push(H),ne||N.set(Y,H),Re||N.set(ve,H);}return s&&T.length>0&&console.log(`Filtered ${T.length} duplicate edge(s) from initial edges`),m},[s]),A=Array.isArray(e)&&Array.isArray(t),pe=ot.useMemo(()=>A?e||[]:o||e||[],[A,e,o]),se=ot.useMemo(()=>A?t||[]:r||t||[],[A,t,r]),le=ot.useMemo(()=>$(se,pe),[se,pe,$]),j=ot.useMemo(()=>a||Jn({nodes:pe,edges:le,debug:s}),[a,A,s,le]),ke=ei(j),oe=ti(j),[re,J]=useNodesState(ke),[Oe,Ze,wt]=useEdgesState(oe),de=Ca(j),xt=useRef(null),[qe,Vr]=useState(false);useEffect(()=>{let d=()=>{Vr(window.innerWidth<=768||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return d(),window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[]);let xe=ie===true,Ee=useMemo(()=>{let b={...{nodesDraggable:true,nodesConnectable:true,elementsSelectable:!qe,edgesFocusable:!qe,edgesReconnectable:true,connectOnClick:V,panOnDrag:B,panOnScroll:O&&!qe,zoomOnScroll:X&&!qe,zoomOnPinch:!qe,zoomOnDoubleClick:!qe,allowKeyboardDelete:true,showControls:true,showMiniMap:!qe,showInteractiveControl:true},...ce??{}};return xe?{...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},[qe,V,B,O,X,ce,xe]),Fe=useMemo(()=>({enabled:z?.enabled??true,showRearToggle:z?.showRearToggle??true,showDeRack:z?.showDeRack??true}),[z]),{toObject:je,setViewport:Pe,setNodes:co,setEdges:ct,getNodes:Qe,getEdges:Nt,fitView:lo,flowToScreenPosition:To}=useReactFlow();useEffect(()=>{E&&E({toObject:()=>je(),setViewport:Pe,setNodes:d=>{co(d),j.setState({nodes:d});},setEdges:d=>{ct(d),j.setState({edges:d});},toImage:d=>xt.current?toPng(xt.current,Lc(d)):Promise.reject(new Error("ReactFlow wrapper not available")),getNodes:()=>Qe(),getEdges:()=>Nt(),fitView:d=>{if(d?.nodes&&Array.isArray(d.nodes)&&d.nodes.length>0){let b=d.nodes.map(T=>Qe().find(F=>F.id===T)).filter(T=>T!==void 0),{nodes:N,...m}=d;lo({...m,nodes:b});}else {let{nodes:b,...N}=d||{};lo(N);}}});},[E,je,Pe,co,ct,j,lo,Qe,Nt]);let[kt,qo]=useState(false),Jo=useCallback(()=>{if(!kt){if(!xt.current){s&&console.error("ReactFlow wrapper ref is not available");return}qo(true),toPng(xt.current,{filter:d=>!(d?.classList?.contains("react-flow__minimap")||d?.classList?.contains("react-flow__controls")||d?.classList?.contains("react-flow__attribution")||d?.classList?.contains("download-button")||d?.tagName==="BUTTON"),backgroundColor:I==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(d=>{let b=document.createElement("a");b.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,b.href=d,b.click();}).catch(d=>{s&&console.error("Error downloading image:",d);}).finally(()=>{qo(false);});}},[I,s,kt]),[Vt,lt]=useState(null),Gr=useRef(null),Ae=useRef(w),Gt=useRef(k);useEffect(()=>{Ae.current=w;},[w]),useEffect(()=>{Gt.current=k;},[k]),useEffect(()=>{Gr.current=Vt;},[Vt]);let ut=useCallback((d,b)=>{Ae.current?.(d,b);},[]),pt=useCallback((d,b)=>{Gt.current?.(d,b);},[]),Dt=useCallback(()=>Gr.current,[]),li=useRef({...Ea(ut,pt,Dt),...g??{}});useEffect(()=>{li.current={...Ea(ut,pt,Dt),...g??{}};},[ut,pt,Dt,g]);let ds=useMemo(()=>({...Dc,...f??{}}),[f]),ft=useRef(re);useEffect(()=>{ft.current=re;},[re]);let Z=useRef(Oe);useEffect(()=>{Z.current=Oe;},[Oe]),useEffect(()=>{J(ke);},[ke,J]),useEffect(()=>{Ze(oe);},[oe,Ze]),useEffect(()=>{if(A&&t){let d=$(t,e||[]);d.length!==t.length&&(s&&console.warn(`Controlled edges had ${t.length-d.length} duplicate(s) removed`),i?.(d));}},[A,t,e,$,i,s]),useEffect(()=>{A&&j.setState({nodes:e||[]});},[A,e,j]),useEffect(()=>{A&&j.setState({edges:t||[]});},[A,t,j]),useEffect(()=>{if(!R||!re||re.length===0)return;let d=re.filter(S=>S.type==="rack");if(d.length===0)return;let b=d.map(S=>{let ne=S.data?.uHeight||42,Ce=60+ne*20;return (S.position?.y||0)+Ce}),N=Math.min(...b),m=Math.max(...b);if(m-N<20)return;let F=m,H=re.map(S=>{if(S.type!=="rack")return S;let ne=S.data?.uHeight||42,Ce=60+ne*20,ve=(S.position?.y||0)+Ce,Re=F-ve;return Math.abs(Re)<5?S:{...S,position:{x:S.position?.x||0,y:(S.position?.y||0)+Re}}});H.some((S,Y)=>S.position!==re[Y].position)&&J(H);},[R,re,J]);let So=useRef(new Map);useEffect(()=>{let d=new Map;re.forEach(b=>{d.set(b.id,b);}),So.current=d;},[re]);let fe=useCallback(d=>So.current.get(d),[]),Ve=useCallback(d=>{if(!d)return;if(typeof d.parentId=="string")return d.parentId;let b=d.parentNode;if(typeof b=="string")return b},[]),ui=useCallback(d=>{let b=Ve(d);if(!b)return;let N=fe(b);if(!(!N||N.type!=="rack"))return N},[fe,Ve]),pi=useCallback(d=>!d||d.type!=="rack"?false:Ie(d.data),[]),uo=useCallback(d=>{if(!d||!Xe(d))return false;let b=ui(d);return b?Ie(b.data):false},[ui]),Xr=useCallback(d=>{if(!d||d.type!=="device")return false;let b=d.data?.deviceType;return typeof b=="string"&&b.toLowerCase().replace(/_/g,"-")==="patch-panel"},[]),Qo=useCallback(d=>{ft.current=d;let b=new Map;d.forEach(N=>{b.set(N.id,N);}),So.current=b,J(d),A?n?.(d):j.setState({nodes:d});},[A,j,J,n]),we=useCallback(d=>{Z.current=d,Ze(d),A?i?.(d):j.setState({edges:d});},[A,j,Ze,i]),_t=useCallback(d=>{if(d.positionAbsolute)return d.positionAbsolute;let b=d.position?.x||0,N=d.position?.y||0,m=Ve(d),T=new Set;for(;m&&!T.has(m);){T.add(m);let F=fe(m);if(!F)break;if(F.positionAbsolute){b+=F.positionAbsolute.x,N+=F.positionAbsolute.y;break}b+=F.position?.x||0,N+=F.position?.y||0,m=Ve(F);}return {x:b,y:N}},[fe,Ve]),er=useCallback(d=>{let b=_t(d),N=d.width||0,m=d.height||0;return {x:b.x+N/2,y:b.y+m/2}},[_t]),Io=useCallback((d,b)=>{if(!d||!b)return;let N=fe(d);if(!N)return;let m=b.replace(/-(source|target)$/i,"");if(N.type==="fibre-split"&&m.startsWith("output-")){let F=Z.current.filter(H=>H.target===d&&(H.targetHandle||"").replace(/-(source|target)$/i,"").startsWith("input-"));if(F.length>0){let H=F[0]?.data?.color;if(H)return {color:H}}}if((N.type==="tube"||N.type==="cable")&&b.startsWith("fiber-")){let F=b.replace("fiber-",""),H=parseInt(F,10);if(H>=1&&H<=24){let L=qt(H),S=H>12;return {color:L,striped:S}}}if((N.type==="multi-tube-cable"||N.type==="tube")&&b.startsWith("tube-")){let F=b.replace("tube-",""),H=parseInt(F,10);if(H>=1&&H<=24){let L=ze(H),S=H>12;return {color:L,striped:S}}}let T=N.data;if(T.color)return {color:T.color}},[fe]),fi=useRef(new Map);useEffect(()=>{Ze(d=>{let b=false,N=d.map(m=>{let T=de(m);return fi.current.get(m.id)!==T?(b=true,fi.current.set(m.id,T),{...m,zIndex:T,style:{...m.style,zIndex:T}}):m});return b?N:d});},[re,Ze,de]),useEffect(()=>{let d=re.map(N=>{if(N.type==="coupler"&&N.parentId){let m=fe(N.parentId);if(m&&(m.type==="patch-panel"||m.type==="closure")&&(!N.extent||N.extent!=="parent"))return {...N,extent:"parent"}}if(N.type==="splice"&&N.parentId&&N.data.holderPosition&&(!N.position||N.position.x===0&&N.position.y===0)){let m=fe(N.parentId);if(m&&m.type==="splice-tray"){let T=N.data.mode==="ribbon",F=Xo(m,N.data.holderPosition,T);return {...N,position:F}}}if(Xe(N)&&N.parentId&&N.data.uPosition&&(!N.position||N.position.x===0&&N.position.y===0)){let m=fe(N.parentId);if(m){let T=N.data.uHeight||1,F=bo(m,N.data.uPosition,T,N.data);return {...N,position:F}}}return N});d.some((N,m)=>{let T=re[m];return N.extent!==T.extent||N.position?.x!==T.position?.x||N.position?.y!==T.position?.y})&&J(d);},[re,J,fe]);let cs=useCallback(d=>{if(xe)return null;let b=new Map,N=new Map,m=new Set,T=d.map(L=>{if(L.type==="position"&&L.position){let S=fe(L.id);if(S&&S.type==="coupler"&&S.parentId){let Y=fe(S.parentId);if(Y&&(Y.type==="patch-panel"||Y.type==="closure"))return (!S.extent||S.extent!=="parent")&&m.add(S.id),{...L,position:S.position||{x:0,y:0}}}if(S&&(S.type==="tube"||S.type==="splice-tray")&&S.parentId){let Y=fe(S.parentId);if(Y&&Y.type==="closure")return (!S.extent||S.extent!=="parent")&&m.add(S.id),{...L,position:S.position||{x:0,y:0}}}if(S&&S.type==="splice"&&S.parentId){let Y=fe(S.parentId);if(Y&&Y.type==="splice-tray"){let ne=In(S,Y,L.position,ft.current);return ne.holderPosition!==void 0&&b.set(S.id,ne.holderPosition),{...L,position:{x:ne.x,y:ne.y}}}}if(S&&Xe(S)&&S.parentId){let Y=fe(S.parentId);if(Y&&Y.type==="rack"){let ne=lr(S,Y,L.position,ft.current);return ne.uPosition!==void 0&&N.set(S.id,ne.uPosition),{...L,position:{x:ne.x,y:ne.y}}}}}return L}),F=applyNodeChanges(T,ft.current).map(L=>{let S=L;m.has(L.id)&&(S={...S,extent:"parent"});let Y=b.get(L.id);Y!==void 0&&(S={...S,data:{...S.data,holderPosition:Y}});let ne=N.get(L.id);return ne!==void 0&&(S={...S,data:{...S.data,uPosition:ne}}),S});ft.current=F;let H=new Map;return F.forEach(L=>{H.set(L.id,L);}),So.current=H,J(F),F},[J,fe,xe]),ls=useCallback((d,b)=>{lt(null);},[]),us=useCallback((d,b,N)=>{let m=Ve(b);if(!x||!Xe(b)||m){lt(null);return}let T=ft.current.filter(S=>S.type==="rack").map(S=>S),F=er(b),L=Ar(F,T)?.id??null;lt(S=>S===L?S:L);},[x,er,Ve]),ps=useCallback((d,b,N)=>{lt(null);let m=Ve(b);if(!x||!Xe(b)||m)return;let T=_t(b),F=ft.current.filter(W=>W.type==="rack").map(W=>W),H=er(b),L=Ar(H,F),S=ft.current;if(!L)return;let Y={x:T.x-L.position.x,y:T.y-L.position.y},ne=S.find(W=>W.id===b.id)||b,Ce=Ie(L.data),ve=$t(L.data),Re=Lt(L.data),Ge=Ce?Ei(ne.data,Y.x,ve,Re):"both",Ye=Ce&&Ge==="front"?ve+Re:0,He=Ge==="rear"?"rear":Ge==="front"?"front":ne.data.view==="front"||ne.data.view==="rear"?ne.data.view:void 0,We={...ne,parentId:L.id,extent:"parent",position:{x:Ye,y:Y.y},data:{...ne.data,rackLayout:Ce?"split-face":"single-face",rackWidthPx:ve,rackFaceGapPx:Re,mountMode:Ge,view:He}},De=S.filter(W=>W.id!==b.id).concat(We),Ne=lr(We,L,We.position,De);if(Ne.uPosition===void 0||!jt(L,We,Ne.uPosition,De))return;let et=S.map(W=>W.id!==b.id?W:{...W,parentId:L.id,extent:"parent",position:{x:Ne.x,y:Ne.y},data:{...W.data,rackLayout:Ce?"split-face":"single-face",rackWidthPx:ve,rackFaceGapPx:Re,mountMode:Ge,view:He,uPosition:Ne.uPosition??W.data.uPosition}});Qo(et);},[x,_t,er,Qo,Ve]),fs=useCallback(d=>{if(!d.source||!d.target||!d.sourceHandle||!d.targetHandle)return true;let b=fe(d.source),N=fe(d.target),m=ae(b,d.sourceHandle),T=ae(N,d.targetHandle),F=Z.current.some(K=>K.source===d.source?ae(b,K.sourceHandle)===m:K.target===d.source?ae(b,K.targetHandle)===m:false),H=Z.current.some(K=>K.target===d.target?ae(N,K.targetHandle)===T:K.source===d.target?ae(N,K.sourceHandle)===T:false);if(F&&s&&console.log("Connection will replace: Source handle already connected",{source:d.source,sourceHandle:d.sourceHandle,existingEdges:Z.current.filter(K=>K.source===d.source&&K.sourceHandle===d.sourceHandle||K.target===d.source&&K.targetHandle===d.sourceHandle)}),H&&s&&console.log("Connection will replace: Target handle already connected",{target:d.target,targetHandle:d.targetHandle,existingEdges:Z.current.filter(K=>K.target===d.target&&K.targetHandle===d.targetHandle||K.source===d.target&&K.sourceHandle===d.targetHandle)}),!_r(b,N))return true;if(b?.type==="splice"&&N?.type==="splice"){let K=b.data?.mode==="ribbon",me=N.data?.mode==="ribbon";if(K!==me)return s&&console.log("Connection rejected: Ribbon splices can only connect to other ribbon splices",d),false}let S=(K,me)=>(K?.type==="tube"||K?.type==="cable")&&!!me&&me.startsWith("fiber-"),Y=(K,me)=>(K?.type==="tube"||K?.type==="multi-tube-cable")&&!!me&&me.startsWith("tube-"),ne=(K,me)=>K?.type==="multi-tube-cable"&&!!me&&me.startsWith("tube-"),Ce=(K,me)=>K?.type==="tube"&&!!me&&me.startsWith("tube-"),ve=(K,me)=>(K?.type==="cable"||K?.type==="multi-tube-cable")&&me==="cable-button",Re=(K,me)=>K?.type==="splice"&&(me==="left"||me==="right"),Ge=(K,me)=>K?.type==="coupler"&&!!me&&(me.startsWith("left-")||me.startsWith("right-")),Ye=(K,me)=>{if(K?.type!=="fibre-split"||!me)return false;let P=me.replace(/-(source|target)$/i,"");return P.startsWith("input-")||P.startsWith("output-")},He=S(b,d.sourceHandle),We=S(N,d.targetHandle),De=Re(b,d.sourceHandle),Ne=Re(N,d.targetHandle),et=Ge(b,d.sourceHandle),W=Ge(N,d.targetHandle),Se=Ye(b,d.sourceHandle),ue=Ye(N,d.targetHandle),tr=ve(b,d.sourceHandle),Zr=ve(N,d.targetHandle),fo=ne(b,d.sourceHandle),go=ne(N,d.targetHandle),qr=Ce(b,d.sourceHandle),Jr=Ce(N,d.targetHandle),or=Y(b,d.sourceHandle),Qr=Y(N,d.targetHandle);return He&&Ne||We&&De||(De&&(W||ue)||Ne&&(et||Se))||(et&&(W||ue||Ne)||W&&(et||Se||De))||tr&&Zr||(fo&&Jr||go&&qr)?true:or&&Qr?(s&&console.log("Connection rejected: Tube handles can only connect between cable and tube nodes",d),false):(s&&console.log("Connection rejected: Connection not allowed by fiber rules",d),false)},[fe,s]),gs=useCallback(d=>{if(xe)return;s&&console.log("onConnect called:",d);let b=fe(d.source),N=fe(d.target);s&&(console.log("onConnect: sourceNode type:",b?.type,"targetNode type:",N?.type),console.log("onConnect: sourceHandle:",d.sourceHandle,"targetHandle:",d.targetHandle));let m=Ha(d,b,N),T=j.validateConnection({source:m.source??null,target:m.target??null,sourceHandle:m.sourceHandle,targetHandle:m.targetHandle});if(!T.valid&&!(T.reason??"").includes("already connected")){s&&console.warn(`Connection rejected: ${T.reason}`);return}let F=b?.type==="vertical-pdu",H=b?.type==="vertical-pdu"||N?.type==="vertical-pdu",L=io(b,m.sourceHandle),S=io(N,m.targetHandle),Y=L&&S&&H,ne=b?.data,Ce=b?.type==="switch"||b?.type==="device"&&ne?.deviceType==="switch",ve=S,Re=!!m.targetHandle&&(m.targetHandle.startsWith("net-")||m.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Le(m.targetHandle))),Ge=!!m.sourceHandle&&(m.sourceHandle.startsWith("net-")||m.sourceHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(Le(m.sourceHandle))),Ye=N?.type==="switch"||N?.type==="device"&&N.data?.deviceType==="switch",He=N?.type==="vertical-pdu",We=L,De=b?.type==="tube"&&N?.type==="multi-tube-cable",Ne=b?.type==="multi-tube-cable"&&N?.type==="tube",et=De||Ne,W=m.sourceHandle==="cable-button"&&m.targetHandle==="cable-button",Se="fiber";Y?Se="power":W?Se="thick-cable":et&&(Se=te?"smoothstep":"fiber");let ue,tr=Ia(N),Zr=Ia(b);if(tr||Zr){let P=N?.data,G=b?.data,ye=tr?P.ribbonFiberIds:G.ribbonFiberIds;ye&&Array.isArray(ye)&&ye.length>=6&&ye.length<=12&&(ue={ribbonFiberIds:ye,isRibbon:true});}if(!ue&&(Se==="fiber"||Se==="smoothstep")&&!F){let P;De?P=Io(m.target,m.targetHandle):P=Io(m.source,m.sourceHandle),P&&(ue={color:P.color,striped:P.striped,isRibbon:false});}else if(Se==="thick-cable"&&W){let P=b?.data;ue={color:P?.color||(P?.tubeStartIndex?ze(P.tubeStartIndex):"#6366f1")};}let fo=ae(b,m.sourceHandle),go=ae(N,m.targetHandle),qr=Z.current.some(P=>P.source===m.source?ae(b,P.sourceHandle)===fo:P.target===m.source?ae(b,P.targetHandle)===fo:false),Jr=Z.current.some(P=>P.target===m.target?ae(N,P.targetHandle)===go:P.source===m.target?ae(N,P.sourceHandle)===go:false);if(qr||Jr){let P=new Set;for(let G of Z.current){if(G.source===m.source&&ae(b,G.sourceHandle)===fo){P.add(G.id);continue}if(G.target===m.source&&ae(b,G.targetHandle)===fo){P.add(G.id);continue}if(G.source===m.target&&ae(N,G.sourceHandle)===go){P.add(G.id);continue}G.target===m.target&&ae(N,G.targetHandle)===go&&P.add(G.id);}if(P.size>0){let G=Z.current.filter(gt=>!P.has(gt.id)),ye=addEdge(m,G);if(ye.length===G.length)s&&console.warn("Handle replacement skipped: addEdge did not create a new edge",m);else {let gt=ye[ye.length-1],Mt=de({...m,id:gt.id,type:Se}),Xt={...gt,type:Se,zIndex:Mt,style:{...gt.style,zIndex:Mt},data:ue!==void 0?ue:gt.data};we([...ye.slice(0,-1),Xt]),s&&console.log("Handle replacement: Replaced",P.size,"edge(s)");return}}}if(N?.type==="splice"&&(d.targetHandle==="left"||d.targetHandle==="right")&&d.target&&d.targetHandle){let P=Z.current.find(G=>G.target===d.target&&G.targetHandle===d.targetHandle||G.source===d.target&&G.sourceHandle===d.targetHandle);if(P){s&&(console.log("Splice target handle replacement: Found existing edge",P.id,"on splice handle",d.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=d.source&&d.sourceHandle?Z.current.find(Pt=>Pt.source===d.source&&Pt.sourceHandle===d.sourceHandle):null;s&&G&&console.log("Splice target handle replacement: Also found existing source edge",G.id);let ye=new Set;P&&ye.add(P.id),G&&G.id!==P.id&&ye.add(G.id);let gt=Z.current.filter(Pt=>!ye.has(Pt.id));s&&console.log("Splice target handle replacement: Removing",ye.size,"edge(s), creating new connection");let Mt=`edge-${d.source}-${d.sourceHandle}-${d.target}-${d.targetHandle}-${Date.now()}`,Xt=de({...d,id:Mt,type:"fiber"}),Fo={id:Mt,source:d.source,target:d.target,sourceHandle:d.sourceHandle,targetHandle:d.targetHandle,type:"fiber",zIndex:Xt,style:{zIndex:Xt},data:ue!==void 0?ue:{}},tn=[...gt,Fo];we(tn),s&&console.log("Splice target handle replacement: Successfully replaced edge with new edge",Fo.id);return}}if(b?.type==="splice"&&d.sourceHandle==="right"&&d.source&&d.sourceHandle){let P=Z.current.find(G=>G.source===d.source&&G.sourceHandle===d.sourceHandle||G.target===d.source&&G.targetHandle===d.sourceHandle);if(P){s&&console.log("Splice source handle replacement: Found existing edge",P.id,"on splice handle",d.sourceHandle);let G=d.target&&d.targetHandle?Z.current.find(Pt=>Pt.target===d.target&&Pt.targetHandle===d.targetHandle):null;s&&G&&console.log("Splice source handle replacement: Also found existing target edge",G.id);let ye=new Set;P&&ye.add(P.id),G&&G.id!==P.id&&ye.add(G.id);let gt=Z.current.filter(Pt=>!ye.has(Pt.id));s&&console.log("Splice source handle replacement: Removing",ye.size,"edge(s), creating new connection");let Mt=`edge-${d.source}-${d.sourceHandle}-${d.target}-${d.targetHandle}-${Date.now()}`,Xt=de({...d,id:Mt,type:"fiber"}),Fo={id:Mt,source:d.source,target:d.target,sourceHandle:d.sourceHandle,targetHandle:d.targetHandle,type:"fiber",zIndex:Xt,style:{zIndex:Xt},data:ue!==void 0?ue:{}},tn=[...gt,Fo];we(tn),s&&console.log("Splice source handle replacement: Successfully replaced edge with new edge",Fo.id);return}}if((b?.type==="tube"||b?.type==="cable")&&d.sourceHandle?.startsWith("fiber-")&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if((N?.type==="tube"||N?.type==="cable")&&d.targetHandle?.startsWith("fiber-")&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if((b?.type==="multi-tube-cable"||b?.type==="tube")&&d.sourceHandle?.startsWith("tube-")&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:Se,selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if((N?.type==="multi-tube-cable"||N?.type==="tube")&&d.targetHandle?.startsWith("tube-")&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:Se,selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(b?.type==="coupler"&&(d.sourceHandle?.startsWith("left-")||d.sourceHandle?.startsWith("right-"))){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if(N?.type==="coupler"&&(d.targetHandle?.startsWith("left-")||d.targetHandle?.startsWith("right-"))){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(W&&d.source&&d.sourceHandle&&d.target&&d.targetHandle){let P=b?.data,G=P?.color||(P?.tubeStartIndex?ze(P.tubeStartIndex):"#6366f1"),ye=Me({edges:Z.current,connection:m,edgeType:"thick-cable",selectEdgeZIndex:de,findBy:"source",data:{color:G}});if(ye){we(ye);return}if(ye=Me({edges:Z.current,connection:m,edgeType:"thick-cable",selectEdgeZIndex:de,findBy:"target",data:{color:G}}),ye){we(ye);return}}if(F&&ve&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"power",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(He&&We&&d.source&&d.sourceHandle&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"power",selectEdgeZIndex:de,findBy:"source",matchOn:"target",data:ue});if(P){we(P);return}}if(Ce&&Re&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",data:ue});if(P){we(P);return}}if(Ye&&Ge&&d.source&&d.sourceHandle&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",matchOn:"source",data:ue});if(P){we(P);return}}let or=j.validateConnection({source:m.source??null,target:m.target??null,sourceHandle:m.sourceHandle,targetHandle:m.targetHandle});if(!or.valid){if(F&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:ve?"power":"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if(He&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:"power",selectEdgeZIndex:de,findBy:"source",matchOn:"target",data:ue});if(P){we(P);return}}if(Ce&&d.source&&d.sourceHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"source",data:ue});if(P){we(P);return}}if(Ye&&d.target&&d.targetHandle){let P=Me({edges:Z.current,connection:m,edgeType:"fiber",selectEdgeZIndex:de,findBy:"target",matchOn:"source",data:ue});if(P){we(P);return}}s&&console.warn(`Connection rejected: ${or.reason}`);return}let Qr=Z.current.some(P=>P.source===m.source&&P.sourceHandle===m.sourceHandle||P.target===m.source&&P.targetHandle===m.sourceHandle),mi=Z.current.some(P=>P.target===m.target&&P.targetHandle===m.targetHandle||P.source===m.target&&P.sourceHandle===m.targetHandle),en=(P,G)=>!P||!G?false:!!(P.startsWith("tube-")||G.type==="splice"&&(P==="left"||P==="right")||P==="cable-button"),hi=en(m.sourceHandle||"",b),yi=en(m.targetHandle||"",N);if(Qr&&!hi){s&&console.warn("FINAL SAFETY CHECK: Source handle already connected, rejecting duplicate connection",{source:d.source,sourceHandle:m.sourceHandle,existingEdges:Z.current.filter(P=>P.source===m.source&&P.sourceHandle===m.sourceHandle||P.target===m.source&&P.targetHandle===m.sourceHandle)});return}if(mi&&!yi){s&&console.warn("FINAL SAFETY CHECK: Target handle already connected, rejecting duplicate connection",{target:m.target,targetHandle:m.targetHandle,existingEdges:Z.current.filter(P=>P.target===m.target&&P.targetHandle===m.targetHandle||P.source===m.target&&P.sourceHandle===m.targetHandle)});return}let wi={...m,type:Se,zIndex:de({...m,id:"temp-id"}),data:ue},K=addEdge(wi,Z.current),me=K[K.length-1];me&&(bi(P=>new Set(P).add(me.id)),setTimeout(()=>{bi(P=>{let G=new Set(P);return G.delete(me.id),G});},1e3)),we(K);},[we,j,de,fe,s,Io,te,xe]),bs=useCallback((d,b)=>{if(xe||!b.source||!b.target||!b.sourceHandle||!b.targetHandle)return;let N=fe(b.source),m=fe(b.target),T=Ha(b,N,m),F=ae(N,T.sourceHandle),H=ae(m,T.targetHandle),L=Z.current.some(W=>{if(W.id===d.id)return false;let Se=W.source===T.source&&ae(N,W.sourceHandle)===F||W.target===T.source&&ae(N,W.targetHandle)===F,ue=W.target===T.target&&ae(m,W.targetHandle)===H||W.source===T.target&&ae(m,W.sourceHandle)===H;return Se||ue}),S=j.validateConnection({source:T.source??null,target:T.target??null,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,ignoreEdgeId:d.id});if(!S.valid&&!((S.reason??"").includes("already connected")&&L)){s&&console.warn(`Edge update rejected: ${S.reason}`);return}let Y=N?.type==="vertical-pdu"||m?.type==="vertical-pdu",ne=io(N,T.sourceHandle),Ce=io(m,T.targetHandle),ve=ne&&Ce&&Y,Re=N?.type==="tube"&&m?.type==="multi-tube-cable",Ge=N?.type==="multi-tube-cable"&&m?.type==="tube",Ye=Re||Ge,He;ve?He="power":Ye?He=te?"smoothstep":"fiber":He="fiber";let We;if(He==="fiber"||He==="smoothstep"){let W=Io(T.source,T.sourceHandle);W&&(We={color:W.color,striped:W.striped});}let et=Z.current.filter(W=>{if(W.id===d.id)return true;let Se=W.source===T.source&&ae(N,W.sourceHandle)===F||W.target===T.source&&ae(N,W.targetHandle)===F,ue=W.target===T.target&&ae(m,W.targetHandle)===H||W.source===T.target&&ae(m,W.sourceHandle)===H;return !(Se||ue)}).map(W=>W.id===d.id?{...W,source:T.source,target:T.target,sourceHandle:T.sourceHandle,targetHandle:T.targetHandle,type:He,data:We!==void 0?{...W.data,...We}:W.data,zIndex:de({...T,id:W.id,type:He}),style:{...W.style,zIndex:de({...T,id:W.id,type:He})}}:W);we(et);},[we,fe,Io,de,te,s,j,xe]),ms=useCallback((d,b)=>{if(qe){c&&c(b);return}let N=d.metaKey||d.ctrlKey,m=Qe(),T=b,F=Ve(b);if(b.type==="tube"&&F&&!N){let H=m.find(L=>L.id===F&&(L.type==="cable"||L.type==="multi-tube-cable"));H&&(T=H);}if(jr(T),Eo([]),J(H=>H.map(L=>{let S=L.id===T.id;return L.selected===S?L:{...L,selected:S}})),N&&Xe(T)&&!uo(T)){let H=T.data||{},L=H.view||it(H),S=L==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${T.id} from ${L} to ${S}`),w&&w(T.id,S);}c&&c(T);},[w,c,s,Qe,J,qe,Ve,uo]),hs=useCallback(()=>{},[]),ys=useCallback((d,b)=>{jr(null),Eo([b]),J(N=>N.map(m=>m.selected?{...m,selected:false}:m)),c?.(null),l&&l(b);},[l,c,J]),ws=useCallback(()=>{jr(null),Eo([]),J(d=>d.map(b=>b.selected?{...b,selected:false}:b)),c?.(null);},[c,J]),[nt,jr]=useState(null),[gi,bi]=useState(new Set);useOnSelectionChange({onChange:({edges:d})=>{Eo(d||[]);}});let[Yr,Eo]=useState([]);useEffect(()=>{let d=b=>{if(Ee.allowKeyboardDelete&&(b.key==="Backspace"||b.key==="Delete")&&Yr.length>0){if(document.activeElement?.tagName==="INPUT"||document.activeElement?.tagName==="TEXTAREA")return;let N=Yr.filter(m=>{let T=m.sourceHandle||"",F=m.targetHandle||"";return T.startsWith("tube-")||F.startsWith("tube-")?(s&&console.log("Cannot delete edge connected to tube handle",m),false):true});if(N.length>0){let m=new Set(N.map(F=>F.id)),T=Z.current.filter(F=>!m.has(F.id));we(T),Eo([]),s&&console.log("Deleted edges:",N.map(F=>F.id));}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[Yr,we,s,Ee.allowKeyboardDelete]);let xs=useCallback((d,{nodeId:b,handleType:N})=>{s&&console.log("Connection started from",{nodeId:b,handleType:N});},[s]),Ns=useCallback(d=>{s&&console.log("Connection ended",d);},[s]),ks=useCallback(()=>{if(xe||!nt)return;let d=fe(nt.id);if(d){if(d.type==="rack"){let b=d.data||{};if(Ie(b))return;let m=(b.face||"front")==="front"?"rear":"front";k?(k(d.id,m),w&&Qe().filter(F=>F.parentId===d.id).forEach(F=>{w(F.id,m);})):J(T=>T.map(F=>F.id===d.id?{...F,data:{...F.data,face:m}}:F.parentId===d.id?{...F,data:{...F.data,view:m}}:F));return}if(Xe(d)){if(uo(d))return;let b=d.data||{},m=(b.view||it(b))==="front"?"rear":"front";w?w(d.id,m):J(T=>T.map(F=>F.id===d.id?{...F,data:{...F.data,view:m}}:F));}}},[nt,fe,k,w,J,Qe,xe,uo]),Ps=useCallback(()=>{if(xe||!x||!nt||!Xe(nt))return;let d=fe(nt.id),b=Ve(d);if(!d||!Xe(d)||!b)return;let N=_t(d),T=ft.current.map(F=>F.id!==d.id?F:{...F,parentId:void 0,parentNode:void 0,extent:void 0,position:N,data:{...F.data,uPosition:void 0}});Qo(T);},[xe,x,nt,fe,_t,Qo,Ve]),Cs=useMemo(()=>{let d=So.current;return Oe.map(b=>{let N=b,m=d.get(String(N.source)),T=d.get(String(N.target)),F=$r(N.sourceHandle||"",m),H=$r(N.targetHandle||"",T),L=De=>{if(!De||!Xe(De))return;let Ne=De.data??{},et=typeof De.parentId=="string"?De.parentId:De.parentNode,W=et?d.get(et):void 0;return W&&W.type==="rack"&&Ie(W.data)?At(Be(Ne)):[Ne.view||it(Ne)]},S=L(m),Y=L(T),ne=Xr(m),Ce=Xr(T),ve=Xe(m)&&!ne&&!!S&&!!F&&!S.includes(F),Re=Xe(T)&&!Ce&&!!Y&&!!H&&!Y.includes(H),He=ve||Re,We=b.style;if(He)We={...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 Ne={...b.style};delete Ne.opacity,delete Ne.pointerEvents,delete Ne.zIndex,We=Object.keys(Ne).length>0?Ne:void 0;}return {...b,style:We,className:gi.has(b.id)?"edge-connecting":b.className}})},[Oe,gi,Xr]),Te=useMemo(()=>nt?fe(nt.id)??nt:null,[nt,fe]),po=useMemo(()=>{if(!Te||!Fe.enabled||xe)return {showRearToggle:false,showDeRack:false,count:0};let d=Te.type==="rack"?!pi(Te):Xe(Te)?!uo(Te):false,b=Fe.showRearToggle&&d,N=Fe.showDeRack&&x&&!xe&&Xe(Te)&&!!Ve(Te);return {showRearToggle:b,showDeRack:N,count:(b?1:0)+(N?1:0)}},[Te,Fe,x,xe,Ve,uo,pi]),Kr=useMemo(()=>{if(!Te||po.count===0||!xt.current)return null;let d=xt.current.getBoundingClientRect();if(d.width<=0||d.height<=0)return null;let b=Te.positionAbsolute??_t(Te),N=Te.width||0,m=Te.height||0,T=po.count>1?220:110,F=34;try{let H=To({x:b.x+N/2,y:b.y}),L=To({x:b.x+N/2,y:b.y+m}),S=H.x-d.left-T/2,Y=H.y-d.top-F-10;return Y<8&&(Y=L.y-d.top+10),S=Math.max(8,Math.min(S,d.width-T-8)),Y=Math.max(8,Math.min(Y,d.height-F-8)),{left:S,top:Y}}catch{return null}},[Te,po,_t,To]),vs=Ni(I,v),Rs=Pi(I,{touchAction:"none",...C});return jsxs("div",{ref:xt,className:vs,style:Rs,children:[jsxs(ReactFlow,{nodes:re,edges:Cs,onNodesChange:d=>{if(xe)return;let b=cs(d);b&&(A?n&&n(b):j.setState({nodes:b}));},onEdgesChange:d=>{if(xe)return;let b=d.filter(N=>{if(N.type==="remove"){let m=Z.current.find(T=>T.id===N.id);if(m){let T=m.sourceHandle||"",F=m.targetHandle||"";if(T.startsWith("tube-")||F.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",m),false}}return true});if(b.length>0){let N=applyEdgeChanges(b,Z.current);wt(b),A?i&&i(N):j.setState({edges:N});}},onConnect:xe?void 0:p??gs,onConnectStart:xs,onConnectEnd:Ns,onEdgeUpdate:xe?void 0:u??bs,isValidConnection:y??fs,connectionMode:h,onNodeClick:ms,onNodeDoubleClick:hs,onPaneClick:ws,onNodeDragStart:ls,onNodeDrag:us,onNodeDragStop:ps,onEdgeClick:ys,onInit:_,nodeTypes:li.current,edgeTypes:ds,defaultEdgeOptions:{zIndex:1e3,reconnectable:Ee.edgesReconnectable},nodesDraggable:Ee.nodesDraggable,nodesConnectable:Ee.nodesConnectable,elementsSelectable:Ee.elementsSelectable,edgesFocusable:Ee.edgesFocusable,elevateNodesOnSelect:false,selectNodesOnDrag:false,connectOnClick:Ee.connectOnClick,panOnDrag:Ee.panOnDrag,panOnScroll:Ee.panOnScroll,zoomOnScroll:Ee.zoomOnScroll,zoomOnPinch:Ee.zoomOnPinch,zoomOnDoubleClick:Ee.zoomOnDoubleClick,preventScrolling:qe,onlyRenderVisibleElements:true,fitView:true,fitViewOptions:Q,proOptions:{hideAttribution:true},children:[jsx(Background,{color:ki(I)}),Ee.showControls&&jsx(Controls,{showInteractive:Ee.showInteractiveControl}),Ee.showMiniMap&&jsx(MiniMap,{}),jsx(Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),M&&jsx("button",{className:"download-button",onClick:Jo,disabled:kt,"aria-busy":kt,style:{position:"absolute",top:D.includes("top")?"10px":"auto",bottom:D.includes("bottom")?"10px":"auto",right:D.includes("right")?"10px":"auto",left:D.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:kt?"not-allowed":"pointer",opacity:kt?.7:1,transition:"all 0.2s ease",...ee},children:kt?`${U}...`:U}),Te&&Kr&&po.count>0&&jsxs("div",{style:{position:"absolute",top:Kr.top,left:Kr.left,display:"flex",gap:8,zIndex:2e3},children:[po.showRearToggle&&jsx("button",{onClick:d=>{d.preventDefault(),ks();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let d=Te.data;return Te.type==="rack"?(d?.face||"front")==="front"?"Switch to rear":"Switch to front":(d?.view||it(d))==="front"?"Switch to rear":"Switch to front"})(),children:(()=>{let d=Te.data;return Te.type==="rack"?(d?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front":(d?.view||it(d))==="front"?"\u21C4 Rear":"\u21C4 Front"})()}),po.showDeRack&&jsx("button",{onClick:d=>{d.preventDefault(),Ps();},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"})]})]})},ri=e=>jsx(ReactFlowProvider,{children:jsx(Bc,{...e})});var ni=class extends 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??jsxs("div",{role:"alert",style:{padding:16,margin:8,border:"1px solid #e53e3e",borderRadius:4,backgroundColor:"#fff5f5",color:"#c53030"},children:[jsx("strong",{children:"Diagram error"}),": ",o.message,jsx("button",{type:"button",onClick:this.reset,style:{marginLeft:12,padding:"4px 8px",cursor:"pointer"},children:"Try again"})]}):r}};function Ko(e,{rowHeight:t,tubeGap:o}){let r=[],n=[],i=e.kind??(e.tubeCount?"tube":"simple"),a=i==="tube"?Math.max(1,Math.min(24,e.tubeCount??1)):1,s=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<a;f+=1){let p=c+f,u=e.tubeColorMap?.[p];n.push({tubeIndex:p,y:g,label:`T${p}`,color:u??ze(p)});for(let y=0;y<s;y+=1){let h=l+y,w=ln(h);r.push({key:`${p}-${h}`,tubeIndex:i==="tube"?p:void 0,fiberIndex:h,y:g,color:qt(h),striped:Zt(h),backgroundImage:typeof w.backgroundImage=="string"?w.backgroundImage:void 0}),g+=t;}f<a-1&&(g+=o);}return {rows:r,tubeLabels:n,height:g}}var ii=e=>typeof e=="object"&&e!==null,Vc=e=>{if(!ii(e.data))return false;if(e.type==="fibre-flow-cable"){let t=e.data;return typeof t.label=="string"&&ii(t.cable)&&(t.side==="left"||t.side==="right")&&typeof t.rowHeight=="number"&&typeof t.columnWidth=="number"&&typeof t.showTubeLabels=="boolean"&&typeof t.showFiberNumbers=="boolean"&&ii(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},Gc=e=>e==="fibre-flow"||e==="fibre-flow-link",Xc=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,jc=e=>e.sourceHandle==="cable-run"||e.targetHandle==="cable-run"?"fibre-flow-link":"fibre-flow",Yc=(e,t=[])=>{let o=new Map(t.map(n=>[n.id,n])),r=[];return e.forEach(n=>{if(!Xc(n))return;let i=o.get(n.id),a=Gc(n.type)?n.type:i?.type??jc(n);r.push({...i??{},...n,type:a});}),r},Aa=e=>`fiber-${e.tube??1}-${e.fiber}`,La=e=>qt(e.fiber),Ba=e=>Zt(e.fiber),Kc=(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`},Zc=(e,t,o,r,n,i)=>e?`${o} ${i}`:t?`0 ${n} ${r} ${i}`:"6 6",qc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s})=>{let[c,l,g]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,curvature:.35}),f=typeof s?.lossDb=="number"?`${s.lossDb.toFixed(2)} dB`:"",p=s?.label??f,u=s?.sourceColor,y=s?.targetColor,h=s?.color??u??y??"#94a3b8",w=s?.sourceStriped??false,k=s?.targetStriped??false,v=s?.highlighted??true,C=s?.dimmed??false,R=s?.circuitId,x=s?.circuitLabel??R,I=s?.showCircuitId??false,_=u&&y&&u!==y,E=r-t,M=n-o,D=Math.sqrt(E*E+M*M),U=l-t,ee=g-o,te=Math.sqrt(U*U+ee*ee),ie=D>0?te/D*100:50,ce=`fibre-flow-gradient-${e}`,z=w&&!k,V=k&&!w,B=w&&k,O=D*1.25,X=O/2,Q=12,$=Math.ceil(X*1.2/Q),A=Array($).fill("6 6").join(" "),pe=Math.ceil(X*1.2/Q),se=Array(pe).fill("6 6").join(" "),le=I&&x,j=Math.max(p?p.length*6.2+16:0,le?(x?.length||0)*5.5+16:0),ke=le?32:16;return jsxs(Fragment,{children:[jsx("defs",{children:_&&jsxs("linearGradient",{id:ce,x1:t,y1:o,x2:r,y2:n,gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0%",stopColor:u}),jsx("stop",{offset:`${ie}%`,stopColor:u}),jsx("stop",{offset:`${ie}%`,stopColor:y}),jsx("stop",{offset:"100%",stopColor:y})]})}),_?jsx("path",{id:e,d:c,fill:"none",stroke:`url(#${ce})`,strokeWidth:v?4:3,strokeLinecap:"round",strokeLinejoin:"round",opacity:C?.25:1,strokeOpacity:C?.25:1,style:{mixBlendMode:"normal"}}):jsx(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)&&jsx("path",{id:`${e}-stripe`,d:c,fill:"none",stroke:"#000",strokeWidth:v?1.6:1.3,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:Zc(z,V,A,se,X,O),strokeDashoffset:0,opacity:C?.2:.9,style:{mixBlendMode:"normal"}}),(p||le)&&v&&jsx(EdgeLabelRenderer,{children:jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${l}px, ${g}px)`,width:j,height:ke,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&&jsx("div",{style:{lineHeight:1.2},children:p}),le&&jsx("div",{style:{fontSize:8,opacity:.8,lineHeight:1.2,marginTop:p?2:0},children:x})]})})]})},Jc=({id:e,sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,data:s})=>{let[c,l,g]=getBezierPath({sourceX:t,sourceY:o,targetX:r,targetY:n,sourcePosition:i,targetPosition:a,curvature:.2}),f=s?.label,p=s?.color??"#64748b";return jsxs(Fragment,{children:[jsx(BaseEdge,{id:e,path:c,style:{stroke:p,strokeWidth:3,opacity:.85,strokeDasharray:"8 10"}}),f&&jsx(EdgeLabelRenderer,{children: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})})]})},Qc=({data:e})=>{let{cable:t,side:o,rowHeight:r,columnWidth:n,showTubeLabels:i,showFiberNumbers:a,layout:s,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",w=i&&h,k=o==="left"?g+u:u,v=o==="right"?g+u:u,C=o==="left"?Position.Right:Position.Left,R={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 jsxs("div",{style:{position:"relative",width:n,height:s.height,fontFamily:"monospace",color:"inherit",overflow:"visible"},children:[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}),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&&s.tubeLabels.map((x,I)=>{let _=s.rows.filter(te=>te.tubeIndex===x.tubeIndex);if(_.length===0)return null;let E=_[0].y,M=_[_.length-1].y+r,D=M-E,U=s.tubeLabels[I+1],ee=U&&U.y-M>0;return jsx("div",{style:{position:"absolute",top:E,left:0,right:0,height:D,background:x.color,borderLeft:`2px solid ${x.color}`,borderRight:`2px solid ${x.color}`,borderTop:I===0?`2px solid ${x.color}`:"1px solid rgba(0,0,0,0.15)",borderBottom:ee?"1px solid rgba(0,0,0,0.15)":`2px solid ${x.color}`,boxShadow:"inset 0 0 3px rgba(0,0,0,0.1)",borderRadius:I===0&&!ee||I===0?"4px 4px 0 0":ee?"0":"0 0 4px 4px",zIndex:2}},`tube-segment-${x.tubeIndex}`)})}),!w&&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&&s.tubeLabels.map((x,I)=>{let _=s.rows.filter(U=>U.tubeIndex===x.tubeIndex);if(_.length===0)return null;let E=_[0].y,D=_[_.length-1].y+r-E;return jsx("div",{style:{position:"absolute",top:E,left:k,right:v,height:D,...o==="left"?{borderRight:`2px solid ${x.color}`}:{borderLeft:`2px solid ${x.color}`},opacity:.5,pointerEvents:"none"}},`tube-border-${x.tubeIndex}`)}),s.rows.map(x=>{let I=`fiber-${x.tubeIndex??1}-${x.fiberIndex}`,_=x.y+r/2,E={position:"absolute",width:f,height:f,borderRadius:"50%",top:_,background:x.backgroundImage?x.backgroundImage:x.color,backgroundColor:x.color,border:`2px solid ${x.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":x.color,minWidth:f,minHeight:f};x.backgroundImage&&(E["--fiber-bg-image"]=x.backgroundImage);let M=o==="left"?{right:f+p,textAlign:"right"}:{left:f+p,textAlign:"left"};return jsxs(ot.Fragment,{children:[jsx(Handle,{id:I,type:"source",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":x.fiberIndex,"data-tube-idx":x.tubeIndex,"data-fiber-color":x.color}),jsx(Handle,{id:I,type:"target",position:C,className:"fibre-flow-handle",style:E,isConnectable:true,"data-fiber-idx":x.fiberIndex,"data-tube-idx":x.tubeIndex,"data-fiber-color":x.color}),a&&jsx("div",{style:{position:"absolute",top:x.y+r/2-6,...M,fontSize:8,fontWeight:600,color:l?"rgba(15, 23, 42, 0.7)":"rgba(148, 163, 184, 0.95)",whiteSpace:"nowrap",lineHeight:1},children:x.fiberIndex})]},x.key)}),jsx(Handle,{id:"cable-run",type:"source",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:R,isConnectable:true,"data-handle-type":"cable-run"}),jsx(Handle,{id:"cable-run",type:"target",position:o==="left"?Position.Left:Position.Right,className:"cable-run-handle",style:R,isConnectable:true,"data-handle-type":"cable-run"})]})},el=({data:e})=>{let t=e.colorMode==="light";return 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: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})})},tl=(e,t,o,r,n,i,a,s,c,l="dark")=>{let g=[],f=0;return e.forEach(p=>{let u=Ko(p.leftCable,{rowHeight:o,tubeGap:r}),y=Ko(p.rightCable,{rowHeight:o,tubeGap:r}),h=Math.max(u.height,y.height),w=i*2+a,k=32,v=16,C=w+v*2,R=h+k+v*2,x=`flow-closure-${p.id}`,I=`flow-cable-${p.id}-left`,_=`flow-cable-${p.id}-right`,E=t==="horizontal"?{x:f,y:0}:{x:0,y:f};f+=(t==="horizontal"?C:R)+n;let M=p.chamberId?`${p.id} - ${p.chamberId}`:p.id;g.push({id:x,type:"fibre-flow-closure",position:E,data:{label:M,width:C,height:R,headerHeight:k,colorMode:l},selectable:false,draggable:false,style:{width:C,height:R}});let D=k+v+(h-u.height)/2,U=k+v+(h-y.height)/2;g.push({id:I,type:"fibre-flow-cable",position:{x:v,y:D},parentId:x,extent:"parent",data:{label:p.leftCable.label,cable:p.leftCable,side:"left",rowHeight:o,columnWidth:i,showTubeLabels:s,showFiberNumbers:c,layout:u,colorMode:l},style:{width:i,height:u.height}}),g.push({id:_,type:"fibre-flow-cable",position:{x:v+w-i,y:U},parentId:x,extent:"parent",data:{label:p.rightCable.label,cable:p.rightCable,side:"right",rowHeight:o,columnWidth:i,showTubeLabels:s,showFiberNumbers:c,layout:y,colorMode:l},style:{width:i,height:y.height}});}),g},ol=(e,t,o,r=false)=>{let n=[],i=new Map,a=new Map,s=new Map;return (t??[]).forEach(c=>{c.color&&i.set(c.id,c.color),c.label&&a.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=s.get(u.id);if(y&&y.closureId!==c.id){let h=Kc(u.distanceMeters??y.distanceMeters,u.distanceLabel??y.distanceLabel),w=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:w}});}s.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,w=p.circuitId?a.get(p.circuitId):void 0,k=p.color??h,v=La(p.from),C=La(p.to),R=Ba(p.from),x=Ba(p.to);n.push({id:`flow-edge-${c.id}-${p.id}`,type:"fibre-flow",source:l,target:g,sourceHandle:Aa(p.from),targetHandle:Aa(p.to),data:{lossDb:p.lossDb,label:p.label,color:k,sourceColor:v,targetColor:C,sourceStriped:R,targetStriped:x,highlighted:u,dimmed:y,circuitId:p.circuitId,circuitLabel:w,showCircuitId:r}});});}),n},rl=({closures:e,circuits:t,highlightedCircuitId:o,layout:r="horizontal",rowHeight:n=20,tubeGap:i=10,closureGap:a=140,cableColumnWidth:s=32,spliceAreaWidth:c=260,showTubeLabels:l=true,showFiberNumbers:g=true,colorMode:f="dark",showCircuitId:p=false,className:u,style:y,readOnly:h=false,panOnDrag:w=true,panOnScroll:k=true,zoomOnScroll:v=true})=>{let C=useMemo(()=>tl(e,r,n,i,a,s,c,l,g,f),[e,r,n,i,a,s,c,l,g,f]),R=useMemo(()=>ol(e,t,o,p),[e,t,o,p]),[x,I]=useState(C),[_,E]=useState(R);useEffect(()=>{I(C);},[C,I]),useEffect(()=>{E(R);},[R,E]);let M=useCallback((B,O)=>{if(!B||!O||!O.startsWith("fiber-"))return;let X=x.find(le=>le.id===B);if(!X||X.type!=="fibre-flow-cable")return;let Q=/^fiber-(\d+)-(\d+)$/.exec(O);if(!Q)return;let $=Number(Q[1]),A=Number(Q[2]),se=X.data.layout.rows.find(le=>(le.tubeIndex??1)===$&&le.fiberIndex===A);if(se)return {color:se.color,striped:se.striped??false}},[x]),D=useCallback(B=>{if(h||!B.source||!B.target||!B.sourceHandle||!B.targetHandle)return false;let O=x.find(pe=>pe.id===B.source),X=x.find(pe=>pe.id===B.target);if(!O||!X)return false;let Q=typeof B.sourceHandle=="string"&&B.sourceHandle.startsWith("fiber-"),$=typeof B.targetHandle=="string"&&B.targetHandle.startsWith("fiber-");return B.sourceHandle==="cable-run"||B.targetHandle==="cable-run"?true:Q&&$?O.type==="fibre-flow-cable"&&X.type==="fibre-flow-cable":false},[x,h]),U=useCallback(B=>{if(h)return;let O=B.sourceHandle==="cable-run"||B.targetHandle==="cable-run",X=j=>typeof j=="string"&&j.startsWith("fiber-"),Q=X(B.sourceHandle),$=X(B.targetHandle),A=(j,ke,oe)=>j.source===ke&&j.sourceHandle===oe||j.target===ke&&j.targetHandle===oe,pe=O?void 0:M(B.source,B.sourceHandle),se=O?void 0:M(B.target,B.targetHandle),le=O?void 0:{sourceColor:pe?.color,targetColor:se?.color,color:pe?.color??se?.color,sourceStriped:pe?.striped,targetStriped:se?.striped};E(j=>{let ke=j.filter(oe=>{let re=Q&&A(oe,B.source,B.sourceHandle),J=$&&A(oe,B.target,B.targetHandle);return !(re||J)});return addEdge({...B,type:O?"fibre-flow-link":"fibre-flow",data:le},ke)});},[M,h,E]),ee=useCallback((B,O)=>{if(h)return;let X=O.sourceHandle==="cable-run"||O.targetHandle==="cable-run",Q=X?void 0:M(O.source,O.sourceHandle),$=X?void 0:M(O.target,O.targetHandle),A=X?void 0:{sourceColor:Q?.color,targetColor:$?.color,color:Q?.color??$?.color,sourceStriped:Q?.striped,targetStriped:$?.striped},pe=le=>typeof le=="string"&&le.startsWith("fiber-"),se=(le,j,ke)=>le.source===j&&le.sourceHandle===ke||le.target===j&&le.targetHandle===ke;E(le=>{let j=le.filter(J=>J.id!==B.id),ke=pe(O.sourceHandle),oe=pe(O.targetHandle),re=j.filter(J=>{let Oe=ke&&se(J,O.source,O.sourceHandle),Ze=oe&&se(J,O.target,O.targetHandle);return !(Oe||Ze)});return addEdge({...O,type:X?"fibre-flow-link":"fibre-flow",data:A},re)});},[M,h,E]),te=useCallback(B=>{h||I(B.filter(Vc));},[h,I]),ie=useCallback(B=>{h||E(O=>Yc(B,O));},[h,E]),ce=useMemo(()=>({"fibre-flow-cable":Qc,"fibre-flow-closure":el}),[]),z=useMemo(()=>({"fibre-flow":qc,"fibre-flow-link":Jc}),[]),V={borderRadius:8,overflow:"hidden",...y};return jsx(ri,{nodes:x,edges:_,onNodesChange:te,onEdgesChange:ie,onConnect:U,onEdgeUpdate:ee,isValidConnection:D,connectionMode:ConnectionMode.Loose,nodeTypes:ce,edgeTypes:z,className:u,style:V,colorMode:f,readOnly:h,panOnDrag:w,panOnScroll:k,zoomOnScroll:v,fitViewOptions:{padding:.2}})},nl=e=>jsx(rl,{...e});var sl=({cable:e,side:t,rowHeight:o=22,tubeGap:r=10,columnWidth:n=150,layout:i,showTubeLabels:a,showFiberNumbers:s=true,showCableLabel:c=true})=>{let l=useMemo(()=>i??Ko(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,w=e.jacketColor??"#facc15",k=a??(e.kind??(e.tubeCount?"tube":"simple"))==="tube";return jsxs("div",{style:{position:"relative",width:n,height:l.height,fontFamily:"monospace",color:"inherit"},children:[c&&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}),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, ${w} 0%, ${w} 60%, rgba(0,0,0,0.25) 100%)`,border:`2px solid ${w}`,boxShadow:"inset 0 0 6px rgba(0,0,0,0.4)"}}),k&&l.tubeLabels.map(v=>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:[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)"}}),jsx("span",{children:v.label})]},`tube-${v.tubeIndex}`)),l.rows.map(v=>{let C=v.y+o/2-f/2,R=t==="left"?u-f/2-y:u+f/2+y;return jsxs(ot.Fragment,{children:[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)"}}),s&&jsx("div",{style:{position:"absolute",top:v.y+o/2-6,left:R,transform:t==="left"?"translateX(-100%)":"none",fontSize:10,fontWeight:600,color:"rgba(15, 23, 42, 0.75)"},children:v.fiberIndex})]},v.key)})]})};var Va=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}}),Ga=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}}),Xa=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}}},dl=e=>{let t=[],o=[];return e.racks.forEach(r=>t.push(Va(r))),e.devices.forEach(r=>t.push(Ga(r))),e.cables.forEach(r=>o.push(Xa(r))),{nodes:t,edges:o}},cl=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(a=>a.id===n.parentId);if(i){let a=n.data.uPosition||1,s=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+a*20-s*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 ja=e=>typeof e.id=="number"?`device-${e.id}`:`device-${e.name}`,ll="Interfaces",ul="Management",pl="Power",si=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ft=e=>{if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0},Or=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}},Ht=e=>{if(typeof e!="string")return;let t=e.trim().toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20")return t},fl=e=>typeof e=="string"&&e.toLowerCase()==="rear"?"rear":"front",Wr=e=>si(e.custom_fields)?e.custom_fields:void 0,zr=e=>si(e)?e:void 0,Ya=(e,t)=>{let o=Wr(e),r=zr(o?.layout);return fl(t??e.layout?.face??e.face??r?.face??o?.port_face??o?.portFace??o?.face)},Ka=(e,t,o)=>{let r=Wr(e),n=zr(r?.layout),i=Ft(o)??Ft(e.layout?.group)??Ft(e.port_group)??Ft(n?.group)??Ft(r?.port_group)??Ft(r?.portGroup)??Ft(r?.interface_group)??Ft(r?.interfaceGroup)??Ft(r?.group);return i||(t==="power_ac"||t==="power_c13"||t==="power_c19"?pl:t==="console"||t==="mgmt"?ul:ll)},Za=(e,t,o)=>{let r=Wr(e),n=zr(r?.layout);return Ht(o)??Ht(e.layout?.connectorType)??Ht(e.layout?.connector_type)??Ht(e.connector_type)??Ht(n?.connectorType)??Ht(n?.connector_type)??Ht(r?.connectorType)??Ht(r?.connector_type)??Ht(t)},qa=(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"},Ja=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"}},gl=e=>{if(!si(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=Or(e.offsetPercent??e.offset_percent??e.offsetPct??e.offset_pct),n=Or(e.offsetPx??e.offset_px??e.offsetPixels??e.offset_pixels),i=Or(e.xPercent??e.x_percent??e.xPct??e.x_pct??e.horizontalPercent??e.horizontal_percent??e.x),a=Or(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&&a===void 0))return {side:o,offsetPercent:r,offsetPx:n,xPercent:i,yPercent:a}},Qa=(e,t,o)=>{if(!o)return;let r=Wr(e),n=zr(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 a of i){let s=gl(a);if(s)return s}},bl=(e,t)=>{let o=e.type?.value??e.type?.label??e.layout?.type??void 0,r=Za(e,o),n=qa(o,r),i=Ka(e,n);return {label:e.name,face:Ya(e),group:i,type:n,cableType:Ja(o),connected:!!(e.connected_endpoint||e.cable),connectorType:r,position:Qa(e,void 0,t)}},ml=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)}),hl=(e,t)=>{let{includePortPositions:o=false,mapInterfaceToPort:r}=t,n=[];return ml(e.interfaces??[]).forEach((a,s)=>{let c=r?r({device:e,iface:a,index:s}):bl(a,o);if(!c)return;let l=c.type??a.type?.value??a.type?.label??void 0,g=Za(a,l,c.connectorType),f=qa(l,g),p=Ya(a,c.face),u=Ka(a,f,c.group);n.push({id:c.id,label:c.label??a.name,face:p,group:u,connected:c.connected??!!(a.connected_endpoint||a.cable),type:f,cableType:Ja(c.cableType??a.type?.value??a.type?.label??void 0),connectorType:g,position:Qa(a,c,o)});}),n},es=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}}),ts=(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 r=hl(e,t);r.length>0&&(o.ports=r);}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}},os=e=>({id:`cable-${e.id}`,source:ja(e.termination_a.device),target:ja(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}}),yl=(e,t={})=>{let o=[],r=[],n=new Map;return e.racks.forEach(i=>{o.push(es(i));}),e.devices.forEach(i=>{let a=ts(i,t);o.push(a),n.set(i.name,a.id);}),e.cables.forEach(i=>{let a=os(i),s=(typeof i.termination_a.device.id=="number"?`device-${i.termination_a.device.id}`:void 0)??n.get(i.termination_a.device.name)??a.source,c=(typeof i.termination_b.device.id=="number"?`device-${i.termination_b.device.id}`:void 0)??n.get(i.termination_b.device.name)??a.target;r.push({...a,source:s,target:c});}),{nodes:o,edges:r}},wl=(e,t)=>{let o=new Map,r=new Set;return e.filter(i=>i.position!==null).sort((i,a)=>(i.position||0)-(a.position||0)).forEach(i=>{i.position&&(o.set(i.id,i.position),r.add(i.position));}),o};function Ur(e){let{items:t,checkOutOfBounds:o,checkConflicts:r}=e,n=[],i=[];for(let a of t){let s=o(a);s&&!s.isValid&&s.error&&i.push(s.error);}for(let a=0;a<t.length;a++){let s=t[a];for(let c=a+1;c<t.length;c++){let l=t[c],g=r(s,l);g&&g.hasConflict&&g.conflict&&n.push(g.conflict);}}return {isValid:n.length===0&&i.length===0,conflicts:n,outOfBounds:i}}var vo=class extends Error{constructor(o,r,n,i,a){super(`Device placement conflict: ${r} at U${n}-${n+i-1} in rack ${o}${a?` conflicts with ${a}`:""}`);this.rackId=o;this.deviceId=r;this.uPosition=n;this.uHeight=i;this.conflictWith=a;this.name="DevicePlacementError";}};function di(e,t={}){let o=Ie(e);return Ur({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,a=r.unit+r.height-1,s=n.unit,c=n.unit+n.height-1;if(i<=c&&a>=s){if(o){let l=Be(r),g=Be(n);if(!ar(l,g))return null}return {hasConflict:true,conflict:{deviceId:r.id,uPosition:r.unit,uHeight:r.height,conflictWith:n.id}}}return null}})}function rs(e,t,o={}){let{deviceTypeMapping:r={}}=o,n=r[e.type]||"device",i=bo(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,portGroups:e.portGroups,rearPortGroups:e.rearPortGroups,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 xl(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,rackWidthPx:e.rackWidthPx,rackLayout:e.rackLayout,rackFaceGapPx:e.rackFaceGapPx}}}function Nl(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let a of e){let s=di(a,t);if(!s.isValid&&o==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new vo(a.id,s.conflicts[0]?.deviceId||s.outOfBounds[0]?.deviceId||"unknown",s.conflicts[0]?.uPosition||s.outOfBounds[0]?.uPosition||1,s.conflicts[0]?.uHeight||s.outOfBounds[0]?.uHeight||1)}}for(let a of e){let s=xl(a);n.push(s);for(let c of a.devices)try{let l=rs(c,s,t);i.push(l);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=ur(s,{id:c.id,data:{label:c.name,uHeight:c.height,mountMode:Be(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=rs(f,s,t);i.push(p);}else throw new vo(a.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function kl(e){let t=[],o=e.filter(r=>r.type==="rack");for(let r of o){let i=e.filter(a=>Do(a.type)&&a.parentId===r.id).map(a=>({id:a.id,name:a.data.label,unit:a.data.uPosition||1,height:a.data.uHeight||1,type:a.data.deviceType||"server",width:a.data.width==="full"||a.data.width==="half"?a.data.width:void 0,ports:Array.isArray(a.data.ports)?a.data.ports:void 0,portGroups:Array.isArray(a.data.portGroups)?a.data.portGroups:void 0,rearPortGroups:Array.isArray(a.data.rearPortGroups)?a.data.rearPortGroups:void 0,connections:a.data.connections,frontImageUrl:a.data.frontImageUrl,rearImageUrl:a.data.rearImageUrl,frontImageAttribution:a.data.frontImageAttribution,rearImageAttribution:a.data.rearImageAttribution,imageFit:a.data.imageFit,imagePosition:a.data.imagePosition,imageRepeat:a.data.imageRepeat,stretchToFit:a.data.stretchToFit,mountMode:Be(a.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 Pl(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 Cl(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!di({...i,devices:[...i.devices,o]},r).isValid)throw new vo(t,o.id,o.unit,o.height);return {...i,devices:[...i.devices,o]}})}function vl(e,t,o){return e.map(r=>r.id!==t?r:{...r,devices:r.devices.filter(n=>n.id!==o)})}var Ro=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 ci(e,t={}){return Ur({items:e.splices,checkOutOfBounds:o=>o.holder<1||o.holder>Wt?{isValid:false,error:{spliceId:o.id,holder:o.holder,max:Wt}}:null,checkConflicts:(o,r)=>o.holder===r.holder?{hasConflict:true,conflict:{spliceId:o.id,holder:o.holder,conflictWith:r.id}}:null})}function ns(e,t){let o=e.mode==="ribbon",r=Xo(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 Rl(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Tl(e,t={}){let{conflictPolicy:o="strict",validatePlacements:r=true}=t,n=[],i=[];if(r)for(let a of e){let s=ci(a,t);if(!s.isValid&&o==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new Ro(a.id,s.conflicts[0]?.spliceId||s.outOfBounds[0]?.spliceId||"unknown",s.conflicts[0]?.holder||s.outOfBounds[0]?.holder||1)}}for(let a of e){let s=Rl(a);n.push(s);for(let c of a.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];Uo(s,p,c.holder,u)||(l=Go(s,p,u,c.holder));}let g=l!==c.holder?{...c,holder:l}:c,f=ns(g,s);i.push(f);}catch(l){if(o==="strict")throw l;if(o==="nearest"){let g=[...n,...i],f=Go(s,{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=ns(p,s);i.push(u);}else throw new Ro(a.id,c.id,c.holder)}}}return n.push(...i),n}function Sl(e){let t=[],o=e.filter(r=>r.type==="splice-tray");for(let r of o){let i=e.filter(a=>a.type==="splice"&&a.parentId===r.id).map(a=>({id:a.id,name:a.data.label,holder:a.data.holderPosition||1,lossDb:a.data.lossDb,mode:a.data.mode||"single",ribbonFiberIds:a.data.ribbonFiberIds}));t.push({id:r.id,name:r.data.label,position:r.position,splices:i});}return t}function Il(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 El(e,t,o,r={}){let{conflictPolicy:n="strict"}=r;return e.map(i=>{if(i.id!==t)return i;if(n==="strict"&&!ci({...i,splices:[...i.splices,o]},r).isValid)throw new Ro(t,o.id,o.holder);return {...i,splices:[...i.splices,o]}})}function Fl(e,t,o){return e.map(r=>r.id!==t?r:{...r,splices:r.splices.filter(n=>n.id!==o)})}var is=2;var be=e=>typeof e=="string"?e.trim():"",yt=e=>{if(typeof e=="number"&&Number.isFinite(e))return e},Hl=e=>{let t=be(e).toUpperCase();if(t==="C13"||t==="C14"||t==="C19"||t==="C20"||t==="AC")return t},Dl=(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"},_l=e=>{if(e==="power_c13")return "C13";if(e==="power_c19")return "C19";if(e==="power_ac")return "AC"},Ml=e=>e.toLowerCase().replace(/_/g,"-").trim(),$l=e=>e>=1?"rackable":"zero-u",Al=e=>(e??"").toLowerCase()==="half"?"half":"full",Ll=(e,t,o,r)=>{let n=r.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase();return `${e}-b${t}-${n||`p${o}`}`},as=(e,t)=>`${e}-${t}`.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function Bl(e){let t=[],o=be(e.manufacturer),r=be(e.model),n=be(e.role)||be(e.deviceType)||be(e.device_type)||"device",i=yt(e.uHeight)??yt(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 a=be(e.id)||be(e.slug)||as(o,r)||"unknown",s=be(e.slug)||as(o,r)||a,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:be(p.frontPortId)||be(p.front_port_id),rearPortId:be(p.rearPortId)||be(p.rear_port_id)}));return {id:a,slug:s,manufacturer:o,model:r,role:n,uHeight:i,width:be(e.width)||void 0,frontBlocks:c,rearBlocks:l,rawLinks:f,frontImageUrl:be(e.frontImageUrl)||be(e.front_image_url)||void 0,rearImageUrl:be(e.rearImageUrl)||be(e.rear_image_url)||void 0,frontImageAttribution:be(e.frontImageAttribution)||void 0,rearImageAttribution:be(e.rearImageAttribution)||void 0,tags:Array.isArray(e.tags)?e.tags.map(be).filter(Boolean):[],sourceRepository:be(e.sourceRepository)||be(e.source_repository)||void 0,sourcePath:be(e.sourcePath)||be(e.source_path)||void 0,issues:t}}function ss(e,t,o){let r=be(e.name)||`Block ${o+1}`,i=(Array.isArray(e.ports)?e.ports:[]).map((a,s)=>{let c=be(a.label)||be(a.name)||`Port ${s+1}`,l=Hl(a.connectorType??a.connector_type),g=Dl(be(a.type),l),f=l??_l(g),u={id:be(a.id)||Ll(t,o,s,c),label:c,type:g,connectorType:f};if(a.position){let y=a.position,h=be(y.side),w={},k=false;h&&["top","right","bottom","left"].includes(h)&&(w.side=h,k=true);let v=yt(y.offsetPercent)??yt(y.offset_percent);v!==void 0&&(w.offsetPercent=v,k=true);let C=yt(y.offsetPx)??yt(y.offset_px);C!==void 0&&(w.offsetPx=C,k=true);let R=yt(y.xPercent)??yt(y.x_percent);R!==void 0&&(w.xPercent=R,k=true);let x=yt(y.yPercent)??yt(y.y_percent);x!==void 0&&(w.yPercent=x,k=true),k&&(u.position=w);}return u});return {name:r,ports:i}}function Ol(e){let t=[],o=Ml(e.role),r=e.uHeight,n=$l(r),i=Al(e.width),a=e.frontBlocks.map((c,l)=>ss(c,"front",l)),s=e.rearBlocks.map((c,l)=>ss(c,"rear",l));return {role:o,mountClass:n,uHeight:r,width:i,frontFace:{portBlocks:a,imageUrl:e.frontImageUrl,imageAttribution:e.frontImageAttribution},rearFace:{portBlocks:s,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 zl(e){let t=[],{front:o,rear:r}=Wl(e.frontFace,e.rearFace),n=e.role;return (!n||n==="device")&&[...o.portBlocks,...r.portBlocks].some(a=>a.ports.some(s=>s.type&&s.type.startsWith("power")))&&e.mountClass==="zero-u"&&(n="pdu"),{frontFace:o,rearFace:r,mountClass:e.mountClass,role:n,issues:t}}function Zo(e){return e.portBlocks.reduce((t,o)=>t+o.ports.length,0)}function Ul(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),a=e.rearBlocks.reduce((u,y)=>u+(Array.isArray(y.ports)?y.ports.length:0),0),s=Zo(t.frontFace),c=Zo(t.rearFace);s!==i&&o.push({severity:"error",code:"FRONT_PORT_COUNT_MISMATCH",message:`Front port count mismatch: raw=${i}, parsed=${s}`,path:"faces.front"}),c!==a&&o.push({severity:"error",code:"REAR_PORT_COUNT_MISMATCH",message:`Rear port count mismatch: raw=${a}, 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:s,rear:c}}}function Vl(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 Gl(e){let t=Bl(e),o=Ol(t),r=zl(o),n=Ul(t,r);return n.issues.push(...t.issues,...o.issues,...r.issues),n.valid?{template:Vl(t,o,r),report:n}:{template:null,report:n}}function Xl(e){return Zo(e)}function jl(e,t,o){let r=[],n=Zo(e.faces.front),i=Zo(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
+ export{ic as COUPLERS_PER_PANEL,Er as COUPLER_SLOT_HEIGHT_PX,ac as COUPLER_WIDTH_PX,$n as CableNode,Kn as ClosureNode,Bn as CouplerNode,ho as DeviceNode,vo as DevicePlacementError,ni as DiagramErrorBoundary,_i as FIBER_COLORS_12,gr as FiberEdge,cn as FiberNode,sl as FibreCableWithTubesExpanded,nl as FibreFlowMap,qn as FibreSplitNode,Ho as HANDLE_EXTENSION_PX,Ln as MultiTubeCableNode,ri as NetworkDiagram,la as PANEL_BORDER_WIDTH,no as PANEL_HEADER_HEIGHT,Ir as PANEL_HEIGHT_PX,ro as PANEL_PADDING,ua as PANEL_TUBE_TRAY_SPACING,Sr as PANEL_WIDTH_PX,fn as POWER_CONNECTORS,Xn as PatchPanelNode,un as PowerEdge,Ct as RACK_HEADER_HEIGHT,on as RACK_WIDTH_PX,dn as RackNode,Tn as SpliceNode,Ro as SplicePlacementError,Hn as SpliceTrayNode,is as TEMPLATE_SCHEMA_VERSION,Dn as TubeNode,Ke as U_HEIGHT_PX,Cn as VerticalPDU,Gi as Width,Cl as addDeviceToRack,El as addSpliceToTray,ze as baseColorFor,Nl as buildNodesFromRackConfig,Tl as buildNodesFromSpliceConfig,Ri as buildPortBlocksFromPorts,Un as calculateClosureDimensions,dc as calculateCouplerRightX,lc as calculateCouplerSlotSpacing,wa as calculateCouplerSpacing,bo as calculateDevicePositionFromU,zn as calculatePanelDimensions,ha as calculateSlotPositionFromY,qd as calculateSplicePositionFromNumber,wl as calculateUPositions,ya as calculateYFromSlotPosition,Xl as countTemplateFacePorts,Jn as createNetworkDiagramStore,kl as createRackConfigFromNodes,Sl as createSpliceConfigFromNodes,ln as fiberSolidOrStriped,Ar as findNearestRack,Go as findNextAvailableHolderPosition,ur as findNextAvailableUPosition,cl as generateLayout,Xi as getConnectorConfig,Wn as getCouplerDimensions,it as getDefaultDeviceView,gn as getDeviceConnectorType,qt as getFiberColor,nn as getFrontPortBlocks,ma as getInnerContentWidth,mr as getPDUPortType,sc as getPanelHeight,ba as getPanelWidth,Ot as getPowerPortStyle,va as getRackBounds,an as getRearPortBlocks,Je as getResolvedPortBlocks,bt as getStatusColor,pa as getTrayDimensions,Fr as getTubeDimensions,Ti as hasFrontPorts,Si as hasRearPorts,Xa as inventoryCableToNetworkEdge,Ga as inventoryDeviceToNetworkNode,Va as inventoryRackToNetworkNode,dl as inventoryToNetworkDiagram,cd as isHighPowerConnector,Ra as isPointInRack,Zt as isStriped,jt as isUPositionAvailable,os as netboxCableToNetworkEdge,ts as netboxDeviceToNetworkNode,es as netboxRackToNetworkNode,yl as netboxToNetworkDiagram,Gl as parseNetboxTemplate,vl as removeDeviceFromRack,Fl as removeSpliceFromTray,Me as replaceEdge,cc as snapToCouplerPosition,In as snapToSplicePosition,lr as snapToUPosition,Di as updateDeviceUPosition,Pl as updateDeviceUPositionInSchema,Il as updateSpliceHolderPosition,ti as useDiagramEdges,ei as useDiagramNodes,wc as useNetworkDiagram,Vs as validateAndSnapDevice,di as validateRackDevicePlacements,jl as validateRenderFidelity,ci as validateSplicePlacements};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map