import{f as x,d as s,k as A,l as C,o as S,r as c,J as m,j as t,M as g,c as b,q as l}from"./index-Cziemgsu.js";import{c as v,a as F}from"./index.esm-dDZ7-lOE.js";import{b as L}from"./networks-mhWNV24c.js";import{M as q,N as R,t as p}from"./NetworkAclForm-DDs63e-T.js";import{N as $}from"./NotificationRow-BJRTvUVl.js";import{c as B,y as M,d as O}from"./YamlSwitch-GKWclbu0.js";import{B as T}from"./BaseLayout-7LTMOawH.js";import{F as E}from"./FormFooterLayout-BJQGpdhQ.js";import{R as I}from"./ResourceLink-D2AYI_En.js";import"./FormMenuItem-phSiN9Ls.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-1GO19eHS.js";import"./AutoExpandingTextArea-Bc4N4lSt.js";import"./ScrollableTable-D1yV1_jU.js";import"./formFields-BDRvqvBI.js";import"./snapshots-AEdTpwkf.js";import"./YamlNotification-hNvwvtOz.js";import"./ScrollableContainer-C6sud4ax.js";import"./ResourceIcon-DRRIqKSs.js";const st=()=>{const r=x(),u=s.useNotify(),d=A(),k=C(),{project:o}=S(),[i,f]=c.useState(m(q)),w=c.useState(null);if(!o)return t.jsx(t.Fragment,{children:"Missing project"});const y=v().shape({name:F().test("deduplicate","A network ACL with this name already exists",e=>g(e,o,w,"network-acls")).required("Network ACL name is required")}),a=b({initialValues:{readOnly:!1,isCreating:!0,name:"",entityType:"networkAcl"},validationSchema:y,onSubmit:e=>{const j=e.yaml?M(e.yaml):p(e);L(j,o).then(()=>{k.invalidateQueries({queryKey:[l.projects,o,l.networkAcls]}),r(`/ui/project/${o}/network-acls`),d.success(t.jsxs(t.Fragment,{children:["Network ACL"," ",t.jsx(I,{type:"network-acl",value:e.name,to:`/ui/project/${o}/network-acls/${e.name}`})," ","created."]}))}).catch(h=>{a.setSubmitting(!1),u.failure("Network ACL creation failed",h)})}}),N=()=>{const e=p(a.values);return O(e)},n=e=>{f(m(e))};return t.jsxs(T,{title:"Create a network ACL",contentClassName:"create-network",children:[t.jsx($,{}),t.jsx(R,{formik:a,getYaml:N,section:i,setSection:n}),t.jsxs(E,{children:[t.jsx("div",{className:"yaml-switch",children:t.jsx(B,{formik:a,section:i,setSection:n,disableReason:a.values.name?void 0:"Please enter a network ACL name to enable this section"})}),t.jsx(s.Button,{appearance:"base",onClick:()=>r(`/ui/project/${o}/network-acls`),children:"Cancel"}),t.jsx(s.ActionButton,{appearance:"positive",loading:a.isSubmitting,disabled:!a.isValid||!a.values.name,onClick:()=>void a.submitForm(),children:"Create"})]})]})};export{st as default};
