import{E as N,s as y,d as l,n as B,H as j,r as L,aT as g,l as h,q as s,j as r,L as x}from"./index-Dz5JRQhj.js";import{N as C,t as E,a as v}from"./NetworkLoadBalancerForm-B_Mxn1oR.js";import{u as F,f as _}from"./network-load-balancers-lf3pAEUH.js";import{B as q}from"./BaseLayout-Zdoa_UmA.js";import{H as R}from"./HelpLink-IKbgKG-X.js";import{F as S}from"./FormFooterLayout-Da4gzEk-.js";import{u as $}from"./useNetworks-kWi7yZ5O.js";import"./ScrollableForm-1W--OJbe.js";const V=()=>{const m=N(),p=y(),d=l.useNotify(),k=l.useToastNotification(),f=B(),{network:a,project:t,listenAddress:i}=j(),{data:w,error:c}=$(a??"",t??"");L.useEffect(()=>{c&&d.failure("Loading network failed",c)},[c]);const{data:n}=g({queryKey:[s.projects,t,s.networks,a,s.loadBalancers,i],queryFn:async()=>_(a??"",i??"",t??"")}),o=h({initialValues:{listenAddress:i??"",description:n?.description??"",ports:n?.ports?.map(e=>({listenPort:e.listen_port,protocol:e.protocol,targetBackend:e.target_backend.join(",")}))??[],backends:n?.backends?.map(e=>({name:e.name,targetAddress:e.target_address,targetPort:e.target_port??""}))??[],location:n?.location},enableReinitialize:!0,validationSchema:C,onSubmit:e=>{const u=E(e);F(a??"",u,t??"").then(()=>{f.invalidateQueries({queryKey:[s.projects,t,s.networks,a,s.loadBalancers]}),p(`/ui/project/${encodeURIComponent(t??"")}/network/${encodeURIComponent(a??"")}/load-balancers`),k.success(`Network load balancer ${u.listen_address} updated.`)}).catch(b=>{o.setSubmitting(!1),d.failure("Network load balancer update failed",b)})}});return r.jsxs(q,{title:r.jsx(R,{href:`${m}/howto/network_load_balancers/`,title:"Learn more about network load balancers",children:"Edit a network load balancer"}),contentClassName:"edit-network",children:[r.jsx(v,{formik:o,isEdit:!0,network:w}),r.jsxs(S,{children:[r.jsx(x,{className:"p-button--base",to:`/ui/project/${encodeURIComponent(t??"")}/network/${encodeURIComponent(a??"")}/load-balancers`,children:"Cancel"}),r.jsx(l.ActionButton,{appearance:"positive",loading:o.isSubmitting,disabled:!o.isValid||o.isSubmitting||!o.values.listenAddress,onClick:()=>{o.submitForm()},children:"Update"})]})]})};export{V as default};
