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-Cziemgsu.js";import{c as I,a as k}from"./index.esm-dDZ7-lOE.js";import{c as Q,a as P}from"./networks-mhWNV24c.js";import{M as U,N as V,t as w}from"./NetworkForm-xs0bWTpu.js";import{N as Y}from"./NotificationRow-BJRTvUVl.js";import{c as D,y as G,d as J}from"./YamlSwitch-GKWclbu0.js";import{B as _}from"./BaseLayout-7LTMOawH.js";import{F as z}from"./FormFooterLayout-BJQGpdhQ.js";import{R as H}from"./ResourceLink-D2AYI_En.js";import"./FormMenuItem-phSiN9Ls.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-1GO19eHS.js";import"./AutoExpandingTextArea-Bc4N4lSt.js";import"./ScrollableTable-D1yV1_jU.js";import"./formFields-BDRvqvBI.js";import"./snapshots-AEdTpwkf.js";import"./YamlNotification-hNvwvtOz.js";import"./ScrollableContainer-C6sud4ax.js";import"./ResourceIcon-DRRIqKSs.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};
