import{d as o,r as m,D as v,j as t,H as F,n as P,f as A,k as L,l as S,o as I,g as R,c as k,L as q,e as $,q as p}from"./index-CzUo07dn.js";import{c as E}from"./index.esm-BBoKC3tX.js";import{N as _}from"./NotificationRow-IVGrYQV6.js";import{S as H,F as D}from"./FormFooterLayout-CkQ9739Z.js";import{B as O}from"./BaseLayout-D6pt0Et9.js";import{H as T}from"./HelpLink-INVHAe6u.js";import{u as B,f as K}from"./networks-AOdNDxHC.js";import"./ScrollableContainer-CSFAM_C4.js";const M=e=>({action:e.action,state:e.state,description:e.description,source:e.source,destination:e.destination,protocol:e.protocol,source_port:e.sourcePort,destination_port:e.destinationPort,icmp_type:e.icmpType,icmp_code:e.icmpCode}),Q=E().shape({}),V=({formik:e,showNotify:b})=>{var a;const i=o.useNotify(),r=m.useRef(null),n=()=>{F("form-contents","p-bottom-controls")};return m.useEffect(n,[(a=i.notification)==null?void 0:a.message]),v("resize",n),m.useEffect(()=>{var c;(c=r.current)==null||c.scrollIntoView({behavior:"smooth"})},[b]),t.jsx(o.Form,{className:"form network-forwards-form",onSubmit:e.handleSubmit,children:t.jsx(o.Row,{className:"form-contents",children:t.jsx(o.Col,{size:12,children:t.jsxs(H,{children:[t.jsx(o.Input,{type:"submit",hidden:!0,value:"Hidden input"}),t.jsx("div",{ref:r,children:t.jsx(o.Row,{className:"p-form__group p-form-validation",children:t.jsx(_,{})})}),t.jsx(o.Select,{...e.getFieldProps("action"),options:[{label:"allow",value:"allow"},{label:"allow-stateless",value:"allow-stateless"},{label:"reject",value:"reject"},{label:"drop",value:"drop"}],onChange:e.handleChange,label:"Action",help:"Action to take for matching traffic",required:!0,disabled:e.values.readOnly||!e.values.isCreating}),t.jsx(o.Select,{...e.getFieldProps("state"),options:[{label:"enabled",value:"enabled"},{label:"disabled",value:"disabled"},{label:"logged",value:"logged"}],onChange:e.handleChange,label:"State",help:"State of the rule",required:!0,disabled:e.values.readOnly||!e.values.isCreating}),t.jsx(o.Input,{...e.getFieldProps("description"),id:"description",type:"text",label:"Description",placeholder:"Enter description"}),t.jsx(o.Input,{...e.getFieldProps("source"),id:"source",type:"text",label:"Source"}),t.jsx(o.Input,{...e.getFieldProps("destination"),id:"destination",type:"text",label:"Destination"}),t.jsx(o.Select,{...e.getFieldProps("protocol"),options:[{label:"",value:""},{label:"icmp4",value:"icmp4"},{label:"icmp6",value:"icmp6"},{label:"tcp",value:"tcp"},{label:"udp",value:"udp"}],onChange:e.handleChange,label:"Protocol",disabled:e.values.readOnly||!e.values.isCreating}),t.jsx(o.Input,{...e.getFieldProps("sourcePort"),id:"sourcePort",type:"text",label:"Source port"}),t.jsx(o.Input,{...e.getFieldProps("destinationPort"),id:"destinationPort",type:"text",label:"Destination port"}),t.jsx(o.Input,{...e.getFieldProps("icmpType"),id:"icmpType",type:"text",label:"ICMP type"}),t.jsx(o.Input,{...e.getFieldProps("icmpCode"),id:"icmpCode",type:"text",label:"ICMP code"})]})})})})},ee=()=>{const e=P(),b=A(),i=o.useNotify(),r=L(),n=S(),[a,c]=m.useState(!1),{acl:d,project:s,type:g}=I(),{data:y,error:x,isLoading:j}=R({queryKey:[p.projects,s,p.networkAcls,d],queryFn:()=>K(d,s)});x&&i.failure("Loading network ACL failed",x);const f=g,l=k({initialValues:{readOnly:!1,isCreating:!0,action:"allow",state:"enabled"},validationSchema:Q,onSubmit:w=>{const C=M(w),u=y,h={...u,ingress:[...u.ingress],egress:[...u.egress]};h[f].push(C),B({...h,etag:h.etag},s).then(()=>{n.invalidateQueries({queryKey:[p.projects,s,p.networkAcls,u.name]}),b(`/ui/project/${s}/network-acls/${d}/${g}`),r.success(t.jsx(t.Fragment,{children:"Network ACL rule added."}))}).catch(N=>{i.failure("Network ACL rule update failed",N),c(!a)}).finally(()=>l.setSubmitting(!1))}});return j?t.jsx(q,{text:"Loading network ACL..."}):t.jsxs(O,{title:t.jsx(T,{href:`${e}/howto/network_acls/`,title:"Learn more about network ACLs",children:"Create a network ACL rule"}),contentClassName:"create-network",children:[t.jsx(V,{formik:l,showNotify:a}),t.jsxs(D,{children:[t.jsx($,{className:"p-button--base",to:`/ui/project/${s}/network-acls/${d}/${g}`,children:"Cancel"}),t.jsx(o.ActionButton,{loading:l.isSubmitting,disabled:!l.isValid,onClick:()=>void l.submitForm(),children:"Create"})]})]})};export{ee as default};
