import{aJ as N,j as e,R as u,bP as C,n as D,b9 as A,bQ as I,bR as T,d as x,bh as U,bS as F,bt as K,L as H}from"./index-BGoV7aa6.js";import{b as M}from"./useNetworks-DAjhMC6T.js";const O=({device:t,project:r})=>t.type==="disk"?N(t)?e.jsxs(e.Fragment,{children:["Pool"," ",e.jsx(u,{type:"pool",value:t.pool||"",to:`/ui/project/${encodeURIComponent(r)}/storage/pool/${encodeURIComponent(t.pool??"")}`})]}):C(t)?t.source:e.jsxs(e.Fragment,{children:["Volume"," ",e.jsx(u,{type:"volume",value:t.source,to:`/ui/project/${encodeURIComponent(r)}/storage/pool/${encodeURIComponent(t.pool??"")}/volumes/custom/${encodeURIComponent(t.source??"")}`})," ","on pool"," ",e.jsx(u,{type:"pool",value:t.pool||"",to:`/ui/project/${encodeURIComponent(r)}/storage/pool/${encodeURIComponent(t.pool??"")}`})]}):t.type==="gpu"?e.jsx("span",{title:t.pci,className:"u-truncate",children:t.pci?`PCI  ${t.pci}`:`ID ${t.id}`}):t.type==="proxy"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{title:t.listen,className:"u-truncate",children:["Listen: ",t.listen]}),e.jsxs("div",{title:t.connect,className:"u-truncate",children:["Connect: ",t.connect]})]}):"-",B=({configBaseURL:t,devices:r})=>{const{project:l}=D(),p=(s,o)=>{const c=s[0].toLowerCase(),w=o[0].toLowerCase(),f=s[1].type,a=o[1].type;return f===a?c.localeCompare(w):f.localeCompare(a)},i=Object.entries(r??{}).filter(([s,o])=>o.type!=="nic"&&o.type!=="none").sort(p),m=i.length>0,h=[{content:"Name",sortKey:"name",className:"u-text--muted"},{content:"Type",sortKey:"type",className:"u-text--muted"},{content:"Details",className:"u-text--muted"}],d=i.map(([s,o])=>{let c=o.type;return A(o)&&(N(o)&&(c+=" (root)"),I(o)&&(c+=" (volume)"),C(o)&&(c+=" (host path)")),{key:s,columns:[{content:e.jsx(u,{type:"device",value:s,to:`${t}/${T(o)?"other":o.type}`}),role:"rowheader","aria-label":"Name"},{content:c,role:"cell","aria-label":"Type"},{content:e.jsx(O,{device:o,project:l}),role:"cell","aria-label":"Details"}],sortData:{name:s.toLowerCase(),type:o.type}}});return e.jsxs(e.Fragment,{children:[m&&e.jsx(x.MainTable,{headers:h,rows:d,className:"device-table",sortable:!0}),!m&&e.jsx(e.Fragment,{children:"-"})]})},E=({onFailure:t,devices:r,instance:l})=>{const{project:p}=D(),{data:i=[],error:m,isLoading:h}=M(p);m&&t("Loading networks failed",m);const d=Object.values(r??{}).filter(U),s=d.length>0,o=i.length>0,c=[{content:"Name",sortKey:"name",className:"u-text--muted"},{content:"Interface",sortKey:"interfaceName",className:"u-text--muted"},{content:"Type",sortKey:"type",className:"u-text--muted"},{content:"MAC address",sortKey:"macAddress",className:"u-text--muted u-hide--small u-hide--medium"},{content:"ACLs",sortKey:"acls",className:"u-text--muted u-hide--small u-hide--medium"}],w=Object.entries(r??{}).map(([a,j])=>{var b,k;if(j.type!=="nic")return null;const n=i.find(y=>y.name===j.network||y.name===j.parent);if(!n)return null;const R=d.find(y=>y.network===n.name),L=F(R),$=K(n),g=new Set(L.concat($)).size;return{key:n.name,columns:[{content:e.jsx(u,{type:"network",value:n.name,to:`/ui/project/${encodeURIComponent(p??"")}/network/${encodeURIComponent(n.name)}`}),role:"rowheader","aria-label":"Name"},{content:a,role:"cell","aria-label":"Interface"},{content:e.jsxs(e.Fragment,{children:[n.type,e.jsxs("span",{className:"u-text--muted",children:[", ",n.managed?"managed":"unmanaged"]})]}),role:"cell","aria-label":"Type"},{content:((b=l==null?void 0:l.config)==null?void 0:b[`volatile.${a}.hwaddr`])||"-",role:"cell","aria-label":"MAC address"},{content:g>0?e.jsx(H,{to:"configuration/network",children:g}):e.jsx(e.Fragment,{children:"-"}),role:"cell","aria-label":"ACLs count"}],sortData:{name:n.name.toLowerCase(),type:n.type+n.managed?"managed":"unmanaged",interfaceName:a.toLowerCase(),macAddress:((k=l==null?void 0:l.config)==null?void 0:k[`volatile.${a}.hwaddr`])||"-"}}}).filter(a=>a!==null);return h?e.jsx(x.Spinner,{className:"u-loader",text:"Loading networks..."}):s&&!o?e.jsx(x.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to view network details."}):s?e.jsx(x.MainTable,{headers:c,rows:w,sortable:!0,className:"network-table"}):e.jsx(e.Fragment,{children:"-"})};export{B as D,E as N};
