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