import{x as f,u as k,g as v,q as z,j as e,a4 as L,A as O,d as r,L as U,r as j}from"./index-Cziemgsu.js";import{U as w}from"./UploadCustomIso-DH4SL5Zf.js";import{l as y}from"./loadIsoVolumes-DrpDOMmD.js";const A=({primaryImage:s,onSelect:i,onUpload:l,onCancel:n})=>{const{project:t}=f(),u=(t==null?void 0:t.name)??"",{hasStorageVolumesAll:d}=k(),{data:p=[],isLoading:m}=v({queryKey:[z.isoVolumes,t],queryFn:()=>y(u,d)}),N=[{content:"Name",sortKey:"name"},{content:"Storage pool",sortKey:"storagePool"},{content:"Upload date",sortKey:"uploadedAt"},{content:"Size",sortKey:"size"},{"aria-label":"Actions",className:"actions"}],x=p.map(o=>{var C,b,h;const a=()=>i(o,"virtual-machine");return{className:"u-row",columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:o.aliases,children:o.aliases}),role:"cell","aria-label":"Name",onClick:a},{content:o.pool,role:"cell","aria-label":"Storage pool",onClick:a},{content:L(new Date(o.created_at).toISOString()),role:"cell","aria-label":"Uploaded at",onClick:a},{content:((C=o.volume)==null?void 0:C.config.size)&&O(+o.volume.config.size),role:"cell","aria-label":"Size",onClick:a},{content:e.jsx(r.Button,{appearance:(s==null?void 0:s.name)===o.aliases&&(s==null?void 0:s.pool)===o.pool?"positive":"",onClick:a,dense:!0,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:a}],sortData:{name:o.aliases.toLowerCase(),storagePool:(b=o.pool)==null?void 0:b.toLowerCase(),size:+(((h=o.volume)==null?void 0:h.config.size)??0),uploadedAt:o.created_at}}});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"iso-table",children:e.jsx(r.MainTable,{headers:N,rows:x,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:m?e.jsx(U,{text:"Loading images..."}):"No custom ISOs found"})}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(r.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:n,children:"Cancel"}),e.jsx(r.Button,{appearance:x.length===0?"positive":"",onClick:l,type:"button",className:"iso-btn u-no-margin--bottom",children:e.jsx("span",{children:"Upload custom ISO"})})]})]})},c="selectIso",S="uploadIso",E=({onClose:s,onSelect:i})=>{const[l,n]=j.useState(c),[t,u]=j.useState(null),d=()=>{switch(l){case c:return"Select custom ISO";case S:return"Upload custom ISO";default:return""}};return e.jsxs(r.Modal,{close:s,title:d(),className:"custom-iso-modal",children:[l===c&&e.jsx(A,{primaryImage:t,onSelect:i,onUpload:()=>n(S),onCancel:s}),l===S&&e.jsx(w,{onCancel:()=>n(c),onFinish:(p,m)=>{n(c),u({name:p,pool:m})}})]})};export{E as C};
