import{aF as V,r as o,j as e,B as f,bm as E,f as Z,Z as B,u as F,aL as H,bw as M,cf as T,aD as $,ds as O,aG as R,s as D,af as k,ag as N,e as P,at as _}from"./index-dP1W1_bd.js";import{A as I}from"./alertManagerConfig.selectors-B_R5cvew.js";import{u as L,j as K,s as Q,a as Y}from"./Project-CsYwwOpN.js";const q=({receivers:h,severityOptions:m,type:t,entityType:a,index:r,onRemove:b,alert:n,setAlert:u})=>{const y=V(),w=L()(`validation-${a}`),[j,l]=o.useState(),[C,x]=o.useState(),[S,A]=o.useState();o.useEffect(()=>{A(n.status),l(n.severity),x(n.receiver)},[n]);const v=o.useCallback(g=>s=>{u({...n,[g]:s},r)},[n,r,u]);return e.jsxs(f,{flexDirection:"row",justifyContent:"space-between",mt:"5px",children:[e.jsx(E,{width:"330px",label:"Trigger",options:t==="job"?K:w,value:S,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:C,isDisabled:!h||h.length<1,noDataMessage:"You have to setup receivers first",onChange:v("receiver"),mr:"8px"}),e.jsx(Z,{mt:"23px",onClick:()=>{b(r)},icon:B.bin,tooltip:"Remove"})]})},W=({type:h,entityType:m="fg",alerts:t,setAlerts:a,error:r,mb:b})=>{const{id:n}=F(),u=H(Q),[y,w]=o.useState([]),j=L()(`validation-${m}`),{canAddGlobalEvent:l}=Y(),C=M(),{isAdmin:x}=T(),S=Object.keys(I).filter(s=>Number.isNaN(Number(s))),A=o.useCallback((s,i)=>{const c=t.map((d,p)=>p===i?s:d);a([...c])},[t,a]),v=()=>(t?t.filter(i=>{var c,d,p;return((c=i.status)==null?void 0:c.length)>1&&((d=i.severity)==null?void 0:d.length)>1&&((p=i.receiver)==null?void 0:p.length)>1}):[]).length===t.length,g=$();return o.useEffect(()=>{g.alerts.fetch(+n),g.alerts.fetchReceivers(+n)},[g.alerts,n]),o.useEffect(()=>{var s;w((s=u.receivers)==null?void 0:s.map(i=>i.name))},[u]),e.jsxs(O,{mb:b||0,title:"Alerts",sx:{width:"100%"},children:[x&&l&&e.jsx(R,{onClick:()=>{C(D.settings.alerts.list)},intent:"inline",mt:-10,pl:0,children:"Go to alert configuration↗"}),!x&&!l&&e.jsx(f,{flexDirection:"row",children:e.jsx(k,{content:"To add alerts, a Hops Admin has to configure alerts channels first.",type:N.neutral})}),x&&!l&&e.jsx(f,{flexDirection:"row",children:e.jsx(k,{type:N.neutral,content:"To add alerts, you need to configure alert channels first",cta:e.jsx(R,{onClick:()=>{C(D.settings.alerts.list)},intent:"secondary",children:"Go to alerts configuration"})})}),l&&e.jsxs(e.Fragment,{children:[t&&t.length>0&&e.jsx(P,{children:e.jsxs(f,{flexDirection:"column",p:"10px",sx:{border:"1px solid",borderColor:"grayShade2"},children:[t.map((s,i)=>e.jsx(q,{index:i,receivers:y,severityOptions:S,type:h,entityType:m,onRemove:c=>{if(t.length>0){const d=t.filter((p,G)=>G!==c);a(d)}},alert:s,setAlert:A},i)),r&&e.jsx(_,{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{W as A};
