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-BTX30BGB.js";import{N as q,t as v,a as A}from"./NetworkForwardForm-AmAZJKo8.js";import{u as L,f as _}from"./network-forwards-C9rQkTHv.js";import{B as $}from"./BaseLayout-C9qzVjMS.js";import{H as C}from"./HelpLink-kd-C01he.js";import{F as E}from"./FormFooterLayout-C8pm2C5J.js";import{d as S}from"./networks-CpaxpXQg.js";import"./index.esm-BV12eBbn.js";import"./NotificationRow-BrFpgHY8.js";import"./ClusterMemberSelector-DcVN_9Mu.js";import"./formFields-BDRvqvBI.js";import"./ScrollableContainer-BFMZMaL4.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};
