import{k as x,d as a,h as b,n as P,r as p,V as u,g as N,y as v,j as e,c as I,b as R,a8 as F,a9 as M,f as k,aa as q,ab as $,q as T,R as U,ac as w,ad as z,ae as A}from"./index-DET0E_3l.js";import{B}from"./BaseLayout-CzqnKJIH.js";import{N as O}from"./NotificationRow-BgqB5Xch.js";import{M as D,t as E,S as L}from"./StoragePoolForm-BmBonEB2.js";import{F as V}from"./FormFooterLayout-YMKZRDmQ.js";import{y as K,c as Q}from"./YamlSwitch-BHRorJou.js";import"./DiskSizeSelector-DzL40sWO.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-C0eJ1NqN.js";import"./formFields-D4E6x_f1.js";import"./SshKeyForm-CCywfCqi.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-9ZU6uOm7.js";import"./snapshots-Bv7XY7g-.js";import"./FormMenuItem-CafR0V9n.js";import"./ClusterSpecificInput-Dws2qcY8.js";const le=()=>{const i=x(),d=a.useNotify(),g=a.useToastNotification(),S=b(),{project:s}=P(),[n,y]=p.useState(u(D)),f=p.useState(null),{data:c=[]}=N(),{data:C}=v();if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const j=I().shape({name:R().test(...F(s,f)).required("This field is required")}),l=M(C),t=k({initialValues:{isCreating:!0,readOnly:!1,name:"",description:"",driver:l.size>0?l.values().next().value:"",source:"",size:"",entityType:"storagePool"},validationSchema:j,onSubmit:o=>{const r=o.yaml?K(o.yaml):E(o);(c.length>0?async()=>q(r,c,o.sourcePerClusterMember,o.zfsPoolNamePerClusterMember,o.sizePerClusterMember):async()=>$(r))().then(()=>{S.invalidateQueries({queryKey:[T.storage]}),i(`/ui/project/${encodeURIComponent(s)}/storage/pools`),g.success(e.jsxs(e.Fragment,{children:["Storage pool"," ",e.jsx(U,{type:"pool",value:r.name,to:`/ui/project/${encodeURIComponent(s)}/storage/pool/${encodeURIComponent(o.name)}`})," ","created."]}))}).catch(h=>{t.setSubmitting(!1),d.failure("Storage pool creation failed",h)})}}),m=o=>{y(u(o))};return e.jsxs(B,{title:"Create a storage pool",contentClassName:"create-storage-pool",children:[e.jsx(O,{}),e.jsx(L,{formik:t,section:n,setSection:m}),e.jsxs(V,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(Q,{formik:t,section:n,setSection:m,disableReason:t.values.name?void 0:"Please enter a storage pool name to enable this section"})}),e.jsx(a.Button,{appearance:"base",onClick:async()=>i(`/ui/project/${encodeURIComponent(s)}/storage/pools`),children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",loading:t.isSubmitting,disabled:!t.isValid||t.isSubmitting||!t.values.name||w(t)||z(t)||A(t),onClick:()=>void t.submitForm(),children:"Create"})]})]})};export{le as default};
