import{k as p,d as n,h as k,n as N,r as h,f as j,q as d,j as t,L as y,$ as C}from"./index-BGoV7aa6.js";import{N as g,t as x,a as F}from"./NetworkForwardForm-CNBHluvV.js";import{c as b}from"./network-forwards-CofabOyJ.js";import{B as v}from"./BaseLayout-CMa6UuLt.js";import{H as L}from"./HelpLink-DaSUIWcZ.js";import{F as S}from"./FormFooterLayout-6fxJS5rR.js";import{u as $}from"./useNetworks-DAjhMC6T.js";import"./NotificationRow-TiNMatDC.js";import"./formFields-Bl9l8MgP.js";import"./ClusterMemberSelector-DgK9Dzlt.js";import"./networks-C4OkUUfr.js";const T=()=>{const m=p(),c=n.useNotify(),u=n.useToastNotification(),f=k(),{network:s,project:o}=N(),{data:e,error:a}=$(s??"",o??"");h.useEffect(()=>{a&&c.failure("Loading networks failed",a)},[a]);const r=j({initialValues:{listenAddress:C(e)?(e==null?void 0:e.config["ipv4.address"])!=="none"?"0.0.0.0":(e==null?void 0:e.config["ipv6.address"])!=="none"?"::":"":"",ports:[]},validationSchema:g,onSubmit:l=>{const w=x(l);b(s??"",w,o??"").then(i=>{f.invalidateQueries({queryKey:[d.projects,o,d.networks,e,d.forwards]}),m(`/ui/project/${encodeURIComponent(o??"")}/network/${encodeURIComponent(s??"")}/forwards`),u.success(`Network forward with listen address ${i} created.`)}).catch(i=>{r.setSubmitting(!1),c.failure("Network forward creation failed",i)})}});return t.jsxs(v,{title:t.jsx(L,{docPath:"/howto/network_forwards/",title:"Learn more about network forwards",children:"Create a network forward"}),contentClassName:"create-network",children:[t.jsx(F,{formik:r,network:e}),t.jsxs(S,{children:[t.jsx(y,{className:"p-button--base",to:`/ui/project/${encodeURIComponent(o??"")}/network/${encodeURIComponent(s??"")}/forwards`,children:"Cancel"}),t.jsx(n.ActionButton,{loading:r.isSubmitting,disabled:!r.isValid||r.isSubmitting||!r.values.listenAddress,onClick:()=>void r.submitForm(),children:"Create"})]})]})};export{T as default};
