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-CzUo07dn.js";import{c as I,a as k}from"./index.esm-BBoKC3tX.js";import{c as Q,a as P}from"./networks-AOdNDxHC.js";import{M as U,N as V,t as w}from"./NetworkForm-C0boDyV4.js";import{N as Y}from"./NotificationRow-IVGrYQV6.js";import{c as D,y as G,d as J}from"./YamlSwitch-DLbjsyg1.js";import{B as _}from"./BaseLayout-D6pt0Et9.js";import{F as z}from"./FormFooterLayout-CkQ9739Z.js";import{R as H}from"./ResourceLink-5fvv3Myt.js";import"./FormMenuItem-D-3tk9Lf.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-DYgLBIgn.js";import"./AutoExpandingTextArea-DbenJele.js";import"./ScrollableTable-COas1_r_.js";import"./formFields-BDRvqvBI.js";import"./snapshots-DWXTDgvk.js";import"./YamlNotification-DqaTFbgr.js";import"./ScrollableContainer-CSFAM_C4.js";import"./ResourceIcon-CQum9kVZ.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};
