import{E as N,s as y,d as l,n as B,H as j,r as L,aP as g,l as h,q as s,j as r,L as x}from"./index-C88DWJny.js";import{N as C,t as E,a as v}from"./NetworkLoadBalancerForm-ruZCVsss.js";import{u as F,f as _}from"./network-load-balancers-D1QMrTOv.js";import{B as q}from"./BaseLayout-axPPiMeo.js";import{H as R}from"./HelpLink-c8Zoz7ma.js";import{F as S}from"./FormFooterLayout-BHqxrLH2.js";import{u as $}from"./useNetworks-C8634WBO.js";import"./ScrollableForm-ChpocQAZ.js";const z=()=>{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{z as default};
