import{u as $,k as E,d as s,h as U,n as L,r as k,V as n,y as q,W as A,X as M,g as O,j as t,c as Y,b as B,Y as G,f as P,Z as w,_ as K,q as y,R as f}from"./index-lOezWVmi.js";import{c as Q,a as V,f as D,d as W}from"./networks-C9MSk_NH.js";import{t as h,N as X,i as Z}from"./NetworkForm-dzFzin3W.js";import{N as z}from"./NotificationRow-DdxAfFhk.js";import{y as H,c as J,o as ee}from"./YamlSwitch-Dx35FPoh.js";import{B as te}from"./BaseLayout-CM5eWMFT.js";import{G as N,Y as j}from"./NetworkFormMenu-DEGyoSSo.js";import{F as oe}from"./FormFooterLayout-B1eckygM.js";import{s as re}from"./scroll-BEbDVMxI.js";import"./FormMenuItem-D_mb6BGW.js";import"./SshKeyForm-DyzN8_u6.js";import"./formFields-D9YYYKxX.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-CUTbkJs9.js";import"./ConfigFieldDescription-CHLzDgpY.js";import"./snapshots-ByuD-MsK.js";import"./useNetworks-Dvw5If3E.js";import"./ClusterSpecificSelect-BH0WptdM.js";import"./ClusterSpecificInput-Dv4yt4Ow.js";import"./ExpandableList-QVhlqlHQ.js";import"./UsedByItem-DaMb0MQB.js";import"./YamlNotification-BNbKV1s_.js";import"./useNetworkAcls-Bclr5QsB.js";import"./network-acls-B9tLpGS2.js";const Ie=()=>{const{isFineGrained:C}=$(),i=E(),x=s.useNotify(),m=s.useToastNotification(),g=U(),{project:o}=L(),[c,b]=k.useState(n(N)),S=k.useState(null),{data:p,isLoading:R}=q(),F=A(p),T=M(p),{data:u=[]}=O();if(!o)return t.jsx(t.Fragment,{children:"Missing project"});if(R)return t.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const I=Y().shape({name:B().test("deduplicate","A network with this name already exists",async e=>G(e,o,S,"networks")).required("Network name is required")}),r=P({initialValues:{readOnly:!1,isCreating:!0,name:"",networkType:T?w:K,entityType:"network",ipv4_address:"auto",ipv6_address:"auto",security_acls:[]},validationSchema:I,onSubmit:e=>{const a=e.yaml?H(e.yaml):h(e);(F&&e.networkType!==w?async()=>Q(a,o,u,e.parentPerClusterMember,e.bridge_external_interfaces_per_member):async()=>V(a,o))().then(()=>{g.invalidateQueries({queryKey:[y.projects,o,y.networks]}),i(`/ui/project/${encodeURIComponent(o)}/networks`),m.success(t.jsxs(t.Fragment,{children:["Network"," ",t.jsx(f,{type:"network",value:e.name,to:`/ui/project/${encodeURIComponent(o)}/network/${encodeURIComponent(e.name)}`})," ","created."]}))}).catch(d=>{r.setSubmitting(!1),x.failure("Network creation failed",d),D(e.name,o,C).then(_=>{_.status==="Errored"&&W(e.name,o).catch(()=>{i(`/ui/project/${encodeURIComponent(o)}/networks`),m.failure("Error during network creation",d,t.jsxs(t.Fragment,{children:["Network"," ",t.jsx(f,{type:"network",value:e.name,to:`/ui/project/${encodeURIComponent(o)}/network/${encodeURIComponent(e.name)}`})," ","created with error status."]}))})}).catch(()=>{})})}}),v=()=>{const e=h(r.values);return ee(e)},l=(e,a)=>{b(n(e)),a==="click"&&re(n(e))};return t.jsxs(te,{title:"Create a network",contentClassName:"create-network",children:[t.jsxs(s.Row,{children:[t.jsx(z,{}),t.jsx(X,{formik:r,getYaml:v,project:o,section:c,setSection:l},r.values.networkType)]}),t.jsxs(oe,{children:[t.jsx("div",{className:"yaml-switch",children:t.jsx(J,{formik:r,section:c,setSection:()=>{l(c===n(j)?N:j,"click")},disableReason:r.values.name?void 0:"Please enter a network name to enable this section"})}),t.jsx(s.Button,{appearance:"base",onClick:async()=>i(`/ui/project/${encodeURIComponent(o)}/networks`),children:"Cancel"}),t.jsx(s.ActionButton,{appearance:"positive",loading:r.isSubmitting,disabled:Z(r,u)||r.isSubmitting,onClick:()=>void r.submitForm(),children:"Create"})]})]})};export{Ie as default};
