import{s as v,d as m,n as _,H as C,Q as E,J as S,r as A,aP as R,l as $,j as a,L as q,R as g,q as e}from"./index-C88DWJny.js";import{N as L,t as Q,a as U}from"./NetworkForwardForm-DIfr_DGi.js";import{u as P,f as H}from"./network-forwards-CHB4VIhb.js";import{B as I}from"./BaseLayout-axPPiMeo.js";import{H as K}from"./HelpLink-c8Zoz7ma.js";import{F as T}from"./FormFooterLayout-BHqxrLH2.js";import{u as B}from"./useNetworks-C8634WBO.js";import"./ScrollableForm-ChpocQAZ.js";import"./ClusterMemberSelector-Ciw-uzfW.js";const Y=()=>{const h=v(),w=m.useNotify(),f=m.useToastNotification(),p=_(),{network:r,project:o,forwardAddress:i,memberName:c}=C(),{data:F,error:u}=B(r??"",o??""),{hasStorageAndNetworkOperations:j}=E(),b=S();A.useEffect(()=>{u&&w.failure("Loading network failed",u)},[u]);const{data:d}=R({queryKey:[e.projects,o,e.networks,r,e.forwards,i,e.members,c],queryFn:async()=>H(r??"",i??"",o??"",c??"")}),k=()=>{p.invalidateQueries({queryKey:[e.projects,o,e.networks,r,e.forwards]}),p.invalidateQueries({queryKey:[e.projects,o,e.networks,r,e.forwards,i,e.members,c]})},y=t=>{k(),h(`${g}/ui/project/${encodeURIComponent(o??"")}/network/${encodeURIComponent(r??"")}/forwards`),f.success(`Network forward ${t} updated.`)},N=(t,s)=>{k(),n.setSubmitting(!1),w.failure(`Update of network forward ${t} failed`,s)},n=$({initialValues:{listenAddress:i??"",defaultTargetAddress:d?.config.target_address??"",description:d?.description??"",ports:d?.ports.map(t=>({listenPort:t.listen_port,protocol:t.protocol,targetAddress:t.target_address,targetPort:t.target_port}))??[],location:d?.location},enableReinitialize:!0,validationSchema:L,onSubmit:t=>{const s=Q(t);P(r??"",s,o??"").then(l=>{j?(f.info(a.jsxs(a.Fragment,{children:["Update of network forward ",s.listen_address," has started."]})),b.set(l.metadata.id,()=>{y(s.listen_address)},x=>{N(s.listen_address,new Error(x))})):y(s.listen_address)}).catch(l=>{N(s.listen_address,l)})}});return a.jsxs(I,{title:a.jsx(K,{docPath:"/howto/network_forwards/",title:"Learn more about network forwards",children:"Edit a network forward"}),contentClassName:"edit-network",children:[a.jsx(U,{formik:n,isEdit:!0,network:F}),a.jsxs(T,{children:[a.jsx(q,{className:"p-button--base",to:`${g}/ui/project/${encodeURIComponent(o??"")}/network/${encodeURIComponent(r??"")}/forwards`,children:"Cancel"}),a.jsx(m.ActionButton,{appearance:"positive",loading:n.isSubmitting,disabled:!n.isValid||n.isSubmitting||!n.values.listenAddress,onClick:()=>{n.submitForm()},children:"Update"})]})]})};export{Y as default};
