import{eB as M,r as o,j as e,q as f,be as E,n as P,v as T,u as G,bX as H,bx as $,cy as q,bW as B,bk as O,aJ as R,x as k,a4 as D,a5 as N,F as V,ap as I}from"./index-DHiyXWqE.js";import{A as J}from"./alertManagerConfig.selectors-0se_RTtj.js";import{u as F,j as W,s as X,a as Y}from"./Project-DwrxbZJj.js";const Z=({receivers:h,severityOptions:m,type:t,entityType:a,index:r,onRemove:C,alert:n,setAlert:x})=>{const y=M(),S=F()(`validation-${a}`),[j,l]=o.useState(),[b,u]=o.useState(),[w,A]=o.useState();o.useEffect(()=>{A(n.status),l(n.severity),u(n.receiver)},[n]);const v=o.useCallback(p=>s=>{x({...n,[p]:s},r)},[n,r,x]);return e.jsxs(f,{flexDirection:"row",justifyContent:"space-between",mt:"5px",children:[e.jsx(E,{width:"330px",label:"Trigger",options:t==="job"?W:S,value:w,onChange:v("status"),mr:"8px"}),e.jsx(f,{mt:"30px",mr:"8px",children:e.jsx("svg",{width:"28",height:"19",viewBox:"0 0 28 19",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M16.7024 1.08319C17.4849 0.303578 18.7512 0.305905 19.5309 1.08839L27.9116 9.5L19.5309 17.9116C18.7512 18.6941 17.4849 18.6964 16.7024 17.9168C15.92 17.1372 15.9176 15.8709 16.6972 15.0884L20.2725 11.5H2.08838C0.983809 11.5 0.0883789 10.6046 0.0883789 9.5C0.0883789 8.39543 0.983809 7.5 2.08838 7.5H20.2725L16.6972 3.91161C15.9176 3.12913 15.92 1.8628 16.7024 1.08319Z",fill:y.colors.grayShade2})})}),e.jsx(E,{width:"230px",label:"Severity",options:m||[],value:j,onChange:v("severity"),mr:"8px"}),e.jsx(E,{sx:{flex:"4 0"},width:"100%",label:"Receiver",options:h||[],value:b,isDisabled:!h||h.length<1,noDataMessage:"You have to setup receivers first",onChange:v("receiver"),mr:"8px"}),e.jsx(P,{mt:"23px",onClick:()=>{C(r)},icon:T.bin,tooltip:"Remove"})]})},Q=({type:h,entityType:m="fg",alerts:t,setAlerts:a,error:r,mb:C})=>{const{id:n}=G(),x=H(X),[y,S]=o.useState([]),j=F()(`validation-${m}`),{canAddGlobalEvent:l}=Y(),b=$(),{isAdmin:u}=q(),w=Object.keys(J).filter(s=>Number.isNaN(Number(s))),A=o.useCallback((s,i)=>{const c=t.map((d,g)=>g===i?s:d);a([...c])},[t,a]),v=()=>(t?t.filter(i=>{var c,d,g;return((c=i.status)==null?void 0:c.length)>1&&((d=i.severity)==null?void 0:d.length)>1&&((g=i.receiver)==null?void 0:g.length)>1}):[]).length===t.length,p=B();return o.useEffect(()=>{p.alerts.fetch(+n),p.alerts.fetchReceivers(+n)},[p.alerts,n]),o.useEffect(()=>{var s;S((s=x.receivers)==null?void 0:s.map(i=>i.name))},[x]),e.jsxs(O,{mb:C||0,title:"Alerts",sx:{width:"100%"},children:[u&&l&&e.jsx(R,{onClick:()=>{b(k.settings.alerts.list)},intent:"inline",mt:-10,pl:0,children:"Go to alert configuration↗"}),!u&&!l&&e.jsx(f,{flexDirection:"row",children:e.jsx(D,{content:"To add alerts, a Hops Admin has to configure alerts channels first.",type:N.neutral})}),u&&!l&&e.jsx(f,{flexDirection:"row",children:e.jsx(D,{type:N.neutral,content:"To add alerts, you need to configure alert channels first",cta:e.jsx(R,{onClick:()=>{b(k.settings.alerts.list)},intent:"secondary",children:"Go to alerts configuration"})})}),l&&e.jsxs(e.Fragment,{children:[t&&t.length>0&&e.jsx(V,{children:e.jsxs(f,{flexDirection:"column",p:"10px",sx:{border:"1px solid",borderColor:"grayShade2"},children:[t.map((s,i)=>e.jsx(Z,{index:i,receivers:y,severityOptions:w,type:h,entityType:m,onRemove:c=>{if(t.length>0){const d=t.filter((g,L)=>L!==c);a(d)}},alert:s,setAlert:A},i)),r&&e.jsx(I,{intent:"error",children:r})]})}),e.jsx(R,{onClick:()=>{t.length<j.length&&a([...t,{}])},intent:t&&t.length>0?"ghost":"secondary",mt:"5px",disabled:t.length>=j.length||!v(),children:t&&t.length>0?"Add another alert":"Add alert"})]})]})};export{Q as A};
