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-lOezWVmi.js";import{N as F}from"./NotificationRow-DdxAfFhk.js";import{y as q,c as I,o as Y}from"./YamlSwitch-Dx35FPoh.js";import{B as $}from"./BaseLayout-CM5eWMFT.js";import{G as m,Y as u}from"./NetworkFormMenu-DEGyoSSo.js";import{F as E}from"./FormFooterLayout-B1eckygM.js";import{t as T,N as U}from"./NetworkAclForm-BBTYD3fD.js";import{c as B}from"./network-acls-B9tLpGS2.js";import"./FormMenuItem-D_mb6BGW.js";import"./AutoExpandingTextArea-CUTbkJs9.js";import"./SshKeyForm-DyzN8_u6.js";import"./formFields-D9YYYKxX.js";import"./limits-CLEFMbq-.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-CHLzDgpY.js";import"./snapshots-ByuD-MsK.js";import"./ExpandableList-QVhlqlHQ.js";import"./UsedByItem-DaMb0MQB.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};
