import{a as Y,s as q,d as r,n as B,H as G,r as N,au as i,u as P,av as U,aw as H,m as K,Q as V,J,j as t,f as z,l as D,ax as g,ay as W,R as l,t as X,e as Z,q as x}from"./index-C88DWJny.js";import{g as ee,t as C,N as te,i as se}from"./NetworkForm-Bw-v4FZu.js";import{c as oe,a as ae,f as re,d as ne}from"./useNetworks-C8634WBO.js";import{y as ie,d as ce,o as me}from"./YamlSwitch-BOxCVwX4.js";import{B as ue}from"./BaseLayout-axPPiMeo.js";import{G as b,Y as S}from"./NetworkFormMenu-C1uTzckQ.js";import{F as le}from"./FormFooterLayout-BHqxrLH2.js";import{s as pe}from"./scroll-Dc7Cgzms.js";import{N as F}from"./NetworkRichChip-DxyZjHa7.js";import"./ClusterSpecificSelect-CTgIb3ZA.js";import"./ClusterSpecificInput-z29yDaau.js";import"./ExpandableList-DztXpwLZ.js";import"./UsedByItem-CNDK_7QF.js";import"./useImages-D7BEIPVo.js";import"./image-registries-T9CKqPfx.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-BlhTHgMo.js";import"./ProfileResourceLimits-ChaqL2tV.js";import"./AutoExpandingTextArea-BSlqPK2l.js";import"./NetworkDefaultACLSelector-BRkbz2SG.js";import"./useNetworkAcls-P_dd657c.js";import"./network-acls-DoFbevfN.js";import"./FormMenuItem-f1QSo43l.js";const Ie=()=>{const{isFineGrained:v}=Y(),c=q(),R=r.useNotify(),m=r.useToastNotification(),T=B(),{project:s}=G(),[u,E]=N.useState(i(b)),O=N.useState(null),{data:p,isLoading:_}=P(),$=U(p),A=H(p),{data:d=[]}=K(),{hasStorageAndNetworkOperations:f}=V(),L=J();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=z().shape({name:ee(s,O)}),k=()=>{T.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),R.failure(`Creation of network ${e} failed`,a),re(e,s,v).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:A?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);($&&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)},Q=>{y(e.name,new Error(Q))})):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};
