import{E as w,s as b,d as n,n as N,H as L,r as h,l as j,q as i,j as a,L as C}from"./index-C88DWJny.js";import{N as x,t as y,a as B}from"./NetworkLoadBalancerForm-ruZCVsss.js";import{c as g}from"./network-load-balancers-D1QMrTOv.js";import{B as v}from"./BaseLayout-axPPiMeo.js";import{H as E}from"./HelpLink-c8Zoz7ma.js";import{F}from"./FormFooterLayout-BHqxrLH2.js";import{u as S}from"./useNetworks-C8634WBO.js";import"./ScrollableForm-ChpocQAZ.js";const Q=()=>{const d=w(),m=b(),c=n.useNotify(),u=n.useToastNotification(),k=N(),{network:t,project:o}=L(),{data:l,error:r}=S(t??"",o??"");h.useEffect(()=>{r&&c.failure("Loading networks failed",r)},[r]);const e=j({initialValues:{listenAddress:"",backends:[],ports:[]},validationSchema:x,onSubmit:p=>{const f=y(p);g(t??"",f,o??"").then(s=>{k.invalidateQueries({queryKey:[i.projects,o,i.networks,l,i.loadBalancers]}),m(`/ui/project/${encodeURIComponent(o??"")}/network/${encodeURIComponent(t??"")}/load-balancers`),u.success(`Network load balancer with listen address ${s} created.`)}).catch(s=>{e.setSubmitting(!1),c.failure("Network load balancer creation failed",s)})}});return a.jsxs(v,{title:a.jsx(E,{href:`${d}/howto/network_load_balancers/`,title:"Learn more about network load balancers",children:"Create a network load balancer"}),contentClassName:"create-network",children:[a.jsx(B,{formik:e,network:l}),a.jsxs(F,{children:[a.jsx(C,{className:"p-button--base",to:`/ui/project/${encodeURIComponent(o??"")}/network/${encodeURIComponent(t??"")}/load-balancers`,children:"Cancel"}),a.jsx(n.ActionButton,{loading:e.isSubmitting,disabled:!e.isValid||e.isSubmitting||!e.values.listenAddress,onClick:()=>{e.submitForm()},children:"Create"})]})]})};export{Q as default};
