import{d as s,H as N,aP as f,r as x,j as t,cU as I,cK as g,e as b,D as U,R as p,q as l}from"./index-C88DWJny.js";import{H as C}from"./HelpLink-c8Zoz7ma.js";import{P as i}from"./PageHeader-6_Og6mu3.js";import{h as P,k as R}from"./useNetworks-C8634WBO.js";import{U as A}from"./UsedByItem-CNDK_7QF.js";import{I as L}from"./InstanceIpEdit-BGZ9XBNZ.js";import{N as T}from"./NetworkRichChip-DxyZjHa7.js";import"./useImages-D7BEIPVo.js";import"./image-registries-T9CKqPfx.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-BlhTHgMo.js";import"./ProfileResourceLimits-ChaqL2tV.js";const O=()=>{const y=s.useNotify(),{project:o}=N(),{data:a=[],error:c,isLoading:m}=f({queryKey:[l.projects,o,l.networkAllocations],queryFn:async()=>R(o??"default")}),{data:u}=P(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(A,{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(L,{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(C,{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(U,{docPath:"/howto/network_ipam/",hasExternalIcon:!0,children:"Learn more about network allocations"})})]})]})]})};export{O as default};
