import{E as N,s as y,d as l,n as B,H as j,r as L,aS as g,l as h,q as s,j as r,L as x}from"./index-66XtK6kJ.js";import{N as C,t as E,a as v}from"./NetworkLoadBalancerForm--djYWSbK.js";import{u as F,f as S}from"./network-load-balancers-CZoG8e_b.js";import{B as _}from"./BaseLayout-DHllEyf6.js";import{H as q}from"./HelpLink-DrvsxU7S.js";import{F as R}from"./FormFooterLayout-CcTAlRx3.js";import{u as $}from"./useNetworks-CRf3hLWI.js";import"./ScrollableForm-DnwqOi93.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()=>S(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(_,{title:r.jsx(q,{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(R,{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};
