import{eg as T,r as o,j as e,B as m,be as E,e as $,C as B,u as G,bK as H,bp as P,cm as F,bI as M,dz as O,b4 as R,s as k,ah as D,ai as N,d as V,aw as _}from"./index-C1DmWO_C.js";import{A as z}from"./alertManagerConfig.selectors-B9ELaxCY.js";import{u as I,j as K,s as Y,a as Z}from"./Project-CpwJZ-CK.js";const q=({receivers:h,severityOptions:f,type:t,entityType:a,index:r,onRemove:C,alert:n,setAlert:u})=>{const w=T(),y=I()(`validation-${a}`),[j,l]=o.useState(),[b,x]=o.useState(),[S,A]=o.useState();o.useEffect(()=>{A(n.status),l(n.severity),x(n.receiver)},[n]);const v=o.useCallback(p=>s=>{u({...n,[p]:s},r)},[n,r,u]);return e.jsxs(m,{flexDirection:"row",justifyContent:"space-between",mt:"5px",children:[e.jsx(E,{width:"330px",label:"Trigger",options:t==="job"?K:y,value:S,onChange:v("status"),mr:"8px"}),e.jsx(m,{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:w.colors.grayShade2})})}),e.jsx(E,{width:"230px",label:"Severity",options:f||[],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($,{mt:"23px",onClick:()=>{C(r)},icon:B.bin,tooltip:"Remove"})]})},W=({type:h,entityType:f="fg",alerts:t,setAlerts:a,error:r,mb:C})=>{const{id:n}=G(),u=H(Y),[w,y]=o.useState([]),j=I()(`validation-${f}`),{canAddGlobalEvent:l}=Z(),b=P(),{isAdmin:x}=F(),S=Object.keys(z).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=M();return o.useEffect(()=>{p.alerts.fetch(+n),p.alerts.fetchReceivers(+n)},[p.alerts,n]),o.useEffect(()=>{var s;y((s=u.receivers)==null?void 0:s.map(i=>i.name))},[u]),e.jsxs(O,{mb:C||0,title:"Alerts",sx:{width:"100%"},children:[x&&l&&e.jsx(R,{onClick:()=>{b(k.settings.alerts.list)},intent:"inline",mt:-10,pl:0,children:"Go to alert configuration↗"}),!x&&!l&&e.jsx(m,{flexDirection:"row",children:e.jsx(D,{content:"To add alerts, a Hops Admin has to configure alerts channels first.",type:N.neutral})}),x&&!l&&e.jsx(m,{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(m,{flexDirection:"column",p:"10px",sx:{border:"1px solid",borderColor:"grayShade2"},children:[t.map((s,i)=>e.jsx(q,{index:i,receivers:w,severityOptions:S,type:h,entityType:f,onRemove:c=>{if(t.length>0){const d=t.filter((g,L)=>L!==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};
