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-lOezWVmi.js";import{B}from"./BaseLayout-CM5eWMFT.js";import{N as O}from"./NotificationRow-DdxAfFhk.js";import{M as D,t as E,S as L}from"./StoragePoolForm-BKE59_0n.js";import{F as V}from"./FormFooterLayout-B1eckygM.js";import{y as K,c as Q}from"./YamlSwitch-Dx35FPoh.js";import"./DiskSizeSelector-B_DkPsg-.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-CUTbkJs9.js";import"./formFields-D9YYYKxX.js";import"./SshKeyForm-DyzN8_u6.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-CHLzDgpY.js";import"./snapshots-ByuD-MsK.js";import"./FormMenuItem-D_mb6BGW.js";import"./ClusterSpecificInput-Dv4yt4Ow.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};
