import{n as N,f as j,d as c,k as F,l as g,o as h,g as u,c as x,q as o,j as i,e as b}from"./index-CzUo07dn.js";import{N as q,t as v,a as A}from"./NetworkForwardForm-CYTKEd4X.js";import{u as L,f as _}from"./network-forwards-DoiUK_R5.js";import{B as $}from"./BaseLayout-D6pt0Et9.js";import{H as C}from"./HelpLink-INVHAe6u.js";import{F as E}from"./FormFooterLayout-CkQ9739Z.js";import{d as S}from"./networks-AOdNDxHC.js";import"./index.esm-BBoKC3tX.js";import"./NotificationRow-IVGrYQV6.js";import"./formFields-BDRvqvBI.js";import"./ScrollableContainer-CSFAM_C4.js";const G=()=>{const l=N(),m=j(),p=c.useNotify(),w=F(),f=g(),{network:e,project:r,forwardAddress:n}=h(),{data:k}=u({queryKey:[o.projects,r,o.networks,e],queryFn:()=>S(e??"",r??"")}),{data:t}=u({queryKey:[o.projects,r,o.networks,e,o.forwards,n],queryFn:()=>_(e??"",n??"",r??"")}),s=x({initialValues:{listenAddress:n??"",defaultTargetAddress:(t==null?void 0:t.config.target_address)??"",description:(t==null?void 0:t.description)??"",ports:(t==null?void 0:t.ports.map(a=>({listenPort:a.listen_port,protocol:a.protocol,targetAddress:a.target_address,targetPort:a.target_port})))??[]},enableReinitialize:!0,validationSchema:q,onSubmit:a=>{const d=v(a);L(e??"",d,r??"").then(()=>{f.invalidateQueries({queryKey:[o.projects,r,o.networks,e,o.forwards]}),m(`/ui/project/${r}/network/${e}/forwards`),w.success(`Network forward ${d.listen_address} updated.`)}).catch(y=>{s.setSubmitting(!1),p.failure("Network forward update failed",y)})}});return i.jsxs($,{title:i.jsx(C,{href:`${l}/howto/network_forwards/`,title:"Learn more about network forwards",children:"Edit a network forward"}),contentClassName:"edit-network",children:[i.jsx(A,{formik:s,isEdit:!0,network:k}),i.jsxs(E,{children:[i.jsx(b,{className:"p-button--base",to:`/ui/project/${r}/network/${e}/forwards`,children:"Cancel"}),i.jsx(c.ActionButton,{appearance:"positive",loading:s.isSubmitting,disabled:!s.isValid||!s.values.listenAddress,onClick:()=>void s.submitForm(),children:"Update"})]})]})};export{G as default};
