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