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-DRe7Uehz.js";import{N as q,t as v,a as A}from"./NetworkForwardForm-DpcrcmP_.js";import{u as L,f as _}from"./network-forwards-CtWWd4AF.js";import{B as $}from"./BaseLayout-uhDucFhR.js";import{H as C}from"./HelpLink-DRmkMXIl.js";import{F as E}from"./FormFooterLayout-DzEn1tAf.js";import{d as S}from"./networks-elw-cN1u.js";import"./index.esm-9c567zNd.js";import"./NotificationRow-DDCUSSQc.js";import"./formFields-BDRvqvBI.js";import"./ScrollableContainer-i2n9yzu7.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};
