import{j as e,y as _,d as l,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-BTX30BGB.js";import{N as O}from"./NotificationRow-BrFpgHY8.js";import{P as V}from"./ProgressBar-KxLw-VrG.js";import{S as K}from"./StoragePoolSelector-CKTl-q9P.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=l.useNotify(),g=L(),y=q(),{project:c}=A(),[n,I]=o.useState(null),[d,x]=o.useState(""),[k,u]=o.useState(!1),[i,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(i,n,d,h,m,a).then(s=>v.set(s.metadata.id,()=>b(d,i),p=>g.failure("Custom ISO upload failed",new Error(p)),()=>{u(!1),m(null),y.invalidateQueries({queryKey:[C.storage,i,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(l.Input,{name:"iso",type:"file",id:"iso-image",label:"Local file",onChange:U,stacked:!0}),e.jsx(l.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:i,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(l.Button,{appearance:"base",onClick:P,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(l.ActionButton,{appearance:"positive",loading:k,disabled:!n,className:"u-no-margin--bottom",onClick:w,children:"Upload"})]})]})};export{D as U};
