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-C88DWJny.js";import{y as P,d as H,o as K}from"./YamlSwitch-BOxCVwX4.js";import{B as M}from"./BaseLayout-axPPiMeo.js";import{G as j,Y as y}from"./NetworkFormMenu-C1uTzckQ.js";import{F as _}from"./FormFooterLayout-BHqxrLH2.js";import{t as z,N as D}from"./NetworkAclForm-_ZA0jnah.js";import{c as J}from"./network-acls-DoFbevfN.js";import"./FormMenuItem-f1QSo43l.js";import"./AutoExpandingTextArea-BSlqPK2l.js";import"./UsedByRow-Cdbm4-ZF.js";import"./UsedByItem-CNDK_7QF.js";import"./useImages-D7BEIPVo.js";import"./image-registries-T9CKqPfx.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-BlhTHgMo.js";import"./ProfileResourceLimits-ChaqL2tV.js";import"./ExpandableList-DztXpwLZ.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};
