import{f as q,d as i,k as F,l as T,o as L,r as p,J as d,p as M,s as O,K as R,g as $,j as t,L as B,M as A,c as K,q as a,t as E}from"./index-DRe7Uehz.js";import{c as I,a as k}from"./index.esm-9c567zNd.js";import{c as Q,a as P}from"./networks-elw-cN1u.js";import{M as U,N as V,t as w}from"./NetworkForm-DFX8O-tu.js";import{N as Y}from"./NotificationRow-DDCUSSQc.js";import{c as D,y as G,d as J}from"./YamlSwitch-DXMT8dhi.js";import{B as _}from"./BaseLayout-uhDucFhR.js";import{F as z}from"./FormFooterLayout-DzEn1tAf.js";import{R as H}from"./ResourceLink-DsyYS3_L.js";import"./FormMenuItem-Drov6ZdA.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-BsPKhbuP.js";import"./AutoExpandingTextArea-CM-5O8_l.js";import"./ScrollableTable-tzQTcMDf.js";import"./formFields-BDRvqvBI.js";import"./snapshots-Ch4qmIVo.js";import"./YamlNotification-DkaGqo7L.js";import"./ScrollableContainer-i2n9yzu7.js";import"./ResourceIcon-iakkHkJJ.js";const fe=()=>{const n=q(),y=i.useNotify(),f=F(),N=T(),{project:o}=L(),[c,j]=p.useState(d(U)),h=p.useState(null),{data:m,isLoading:x}=M(),u=O(m),v=R(m),{data:g=[]}=$({queryKey:[a.cluster,a.members],queryFn:E,enabled:u});if(!o)return t.jsx(t.Fragment,{children:"Missing project"});if(x)return t.jsx(B,{});const C=I().shape({name:k().test("deduplicate","A network with this name already exists",e=>A(e,o,h,"networks")).required("Network name is required"),network:k().test("required","Uplink network is required",(e,r)=>r.parent.networkType!=="ovn"||!!e)}),s=K({initialValues:{readOnly:!1,isCreating:!0,name:"",networkType:v?"ovn":"bridge",entityType:"network"},validationSchema:C,onSubmit:e=>{const r=e.yaml?G(e.yaml):w(e);(u&&e.networkType!=="ovn"?()=>Q(r,o,g):()=>P(r,o))().then(()=>{N.invalidateQueries({queryKey:[a.projects,o,a.networks]}),n(`/ui/project/${o}/networks`),f.success(t.jsxs(t.Fragment,{children:["Network"," ",t.jsx(H,{type:"network",value:e.name,to:`/ui/project/${o}/network/${e.name}`})," ","created."]}))}).catch(b=>{s.setSubmitting(!1),y.failure("Network creation failed",b)})}}),S=()=>{const e=w(s.values);return J(e)},l=e=>{j(d(e))};return t.jsxs(_,{title:"Create a network",contentClassName:"create-network",children:[t.jsx(Y,{}),t.jsx(V,{formik:s,getYaml:S,project:o,section:c,setSection:l}),t.jsxs(z,{children:[t.jsx("div",{className:"yaml-switch",children:t.jsx(D,{formik:s,section:c,setSection:l,disableReason:s.values.name?void 0:"Please enter a network name to enable this section"})}),t.jsx(i.Button,{appearance:"base",onClick:()=>n(`/ui/project/${o}/networks`),children:"Cancel"}),t.jsx(i.ActionButton,{appearance:"positive",loading:s.isSubmitting,disabled:!s.isValid||!s.values.name||s.values.networkType==="ovn"&&!s.values.network,onClick:()=>void s.submitForm(),children:"Create"})]})]})};export{fe as default};
