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