import{d as s,H as N,aT 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-Dz5JRQhj.js";import{H as R}from"./HelpLink-IKbgKG-X.js";import{P as i}from"./PageHeader-DVZxT41l.js";import{h as U,k as A}from"./useNetworks-kWi7yZ5O.js";import{U as L}from"./UsedByItem-DL7zobGp.js";import{I as P}from"./InstanceIpEdit-DvikMKyC.js";import{N as T}from"./NetworkRichChip-Cbl_TiNv.js";import"./useImages-D_Klrmxd.js";import"./image-registries-8O1zsvZX.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-SxdUk4Mb.js";import"./ProfileResourceLimits-Bjfzp666.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};
