1import{r as i,M as me,j as t,u as ce,d as si,b as Ct,af as ae,ae as Ce,x as jt,C as yt,R as et,w as We,B as vt,t as ni,N as ai,b7 as oi}from"./CgBZl8m0.production.bundle.min.js";import{f1 as ot,f2 as li,mv as ci,mw as di,mx as ui,my as mi,mz as tt,lw as fi,l2 as hi,mA as at,mB as gi,mC as Si,mD as bt,jb as xi,jd as ji,aI as it,aJ as ft,hT as vi,mE as bi,d$ as Ge,aF as wt,dY as mt,d_ as st,bc as _i,e$ as lt,aM as Ci,mF as $,ef as Z,ec as Me,eb as De,r as re,mG as Nt,ee as qe,mb as Ae,eg as Le,n as xe,o as je,el as Oe,eh as Ve,ji as Ue,iW as yi,mH as wi,mI as Ni,j8 as Lt,dI as Ai,mJ as Ei,dZ as Ti,mK as Ri,s as Ne,ej as Ut,mL as Bt,mM as Ii,f3 as $t,mN as Mi,gH as gt,mO as _t,mP as Oi,hS as Wt,mQ as ki,fK as pi,gE as ri,dX as Di,mR as zt,en as Vi,em as Pi,mS as Fi,mT as qi,mU as Li,mV as Ui,gW as Bi,mW as Gt,f0 as $i,mX as Wi,b$ as Ht,P as Yt,je as zi,u as Gi,l$ as Hi,mY as Yi,a as Ji,mZ as Ki,m_ as Qi,m$ as Zi,fQ as Jt,n0 as Xi,n1 as es,n2 as ts,n3 as is,n4 as ss,n5 as rs,n6 as ns,n7 as as,n8 as os,n9 as ls}from"./CY9JcdZ7.production.bundle.min.js";import{A as ht}from"./CK-5Vo_r.production.bundle.min.js";import{u as rt,s as Xe}from"./CUU-sqeu.production.bundle.min.js";import{f as ee,s as cs,P as Kt}from"./CHbJgqnE.production.bundle.min.js";import{u as He}from"./BWr4BVpJ.production.bundle.min.js";import{u as ds}from"./CRSxynHN.production.bundle.min.js";import{a as us,T as At,bt as ms,bu as fs}from"./B_v3Fv2u.production.bundle.min.js";import{c as hs}from"./DhCfBX8j.production.bundle.min.js";import{c as gs,r as Ss,i as xs,f as js}from"./BpQvVIpM.production.bundle.min.js";import{k as Et}from"./IimQW1M7.production.bundle.min.js";import{a as vs,G as St,b as ct}from"./D-auQP5C.production.bundle.min.js";import{B as ze}from"./B7jgtT_H.production.bundle.min.js";import{T as pe}from"./BhEpiGZx.production.bundle.min.js";import{aa as R,l as I}from"./DpOFvyFl.production.bundle.min.js";import{l as le}from"./BS0dGend.production.bundle.min.js";import{c as ke,b as Be}from"./s2Tdj82o.production.bundle.min.js";import{S as bs}from"./BfAZ3A5m.production.bundle.min.js";import{D as he,S as _s,a as Tt}from"./Czbq-YEj.production.bundle.min.js";import{F as Fe,I as Rt}from"./DuMSlPdM.production.bundle.min.js";import{u as It,A as $e}from"./BPCCmZp8.production.bundle.min.js";import{as as Cs,at as ys,au as ws,N as Ns,a7 as As,i as Es}from"./uYRgXL5M.production.bundle.min.js";import{F as Qt}from"./DV0DPFOt.production.bundle.min.js";import{A as Zt}from"./CuBqghHU.production.bundle.min.js";import{F as Ts}from"./BOFlCg2s.production.bundle.min.js";import{B as Rs}from"./sSK35D5G.production.bundle.min.js";import{b as Is,G as Ms,F as Os}from"./BFsIcxdk.production.bundle.min.js";import{U as ks}from"./CzFgFX4I.production.bundle.min.js";import{y as ps,i as Ds,b as Vs}from"./D4liyLd7.production.bundle.min.js";import"./BTOj8ijf.production.bundle.min.js";import"./CJLuAe4t.production.bundle.min.js";import"./Dsqj8S3w.production.bundle.min.js";import"./9zG8c1d8.production.bundle.min.js";import"./D4lvmK5r.production.bundle.min.js";import"./M_FBjfQJ.production.bundle.min.js";import"./CHbz8HD7.production.bundle.min.js";import"./BZwPEnwo.production.bundle.min.js";import"./DohGM9_I.production.bundle.min.js";import"./Czj00ZrM.production.bundle.min.js";import"./vhNSgALD.production.bundle.min.js";import"./C7aKDdDU.production.bundle.min.js";import"./PSw9bd14.production.bundle.min.js";import"./BaeVAzEX.production.bundle.min.js";import"./BAUftK01.production.bundle.min.js";import"./DlG3g9Q4.production.bundle.min.js";import"./BKtnA6hw.production.bundle.min.js";import"./URTTg1rg.production.bundle.min.js";import"./CMxhj3GZ.production.bundle.min.js";import"./CIT-tl5U.production.bundle.min.js";import"./DnFKFUTo.production.bundle.min.js";import"./CrsULzDT.production.bundle.min.js";import"./_LyuCvYL.production.bundle.min.js";import"./DnQqxH0F.production.bundle.min.js";import"./DvJkqRNe.production.bundle.min.js";import"./BEMZOgku.production.bundle.min.js";import"./Cv3GWBJv.production.bundle.min.js";import"./DZSwJOZ8.production.bundle.min.js";import"./ss4v-xya.production.bundle.min.js";import"./D7jmmEF8.production.bundle.min.js";import"./DVYtYn_y.production.bundle.min.js";import"./v06WTCWU.production.bundle.min.js";const Ps=({chats:e,setChats:l,toolHandlerRef:n,editId:o,projectId:g})=>{var V,k,B,P,y;const v=o?"Edit Alerts with OpsAI":"Your Alerts, Generated in Minutes",C=o?"Just describe your edit. OpsAI converts your intent into a fully configured, production-ready alert.":"Just describe your use case. OpsAI converts your intent into a fully configured, production-ready alert.",d=i.useContext(me),s=i.useMemo(()=>Date.now(),[g]),u=(k=(V=d==null?void 0:d.params)==null?void 0:V.query)==null?void 0:k.get("tempId"),h=(P=(B=d==null?void 0:d.params)==null?void 0:B.query)==null?void 0:P.get(ot),b=He(li),x=i.useMemo(()=>
1{if(b)return b;if(h)return ci(h)??void 0},[b,h]),S=i.useRef(!1),[c]=i.useState(()=>di());i.useEffect(()=>{S.current=!1},[s]);const[m,_]=i.useState(()=>ui(o)),[w,E]=i.useState(null);i.useEffect(()=>{m&&E({text:mi,onConsumed:()=>{E(null),_(!1)}})},[m]),i.useEffect(()=>{const j=r=>{E({text:Si(r,!!o),onConsumed:()=>{bt(),E(null)}})},A=gi();A&&j(A.note);const a=r=>{var f;bt(),j((f=r.detail)==null?void 0:f.note)};return window.addEventListener(tt,a),()=>window.removeEventListener(tt,a)},[o]);const F=o?Number(o):void 0;return t.jsx("div",{className:"dashboard-sidepanel-container",children:t.jsx(fi,{dashboardChats:e,dashboardId:`${(y=e[0])==null?void 0:y.id}`,setDashboardChats:l,toolHandlerRef:n,parentId:`alert${o?"":"_temp"}_${g}_${o??u??s}`,state:hi.ALERT_CREATION,noChatDataState:{title:v,description:C},onChatCreate:()=>{var j,A,a,r;!u&&!o&&(S.current=!0,(A=(j=d==null?void 0:d.params)==null?void 0:j.query)==null||A.set("tempId",`${s}`),(r=(a=d==null?void 0:d.params)==null?void 0:a.query)==null||r.redirect())},emptyChatState:{title:v,subTitle:C,placeholder:"Outline your alerting objective ",suggestedText:"Try one of these:",samplePrompts:o?[]:[{title:"",icon:at(0),subTitle:"Create an alert when CPU usage across Kubernetes nodes exceeds 85% for more than 5 minutes."},{title:"",icon:at(1),subTitle:"Create an alert when error logs increase by more than 50% in the last 10 minutes."},{title:"",icon:at(2),subTitle:"Create an alert when node health status changes from healthy to degraded."},{title:"",icon:at(3),subTitle:"Generate an alert when pod restarts increase unusually in the last 10 minutes."}]},currentAlertObject:x,currentAlertRuleId:F,currentAlertHealthCheck:m,bootstrapUserMessage:w,bootstrapCreatesChat:!0,suppressInitialActivitiesFetchRef:S,initialUserInput:c})})},Fs=({isOpen:e,onClose:l,suggestion:n,saveLabel:o,onApply:g,onSaveWithoutApplying:v})=>{const C=xi(n==null?void 0:n.config.config);if(!n)return null;const d=ji(n.config,n.uiDisplay,C);return t.jsx(it,{isOpen:e,type:ft.Update,headerIcon:t.jsx(Et,{size:40}),classname:"opsai-suggested-config-confirmation",title:"OpsAI suggested a tuned config",description:"It hasn't been applied yet - review it before saving.",cancelBtnText:`${o.startsWith("Update")?"Update":"Create"} as it is`,confirmBtnText:"Apply config",handleCancelEvent:v,handleConfirmEvent:g,onClose:l,children:t.jsxs("div",{className:"suggested-config-dialog-v2",children:[t.jsx("div",{className:"suggested-config-dialog-v2__rows",children:d.map(s=>t.jsxs("div",{className:"suggested-config-dialog-v2__row",children:[t.jsx("span",{className:"suggested-config-dialog-v2__key",children:s.label}),t.jsx(vi,{text:s.value,className:"suggested-config-dialog-v2__value",mode:"multi-line"})]},s.label))}),t.jsxs("div",{className:"suggested-config-dialog-v2__note",children:["Applying fills the form - nothing is saved until you click ",o,"."]})]})})},qs=({isOpen:e,isEdit:l=!1,onClose:n,onSaveAsIs:o})=>{const g=`${l?"Update":"Create"} as it is`;return t.jsx(it,{isOpen:e,type:ft.Update,headerIcon:t.jsx(Et,{size:40}),classname:"opsai-suggested-config-confirmation",title:"OpsAI is creating a config",description:"A suggested config is being prepared. You can wait for it, or save with your current settings.",cancelBtnText:g,confirmBtnText:"Wait for OpsAI",handleCancelEvent:o,handleConfirmEvent:n,onClose:n})},Ls=({isOpen:e,onClose:l,onCreateAnyway:n,onReview:o,isEdit:g=!1})=>{const[v,C]=i.useState(""),d=()=>{C(""),l()};return t.jsx(it,{isOpen:e,type:ft.Update,headerIcon:t.jsx(Et,{size:40}),classname:"opsai-review-confirmation",title:"Review This Alert With OpsAI?",description:"OpsAI tests your settings against your recent data and tells you if they're good to go or need tuning.",cancelBtnText:`${g?"Update":"Create"} as it is`,confirmBtnText:"Review with OpsAI",handleCancelEvent:()=>{d(),n()},handleConfirmEvent:()=>{const s=v;d(),o(s)},onClose:d,children:t.jsx(us,{id:"opsai-alert-intent",label:"What should this alert catch?",placeholder:"e.g. Alert only when CPU stays high during peak traffic",value:v,onChange:C,rows:3})})},Us=({onSubmit:e,isValid:l=!1,loading:n=!1,errors:o,opsAIEnabled:g=!0})=>{const{id:v}=ce(),{pathname:C}=si(),d=Ct(),[s,u]=i.useState(!1),[h,b]=i.useState(null);i.useEffect(()=>{n||b(null)},[n]);
1const x=o?Object.values(o)[0]:"",S=!l||n,c=`${v?"Update":"Create"} Alert`,m=`Review & ${v?"Update":"Create"}`,_=()=>{S||(b("direct"),e())},w=()=>{S||(b("review"),e())};return t.jsxs("div",{className:"alert-footer",children:[t.jsx(ze,{secondary:!0,error:!0,onClick:()=>{C.startsWith("/alerts/new-rule")?d("/alerts/new-rule"):d("/alerts/rules")},children:"Cancel"}),t.jsx(pe,{content:x||"",children:t.jsx("div",{children:t.jsx(ze,{primary:!g,secondary:g,onClick:_,disabled:S,loading:n&&h!=="review",children:c})})}),g&&t.jsxs(t.Fragment,{children:[t.jsx(pe,{content:x||"",children:t.jsx("div",{children:t.jsx(ze,{primary:!0,onClick:()=>{S||u(!0)},disabled:S,loading:n&&h==="review",children:m})})}),t.jsx(Ls,{isOpen:s,isEdit:!!v,onClose:()=>u(!1),onCreateAnyway:w,onReview:E=>{bi(E),window.dispatchEvent(new CustomEvent(tt,{detail:{note:E}}))}})]})]})},ve=({completedStep:e,stepItems:l})=>t.jsx("div",{className:"alert-steps-progress-wrapper",children:t.jsx(bs,{stepItems:l,completedStep:e})}),Xt=.3;function Ee(){const e=i.useRef(null),[l,n]=i.useState(),o={height:l!==void 0?`${l}px`:`${Xt*100}%`};return{containerRef:e,graphSectionStyle:o,resizerProps:{containerRef:e,initialRatio:Xt,onChange:n,min:120,max:700}}}const Bs=({rule:e,updateRule:l})=>{const{type:n,active_step:o,id:g}=ce();e.conditions.map(c=>{c.status===200&&(c.threshold===0?c.threshold=100:c.threshold)});const[v,C]=i.useState(""),[d,s]=i.useState(Ge((e==null?void 0:e.time_window)||86400)),[u,h]=i.useState(e.conditions.reduce((c,m,_)=>({...c,[_]:m.threshold.toString()}),{})),{debouncedValidation:b}=It({setValidationError:C}),x=(c,m)=>{m!==""&&!/^\d+$/.test(m)||Number(m)<0||Number(m)>100||h(_=>({..._,[c]:m}))},S=(c,m)=>{const _=m===""?0:Number(m),w=[...e.conditions];w[c]={...w[c],threshold:_,operator:">="};const E=w[0].operator;b(w,E),l({...e,conditions:w})};return t.jsxs("div",{className:"threshold-container",children:[t.jsx("div",{className:"threshold-title",children:"Trigger when the percentage of evaluated values have been above the anomaly bounds"}),t.jsx("div",{className:"threshold-settings",children:e.conditions.map((c,m)=>{const _=`(over ${u==null?void 0:u[m]}% of the values in the last ${d} are outside the bounds)`;return t.jsxs("div",{className:`alert-row ${c.status===200?"alert-threshold-section":"warning-threshold-section"}`,children:[t.jsxs("div",{className:"threshold-label",children:[c.status===200?"Alert":"Warning"," ","Anomaly Bound: "]}),t.jsx("div",{className:"threshold-inputs",children:t.jsx(wt,{unit:t.jsxs(t.Fragment,{children:[t.jsx(pe,{content:_,children:t.jsx("div",{className:"threshold-value-tooltip",children:t.jsx(Rt,{size:15,color:"var(--color-primary)"})})}),t.jsx(pe,{content:`${u==null?void 0:u[m]}%`,children:t.jsx("div",{className:"threshold-value",children:`${u==null?void 0:u[m]}%`})})]}),children:t.jsx(Fe,{id:`warning-threshold-${m}`,type:"text",value:u[m],placeholder:"Enter Value: 0% - 100%",onChange:w=>x(m,w),onBlur:()=>S(m,u[m])})})})]},m)})}),v&&t.jsx("div",{className:"rule-error-message",children:v}),t.jsxs("div",{className:"threshold-condition-section",children:[t.jsx("div",{className:"threshold-label",children:"Evaluate the bounds for the last "}),t.jsx("div",{className:"condition-dropdown",children:t.jsx(he,{notFoundContent:"No options found",options:mt,showSearch:!1,defaultValue:Ge((e==null?void 0:e.time_window)||300),onChange:c=>{const m=Array.isArray(c)?c[0]:c;l({...e,time_window:st(m)}),s(m)}},"check-every")})]})]})},$s=[{label:"Unrestricted",value:0},{label:"Restricted",value:1}],be=({rule:e,updateRule:l})=>{var j,A,a;const n=i.useContext(ht),o=n==null?void 0:n.user,g=He(_i),[v,C]=i.useState(((j=e.permission)==null?void 0:j.permission_type)===lt.RESTRICTED?1:0),[d,s]=i.useState(""),[u,h]=i.useState([]),[b,x]=i.useState(((A=e.permission)==null?void 0:A.users)||[]),[S,c]=i.useState([]),[m,_]=i.useState("asc");i.useEffect(()=>{var r,f;(((r=e.permission)==null?void 0:r.users)??[]).length>0&&b.length===0&&(x(((f=e.permission)==null?void 0:f.users)??[]),C(0))},[(a=e.permission)==null?void 0:a.users,b.length]);const w=i.useMemo(()=>{var r;return(r=Object.keys(g))==null?void 0:r.filter(f=>{var N,p,L,M,W;return g[f].Status==="active"&&((W=(M=(L=(p=(N=g[f])==null?void 0:N.Role)==null?void 0:p.Scopes)==null?void 0:L.RawMessage)==null?void 0:M.alert)==null?void 0:W.includes("edit_rules"))&&g[f].Id!==(o==null?void 0:o.user_id
1)}).map(f=>({value:g[f].Email,label:g[f].Name}))},[g,o]),E=i.useCallback((r,f)=>{h(N=>f?[...N,r]:N.filter(p=>p!==r)),s("")},[]),F=i.useCallback(r=>{c(r?b:[])},[b]),V=i.useCallback(()=>{x(r=>r.filter(f=>!S.includes(f))),c([])},[S]),k=i.useCallback((r,f)=>{c(N=>f?[...N,r]:N.filter(p=>p!==r))},[]);i.useEffect(()=>{var f,N;const r={permission_type:v===0?lt.UNRESTRICTED:lt.RESTRICTED,users:v===0?[]:b};(((f=e.permission)==null?void 0:f.permission_type)!==r.permission_type||JSON.stringify((N=e.permission)==null?void 0:N.users)!==JSON.stringify(r.users))&&l({...e,permission:r})},[v,b,e,l]);const B=i.useMemo(()=>w.filter(r=>r.label.toLowerCase().includes(d.toLowerCase())&&!b.includes(r.value)),[w,d,b]),P=i.useCallback(()=>B.length===0?t.jsx("div",{className:"team-users-list",children:"No user found!"}):t.jsx("div",{className:"team-user-list-container",children:B.map(r=>{const f=u.includes(r.value);return t.jsxs("div",{className:`team-users-list ${f?"selected-option":""}`,children:[t.jsxs("div",{className:"user-details-container",onClick:()=>E(r.value,!f),children:[t.jsx(Zt,{seed:r.label,size:20}),t.jsx("div",{className:"name",children:r.label})]}),f&&t.jsx(Ts,{size:12,color:"var(--color-primary)"})]},r.value)})}),[B,u,E]),y=i.useMemo(()=>w.filter(r=>u.includes(r.value)),[w,u]);return t.jsxs("div",{className:"permission-container",children:[t.jsxs("div",{className:"permissions-left-section",children:[t.jsxs("div",{className:"permission-header",children:[t.jsx(At,{tabs:$s,selectedTab:v,onTabChange:({value:r})=>{var f;r===0?(x([]),c([])):r===1&&x(((f=e.permission)==null?void 0:f.users)??[]),C(r)}}),v===0&&t.jsxs("div",{className:"permission-type full-access",children:[t.jsx("div",{className:"permission-icon",children:t.jsx(Cs,{size:16})}),t.jsx("span",{children:"Everyone in my org has full access"})]})]}),v===1&&t.jsxs("div",{className:"user-selection-container",children:[t.jsxs("div",{className:"user-permission-selector",children:[t.jsx("div",{className:"user-selector",children:t.jsx(Ci,{placeholder:"Search to add user",onChange:r=>h(r),selectedValues:u,dropdownRender:P,labelRender:y.map(r=>t.jsx(_s.Option,{value:r.value,children:t.jsx("span",{className:"selected-tags",children:`${r.label}`})},r.value)),onSearch:s,className:"team-members",popupClassName:"team-members-list",allowClear:!1})}),t.jsx("div",{children:t.jsx(ze,{primary:!0,onClick:()=>{x(r=>[...r,...u]),h([]),s("")},children:"Add User"})})]}),t.jsxs("div",{className:"permission-description",children:[t.jsx(ys,{size:16,color:"var(--color-secondary)"}),"Only the above selected users will have access to edit this alert rule."]})]})]}),v===1&&t.jsxs("div",{className:"permissions-right-section",children:[t.jsxs("div",{className:"manage-access-header",children:[t.jsxs("div",{className:"users-header",children:[t.jsx("span",{className:"section-title",children:"USERS WITH EDIT ACCESS"}),t.jsx("span",{className:"divider"}),t.jsx("span",{className:"select-all",onClick:()=>F(!0),children:"Select All"})]}),t.jsx("div",{className:"remove-user",children:t.jsx(ze,{error:!0,disabled:!S.length,onClick:V,children:"Remove Selected"})})]}),t.jsxs("div",{className:"selected-users-list-container",children:[t.jsxs("div",{className:"list-header",children:[t.jsx(Qt,{id:"select-all",checked:S.length>0&&S.length===b.length,showMinusIcon:S.length>0&&S.length<b.length,label:t.jsx("div",{className:"header-label-container",children:t.jsx("span",{className:"title",children:"User Name"})}),onChange:r=>F(r),disabled:!1}),t.jsx("div",{onClick:()=>{_(r=>r==="asc"?"desc":"asc")},className:"sort-icon",children:t.jsx(ws,{className:`${m==="asc"?"ascend-arrow":""}`})})]}),b.length>0?t.jsx("div",{className:"users-list-container",children:b.map(r=>w.find(f=>f.value===r)).sort((r,f)=>{if(!r||!f)return 0;const N=r.label.localeCompare(f.label);return m==="asc"?N:-N}).map(r=>r?t.jsx("div",{className:"user-container",children:t.jsx(Qt,{id:`email-${r.value}`,checked:S.includes(r.value),label:t.jsxs("div",{className:"user-label",children:[t.jsx(Zt,{seed:r.label,size:20}),t.jsx("span",{children:r.label})]}),onChange:f=>k(r.value,f)})},r==null?void 0:r.value):null)}):t.jsxs("div",{className:"no-data-container",children:[t.jsx(Ns,{}),t.jsxs("div",{className:"no-data-content",children:["Oops! No data found.",t.jsx("br",{})," Add users to allow their access"]})]})]})]})]})},Ws=e=>{const l=$.anomaly,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.anomaly,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),[b,x]=i.useState(h&&h.length>0&&h[0].source.name?h[0].source.name:""),S=i.useMemo(()=>Me(s),[s]),c=i.useMemo(()=>De(s,S,!0),[S,s]),m=i.useCallback(()=>{x(e.defaultSource||""),u(Z(e.defaultSource))},[e.defaultSource]);i.useEffect(()=>{d||m()},[m]),i.useEffect(()=>{const a={name:e.formState.name||"",type:e.formState.type||re.anomaly,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(a)},[s]),i.useEffect(()=>m,[]);const[_,w]=i.useState(),[E,F]=i.useState(),V=i.useMemo(()=>ke(e.formState.conditions,E),[e.formState.conditions,E]),k=()=>S.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:a=>{var r,f,N,p,L,M;F((p=(N=(f=(r=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:r.series)==null?void 0:f[0])==null?void 0:N.custom)==null?void 0:p.config),w((M=(L=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:L.series)==null?void 0:M.length)},yAxisConfigOptions:{tickAmount:8,...V}}},widget:c,dateRange:C.params.dateRange,showOnlyGraph:!0}
1):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b===""?"No metrics available!":S.msg})}),B=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:b,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0}),P=i.useCallback(a=>{x(a),u(r=>a===Nt?r:qe(a,r))},[]),{containerRef:y,graphSectionStyle:j,resizerProps:A}=Ee();return t.jsxs("div",{className:"rule-container",ref:y,children:[t.jsx("div",{className:"graph-section",style:j,children:k()}),t.jsx(Ae,{...A}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{isCategoryDataSource:!0,source:b,onSourceChange:P})}),B()]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(Bs,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:_,rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})};function Ye(e){var b,x,S;const{alertType:l,appliedTemplate:n,onTemplateSelect:o}=e,g=i.useMemo(()=>{const c=vs[l],m={};return c==null||c.forEach(_=>{m[_.name]=_}),m},[l]),v=i.useMemo(()=>Object.values(g).map(c=>{var m,_,w;return{label:c.name,value:c.name,prefixIcon:St(((w=(_=(m=c.config)==null?void 0:m[0])==null?void 0:_.source)==null?void 0:w.name)||"")}}),[g]),C=i.useMemo(()=>["metric","custom"].includes(l)?[le.cloneDeep(ct["High CPU Usage"]),le.cloneDeep(ct["High Memory Usage"]),le.cloneDeep(ct["Pod is in an OOMKilled state"])]:[...le.cloneDeep(v)].map(c=>g[c.value]).slice(0,3),[v,l]),[d,s]=i.useState(le.cloneDeep(v)),u=i.useMemo(()=>le.debounce(c=>{if(!c||c.trim()===""){s(v);return}s(v.filter(m=>m.label.toLowerCase().includes(c.toLowerCase())))},500),[v]),h=i.useCallback(()=>{s(v)},[v]);return v!=null&&v.length?n?t.jsxs("div",{className:"applied-template-bar",children:[t.jsxs("div",{className:"left-section",children:[t.jsx("div",{className:"icon-wrapper",children:St(((S=(x=(b=n.config)==null?void 0:b[0])==null?void 0:x.source)==null?void 0:S.name)||"")}),t.jsxs("div",{className:"title",children:[t.jsx("h6",{children:n.name}),t.jsx("label",{className:"template-applied",children:"Template Applied"})]})]}),t.jsx(ze,{prefixicon:t.jsx(Rs,{color:"var(--color-text)"}),onClick:()=>o==null?void 0:o(void 0),outlined:!0,children:"Browse All Templates"})]}):t.jsxs("div",{className:"browse-template-bar",children:[t.jsxs("div",{className:"left-section",children:[t.jsxs("div",{className:"content",children:[t.jsx("h6",{children:"Start with alert template"}),t.jsx("label",{children:"Includes search queries, alert conditions, and notifications"})]}),t.jsx("div",{className:"search-wrapper",children:t.jsx(he,{options:d,placeholder:"Search by name",mode:Tt.Default,showSearch:!0,prefix:t.jsx(Is,{}),onChange:c=>{o==null||o(g[c]),h()},showSuffixIcon:!1,onSearch:u,onClear:h,disableInternalFiltering:!0})})]}),t.jsx("div",{className:"divider"}),t.jsx("div",{className:"right-section",children:C.map(c=>{var m,_,w;return t.jsxs("div",{className:"template-tile",onClick:()=>{o==null||o(c)},children:[t.jsxs("div",{className:"left-part",children:[t.jsx("div",{className:"icon-wrapper",children:St(((w=(_=(m=c.config)==null?void 0:m[0])==null?void 0:_.source)==null?void 0:w.name)||"")}),t.jsx("div",{children:c.name})]}),t.jsx(Ms,{})]},c.name)})})]}):null}const zs=e=>{const l=$.trace,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.trace,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),b=i.useMemo(()=>h&&h.length>0&&h[0].source.name?h[0].source.name:"",[h]),x=i.useMemo(()=>Me(s),[s]),S=i.useMemo(()=>De(s,x,!0),[x,s]),[c,m]=i.useState(),[_,w]=i.useState(),[E,F]=i.useState([]),V=i.useMemo(()=>ke(e.formState.conditions,c),[e.formState.conditions,c]);i.useEffect(()=>{d||u(Z(e.defaultSource))},[e.defaultSource]),i.useEffect(()=>{const a={name:e.formState.name||"",type:e.formState.type||re.metric,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(a)},[s]),i.useEffect(()=>()=>{u(Z(e.defaultSource))},[]),i.useEffect(()=>{var a;if(e.template){const r=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:(a=e.template)==null?void 0:a.config});u(f=>({...f,builderConfig:r==null?void 0:r.builderConfig,formulas:r==null?void 0:r.formulas,dontRefreshData:!1}))}},[e.template]);const k=()=>x.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:a=>{var r,f,N,p,L,M,W,G,Y,O;m((p=(N=(f=(r=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:r.series)==null?void 0:f[0])==null?void 0:N.custom)==null?void 0:p.config),w((M=(L=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:L.series)==null?void 0:M.length),F(Be((W=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:W.series,e.formState.evaluate,e.formState.time_window,((Y=(G=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:G.t
1imeRange)==null?void 0:Y.interval)||((O=a==null?void 0:a.time_range)==null?void 0:O.interval)))},timeseriesChartOptions:{extraSeries:E},yAxisConfigOptions:{tickAmount:8,...V}}},widget:S,dateRange:C.params.dateRange,showOnlyGraph:!0}):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b===""?"No metrics available!":x.msg})}),B=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:b,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0,isApmAlert:!0}),P=i.useCallback(a=>{u(r=>qe(a,r))},[]),{containerRef:y,graphSectionStyle:j,resizerProps:A}=Ee();return t.jsxs("div",{className:"rule-container",ref:y,children:[t.jsx("div",{className:"graph-section",style:j,children:k()}),t.jsx(Ae,{...A}),t.jsx(Ye,{alertType:"apm",appliedTemplate:e.template,onTemplateSelect:e.onTemplateSelect}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{isCategoryDataSource:!0,source:b,onSourceChange:P})}),B()]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,config:c,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:_,rule:e.formState,updateRule:e.upsertState,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},Gs=({rule:e,updateRule:l})=>{var b,x,S,c;const n=(S=(x=(b=e.config)==null?void 0:b[0])==null?void 0:x.meta_data)==null?void 0:S.billingUnit,[o,g]=i.useState(""),[v,C]=i.useState(e.conditions.reduce((m,_,w)=>({...m,[w]:String(_.threshold)}),{})),{debouncedValidation:d}=It({setValidationError:g}),s=(m,_)=>{_!==""&&!/^\d*\.?\d*$/.test(_)||C(w=>({...w,[m]:_}))},u=(m,_)=>{const w=_===""?0:Number(_),E=[...e.conditions];E[m]={...E[m],threshold:w};const F=E[0].operator;d(E,F),l({...e,conditions:E})},h=(c=e.eval)!=null&&c.trim()?e.eval:Ge(e==null?void 0:e.time_window);return t.jsxs("div",{className:"threshold-container",children:[t.jsx("div",{className:"threshold-title",children:"Set threshold conditions when the alerts will be triggered"}),t.jsx("div",{className:"common-operator-section",children:t.jsx("div",{className:"threshold-label",children:"Trigger when the evaluated values are above the threshold"})}),t.jsx("div",{className:"threshold-settings",children:e.conditions.map((m,_)=>{const w=Number(v[_]),E=yi(w,n);return t.jsxs("div",{className:`alert-row ${m.status===200?"alert-threshold-section":"warning-threshold-section"}`,children:[t.jsxs("div",{className:"threshold-label",children:[m.status===200?"Critical":"Warning"," ","threshold: "]}),t.jsx("div",{className:"threshold-inputs",children:t.jsx(wt,{unit:t.jsxs(t.Fragment,{children:[t.jsx(pe,{content:"Threshold value with unit",children:t.jsx("div",{className:"threshold-value-tooltip",children:t.jsx(Rt,{size:15,color:"var(--color-primary)"})})}),t.jsx(pe,{content:E,children:t.jsx("div",{className:"threshold-value",children:E})})]}),children:t.jsx(Fe,{id:`warning-threshold-${_}`,type:"text",placeholder:n?wi(n):"Enter value",value:v[_],onChange:F=>s(_,F),onBlur:()=>u(_,v[_])})})})]},_)})}),o&&t.jsx("div",{className:"rule-error-message",children:o}),t.jsxs("div",{className:"threshold-condition-section",children:[t.jsx("div",{className:"threshold-label",children:"Evaluate billing usage over the past "}),t.jsx("div",{className:"condition-dropdown",children:t.jsx(he,{notFoundContent:"No options foun
1d",options:Ni,showSearch:!1,defaultValue:h,onChange:m=>{const _=Array.isArray(m)?m[0]:m;l(_===Lt?{...e,eval:Lt}:{...e,time_window:st(_),eval:""})}},"check-every")})]})]})},ei={size:"Size (GB)",checks:"Checks (Count)",sessions:"Sessions (Count)",browser_test:"Browser Tests (Count)",tokens:"Tokens (Count)"},dt=[ee.MetricSize,ee.TraceSize,ee.LogSize,ee.synthetics,ee.Rum,ee.browserTest,ee.OpsAI],Hs=[{label:"Metrics (by Size or Cost)",value:ee.MetricSize},{label:"Traces (by Size or Cost)",value:ee.TraceSize},{label:"Logs (by Size or Cost)",value:ee.LogSize},{label:"RUM (by Sessions or Cost)",value:ee.Rum},{label:"Synthetic Monitoring (by Checks or Cost)",value:ee.synthetics},{label:"Browser Tests (by Tests or Cost)",value:ee.browserTest},{label:"Ops AI Tokens (by Tokens or Cost)",value:ee.OpsAI}],ti={[ee.LogSize]:["size"],[ee.MetricSize]:["size"],[ee.TraceSize]:["size"],[ee.synthetics]:["checks"],[ee.Rum]:["sessions"],[ee.browserTest]:["browser_test"],[ee.OpsAI]:["tokens"]},ut={...JSON.parse(JSON.stringify(Ce)),builderConfig:[{...jt,columns:dt,source:{...jt.source,name:"billing"},meta_data:{billingUnit:"cost"}}],label:""},Ys=e=>{var k,B,P,y,j,A,a,r;const l=$.billing,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.billing,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=rt(),d=i.useContext(me),s=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[u,h]=i.useState(()=>{var f,N;return s?{...ut,builderConfig:(N=(f=e.formState)==null?void 0:f.config)==null?void 0:N[0]}:JSON.parse(JSON.stringify(ut))});i.useEffect(()=>{const f={name:e.formState.name||"",type:e.formState.type||re.metric,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(u.builderConfig)?u.builderConfig:u.builderConfig?[u.builderConfig]:[],formulas:u.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(f)},[u]),i.useEffect(()=>()=>{h(JSON.parse(JSON.stringify(ut)))},[]);const[b,x]=i.useState(!1),{containerRef:S,graphSectionStyle:c,resizerProps:m}=Ee();i.useEffect(()=>{const f={sts:d.params.dateRange.fromTs,ets:d.params.dateRange.toTs,filterby:cs.account};x(!0),C(Ai(f,()=>{x(!1)}))},[]);const[_,w]=i.useState([...((B=(k=e.formState.config)==null?void 0:k[0])==null?void 0:B.columns)||dt]),[E,F]=i.useState([{label:"Cost (USD)",value:"cost"}]);i.useEffect(()=>{var W,G,Y,O,K,te,ge,ue,oe;const f=((G=(W=e.formState.config)==null?void 0:W[0])==null?void 0:G.columns)||[];let N=[];if(f.length>0){N=ti[f[0]]||[];for(let ie=1;ie<f.length;ie++){const ye=ti[f[ie]]||[];N=N.filter(Je=>ye.includes(Je))}}const p=[{label:"Cost (USD)",value:"cost"}];N.forEach(ie=>{ei[ie]&&p.push({label:ei[ie],value:ie})}),F(p);const L=(K=(O=(Y=e.formState.config)==null?void 0:Y[0])==null?void 0:O.meta_data)==null?void 0:K.billingUnit,M=p.some(ie=>ie.value===L);(!L||!M)&&((ue=(ge=(te=e.formState.config)==null?void 0:te[0])==null?void 0:ge.meta_data)==null?void 0:ue.billingUnit)!=="cost"&&e.upsertState({...e.formState,config:e.formState.config?[{...e.formState.config[0],meta_data:{...(oe=e.formState.config[0])==null?void 0:oe.meta_data,billingUnit:"cost"}}]:[]})},[(j=(y=(P=e.formState.config)==null?void 0:P[0])==null?void 0:y.meta_data)==null?void 0:j.billingUnit,e.upsertState]);const V=f=>{const N=Array.isArray(f)?f:[f];if(N.length===0){e.upsertState({...e.formState,config:[{columns:[...dt],source:{name:"billing",alias:"",dataset_id:0}}]}),w([...dt]);return}e.upsertState({...e.formState,config:[{columns:N,source:{name:"billing",alias:"",dataset_id:0}}]}),w(N)};
1return t.jsxs("div",{className:"rule-container",ref:S,children:[t.jsxs("div",{className:"billing-graph-section",style:c,children:[b&&t.jsx(yt,{}),!b&&t.jsx(ks,{selectedDateRange:{fromTs:d.params.dateRange.fromTs,toTs:d.params.dateRange.toTs},oldPlan:!1,filterKeys:_})]}),t.jsx(Ae,{...m}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsxs("div",{className:"step-component billing-steps",children:[t.jsxs("div",{className:"time-window-area",style:{verticalAlign:"middle",width:"910px"},children:[t.jsx("label",{children:"Select product"}),t.jsx(he,{mode:Tt.AddOptions,showSearch:!1,placeholder:"Select service(s)",defaultValue:_,isError:e.checkValid("define__frequency"),onChange:V,notFoundContent:"No options found",options:Hs},"select-product")]}),t.jsxs("div",{className:"time-window-area billing-unit",style:{verticalAlign:"middle",width:"200px"},children:[t.jsx("label",{children:"Select unit"}),t.jsx(he,{placeholder:"Select unit",defaultValue:((r=(a=(A=e.formState.config)==null?void 0:A[0])==null?void 0:a.meta_data)==null?void 0:r.billingUnit)??"cost",isError:e.checkValid("define__frequency"),disabled:E.length===1,onChange:f=>{var p;const N=Array.isArray(f)?f[0]:f;e.upsertState({...e.formState,config:e.formState.config?[{...e.formState.config[0],source:{name:"billing",alias:"",dataset_id:0},meta_data:{...(p=e.formState.config[0])==null?void 0:p.meta_data,billingUnit:N}}]:[],valid:{...e.formState.valid,define__frequency:N.trim().length<1}})},options:E},E.map(f=>f.value).join("-"))]})]})})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(Gs,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},Js=e=>{const l=$.trace,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.trace,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),b=i.useMemo(()=>Me(s),[s]),x=i.useMemo(()=>De(s,b,!0),[b,s]),[S,c]=i.useState(),[m,_]=i.useState(),[w,E]=i.useState([]),F=i.useMemo(()=>ke(e.formState.conditions,S),[e.formState.conditions,S]);i.useEffect(()=>{d||u(Z(e.defaultSource))},[e.defaultSource]),i.useEffect(()=>{const j={name:e.formState.name||"",type:e.formState.type||re.metric,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(j)},[s]),i.useEffect(()=>()=>{u(Z(e.defaultSource))},[]),i.useEffect(()=>{var j;if(e.template){const A=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:(j=e.template)==null?void 0:j.config});u(a=>({...a,builderConfig:A==null?void 0:A.builderConfig,formulas:A==null?void 0:A.formulas,dontRefreshData:!1}))}},[e.template]);const{containerRef:V,graphSectionStyle:k,resizerProps:B}=Ee(),P=()=>b.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:j=>{var A,a,r,f,N,p,L,M,W,G;c((f=(r=(a=(A=j==null?void 0:j.timeseriesChartDataV2)==null?void 0:A.series)==null?void 0:a[0])==null?void 0:r.custom)==null?void 0:f.config),_((p=(N=j==null?void 0:j.timeseriesChartDataV2)==null?void 0:N.series)==null?void 0:p.length),E(Be((L=j==null?void 0:j.timeseriesChartDataV2)==null?void 0:L.series,e.formState.evaluate,e.formState.time_window,((W=(M=j==null?void 0:j.timeseriesChartDataV2)==null?void 0:M.timeRange)==null?void 0:W.interval)||((G=j==null?void 0:j.time_range)==null?void 0:G.interval)))},timeseriesChartOptions:{extraSeries:w},yAxisConfigOptions:{tickAmount:8,...F}}},widget:x,dateRange:C.params.dateRange,showOnlyGraph:!0}
1):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b.msg})}),y=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0,isCustomAlert:!0});return t.jsxs("div",{className:"rule-container",ref:V,children:[t.jsx("div",{className:"graph-section",style:k,children:P()}),t.jsx(Ae,{...B}),t.jsx(Ye,{alertType:"custom",appliedTemplate:e.template,onTemplateSelect:e.onTemplateSelect}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:y()})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,config:S,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:m,rule:e.formState,updateRule:e.upsertState,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},Ks=e=>{var ie,ye,Je,de;const l=$.error_tracking,[n,o]=i.useState(()=>{var D,H;return((H=(D=e==null?void 0:e.formState)==null?void 0:D.meta)==null?void 0:H.issue_type)??1}),g=et.useContext(ht),v=(ye=(ie=g==null?void 0:g.user)==null?void 0:ie.account)==null?void 0:ye.project_uid,C="p2i13hg",[d,s]=i.useState(n===2?1:3),u={TRACE:"trace",TRACE_SERVICE:"trace.service",RUM:"rum"},[h,b]=i.useState(()=>n===2?u.RUM:n===3?u.TRACE_SERVICE:u.TRACE),[x,S]=i.useState(),[c,m]=i.useState(),[_,w]=i.useState([]),[E,F]=i.useState(0),{type:V,active_step:k,id:B}=ce(),P={name:"trace",alias:"",dataset_id:0},y=["avg(total_requests,value(avg))"],{containerRef:j,graphSectionStyle:A,resizerProps:a}=Ee(),r=v===C?[...mt,"1 month"]:mt,f=["avg","max","min","sum"],N=i.useMemo(()=>V?$[V]:$.error_tracking,[V]),p=i.useMemo(()=>k?parseInt(k.split("-")[1],10):1,[k]),L=i.useContext(me),[M,W]=i.useState(()=>e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource));i.useEffect(()=>{if(e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name){const H={with:e.formState.config[0].with,columns:y,source:P};K(H),e.upsertState({...e.formState,config:[H]})}},[B]);const G=()=>{o(x.oldTab),S(void 0),F(D=>D+1)},Y=D=>{switch(D){case 1:return{with:[{key:"GLOBAL_ATTRIBUTE_FILTER",value:{or:[{statusCode:{"=":"2"}},{"http.response.status_code":{"=":"404"}}]},is_arg:!0}],columns:y,source:P};case 2:return{with:[{key:"GLOBAL_ATTRIBUTE_FILTER",value:{and:[{statusCode:{"=":"2"}},{"mw.resource.type":{"=":"rum"}}]},is_arg:!0}],columns:y,source:P};case 3:return{with:[{key:"GLOBAL_ATTRIBUTE_FILTER",value:{or:[{statusCode:{"=":"2"}},{"http.response.status_code":{"=":"404"}}],and:[{"mw.resource.type":{"!=":"rum"}},{"mw.resource.type":{"!=":"llm"}}]},is_arg:!0}],columns:y,source:P};default:return{with:[],columns:[],source:P}}},[O,K]=i.useState(()=>e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name?e.formState.config[0]:Y(n));i.useEffect(()=>{const D={name:e.formState.name||"",type:e.formState.type||re.metric,resource:e.formState.resource||"trace",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:[O],formulas:M.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:{...(e.formState.meta||{})??{},issue_type:n}};e.upsertState(D)},[M]);const te=D=>{const H=le.cloneDeep(O);let X=H.with||[];if(!D)X=X.filter(ne=>ne.key!==We);else{const ne=vt.ConvertToValueType(D);if(!ne)return;const Se=X.findIndex(Te=>Te.key===We);Se===-1?X.push({key:We,value:ne,is_arg:!0}):X[Se].value=le.cloneDeep(ne)}H.with=X,K(H),e.upsertState({...e.formState,config:[H]})},ge=i.useMemo(()=>{var H,X;if(e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name){const Se=(H=e.formState.config[0].with)==null?void 0:H.find(Te=>Te.key===We);return(Se==null?void 0:Se.value)||{}}const D=(X=O.with)==null?void 0:X.find(ne=>ne.key===We);return(D==null?void 0:D.value)||{}},[O.with,e.formState.config]),ue={label:"",builderId:1,scopeId:0,widgetAppId:gs,builderConfig:O,builderViewOptions:{}},oe=i.useMemo(()=>ke(e.formState.conditions,As),[e.formState.conditions]);return t.jsxs("div",{className:"rule-container",ref:j,children:[t.jsx("div",{className:"graph-section",style:A,children:t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:D=>{var H,X,ne,Se,Te,Ke;m((X=(H=D==null?void 0:D.timeseriesChartDataV2)==null?void 0:H.series)==null?void 0:X.length),w(Be((ne=D==null?void 0:D.timeseriesChartDataV2)==null?void 0:ne.series,e.formState.evaluate,e.formState.time_window,((Te=(Se=D==null?void 0:D.timeseriesChartDataV2)==null?void 0:Se.timeRange)==null?void 0:Te.interval)||((Ke=D==null?void 0:D.time_range)==null?void 0:Ke.interval)))},timeseriesChartOptions:{extraSeries:_},yAxisConfigOptions:{tickAmount:8,...oe}}},widget:ue,dateRange:L.params.dateRange,showOnlyGraph:!0})}),t.jsx(Ae,{...a}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:N,completedStep:p-1}
1)}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsxs("div",{className:"error-tracking-sources",children:[t.jsx("div",{className:"error-tracking-label",children:t.jsx("span",{children:"Source"})}),t.jsx(At,{tabs:[{label:"All",value:1},{label:"Frontend Issue",value:2},{label:"Backend Issue",value:3}],selectedTab:n,onTabChange:D=>{const H=D.value;let X=d,ne=h;switch(D.value){case 1:X=3,ne=u.TRACE;break;case 2:X=1,ne=u.RUM;break;case 3:X=3,ne=u.TRACE_SERVICE;break}S({...x,nextTab:H,oldTab:n,kpiType:X,resource:ne})}},E)]}),t.jsx("div",{className:"error-tracking-label",children:t.jsx("span",{children:"Alert"})}),t.jsxs("div",{className:"alert-config-row height",children:[t.jsx("label",{className:"label",children:"Query on"}),t.jsx("div",{className:"box-dropdown query-box",children:t.jsx(Ei,{kpiType:d,widgetType:"timeseries",filter:ge,resource:h,onChange:te})},String(n))]}),t.jsxs("div",{className:"alert-config-row",children:[t.jsx("label",{className:"label",children:"Alerts on the"}),t.jsx("div",{className:"box-dropdown",children:t.jsx(he,{notFoundContent:"No options found",options:f,showSearch:!1,defaultValue:Ti((Je=e==null?void 0:e.formState)==null?void 0:Je.evaluate),onChange:D=>{const H=Array.isArray(D)?D[0]:D;e.upsertState({...e.formState,evaluate:H})}},"evaluate-method")}),t.jsx("label",{className:"label",children:"value of"}),t.jsx("div",{className:"box-dropdown",children:t.jsx(he,{notFoundContent:"No options found",options:["Error occurrence(*)"],selectedValues:"Error occurrence(*)",onChange:D=>{}})}),t.jsx("label",{className:"label",children:"over the last"}),t.jsx("div",{className:"box-dropdown",children:t.jsx(he,{notFoundContent:"No options found",options:r,showSearch:!1,defaultValue:Ge(((de=e==null?void 0:e.formState)==null?void 0:de.time_window)||300),onChange:D=>{const H=Array.isArray(D)?D[0]:D;e.upsertState({...e.formState,time_window:st(H)})}},"check-every")})]})]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,check_every_show:!1})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:c,rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]}),x&&t.jsx(it,{isOpen:!0,onClose:G,handleCancelEvent:G,handleConfirmEvent:()=>{S(void 0),te(void 0),o(x.nextTab),s(x.kpiType),b(x.resource);const D=Y(x.nextTab);K(D),e.upsertState({...e.formState,config:[D],meta:{...(e.formState.meta||{})??{},issue_type:x.nextTab}})},title:"Change Source Type",description:t.jsx("span",{children:"Changing the source type will cause the filter to be reset."}),headerIcon:t.jsx(Ri,{})})]})},Qs=({rule:e,updateRule:l,config:n})=>{const{type:o,active_step:g,id:v}=ce(),[C,d]=i.useState(""),[s,u]=i.useState(e.conditions.reduce((S,c,m)=>({...S,[m]:String(c.threshold)}),{})),{debouncedValidation:h}=It({setValidationError:d}),b=(S,c)=>{c!==""&&!/^(\d*\.?\d*)([eE][+-]?\d*)?$/.test(c)||u(m=>({...m,[S]:c}))},x=(S,c)=>{let m=0;if(c!==""&&c!=="."&&!c.endsWith(".")&&!c.match(/[eE]$/)){const E=parseFloat(c);!isNaN(E)&&E>=0&&(m=E)}const _=[...e.conditions];_[S]={..._[S],threshold:m};const w=_[0].operator;h(_,w),l({...e,conditions:_})};return t.jsxs("div",{className:"threshold-container",children:[t.jsx("h3",{className:"threshold-title",children:"Trigger an alert when the edge of the forecast confidence bounds goes above the threshold."}),t.jsx("div",{className:"threshold-settings",children:e.conditions.map((S,c)=>{const m=n&&(s!=null&&s[c])?Es(parseFloat(s[c]),n):(s==null?void 0:s[c])||"0";return t.jsxs("div",{className:`alert-row ${S.status===200?"alert-threshold-section":"warning-threshold-section"}`,children:[t.jsxs("div",{className:"threshold-label",children:[S.status===200?"Critical":"Warning"," ","threshold: "]}),t.jsx("div",{className:"threshold-inputs",children:t.jsx(wt,{unit:t.jsxs(t.Fragment,{children:[t.jsx(pe,{content:"Threshold value with unit",children:t.jsx("div",{className:"threshold-value-tooltip",children:t.jsx(Rt,{size:15,color:"var(--color-primary)"})})}),t.jsx(pe,{content:m,children:t.jsx("div",{className:"threshold-value",children:m})})]}),children:t.jsx(Fe,{id:`warning-threshold-${c}`,type:"text",placeholder:"Enter Value: 100, 100.5, 100e2, 100e-2",value:s[c],onChange:_=>{b(c,_),x(c,_)}})})})]},c)})}),C&&t.jsx("div",{className:"rule-error-message",children:C}),t.jsxs("div",{className:"threshold-condition-section",children:[t.jsx("div",{className:"threshold-label",children:"Evaluate the forecast bounds within the next "}),t.jsx("div",{className:"condition-dropdown",children:t.jsx(he,{notFoundContent:"No options foun
1d",options:mt,showSearch:!1,defaultValue:Ge((e==null?void 0:e.time_window)||300),onChange:S=>{const c=Array.isArray(S)?S[0]:S;l({...e,time_window:st(c)})}},"check-every")})]})]})},Zs=e=>{const l=$.forecast,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.forecast,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),[b,x]=i.useState(h&&h.length>0&&h[0].source.name?h[0].source.name:""),S=i.useMemo(()=>Me(s),[s]),c=i.useMemo(()=>De(s,S,!0),[S,s]),m=i.useCallback(()=>{x(e.defaultSource||""),u(Z(e.defaultSource))},[e.defaultSource]);i.useEffect(()=>{d||m()},[m]),i.useEffect(()=>{const a={name:e.formState.name||"",type:e.formState.type||re.forecast,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(a)},[s]),i.useEffect(()=>m,[]);const[_,w]=i.useState(),[E,F]=i.useState(),V=i.useMemo(()=>ke(e.formState.conditions,E),[e.formState.conditions,E]),k=()=>S.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:a=>{var r,f,N,p,L,M;F((p=(N=(f=(r=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:r.series)==null?void 0:f[0])==null?void 0:N.custom)==null?void 0:p.config),w((M=(L=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:L.series)==null?void 0:M.length)},yAxisConfigOptions:{tickAmount:8,...V}}},widget:c,dateRange:C.params.dateRange,showOnlyGraph:!0}):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b===""?"No metrics available!":S.msg})}),B=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:b,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0}),P=i.useCallback(a=>{x(a),u(r=>a===Nt?r:qe(a,r))},[]),{containerRef:y,graphSectionStyle:j,resizerProps:A}=Ee();return t.jsxs("div",{className:"rule-container",ref:y,children:[t.jsx("div",{className:"graph-section",style:j,children:k()}),t.jsx(Ae,{...A}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{isCategoryDataSource:!0,source:b,onSourceChange:P})}),B()]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(Qs,{rule:e.formState,updateRule:e.upsertState,config:E})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:_,rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},Xs=["1 minute","5 minutes","10 minutes","20 minutes","30 minutes","45 minutes","1 hour"],er=({rule:e,updateRule:l})=>t.jsxs("div",{className:"threshold-container",children:[t.jsx("div",{className:"threshold-title",children:"An alert is triggered when a host stops reporting."}),t.jsx("div",{className:"threshold-settings-host",children:t.jsxs("div",{className:"alert-row-host alert-threshold-section",children:[t.jsx("div",{className:"threshold-label",children:"Notify if host stops reporting data for more than"}),t.jsx("div",{className:"threshold-inputs",children:t.jsx("div",{className:"evaluation-dropdown",children:t.jsx(he,{notFoundContent:"No options foun
1d",options:Xs,defaultValue:Ge((e==null?void 0:e.time_window)||300),onChange:n=>{const o=Array.isArray(n)?n[0]:n;l({...e,time_window:st(o)})}})})})]})})]}),tr=({rule:e,updateRule:l})=>{const[n,o]=i.useState([]),[g,v]=i.useState(!1),C=et.useContext(me),{dateRange:d}=C.params,s=d.fromTs,u=d.toTs,h=rt(),b=()=>{const x=[],S={label:"",builderId:0,scopeId:0,widgetAppId:5,builderConfig:{with:[{key:"SELECT_DATA_BY",value:["host.name"],is_arg:!0}],columns:["host.name"],source:{name:"host",alias:"",dataset_id:0}},builderViewOptions:{},params:[{key:"from_ts",value:s},{key:"to_ts",value:u}]};x.push(S),h(Ss(x,(c,m,_)=>{if(v(!!m),c&&_){const w=_;x.forEach((E,F)=>{const k=w[F].chart_data.data,B=k.map(P=>P["host.name"]);o(k.length>0?B:[])})}}))};return i.useEffect(()=>{b()},[]),t.jsx("div",{className:"host-details-alert",children:t.jsx("div",{className:"host-container",children:t.jsx("div",{className:"label-container",children:t.jsxs("div",{className:"label-body",children:[t.jsx("label",{className:"label",children:"Select Host"}),t.jsx("div",{className:"evaluation-dropdown",children:t.jsx(he,{notFoundContent:"No options found",options:n,isLoading:g,defaultValue:(e==null?void 0:e.host_list)??[],mode:Tt.Multiple,onChange:x=>{const S=Array.isArray(x)?x:[x];l({...e,type:re.host,host_list:S,config:[{columns:["host.name","resource_status"],source:{name:"host",alias:"",dataset_id:0},with:[{key:We,is_arg:!0,value:vt.ConvertToValueType(vt.In("host.name",S))},{key:"SELECT_DATA_BY",value:["host.name"],is_arg:!0}]}]})}})})]})})})})},ir=e=>{const l=$.host,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.host,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]);return t.jsx("div",{className:"rule-container",children:t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(tr,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(er,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})})},sr=e=>{const l=$.llm,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.apm,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),b=i.useMemo(()=>h&&h.length>0&&h[0].source.name?h[0].source.name:"",[h]),x=i.useMemo(()=>Me(s),[s]),S=i.useMemo(()=>De(s,x,!0),[x,s]),[c,m]=i.useState(),[_,w]=i.useState(),[E,F]=i.useState([]),V=i.useMemo(()=>ke(e.formState.conditions,c),[e.formState.conditions,c]);i.useEffect(()=>{d||u(Z(e.defaultSource))},[e.defaultSource]),i.useEffect(()=>{const a={name:e.formState.name||"",type:e.formState.type||re.metric,resource:"rum",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(a)},[s]),i.useEffect(()=>()=>{u(Z(e.defaultSource))},[]),i.useEffect(()=>{var a;if(e.template){const r=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:(a=e.template)==null?void 0:a.config});u(f=>({...f,builderConfig:r==null?void 0:r.builderConfig,formulas:r==null?void 0:r.formulas,dontRefreshData:!1}))}},[e.template]);const{containerRef:k,graphSectionStyle:B,resizerProps:P}=Ee(),y=()=>x.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:a=>{var r,f,N,p,L,M,W,G,Y,O;m((p=(N=(f=(r=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:r.series)==null?void 0:f[0])==null?void 0:N.custom)==null?void 0:p.config),w((M=(L=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:L.series)==null?void 0:M.length),F(Be((W=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:W.series,e.formState.evaluate,e.formState.time_window,((Y=(G=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:G.t
1imeRange)==null?void 0:Y.interval)||((O=a==null?void 0:a.time_range)==null?void 0:O.interval)))},timeseriesChartOptions:{extraSeries:E},yAxisConfigOptions:{tickAmount:8,...V}}},widget:S,dateRange:C.params.dateRange,showOnlyGraph:!0}):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b===""?"No metrics available!":x.msg})}),j=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:b,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0,isRumAlert:!0}),A=i.useCallback(a=>{u(r=>qe(a,r))},[]);return t.jsxs("div",{className:"rule-container",ref:k,children:[t.jsx("div",{className:"graph-section",style:B,children:y()}),t.jsx(Ae,{...P}),t.jsx(Ye,{alertType:"llm",appliedTemplate:e.template,onTemplateSelect:e.onTemplateSelect}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{source:b,onSourceChange:A})}),j()]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,config:c,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(xe,{groupCount:_,rule:e.formState,updateRule:e.upsertState,template:e.template})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},rr=e=>{const{type:l,active_step:n}=ce(),o=i.useContext(me),g=$.log,v=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[C,d]=i.useState(()=>v?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),s=i.useMemo(()=>C.builderConfig?Array.isArray(C.builderConfig)?C.builderConfig:[C.builderConfig]:void 0,[C.builderConfig]),u=i.useMemo(()=>s&&s.length>0&&s[0].source.name?s[0].source.name:"",[s]),h=i.useMemo(()=>Me(C),[C]),b=i.useMemo(()=>De(C,h,!0),[h,C]),[x,S]=i.useState(),[c,m]=i.useState(),[_,w]=i.useState([]),E=i.useMemo(()=>ke(e.formState.conditions,x),[e.formState.conditions,x]);i.useEffect(()=>{v||d(Z(e.defaultSource))},[e.defaultSource]),i.useEffect(()=>{const a={name:e.formState.name||"",type:e.formState.type||re.metric,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(C.builderConfig)?C.builderConfig:C.builderConfig?[C.builderConfig]:[],formulas:C.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(a)},[C]),i.useEffect(()=>()=>{d(Z(e.defaultSource))},[]),i.useEffect(()=>{var a;if(e.template){const r=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:(a=e.template)==null?void 0:a.config});d(f=>({...f,builderConfig:r==null?void 0:r.builderConfig,formulas:r==null?void 0:r.formulas,dontRefreshData:!1}))}},[e.template]);const F=i.useMemo(()=>l?$[l]:$.log,[l]),V=i.useMemo(()=>n?parseInt(n.split("-")[1],10):1,[n]),{containerRef:k,graphSectionStyle:B,resizerProps:P}=Ee(),y=()=>h.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:a=>{var r,f,N,p,L,M,W,G,Y,O;S((p=(N=(f=(r=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:r.series)==null?void 0:f[0])==null?void 0:N.custom)==null?void 0:p.config),m((M=(L=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:L.series)==null?void 0:M.length),w(Be((W=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:W.series,e.formState.evaluate,e.formState.time_window,((Y=(G=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:G.t
1imeRange)==null?void 0:Y.interval)||((O=a==null?void 0:a.time_range)==null?void 0:O.interval)))},timeseriesChartOptions:{extraSeries:_},yAxisConfigOptions:{tickAmount:8,...E}}},widget:b,dateRange:o.params.dateRange,showOnlyGraph:!0}):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:u===""?"No metrics available!":h.msg})}),j=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:u,queries:s,formulas:C.formulas,updateWidget:d,isFromAlert:!0,isLogAlert:!0}),A=i.useCallback(a=>{d(r=>qe(a,r))},[]);return t.jsxs("div",{className:"rule-container",ref:k,children:[t.jsx("div",{className:"graph-section",style:B,children:y()}),t.jsx(Ae,{...P}),t.jsx(Ye,{alertType:"log",appliedTemplate:e.template,onTemplateSelect:e.onTemplateSelect}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:F,completedStep:V-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:g[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{isCategoryDataSource:!0,source:u,onSourceChange:A})}),j()]})}),t.jsx(R,{defaultExpanded:!0,title:g[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,config:x,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:g[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:c,rule:e.formState,updateRule:e.upsertState,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:g[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:g[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},nr=e=>{const l=$.metric,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.metric,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),[b,x]=i.useState(h&&h.length>0&&h[0].source.name?h[0].source.name:""),S=i.useMemo(()=>Me(s),[s]),c=i.useMemo(()=>De(s,S,!0),[S,s]),[m,_]=i.useState(),[w,E]=i.useState(),[F,V]=i.useState([]),k=i.useMemo(()=>ke(e.formState.conditions,m),[e.formState.conditions,m]);i.useEffect(()=>{d||(x(e.defaultSource||""),u(Z(e.defaultSource)))},[e.defaultSource]),i.useEffect(()=>{const r={name:e.formState.name||"",type:e.formState.type||re.metric,resource:e.formState.resource||"",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(r)},[s]),i.useEffect(()=>{var r,f,N,p,L;if(e.template){const M=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:(r=e.template)==null?void 0:r.config});u(W=>({...W,builderConfig:M==null?void 0:M.builderConfig,formulas:M==null?void 0:M.formulas,dontRefreshData:!1})),x(((L=(p=(N=(f=e.template)==null?void 0:f.config)==null?void 0:N[0])==null?void 0:p.source)==null?void 0:L.name)||"")}},[e.template]);const{containerRef:B,graphSectionStyle:P,resizerProps:y}=Ee(),j=()=>S.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:r=>{var f,N,p,L,M,W,G,Y,O,K;_((L=(p=(N=(f=r==null?void 0:r.timeseriesChartDataV2)==null?void 0:f.series)==null?void 0:N[0])==null?void 0:p.custom)==null?void 0:L.config),E((W=(M=r==null?void 0:r.timeseriesChartDataV2)==null?void 0:M.series)==null?void 0:W.length),V(Be((G=r==null?void 0:r.timeseriesChartDataV2)==null?void 0:G.series,e.formState.evaluate,e.formState.time_window,((O=(Y=r==null?void 0:r.timeseriesChartDataV2)==null?void 0:Y.timeRange)==null?void 0:O.interval)||((K=r==null?void 0:r.time_range)==null?void 0:K.interval)))},timeseriesChartOptions:{extraSeries:F},yAxisConfigOptions:{tickAmount:8,...k}}},widget:c,dateRange:C.params.dateRange,showOnlyGraph:!0}
1):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b===""?"No metrics available!":S.msg})}),A=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:b,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0}),a=i.useCallback(r=>{x(r),u(f=>r===Nt?f:qe(r,f))},[]);return t.jsxs("div",{className:"rule-container",ref:B,children:[t.jsx("div",{className:"graph-section",style:P,children:j()}),t.jsx(Ae,{...y}),t.jsx(Ye,{alertType:"metric",appliedTemplate:e.template,onTemplateSelect:e.onTemplateSelect}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{isCategoryDataSource:!0,source:b,onSourceChange:a})}),A()]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,config:m,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{groupCount:w,rule:e.formState,updateRule:e.upsertState,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},ar=e=>{const l=$.rum,{type:n,active_step:o}=ce(),g=i.useMemo(()=>n?$[n]:$.apm,[n]),v=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),C=i.useContext(me),d=e.formState.config&&e.formState.config.length>0&&e.formState.config[0].source.name,[s,u]=i.useState(()=>d?{...le.cloneDeep(Ce),label:"",builderConfig:e.formState.config,formulas:e.formState.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:e.formState.id||0}:Z(e.defaultSource)),h=i.useMemo(()=>s.builderConfig?Array.isArray(s.builderConfig)?s.builderConfig:[s.builderConfig]:void 0,[s.builderConfig]),b=i.useMemo(()=>h&&h.length>0&&h[0].source.name?h[0].source.name:"",[h]),x=i.useMemo(()=>Me(s),[s]),S=i.useMemo(()=>De(s,x,!0),[x,s]),[c,m]=i.useState(),[_,w]=i.useState(),[E,F]=i.useState([]),V=i.useMemo(()=>ke(e.formState.conditions,c),[e.formState.conditions,c]);i.useEffect(()=>{d||u(Z(e.defaultSource))},[e.defaultSource]),i.useEffect(()=>{const a={name:e.formState.name||"",type:e.formState.type||re.metric,resource:"rum",frequency:e.formState.frequency||"single",tags:e.formState.tags||[],time_window:e.formState.time_window||0,eval:e.formState.eval||"",columns:e.formState.columns||[],conditions:e.formState.conditions||[],notification_setting:e.formState.notification_setting||{},config:Array.isArray(s.builderConfig)?s.builderConfig:s.builderConfig?[s.builderConfig]:[],formulas:s.formulas||[],id:e.formState.id,project_id:e.formState.project_id,project_uid:e.formState.project_uid,created_by:e.formState.created_by,is_active:e.formState.is_active,is_triggered:e.formState.is_triggered,valid:e.formState.valid,editMode:e.formState.editMode,unit:e.formState.unit,with:e.formState.with,billing_unit:e.formState.billing_unit,datapoint_count:e.formState.datapoint_count,resolved_notify:e.formState.resolved_notify,hide_graph_from_notification:e.formState.hide_graph_from_notification,custom_message:e.formState.custom_message,meta:e.formState.meta};e.upsertState(a)},[s]),i.useEffect(()=>()=>{u(Z(e.defaultSource))},[]),i.useEffect(()=>{var a;if(e.template){const r=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:(a=e.template)==null?void 0:a.config});u(f=>({...f,builderConfig:r==null?void 0:r.builderConfig,formulas:r==null?void 0:r.formulas,dontRefreshData:!1}))}},[e.template]);const{containerRef:k,graphSectionStyle:B,resizerProps:P}=Ee(),y=()=>x.isValid?t.jsx(Oe,{builderProps:{nestedProps:{onDataReceived:a=>{var r,f,N,p,L,M,W,G,Y,O;m((p=(N=(f=(r=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:r.series)==null?void 0:f[0])==null?void 0:N.custom)==null?void 0:p.config),w((M=(L=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:L.series)==null?void 0:M.length),F(Be((W=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:W.series,e.formState.evaluate,e.formState.time_window,((Y=(G=a==null?void 0:a.timeseriesChartDataV2)==null?void 0:G.t
1imeRange)==null?void 0:Y.interval)||((O=a==null?void 0:a.time_range)==null?void 0:O.interval)))},timeseriesChartOptions:{extraSeries:E},yAxisConfigOptions:{tickAmount:8,...V}}},widget:S,dateRange:C.params.dateRange,showOnlyGraph:!0}):t.jsx("div",{className:"widget-builder-placeholder",children:t.jsx("h5",{children:b===""?"No metrics available!":x.msg})}),j=()=>t.jsx(Ve,{chartType:ae.TimeseriesChart,widgetSource:b,queries:h,formulas:s.formulas,updateWidget:u,isFromAlert:!0,isRumAlert:!0}),A=i.useCallback(a=>{u(r=>qe(a,r))},[]);return t.jsxs("div",{className:"rule-container",ref:k,children:[t.jsx("div",{className:"graph-section",style:B,children:y()}),t.jsx(Ae,{...P}),t.jsx(Ye,{alertType:"rum",appliedTemplate:e.template,onTemplateSelect:e.onTemplateSelect}),t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:g,completedStep:v-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsxs(I,{className:"rule-condition-card",bordered:!0,children:[t.jsx("div",{className:"metrics-source-selection-container",children:t.jsx(Le,{source:b,onSourceChange:A})}),j()]})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx($e,{rule:e.formState,updateRule:e.upsertState,config:c,template:e.template})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(xe,{groupCount:_,rule:e.formState,updateRule:e.upsertState,template:e.template})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})]})},xt=[{label:"Error Budget",value:0,mode:"error_budget"},{label:"Burn Rate",value:1,mode:"burn_rate"}],or={error_budget:90,burn_rate:14.4},lr={"7d":7,"30d":30,"90d":90},cr=/^\d*\.?\d*$/,ii=(e,l)=>{if(!e)return"";const n=e.match(new RegExp(`^(\\d+)${l}$`));return n?n[1]:""},dr=({rule:e,updateRule:l,slo:n})=>{var k,B,P,y;const o=((k=e.meta)==null?void 0:k.mode)??"error_budget",g=e.conditions.find(j=>j.status===Ne.critical),v=e.conditions.find(j=>j.status===Ne.warning),[C,d]=i.useState(String((g==null?void 0:g.threshold)??"")),[s,u]=i.useState(v?String(v.threshold):""),[h,b]=i.useState(ii((B=e.meta)==null?void 0:B.long_window,"h")||"1"),[x,S]=i.useState(ii((P=e.meta)==null?void 0:P.short_window,"m")||"5"),c=i.useMemo(()=>((n==null?void 0:n.thresholds)??[]).map((j,A)=>({label:`${lr[j.window]}-day target${A===0?" (primary)":""}`,value:j.window})),[n]),m=(j,A)=>{const a=[{status:Ne.critical,threshold:Number(j)||0,operator:">=",isChecked:!0}];A!==""&&!Number.isNaN(Number(A))&&a.unshift({status:Ne.warning,threshold:Number(A),operator:">=",isChecked:!0}),l({...e,conditions:a})},_=j=>{var r;const A=((r=xt[j])==null?void 0:r.mode)??"error_budget";if(A===o)return;const a=String(or[A]);d(a),u(""),l({...e,meta:{...e.meta,mode:A,...A==="burn_rate"?{long_window:`${h||"1"}h`,short_window:`${x||"5"}m`}:{long_window:void 0,short_window:void 0}},conditions:[{status:Ne.critical,threshold:Number(a),operator:">=",isChecked:!0}]})},w=(j,A)=>{(A===""||cr.test(A))&&j(A)},E=j=>{const A=Array.isArray(j)?j[0]:j;l({...e,meta:{...e.meta,window:A}})},F=(j,A)=>{l({...e,meta:{...e.meta,long_window:`${Number(j)||1}h`,short_window:`${Number(A)||5}m`}})},V=t.jsx("div",{className:"slo-condition-v2__window",children:t.jsx(he,{options:c,showSearch:!1,selectedValues:(y=e.meta)!=null&&y.window?[e.meta.window]:[],placeholder:n?"Select target":"Select an SLO first",onChange:E})});return t.jsxs("div",{className:"threshold-container slo-condition-v2",children:[t.jsx("div",{className:"slo-condition-v2__tabs",children:t.jsx(At,{tabs:xt.map(({label:j,value:A})=>({label:j,value:A}
1)),selectedTab:xt.findIndex(j=>j.mode===o),onTabChange:j=>_(j.value)})}),t.jsx("div",{className:"slo-condition-v2__hint",children:o==="error_budget"?"Get notified when you've consumed too much of your error budget.":"Get notified when the rate of error budget consumption is too fast."}),o==="burn_rate"&&t.jsxs("div",{className:"slo-condition-v2__sentence",children:[t.jsx("span",{children:"Evaluate the last"}),t.jsx("div",{className:"slo-condition-v2__input",children:t.jsx(Fe,{id:"slo-long-window",type:"text",value:h,onChange:j=>w(b,j),onBlur:()=>F(h,x)})}),t.jsx("span",{children:"h and the last"}),t.jsx("div",{className:"slo-condition-v2__input",children:t.jsx(Fe,{id:"slo-short-window",type:"text",value:x,onChange:j=>w(S,j),onBlur:()=>F(h,x)})}),t.jsx("span",{children:"m for"}),V]}),t.jsxs("div",{className:"threshold-settings",children:[t.jsxs("div",{className:"alert-row alert-threshold-section slo-condition-v2__row",children:[t.jsx("span",{children:o==="error_budget"?"Alert if":"Alert when both burn rates are"}),t.jsx("div",{className:"slo-condition-v2__input",children:t.jsx(Fe,{id:"slo-alert-threshold",type:"text",value:C,onChange:j=>w(d,j),onBlur:()=>m(C,s)})}),o==="error_budget"?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"% of budget for"}),V,t.jsx("span",{children:"is consumed."})]}):t.jsx("span",{children:"or more."})]}),t.jsxs("div",{className:"alert-row warning-threshold-section slo-condition-v2__row",children:[t.jsx("span",{children:o==="error_budget"?"Warn if":"Warn if they are"}),t.jsx("div",{className:"slo-condition-v2__input",children:t.jsx(Fe,{id:"slo-warn-threshold",type:"text",placeholder:"â",value:s,onChange:j=>w(u,j),onBlur:()=>m(C,s)})}),t.jsx("span",{children:o==="error_budget"?"% is consumed.":"or more."})]})]}),v&&g&&v.threshold>=g.threshold&&t.jsx("div",{className:"rule-error-message",children:"The warning threshold must be lower than the alert threshold."})]})},ur=({rule:e,updateRule:l,slos:n,isLoading:o})=>{var s;const g=i.useMemo(()=>n.map(u=>({label:u.name,value:String(u.id)})),[n]),v=(s=e.meta)==null?void 0:s.slo_id,C=u=>{var S,c;const h=n.find(m=>m.id===u),b=(h==null?void 0:h.thresholds.map(m=>m.window))??[],x=(S=e.meta)!=null&&S.window&&b.includes(e.meta.window)?e.meta.window:((c=h==null?void 0:h.thresholds[0])==null?void 0:c.window)??"7d";l({...e,name:e.name||(h?`${h.name} budget`:e.name),meta:{...e.meta,slo_id:u||void 0,window:x}})},d=u=>C(Number(Array.isArray(u)?u[0]:u)||0);return i.useEffect(()=>{var b;const u=v?n.find(x=>x.id===v):void 0;if(!u)return;const h=u.thresholds.map(x=>x.window);(!e.name||!((b=e.meta)!=null&&b.window)||!h.includes(e.meta.window))&&C(u.id)},[v,n]),t.jsxs("div",{className:"slo-selection-v2",children:[t.jsx(he,{placeholder:o?"Loading SLOsâ¦":"Select SLO",showSearch:!0,isLoading:o,options:g,selectedValues:v?[String(v)]:[],onChange:d,notFoundContent:"No SLOs yet â create one under Alerts â SLO List"}),!o&&n.length===0&&t.jsx("div",{className:"slo-selection-v2__hint",children:"No SLOs found. Create one from the SLO List page first."})]})},mr=e=>{var s;const l=$.slo,n=rt(),{active_step:o}=ce(),g=He(ps),v=He(Ds);i.useEffect(()=>{n(Vs({limit:1e3}))},[n]);const C=i.useMemo(()=>o?parseInt(o.split("-")[1],10):1,[o]),d=i.useMemo(()=>g.find(u=>{var h;return u.id===((h=e.formState.meta)==null?void 0:h.slo_id)}),[g,(s=e.formState.meta)==null?void 0:s.slo_id]);return t.jsx("div",{className:"rule-container",children:t.jsxs("div",{className:"content-grid",children:[t.jsx("div",{className:"sidebar",children:t.jsx(ve,{stepItems:l,completedStep:C-1})}),t.jsxs("div",{className:"main-content",children:[t.jsx(R,{defaultExpanded:!0,title:l[0],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(ur,{rule:e.formState,updateRule:e.upsertState,slos:g,isLoading:v})})})}),t.jsx(R,{defaultExpanded:!0,title:l[1],children:t.jsx(I,{className:"rule-condition-card",bordered:!0,children:t.jsx("div",{children:t.jsx(dr,{rule:e.formState,updateRule:e.upsertState,slo:d})})})}),t.jsx(R,{defaultExpanded:!0,title:l[2],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx("div",{children:t.jsx(xe,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!0,title:l[3],children:t.jsx(I,{className:"rule-condition-card rule-aggregation-medium",bordered:!0,children:t.jsx("div",{children:t.jsx(je,{rule:e.formState,updateRule:e.upsertState})})})}),t.jsx(R,{defaultExpanded:!1,title:l[4],children:t.jsx(I,{className:"rule-condition-card rule-config-notification",bordered:!0,children:t.jsx(be,{rule:e.formState,updateRule:e.upsertState})})})]})]})})},fr=({chatId:e,projectId:l})=>{var Se,Te,Ke,Mt,Ot,kt;const{type:n,id:o}=ce(),g=rt(),v=Ct(),C=i.useContext(ht),d=i.useContext(me),[s]=ds(),u=s.get("template");(Te=(Se=d==null?void 0:d.params)==null?void 0:Se.query)==null||Te.get("tempId");const h=(Mt=(Ke=d==null?void 0:d.params)==null?void 0:Ke.query)==null?void 0:Mt.get(ot),b=i.useRef(!1),[x,S]=i.useState(null),[c,m]=i.useState(!1),_=i.useMemo(()=>ms(String(e||"")),[e]),w=He(_),E=fs(w),[F,V]=i.useState(),k=He(xs);i.useEffect(()=>{g(js())},[g]),i.useEffect(()=>{if(u){const T=decodeURIComponent(u);V(structuredClone(ct[T]))}else V(void 0)},[u]);const B=i.useMemo(()=>{var U;if(!(k!=null&&k.resources)||((U=k==null?void 0:k.resources)==null?void 0:U.length)===0||!n)return"";let T=n;(n==="anomaly"||n==="forecast")&&(T="metric"),n==="error_tracking"&&(T="trace");let q=[];return Ut[T]?q=Ut[T].filter(z=>{var J;return(J=k==null?void 0:k.resources)==null?void 0:J.includes(z.value)}):Bt[T]&&(q=Bt[T].filter(z=>{var J;return(J=k==null?void 0:k.resources)==null?void 0:J.includes(z.value)})),q.length>0?q[0].value:""},[k,n]),P=i.useMemo(()=>({name:"",type:n||"metric",resource:"",frequency:"multiple",tags:[],time_window:n===re.billing?1*60*60*24:300,eval:"",columns:[],conditions:n===re.slo?[{status:Ne.critical,threshold:90,operator:">=",isChecked:!0}]:[{status:Ne.warning,threshold:0,operator:">",isChecked:!0},{status:Ne.critical,threshold:0,operator:">",isChecked:!0}],notification_setting:{type:"none",channels:[],addresses:[],webhook:""},unit:"",billing_unit:"",datapoint_count:1,resolved_notify:!1,hide_graph_from_notification:!1,notify_by:[],evaluate:Ii,meta:{aggregated:30,diff:!1,...n===re.slo?{mode:"error_budget",window:"7d"}:{}},config:n===re.billing?ut.builderConfig:[JSON.parse(JSON.stringify(jt))],formulas:[],custom_message:"",host_list:[],notify_condition:{status_slice
1:[],renotify_interval:n===re.billing?60*60*6:60,renotify_count:-1},renotification_message:"",permission:{permission_type:lt.UNRESTRICTED,users:[]}}),[n]),[y,j]=i.useState(()=>{var z,J;if(!o){const Q=$t((J=(z=d==null?void 0:d.params)==null?void 0:z.query)==null?void 0:J.get(ot));if(Q)return{...structuredClone(P),...Q}}const T=structuredClone(P),q=Mi();q.length>0&&(T.tags=q);const U=Number(s.get("slo_id"))||0;return n===re.slo&&U&&(T.meta={...T.meta,slo_id:U}),T}),A=(kt=(Ot=d==null?void 0:d.params)==null?void 0:Ot.query)==null?void 0:kt.get("updateAlertTime");i.useEffect(()=>{if(h){N(!0);const T=$t(h);j(q=>T?{...structuredClone(q),...T}:q),setTimeout(()=>{N(!1)},100)}},[h,o,A]);const a=!1,r=()=>{var J,Q,_e,Re,Qe,Ze,fe,se,Ie;const T={define__rule_name:!1,define__frequency:!1,define__time:!1,define__notification:!1,define__group_by:!1,define__aggrigation:!1};(J=y.meta)!=null&&J.aggregated&&y.meta.aggregated>y.time_window&&(T.define__aggrigation=!0);const q=y.conditions.length>0;(y.name.trim().length<1||y.name.trim().length>50)&&(T.define__rule_name=!0),y.frequency.trim().length<1&&(T.define__frequency=!0),y.time_window<1&&(T.define__time=!0),q||(T.assertions__cases=!0),y.conditions&&y.conditions.every(Pe=>Pe.isChecked===!1)&&(T.assertions__cases=!0);const U=y.notification_setting;return(((Q=U.addresses)==null?void 0:Q.length)??0)>0||(((_e=U.channels)==null?void 0:_e.length)??0)>0||(((Re=U.msteams_channel)==null?void 0:Re.length)??0)>0||(((Qe=U.pager_duty_list)==null?void 0:Qe.length)??0)>0||(((Ze=U.opsgenie)==null?void 0:Ze.length)??0)>0||(((fe=U.jsm_ops)==null?void 0:fe.length)??0)>0||(((se=U.zenduty)==null?void 0:se.length)??0)>0||(((Ie=U.webhook)==null?void 0:Ie.trim().length)??0)>0||(T.define__notification=!0),ye({...T}),T},[f,N]=i.useState(!0),[p,L]=i.useState(!1),[M,W]=i.useState(null),G=i.useRef(!1),Y=i.useRef(null);i.useEffect(()=>{if(E){G.current=!0;return}!G.current||!o||(G.current=!1,g(gt(o,(T,q)=>{if(!T||!q)return;const U=q;W(z=>z?{...z,ai_quality:U.ai_quality}:U)})))},[E,o,g]);const O=i.useRef(),K=i.useRef("");i.useEffect(()=>(g(hs()),()=>{N(!1),j({...P}),V(void 0),clearTimeout(O.current),K.current="",g(_t()),d.params.query.delete("template"),d.params.query.delete(ot),d.params.query.delete(Oi),d.params.query.delete("updateAlertTime"),d.params.query.redirect()}),[g]),i.useEffect(()=>{const T=Wt(y);T!==K.current&&(K.current=T,g(ki(structuredClone(y))))},[y,g]);const te=T=>{const q={...P,...structuredClone(T)};q.conditions=q.conditions.map(z=>({...z,isChecked:!0}));const U=Ue({builderId:0,scopeId:0,label:"",widgetAppId:0,builderViewOptions:{},builderConfig:q.config});q.config=U==null?void 0:U.builderConfig,q.formulas=U==null?void 0:U.formulas,j(q),N(!1)};i.useEffect(()=>{!M||!o||h||M.id===Number(o)&&Y.current!==o&&(Y.current=o,te(M))},[M,o,h]),i.useEffect(()=>{F&&te(F)},[F]),i.useEffect(()=>{o?g(gt(o,(T,q)=>{T?W(q):(N(!1),v("/alerts/rules"))})):N(!1)},[o]);const ge=T=>{Object.keys(T).length>0&&j(q=>({...q,...T}))},ue=(T,q)=>{var J;const z=(J=(q||y).valid)==null?void 0:J[T];return z!==void 0?z:!1},oe=(T,q)=>{let U=!1;const z=q||y;let J;if(z.valid){const Q=Object.keys(z.valid);for(J of Q)if(J.indexOf(T)>=0&&z.valid[J]==!0){U=!0;break}}return U},ie=T=>{const q=T||y;return Object.keys(q.valid).some(U=>q.valid[U]===!0)},ye=T=>{j(q=>Object.assign({},{...q,valid:{...T}}))},de={inflight:a,formState:y,upsertState:ge,checkValid:ue,checkValidAll:oe,checkValidAny:ie,setValidState:ye,defaultSource:B,template:F,onTemplateSelect:T=>{T?d.params.query.set("template",encodeURIComponent((T==null?void 0:T.name)||"")):d.params.query.delete("template"),d.params.query.redirect()}},D=pi(y.notification_setting.webhook),H=i.useMemo(()=>{const T=[{key:"name",validate:()=>!!y.name.trim(),errorMessage:"Rule name is required"},{key:"warningThreshold",validate:()=>{const Q=y.conditions.find(Re=>Re.status===Ne.warning),_e=y.conditions.find(Re=>Re.status===Ne.critical);return Q&&_e?Di([Q,_e]):!0},errorMessage:"Invalid threshold values"},{key:"customMessage",validate:()=>zt((y==null?void 0:y.custom_message)||"")===null,errorMessage:"Check Custom Message Editor"},{key:"renotificationMessage",validate:()=>zt((y==null?void 0:y.renotification_message)||"")===null,errorMessage:"Check Renotification Message Editor"},{key:"invalid webhook url",validate:()=>D,errorMessage:"Check WebHook URL"},{key:"slo",validate:()=>{var Q,_e;return y.type!==re.slo||!!((Q=y.meta)!=null&&Q.slo_id&&((_e=y.meta)!=null&&_e.window))},errorMessage:"Select an SLO"}];({...JSON.parse(JSON.stringify(Ce))});const q={builderConfig:y.config,formulas:y.formulas||[],widgetAppId:ae.TimeseriesChart,scopeId:y.id||0},U=Me(q),z={};let J=!0;return!U.isValid&&y.type!==re.slo&&(J=!1,z["config-check"]=U.msg),T.forEach(Q=>{Q.validate()||(J=!1,z[Q.key]=Q.errorMessage)}),{isValid:J,errors:z}},[y,D]),X=()=>{var Re,Qe,Ze;
1if(!H.isValid){Object.entries(H.errors).forEach(([fe,se])=>{console.error(`Validation Error for ${fe}: ${se}`)}),ye({...y.valid,...Object.fromEntries(Object.keys(H.errors).map(fe=>[fe,!1]))});return}const{...T}=y;delete T.description;const q=r(),U=T.conditions,z={...T,conditions:U};let J={label:"",builderId:0,scopeId:0,widgetAppId:1,builderConfig:z.config,formulas:z.formulas,builderViewOptions:{},returnOnlyFormulaResult:!!(z.formulas&&z.formulas.length>0)};J=Vi(Pi(J)),z.config=J.builderConfig,ni()&&(console.debug("Submitting form:",T),console.debug("Submitting validation:",q));const Q=Fi(),_e=b.current;if(b.current=!1,!_e){const fe=qi(o??"new"),se=(fe==null?void 0:fe.liveAt)!=null?fe:null,Ie=(Re=M==null?void 0:M.ai_quality)==null?void 0:Re.suggested_config_object,Pe=!se&&o&&Ie&&!((Qe=M==null?void 0:M.ai_quality)!=null&&Qe.suggestion_applied)?{key:o,config:Ie,uiDisplay:(Ze=M==null?void 0:M.ai_quality)==null?void 0:Ze.suggested_ui_display}:null,we=se??Pe,nt=we!=null&&!Li(we.config,M==null?void 0:M.ai_quality)&&(Q==null||(we.liveAt??0)>Q.appliedAt&&Wt(we.config)!==Q.ruleState)&&!Ui(we.config,y);if(we&&nt){m(!1),S(we);return}if(!Q&&E){m(!0);return}}L(!0),g(o?Bi({...z,id:z.id??Number(o)},(fe,se)=>{L(!1),(se==null?void 0:se.status)==200?(g(Xe("success","Rule updated successfully")),j({...P}),v("/alerts/rules"),g(gt(o,(Ie,Pe)=>{}))):g(Xe("error",Gt(se,"Error while updating rule. Please check fields")))},Q!=null):$i({...z},async(fe,se)=>{var Ie,Pe,we,nt,pt,Dt,Vt,Pt,Ft,qt;L(!1),(Pe=(Ie=d==null?void 0:d.params)==null?void 0:Ie.query)!=null&&Pe.has("tempId")&&((nt=(we=d==null?void 0:d.params)==null?void 0:we.query)==null||nt.delete("tempId"),(Dt=(pt=d==null?void 0:d.params)==null?void 0:pt.query)==null||Dt.redirect()),(se==null?void 0:se.status)==200?(g(Xe("success","Rule created successfully")),l&&e&&await Wi(`alert_${l}_${(Vt=se==null?void 0:se.data)==null?void 0:Vt.id}`,+e),((Ft=(Pt=C.user)==null?void 0:Pt.project_meta_data)==null?void 0:Ft.user_created_alert_rule)===!1&&(g(Ht(Yt.AlertRules)),C.changeContext({key:"user",value:{...C.user,project_meta_data:{...(qt=C.user)==null?void 0:qt.project_meta_data,user_created_alert_rule:!0}}})),g(Ht(Yt.AlertRules)),j({...P}),v("/alerts/rules")):g(Xe("error",Gt(se,"Error while creating rule. Please check fields")))}))};if(f)return t.jsx(yt,{});const ne=()=>{var U;if(!x)return;const T=x;S(null);const q=zi(T.config,o,(U=d==null?void 0:d.params)==null?void 0:U.query);q&&(v({pathname:window.location.pathname,search:q},{replace:!0}),g(Xe("success","Suggested config applied to the form",{title:"Config applied!"})))};return t.jsxs("div",{className:"rule-configuration",children:[t.jsxs("div",{className:`container alert-rule-container ${n}-rule-container-wrapper`,children:[(n==="metric"||n==="kubernetes")&&t.jsx(nr,{...de}),n==="trace"&&t.jsx(zs,{...de}),n==="host"&&t.jsx(ir,{...de}),n==="rum"&&t.jsx(ar,{...de}),n==="llm"&&t.jsx(sr,{...de}),n==="log"&&t.jsx(rr,{...de}),n==="billing"&&t.jsx(Ys,{...de}),n==="anomaly"&&t.jsx(Ws,{...de}),n==="forecast"&&t.jsx(Zs,{...de}),n==="custom"&&t.jsx(Js,{...de}),n==="error_tracking"&&t.jsx(Ks,{...de}),n==="slo"&&t.jsx(mr,{...de}),t.jsx("div",{className:"footer",children:t.jsx(Us,{onSubmit:X,isValid:H.isValid,errors:H.errors,loading:p,opsAIEnabled:ri(n)})})]}),t.jsx(Fs,{isOpen:!!x,onClose:()=>S(null),suggestion:x,saveLabel:o?"Update Alert":"Create Alert",onApply:ne,onSaveWithoutApplying:()=>{b.current=!0,S(null),X()}}),t.jsx(qs,{isOpen:c,isEdit:!!o,onClose:()=>m(!1),onSaveAsIs:()=>{b.current=!0,m(!1),X()}})]})},hr=i.memo(fr),gr=[{icon:Ki,title:"Metrics",query_param:"metric",description:"A metric threshold alert compares metric values to a static threshold",sources:[]},{icon:Qi,title:"Host",query_param:"host",description:"Check if one or more hosts are reporting to Middleware",sources:[]},{icon:Zi,title:"Logs",query_param:"log",description:"Monitor logs gathered by Middleware",sources:[]},{icon:Jt,title:"APM",query_param:"trace",description:"Monitor Application Performance data gathered by Middleware",sources:[]},{icon:Xi,title:"RUM",query_param:"rum",description:"Monitor Real User data gathered by Middleware",sources:[]},{icon:es,title:"LLM",query_param:"llm",description:"Alert on error rate, latency increase, or custom evaluation metrics for your LLM applications.",sources:[]},{icon:ts,title:"Billing",query_param:"billing",description:"Alert based on the size of ingested data for your account.",sources:[]},{icon:is,title:"Anomaly",query_param:"anomaly",description:"Detect anomalous behavior for a metrics based on historical data.",sources:[]},{icon:ss,title:"Forecast",query_param:"forecast",description:"Alert when a metrics is projected to cross a threshold.",sources:[]},{icon:Jt,title:"Error Tracking",query_param:"error_tracking",description:"Identify the most important issues in your applications",sources:[]},{icon:rs,title:"SLO",query_param:"slo",description:"Track the consumption of SLO error budget",sources:[]}],Sr=e=>e.includes("/alerts/new-rule")||e.includes("/alerts/edit-rule"),Nn=()=>{var L,M,W,G,Y;const e=Ct(),l=si(),n=i.useContext(ai),o=i.useRef(l),g=Gi();o.current=l;const v=i.useRef(null),C=i.useRef(null),d=i.useRef(null),[s,u]=i.useState([]),h=et.useRef(null),b=rt(),x=et.useContext(me),{type:S,id:c}=ce(),m=i.useContext(ht),_=(M=(L=m==null?void 0:m.user)==null?void 0:L.account)==null?void 0:M.project_id,w=+(((G=(W=x==null?void 0:x.params)==null?void 0:W.query)==null?void 0:G.get("tempId"))??0),E=i.useRef(w);E.current=w;const F=g(c?Kt.EditRules:Kt.CreateAlerts),V=ri(S),[k,B]=et.useState(V),[P,y]=i.useState(!1),[j,A]=i.useState(!0);i.useEffect(()=>()=>{b(_t()),bt()},[b]),i.useEffect(()=>{B(V)},[V]),i.useEffect(()=>{if(!V)return;const O=()=>B(!0);
1return window.addEventListener(tt,O),()=>window.removeEventListener(tt,O)},[V]),i.useEffect(()=>{S||b(_t())},[S,b]),i.useEffect(()=>{if(!F)return;const O=n==null?void 0:n.navigator;if(!O)return;const K=O.push.bind(O),te=O.replace.bind(O);C.current=K,d.current=te;const ge=(ue,oe,ie)=>{const ye=oi(oe,o.current.pathname).pathname;if(Sr(ye)){ue==="push"?K(oe,ie):te(oe,ie);return}if(!E.current){ue==="push"?K(oe,ie):te(oe,ie);return}v.current={kind:ue,to:oe,state:ie},y(!0)};return O.push=(ue,oe)=>{ge("push",ue,oe)},O.replace=(ue,oe)=>{ge("replace",ue,oe)},()=>{O.push=K,O.replace=te}},[n==null?void 0:n.navigator,F]),i.useEffect(()=>{if(!V){A(!1);return}(c||w)&&_?(b(Hi()),b(Yi(`${c||w}`,!c,_,(O,K,te)=>{var ge;!O&&K===200&&u(((ge=te==null?void 0:te.data)==null?void 0:ge.items)??[]),A(!1)}))):A(!1)},[c,w,_,V,b]);const a=()=>{e("/alerts/new-rule/custom/step-1")},r=i.useCallback(()=>{B(O=>!O)},[]),f=i.useCallback(()=>{const O=v.current;v.current=null;const K=C.current,te=d.current;!O||!K||!te||(O.kind==="push"?K(O.to,O.state):te(O.to,O.state))},[]),N=i.useCallback(()=>{v.current=null,y(!1)},[]),p=(Y=s==null?void 0:s[0])==null?void 0:Y.id;return F?t.jsxs("div",{className:"grid-view-with-sidepanel",children:[S?t.jsx(hr,{projectId:_,chatId:p?`${p}`:void 0}):t.jsxs("div",{className:"new-alert-content-body",children:[t.jsxs("div",{className:"create-alert-section-container",children:[t.jsx("h1",{className:"rule-title",children:"Pick A Monitor Type"}),t.jsx("div",{className:"alert-types-container",children:gr.map((O,K)=>t.jsx(ns,{info:O,onClick:()=>{e(`/alerts/new-rule/${O.query_param}/step-1`)}},K))}),t.jsx("div",{className:"footer-text",children:"Can't find what you're looking for?"}),t.jsx("div",{className:"custom-alert-container",children:t.jsx(as,{title:"Create Custom Alerts Tailored to Your Needs",prefixIcon:os,onCardClick:a})})]}),t.jsx("div",{className:"bottom-footer",children:"Once you select a monitor type, you can then add custom attributes and threshold values for alert trigger."})]}),V&&t.jsxs("div",{className:"side-panel",children:[k&&_&&t.jsx("div",{className:"side-panel-content",children:j?t.jsx("div",{className:"alert-chat-loader",children:t.jsx(yt,{})}):t.jsx(Ps,{chats:s,setChats:u,toolHandlerRef:h,tokenLimitExceeded:!1,editId:c,projectId:_})}),t.jsx("div",{className:"panel-left-icon-container",onClick:()=>{r()},children:t.jsx(Os,{size:16,className:`${k?"open":"closed"}`,color:"var(--color-primary)"})})]}),t.jsx(it,{isOpen:P,onClose:N,type:ft.Delete,title:"Are you sure you want to go back?",description:"Your chat with OpsAI and the alert configuration will not be saved if you leave without creating the alert.",confirmBtnText:"Delete",handleConfirmEvent:()=>{p&&ls(`alert_temp_${_}_${w}`,p),x.params.query.delete("tempId"),y(!1),f()},cancelBtnText:"Cancel",handleCancelEvent:N})]}):t.jsx(Ji,{})};export{Nn as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.