import{M as N,O as o,bG as H,bH as J,bx as Q,r as s,j as e,q as l,aJ as g,t as U,x as P,f as V,L as Y,F as z,c as K,a4 as j,a5 as y,d as u,aI as W,ch as _,ap as E}from"./index-DNBEEyYo.js";import{j as m}from"./js-yaml-DoUMCdfs.js";const B=N.injectEndpoints({endpoints:t=>({getAlertmanagerConfig:t.query({query:()=>({url:"admin/alerts/management/config"}),providesTags:[o.AdminTags.Config]}),getAlertmanagerStatus:t.query({query:()=>({url:"admin/alerts/management/status"}),providesTags:[o.AdminTags.Status]}),updateAlertmanagerConfig:t.mutation({query:({data:a})=>({url:"admin/alerts/management/config",method:"post",data:a}),invalidatesTags:[o.AdminTags.Config,o.AdminTags.Status]}),reloadAlertmanagerConfig:t.mutation({query:()=>({url:"admin/alerts/management/reload",method:"post"}),invalidatesTags:[o.AdminTags.Status],extraOptions:{skipError:!0}}),updateGlobal:t.mutation({query:({data:a})=>({url:"admin/alerts/management/global",method:"post",data:a}),invalidatesTags:[o.AdminTags.Config,o.AdminTags.Status]})})}),{useGetAlertmanagerConfigQuery:X,useGetAlertmanagerStatusQuery:Z,useUpdateAlertmanagerConfigMutation:$,useReloadAlertmanagerConfigMutation:ee}=B,M=({response:t})=>{var a,c,n;if((t==null?void 0:t.status)>=400)return(a=t.data)!=null&&a.usrMsg?(c=t.data)==null?void 0:c.usrMsg:(n=t.data)==null?void 0:n.errorMsg},te=(t,a)=>t==="json"?JSON.parse(a||""):m.load(a||"",{json:!0}),q=(t,a)=>t==="json"?JSON.stringify(a||"",null,4):m.dump(a||"").trim(),ie=()=>{var v,w;H(J.AlertsSettings);const t=Q(),[a,c]=s.useState("yaml"),[n,C]=s.useState(!1),{data:h,isLoading:L}=X(),{data:i,isLoading:O}=Z(),[A,{isLoading:b,error:S,reset:T}]=$(),[f,{isLoading:G,error:k}]=ee(),[x,d]=s.useState();s.useEffect(()=>{var r;d(m.dump(((r=i==null?void 0:i.config)==null?void 0:r.original)||"").trim()),f()},[(v=i==null?void 0:i.config)==null?void 0:v.original,f]);const I=s.useCallback(([r])=>{c(r),T(),d(q(r,h))},[T,h]),F=()=>{C(!0),d(q(a,h))},p=s.useCallback(()=>{var r;C(!1),d(m.dump(((r=i==null?void 0:i.config)==null?void 0:r.original)||"").trim())},[(w=i==null?void 0:i.config)==null?void 0:w.original]),R=s.useCallback(()=>{const r=te(a,x);A({data:r}).unwrap().then(()=>{p()})},[A,p,a,x]),D=n?a:"yaml";return e.jsxs(l,{flexGrow:1,flexDirection:"column",children:[e.jsx(g,{mb:"20px",pl:"0px",intent:"inline",onClick:()=>t(U(P.settings.alerts.list)),children:"<- back to alert configuration"}),e.jsx(V,{title:"Advanced configuration",maxHeight:"calc(100vh - 265px)",actions:!n&&e.jsx(g,{onClick:F,intent:"primary",children:"Edit"}),children:L||O?e.jsx(Y,{}):e.jsxs(e.Fragment,{children:[e.jsxs(z,{mb:"20px",children:[!n&&e.jsxs(l,{flexGrow:1,flexDirection:"column",mb:"20px",children:[e.jsx(K,{fontSize:"12px",gray:!0,mb:"20px",mr:"auto",children:"This is the configuration currently loaded on the Alertmanager."}),e.jsx(j,{content:e.jsxs(l,{flexDirection:"column",children:[e.jsx(u,{children:"If you make any changes to this configuration ensure that the changes are valid by reloading the configuration until the changes are loaded and visible here."}),e.jsx(u,{children:"The reload button will try to load the changes to the Alertmanager. You can use it to test if the changes you made to the configuration is valid."})]}),type:y.neutral})]}),e.jsx(W,{mode:D,readOnly:!n,labelAction:n&&e.jsx(_,{ml:"auto",placeholder:"format",noDataMessage:"format",options:["json","yaml"],value:[a],onChange:I,width:"auto"}),labelProps:{align:"top"},value:x,onChange:r=>{d(r)}})]}),n?e.jsx(j,{content:e.jsx(l,{alignItems:"center",children:e.jsx(u,{children:"Updating the configuration will overwrite any change made after the current configuration is loaded into the browser. I sure hope you know what you are doing."})}),type:y.warning}):e.jsx(j,{content:e.jsx(l,{alignItems:"center",children:e.jsx(u,{children:"Keep in mind that it takes some time to propagate changes to the alertmanager."})}),type:y.neutral}),n&&S&&e.jsx(E,{intent:"error",children:M(S)}),!n&&k&&e.jsx(E,{intent:"error",children:M(k)}),e.jsx(l,{justifyContent:"right",mt:"20px",children:n?e.jsxs(e.Fragment,{children:[e.jsx(g,{type:"button",onClick:p,disabled:b,intent:"secondary",mr:"15px",children:"Cancel"}),e.jsx(g,{type:"button",onClick:R,isLoading:b,children:"Save"})]}):e.jsx(g,{type:"button",onClick:f,isLoading:G,children:"Reload"})})]})})]})};export{ie as default};
