import{s as v,d as m,n as _,H as C,Q as E,J as S,r as A,aT as R,l as $,j as a,L as q,R as g,q as e}from"./index-Dz5JRQhj.js";import{N as L,t as Q,a as U}from"./NetworkForwardForm-DzP5GBgc.js";import{u as P,f as T}from"./network-forwards-DzKPx1h6.js";import{B as H}from"./BaseLayout-Zdoa_UmA.js";import{H as I}from"./HelpLink-IKbgKG-X.js";import{F as K}from"./FormFooterLayout-Da4gzEk-.js";import{u as B}from"./useNetworks-kWi7yZ5O.js";import"./ScrollableForm-1W--OJbe.js";import"./ClusterMemberSelector-Dlkp1Rus.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()=>T(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(H,{title:a.jsx(I,{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(K,{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};
