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-CzUo07dn.js";import{c as v,a as F}from"./index.esm-BBoKC3tX.js";import{b as L}from"./networks-AOdNDxHC.js";import{M as q,N as R,t as p}from"./NetworkAclForm-BX3RXhog.js";import{N as $}from"./NotificationRow-IVGrYQV6.js";import{c as B,y as M,d as O}from"./YamlSwitch-DLbjsyg1.js";import{B as T}from"./BaseLayout-D6pt0Et9.js";import{F as E}from"./FormFooterLayout-CkQ9739Z.js";import{R as I}from"./ResourceLink-5fvv3Myt.js";import"./FormMenuItem-D-3tk9Lf.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-DYgLBIgn.js";import"./AutoExpandingTextArea-DbenJele.js";import"./ScrollableTable-COas1_r_.js";import"./formFields-BDRvqvBI.js";import"./snapshots-DWXTDgvk.js";import"./YamlNotification-DqaTFbgr.js";import"./ScrollableContainer-CSFAM_C4.js";import"./ResourceIcon-CQum9kVZ.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};
