import{s as O,d as r,n as T,H as q,r as h,au as y,m as I,Q as $,J as k,u as w,j as e,f as A,h as E,aJ as Q,aK as z,l as B,aL as D,aM as L,R as C,t as K,e as U,aN as H,aO as J,q as V}from"./index-C88DWJny.js";import{B as _}from"./BaseLayout-axPPiMeo.js";import{M as G,t as Y,S as W}from"./StoragePoolForm-Bp8ZnIFt.js";import{F as X}from"./FormFooterLayout-BHqxrLH2.js";import{y as Z,d as ee}from"./YamlSwitch-BOxCVwX4.js";import"./DiskSizeSelector-BLS6z1wW.js";import"./AutoExpandingTextArea-BSlqPK2l.js";import"./ScrollableForm-ChpocQAZ.js";import"./ClusterSpecificInput-z29yDaau.js";import"./FormMenuItem-f1QSo43l.js";const pe=()=>{const n=O(),j=r.useNotify(),c=r.useToastNotification(),b=T(),{project:s}=q(),[l,x]=h.useState(y(G)),P=h.useState(null),{data:u=[]}=I(),{hasRemoteDropSource:N,hasStorageAndNetworkOperations:m}=$(),v=k(),{data:F}=w();if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const R=A().shape({name:E().test(...Q(s,P)).required("This field is required")}),p=()=>{b.invalidateQueries({queryKey:[V.storage]})},d=t=>{p(),o.setSubmitting(!1),c.success(e.jsxs(e.Fragment,{children:["Storage pool"," ",e.jsx(J,{poolName:t,projectName:s})," ","created."]}))},g=t=>{p(),o.setSubmitting(!1),j.failure("Creation of storage pool failed",t)},S=z(F),o=B({initialValues:{isCreating:!0,readOnly:!1,name:"",description:"",driver:S.size>0?S.values().next().value:"",source:"",size:"",entityType:"storagePool"},validationSchema:R,onSubmit:t=>{const a=t.yaml?Z(t.yaml):Y(t,N);(u.length>0?async()=>D(a,u,m,t.sourcePerClusterMember,t.zfsPoolNamePerClusterMember,t.sizePerClusterMember):async()=>L(a))().then(i=>{n(`${C}/ui/project/${encodeURIComponent(s)}/storage/pools`),m?(c.info(e.jsxs(e.Fragment,{children:["Creation of storage pool"," ",e.jsx(K,{bold:!0,type:"pool",value:a.name})," has started."]})),v.set(i.metadata.id,()=>{d(a.name)},M=>{g(new Error(M))})):d(a.name)}).catch(i=>{g(i)})}}),f=t=>{x(y(t))};return e.jsxs(_,{title:"Create a storage pool",contentClassName:"create-storage-pool",children:[e.jsx(U,{}),e.jsx(W,{formik:o,section:l,setSection:f}),e.jsxs(X,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(ee,{formik:o,section:l,setSection:f,disableReason:o.values.name?void 0:"Please enter a storage pool name to enable this section"})}),e.jsx(r.Button,{appearance:"base",onClick:async()=>n(`${C}/ui/project/${encodeURIComponent(s)}/storage/pools`),children:"Cancel"}),e.jsx(r.ActionButton,{appearance:"positive",loading:o.isSubmitting,disabled:!o.isValid||o.isSubmitting||!o.values.name||H(o),onClick:()=>{o.submitForm()},children:"Create"})]})]})};export{pe as default};
