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-DyZtLAjB.js";import{N as g,t as x,a as F}from"./NetworkForwardForm-B_oxaj9f.js";import{c as b}from"./network-forwards-B3fWK16c.js";import{B as v}from"./BaseLayout-BBVAHUxR.js";import{H as L}from"./HelpLink-D3hDVaXE.js";import{F as S}from"./FormFooterLayout-BVf_vA5z.js";import{u as $}from"./useNetworks-C137e8fZ.js";import"./NotificationRow-Cej0AnMm.js";import"./formFields-BbQUt1T2.js";import"./ClusterMemberSelector-Dewu9UFZ.js";import"./networks-D-awX-Ft.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};
