import{k as g,d as a,h as x,n as A,r as c,V as n,j as e,c as v,b as S,Y as b,f as R,q as l,R as L}from"./index-DET0E_3l.js";import{N as F}from"./NotificationRow-BgqB5Xch.js";import{y as q,c as I,o as Y}from"./YamlSwitch-BHRorJou.js";import{B as $}from"./BaseLayout-CzqnKJIH.js";import{G as m,Y as u}from"./NetworkFormMenu-B04_v0-q.js";import{F as E}from"./FormFooterLayout-YMKZRDmQ.js";import{t as T,N as U}from"./NetworkAclForm-hPRjrqtf.js";import{c as B}from"./network-acls-C0nCs2DL.js";import"./FormMenuItem-CafR0V9n.js";import"./AutoExpandingTextArea-C0eJ1NqN.js";import"./SshKeyForm-CCywfCqi.js";import"./formFields-D4E6x_f1.js";import"./limits-CLEFMbq-.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-9ZU6uOm7.js";import"./snapshots-Bv7XY7g-.js";import"./ExpandableList--o9sPOUL.js";import"./UsedByItem-DZYeZo1T.js";const oe=()=>{const i=g(),p=a.useNotify(),d=a.useToastNotification(),k=x(),{project:o}=A(),[r,y]=c.useState(n(m)),w=c.useState(null);if(!o)return e.jsx(e.Fragment,{children:"Missing project"});const f=v().shape({name:S().test("deduplicate","An ACL with this name already exists",async s=>b(s,o,w,"network-acls")).required("ACL name is required")}),t=R({initialValues:{readOnly:!1,isCreating:!0,name:"",egress:[],ingress:[],entityType:"network-acl"},validationSchema:f,onSubmit:s=>{const C=s.yaml?q(s.yaml):T(t.values);B(C,o).then(()=>{k.invalidateQueries({queryKey:[l.projects,o,l.networkAcls]}),i(`/ui/project/${encodeURIComponent(o)}/network-acls`),d.success(e.jsxs(e.Fragment,{children:["Network ACL"," ",e.jsx(L,{type:"network-acl",value:s.name,to:`/ui/project/${encodeURIComponent(o)}/network-acl/${encodeURIComponent(s.name)}`})," ","created."]}))}).catch(N=>{t.setSubmitting(!1),p.failure("Network ACL creation failed",N)})}}),j=s=>{y(n(s))},h=()=>{const s={name:t.values.name,description:t.values.description,ingress:t.values.ingress,egress:t.values.egress};return Y(s)};return e.jsxs($,{title:"Create a network ACL",contentClassName:"create-network-acl",children:[e.jsxs(a.Row,{children:[e.jsx(F,{}),e.jsx(U,{formik:t,getYaml:h,section:r})]}),e.jsxs(E,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(I,{formik:t,section:r,setSection:()=>{j(r===n(u)?m:u)},disableReason:t.values.name?void 0:"Please enter a network ACL name to enable this section"})}),e.jsx(a.Button,{appearance:"base",onClick:async()=>i(`/ui/project/${encodeURIComponent(o)}/network-acls`),children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",loading:t.isSubmitting,disabled:t.values.name.length===0||t.isSubmitting,onClick:()=>void t.submitForm(),children:"Create"})]})]})};export{oe as default};
