import{s as O,d as r,n as T,H as q,r as h,ax as y,m as I,Q,J as $,u as k,j as e,f as w,h as A,aM as E,aN as z,l as B,aO as D,aP as L,R as C,t as U,e as H,aQ as K,aR as V,q as _}from"./index-66XtK6kJ.js";import{B as G}from"./BaseLayout-DHllEyf6.js";import{M as J,t as Y,S as W}from"./StoragePoolForm-CrClI-6h.js";import{F as X}from"./FormFooterLayout-CcTAlRx3.js";import{y as Z,d as ee}from"./YamlSwitch-CYh-6cCu.js";import"./DiskSizeSelector-CY9M2-VV.js";import"./AutoExpandingTextArea-BdkUE9YB.js";import"./ScrollableForm-DnwqOi93.js";import"./ClusterSpecificInput-C7G01bbQ.js";import"./FormMenuItem-DRWC8EpE.js";const pe=()=>{const n=O(),j=r.useNotify(),c=r.useToastNotification(),x=T(),{project:s}=q(),[l,b]=h.useState(y(J)),P=h.useState(null),{data:u=[]}=I(),{hasRemoteDropSource:N,hasStorageAndNetworkOperations:m}=Q(),v=$(),{data:F}=k();if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const R=w().shape({name:A().test(...E(s,P)).required("This field is required")}),p=()=>{x.invalidateQueries({queryKey:[_.storage]})},d=t=>{p(),o.setSubmitting(!1),c.success(e.jsxs(e.Fragment,{children:["Storage pool"," ",e.jsx(V,{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(U,{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=>{b(y(t))};return e.jsxs(G,{title:"Create a storage pool",contentClassName:"create-storage-pool",children:[e.jsx(H,{}),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||K(o),onClick:()=>{o.submitForm()},children:"Create"})]})]})};export{pe as default};
