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-lOezWVmi.js";import{N as g,t as x,a as F}from"./NetworkForwardForm-DyJBaJAy.js";import{c as b}from"./network-forwards-DOX4mTcD.js";import{B as v}from"./BaseLayout-CM5eWMFT.js";import{H as L}from"./HelpLink-8_zL-2ID.js";import{F as S}from"./FormFooterLayout-B1eckygM.js";import{u as $}from"./useNetworks-Dvw5If3E.js";import"./NotificationRow-DdxAfFhk.js";import"./formFields-D9YYYKxX.js";import"./ClusterMemberSelector-BzqYPTQI.js";import"./networks-C9MSk_NH.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};
