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-BGoV7aa6.js";import{B}from"./BaseLayout-CMa6UuLt.js";import{N as O}from"./NotificationRow-TiNMatDC.js";import{M as D,t as E,S as L}from"./StoragePoolForm-BwmW3VRT.js";import{F as V}from"./FormFooterLayout-6fxJS5rR.js";import{y as K,c as Q}from"./YamlSwitch-3bR2x_mM.js";import"./DiskSizeSelector-CdqrTfL2.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-BSccmSbv.js";import"./formFields-Bl9l8MgP.js";import"./SshKeyForm-CUKak12D.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-DJQj4qcy.js";import"./snapshots-DaF1fk6i.js";import"./FormMenuItem-DL6BRTfq.js";import"./ClusterSpecificInput-BCp1H3dp.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};
