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-Dz5JRQhj.js";import{y as P,d as H,o as K}from"./YamlSwitch-BsfuLnhQ.js";import{B as M}from"./BaseLayout-Zdoa_UmA.js";import{G as j,Y as y}from"./NetworkFormMenu-CwcyljSA.js";import{F as _}from"./FormFooterLayout-Da4gzEk-.js";import{t as z,N as D}from"./NetworkAclForm-BI2bP_LV.js";import{c as J}from"./network-acls-AXDaDgjx.js";import"./FormMenuItem-lDrBwrvi.js";import"./AutoExpandingTextArea-D6xwa84K.js";import"./UsedByRow-pMRLFfUg.js";import"./UsedByItem-DL7zobGp.js";import"./useImages-D_Klrmxd.js";import"./image-registries-8O1zsvZX.js";import"./imageServers-B4hb8Ggx.js";import"./ProfileRichChip-SxdUk4Mb.js";import"./ProfileResourceLimits-Bjfzp666.js";import"./ExpandableList-C5toH4xB.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};
