import{e as v,d as r,i as x,m as S,r as l,G as d,n as q,f as F,j as t,L as O,z as B,B as L,b as M,q as i,p as A}from"./index-3c1b2661.js";import{c as I,a as R,u as $}from"./index.esm-7989c879.js";import{S as G}from"./updateMaxHeight-4e644a5f.js";import{c as K,a as Q}from"./networks-a82d149f.js";import{N as T,M as V,t as p}from"./NetworkForm-7a372877.js";import{y as Y,d as z}from"./instanceValidation-ad252104.js";import{i as D,s as E}from"./settings-c23f9009.js";import{Y as U}from"./ProfileFormMenu-402fd3a6.js";import"./FormMenuItem-c982b037.js";import"./ConfigurationTable-5663621c.js";import"./ConfigFieldDescription-f8ae8325.js";import"./AutoExpandingTextArea-38ef4775.js";import"./instanceConfigInheritance-8da60590.js";const ne=()=>{const n=v(),o=r.useNotify(),y=x(),{project:a}=S(),[f,k]=l.useState(d(V)),N=l.useState(null),{data:c,isLoading:w}=q(),m=D(c),b=E(c),{data:h=[]}=F({queryKey:[i.cluster,i.members],queryFn:A,enabled:m});if(!a)return t.jsx(t.Fragment,{children:"Missing project"});if(w)return t.jsx(O,{});const j=I().shape({name:R().test("deduplicate","A network with this name already exists",e=>B(e,a,N,"networks")).required("Network name is required")}),s=$({initialValues:{readOnly:!1,isCreating:!0,name:"",type:b?"ovn":"bridge"},validationSchema:j,onSubmit:e=>{const u=e.yaml?Y(e.yaml):p(e);(m&&e.type!=="ovn"?()=>K(u,a,h):()=>Q(u,a))().then(()=>{y.invalidateQueries({queryKey:[i.networks]}),n(`/ui/project/${a}/networks`,o.queue(o.success(`Network ${e.name} created.`)))}).catch(C=>{s.setSubmitting(!1),o.failure("Network creation failed",C)})}}),g=()=>{const e=p(s.values);return z(e)};return t.jsxs(L,{title:"Create a network",contentClassName:"create-network",children:[t.jsx(M,{}),t.jsx(T,{formik:s,getYaml:g,project:a,section:f,setSection:e=>{s.values.yaml&&e!==U&&s.setFieldValue("yaml",void 0),k(d(e))}}),t.jsxs("div",{className:"p-bottom-controls",children:[t.jsx("hr",{}),t.jsx(r.Row,{className:"u-align--right",children:t.jsxs(r.Col,{size:12,children:[t.jsx(r.Button,{appearance:"base",onClick:()=>n(`/ui/project/${a}/networks`),children:"Cancel"}),t.jsx(G,{isSubmitting:s.isSubmitting,isDisabled:!s.isValid||!s.values.name||s.values.type==="ovn"&&!s.values.network,buttonLabel:"Create",onClick:()=>void s.submitForm()})]})})]})]})};export{ne as default};
