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-BTX30BGB.js";import{B as w}from"./BaseLayout-C9qzVjMS.js";import{N as B}from"./NotificationRow-BrFpgHY8.js";import{c as I,a as O}from"./index.esm-BV12eBbn.js";import{M as A,u as D,t as E,S as L}from"./useClusterMembers-l3XGcHC0.js";import{F as V}from"./FormFooterLayout-C8pm2C5J.js";import{y as z,c as K}from"./YamlSwitch-DkgRZQ-2.js";import{R as Q}from"./ResourceLink-O9uDwzG_.js";import"./DiskSizeSelector-DAjbyRDE.js";import"./FormMenuItem-DWiPu6Qh.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-BRIgBWxu.js";import"./AutoExpandingTextArea-DKXPgS_L.js";import"./ScrollableTable-CbBkBQ-n.js";import"./formFields-BDRvqvBI.js";import"./snapshots-L1dGj61Z.js";import"./ScrollableContainer-BFMZMaL4.js";import"./ResourceIcon-ppn0Y8QG.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};
