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-lOezWVmi.js";import{N as E,t as F,a as _}from"./NetworkLoadBalancerForm-Cii09QPL.js";import{u as q,f as R}from"./network-load-balancers-DR25Swbu.js";import{B as S}from"./BaseLayout-CM5eWMFT.js";import{H as $}from"./HelpLink-8_zL-2ID.js";import{F as A}from"./FormFooterLayout-B1eckygM.js";import{u as U}from"./useNetworks-Dvw5If3E.js";import"./NotificationRow-DdxAfFhk.js";import"./formFields-D9YYYKxX.js";import"./networks-C9MSk_NH.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};
