import{s as F,d as n,n as $,H as E,r as k,au as c,Q as O,J as T,j as e,f as q,h as I,z as U,l as Q,R as l,t as Y,e as B,o as G,q as w}from"./index-C6X1YceK.js";import{y as P,d as H,o as K}from"./YamlSwitch-r29gy9XW.js";import{B as M}from"./BaseLayout-BBlTJM7k.js";import{G as j,Y as y}from"./NetworkFormMenu-BNeG2tTe.js";import{F as _}from"./FormFooterLayout-Cxn5aY22.js";import{t as z,N as D}from"./NetworkAclForm-CYT2MM-e.js";import{c as J}from"./network-acls-9F8fg2yt.js";import"./FormMenuItem-CyQ1NpRu.js";import"./AutoExpandingTextArea-B-7MHL2n.js";import"./UsedByRow-BgtswVKB.js";import"./UsedByItem-DhKdJMhn.js";import"./useImages-pmJSlY_A.js";import"./image-registries-BVHvhUXZ.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-S6d1WGob.js";import"./ProfileResourceLimits-Dix7I59c.js";import"./ExpandableList-DW7n7Ci8.js";const de=()=>{const m=F(),C=n.useNotify(),u=n.useToastNotification(),f=$(),{project:o}=E(),[r,g]=k.useState(c(j)),A=k.useState(null),{hasStorageAndNetworkOperations:x}=O(),v=T();if(!o)return e.jsx(e.Fragment,{children:"Missing project"});const N=q().shape({name:I().test("deduplicate","An ACL with this name already exists",async t=>U(t,o,A,"network-acls")).required("ACL name is required")}),S=t=>`${l}/ui/project/${encodeURIComponent(o)}/network-acl/${encodeURIComponent(t)}`,p=()=>{f.invalidateQueries({queryKey:[w.projects,o,w.networkAcls]})},d=t=>{p(),u.success(e.jsxs(e.Fragment,{children:["Network ACL"," ",e.jsx(G,{type:"network-acl",value:t,to:S(t)})," ","created."]}))},h=(t,a)=>{p(),s.setSubmitting(!1),C.failure(`Creation of network ACL ${t} failed`,a)},s=Q({initialValues:{readOnly:!1,isCreating:!0,name:"",egress:[],ingress:[],entityType:"network-acl"},validationSchema:N,onSubmit:t=>{const a=t.yaml?P(t.yaml):z(s.values);J(a,o).then(i=>{m(`${l}/ui/project/${encodeURIComponent(o)}/network-acls`),x?(u.info(e.jsxs(e.Fragment,{children:["Creation of Network ACL"," ",e.jsx(Y,{bold:!0,type:"network-acl",value:a.name})," ","has started."]})),v.set(i.metadata.id,()=>{d(a.name)},R=>{h(a.name,new Error(R))})):d(a.name)}).catch(i=>{h(a.name,i)})}}),b=t=>{g(c(t))},L=()=>{const t={name:s.values.name,description:s.values.description,ingress:s.values.ingress,egress:s.values.egress};return K(t)};return e.jsxs(M,{title:e.jsxs(e.Fragment,{children:["Create a network ",e.jsx("abbr",{title:"Access Control List",children:"ACL"})]}),contentClassName:"create-network-acl",children:[e.jsxs(n.Row,{children:[e.jsx(B,{}),e.jsx(D,{formik:s,getYaml:L,section:r})]}),e.jsxs(_,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(H,{formik:s,section:r,setSection:()=>{b(r===c(y)?j:y)},disableReason:s.values.name?void 0:"Please enter a network ACL name to enable this section"})}),e.jsx(n.Button,{appearance:"base",onClick:async()=>m(`${l}/ui/project/${encodeURIComponent(o)}/network-acls`),children:"Cancel"}),e.jsx(n.ActionButton,{appearance:"positive",loading:s.isSubmitting,disabled:s.values.name.length===0||s.isSubmitting,onClick:()=>{s.submitForm()},children:"Create"})]})]})};export{de as default};
