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-Dz5JRQhj.js";import{g as ee,t as C,N as te,i as se}from"./NetworkForm-1HMmK8Kv.js";import{c as oe,a as ae,f as re,d as ne}from"./useNetworks-kWi7yZ5O.js";import{y as ie,d as ce,o as me}from"./YamlSwitch-BsfuLnhQ.js";import{B as ue}from"./BaseLayout-Zdoa_UmA.js";import{G as b,Y as S}from"./NetworkFormMenu-CwcyljSA.js";import{F as le}from"./FormFooterLayout-Da4gzEk-.js";import{s as pe}from"./scroll-Dc7Cgzms.js";import{N as F}from"./NetworkRichChip-Cbl_TiNv.js";import"./ClusterSpecificSelect-N1D7bveS.js";import"./ClusterSpecificInput-ChmSuJw_.js";import"./ExpandableList-C5toH4xB.js";import"./UsedByItem-DL7zobGp.js";import"./useImages-D_Klrmxd.js";import"./image-registries-8O1zsvZX.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-SxdUk4Mb.js";import"./ProfileResourceLimits-Bjfzp666.js";import"./AutoExpandingTextArea-D6xwa84K.js";import"./NetworkDefaultACLSelector-CFVSHPge.js";import"./useNetworkAcls-cogdr8p1.js";import"./network-acls-AXDaDgjx.js";import"./FormMenuItem-lDrBwrvi.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};
