import{d as s,H as N,aS as f,r as x,j as t,cY as I,cO as g,e as b,D as C,R as p,q as l}from"./index-66XtK6kJ.js";import{H as R}from"./HelpLink-DrvsxU7S.js";import{P as i}from"./PageHeader-quqXpI4T.js";import{h as U,k as A}from"./useNetworks-CRf3hLWI.js";import{U as L}from"./UsedByItem-BR7-4Zz2.js";import{I as P}from"./InstanceIpEdit-B-0RUDzY.js";import{N as T}from"./NetworkRichChip--TmCCnRo.js";import"./useImages-y_oimAtQ.js";import"./image-registries-Dmf_bwCV.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-BYCO4lqY.js";import"./ProfileResourceLimits-Bgn_DF19.js";const v=()=>{const y=s.useNotify(),{project:o}=N(),{data:a=[],error:c,isLoading:m}=f({queryKey:[l.projects,o,l.networkAllocations],queryFn:async()=>A(o??"default")}),{data:u}=U(o??""),w=e=>u?.find(d=>d.name===e.network)?.type;if(x.useEffect(()=>{c&&y.failure("Loading network allocations failed",c)},[c]),!o)return t.jsx(t.Fragment,{children:"Missing project"});const h=[{content:"Type",sortKey:"type",className:"type"},{content:"Used by",sortKey:"usedBy",className:"usedBy"},{content:"Network",sortKey:"network",className:"network"},{content:"NAT",sortKey:"nat",className:"nat"},{content:"MAC address",sortKey:"hwaddress",className:"hwaddr"},{content:"Address",sortKey:"address",className:"address"}],j=a.map(e=>{const d=I(e.type,[e.used_by]),n=d.length===1?d[0]:null,k=r=>e.type==="instance"?`${p}/ui/project/${encodeURIComponent(r.project)}/instance/${encodeURIComponent(r.name)}`:e.type==="network"?`${p}/ui/project/${encodeURIComponent(r.project)}/network/${encodeURIComponent(r.name)}`:e.type==="network-forward"&&r.network?`${p}/ui/project/${encodeURIComponent(r.project)}/network/${encodeURIComponent(r.network)}/forwards`:"";return{columns:[{content:e.type,role:"cell",className:"type"},{content:n&&t.jsx(L,{item:n,activeProject:o,type:e.type,to:k(n)}),role:"rowheader",className:"usedBy"},{content:t.jsx(T,{networkName:e.network,projectName:o}),role:"cell",className:"network"},{content:e.nat?"Yes":"No",role:"cell",className:"nat"},{content:e.hwaddr,role:"cell",className:"hwaddr"},{content:e.type==="instance"&&n&&g.includes(w(e)??"")?t.jsx(P,{address:e.addresses,instanceName:n.name,projectName:n.project}):t.jsx(t.Fragment,{children:e.addresses}),role:"cell",className:"address"}],sortData:{usedBy:e.used_by.toLowerCase(),type:e.type,nat:e.nat,hwaddress:e.hwaddr,network:e.network?.toLowerCase(),address:e.addresses}}});return m?t.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):t.jsxs(s.CustomLayout,{header:t.jsx(i,{children:t.jsx(i.Left,{children:t.jsx(i.Title,{children:t.jsx(R,{docPath:"/howto/network_ipam/",title:"Learn more about IPAM",children:"IP Address Management"})})})}),children:[t.jsx(b,{}),t.jsxs(s.Row,{children:[a.length>0&&t.jsx(s.ScrollableTable,{dependencies:a,tableId:"network-ipam-table",belowIds:["status-bar"],children:t.jsx(s.MainTable,{className:"network-ipam-table",id:"network-ipam-table",headers:h,rows:j,defaultSort:"address",defaultSortDirection:"ascending",responsive:!0,sortable:!0,emptyStateMsg:"No data to display"})}),!m&&a.length===0&&t.jsxs(s.EmptyState,{className:"empty-state",image:t.jsx(s.Icon,{className:"empty-state-icon",name:"exposed"}),title:"No network allocations found",children:[t.jsx("p",{children:"There are no network allocations in this project."}),t.jsx("p",{children:t.jsx(C,{docPath:"/howto/network_ipam/",hasExternalIcon:!0,children:"Learn more about network allocations"})})]})]})]})};export{v as default};
