import{k as N,d as m,h as g,n as j,r as b,z as h,f as F,q as t,j as i,L as x}from"./index-lOezWVmi.js";import{N as C,t as v,a as q}from"./NetworkForwardForm-DyJBaJAy.js";import{u as E,f as L}from"./network-forwards-DOX4mTcD.js";import{B as A}from"./BaseLayout-CM5eWMFT.js";import{H as R}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 D=()=>{const w=N(),u=m.useNotify(),f=m.useToastNotification(),l=g(),{network:o,project:r,forwardAddress:n,memberName:d}=j(),{data:k,error:c}=_(o??"",r??"");b.useEffect(()=>{c&&u.failure("Loading network failed",c)},[c]);const{data:e}=h({queryKey:[t.projects,r,t.networks,o,t.forwards,n,t.members,d],queryFn:async()=>L(o??"",n??"",r??"",d??"")}),s=F({initialValues:{listenAddress:n??"",defaultTargetAddress:(e==null?void 0:e.config.target_address)??"",description:(e==null?void 0:e.description)??"",ports:(e==null?void 0:e.ports.map(a=>({listenPort:a.listen_port,protocol:a.protocol,targetAddress:a.target_address,targetPort:a.target_port})))??[],location:e==null?void 0:e.location},enableReinitialize:!0,validationSchema:C,onSubmit:a=>{const p=v(a);E(o??"",p,r??"").then(()=>{l.invalidateQueries({queryKey:[t.projects,r,t.networks,o,t.forwards]}),l.invalidateQueries({queryKey:[t.projects,r,t.networks,o,t.forwards,n,t.members,d]}),w(`/ui/project/${encodeURIComponent(r??"")}/network/${encodeURIComponent(o??"")}/forwards`),f.success(`Network forward ${p.listen_address} updated.`)}).catch(y=>{s.setSubmitting(!1),u.failure("Network forward update failed",y)})}});return i.jsxs(A,{title:i.jsx(R,{docPath:"/howto/network_forwards/",title:"Learn more about network forwards",children:"Edit a network forward"}),contentClassName:"edit-network",children:[i.jsx(q,{formik:s,isEdit:!0,network:k}),i.jsxs(S,{children:[i.jsx(x,{className:"p-button--base",to:`/ui/project/${encodeURIComponent(r??"")}/network/${encodeURIComponent(o??"")}/forwards`,children:"Cancel"}),i.jsx(m.ActionButton,{appearance:"positive",loading:s.isSubmitting,disabled:!s.isValid||s.isSubmitting||!s.values.listenAddress,onClick:()=>void s.submitForm(),children:"Update"})]})]})};export{D as default};
