import{j as e,y as _,d as i,k as L,l as q,x as A,r as o,A as S,L as B,bB as Q,q as C}from"./index-Cziemgsu.js";import{N as O}from"./NotificationRow-BJRTvUVl.js";import{P as V}from"./ProgressBar-DVAOFVJp.js";import{S as K}from"./StoragePoolSelector-BZZPCPdz.js";const R=()=>e.jsx(e.Fragment,{children:e.jsx("div",{className:"p-notification--information",children:e.jsx("div",{className:"p-notification__content",children:e.jsx("h3",{className:"p-notification__title",children:"Some image formats need to be modified in order to work with Incus."})})})}),D=({onCancel:N,onFinish:b})=>{const v=_(),r=i.useNotify(),g=L(),y=q(),{project:c}=A(),[n,I]=o.useState(null),[d,x]=o.useState(""),[k,u]=o.useState(!1),[l,E]=o.useState(""),[t,m]=o.useState(null),[f,F]=o.useState(null);o.useEffect(()=>{r.clear()},[]);const h=(c==null?void 0:c.name)??"",P=()=>{f==null||f.abort(),N()},w=()=>{if(!n)return;r.clear(),u(!0);const a=new AbortController;F(a),Q(l,n,d,h,m,a).then(s=>v.set(s.metadata.id,()=>b(d,l),p=>g.failure("Custom ISO upload failed",new Error(p)),()=>{u(!1),m(null),y.invalidateQueries({queryKey:[C.storage,l,C.volumes,h]})})).catch(s=>{var j;const p=new Error((j=s.response)==null?void 0:j.data.error);g.failure("Custom ISO upload failed",p),u(!1),m(null)})},U=a=>{if(a.target.files){const s=a.target.files[0];I(s),x(s.name)}};return e.jsxs(e.Fragment,{children:[r.notification?e.jsx(O,{}):e.jsx(R,{}),e.jsxs("div",{className:t===null?"":"u-hide",children:[e.jsx(i.Input,{name:"iso",type:"file",id:"iso-image",label:"Local file",onChange:U,stacked:!0}),e.jsx(i.Input,{name:"name",type:"text",id:"name",label:"Alias",value:d,onChange:a=>x(a.target.value),disabled:n===null,stacked:!0}),e.jsx(K,{value:l,setValue:E,selectProps:{id:"storagePool",label:"Storage pool",disabled:n===null,stacked:!0}})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx(V,{percentage:Math.floor(t.percentage)}),e.jsxs("p",{children:[S(t.loaded)," loaded of"," ",S(t.total??0)]}),t.loaded===t.total&&e.jsx(B,{text:"Validating ISO"})]}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(i.Button,{appearance:"base",onClick:P,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(i.ActionButton,{appearance:"positive",loading:k,disabled:!n||!l,className:"u-no-margin--bottom",onClick:w,children:"Upload"})]})]})};export{D as U};
