import{s as M,d as r,n as O,H as w,r as h,au as y,m as T,Q as q,J as A,u as Q,j as e,f as $,h as k,aJ as E,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,aP as V,aQ as _,aR as G,aS as Y,q as W}from"./index-Dz5JRQhj.js";import{B as X}from"./BaseLayout-Zdoa_UmA.js";import{M as Z,t as ee,S as te}from"./StoragePoolForm-D9i00wle.js";import{F as oe}from"./FormFooterLayout-Da4gzEk-.js";import{y as se,d as ae}from"./YamlSwitch-BsfuLnhQ.js";import"./DiskSizeSelector-Dnnbm-Yn.js";import"./AutoExpandingTextArea-D6xwa84K.js";import"./ScrollableForm-1W--OJbe.js";import"./ClusterSpecificInput-ChmSuJw_.js";import"./FormMenuItem-lDrBwrvi.js";const fe=()=>{const n=M(),j=r.useNotify(),c=r.useToastNotification(),P=O(),{project:s}=w(),[l,x]=h.useState(y(Z)),b=h.useState(null),{data:m=[]}=T(),{hasRemoteDropSource:N,hasStorageAndNetworkOperations:u}=q(),v=A(),{data:F}=Q();if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const R=$().shape({name:k().test(...E(s,b)).required("This field is required")}),p=()=>{P.invalidateQueries({queryKey:[W.storage]})},d=o=>{p(),t.setSubmitting(!1),c.success(e.jsxs(e.Fragment,{children:["Storage pool"," ",e.jsx(Y,{poolName:o,projectName:s})," ","created."]}))},g=o=>{p(),t.setSubmitting(!1),j.failure("Creation of storage pool failed",o)},S=z(F),t=B({initialValues:{isCreating:!0,readOnly:!1,name:"",description:"",driver:S.size>0?S.values().next().value:"",source:"",size:"",entityType:"storagePool"},validationSchema:R,onSubmit:o=>{const a=o.yaml?se(o.yaml):ee(o,N);(m.length>0?async()=>D(a,m,u,o.sourcePerClusterMember,o.zfsPoolNamePerClusterMember,o.sizePerClusterMember):async()=>L(a))().then(i=>{n(`${C}/ui/project/${encodeURIComponent(s)}/storage/pools`),u?(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)},I=>{g(new Error(I))})):d(a.name)}).catch(i=>{g(i)})}}),f=o=>{x(y(o))};return e.jsxs(X,{title:"Create a storage pool",contentClassName:"create-storage-pool",children:[e.jsx(U,{}),e.jsx(te,{formik:t,section:l,setSection:f}),e.jsxs(oe,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(ae,{formik:t,section:l,setSection:f,disableReason:t.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:t.isSubmitting,disabled:!t.isValid||t.isSubmitting||!t.values.name||H(t)||J(t)||V(t)||_(t)||G(t),onClick:()=>{t.submitForm()},children:"Create"})]})]})};export{fe as default};
