@mp70/react-networks 0.1.4-alpha → 0.1.6-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var Lt=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Lt__default=/*#__PURE__*/_interopDefault(Lt);var Pt=()=>"bottom-up",se=e=>e.data.uNumberingDirection||Pt(),xe=(e,o,t)=>t==="bottom-up"?o-e+1:e,Ne=(e,o,t)=>t==="bottom-up"?o-e+1:e;var Te=(e,o,t,i)=>{if(!e.parentId||e.parentId!==o.id)return t;let r=e.data.uHeight||1,a=o.data.uHeight||42,c=se(o),s=60,d=t.y-s,f=Math.round(d/20)+1,h;c==="bottom-up"?h=xe(f,a,c)-r+1:h=xe(f,a,c);let m=a-r+1,k=Math.max(1,Math.min(m,h));if(c==="top-down"&&h<=1&&(k=1),!Ie(o,e,k,i)){let P=ke(o,e,i,k);P!==k&&(k=P);}let v;if(c==="bottom-up"){let P=k+r-1,$=Ne(P,a,c);v=s+($-1)*20-1;}else {let P=Ne(k,a,c);v=s+(P-1)*20-1;}return {x:t.x,y:v,uPosition:k}},Ie=(e,o,t,i)=>{let r=o.data.uHeight||1,a=e.data.uHeight||42;if(t<1||t+r-1>a)return false;let c=i.filter(s=>s.type==="device"&&s.parentId===e.id&&s.id!==o.id);for(let s of c){let d=s.data.uPosition||1,f=s.data.uHeight||1,h=t,m=t+r-1,k=d,v=d+f-1;if(h<=v&&m>=k)return false}return true},ke=(e,o,t,i=1)=>{let r=o.data.uHeight||1,a=e.data.uHeight||42;for(let c=i;c<=a-r+1;c++)if(Ie(e,o,c,t))return c;return 1},ue=(e,o,t=1)=>{let i=60,r=se(e),a=e.data.uHeight||42,c=Ne(o,a,r),s;if(r==="bottom-up"){let d=o+t-1,f=Ne(d,a,r);s=i+(f-1)*20-1;}else s=i+(c-1)*20-1;return {x:0,y:s}},Qe=(e,o,t)=>{let i=e.data.uHeight||1,r=ue(o,t,i);return {...e,position:r,data:{...e.data,uPosition:t}}},Dt=(e,o)=>{let t=e.data.uPosition||1,i=e.data.uHeight||1,r=o.data.uHeight||42,a=Math.max(1,Math.min(r-i+1,t));return a!==t?Qe(e,o,a):e};function Z(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var Ue=({data:e,selected:o,id:t,onViewChange:i,onRackFaceChange:r,isDragOver:a=false})=>{let{label:c,ports:s=0,status:d="active",uHeight:f=42,face:h="front",customHeaderText:m}=e,{getNodes:k,setNodes:v}=reactflow.useReactFlow(),P=k(),[$,b]=Lt.useState(true),T=()=>{let D=se({data:e})==="bottom-up"?"top-down":"bottom-up";v(p=>p.map(l=>l.id===t?{...l,data:{...l.data,uNumberingDirection:D}}:l));},B=()=>{let u=h==="front"?"rear":"front";r?(r(t,u),i&&P.filter(p=>p.parentId===t).forEach(p=>{i(p.id,u);})):i?P.filter(p=>p.parentId===t).forEach(p=>{i(p.id,u);}):v(D=>D.map(p=>p.id===t?{...p,data:{...p.data,face:u}}:p.parentId===t?{...p,data:{...p.data,view:u}}:p));},M=()=>{let u=[],D=60,p=se({data:e});for(let l=1;l<=f;l++){let I=D+(l-1)*20-4,U=xe(l,f,p);u.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${I}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:U},l));}return u};return jsxRuntime.jsxs("div",{className:`rack-node ${o?"selected":""} ${a?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${Z(d)}`,borderRadius:"8px",padding:0,width:`${300}px`,height:`${60+f*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:a?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:c}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[m?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:m}):jsxRuntime.jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",f,"U \u2022 ",h]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:u=>{u.stopPropagation();},onMouseDown:u=>{u.stopPropagation();},onClick:u=>{u.stopPropagation(),u.preventDefault(),b(!$);},style:{background:$?"#10b981":"#374151",color:$?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${$?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:u=>{u.stopPropagation();},onMouseDown:u=>{u.stopPropagation();},onClick:u=>{u.stopPropagation(),u.preventDefault(),T();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch U numbering to ${se({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:se({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsxRuntime.jsx("button",{onPointerDown:u=>{u.stopPropagation();},onMouseDown:u=>{u.stopPropagation();},onClick:u=>{u.stopPropagation(),u.preventDefault(),B();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${h==="front"?"rear":"front"} view`,children:h==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${f*20}px`,overflow:"hidden"}}),$&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:M()})]})};var _e=({data:e,selected:o})=>{let{label:t,status:i="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${Z(i)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:t})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:Z(i),borderRadius:"50%"}})]})};var Me=({id:e,sourceX:o,sourceY:t,targetX:i,targetY:r,sourcePosition:a,targetPosition:c,data:s,selected:d,style:f={}})=>{let[h,m,k]=reactflow.getBezierPath({sourceX:o,sourceY:t,sourcePosition:a,targetX:i,targetY:r,targetPosition:c}),{bandwidth:v,length:P,color:$="#00FFFF"}=s||{},b={...f,stroke:$,strokeWidth:d?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:h,style:b}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:d&&s&&(v||P)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${m}px,${k}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${$}`,pointerEvents:"none",zIndex:9999},children:[v&&jsxRuntime.jsx("div",{children:v}),P&&jsxRuntime.jsxs("div",{children:[P,"m"]})]})})]})};var ze=({id:e,sourceX:o,sourceY:t,targetX:i,targetY:r,sourcePosition:a,targetPosition:c,style:s={},data:d,markerEnd:f})=>{let[h]=reactflow.getBezierPath({sourceX:o,sourceY:t,sourcePosition:a,targetX:i,targetY:r,targetPosition:c}),m=d?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:h,markerEnd:f,style:(()=>{let v={stroke:d?.color||"#f59e0b",strokeWidth:m==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return m==="C19"?{...v,strokeDasharray:"none"}:{...v,strokeDasharray:"6,3"}})()})};var et=(t=>(t.FULL="full",t.HALF="half",t))(et||{});var Be={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1}};function ge(e){let o=Be[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let t=o.amperage===16,i=t?12:8,r=t?10:5,a=t?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:i,height:r,color:o.color,borderColor:o.borderColor,fontSize:t?"3px":"4px",...a}}function De(e){let o=Be[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function At(e){return De(e).amperage===16}function We(e){return e%10<8?"C13":"C19"}function Re(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Oe=({data:e,selected:o})=>{let{label:t,status:i="active",deviceType:r="server",manufacturer:a,role:c,uHeight:s=1,width:d="full",ports:f=[],rearPorts:h=[],view:m}=e,k=m||(h.length>0&&f.length===0?"rear":"front"),v={};v["net-top"]="front",v["net-bottom"]="front",f.length>0&&f.forEach(u=>{u.ports.forEach(D=>{let p=D.type?.includes("power")?D.label:`${u.name}-${D.label}`;v[p]="front";});}),v["pwr-left-1"]="rear",v["pwr-left-2"]="rear",v["net-right-1"]="rear",v["net-right-2"]="rear",h.length>0&&h.forEach(u=>{u.ports.forEach(D=>{let p=D.type?.includes("power")?D.label:`${u.name}-${D.label}`;v[p]="rear";});});let P=s*20,$=d==="half"?"150px":"304px",b=d==="half"?"150px":void 0,T=(u,D)=>{let p=[];if(u.length===0)return p;let l=Math.max(4,Math.floor(P*.4)),I=Math.max(2,Math.floor(P*.2));return u.forEach((U,C)=>{U.ports.forEach((y,R)=>{let G=!!y.type&&y.type.includes("power");if(D==="front"&&G)return;let A=G?`${y.label}`:`${U.name}-${y.label}`,ee=y.connected,E="#6b7280";if(ee)if(y.type?.includes("power"))E=y.type==="power_c19"?"#fbbf24":"#f59e0b";else if(y.type==="console"||y.type==="mgmt")E="#8b5cf6";else if(y.type==="usb")E="#10b981";else switch(y.cableType){case "smf":E="#fbbf24";break;case "cat6":E="#8b5cf6";break;case "om3":E="#06b6d4";break;case "om4":E="#8b5cf6";break;case "om5":E="#84cc16";break;case "cat5e":E="#3b82f6";break;case "cat6a":E="#ef4444";break;case "cat7":E="#f97316";break;case "fiber":E="#3b82f6";break;case "ethernet":E="#10b981";break;default:E="#10b981";}let W=reactflow.Position.Top,F={width:`${l}px`,height:`${I}px`,background:ee?E:"#6b7280",border:`1px solid ${ee?E:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(D==="front")R%2===0?(W=reactflow.Position.Top,F.transform="translateY(50%)",F.left=`${R/2*(l+2)}px`):(W=reactflow.Position.Bottom,F.transform="translateY(-50%)",F.left=`${(R-1)/2*(l+2)}px`);else if((r?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel")R%2===0?(W=reactflow.Position.Top,F.transform="translateY(50%)",F.left=`${R/2*(l+2)}px`):(W=reactflow.Position.Bottom,F.transform="translateY(-50%)",F.left=`${(R-1)/2*(l+2)}px`);else if(y.type?.includes("power")){W=reactflow.Position.Left,F.transform="translateX(50%)";let we=P<=20?10:20,de=P<=20?30:50;F.top=`${we+R*de}%`;let He=Re(t),ae=ge(He);F={...F,width:`${ae.width}px`,height:`${ae.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:ae.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:ae.borderRadius,clipPath:ae.clipPath};}else W=reactflow.Position.Right,F.transform="translateX(-50%)",F.top=`${25+R*50}%`;let ye=(r?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",oe;if(G)oe="target";else if(r==="switch"||r==="router")oe="source",p.push(jsxRuntime.jsx(reactflow.Handle,{id:`${A}-target`,type:"target",position:W,style:F,title:`${U.name} - ${y.label} (input) ${ee?"(connected)":"(disconnected)"}`},`${A}-target`));else if(ye){oe=D==="rear"?"source":"target";let ie=D==="rear"?"target":"source";p.push(jsxRuntime.jsx(reactflow.Handle,{id:`${A}-${ie}`,type:ie,position:W,style:F,title:`${U.name} - ${y.label} (${ie}) ${ee?"(connected)":"(disconnected)"}`},`${A}-${ie}`));}else oe=ee?"source":"target";p.push(jsxRuntime.jsx(reactflow.Handle,{id:A,type:oe,position:W,style:F,title:`${U.name} - ${y.label} ${ee?"(connected)":"(disconnected)"}`,children:G?R+1:void 0},A));});}),p},B=()=>{let u=[],D=Math.max(4,Math.floor(P*.4)),p=Math.max(2,Math.floor(P*.2));if(k==="front"){if(f.length>0)return T(f,"front");if(r==="switch"&&(t.toLowerCase().includes("agg")||t.toLowerCase().includes("core")||c==="agg"||c==="core"))return M();u.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${D}px`,height:`${p}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),u.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${D}px`,height:`${p}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(k==="rear"){if(h.length>0)return T(h,"rear");let l=r==="switch",U=(r?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!U){let C=Re(t),y=De(C),R=ge(C),G=P<=20?"10%":"25%";u.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:G,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`Power Port 1 (${y.type}) - ${y.voltage}V, ${y.amperage}A`,children:"1"},"pwr-1"));let A=P<=20?"50%":"75%";u.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:A,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`Power Port 2 (${y.type}) - ${y.voltage}V, ${y.amperage}A`,children:"2"},"pwr-2"));}!l&&!U&&(u.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${D}px`,height:`${p}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"25%"},title:"Network Port 1 (Right)"},"net-right-1")),u.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${D}px`,height:`${p}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"75%"},title:"Network Port 2 (Right)"},"net-right-2")));}return u},M=()=>{let u=[],D=Math.max(10,Math.floor(P*.45)),p=Math.max(5,Math.floor(P*.25));for(let l=1;l<=16;l++){let I=jsxRuntime.jsx(reactflow.Handle,{id:`port-${l}`,type:"source",position:reactflow.Position.Top,style:{width:`${D}px`,height:`${p}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(l-1)*(D+2)}px`},title:`Port ${l}`},`port-${l}`);u.push(I);}for(let l=17;l<=32;l++){let I=l-16,U=jsxRuntime.jsx(reactflow.Handle,{id:`port-${l}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${D}px`,height:`${p}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${(I-1)*(D+2)}px`},title:`Port ${l}`},`port-${l}`);u.push(U);}for(let l=1;l<=4;l++){let I=Math.max(4,Math.floor(P*.3)),U=Math.max(3,Math.floor(P*.15));u.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${l}`,type:"source",position:reactflow.Position.Right,style:{width:`${I}px`,height:`${U}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${l}`},`uplink-${l}`));}return u};return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${Z(i)}`,borderRadius:"2px",padding:"0px",width:$,...b&&{left:b},height:`${P}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),s>1&&jsxRuntime.jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:a})]}),s>1&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"1px",right:"1px",background:"#374151",color:"#9ca3af",padding:"1px 2px",borderRadius:"1px",fontSize:"6px",lineHeight:"1"},children:[s,"U"]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:Z(i),borderRadius:"50%"}}),B()]})};var Ve=({data:e,selected:o})=>{let{label:t,status:i="active",heightCm:r=100,powerPorts:a=36,widthPx:c=15,mgmt_unit:s}=e,d=r*4.2,f=()=>{let k=Math.ceil(a/10),v=Array(10).fill(0).map((p,l)=>l<8?"10A":"16A");for(let p=0,l=0;p<k;++p)for(let I=0;I<10&&l<a;++I,++l){v[I];}let T=[],B=15,D=(d-B-3)/(a-9)*.5;for(let p=0;p<a;p++){let l=B-2+D*p,I=`${p+1}`;if(s&&(s==="top"&&p===0||s==="middle"&&p===Math.floor(a/2)||s==="bottom"&&p===a-1)){T.push(h(l));continue}let C=We(p),y=ge(C),R=Math.round((c-y.width)/2-1);T.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:I,style:{position:"absolute",left:`${R}px`,top:`${l-y.height/2}px`,width:`${y.width}px`,height:`${y.height}px`,background:y.color,border:`1px solid ${y.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:y.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:y.borderRadius,clipPath:y.clipPath},title:`Power Port ${p+1} (${C})`,children:p+1},`handle-${I}`));}return T},h=m=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(c-16)/2}px`,top:`${m-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit");return jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${Z(i)}`,borderRadius:"2px",padding:0,width:`${c}px`,height:`${d}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:"20px",display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:t})}),jsxRuntime.jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${d-20}px`,overflow:"hidden"},children:f()})]})};function Mt(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let t=o.edges.some(b=>b.source===e.source&&b.sourceHandle===e.sourceHandle),i=o.edges.some(b=>b.target===e.target&&b.targetHandle===e.targetHandle);if(t)return {valid:false,reason:"Source port is already connected"};if(i)return {valid:false,reason:"Target port is already connected"};let r=e.sourceHandle,a=e.targetHandle,c=o.nodes.find(b=>b.id===e.source),s=o.nodes.find(b=>b.id===e.target),d=(b,T)=>{if(!b)return false;let B=b.startsWith("pwr")||b.startsWith("power"),M=T?.type==="vertical-pdu"&&b!=="mgmt-net-1";return B||M},f=(b,T)=>{if(!b)return false;if(T?.type==="vertical-pdu"&&b==="mgmt-net-1")return true;let B=b.startsWith("net-")||b.startsWith("port-")||b.startsWith("uplink-")||b.includes("Fiber")||b.includes("Ports"),M=/^[A-Z0-9]+-\d+$/.test(b)&&!b.startsWith("pwr")&&!b.startsWith("power");return B||M},h=d(r,c),m=d(a,s),k=f(r,c),v=f(a,s);if(h&&v||m&&k)return {valid:false,reason:"Cannot connect network cable to power port"};if(h&&!m||m&&!h)return {valid:false,reason:"Power ports must connect to power-compatible ports"};let P=c?.type==="vertical-pdu",$=s?.type==="vertical-pdu";if(h||m){let b=P?s:$?c:null,T=P?c:$?s:null;if(b&&T&&o.edges.filter(u=>{let D=d(u.sourceHandle||""),p=d(u.targetHandle||""),l=u.source===b.id||u.target===b.id;return (D||p)&&l}).some(u=>u.source===T.id||u.target===T.id))return {valid:false,reason:"Dual-feed required: connect second power to a different PDU"}}return {valid:true}}function zt(e,o){if(!o)return;let t=o.data??{},i=t.handleSideMap;if(i&&i[e])return i[e];if(e==="net-top"||e==="net-bottom")return "front";if(e==="pwr-left-1"||e==="pwr-left-2"||e==="net-right-1"||e==="net-right-2")return "rear";let r=Array.isArray(t.ports)?t.ports:[],a=Array.isArray(t.rearPorts)?t.rearPorts:[];if(e.startsWith("pwr")||e.includes("power"))return "rear";for(let s of r)for(let d of s.ports||[])if((!!d.type&&String(d.type).includes("power")?d.label:`${s.name}-${d.label}`)===e)return "front";for(let s of a)for(let d of s.ports||[])if((!!d.type&&String(d.type).includes("power")?d.label:`${s.name}-${d.label}`)===e)return "rear"}function je(e={},o={}){let t={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},i=new Set;return {getState:()=>t,setState:m=>{t={...t,...m},i.forEach(k=>k(t));},subscribe:m=>(i.add(m),()=>i.delete(m)),selectEdgeZIndex:m=>{let k=t.nodes.find(D=>D.id===m.target);if(!k||k.type!=="device")return 1e3;let v=k.data?.view||"front",P=zt(m.targetHandle||"",k);if(P)return v===P?1e3:500;let $=(m.targetHandle||"").toString(),b=$.toLowerCase(),T=b.startsWith("pwr")||b.startsWith("power"),B=b.startsWith("net-")||b.startsWith("port-")||b.startsWith("uplink-")||b.includes("fiber")||b.includes("ports"),M=/^[A-Z0-9]+-\d+$/i.test($)&&!b.startsWith("pwr")&&!b.startsWith("power"),u=B||M;return T?v==="rear"?1e3:500:u?v==="front"?1e3:500:1e3},validateConnection:m=>(o.validateConnection||Mt)(m,t),selectNodeById:m=>t.nodes.find(k=>k.id===m),selectConnectedEdges:m=>t.edges.filter(k=>k.source===m||k.target===m)}}function Bt(e){let o=r=>e.subscribe(r),t=()=>e.getState();return Lt.useSyncExternalStore(o,t,t)}function Xe(e){let o=i=>e.subscribe(i),t=()=>e.getState().nodes;return Lt.useSyncExternalStore(o,t,t)}function Ge(e){let o=i=>e.subscribe(i),t=()=>e.getState().edges;return Lt.useSyncExternalStore(o,t,t)}function nt(e){return e.selectEdgeZIndex}function it(e){let o=300,t=(e.data.uHeight||42)*20,i=e.position.x,r=e.position.x+o,a=e.position.y,c=e.position.y+t;return {left:i,right:r,top:a,bottom:c}}function Se(e,o){let t=it(o);return e.x>=t.left&&e.x<=t.right&&e.y>=t.top&&e.y<=t.bottom}function Ce(e,o){let t=null,i=1/0;for(let r of o){if(!Se(e,r))continue;let a=Math.sqrt(Math.pow(e.x-r.position.x,2)+Math.pow(e.y-r.position.y,2));a<i&&(i=a,t=r);}return t}function me(e){let{edges:o,connection:t,edgeType:i,selectEdgeZIndex:r,findBy:a}=e,c=a==="source"?t.sourceHandle:t.targetHandle,s=a==="source"?t.source:t.target;if(!c||!s)return null;let d=o.find(v=>a==="source"?v.source===s&&v.sourceHandle===c:v.target===s&&v.targetHandle===c);if(!d)return null;let f=o.filter(v=>v.id!==d.id),h=reactflow.addEdge(t,f),m=h[h.length-1],k={...m,type:i,zIndex:r({...t,id:m.id,type:i}),style:{...m.style,zIndex:r({...t,id:m.id,type:i})}};return [...h.slice(0,-1),k]}var eo=(e,o,t)=>({rack:i=>jsxRuntime.jsx(Ue,{...i,onViewChange:e,onRackFaceChange:o,isDragOver:t===i.id}),fiber:_e,device:Oe,"vertical-pdu":Ve}),to={fiber:Me,power:ze},oo=({nodes:e,edges:o,initialNodes:t,initialEdges:i,onNodesChange:r,onEdgesChange:a,store:c,debug:s,onNodeClick:d,onEdgeClick:f,onViewChange:h,onRackFaceChange:m,className:k,style:v,alignRacksToBottom:P,colorMode:$="dark",onInit:b,onFlowMethods:T,showDownloadButton:B=false,downloadButtonPosition:M="top-right",downloadButtonText:u="Download Image",downloadButtonStyle:D})=>{let p=Array.isArray(e)&&Array.isArray(o),l=Lt__default.default.useMemo(()=>c||je({nodes:p?e||[]:t||e||[],edges:p?o||[]:i||o||[],debug:s}),[c,p,s]),I=Xe(l),U=Ge(l),[C,y,R]=reactflow.useNodesState(I),[G,A,ee]=reactflow.useEdgesState(U),E=nt(l),W=Lt.useRef(null),{toObject:F,setViewport:Ee,setNodes:ye,setEdges:oe}=reactflow.useReactFlow();Lt.useEffect(()=>{T&&T({toObject:F,setViewport:Ee,setNodes:n=>{ye(n),l.setState({nodes:n});},setEdges:n=>{oe(n),l.setState({edges:n});},toImage:n=>W.current?htmlToImage.toPng(W.current,n):Promise.reject(new Error("ReactFlow wrapper not available"))});},[T,F,Ee,ye,oe,l]);let ie=Lt.useCallback(()=>{if(!W.current){s&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(W.current,{filter:n=>!(n?.classList?.contains("react-flow__minimap")||n?.classList?.contains("react-flow__controls")||n?.classList?.contains("react-flow__attribution")||n?.classList?.contains("download-button")||n?.tagName==="BUTTON"),backgroundColor:$==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(n=>{let g=document.createElement("a");g.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,g.href=n,g.click();}).catch(n=>{s&&console.error("Error downloading image:",n);});},[$,s]),[we,de]=Lt.useState(null),He=Lt.useMemo(()=>eo(h,m,we),[h,m,we]),ae=Lt.useMemo(()=>to,[]),re=Lt.useRef(C);Lt.useEffect(()=>{re.current=C;},[C]);let te=Lt.useRef(G);Lt.useEffect(()=>{te.current=G;},[G]),Lt.useEffect(()=>{y(I);},[I,y]),Lt.useEffect(()=>{A(U);},[U,A]),Lt.useEffect(()=>{p&&l.setState({nodes:e||[]});},[p,e,l]),Lt.useEffect(()=>{p&&l.setState({edges:o||[]});},[p,o,l]),Lt.useEffect(()=>{if(!P||!C||C.length===0)return;let n=C.filter(H=>H.type==="rack");if(n.length===0)return;let g=n.map(H=>{let le=H.data?.uHeight||42,$e=60+le*20;return (H.position?.y||0)+$e}),w=Math.min(...g),N=Math.max(...g);if(N-w<20)return;let x=N,V=C.map(H=>{if(H.type!=="rack")return H;let le=H.data?.uHeight||42,$e=60+le*20,vt=(H.position?.y||0)+$e,Je=x-vt;return Math.abs(Je)<5?H:{...H,position:{x:H.position?.x||0,y:(H.position?.y||0)+Je}}});V.some((H,_)=>H.position!==C[_].position)&&y(V);},[P,C,y]);let q=Lt.useCallback(n=>re.current.find(g=>g.id===n),[]);Lt.useEffect(()=>{A(n=>n.map(g=>{let w=E(g);return {...g,zIndex:w,style:{...g.style,zIndex:w}}}));},[C,A,E]),Lt.useEffect(()=>{let n=C.map(w=>{if(w.type==="device"&&w.parentId&&w.data.uPosition&&(!w.position||w.position.x===0&&w.position.y===0)){let N=q(w.parentId);if(N){let S=ue(N,w.data.uPosition);return {...w,position:S}}}return w});n.some((w,N)=>w.position!==C[N].position)&&y(n);},[C,y,q]);let ft=Lt.useCallback(n=>{let g=n.map(w=>{if(w.type==="position"&&w.position){let N=q(w.id);if(N&&N.type==="device"&&N.parentId){let S=q(N.parentId);if(S){let x=Te(N,S,w.position,re.current);if(x.uPosition!==void 0){let V={...N,data:{...N.data,uPosition:x.uPosition}};y(O=>O.map(H=>H.id===N.id?V:H));}return {...w,position:{x:x.x,y:x.y}}}}if(N&&N.type==="device"&&N.parentId){let S=q(N.parentId);if(S){let x=S;if(!Se(w.position,x)){let V=w.position.x+x.position.x,O=w.position.y+x.position.y,H={...N,parentId:void 0,extent:void 0,data:{...N.data,uPosition:void 0}};return y(_=>_.map(le=>le.id===N.id?H:le)),{...w,position:{x:V,y:O}}}}}}return w});R(g);},[R,y,q]),mt=Lt.useCallback((n,g)=>{de(null);},[]),ht=Lt.useCallback((n,g,w)=>{if(g.type==="device"&&!g.parentId){let N=re.current.filter(x=>x.type==="rack").map(x=>x),S=Ce(g.position,N);de(S?.id??null);}else de(null);},[]),bt=Lt.useCallback((n,g,w)=>{if(g.type==="device"&&!g.parentId){let N=re.current.filter(x=>x.type==="rack").map(x=>x),S=Ce(g.position,N);if(S){let x=g.position.x-S.position.x,V=g.position.y-S.position.y,O={...g,parentId:S.id,extent:"parent",position:{x,y:V},data:{...g.data,uPosition:1}},H=re.current.map(_=>_.id===g.id?O:_);y(H),p||l.setState({nodes:H});}}de(null);},[y,p,l]);Lt.useCallback(n=>{if(!n.source||!n.target||!n.sourceHandle||!n.targetHandle)return {valid:true};let g=n.sourceHandle,w=n.targetHandle,N=te.current.some(x=>x.source===n.source&&x.sourceHandle===g),S=te.current.some(x=>x.target===n.target&&x.targetHandle===w);return N?{valid:false,reason:"Source port is already connected"}:S?{valid:false,reason:"Target port is already connected"}:{valid:true}},[]);let yt=Lt.useCallback(n=>{let g=q(n.source),w=g?.type==="vertical-pdu",N=g?.data,S=g?.type==="device"&&N?.deviceType==="switch",x=!!n.targetHandle&&(n.targetHandle.startsWith("pwr")||n.targetHandle.startsWith("power")),V=!!n.targetHandle&&(n.targetHandle.startsWith("net-")||n.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(n.targetHandle));if(w&&x&&n.target&&n.targetHandle){let _=me({edges:te.current,connection:n,edgeType:"power",selectEdgeZIndex:E,findBy:"target"});if(_){A(_);return}}if(S&&V&&n.target&&n.targetHandle){let _=me({edges:te.current,connection:n,edgeType:"fiber",selectEdgeZIndex:E,findBy:"target"});if(_){A(_);return}}let O=l.validateConnection({source:n.source??null,target:n.target??null,sourceHandle:n.sourceHandle??null,targetHandle:n.targetHandle??null});if(!O.valid){if(w&&n.source&&n.sourceHandle){let _=me({edges:te.current,connection:n,edgeType:x?"power":"fiber",selectEdgeZIndex:E,findBy:"source"});if(_){A(_);return}}if(S&&n.source&&n.sourceHandle){let _=me({edges:te.current,connection:n,edgeType:"fiber",selectEdgeZIndex:E,findBy:"source"});if(_){A(_);return}}s&&console.warn(`Connection rejected: ${O.reason}`);return}let H={...n,type:w&&x?"power":"fiber",zIndex:E({...n,id:"temp-id"})};A(_=>reactflow.addEdge(H,_));},[A,l,E,q,s]),wt=Lt.useCallback((n,g)=>{if((n.metaKey||n.ctrlKey)&&g.type==="device"){let N=g.data||{},S=N.view||(Array.isArray(N.rearPorts)&&N.rearPorts.length>0?"rear":"front"),x=S==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${g.id} from ${S} to ${x}`),h&&h(g.id,x),d&&d(g);}else d&&d(g);},[h,d,s]),xt=Lt.useCallback(()=>{},[]),Nt=Lt.useCallback((n,g)=>{f&&f(g);},[f]),[J,qe]=Lt.useState(null);reactflow.useOnSelectionChange({onChange:({nodes:n})=>{if(n&&n.length===1){let g=n[0];qe(g),d&&d(g);}else qe(null),d&&d(null);}});let kt=Lt.useCallback(()=>{if(!J)return;let n=q(J.id);if(n){if(n.type==="rack"){let N=((n.data||{}).face||"front")==="front"?"rear":"front";m?m(n.id,N):y(S=>S.map(x=>x.id===n.id?{...x,data:{...x.data,face:N}}:x.parentId===n.id?{...x,data:{...x.data,view:N}}:x));return}if(n.type==="device"){let g=n.data||{},w=Array.isArray(g.rearPorts)&&g.rearPorts.length>0,N=Array.isArray(g.ports)&&g.ports.length>0,x=(g.view||(w&&!N?"rear":"front"))==="front"?"rear":"front";h?h(n.id,x):y(V=>V.map(O=>O.id===n.id?{...O,data:{...O.data,view:x}}:O));}}},[J,q,m,h,y]);return jsxRuntime.jsxs("div",{ref:W,className:`${k||""} ${$==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",...v},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:C,edges:G,onNodesChange:n=>{ft(n),p?r&&r(re.current):l.setState({nodes:re.current});},onEdgesChange:n=>{ee(n),p?a&&a(te.current):l.setState({edges:te.current});},onConnect:yt,onNodeClick:wt,onNodeDoubleClick:xt,onNodeDragStart:mt,onNodeDrag:ht,onNodeDragStop:bt,onEdgeClick:Nt,onInit:b,nodeTypes:He,edgeTypes:ae,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:true,nodesConnectable:true,elementsSelectable:true,selectNodesOnDrag:false,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{}),jsxRuntime.jsx(reactflow.Controls,{}),jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),B&&jsxRuntime.jsx("button",{className:"download-button",onClick:ie,style:{position:"absolute",top:M.includes("top")?"10px":"auto",bottom:M.includes("bottom")?"10px":"auto",right:M.includes("right")?"10px":"auto",left:M.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:"pointer",transition:"all 0.2s ease",...D},children:u}),J&&(J.type==="rack"||J.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:n=>{n.preventDefault(),kt();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let n=J.data;if(J.type==="rack")return (n?.face||"front")==="front"?"Switch to rear":"Switch to front";{let g=Array.isArray(n?.rearPorts)&&n.rearPorts.length>0,w=Array.isArray(n?.ports)&&n.ports.length>0;return (n?.view||(g&&!w?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let n=J.data;if(J.type==="rack")return (n?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let g=Array.isArray(n?.rearPorts)&&n.rearPorts.length>0,w=Array.isArray(n?.ports)&&n.ports.length>0;return (n?.view||(g&&!w?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},ro=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(oo,{...e})});var lt=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}}),pt=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}}),ut=e=>{let o=r=>{if(!r)return;if(typeof r=="string")return r;let a=r.device;return typeof a=="object"&&a?a.id:a},t=o(e.termination_a),i=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${t}`,target:`device-${i}`,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}}},no=e=>{let o=[],t=[];return e.racks.forEach(i=>o.push(lt(i))),e.devices.forEach(i=>o.push(pt(i))),e.cables.forEach(i=>t.push(ut(i))),{nodes:o,edges:t}},io=e=>{let o=e.filter(r=>r.type==="rack"),t=e.filter(r=>r.type==="device"),i=e.filter(r=>!["rack","device"].includes(r.type));return o.forEach((r,a)=>{r.position={x:a*300,y:100};}),t.forEach(r=>{if(r.parentId){let a=o.find(c=>c.id===r.parentId);if(a){let c=r.data.uPosition||1,s=r.data.uHeight||1;r.position={x:a.position.x+50,y:a.position.y+c*20-s*10};}}else r.position={x:Math.random()*400+100,y:Math.random()*200+50};}),i.forEach((r,a)=>{r.position={x:a*150+100,y:300};}),e};var he=class extends Error{constructor(t,i,r,a,c){super(`Device placement conflict: ${i} at U${r}-${r+a-1} in rack ${t}${c?` conflicts with ${c}`:""}`);this.rackId=t;this.deviceId=i;this.uPosition=r;this.uHeight=a;this.conflictWith=c;this.name="DevicePlacementError";}};function Ke(e,o={}){let t=[],i=[];for(let r of e.devices)r.unit+r.height-1>e.units&&i.push({deviceId:r.id,uPosition:r.unit,uHeight:r.height,rackUHeight:e.units});for(let r=0;r<e.devices.length;r++){let a=e.devices[r],c=a.unit,s=a.unit+a.height-1;for(let d=r+1;d<e.devices.length;d++){let f=e.devices[d],h=f.unit,m=f.unit+f.height-1;c<=m&&s>=h&&t.push({deviceId:a.id,uPosition:a.unit,uHeight:a.height,conflictWith:f.id});}}return {isValid:t.length===0&&i.length===0,conflicts:t,outOfBounds:i}}function gt(e,o,t={}){let{deviceTypeMapping:i={}}=t,r=i[e.type]||"device",a=ue(o,e.unit,e.height);return {id:e.id,type:r,position:a,parentId:o.id,extent:"parent",data:{label:e.name,status:"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections}}}function ao(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[]}}}function so(e,o={}){let{conflictPolicy:t="strict",validatePlacements:i=true}=o,r=[],a=[];if(i)for(let c of e){let s=Ke(c,o);if(!s.isValid&&t==="strict"){let d=[];throw s.conflicts.forEach(f=>{d.push(`Device ${f.deviceId} at U${f.uPosition}-${f.uPosition+f.uHeight-1} conflicts with ${f.conflictWith}`);}),s.outOfBounds.forEach(f=>{d.push(`Device ${f.deviceId} at U${f.uPosition}-${f.uPosition+f.uHeight-1} exceeds rack height (${f.rackUHeight}U)`);}),new he(c.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 c of e){let s=ao(c);r.push(s);for(let d of c.devices)try{let f=gt(d,s,o);a.push(f);}catch(f){if(t==="strict")throw f;if(t==="nearest"){let h=ke(s,{id:d.id,data:{label:d.name,uHeight:d.height}},a,d.unit);if(h!==d.unit){console.warn(`Device ${d.id} moved from U${d.unit} to U${h} due to conflict`);let m={...d,unit:h},k=gt(m,s,o);a.push(k);}else throw new he(c.id,d.id,d.unit,d.height)}}}return r.push(...a),r}function co(e){let o=[],t=e.filter(i=>i.type==="rack");for(let i of t){let a=e.filter(c=>c.type==="device"&&c.parentId===i.id).map(c=>({id:c.id,name:c.data.label,unit:c.data.uPosition||1,height:c.data.uHeight||1,type:c.data.deviceType||"server",width:c.data.width,ports:c.data.ports,connections:c.data.connections}));o.push({id:i.id,name:i.data.label,position:i.position,units:i.data.uHeight||42,uNumberingDirection:i.data.uNumberingDirection||"bottom-up",customHeaderText:i.data.customHeaderText,devices:a});}return o}function lo(e,o,t,i){return e.map(r=>r.id!==o?r:{...r,devices:r.devices.map(a=>a.id!==t?a:{...a,unit:i})})}function po(e,o,t,i={}){let{conflictPolicy:r="strict"}=i;return e.map(a=>{if(a.id!==o)return a;if(r==="strict"&&!Ke({...a,devices:[...a.devices,t]},i).isValid)throw new he(o,t.id,t.unit,t.height);return {...a,devices:[...a.devices,t]}})}function uo(e,o,t){return e.map(i=>i.id!==o?i:{...i,devices:i.devices.filter(r=>r.id!==t)})}
2
- exports.DeviceNode=Oe;exports.DevicePlacementError=he;exports.FiberEdge=Me;exports.FiberNode=_e;exports.NetworkDiagram=ro;exports.POWER_CONNECTORS=Be;exports.PowerEdge=ze;exports.RackNode=Ue;exports.VerticalPDU=Ve;exports.Width=et;exports.addDeviceToRack=po;exports.buildNodesFromRackConfig=so;exports.calculateDevicePositionFromU=ue;exports.createNetworkDiagramStore=je;exports.createRackConfigFromNodes=co;exports.findNearestRack=Ce;exports.findNextAvailableUPosition=ke;exports.generateLayout=io;exports.getConnectorConfig=De;exports.getDeviceConnectorType=Re;exports.getPDUPortType=We;exports.getPowerPortStyle=ge;exports.getRackBounds=it;exports.getStatusColor=Z;exports.inventoryCableToNetworkEdge=ut;exports.inventoryDeviceToNetworkNode=pt;exports.inventoryRackToNetworkNode=lt;exports.inventoryToNetworkDiagram=no;exports.isHighPowerConnector=At;exports.isPointInRack=Se;exports.isUPositionAvailable=Ie;exports.removeDeviceFromRack=uo;exports.replaceEdge=me;exports.snapToUPosition=Te;exports.updateDeviceUPosition=Qe;exports.updateDeviceUPositionInSchema=lo;exports.useDiagramEdges=Ge;exports.useDiagramNodes=Xe;exports.useNetworkDiagram=Bt;exports.validateAndSnapDevice=Dt;exports.validateRackDevicePlacements=Ke;//# sourceMappingURL=index.js.map
1
+ 'use strict';var Br=require('react'),reactflow=require('reactflow'),htmlToImage=require('html-to-image'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Br__default=/*#__PURE__*/_interopDefault(Br);var hr=()=>"bottom-up",Pe=e=>e.data.uNumberingDirection||hr(),je=(e,o,r)=>r==="bottom-up"?o-e+1:e,Ge=(e,o,r)=>r==="bottom-up"?o-e+1:e;var ht=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=e.data.uHeight||1,i=o.data.uHeight||42,d=Pe(o),s=60,c=r.y-s,l=Math.round(c/20)+1,b;d==="bottom-up"?b=je(l,i,d)-n+1:b=je(l,i,d);let f=i-n+1,h=Math.max(1,Math.min(f,b));if(d==="top-down"&&b<=1&&(h=1),!mt(o,e,h,a)){let N=Ze(o,e,a,h);N!==h&&(h=N);}let v;if(d==="bottom-up"){let N=h+n-1,T=Ge(N,i,d);v=s+(T-1)*20-1;}else {let N=Ge(h,i,d);v=s+(N-1)*20-1;}return {x:r.x,y:v,uPosition:h}},mt=(e,o,r,a)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;if(r<1||r+n-1>i)return false;let d=a.filter(s=>s.type==="device"&&s.parentId===e.id&&s.id!==o.id);for(let s of d){let c=s.data.uPosition||1,l=s.data.uHeight||1,b=r,f=r+n-1,h=c,v=c+l-1;if(b<=v&&f>=h)return false}return true},Ze=(e,o,r,a=1)=>{let n=o.data.uHeight||1,i=e.data.uHeight||42;for(let d=a;d<=i-n+1;d++)if(mt(e,o,d,r))return d;return 1},De=(e,o,r=1)=>{let a=60,n=Pe(e),i=e.data.uHeight||42,d=Ge(o,i,n),s;if(n==="bottom-up"){let c=o+r-1,l=Ge(c,i,n);s=a+(l-1)*20-1;}else s=a+(d-1)*20-1;return {x:0,y:s}},uo=(e,o,r)=>{let a=e.data.uHeight||1,n=De(o,r,a);return {...e,position:n,data:{...e.data,uPosition:r}}},mr=(e,o)=>{let r=e.data.uPosition||1,a=e.data.uHeight||1,n=o.data.uHeight||42,i=Math.max(1,Math.min(n-a+1,r));return i!==r?uo(e,o,i):e};function se(e){switch(e){case "active":return "#10b981";case "inactive":return "#6b7280";case "maintenance":return "#f59e0b";default:return "#6b7280"}}var yt=({data:e,selected:o,id:r,onViewChange:a,onRackFaceChange:n,isDragOver:i=false})=>{let{label:d,ports:s=0,status:c="active",uHeight:l=42,face:b="front",customHeaderText:f}=e,{getNodes:h,setNodes:v}=reactflow.useReactFlow(),N=h(),[T,w]=Br.useState(true),I=()=>{let H=Pe({data:e})==="bottom-up"?"top-down":"bottom-up";v(y=>y.map(P=>P.id===r?{...P,data:{...P.data,uNumberingDirection:H}}:P));},F=()=>{let x=b==="front"?"rear":"front";n?(n(r,x),a&&N.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);})):a?N.filter(y=>y.parentId===r).forEach(y=>{a(y.id,x);}):v(H=>H.map(y=>y.id===r?{...y,data:{...y.data,face:x}}:y.parentId===r?{...y,data:{...y.data,view:x}}:y));},W=()=>{let x=[],H=60,y=Pe({data:e});for(let P=1;P<=l;P++){let $=H+(P-1)*20-4,C=je(P,l,y);x.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:"-35px",top:`${$}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${20}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:C},P));}return x};return jsxRuntime.jsxs("div",{className:`rack-node ${o?"selected":""} ${i?"drag-over":""}`,style:{background:"transparent",border:`2px solid ${se(c)}`,borderRadius:"8px",padding:0,width:`${300}px`,height:`${60+l*20}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:i?"0 0 20px #3b82f6, 0 0 40px #3b82f6, 0 0 60px #3b82f6":o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",transition:"box-shadow 0.2s ease-in-out"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"8px",position:"relative",height:`${60}px`,display:"flex",flexDirection:"column",justifyContent:"center"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",marginBottom:"4px"},children:d}),jsxRuntime.jsxs("div",{style:{fontSize:"10px",color:"#9ca3af"},children:[f?jsxRuntime.jsx("span",{style:{color:"#fbbf24",fontWeight:"bold"},children:f}):jsxRuntime.jsxs("span",{children:[typeof s=="number"?s:0," ports"]})," \u2022 ",l,"U \u2022 ",b]}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"4px",position:"absolute",top:"4px",right:"4px"},children:[jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),w(!T);},style:{background:T?"#10b981":"#374151",color:T?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${T?"Hide":"Show"} U markers`,children:"U"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),I();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch U numbering to ${Pe({data:e})==="bottom-up"?"top-down":"bottom-up"}`,children:Pe({data:e})==="bottom-up"?"\u2191\u2193":"\u2193\u2191"}),jsxRuntime.jsx("button",{onPointerDown:x=>{x.stopPropagation();},onMouseDown:x=>{x.stopPropagation();},onClick:x=>{x.stopPropagation(),x.preventDefault(),F();},style:{background:"#374151",color:"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`Switch to ${b==="front"?"rear":"front"} view`,children:b==="front"?"\u21C4 Rear":"\u21C4 Front"})]})]}),jsxRuntime.jsx("div",{style:{flex:1,background:"transparent",position:"relative",minHeight:`${l*20}px`,overflow:"hidden"}}),T&&jsxRuntime.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,pointerEvents:"none"},children:W()})]})};var xt=({data:e,selected:o})=>{let{label:r,status:a="active"}=e;return jsxRuntime.jsxs("div",{className:`fiber-node ${o?"selected":""}`,style:{background:"#1f2937",border:`2px solid ${se(a)}`,borderRadius:"50%",width:"60px",height:"60px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontFamily:"monospace",fontSize:"10px",fontWeight:"bold",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative"},children:[jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Top}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Bottom}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right}),jsxRuntime.jsx("div",{style:{textAlign:"center"},children:jsxRuntime.jsx("div",{style:{fontSize:"8px",lineHeight:"1.2"},children:r})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"4px",left:"50%",transform:"translateX(-50%)",width:"8px",height:"8px",background:se(a),borderRadius:"50%"}})]})};var Nt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},className:b})=>{let[f,h,v]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),{bandwidth:N,length:T,color:w="#00FFFF",striped:I=false}=s||{},F={...l,stroke:w,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:f,style:F}),I&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:f,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}}),jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:c&&s&&(N||T)&&jsxRuntime.jsxs("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${h}px,${v}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${w}`,pointerEvents:"none",zIndex:9999},children:[N&&jsxRuntime.jsx("div",{children:N}),T&&jsxRuntime.jsxs("div",{children:[T,"m"]})]})})]})};var kt=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l})=>{let[b]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),f=c?.connectorType||"C13";return jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:b,markerEnd:l,style:(()=>{let v={stroke:c?.color||"#f59e0b",strokeWidth:f==="C19"?5:3,strokeLinecap:"round",strokeLinejoin:"round",...s};return f==="C19"?{...v,strokeDasharray:"none"}:{...v,strokeDasharray:"6,3"}})()})};var go=({data:e,selected:o,style:r={},...a})=>{let{color:n="#00FFFF"}=e||{},i={...r,stroke:n,strokeWidth:o?4:3};return jsxRuntime.jsx(reactflow.SmoothStepEdge,{...a,data:e,selected:o,style:i})};function Tr({sourceX:e,sourceY:o,targetX:r,targetY:a,sourcePosition:n,targetPosition:i}){let d=n===reactflow.Position.Left||n===reactflow.Position.Right,s;if(d){let c=(e+r)/2;s=`M ${e},${o} L ${c},${o} L ${c},${a} L ${r},${a}`;}else {let c=(o+a)/2;s=`M ${e},${o} L ${e},${c} L ${r},${c} L ${r},${a}`;}return s}var yo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,data:s,selected:c,style:l={},...b})=>{let{color:f="#00FFFF",striped:h=false}=s||{},v=Tr({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),N={...l,stroke:f,strokeWidth:c?3:2,strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,style:N}),h&&jsxRuntime.jsx(reactflow.BaseEdge,{id:`${e}-stripe`,path:v,style:{...l,stroke:"#000",strokeWidth:1.5,strokeDasharray:"6 6",opacity:.9}})]})};var xo=({id:e,sourceX:o,sourceY:r,targetX:a,targetY:n,sourcePosition:i,targetPosition:d,style:s={},data:c,markerEnd:l,selected:b})=>{let{color:f="#6366f1",label:h}=c||{},[v,N,T]=reactflow.getBezierPath({sourceX:o,sourceY:r,sourcePosition:i,targetX:a,targetY:n,targetPosition:d}),w={...s,stroke:f,strokeWidth:8,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"none"};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactflow.BaseEdge,{id:e,path:v,markerEnd:l,style:w}),h&&jsxRuntime.jsx(reactflow.EdgeLabelRenderer,{children:jsxRuntime.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${N}px,${T}px)`,background:"#1f2937",padding:"4px 8px",borderRadius:"4px",fontSize:"10px",color:"white",fontFamily:"monospace",border:`1px solid ${f}`,pointerEvents:"none",zIndex:9999},children:h})})]})};var wo=(r=>(r.FULL="full",r.HALF="half",r))(wo||{});var Pt={C13:{type:"C13",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C14:{type:"C14",color:"#f59e0b",borderColor:"#d97706",amperage:10,voltage:230,phases:1},C19:{type:"C19",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1},C20:{type:"C20",color:"#fbbf24",borderColor:"#d97706",amperage:16,voltage:230,phases:1}};function Ie(e){let o=Pt[e];if(!o)throw new Error(`Unknown connector type: ${e}`);let r=o.amperage===16,a=r?12:8,n=r?10:5,i=r?{borderRadius:"3px"}:{clipPath:"polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% 100%, 0 100%, 0 2px)",borderRadius:"0px"};return {width:a,height:n,color:o.color,borderColor:o.borderColor,fontSize:r?"3px":"4px",...i}}function Qe(e){let o=Pt[e];if(!o)throw new Error(`Unknown connector type: ${e}`);return o}function zr(e){return Qe(e).amperage===16}function St(e){return e%10<8?"C13":"C19"}function et(e){let o=e.toLowerCase();return o.includes("mx304")||o.includes("mx480")||o.includes("mx960")?"C20":"C14"}var Ct=({data:e,selected:o})=>{let{label:r,status:a="active",deviceType:n="server",manufacturer:i,role:d,uHeight:s=1,width:c="full",ports:l=[],rearPorts:b=[],view:f}=e,h=f||(b.length>0&&l.length===0?"rear":"front"),v={};v["net-top"]="front",v["net-bottom"]="front",l.length>0&&l.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="front";});}),v["pwr-left-1"]="rear",v["pwr-left-2"]="rear",v["net-right-1"]="rear",v["net-right-2"]="rear",b.length>0&&b.forEach(x=>{x.ports.forEach(H=>{let y=H.type?.includes("power")?H.label:`${x.name}-${H.label}`;v[y]="rear";});});let N=s*20,T=c==="half"?"150px":"304px",w=c==="half"?"150px":void 0,I=(x,H)=>{let y=[];if(x.length===0)return y;let P=Math.max(4,Math.floor(N*.4)),$=Math.max(2,Math.floor(N*.2));return x.forEach((C,z)=>{C.ports.forEach((_,R)=>{let M=!!_.type&&_.type.includes("power");if(H==="front"&&M)return;let V=M?`${_.label}`:`${C.name}-${_.label}`,X=_.connected,E="#6b7280";if(X)if(_.type?.includes("power"))E=_.type==="power_c19"?"#fbbf24":"#f59e0b";else if(_.type==="console"||_.type==="mgmt")E="#8b5cf6";else if(_.type==="usb")E="#10b981";else switch(_.cableType){case "smf":E="#fbbf24";break;case "cat6":E="#8b5cf6";break;case "om3":E="#06b6d4";break;case "om4":E="#8b5cf6";break;case "om5":E="#84cc16";break;case "cat5e":E="#3b82f6";break;case "cat6a":E="#ef4444";break;case "cat7":E="#f97316";break;case "fiber":E="#3b82f6";break;case "ethernet":E="#10b981";break;default:E="#10b981";}let G=reactflow.Position.Top,D={width:`${P}px`,height:`${$}px`,background:X?E:"#6b7280",border:`1px solid ${X?E:"#374151"}`,borderRadius:"1px",cursor:"pointer"};if(H==="front")R%2===0?(G=reactflow.Position.Top,D.transform="translateY(50%)",D.left=`${R/2*(P+2)}px`):(G=reactflow.Position.Bottom,D.transform="translateY(-50%)",D.left=`${(R-1)/2*(P+2)}px`);else if((n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel")R%2===0?(G=reactflow.Position.Top,D.transform="translateY(50%)",D.left=`${R/2*(P+2)}px`):(G=reactflow.Position.Bottom,D.transform="translateY(-50%)",D.left=`${(R-1)/2*(P+2)}px`);else if(_.type?.includes("power")){G=reactflow.Position.Left,D.transform="translateX(50%)";let Ye=N<=20?10:20,ke=N<=20?30:50;D.top=`${Ye+R*ke}%`;let ft=et(r),me=Ie(ft);D={...D,width:`${me.width}px`,height:`${me.height}px`,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:me.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:me.borderRadius,clipPath:me.clipPath};}else G=reactflow.Position.Right,D.transform="translateX(-50%)",D.top=`${25+R*50}%`;let be=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel",ie;if(M)ie="target";else if(n==="switch"||n==="router")ie="source",y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${V}-target`,type:"target",position:G,style:D,title:`${C.name} - ${_.label} (input) ${X?"(connected)":"(disconnected)"}`},`${V}-target`));else if(be){ie=H==="rear"?"source":"target";let he=H==="rear"?"target":"source";y.push(jsxRuntime.jsx(reactflow.Handle,{id:`${V}-${he}`,type:he,position:G,style:D,title:`${C.name} - ${_.label} (${he}) ${X?"(connected)":"(disconnected)"}`},`${V}-${he}`));}else ie=X?"source":"target";y.push(jsxRuntime.jsx(reactflow.Handle,{id:V,type:ie,position:G,style:D,title:`${C.name} - ${_.label} ${X?"(connected)":"(disconnected)"}`,children:M?R+1:void 0},V));});}),y},F=()=>{let x=[],H=Math.max(4,Math.floor(N*.4)),y=Math.max(2,Math.floor(N*.2));if(h==="front"){if(l.length>0)return I(l,"front");if(n==="switch"&&(r.toLowerCase().includes("agg")||r.toLowerCase().includes("core")||d==="agg"||d==="core"))return W();x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-top",type:"target",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(50%)"},title:"Network Port (Top)"},"net-top")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-bottom",type:"target",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateY(-50%)"},title:"Network Port (Bottom)"},"net-bottom"));}else if(h==="rear"){if(b.length>0)return I(b,"rear");let P=n==="switch",C=(n?.toLowerCase().replace(/_/g,"-")||"")==="patch-panel";if(!C){let z=et(r),_=Qe(z),R=Ie(z),M=N<=20?"10%":"25%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-1",type:"target",position:reactflow.Position.Left,style:{width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:M,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`Power Port 1 (${_.type}) - ${_.voltage}V, ${_.amperage}A`,children:"1"},"pwr-1"));let V=N<=20?"50%":"75%";x.push(jsxRuntime.jsx(reactflow.Handle,{id:"pwr-left-2",type:"target",position:reactflow.Position.Left,style:{width:`${R.width}px`,height:`${R.height}px`,background:R.color,border:`1px solid ${R.borderColor}`,cursor:"pointer",transform:"translateX(50%)",top:V,zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:R.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:R.borderRadius,clipPath:R.clipPath},title:`Power Port 2 (${_.type}) - ${_.voltage}V, ${_.amperage}A`,children:"2"},"pwr-2"));}!P&&!C&&(x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-1",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"25%"},title:"Network Port 1 (Right)"},"net-right-1")),x.push(jsxRuntime.jsx(reactflow.Handle,{id:"net-right-2",type:"target",position:reactflow.Position.Right,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"0.5px solid #059669",borderRadius:"1px",cursor:"pointer",transform:"translateX(-50%)",top:"75%"},title:"Network Port 2 (Right)"},"net-right-2")));}return x},W=()=>{let x=[],H=Math.max(10,Math.floor(N*.45)),y=Math.max(5,Math.floor(N*.25));for(let P=1;P<=16;P++){let $=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Top,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(50%)",zIndex:1e3,left:`${(P-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push($);}for(let P=17;P<=32;P++){let $=P-16,C=jsxRuntime.jsx(reactflow.Handle,{id:`port-${P}`,type:"source",position:reactflow.Position.Bottom,style:{width:`${H}px`,height:`${y}px`,background:"#10b981",border:"1px solid #059669",borderRadius:"2px",cursor:"pointer",transform:"translateY(-50%)",zIndex:1e3,left:`${($-1)*(H+2)}px`},title:`Port ${P}`},`port-${P}`);x.push(C);}for(let P=1;P<=4;P++){let $=Math.max(4,Math.floor(N*.3)),C=Math.max(3,Math.floor(N*.15));x.push(jsxRuntime.jsx(reactflow.Handle,{id:`uplink-${P}`,type:"source",position:reactflow.Position.Right,style:{width:`${$}px`,height:`${C}px`,background:"#8b5cf6",border:"0.5px solid #7c3aed",borderRadius:"0.5px",cursor:"pointer",transform:"translateX(-50%)"},title:`Uplink ${P}`},`uplink-${P}`));}return x};return jsxRuntime.jsxs("div",{className:`device-node ${o?"selected":""}`,style:{background:"#1f2937",border:`1px solid ${se(a)}`,borderRadius:"2px",padding:"0px",width:T,...w&&{left:w},height:`${N}px`,color:"white",fontFamily:"monospace",fontSize:"8px",boxShadow:o?"0 0 0 1px #3b82f6":"0 1px 2px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",justifyContent:"center",cursor:"grab",marginBottom:"0px",boxSizing:"border-box",marginTop:"0px",marginLeft:"0px",marginRight:"0px"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",flex:1,display:"flex",flexDirection:"column",justifyContent:"center",overflow:"hidden",padding:"2px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"7px",lineHeight:"1.1",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r}),s>1&&jsxRuntime.jsx("div",{style:{fontSize:"6px",color:"#9ca3af",lineHeight:"1"},children:i})]}),s>1&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"1px",right:"1px",background:"#374151",color:"#9ca3af",padding:"1px 2px",borderRadius:"1px",fontSize:"6px",lineHeight:"1"},children:[s,"U"]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"1px",left:"1px",width:"4px",height:"4px",background:se(a),borderRadius:"50%"}}),F()]})};var Et=({data:e,selected:o})=>{let{label:r,status:a="active",heightCm:n=100,powerPorts:i=36,widthPx:d=15,mgmt_unit:s}=e,c=n*4.2,l=()=>{let h=Math.ceil(i/10),v=Array(10).fill(0).map((y,P)=>P<8?"10A":"16A");for(let y=0,P=0;y<h;++y)for(let $=0;$<10&&P<i;++$,++P){v[$];}let I=[],F=15,H=(c-F-3)/(i-9)*.5;for(let y=0;y<i;y++){let P=F-2+H*y,$=`${y+1}`;if(s&&(s==="top"&&y===0||s==="middle"&&y===Math.floor(i/2)||s==="bottom"&&y===i-1)){I.push(b(P));continue}let z=St(y),_=Ie(z),R=Math.round((d-_.width)/2-1);I.push(jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:$,style:{position:"absolute",left:`${R}px`,top:`${P-_.height/2}px`,width:`${_.width}px`,height:`${_.height}px`,background:_.color,border:`1px solid ${_.borderColor}`,cursor:"pointer",zIndex:10,display:"flex",alignItems:"center",justifyContent:"center",fontSize:_.fontSize,color:"#1a1a1a",fontFamily:"monospace",fontWeight:"bold",borderRadius:_.borderRadius,clipPath:_.clipPath},title:`Power Port ${y+1} (${z})`,children:y+1},`handle-${$}`));}return I},b=f=>jsxRuntime.jsxs("div",{style:{position:"absolute",left:`${(d-16)/2}px`,top:`${f-12/2}px`,width:"16px",height:"12px",background:"#1a1a1a",border:"1px solid #374151",borderRadius:"1px",display:"flex",flexDirection:"column",padding:"1px",zIndex:10},children:[jsxRuntime.jsx("div",{style:{position:"absolute",left:"-10px",top:"1px",background:"#ffffff",border:"0.5px solid #6b7280",borderRadius:"0.5px",width:"8px",height:"10px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"3px",color:"#10b981",fontFamily:"monospace",fontWeight:"bold",transform:"rotate(90deg)",transformOrigin:"center"},children:"APC"}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"mgmt-net-1",style:{width:"70%",height:"6px",background:"#10b981",border:"1px solid #059669",borderRadius:"1px",cursor:"pointer",zIndex:11,margin:"0 auto"},title:"Management Network Port"},"mgmt-net-1")]},"mgmt-unit");return jsxRuntime.jsxs("div",{className:`vertical-pdu-node ${o?"selected":""}`,style:{background:"linear-gradient(90deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",border:`1px solid ${se(a)}`,borderRadius:"2px",padding:0,width:`${d}px`,height:`${c}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 1px 3px rgba(0,0,0,0.3)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"linear-gradient(90deg, #4a5568 0%, #2d3748 50%, #4a5568 100%)",padding:"2px",position:"relative",height:"20px",display:"flex",flexDirection:"column",justifyContent:"center",borderBottom:"1px solid #4a5568"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"6px",color:"#e2e8f0"},children:r})}),jsxRuntime.jsx("div",{style:{flex:1,background:"linear-gradient(180deg, #2d3748 0%, #1a202c 50%, #2d3748 100%)",position:"relative",minHeight:`${c-20}px`,overflow:"hidden"},children:l()})]})};var Dt=({data:e,selected:o,id:r})=>{let{lossDb:a}=e||{},n=reactflow.useEdges(),i=n.find(h=>h.target===r&&h.targetHandle==="left"),d=n.find(h=>h.source===r&&h.sourceHandle==="right"),s=n.find(h=>h.target===r&&h.targetHandle==="right"),c=d||s,l=i?.data?.color||"#555",b=c?.data?.color||"#555",f=!!i&&!!c;return jsxRuntime.jsxs("div",{className:`splice-node ${o?"selected":""}`,style:{width:69,height:16,borderRadius:8,border:"none",outline:"none",position:"relative",background:"transparent",boxShadow:o?"0 0 0 2px #3b82f6":"none"},children:[jsxRuntime.jsxs("div",{style:{position:"absolute",inset:0,display:"grid",gridTemplateColumns:"1fr 1fr",borderRadius:8,overflow:"hidden",opacity:.75,pointerEvents:"none"},children:[jsxRuntime.jsx("div",{style:{background:l}}),jsxRuntime.jsx("div",{style:{background:b}})]}),jsxRuntime.jsx("div",{className:"splice-text-overlay",style:{position:"absolute",inset:0,borderRadius:8,pointerEvents:"none",zIndex:1}}),f&&jsxRuntime.jsx("div",{className:"splice-glow",style:{position:"absolute",left:"50%",top:0,bottom:0,width:"1px",background:"rgba(255, 255, 255, 0.6)",boxShadow:"0 0 2px rgba(255, 255, 255, 0.8), 0 0 4px rgba(255, 255, 255, 0.4)",pointerEvents:"none",zIndex:2}}),f&&typeof a=="number"&&jsxRuntime.jsx("div",{className:"splice-text-label animate-in",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:9,fontFamily:"monospace",pointerEvents:"none",zIndex:3,fontWeight:"bold"},children:`${a.toFixed(2)} dB`}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Left,id:"left",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:l,zIndex:100,cursor:"crosshair",left:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"source",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:b,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}}),jsxRuntime.jsx(reactflow.Handle,{type:"target",position:reactflow.Position.Right,id:"right",isConnectable:true,style:{width:12,height:12,borderRadius:"50%",border:"none",background:b,zIndex:100,cursor:"crosshair",right:-6,top:"50%",transform:"translateY(-50%)"}})]})};var we=20,He=32,So=4,Ne=12,Mr=69,Ce=80,It=(Ce-Mr)/2;var _t=(e,o,r,a)=>{if(!e.parentId||e.parentId!==o.id)return r;let n=He,i=r.y-n,d=Math.round(i/we)+1,c=Math.max(1,Math.min(Ne,d));if(!$t(o,e,c,a)){let f=tt(o,e,a,c);if(f!==c)return {x:It,y:n+(f-1)*we+5,holderPosition:f}}let b=n+(c-1)*we+5;return {x:It,y:b,holderPosition:c}},$t=(e,o,r,a)=>!a.filter(i=>i.parentId===e.id&&i.type==="splice"&&i.id!==o.id).some(i=>i.data.holderPosition===r),tt=(e,o,r,a=1)=>{for(let n=a;n<=Ne;n++)if($t(e,o,n,r))return n;for(let n=a-1;n>=1;n--)if($t(e,o,n,r))return n;return 1},Me=(e,o)=>{let n=He+(o-1)*we+5;return {x:It,y:n}};var Wt=({data:e,selected:o})=>{let{label:r="Splice Tray"}=e||{},[a,n]=Br.useState(false),i=()=>{if(!a)return null;let d=[],s=He;for(let c=1;c<=Ne;c++){let l=s+(c-1)*we;d.push(jsxRuntime.jsxs("div",{style:{position:"absolute",left:"-35px",top:`${l}px`,background:"#374151",color:"#9ca3af",padding:"2px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:"bold",width:"28px",textAlign:"center",border:"1px solid #4b5563",zIndex:10,height:`${we}px`,display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1},children:["H",c]},c));}return d};return jsxRuntime.jsxs("div",{className:`splice-tray-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${Ce}px`,height:`${He+Ne*we+So}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsxs("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#1f2937",padding:"2px",position:"relative",height:`${He}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"8px"},children:[jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"10px"},children:r}),jsxRuntime.jsx("button",{onPointerDown:d=>{d.stopPropagation();},onMouseDown:d=>{d.stopPropagation();},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(!a);},style:{background:a?"#10b981":"#374151",color:a?"#ffffff":"#9ca3af",border:"1px solid #4b5563",borderRadius:"2px",padding:"2px 6px",fontSize:"8px",cursor:"pointer",fontFamily:"monospace"},title:`${a?"Hide":"Show"} holder markers`,children:"H"})]}),i(),jsxRuntime.jsx("div",{style:{position:"absolute",top:He,left:0,right:0,bottom:0,pointerEvents:"none"}})]})};var Ho=["#1f77b4","#ff7f0e","#2ca02c","#8c564b","#708090","#ffffff","#d62728","#000000","#ffdf00","#8a2be2","#ff69b4","#00ffff"];function te(e){let o=(e-1)%12;return Ho[o]}function Co(e){return e>12}function Ue(e){let o=te(e);return Co(e)?{background:o,backgroundImage:`repeating-linear-gradient(45deg, ${o} 0 6px, #000 6px 9px)`}:{background:o}}function zt(e){return te(e)}var Lt=({data:e,selected:o,id:r})=>{let{fibersPerTube:a=12,tubeIndex:n=1,startOn:i="left-center"}=e||{},d=Math.max(1,Math.min(24,Number(a)||12)),s=14,c=4,l=1,b=2,f=20,h=d*s+(d-1)*c,v=Math.max(60,h+l*2+b*2),N=te((n-1)%12+1),T=`tube-${n}`,w=18,I={width:w,height:w,borderRadius:"50%",opacity:.25,pointerEvents:"auto",background:N,backgroundColor:N,border:`2px solid ${N}`,"--fiber-bg":N},F=()=>i==="left"?reactflow.Position.Left:i==="right"?reactflow.Position.Right:reactflow.Position.Bottom,W=()=>{let x=[],H=v-b*2-l*2,y,P,$=false;i==="left"?(y=l,P=reactflow.Position.Top):i==="right"?(y=l+H-h,P=reactflow.Position.Top,$=true):(y=l+(H-h)/2,P=reactflow.Position.Top);for(let C=0;C<d;C++){let z=$?d-C:C+1,_=Ue(z),R=te(z),M=y+C*(s+c),V=l,X=_.backgroundImage?_.backgroundImage:R,E={position:"absolute",left:`${M}px`,top:`${V}px`,width:s,height:s,borderRadius:"50%",border:"none",background:X,backgroundColor:R,zIndex:10,cursor:"pointer","--fiber-bg":R};_.backgroundImage&&(E["--fiber-bg-image"]=_.backgroundImage);let G=`fiber-${z}`;x.push(jsxRuntime.jsxs(Br__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:G,type:"target",position:P,className:"tube-fiber-handle",isConnectable:true,style:E,"data-fiber-idx":z,"data-fiber-color":R}),jsxRuntime.jsx(reactflow.Handle,{id:G,type:"source",position:P,className:"tube-fiber-handle",isConnectable:true,style:E,"data-fiber-idx":z,"data-fiber-color":R})]},`fiber-${z}`));}return x};return jsxRuntime.jsxs("div",{style:{width:v,height:f,borderRadius:4,background:"#111827",border:`${b}px solid ${o?"#3b82f6":N}`,position:"relative",boxShadow:o?`0 0 0 ${b}px #3b82f6`:"0 2px 4px rgba(0,0,0,0.2)",padding:l,boxSizing:"border-box"},children:[W(),jsxRuntime.jsx(reactflow.Handle,{id:T,type:"target",position:F(),isConnectable:true,style:I,"data-tube-idx":n,"data-tube-color":N}),jsxRuntime.jsx(reactflow.Handle,{id:T,type:"source",position:F(),isConnectable:true,style:I,"data-tube-idx":n,"data-tube-color":N})]})};var Mt=({data:e,selected:o})=>{let{tubeCount:r=12,fibersPerTube:a=12,fiberCount:n,cableId:i="CBL-002",label:d,tubeStartIndex:s=1,color:c}=e||{},l=Math.max(1,Math.min(24,Number(r)||12)),b=Math.max(1,Number(s)||1),f=8,h=2,v=6,N=v+f+4,T=60,w=Math.max(120,l*(f+h)+v*2),I=n??l*(Number(a)||12),F=d??`${I}f Cable`,W=i?`Cable ID ${i}`:void 0,x=te(b),H=c||x,y=o?"#3b82f6":H,P=()=>{let R=[];for(let M=0;M<l;M++){let V=b+M,X=Ue(V),E=te(V),G=v+M*(f+h),D=-4,ge=X.backgroundImage?X.backgroundImage:E,be={position:"absolute",left:`${G}px`,top:`${D}px`,width:f,height:f,borderRadius:"50%",border:"none",background:ge,backgroundColor:E,zIndex:10,cursor:"pointer","--fiber-bg":E};X.backgroundImage&&(be["--fiber-bg-image"]=X.backgroundImage);let ie=`tube-${V}`;R.push(jsxRuntime.jsxs(Br__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:ie,type:"target",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:be,"data-fiber-idx":V,"data-tube-idx":V,"data-tube-color":E}),jsxRuntime.jsx(reactflow.Handle,{id:ie,type:"source",position:reactflow.Position.Top,className:"tube-fiber-handle",isConnectable:true,style:be,"data-fiber-idx":V,"data-tube-idx":V,"data-tube-color":E})]},`tube-${V}`));}return R},$="cable-button",C=8,z={width:C,height:C,borderRadius:"50%",background:H,backgroundColor:H,border:`1px solid ${H}`,cursor:"pointer",zIndex:10};return jsxRuntime.jsxs("div",{style:{width:w,height:T,borderRadius:4,background:"#111827",border:`2px solid ${y}`,position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",padding:v,paddingTop:N,boxSizing:"border-box",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",textAlign:"center",gap:2},children:[P(),jsxRuntime.jsx(reactflow.Handle,{id:$,type:"source",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:z,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx(reactflow.Handle,{id:$,type:"target",position:reactflow.Position.Bottom,className:"cable-button-handle",isConnectable:true,style:z,"data-handle-type":"cable-button","data-cable-color":H}),jsxRuntime.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.5},children:F}),W&&jsxRuntime.jsx("div",{style:{fontSize:10,opacity:.8},children:W})]})};var Ut=({data:e,selected:o,id:r})=>{let{connector:a="LC",couplerFiberCount:n,label:i,portLabelsLeft:d,portLabelsRight:s}=e||{},c=reactflow.useEdges(),l=typeof n=="number"&&[1,2,4].includes(n)?n:2,b=Math.max(1,Math.min(4,l)),f=7,h=3,v=3,N=60,T=30,w=b*f+(b-1)*h,I=Math.max(T,w+v*2),F=Math.max(N,80),W=(y,P)=>{let $=`${y}-${P+1}`;return c.find(z=>z.source===r&&z.sourceHandle===$||z.target===r&&z.targetHandle===$)?.data?.color||"#555"},x=y=>{let P=[],$=y==="left"?reactflow.Position.Left:reactflow.Position.Right,C=y==="left"?d:s;for(let z=0;z<b;z++){let _=z+1,R=`${y}-${_}`,M=W(y,z),E=v+(I-w)/2+z*(f+h),G={position:"absolute",left:y==="left"?-5:void 0,right:y==="right"?-5:void 0,top:`${E}px`,width:f,height:f,borderRadius:"50%",border:"none",background:M,zIndex:100,cursor:"crosshair",transform:"translateY(-50%)"};P.push(jsxRuntime.jsxs(Br__default.default.Fragment,{children:[jsxRuntime.jsx(reactflow.Handle,{id:R,type:"target",position:$,isConnectable:true,style:G}),jsxRuntime.jsx(reactflow.Handle,{id:R,type:"source",position:$,isConnectable:true,style:G})]},R)),C&&C[z]&&P.push(jsxRuntime.jsx("div",{style:{position:"absolute",left:y==="left"?-30:void 0,right:y==="right"?-30:void 0,top:`${E}px`,transform:"translateY(-50%)",fontSize:"8px",color:"#9ca3af",fontFamily:"monospace",pointerEvents:"none",textAlign:y==="left"?"right":"left",width:"25px"},children:C[z]},`${R}-label`));}return P},H=i||`${a}-${b}f`;return jsxRuntime.jsxs("div",{className:`coupler-node ${o?"selected":""}`,style:{width:F,height:I,borderRadius:4,border:`2px solid ${o?"#3b82f6":"#4b5563"}`,background:"#1f2937",position:"relative",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#e5e7eb",fontFamily:"monospace",fontSize:"10px",padding:`${v}px`,boxSizing:"border-box"},children:[x("left"),jsxRuntime.jsx("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",textAlign:"center",pointerEvents:"none",zIndex:1},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"9px"},children:H})}),x("right")]})};var Ee=32,dt=30,Xr=24,jr=80,at=400,st=300,Ao=2,fe=8,Wo=120;function Bt(e){let{couplerFiberCount:o}=e.data||{},r=typeof o=="number"&&[1,2,4].includes(o)?o:2,a=Math.max(1,Math.min(4,r)),n=7,i=3,d=3,s=60,c=30,l=a*n+(a-1)*i,b=Math.max(c,l+d*2);return {width:Math.max(s,80),height:b}}function ct(e){let{fibersPerTube:o=12}=e.data||{},r=Math.max(1,Math.min(24,Number(o)||12)),a=14,n=4,i=1,d=2,s=20,c=r*a+(r-1)*n;return {width:Math.max(60,c+i*2+d*2),height:s}}function zo(e){return {width:Ce,height:0}}function Oe(e){return e.type==="coupler"?Bt(e):e.type==="tube"?ct(e):e.type==="splice-tray"?zo():{width:80,height:30}}function Lo(e){return e.data?.panelWidth||at}function Gr(e){return e.data?.panelHeight||st}function Mo(e){return Lo(e)-Ao*2-fe*2}function Zr(e,o){return Mo(e)-o}function Uo(e,o=dt){return Math.floor(e/o)+1}function Bo(e,o=dt){return (e-1)*o}function Kr(e,o,r){let a=dt,n=Uo(r.y,a),i=Bo(n,a);return {x:r.x,y:i,slotPosition:n}}function Ot(e,o){if(o.length===0)return {width:e.data?.panelWidth||at,height:e.data?.panelHeight||st};let r=o.some(l=>l.type==="tube"),a=o.some(l=>l.type==="splice-tray"),n=o.some(l=>l.type==="coupler"),i,d=5;if(r&&a&&n){let l=0,b=0;for(let f of o)if(f.type==="tube"){let h=ct(f);h.width>l&&(l=h.width);}else if(f.type==="coupler"){let h=Bt(f);h.width>b&&(b=h.width);}i=fe+l+Wo+Ce+b+d;}else {let l=0;for(let b of o){let f=Oe(b),h=(b.position?.x||0)+f.width;h>l&&(l=h);}i=l+fe+d;}i=Math.max(e.data?.panelWidth||at,i);let s=Ee;for(let l of o){let b=Oe(l),f=(l.position?.y||0)+b.height;f>s&&(s=f);}let c=Math.max(e.data?.panelHeight||st,s+fe);return {width:i,height:c}}function Oo(e,o,r){if(e===0)return 0;if(e===1)return o;let a=e*o,n=r-a,i=Math.max(5,n/(e-1));return o+i}function qr(e,o,r){return Oo(e,o,r)}var $o=20,_o=400,Fo=300;function Yo(e,o){if(o.length===0)return {width:e.data?.closureWidth||e.data?.panelWidth||_o,height:e.data?.closureHeight||e.data?.panelHeight||Fo};let r=o.some(c=>c.type==="tube"),a=o.some(c=>c.type==="splice-tray"),n,i=5;if(r&&a){let c=0,l=0,b=0,f=o.filter(v=>v.type==="tube"),h=o.filter(v=>v.type==="splice-tray");if(f.length>0&&h.length>0){let v=f.map(F=>F.position?.x||0);Math.min(...v);Math.max(...v);let w=h.map(F=>F.position?.x||0),I=w.reduce((F,W)=>F+W,0)/w.length;for(let F of f){let W=ct(F);(F.position?.x||0)<I?W.width>c&&(c=W.width):W.width>l&&(l=W.width);}h.length>0&&(b=Ce),n=fe+c+$o+b+$o+l+i;}else {let v=0;for(let N of o){let T=Oe(N),w=(N.position?.x||0)+T.width;w>v&&(v=w);}n=v+fe+i;}}else {let c=0;for(let l of o){let b=Oe(l),f=(l.position?.x||0)+b.width;f>c&&(c=f);}n=c+fe+i;}n=Math.max(e.data?.closureWidth||e.data?.panelWidth||_o,n);let d=Ee;for(let c of o){let l=Oe(c),b=(c.position?.y||0)+l.height;b>d&&(d=b);}let s=Math.max(e.data?.closureHeight||e.data?.panelHeight||Fo,d+fe);return {width:n,height:s}}var Xt=({data:e,selected:o,id:r})=>{let{label:a="Patch Panel",header:n,panelWidth:i,panelHeight:d}=e||{},{getNodes:s,setNodes:c}=reactflow.useReactFlow(),l=Br.useRef(false),b=Br.useMemo(()=>s().filter(F=>F.parentId===r),[s,r]),f=Br.useMemo(()=>({id:r,type:"patch-panel",position:{x:0,y:0},data:{...e,panelWidth:i,panelHeight:d}}),[r,e,i,d]),h=Br.useMemo(()=>i&&d?{width:i,height:d}:b.length===0?{width:i||400,height:d||300}:Ot(f,b),[b,f,i,d]);Br.useEffect(()=>{if(i&&d||l.current)return;let I=i,F=d,W=Math.abs((I||0)-h.width),x=Math.abs((F||0)-h.height);(W>1||x>1)&&(l.current=true,c(H=>H.map(y=>y.id===r?{...y,data:{...y.data,panelWidth:h.width,panelHeight:h.height}}:y)),setTimeout(()=>{l.current=false;},0));},[r,h.width,h.height,i,d,c]);let v=h.width,N=h.height,T=Ee,w=n||a;return jsxRuntime.jsxs("div",{className:`patch-panel-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:"8px",padding:0,width:`${v}px`,height:`${N}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${T}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:"6px 6px 0 0",borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:w})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:T,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};var Zt=({data:e,selected:o,id:r})=>{let{label:a="Closure",header:n,closureWidth:i,closureHeight:d,panelWidth:s,panelHeight:c}=e||{},{getNodes:l,setNodes:b}=reactflow.useReactFlow(),f=Br.useRef(false),h=Br.useMemo(()=>l().filter(H=>H.parentId===r),[l,r]),v=Br.useMemo(()=>({id:r,type:"closure",position:{x:0,y:0},data:{...e,closureWidth:i||s,closureHeight:d||c}}),[r,e,i,d,s,c]),N=Br.useMemo(()=>i&&d?{width:i,height:d}:s&&c?{width:s,height:c}:h.length===0?{width:i||s||400,height:d||c||300}:Yo(v,h),[h,v,i,d,s,c]);Br.useEffect(()=>{if(i&&d||s&&c||f.current)return;let x=i||s,H=d||c,y=Math.abs((x||0)-N.width),P=Math.abs((H||0)-N.height);(y>1||P>1)&&(f.current=true,b($=>$.map(C=>C.id===r?{...C,data:{...C.data,closureWidth:N.width,closureHeight:N.height}}:C)),setTimeout(()=>{f.current=false;},0));},[r,N.width,N.height,i,d,s,c,b]);let T=N.width,w=N.height,I=Ee,F=n||a,W=T/2;return jsxRuntime.jsxs("div",{className:`closure-node ${o?"selected":""}`,style:{background:"transparent",border:"none",borderRadius:`${W}px ${W}px 12px 12px`,padding:0,width:`${T}px`,height:`${w}px`,color:"white",fontFamily:"monospace",fontSize:"12px",boxShadow:o?"0 0 0 2px #3b82f6":"0 2px 4px rgba(0,0,0,0.1)",position:"relative",display:"flex",flexDirection:"column",backgroundColor:"#1f2937",boxSizing:"border-box",overflow:"hidden"},children:[jsxRuntime.jsx("div",{style:{textAlign:"center",marginBottom:0,zIndex:2,background:"#374151",padding:"6px 12px",position:"relative",height:`${I}px`,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:"6px",borderRadius:`${W}px ${W}px 0 0`,borderBottom:"1px solid #4b5563"},children:jsxRuntime.jsx("div",{style:{fontWeight:"bold",fontSize:"11px"},children:F})}),jsxRuntime.jsx("div",{style:{position:"absolute",top:I,left:0,right:0,bottom:0,pointerEvents:"none",overflow:"visible"}})]})};function sn(e,o){if(!e.source||!e.target||!e.sourceHandle||!e.targetHandle)return {valid:true};let r=o.edges.some(w=>w.source===e.source&&w.sourceHandle===e.sourceHandle),a=o.edges.some(w=>w.target===e.target&&w.targetHandle===e.targetHandle);if(r)return {valid:false,reason:"Source port is already connected"};if(a)return {valid:false,reason:"Target port is already connected"};let n=e.sourceHandle,i=e.targetHandle,d=o.nodes.find(w=>w.id===e.source),s=o.nodes.find(w=>w.id===e.target),c=(w,I)=>{if(!w)return false;let F=w.startsWith("pwr")||w.startsWith("power"),W=I?.type==="vertical-pdu"&&w!=="mgmt-net-1";return F||W},l=(w,I)=>{if(!w)return false;if(I?.type==="vertical-pdu"&&w==="mgmt-net-1"||I?.type==="tube"&&w.startsWith("fiber-")||(I?.type==="tube"||I?.type==="cable")&&w.startsWith("tube-")||I?.type==="splice"&&(w==="left"||w==="right"))return true;let F=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("Fiber")||w.includes("Ports"),W=/^[A-Z0-9]+-\d+$/.test(w)&&!w.startsWith("pwr")&&!w.startsWith("power");return F||W},b=c(n,d),f=c(i,s),h=l(n,d),v=l(i,s);if(b&&v||f&&h)return {valid:false,reason:"Cannot connect network cable to power port"};if(b&&!f||f&&!b)return {valid:false,reason:"Power ports must connect to power-compatible ports"};let N=d?.type==="vertical-pdu",T=s?.type==="vertical-pdu";if(b||f){let w=N?s:T?d:null,I=N?d:T?s:null;if(w&&I&&o.edges.filter(x=>{let H=c(x.sourceHandle||""),y=c(x.targetHandle||""),P=x.source===w.id||x.target===w.id;return (H||y)&&P}).some(x=>x.source===I.id||x.target===I.id))return {valid:false,reason:"Dual-feed required: connect second power to a different PDU"}}return {valid:true}}function lt(e,o){if(!o)return;let r=typeof e=="string"?e.replace(/-(target|source)$/i,""):e,a=o.data??{},n=a.handleSideMap;if(n&&n[r])return n[r];if(r==="net-top"||r==="net-bottom")return "front";if(r==="pwr-left-1"||r==="pwr-left-2"||r==="net-right-1"||r==="net-right-2")return "rear";let i=Array.isArray(a.ports)?a.ports:[],d=Array.isArray(a.rearPorts)?a.rearPorts:[];if(r.startsWith("pwr")||r.includes("power"))return "rear";for(let c of i)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "front";for(let c of d)for(let l of c.ports||[])if((!!l.type&&String(l.type).includes("power")?l.label:`${c.name}-${l.label}`)===r)return "rear"}function Kt(e={},o={}){let r={nodes:e.nodes??[],edges:e.edges??[],debug:e.debug??false},a=new Set;return {getState:()=>r,setState:f=>{r={...r,...f},a.forEach(h=>h(r));},subscribe:f=>(a.add(f),()=>a.delete(f)),selectEdgeZIndex:f=>{let h=r.nodes.find(H=>H.id===f.target);if(!h||h.type!=="device")return 1e3;let v=h.data?.view||"front",N=lt(f.targetHandle||"",h);if(N)return v===N?1e3:500;let T=(f.targetHandle||"").toString(),w=T.toLowerCase(),I=w.startsWith("pwr")||w.startsWith("power"),F=w.startsWith("net-")||w.startsWith("port-")||w.startsWith("uplink-")||w.includes("fiber")||w.includes("ports"),W=/^[A-Z0-9]+-\d+$/i.test(T)&&!w.startsWith("pwr")&&!w.startsWith("power"),x=F||W;return I?v==="rear"?1e3:500:x?v==="front"?1e3:500:1e3},validateConnection:f=>(o.validateConnection||sn)(f,r),selectNodeById:f=>r.nodes.find(h=>h.id===f),selectConnectedEdges:f=>r.edges.filter(h=>h.source===f||h.target===f)}}function dn(e){let o=n=>e.subscribe(n),r=()=>e.getState();return Br.useSyncExternalStore(o,r,r)}function Jt(e){let o=a=>e.subscribe(a),r=()=>e.getState().nodes;return Br.useSyncExternalStore(o,r,r)}function Qt(e){let o=a=>e.subscribe(a),r=()=>e.getState().edges;return Br.useSyncExternalStore(o,r,r)}function Vo(e){return e.selectEdgeZIndex}function Xo(e){let o=300,r=(e.data.uHeight||42)*20,a=e.position.x,n=e.position.x+o,i=e.position.y,d=e.position.y+r;return {left:a,right:n,top:i,bottom:d}}function pt(e,o){let r=Xo(o);return e.x>=r.left&&e.x<=r.right&&e.y>=r.top&&e.y<=r.bottom}function ut(e,o){let r=null,a=1/0;for(let n of o){if(!pt(e,n))continue;let i=Math.sqrt(Math.pow(e.x-n.position.x,2)+Math.pow(e.y-n.position.y,2));i<a&&(a=i,r=n);}return r}function j(e){let{edges:o,connection:r,edgeType:a,selectEdgeZIndex:n,findBy:i,data:d}=e,s=i==="source"?r.sourceHandle:r.targetHandle,c=i==="source"?r.source:r.target;if(!s||!c)return null;let l=o.find(T=>i==="source"?T.source===c&&T.sourceHandle===s:T.target===c&&T.targetHandle===s);if(!l)return null;let b=o.filter(T=>T.id!==l.id),f=reactflow.addEdge(r,b),h=f[f.length-1],v=n({...r,id:h.id,type:a}),N={...h,type:a,zIndex:v,style:{...h.style,zIndex:v},data:d!==void 0?d:h.data};return [...f.slice(0,-1),N]}var kn=(e,o,r)=>({rack:a=>jsxRuntime.jsx(yt,{...a,onViewChange:e,onRackFaceChange:o,isDragOver:r?r()===a.id:false}),fiber:xt,device:Ct,"vertical-pdu":Et,splice:Dt,"splice-tray":Wt,tube:Lt,cable:Mt,coupler:Ut,"patch-panel":Xt,closure:Zt}),vn={fiber:Nt,power:kt,smoothstep:go,step:yo,"thick-cable":xo},Pn=({nodes:e,edges:o,initialNodes:r,initialEdges:a,onNodesChange:n,onEdgesChange:i,store:d,debug:s,onNodeClick:c,onEdgeClick:l,onViewChange:b,onRackFaceChange:f,className:h,style:v,alignRacksToBottom:N,colorMode:T="dark",onInit:w,onFlowMethods:I,showDownloadButton:F=false,downloadButtonPosition:W="top-right",downloadButtonText:x="Download Image",downloadButtonStyle:H,allowReconnectExisting:y=false,useSmoothstepEdgesForTubes:P=false})=>{let $=Array.isArray(e)&&Array.isArray(o),C=Br__default.default.useMemo(()=>d||Kt({nodes:$?e||[]:r||e||[],edges:$?o||[]:a||o||[],debug:s}),[d,$,s]),z=Jt(C),_=Qt(C),[R,M,V]=reactflow.useNodesState(z),[X,E,G]=reactflow.useEdgesState(_),D=Vo(C),ge=Br.useRef(null),{toObject:be,setViewport:ie,setNodes:he,setEdges:Ye,getNodes:ke}=reactflow.useReactFlow();Br.useEffect(()=>{I&&I({toObject:be,setViewport:ie,setNodes:t=>{he(t),C.setState({nodes:t});},setEdges:t=>{Ye(t),C.setState({edges:t});},toImage:t=>ge.current?htmlToImage.toPng(ge.current,t):Promise.reject(new Error("ReactFlow wrapper not available"))});},[I,be,ie,he,Ye,C]);let ft=Br.useCallback(()=>{if(!ge.current){s&&console.error("ReactFlow wrapper ref is not available");return}htmlToImage.toPng(ge.current,{filter:t=>!(t?.classList?.contains("react-flow__minimap")||t?.classList?.contains("react-flow__controls")||t?.classList?.contains("react-flow__attribution")||t?.classList?.contains("download-button")||t?.tagName==="BUTTON"),backgroundColor:T==="light"?"#ffffff":"#1a1a1a",pixelRatio:2}).then(t=>{let p=document.createElement("a");p.download=`network-diagram-${new Date().toISOString().split("T")[0]}.png`,p.href=t,p.click();}).catch(t=>{s&&console.error("Error downloading image:",t);});},[T,s]),[me,Ve]=Br.useState(null),no=Br.useRef(null),io=Br.useRef(b),ao=Br.useRef(f);Br.useEffect(()=>{io.current=b;},[b]),Br.useEffect(()=>{ao.current=f;},[f]),Br.useEffect(()=>{no.current=me;},[me]);let so=Br.useCallback(()=>no.current,[]),er=Br.useMemo(()=>kn((t,p)=>io.current?.(t,p),(t,p)=>ao.current?.(t,p),so),[so]),tr=Br.useMemo(()=>vn,[]),pe=Br.useRef(R);Br.useEffect(()=>{pe.current=R;},[R]);let L=Br.useRef(X);Br.useEffect(()=>{L.current=X;},[X]),Br.useEffect(()=>{M(z);},[z,M]),Br.useEffect(()=>{E(_);},[_,E]),Br.useEffect(()=>{$&&C.setState({nodes:e||[]});},[$,e,C]),Br.useEffect(()=>{$&&C.setState({edges:o||[]});},[$,o,C]),Br.useEffect(()=>{if(!N||!R||R.length===0)return;let t=R.filter(U=>U.type==="rack");if(t.length===0)return;let p=t.map(U=>{let ae=U.data?.uHeight||42,le=60+ae*20;return (U.position?.y||0)+le}),g=Math.min(...p),m=Math.max(...p);if(m-g<20)return;let u=m,A=R.map(U=>{if(U.type!=="rack")return U;let ae=U.data?.uHeight||42,le=60+ae*20,Z=(U.position?.y||0)+le,B=u-Z;return Math.abs(B)<5?U:{...U,position:{x:U.position?.x||0,y:(U.position?.y||0)+B}}});A.some((U,ee)=>U.position!==R[ee].position)&&M(A);},[N,R,M]);let Y=Br.useCallback(t=>pe.current.find(p=>p.id===t),[]),Xe=Br.useCallback((t,p)=>{if(!t||!p)return;let g=Y(t);if(!g)return;if(g.type==="tube"&&p.startsWith("fiber-")){let k=p.replace("fiber-",""),u=parseInt(k,10);if(u>=1&&u<=24){let A=zt(u),O=u>12;return {color:A,striped:O}}}if((g.type==="cable"||g.type==="tube")&&p.startsWith("tube-")){let k=p.replace("tube-",""),u=parseInt(k,10);if(u>=1&&u<=24){let A=te(u),O=u>12;return {color:A,striped:O}}}let m=g.data;if(m.color)return {color:m.color}},[Y]);Br.useEffect(()=>{E(t=>t.map(p=>{let g=D(p);return {...p,zIndex:g,style:{...p.style,zIndex:g}}}));},[R,E,D]),Br.useEffect(()=>{let t=R.map(g=>{if(g.type==="coupler"&&g.parentId){let m=Y(g.parentId);if(m&&(m.type==="patch-panel"||m.type==="closure")&&(!g.extent||g.extent!=="parent"))return {...g,extent:"parent"}}if(g.type==="splice"&&g.parentId&&g.data.holderPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let m=Y(g.parentId);if(m&&m.type==="splice-tray"){let k=Me(m,g.data.holderPosition);return {...g,position:k}}}if(g.type==="device"&&g.parentId&&g.data.uPosition&&(!g.position||g.position.x===0&&g.position.y===0)){let m=Y(g.parentId);if(m){let k=De(m,g.data.uPosition);return {...g,position:k}}}return g});t.some((g,m)=>{let k=R[m];return g.extent!==k.extent||g.position?.x!==k.position?.x||g.position?.y!==k.position?.y})&&M(t);},[R,M,Y]);let or=Br.useCallback(t=>{let p=t.map(g=>{if(g.type==="position"&&g.position){let m=Y(g.id);if(m&&m.type==="coupler"&&m.parentId){let k=Y(m.parentId);if(k&&(k.type==="patch-panel"||k.type==="closure")){if(!m.extent||m.extent!=="parent"){let u={...m,extent:"parent"};M(A=>A.map(O=>O.id===m.id?u:O));}return {...g,position:m.position||{x:0,y:0}}}}if(m&&m.type==="splice"&&m.parentId){let k=Y(m.parentId);if(k&&k.type==="splice-tray"){let u=_t(m,k,g.position,pe.current);if(u.holderPosition!==void 0){let A={...m,data:{...m.data,holderPosition:u.holderPosition}};M(O=>O.map(U=>U.id===m.id?A:U));}return {...g,position:{x:u.x,y:u.y}}}}if(m&&m.type==="device"&&m.parentId){let k=Y(m.parentId);if(k){let u=ht(m,k,g.position,pe.current);if(u.uPosition!==void 0){let A={...m,data:{...m.data,uPosition:u.uPosition}};M(O=>O.map(U=>U.id===m.id?A:U));}return {...g,position:{x:u.x,y:u.y}}}}if(m&&m.type==="device"&&m.parentId){let k=Y(m.parentId);if(k){let u=k;if(!pt(g.position,u)){let A=g.position.x+u.position.x,O=g.position.y+u.position.y,U={...m,parentId:void 0,extent:void 0,data:{...m.data,uPosition:void 0}};return M(ee=>ee.map(ae=>ae.id===m.id?U:ae)),{...g,position:{x:A,y:O}}}}}}return g});V(p);},[V,M,Y]),rr=Br.useCallback((t,p)=>{Ve(null);},[]),nr=Br.useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let m=pe.current.filter(u=>u.type==="rack").map(u=>u),k=ut(p.position,m);Ve(k?.id??null);}else Ve(null);},[]),ir=Br.useCallback((t,p,g)=>{if(p.type==="device"&&!p.parentId){let m=pe.current.filter(u=>u.type==="rack").map(u=>u),k=ut(p.position,m);if(k){let u=p.position.x-k.position.x,A=p.position.y-k.position.y,O={...p,parentId:k.id,extent:"parent",position:{x:u,y:A},data:{...p.data,uPosition:1}},U=pe.current.map(ee=>ee.id===p.id?O:ee);M(U),$||C.setState({nodes:U});}}Ve(null);},[M,$,C]),ar=Br.useCallback(t=>{if(!t.source||!t.target||!t.sourceHandle||!t.targetHandle)return true;let p=Y(t.source),g=Y(t.target);if(p?.type==="tube"&&g?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect fibres within tubes",t),false;if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-")&&(g?.type==="cable"||g?.type==="tube")&&t.targetHandle.startsWith("tube-"))return s&&console.log("Connection rejected: Cannot connect individual fibre to cable/tube tube handle",t),false;if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-")&&g?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return s&&console.log("Connection rejected: Cannot connect cable/tube tube handle to individual fibre",t),false;if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")){if(L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle||u.source===t.target&&u.sourceHandle===t.targetHandle))return s&&console.log("Splice handle already connected, will replace",t),true;s&&console.log("Allowing connection to splice handle",t);}if(p?.type==="tube"&&t.sourceHandle.startsWith("fiber-"))return g?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect to splices",t),false):L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube fiber handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube fiber handle to splice",t),true);if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle.startsWith("tube-"))return t.targetHandle.startsWith("tube-")?L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Tube-level handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube-level handle to tube handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect to other tube handles",t),false);if(p?.type==="splice"&&t.sourceHandle==="right"){if(L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle||u.target===t.source&&u.targetHandle===t.sourceHandle))return s&&console.log("Splice source handle already connected, will replace",t),true;s&&console.log("Allowing connection from splice source handle",t);}if(g?.type==="tube"&&t.targetHandle.startsWith("fiber-"))return p?.type!=="splice"?(s&&console.log("Connection rejected: Tube fiber handles can only connect from splices",t),false):L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube fiber target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to tube fiber handle",t),true);if((g?.type==="cable"||g?.type==="tube")&&t.targetHandle.startsWith("tube-"))return t.sourceHandle.startsWith("tube-")?L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Tube-level target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from tube handle to tube-level handle",t),true):(s&&console.log("Connection rejected: Tube handles can only connect from other tube handles",t),false);if(p?.type==="coupler"&&(t.sourceHandle?.startsWith("left-")||t.sourceHandle?.startsWith("right-")))return g?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect to splices",t),false):t.targetHandle!=="left"&&t.targetHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect to splice left/right handles",t),false):L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle)?(s&&console.log("Coupler handle already connected, will replace",t),true):(s&&console.log("Allowing connection from coupler handle to splice",t),true);if(g?.type==="coupler"&&(t.targetHandle?.startsWith("left-")||t.targetHandle?.startsWith("right-")))return p?.type!=="splice"?(s&&console.log("Connection rejected: Coupler handles can only connect from splices",t),false):t.sourceHandle!=="left"&&t.sourceHandle!=="right"?(s&&console.log("Connection rejected: Coupler can only connect from splice left/right handles",t),false):L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle)?(s&&console.log("Coupler target handle already connected, will replace",t),true):(s&&console.log("Allowing connection from splice to coupler handle",t),true);if(t.source&&t.sourceHandle&&L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle already connected, will replace",t),true;if(t.target&&t.targetHandle&&L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle already connected, will replace",t),true;if((p?.type==="cable"||g?.type==="cable")&&(t.sourceHandle==="cable-button"||t.targetHandle==="cable-button"))return t.sourceHandle!=="cable-button"||t.targetHandle!=="cable-button"?(s&&console.log("Connection rejected: Cable button handles can only connect to other cable button handles",t),false):L.current.find(A=>A.source===t.source&&A.sourceHandle===t.sourceHandle)?(s&&console.log("Cable button source handle already connected, will replace",t),true):L.current.find(A=>A.target===t.target&&A.targetHandle===t.targetHandle)?(s&&console.log("Cable button target handle already connected, will replace",t),true):(s&&console.log("Allowing connection between cable button handles",t),true);let m=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!m.valid&&y){if(t.source&&t.sourceHandle&&L.current.find(u=>u.source===t.source&&u.sourceHandle===t.sourceHandle))return s&&console.log("Source handle has existing edge, will replace",t),true;if(t.target&&t.targetHandle&&L.current.find(u=>u.target===t.target&&u.targetHandle===t.targetHandle))return s&&console.log("Target handle has existing edge, will replace",t),true}return s&&!m.valid&&console.log("Connection rejected by store validation:",m.reason,t),m.valid},[Y,C,s,y]),sr=Br.useCallback(t=>{let p=Y(t.source),g=Y(t.target),m=p?.type==="vertical-pdu",k=p?.data,u=p?.type==="device"&&k?.deviceType==="switch",A=!!t.targetHandle&&(t.targetHandle.startsWith("pwr")||t.targetHandle.startsWith("power")),O=!!t.targetHandle&&(t.targetHandle.startsWith("net-")||t.targetHandle.startsWith("port-")||/^[A-Z0-9]+-\d+$/i.test(t.targetHandle)),U=p?.type==="tube"&&g?.type==="cable",ee=p?.type==="cable"&&g?.type==="tube",ae=U||ee,le=t.sourceHandle==="cable-button"&&t.targetHandle==="cable-button",Z="fiber";m&&A?Z="power":le?Z="thick-cable":ae&&(Z=P?"smoothstep":"fiber");let B;if((Z==="fiber"||Z==="smoothstep")&&!m){let S=Xe(t.source,t.sourceHandle);S&&(B={color:S.color,striped:S.striped});}else if(Z==="thick-cable"&&le){let S=p?.data;B={color:S?.color||(S?.tubeStartIndex?te(S.tubeStartIndex):"#6366f1")};}if(t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if(g?.type==="splice"&&(t.targetHandle==="left"||t.targetHandle==="right")&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}if(t.targetHandle==="right"&&(S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B}),S)){E(S);return}}if(p?.type==="splice"&&t.sourceHandle==="right"&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}if(S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B}),S){E(S);return}}if(p?.type==="tube"&&t.sourceHandle?.startsWith("fiber-")&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(g?.type==="tube"&&t.targetHandle?.startsWith("fiber-")&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if((p?.type==="cable"||p?.type==="tube")&&t.sourceHandle?.startsWith("tube-")&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if((g?.type==="cable"||g?.type==="tube")&&t.targetHandle?.startsWith("tube-")&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if(le&&t.source&&t.sourceHandle&&t.target&&t.targetHandle){let S=p?.data,q=S?.color||(S?.tubeStartIndex?te(S.tubeStartIndex):"#6366f1"),ue=j({edges:L.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:D,findBy:"source",data:{color:q}});if(ue){E(ue);return}if(ue=j({edges:L.current,connection:t,edgeType:"thick-cable",selectEdgeZIndex:D,findBy:"target",data:{color:q}}),ue){E(ue);return}}if(m&&A&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"power",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}if(u&&O&&t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}let Re=C.validateConnection({source:t.source??null,target:t.target??null,sourceHandle:t.sourceHandle??null,targetHandle:t.targetHandle??null});if(!Re.valid){if(y){if(t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(t.target&&t.targetHandle){let S=j({edges:L.current,connection:t,edgeType:Z,selectEdgeZIndex:D,findBy:"target",data:B});if(S){E(S);return}}}if(m&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:A?"power":"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}if(u&&t.source&&t.sourceHandle){let S=j({edges:L.current,connection:t,edgeType:"fiber",selectEdgeZIndex:D,findBy:"source",data:B});if(S){E(S);return}}s&&console.warn(`Connection rejected: ${Re.reason}`);return}let ve={...t,type:Z,zIndex:D({...t,id:"temp-id"}),data:B};E(S=>{let q=reactflow.addEdge(ve,S),ue=q[q.length-1];return ue&&(lo(bt=>new Set(bt).add(ue.id)),setTimeout(()=>{lo(bt=>{let po=new Set(bt);return po.delete(ue.id),po});},1e3)),q});},[E,C,D,Y,s,Xe,y,P]),dr=Br.useCallback((t,p)=>{if(!p.source||!p.target||!p.sourceHandle||!p.targetHandle)return;let g=t.sourceHandle||"",m=t.targetHandle||"",k=p.sourceHandle||"",u=p.targetHandle||"";if(g.startsWith("tube-")&&k!==g){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}if(m.startsWith("tube-")&&u!==m){s&&console.log("Edge update blocked: Cannot disconnect tube handle",{oldEdge:t,newConnection:p});return}let A=Y(p.source),O=Y(p.target),U=A?.type==="vertical-pdu",ee=!!p.targetHandle&&(p.targetHandle.startsWith("pwr")||p.targetHandle.startsWith("power")),ae=A?.type==="tube"&&O?.type==="cable",le=A?.type==="cable"&&O?.type==="tube",Z=ae||le,B;U&&ee?B="power":Z?B=P?"smoothstep":"fiber":B="fiber";let Re;if((B==="fiber"||B==="smoothstep")&&!U){let ve=Xe(p.source,p.sourceHandle);ve&&(Re={color:ve.color,striped:ve.striped});}E(ve=>ve.map(q=>q.id===t.id?{...q,source:p.source,target:p.target,sourceHandle:p.sourceHandle,targetHandle:p.targetHandle,type:B,data:Re!==void 0?{...q.data,...Re}:q.data,zIndex:D({...p,id:q.id,type:B}),style:{...q.style,zIndex:D({...p,id:q.id,type:B})}}:q));},[E,Y,Xe,D,P,s]),cr=Br.useCallback((t,p)=>{let g=t.metaKey||t.ctrlKey;if(p.type==="tube"&&p.parentId&&!g){let k=ke().find(u=>u.id===p.parentId&&u.type==="cable");if(k){M(u=>u.map(A=>({...A,selected:A.id===k.id}))),c&&c(k);return}}if(g&&p.type==="device"){let m=p.data||{},k=m.view||(Array.isArray(m.rearPorts)&&m.rearPorts.length>0?"rear":"front"),u=k==="front"?"rear":"front";s&&console.log(`Command+click: Toggling device ${p.id} from ${k} to ${u}`),b&&b(p.id,u),c&&c(p);}else c&&c(p);},[b,c,s,ke,M]),lr=Br.useCallback(()=>{},[]),pr=Br.useCallback((t,p)=>{l&&l(p);},[l]),[ce,gt]=Br.useState(null),[co,lo]=Br.useState(new Set);reactflow.useOnSelectionChange({onChange:({nodes:t})=>{if(t&&t.length===1){let p=t[0];if(p.type==="tube"&&p.parentId){let m=ke().find(k=>k.id===p.parentId&&k.type==="cable");if(m){gt(m),M(k=>k.map(u=>({...u,selected:u.id===m.id}))),c&&c(m);return}}gt(p),c&&c(p);}else gt(null),c&&c(null);}});let ur=Br.useCallback((t,{nodeId:p,handleType:g})=>{s&&console.log("Connection started from",{nodeId:p,handleType:g});},[s]),fr=Br.useCallback(t=>{s&&console.log("Connection ended",t);},[s]),gr=Br.useCallback(()=>{if(!ce)return;let t=Y(ce.id);if(t){if(t.type==="rack"){let m=((t.data||{}).face||"front")==="front"?"rear":"front";f?(f(t.id,m),b&&ke().filter(u=>u.parentId===t.id).forEach(u=>{b(u.id,m);})):M(k=>k.map(u=>u.id===t.id?{...u,data:{...u.data,face:m}}:u.parentId===t.id?{...u,data:{...u.data,view:m}}:u));return}if(t.type==="device"){let p=t.data||{},g=Array.isArray(p.rearPorts)&&p.rearPorts.length>0,m=Array.isArray(p.ports)&&p.ports.length>0,u=(p.view||(g&&!m?"rear":"front"))==="front"?"rear":"front";b?b(t.id,u):M(A=>A.map(O=>O.id===t.id?{...O,data:{...O.data,view:u}}:O));}}},[ce,Y,f,b,M,ke]),br=Br.useMemo(()=>X.map(t=>{let p=t,g=Y(String(p.source)),m=Y(String(p.target)),k=lt(p.sourceHandle||"",g),u=lt(p.targetHandle||"",m),A=g&&g.data?.view,O=m&&m.data?.view,U=g?.type==="device"&&A==="rear",ee=m?.type==="device"&&O==="rear",B=U&&k!=="rear"&&(ee&&u!=="rear")?{...t.style,opacity:0,pointerEvents:"none",zIndex:0}:t.style;return {...t,style:B,className:co.has(t.id)?"edge-connecting":t.className}}),[X,co,Y]);return jsxRuntime.jsxs("div",{ref:ge,className:`${h||""} ${T==="light"?"react-flow-light":"react-flow-dark"}`,style:{width:"100%",height:"100%",...v},children:[jsxRuntime.jsxs(reactflow.ReactFlow,{nodes:R,edges:br,onNodesChange:t=>{or(t),$?n&&n(pe.current):C.setState({nodes:pe.current});},onEdgesChange:t=>{let p=t.filter(g=>{if(g.type==="remove"){let m=L.current.find(k=>k.id===g.id);if(m){let k=m.sourceHandle||"",u=m.targetHandle||"";if(k.startsWith("tube-")||u.startsWith("tube-"))return s&&console.log("Edge deletion blocked: Edge connected to tube handle is not detachable",m),false}}return true});p.length>0&&(G(p),$?i&&i(L.current):C.setState({edges:L.current}));},onConnect:sr,onConnectStart:ur,onConnectEnd:fr,onEdgeUpdate:dr,isValidConnection:ar,onNodeClick:cr,onNodeDoubleClick:lr,onNodeDragStart:rr,onNodeDrag:nr,onNodeDragStop:ir,onEdgeClick:pr,onInit:w,nodeTypes:er,edgeTypes:tr,defaultEdgeOptions:{zIndex:1e3,reconnectable:true},nodesDraggable:true,nodesConnectable:true,elementsSelectable:true,selectNodesOnDrag:false,fitView:true,proOptions:{hideAttribution:true},children:[jsxRuntime.jsx(reactflow.Background,{color:T==="light"?"#e5e5e5":"#2a2a2a"}),jsxRuntime.jsx(reactflow.Controls,{}),jsxRuntime.jsx(reactflow.MiniMap,{}),jsxRuntime.jsx(reactflow.Panel,{position:"bottom-right",className:"react-networks-attribution",children:jsxRuntime.jsx("a",{href:"https://github.com/MP70/react-networks",target:"_blank",rel:"noopener noreferrer",className:"react-networks-attribution-link",children:"react-networks"})})]}),F&&jsxRuntime.jsx("button",{className:"download-button",onClick:ft,style:{position:"absolute",top:W.includes("top")?"10px":"auto",bottom:W.includes("bottom")?"10px":"auto",right:W.includes("right")?"10px":"auto",left:W.includes("left")?"10px":"auto",zIndex:1e3,background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:"4px",padding:"0.5rem 0.75rem",fontSize:"0.875rem",cursor:"pointer",transition:"all 0.2s ease",...H},children:x}),ce&&(ce.type==="rack"||ce.type==="device")&&jsxRuntime.jsx("div",{style:{position:"absolute",top:12,right:12,display:"flex",gap:8,zIndex:2e3},children:jsxRuntime.jsx("button",{onClick:t=>{t.preventDefault(),gr();},style:{background:"#374151",color:"#e5e7eb",border:"1px solid #4b5563",borderRadius:4,padding:"6px 10px",fontSize:11,fontFamily:"monospace",cursor:"pointer"},title:(()=>{let t=ce.data;if(ce.type==="rack")return (t?.face||"front")==="front"?"Switch to rear":"Switch to front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!g?"rear":"front"))==="front"?"Switch to rear":"Switch to front"}})(),children:(()=>{let t=ce.data;if(ce.type==="rack")return (t?.face||"front")==="front"?"\u21C4 Rear":"\u21C4 Front";{let p=Array.isArray(t?.rearPorts)&&t.rearPorts.length>0,g=Array.isArray(t?.ports)&&t.ports.length>0;return (t?.view||(p&&!g?"rear":"front"))==="front"?"\u21C4 Rear":"\u21C4 Front"}})()})})]})},Sn=e=>jsxRuntime.jsx(reactflow.ReactFlowProvider,{children:jsxRuntime.jsx(Pn,{...e})});var Zo=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}}),Ko=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}}),qo=e=>{let o=n=>{if(!n)return;if(typeof n=="string")return n;let i=n.device;return typeof i=="object"&&i?i.id:i},r=o(e.termination_a),a=o(e.termination_b);return {id:`cable-${e.id}`,source:`device-${r}`,target:`device-${a}`,type:"fiber",data:{bandwidth:e.type?.label??e.bandwidth,length:e.length||0,color:e.color,inventoryId:e.id,inventoryType:"cable",status:typeof e.status=="object"&&e.status?e.status.value:e.status,terminationA:typeof e.termination_a=="object"&&e.termination_a?e.termination_a.name:e.termination_a,terminationB:typeof e.termination_b=="object"&&e.termination_b?e.termination_b.name:e.termination_b}}},Hn=e=>{let o=[],r=[];return e.racks.forEach(a=>o.push(Zo(a))),e.devices.forEach(a=>o.push(Ko(a))),e.cables.forEach(a=>r.push(qo(a))),{nodes:o,edges:r}},Cn=e=>{let o=e.filter(n=>n.type==="rack"),r=e.filter(n=>n.type==="device"),a=e.filter(n=>!["rack","device"].includes(n.type));return o.forEach((n,i)=>{n.position={x:i*300,y:100};}),r.forEach(n=>{if(n.parentId){let i=o.find(d=>d.id===n.parentId);if(i){let d=n.data.uPosition||1,s=n.data.uHeight||1;n.position={x:i.position.x+50,y:i.position.y+d*20-s*10};}}else n.position={x:Math.random()*400+100,y:Math.random()*200+50};}),a.forEach((n,i)=>{n.position={x:i*150+100,y:300};}),e};var We=class extends Error{constructor(r,a,n,i,d){super(`Device placement conflict: ${a} at U${n}-${n+i-1} in rack ${r}${d?` conflicts with ${d}`:""}`);this.rackId=r;this.deviceId=a;this.uPosition=n;this.uHeight=i;this.conflictWith=d;this.name="DevicePlacementError";}};function oo(e,o={}){let r=[],a=[];for(let n of e.devices)n.unit+n.height-1>e.units&&a.push({deviceId:n.id,uPosition:n.unit,uHeight:n.height,rackUHeight:e.units});for(let n=0;n<e.devices.length;n++){let i=e.devices[n],d=i.unit,s=i.unit+i.height-1;for(let c=n+1;c<e.devices.length;c++){let l=e.devices[c],b=l.unit,f=l.unit+l.height-1;d<=f&&s>=b&&r.push({deviceId:i.id,uPosition:i.unit,uHeight:i.height,conflictWith:l.id});}}return {isValid:r.length===0&&a.length===0,conflicts:r,outOfBounds:a}}function Jo(e,o,r={}){let{deviceTypeMapping:a={}}=r,n=a[e.type]||"device",i=De(o,e.unit,e.height);return {id:e.id,type:n,position:i,parentId:o.id,extent:"parent",data:{label:e.name,status:"active",deviceType:e.type,uHeight:e.height,uPosition:e.unit,width:e.width||"full",role:e.role,ports:e.ports,rearPorts:e.rearPorts,connections:e.connections}}}function En(e){return {id:e.id,type:"rack",position:e.position,data:{label:e.name,status:"active",uHeight:e.units,uNumberingDirection:e.uNumberingDirection||"bottom-up",customHeaderText:e.customHeaderText,ports:[]}}}function Rn(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=oo(d,o);if(!s.isValid&&r==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Device ${l.deviceId} at U${l.uPosition}-${l.uPosition+l.uHeight-1} exceeds rack height (${l.rackUHeight}U)`);}),new We(d.id,s.conflicts[0]?.deviceId||s.outOfBounds[0]?.deviceId||"unknown",s.conflicts[0]?.uPosition||s.outOfBounds[0]?.uPosition||1,s.conflicts[0]?.uHeight||s.outOfBounds[0]?.uHeight||1)}}for(let d of e){let s=En(d);n.push(s);for(let c of d.devices)try{let l=Jo(c,s,o);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let b=Ze(s,{id:c.id,data:{label:c.name,uHeight:c.height}},i,c.unit);if(b!==c.unit){console.warn(`Device ${c.id} moved from U${c.unit} to U${b} due to conflict`);let f={...c,unit:b},h=Jo(f,s,o);i.push(h);}else throw new We(d.id,c.id,c.unit,c.height)}}}return n.push(...i),n}function Tn(e){let o=[],r=e.filter(a=>a.type==="rack");for(let a of r){let i=e.filter(d=>d.type==="device"&&d.parentId===a.id).map(d=>({id:d.id,name:d.data.label,unit:d.data.uPosition||1,height:d.data.uHeight||1,type:d.data.deviceType||"server",width:d.data.width,ports:d.data.ports,connections:d.data.connections}));o.push({id:a.id,name:a.data.label,position:a.position,units:a.data.uHeight||42,uNumberingDirection:a.data.uNumberingDirection||"bottom-up",customHeaderText:a.data.customHeaderText,devices:i});}return o}function Dn(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,devices:n.devices.map(i=>i.id!==r?i:{...i,unit:a})})}function In(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!oo({...i,devices:[...i.devices,r]},a).isValid)throw new We(o,r.id,r.unit,r.height);return {...i,devices:[...i.devices,r]}})}function $n(e,o,r){return e.map(a=>a.id!==o?a:{...a,devices:a.devices.filter(n=>n.id!==r)})}var ze=class extends Error{constructor(r,a,n,i){super(`Splice placement conflict: ${a} at holder ${n} in tray ${r}${i?` conflicts with ${i}`:""}`);this.trayId=r;this.spliceId=a;this.holder=n;this.conflictWith=i;this.name="SplicePlacementError";}};function ro(e,o={}){let r=[],a=[];for(let n of e.splices)(n.holder<1||n.holder>Ne)&&a.push({spliceId:n.id,holder:n.holder,max:Ne});for(let n=0;n<e.splices.length;n++){let i=e.splices[n];for(let d=n+1;d<e.splices.length;d++){let s=e.splices[d];i.holder===s.holder&&r.push({spliceId:i.id,holder:i.holder,conflictWith:s.id});}}return {isValid:r.length===0&&a.length===0,conflicts:r,outOfBounds:a}}function Qo(e,o){let r=Me(o,e.holder);return {id:e.id,type:"splice",position:r,parentId:o.id,extent:"parent",data:{label:e.name,holderPosition:e.holder,lossDb:e.lossDb}}}function _n(e){return {id:e.id,type:"splice-tray",position:e.position,data:{label:e.name,status:"active"}}}function Fn(e,o={}){let{conflictPolicy:r="strict",validatePlacements:a=true}=o,n=[],i=[];if(a)for(let d of e){let s=ro(d,o);if(!s.isValid&&r==="strict"){let c=[];throw s.conflicts.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} conflicts with ${l.conflictWith}`);}),s.outOfBounds.forEach(l=>{c.push(`Splice ${l.spliceId} at holder ${l.holder} is out of bounds (max: ${l.max})`);}),new ze(d.id,s.conflicts[0]?.spliceId||s.outOfBounds[0]?.spliceId||"unknown",s.conflicts[0]?.holder||s.outOfBounds[0]?.holder||1)}}for(let d of e){let s=_n(d);n.push(s);for(let c of d.splices)try{let l=Qo(c,s);i.push(l);}catch(l){if(r==="strict")throw l;if(r==="nearest"){let b=[...n,...i],f=tt(s,{id:c.id,data:{label:c.name,holderPosition:c.holder}},b,c.holder);if(f!==c.holder){console.warn(`Splice ${c.id} moved from holder ${c.holder} to holder ${f} due to conflict`);let h={...c,holder:f},v=Qo(h,s);i.push(v);}else throw new ze(d.id,c.id,c.holder)}}}return n.push(...i),n}function An(e){let o=[],r=e.filter(a=>a.type==="splice-tray");for(let a of r){let i=e.filter(d=>d.type==="splice"&&d.parentId===a.id).map(d=>({id:d.id,name:d.data.label,holder:d.data.holderPosition||1,lossDb:d.data.lossDb}));o.push({id:a.id,name:a.data.label,position:a.position,splices:i});}return o}function Wn(e,o,r,a){return e.map(n=>n.id!==o?n:{...n,splices:n.splices.map(i=>i.id!==r?i:{...i,holder:a})})}function zn(e,o,r,a={}){let{conflictPolicy:n="strict"}=a;return e.map(i=>{if(i.id!==o)return i;if(n==="strict"&&!ro({...i,splices:[...i.splices,r]},a).isValid)throw new ze(o,r.id,r.holder);return {...i,splices:[...i.splices,r]}})}function Ln(e,o,r){return e.map(a=>a.id!==o?a:{...a,splices:a.splices.filter(n=>n.id!==r)})}
2
+ exports.COUPLERS_PER_PANEL=Xr;exports.COUPLER_SLOT_HEIGHT_PX=dt;exports.COUPLER_WIDTH_PX=jr;exports.CableNode=Mt;exports.ClosureNode=Zt;exports.CouplerNode=Ut;exports.DeviceNode=Ct;exports.DevicePlacementError=We;exports.FIBER_COLORS_12=Ho;exports.FiberEdge=Nt;exports.FiberNode=xt;exports.NetworkDiagram=Sn;exports.PANEL_BORDER_WIDTH=Ao;exports.PANEL_HEADER_HEIGHT=Ee;exports.PANEL_HEIGHT_PX=st;exports.PANEL_PADDING=fe;exports.PANEL_TUBE_TRAY_SPACING=Wo;exports.PANEL_WIDTH_PX=at;exports.POWER_CONNECTORS=Pt;exports.PatchPanelNode=Xt;exports.PowerEdge=kt;exports.RackNode=yt;exports.SpliceNode=Dt;exports.SplicePlacementError=ze;exports.SpliceTrayNode=Wt;exports.TubeNode=Lt;exports.VerticalPDU=Et;exports.Width=wo;exports.addDeviceToRack=In;exports.addSpliceToTray=zn;exports.baseColorFor=te;exports.buildNodesFromRackConfig=Rn;exports.buildNodesFromSpliceConfig=Fn;exports.calculateCouplerRightX=Zr;exports.calculateCouplerSlotSpacing=qr;exports.calculateCouplerSpacing=Oo;exports.calculateDevicePositionFromU=De;exports.calculatePanelDimensions=Ot;exports.calculateSlotPositionFromY=Uo;exports.calculateSplicePositionFromNumber=Me;exports.calculateYFromSlotPosition=Bo;exports.createNetworkDiagramStore=Kt;exports.createRackConfigFromNodes=Tn;exports.createSpliceConfigFromNodes=An;exports.fiberSolidOrStriped=Ue;exports.findNearestRack=ut;exports.findNextAvailableHolderPosition=tt;exports.findNextAvailableUPosition=Ze;exports.generateLayout=Cn;exports.getConnectorConfig=Qe;exports.getCouplerDimensions=Bt;exports.getDeviceConnectorType=et;exports.getFiberColor=zt;exports.getInnerContentWidth=Mo;exports.getPDUPortType=St;exports.getPanelHeight=Gr;exports.getPanelWidth=Lo;exports.getPowerPortStyle=Ie;exports.getRackBounds=Xo;exports.getStatusColor=se;exports.getTrayDimensions=zo;exports.getTubeDimensions=ct;exports.inventoryCableToNetworkEdge=qo;exports.inventoryDeviceToNetworkNode=Ko;exports.inventoryRackToNetworkNode=Zo;exports.inventoryToNetworkDiagram=Hn;exports.isHighPowerConnector=zr;exports.isPointInRack=pt;exports.isStriped=Co;exports.isUPositionAvailable=mt;exports.removeDeviceFromRack=$n;exports.removeSpliceFromTray=Ln;exports.replaceEdge=j;exports.snapToCouplerPosition=Kr;exports.snapToSplicePosition=_t;exports.snapToUPosition=ht;exports.updateDeviceUPosition=uo;exports.updateDeviceUPositionInSchema=Dn;exports.updateSpliceHolderPosition=Wn;exports.useDiagramEdges=Qt;exports.useDiagramNodes=Jt;exports.useNetworkDiagram=dn;exports.validateAndSnapDevice=mr;exports.validateRackDevicePlacements=oo;exports.validateSplicePlacements=ro;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map