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-DyZtLAjB.js";import{N as F}from"./NotificationRow-Cej0AnMm.js";import{y as q,c as I,o as Y}from"./YamlSwitch-Dvinbbrq.js";import{B as $}from"./BaseLayout-BBVAHUxR.js";import{G as m,Y as u}from"./NetworkFormMenu-BRzQ6J0t.js";import{F as E}from"./FormFooterLayout-BVf_vA5z.js";import{t as T,N as U}from"./NetworkAclForm-2yFfpbJw.js";import{c as B}from"./network-acls-CexLeYRs.js";import"./FormMenuItem-CJDouiNf.js";import"./AutoExpandingTextArea-C1-nUkpQ.js";import"./SshKeyForm-wbISdgZG.js";import"./formFields-BbQUt1T2.js";import"./limits-CLEFMbq-.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-DgM07anl.js";import"./snapshots-CdXTmGic.js";import"./ExpandableList-CloHwvSX.js";import"./UsedByItem-BoyTnSNa.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};
