import{a as Q,s as Y,d as r,n as q,H as G,r as N,ax as i,u as P,ay as U,az as H,m as K,Q as V,J as z,j as t,f as J,l as D,aA as g,aB as W,R as l,t as X,e as Z,q as x}from"./index-66XtK6kJ.js";import{g as ee,t as C,N as te,i as se}from"./NetworkForm-BwPcJnOw.js";import{c as oe,a as ae,f as re,d as ne}from"./useNetworks-CRf3hLWI.js";import{y as ie,d as ce,o as me}from"./YamlSwitch-CYh-6cCu.js";import{B as ue}from"./BaseLayout-DHllEyf6.js";import{G as b,Y as S}from"./NetworkFormMenu-BT0gafYf.js";import{F as le}from"./FormFooterLayout-CcTAlRx3.js";import{s as pe}from"./scroll-Dc7Cgzms.js";import{N as F}from"./NetworkRichChip--TmCCnRo.js";import"./ClusterSpecificSelect-B8QYeO7j.js";import"./ClusterSpecificInput-C7G01bbQ.js";import"./ExpandableList-DpOIpfcf.js";import"./UsedByItem-BR7-4Zz2.js";import"./useImages-y_oimAtQ.js";import"./image-registries-Dmf_bwCV.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-BYCO4lqY.js";import"./ProfileResourceLimits-Bgn_DF19.js";import"./AutoExpandingTextArea-BdkUE9YB.js";import"./NetworkDefaultACLSelector-DEbhhV0K.js";import"./useNetworkAcls-CY4xdGt5.js";import"./network-acls-BNDCHn0O.js";import"./FormMenuItem-DRWC8EpE.js";const Ie=()=>{const{isFineGrained:R}=Q(),c=Y(),T=r.useNotify(),m=r.useToastNotification(),v=q(),{project:s}=G(),[u,E]=N.useState(i(b)),O=N.useState(null),{data:p,isLoading:_}=P(),A=U(p),$=H(p),{data:d=[]}=K(),{hasStorageAndNetworkOperations:f}=V(),L=z();if(!s)return t.jsx(t.Fragment,{children:"Missing project"});if(_)return t.jsx(r.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const I=J().shape({name:ee(s,O)}),k=()=>{v.invalidateQueries({queryKey:[x.projects,s,x.networks]})},w=e=>{k(),o.setSubmitting(!1),m.success(t.jsxs(t.Fragment,{children:["Network"," ",t.jsx(F,{networkName:e,projectName:s})," ","created."]}))},y=(e,a)=>{k(),o.setSubmitting(!1),T.failure(`Creation of network ${e} failed`,a),re(e,s,R).then(j=>{j.status==="Errored"&&ne(e,s).catch(()=>{c(`${l}/ui/project/${encodeURIComponent(s)}/networks`),m.failure("Error during network creation",a,t.jsxs(t.Fragment,{children:["Network"," ",t.jsx(F,{networkName:e,projectName:s})," ","created with error status."]}))})}).catch(()=>{})},o=D({initialValues:{readOnly:!1,isCreating:!0,name:"",networkType:$?g:W,entityType:"network",ipv4_address:"auto",ipv6_address:"auto",security_acls:[]},validationSchema:I,onSubmit:e=>{const a=e.yaml?ie(e.yaml):C(e);(A&&e.networkType!==g?async()=>oe(a,s,d,f,e.parentPerClusterMember,e.bridge_external_interfaces_per_member):async()=>ae(a,s))().then(n=>{c(`${l}/ui/project/${encodeURIComponent(s)}/networks`),f&&n.metadata.id?(m.info(t.jsxs(t.Fragment,{children:["Creation of network"," ",t.jsx(X,{bold:!0,type:"network",value:e.name})," has started."]})),L.set(n.metadata.id,()=>{w(e.name)},B=>{y(e.name,new Error(B))})):w(e.name)}).catch(n=>{y(e.name,n)})}}),M=()=>{const e=C(o.values);return me(e)},h=(e,a)=>{E(i(e)),a==="click"&&pe(i(e))};return t.jsxs(ue,{title:"Create a network",contentClassName:"create-network",children:[t.jsxs(r.Row,{children:[t.jsx(Z,{}),t.jsx(te,{formik:o,getYaml:M,project:s,section:u,setSection:h},o.values.networkType)]}),t.jsxs(le,{children:[t.jsx("div",{className:"yaml-switch",children:t.jsx(ce,{formik:o,section:u,setSection:()=>{h(u===i(S)?b:S,"click")},disableReason:o.values.name?void 0:"Please enter a network name to enable this section"})}),t.jsx(r.Button,{appearance:"base",onClick:async()=>c(`${l}/ui/project/${encodeURIComponent(s)}/networks`),children:"Cancel"}),t.jsx(r.ActionButton,{appearance:"positive",loading:o.isSubmitting,disabled:se(o,d)||o.isSubmitting,onClick:()=>{o.submitForm()},children:"Create"})]})]})};export{Ie as default};
