import{bp as g,j as e,aR as j,dn as k,o as C,R,H as b,c7 as T,dp as $,dl as F,d as N,cv as H,dq as I,cU as K,L as O}from"./index-66XtK6kJ.js";import{h as P}from"./useNetworks-CRf3hLWI.js";import{N as M}from"./NetworkRichChip--TmCCnRo.js";const U=({device:t,project:r,location:c})=>t.type==="disk"?g(t)?e.jsxs(e.Fragment,{children:["Pool"," ",e.jsx(j,{poolName:t.pool??"",projectName:r,location:c})]}):k(t)?t.source:e.jsxs(e.Fragment,{children:["Volume"," ",e.jsx(C,{type:"volume",value:t.source,to:`${R}/ui/project/${encodeURIComponent(r)}/storage/pool/${encodeURIComponent(t.pool??"")}/volumes/custom/${encodeURIComponent(t.source??"")}`})," ","on pool"," ",e.jsx(j,{poolName:t.pool??"",projectName:r,location:c})]}):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]})]}):"-",V=({configBaseURL:t,devices:r,location:c})=>{const{project:u}=b(),p=(o,s)=>{const l=o[0].toLowerCase(),f=s[0].toLowerCase(),a=o[1].type,i=s[1].type;return a===i?l.localeCompare(f):a.localeCompare(i)},m=Object.entries(r??{}).filter(([o,s])=>s.type!=="nic"&&s.type!=="none").sort(p),d=m.length>0,y=[{content:"Name",sortKey:"name",className:"u-text--muted"},{content:"Type",sortKey:"type",className:"u-text--muted"},{content:"Details",className:"u-text--muted"}],h=m.map(([o,s])=>{let l=s.type;return T(s)&&(g(s)&&(l+=" (root)"),$(s)&&(l+=" (volume)"),k(s)&&(l+=" (host path)")),{key:o,columns:[{content:e.jsx(C,{type:"device",value:o,to:`${t}/${F(s)?"other":s.type}`}),role:"rowheader","aria-label":"Name"},{content:l,role:"cell","aria-label":"Type"},{content:e.jsx(U,{device:s,project:u,location:c}),role:"cell","aria-label":"Details"}],sortData:{name:o.toLowerCase(),type:s.type}}});return e.jsxs(e.Fragment,{children:[d&&e.jsx(N.MainTable,{headers:y,rows:h,className:"device-table",sortable:!0}),!d&&e.jsx(e.Fragment,{children:"-"})]})},_=({onFailure:t,devices:r,instance:c})=>{const{project:u}=b(),{data:p=[],error:m,isLoading:d}=P(u);m&&t("Loading networks failed",m);const y=Object.values(r??{}).filter(H),h=y.length>0,o=p.length>0,s=[{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"}],l=Object.entries(r??{}).map(([a,i])=>{if(i.type!=="nic")return null;const n=p.find(x=>x.name===i.network||x.name===i.parent);if(!n)return null;const D=y.find(x=>x.network===n.name),L=I(D),A=K(n),w=new Set(L.concat(A)).size;return{key:n.name,columns:[{content:e.jsx(M,{networkName:n.name,projectName:u??""}),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:c?.config?.[`volatile.${a}.hwaddr`]||"-",role:"cell","aria-label":"MAC address"},{content:w>0?e.jsx(O,{to:"configuration/network",children:w}):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:c?.config?.[`volatile.${a}.hwaddr`]||"-",acls:w}}}).filter(a=>a!==null);return d?e.jsx(N.Spinner,{className:"u-loader",text:"Loading networks..."}):h&&!o?e.jsx(N.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to view network details."}):h?e.jsx(N.MainTable,{headers:s,rows:l,sortable:!0,className:"network-table"}):e.jsx(e.Fragment,{children:"-"})};export{V as D,_ as N};
