import{f as v,d as r,k as C,l as N,o as P,r as p,J as u,p as b,j as e,T as F,U as k,c as q,V as R,W as T,q as $,X as M}from"./index-Cziemgsu.js";import{B as w}from"./BaseLayout-7LTMOawH.js";import{N as B}from"./NotificationRow-BJRTvUVl.js";import{c as I,a as O}from"./index.esm-dDZ7-lOE.js";import{M as A,u as D,t as E,S as L}from"./useClusterMembers-BaQdJPtR.js";import{F as V}from"./FormFooterLayout-BJQGpdhQ.js";import{y as z,c as K}from"./YamlSwitch-GKWclbu0.js";import{R as Q}from"./ResourceLink-D2AYI_En.js";import"./DiskSizeSelector--EFhW8D8.js";import"./FormMenuItem-phSiN9Ls.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-1GO19eHS.js";import"./AutoExpandingTextArea-Bc4N4lSt.js";import"./ScrollableTable-D1yV1_jU.js";import"./formFields-BDRvqvBI.js";import"./snapshots-AEdTpwkf.js";import"./ScrollableContainer-C6sud4ax.js";import"./ResourceIcon-DRRIqKSs.js";const me=()=>{const i=v(),d=r.useNotify(),g=C(),S=N(),{project:s}=P(),[n,f]=p.useState(u(A)),y=p.useState(null),{data:c=[]}=D(),{data:j}=b();if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const x=I().shape({name:O().test(...F(s,y)).required("This field is required")}),l=k(j),t=q({initialValues:{isCreating:!0,readOnly:!1,name:"",description:"",driver:l.size>0?l.values().next().value:"",source:"",size:"",entityType:"storagePool"},validationSchema:x,onSubmit:o=>{const a=o.yaml?z(o.yaml):E(o);(c.length>0?()=>R(a,c):()=>T(a))().then(()=>{S.invalidateQueries({queryKey:[$.storage]}),i(`/ui/project/${s}/storage/pools`),g.success(e.jsxs(e.Fragment,{children:["Storage pool"," ",e.jsx(Q,{type:"pool",value:a.name,to:`/ui/project/${s}/storage/pool/${o.name}`})," ","created."]}))}).catch(h=>{t.setSubmitting(!1),d.failure("Storage pool creation failed",h)})}}),m=o=>{f(u(o))};return e.jsxs(w,{title:"Create a storage pool",contentClassName:"create-storage-pool",children:[e.jsx(B,{}),e.jsx(L,{formik:t,section:n,setSection:m}),e.jsxs(V,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(K,{formik:t,section:n,setSection:m,disableReason:t.values.name?void 0:"Please enter a storage pool name to enable this section"})}),e.jsx(r.Button,{appearance:"base",onClick:()=>i(`/ui/project/${s}/storage/pools`),children:"Cancel"}),e.jsx(r.ActionButton,{appearance:"positive",loading:t.isSubmitting,disabled:!t.isValid||!t.values.name||M(t),onClick:()=>void t.submitForm(),children:"Create"})]})]})};export{me as default};
