import{e as b,d as a,i as j,m as x,r as C,j as e,B as v,b as y,M as P,O as q,q as N}from"./index-3c1b2661.js";import{S as z}from"./updateMaxHeight-4e644a5f.js";import{c as $,a as k,u as B}from"./index.esm-7989c879.js";import{u as D,t as F,S as M,z as R,b as V}from"./useClusterMembers-b0b2e2f7.js";import"./DiskSizeSelector-f5c6feab.js";import"./AutoExpandingTextArea-38ef4775.js";import"./FormMenuItem-c982b037.js";import"./StorageVolumeFormMenu-3787a809.js";import"./settings-c23f9009.js";const I=()=>{const i=b(),o=a.useNotify(),u=j(),{project:t}=x(),m=C.useState(null),{data:n=[]}=D();if(!t)return e.jsx(e.Fragment,{children:"Missing project"});const d=$().shape({name:k().test(...F(t,m)).required("This field is required")}),s=B({initialValues:{isCreating:!0,isReadOnly:!1,name:"",description:"",driver:R,source:"",size:""},validationSchema:d,onSubmit:({name:p,description:g,driver:c,source:f,size:l})=>{const S=l.match(/^\d/),r={name:p,description:g,driver:c,source:c!==V?f:void 0,config:{size:S?l:void 0}};(n.length>0?()=>P(r,t,n):()=>q(r,t))().then(()=>{u.invalidateQueries({queryKey:[N.storage]}),i(`/ui/project/${t}/storage`,o.queue(o.success(`Storage pool ${r.name} created.`)))}).catch(h=>{s.setSubmitting(!1),o.failure("Storage pool creation failed",h)})}});return e.jsxs(v,{title:"Create a storage pool",contentClassName:"create-storage-pool",children:[e.jsx(y,{}),e.jsx(M,{formik:s}),e.jsxs("div",{className:"p-bottom-controls",children:[e.jsx("hr",{}),e.jsx(a.Row,{className:"u-align--right",children:e.jsxs(a.Col,{size:12,children:[e.jsx(a.Button,{appearance:"base",onClick:()=>i(`/ui/project/${t}/storage`),children:"Cancel"}),e.jsx(z,{isSubmitting:s.isSubmitting,isDisabled:!s.isValid||!s.values.name,buttonLabel:"Create",onClick:()=>void s.submitForm()})]})})]})]})};export{I as default};
