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 r,j as i,e as b}from"./index-Cziemgsu.js";import{N as q,t as v,a as A}from"./NetworkForwardForm-BzYNysJR.js";import{u as L,f as _}from"./network-forwards-BsCG3hGt.js";import{B as $}from"./BaseLayout-7LTMOawH.js";import{H as C}from"./HelpLink-C4E8LWq2.js";import{F as E}from"./FormFooterLayout-BJQGpdhQ.js";import{d as S}from"./networks-mhWNV24c.js";import"./index.esm-dDZ7-lOE.js";import"./NotificationRow-BJRTvUVl.js";import"./ClusterMemberSelector--J9qxfzT.js";import"./formFields-BDRvqvBI.js";import"./ScrollableContainer-C6sud4ax.js";const I=()=>{const l=N(),m=j(),p=c.useNotify(),w=F(),k=g(),{network:e,project:o,forwardAddress:n}=h(),{data:f}=u({queryKey:[r.projects,o,r.networks,e],queryFn:()=>S(e??"",o??"")}),{data:t}=u({queryKey:[r.projects,o,r.networks,e,r.forwards,n],queryFn:()=>_(e??"",n??"",o??"")}),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})))??[],location:t==null?void 0:t.location},enableReinitialize:!0,validationSchema:q,onSubmit:a=>{const d=v(a);L(e??"",d,o??"").then(()=>{k.invalidateQueries({queryKey:[r.projects,o,r.networks,e,r.forwards]}),m(`/ui/project/${o}/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:f}),i.jsxs(E,{children:[i.jsx(b,{className:"p-button--base",to:`/ui/project/${o}/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{I as default};
