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-Dz5JRQhj.js";import{N as x,t as y,a as B}from"./NetworkLoadBalancerForm-B_Mxn1oR.js";import{c as g}from"./network-load-balancers-lf3pAEUH.js";import{B as v}from"./BaseLayout-Zdoa_UmA.js";import{H as E}from"./HelpLink-IKbgKG-X.js";import{F}from"./FormFooterLayout-Da4gzEk-.js";import{u as S}from"./useNetworks-kWi7yZ5O.js";import"./ScrollableForm-1W--OJbe.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};
