import{s as g,d as c,n as x,H as y,Q as A,J as b,r as S,l as L,R as k,j as t,L as $,az as E,q as u}from"./index-C88DWJny.js";import{N as R,t as Q,a as q}from"./NetworkForwardForm-DIfr_DGi.js";import{c as H}from"./network-forwards-CHB4VIhb.js";import{B as I}from"./BaseLayout-axPPiMeo.js";import{H as O}from"./HelpLink-c8Zoz7ma.js";import{F as T}from"./FormFooterLayout-BHqxrLH2.js";import{u as U}from"./useNetworks-C8634WBO.js";import"./ScrollableForm-ChpocQAZ.js";import"./ClusterMemberSelector-Ciw-uzfW.js";const M=()=>{const h=g(),l=c.useNotify(),w=c.useToastNotification(),v=x(),{network:a,project:r}=y(),{data:s,error:i}=U(a??"",r??""),{hasStorageAndNetworkOperations:N}=A(),C=b();S.useEffect(()=>{i&&l.failure("Loading networks failed",i)},[i]);const F=()=>E(s)?s?.config["ipv4.address"]!=="none"?"0.0.0.0":s?.config["ipv6.address"]!=="none"?"::":"":"",f=()=>{v.invalidateQueries({queryKey:[u.projects,r,u.networks,s,u.forwards]})},m=o=>{f(),w.success(`Network forward with listen address ${o} created.`)},p=(o,d)=>{f(),e.setSubmitting(!1),l.failure(`Creation of network forward with listen address ${d} failed`,o)},e=L({initialValues:{listenAddress:F(),ports:[]},validationSchema:R,onSubmit:o=>{const d=Q(o);H(a??"",d,r??"").then(n=>{h(`${k}/ui/project/${encodeURIComponent(r??"")}/network/${encodeURIComponent(a??"")}/forwards`),N&&n?.metadata.id?(w.info(t.jsxs(t.Fragment,{children:["Creation of network forward with listen address"," ",e.values.listenAddress," has started."]})),C.set(n.metadata.id,()=>{m(e.values.listenAddress)},j=>{p(new Error(j),e.values.listenAddress)})):m(e.values.listenAddress)}).catch(n=>{p(n,e.values.listenAddress)})}});return t.jsxs(I,{title:t.jsx(O,{docPath:"/howto/network_forwards/",title:"Learn more about network forwards",children:"Create a network forward"}),contentClassName:"create-network",children:[t.jsx(q,{formik:e,network:s}),t.jsxs(T,{children:[t.jsx($,{className:"p-button--base",to:`${k}/ui/project/${encodeURIComponent(r??"")}/network/${encodeURIComponent(a??"")}/forwards`,children:"Cancel"}),t.jsx(c.ActionButton,{appearance:"positive",loading:e.isSubmitting,disabled:!e.isValid||e.isSubmitting||!e.values.listenAddress,onClick:()=>{e.submitForm()},children:"Create"})]})]})};export{M as default};
