/*! For license information please see AlertingRuleForm.9e1b485e0020c58a325b.js.LICENSE.txt */
"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5372],{88131:(e,t,n)=>{n.r(t),n.d(t,{default:()=>Er});var i,r=n(27549),a=n(68404),o=n(66015),s=n(95967),l=n(8771),c=n(9617),u=n(40920),d=n(78721),p=n(90894),f=n(29507),h=n(47570),g=n(59052),m=n(16144),v=n(31510),x=n(98134),b=n(14284),y=n(95378),j=n(58257),w=n(26011),C=n(33899),A=n(83809),k=n(88414),I=n(8455),S=n(50475),O=n(59940),R=n(84719),N=n(1652),T=n(65586),$=n(2563),q=n(66322),F=n(86207),E=n(22389),M=n(45916);const L=["onChange","ref"];const D=()=>{var e,t;const n=(0,c.yK)(Q),{register:r,control:a,watch:o,formState:{errors:s}}=(0,g.Gc)();return o("type")===k.$.cloudRecording?null:(0,M.jsxs)(E.z,{stepNo:2,title:"Alert evaluation behavior",children:[(0,M.jsx)(R.g,{label:"For",description:"Expression has to be true for this long for the alert to be fired.",children:(0,M.jsxs)("div",{className:n.flexRow,children:[(0,M.jsx)(R.g,{invalid:!(null===(e=s.forTime)||void 0===e||!e.message),error:null===(t=s.forTime)||void 0===t?void 0:t.message,className:n.inlineField,children:(0,M.jsx)(N.I,Object.assign({},r("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),{width:8}))}),(0,M.jsx)(T.g,{name:"forTimeUnit",render:e=>{let{field:{onChange:t}}=e,i=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,L);return(0,M.jsx)($.Ph,Object.assign({},i,{options:q.qr,onChange:e=>t(null==e?void 0:e.value),width:15,className:n.timeUnit}))},control:a})]})}),i||(i=(0,M.jsx)(F.Y,{}))]})},Q=e=>({inlineField:r.css`
    margin-bottom: 0;
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
  `,timeUnit:r.css`
    margin-left: ${e.spacing.xs};
  `});var _=n(23019),W=n.n(_),P=n(4546),U=n(74025),G=n(9442),z=n(24085),V=n(61959),B=n(93783),Z=n(19854),Y=n(73389);function K(e,t,n){const i=new RegExp("(\\$"+t+"\\b)|(\\${"+t+"})","gm"),r="${"+n+"}";return e.replace(i,r)}function J(e){return!(e.includes("/")||e.includes("\\"))||'Cannot contain "/" or "\\" characters'}const H=["onChange","ref"],X=["ref"];function ee(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}const te=e=>{var t,n,i,r,o;let{rulesSourceName:s}=e;const{control:l,watch:u,formState:{errors:d},setValue:p}=(0,g.Gc)(),f=(0,c.wW)(ne),[m,v]=(0,a.useState)(!1),x=(0,C._)((e=>e.rulerRules)),b=(0,h.I0)();(0,a.useEffect)((()=>{b((0,A.UR)({rulesSourceName:s}))}),[s,b]);const y=null===(t=x[s])||void 0===t?void 0:t.result,j=u("namespace"),w=(0,a.useMemo)((()=>y?Object.keys(y).map((e=>({label:e,value:e}))):[]),[y]),k=(0,a.useMemo)((()=>{var e;return j&&(null==y||null===(e=y[j])||void 0===e?void 0:e.map((e=>({label:e.name,value:e.name}))))||[]}),[j,y]);return(0,M.jsxs)("div",{className:f.flexRow,children:[(0,M.jsx)(R.g,{"data-testid":"namespace-picker",label:"Namespace",error:null===(n=d.namespace)||void 0===n?void 0:n.message,invalid:!(null===(i=d.namespace)||void 0===i||!i.message),children:(0,M.jsx)(T.g,{render:e=>{let{field:{onChange:t}}=e,n=ee(e.field,H);return(0,M.jsx)(Z.P,Object.assign({},n,{className:f.input,onChange:e=>{p("group",""),t(e)},onCustomChange:e=>{e&&v(!0)},options:w,width:42}))},name:"namespace",control:l,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:J}}})}),(0,M.jsx)(R.g,{"data-testid":"group-picker",label:"Group",error:null===(r=d.group)||void 0===r?void 0:r.message,invalid:!(null===(o=d.group)||void 0===o||!o.message),children:(0,M.jsx)(T.g,{render:e=>{let{}=e,t=ee(e.field,X);return(0,M.jsx)(Z.P,Object.assign({},t,{options:k,width:42,custom:m,className:f.input}))},name:"group",control:l,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:J}}})})]})},ne=e=>({flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * + * {
      margin-left: ${e.spacing(3)};
    }
  `,input:r.css`
    width: 330px !important;
  `});var ie=n(95513);const re=()=>{const e=(0,c.wW)(se);return(0,M.jsxs)(U.K,{gap:.5,children:[(0,M.jsx)("div",{className:e.slashNotAllowed,children:"Folders with '/' character are not allowed."}),(0,M.jsx)(G.u,{placement:"top",content:"Link to the Github issue",theme:"info",children:(0,M.jsx)(z.J,{name:"info-circle",size:"xs",className:e.infoIcon,onClick:()=>window.open("https://github.com/grafana/grafana/issues/42947","_blank")})})]})},ae=e=>-1!==e.indexOf("/");function oe(e){const{value:t}=e,n={warningCondition:e=>ae(e),warningComponent:re},i={disallowValues:!0,isAllowedValue:e=>!ae(e)};return(0,M.jsx)(ie.Es,Object.assign({showRoot:!1,allowEmpty:!0,initialTitle:null==t?void 0:t.title,initialFolderId:null==t?void 0:t.id,accessControlMetadata:!0},e,{permissionLevel:h.bf.View,customAdd:i,folderWarning:n}))}const se=e=>({slashNotAllowed:r.css`
    color: ${e.colors.warning.main};
    font-size: 12px;
    margin-bottom: 2px;
  `,infoIcon:r.css`
    color: ${e.colors.warning.main};
    font-size: 12px;
    margin-bottom: 2px;
    cursor: pointer;
  `}),le=["ref"];var ce,ue;const de={message:"Recording rule name must be valid metric name. It may only contain letters, numbers, and colons. It may not contain whitespace.",value:/^[a-zA-Z_:][a-zA-Z0-9_:]*$/},pe=e=>{var t,n,i,r,a,o;let{initialFolder:s}=e;const{register:l,watch:u,formState:{errors:d}}=(0,g.Gc)(),p=(0,c.wW)(he),f=u("type"),m=u("dataSourceName"),v=u("type"),x=fe(s);return(0,M.jsxs)(E.z,{stepNo:v===k.$.cloudRecording?2:3,title:v===k.$.cloudRecording?"Add details for your recording rule":"Add details for your alert",description:v===k.$.cloudRecording?"Add labels to help you better manage your rules":"Write a summary and add labels to help you better manage your alerts",children:[(0,M.jsx)(R.g,{className:p.formInput,label:"Rule name",error:null==d||null===(t=d.name)||void 0===t?void 0:t.message,invalid:!(null===(n=d.name)||void 0===n||!n.message),children:(0,M.jsx)(N.I,Object.assign({id:"name"},l("name",{required:{value:!0,message:"Must enter an alert name"},pattern:f===k.$.cloudRecording?de:void 0,validate:{pathSeparator:e=>f!==k.$.grafana||J(e)}})))}),(f===k.$.cloudRecording||f===k.$.cloudAlerting)&&m&&(0,M.jsx)(te,{rulesSourceName:m}),f===k.$.grafana&&(0,M.jsxs)("div",{className:W()([p.flexRow,p.alignBaseline]),children:[(0,M.jsx)(R.g,{label:ce||(ce=(0,M.jsx)(P._,{htmlFor:"folder",description:"Select a folder to store your rule.",children:(0,M.jsxs)(U.K,{gap:.5,children:["Folder",(0,M.jsx)(G.u,{placement:"top",content:(0,M.jsx)("div",{children:"Each folder has unique folder permission. When you store multiple rules in a folder, the folder access permissions get assigned to the rules."}),children:(0,M.jsx)(z.J,{name:"info-circle",size:"xs"})})]})})),className:p.formInput,error:null===(i=d.folder)||void 0===i?void 0:i.message,invalid:!(null===(r=d.folder)||void 0===r||!r.message),"data-testid":"folder-picker",children:(0,M.jsx)(T.g,{render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,le);return(0,M.jsx)(oe,Object.assign({inputId:"folder"},t,{enableCreateNew:V.Vt.hasPermission(h.bW.FoldersCreate),enableReset:!0,filter:x,dissalowSlashes:!0}))},name:"folder",rules:{required:{value:!0,message:"Please select a folder"},validate:{pathSeparator:e=>J(e.title)}}})}),(0,M.jsx)(R.g,{label:"Group","data-testid":"group-picker",description:"Rules within the same group are evaluated after the same time interval.",className:p.formInput,error:null===(a=d.group)||void 0===a?void 0:a.message,invalid:!(null===(o=d.group)||void 0===o||!o.message),children:(0,M.jsx)(N.I,Object.assign({id:"group"},l("group",{required:{value:!0,message:"Must enter a group name"}})))})]}),v!==k.$.cloudRecording&&(ue||(ue=(0,M.jsx)(B.Z,{})))]})},fe=e=>{const t=(0,a.useCallback)((t=>{const n=V.Vt.hasEditPermissionInFolders,i=V.Vt.hasAccessInMetadata(h.bW.AlertingRuleCreate,t,n),r=e&&t.folderId===e.id&&V.Vt.hasAccessInMetadata(h.bW.AlertingRuleUpdate,t,n);return i||r}),[e]);return(0,a.useCallback)((e=>e.filter(t).filter((e=>{var t;return!ae(null!==(t=e.title)&&void 0!==t?t:"")}))),[t])},he=e=>({alignBaseline:r.css`
    align-items: baseline;
    margin-bottom: ${e.spacing(3)};
  `,formInput:r.css`
    width: 275px;

    & + & {
      margin-left: ${e.spacing(3)};
    }
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: end;
  `});var ge,me,ve,xe=n(78316),be=n(11340),ye=n(35011),je=n(2394);const we=()=>{const[e,t]=(0,a.useState)(!1),n=(0,c.wW)(Ce),i=(0,c.l4)();return(0,M.jsxs)(E.z,{stepNo:4,title:"Notifications",description:"Grafana handles the notifications for alerts by assigning labels to alerts. These labels connect alerts to contact points and silence alert instances that have matching labels.",children:[(0,M.jsx)("div",{children:(0,M.jsx)("div",{className:n.hideButton,onClick:()=>t(!e),children:(e?"Show":"Hide")+" flow chart"})}),(0,M.jsxs)("div",{className:n.contentWrapper,children:[!e&&(0,M.jsx)("img",{className:n.flowChart,src:`public/img/alerting/notification_policy_${i.name.toLowerCase()}.svg`,alt:"notification policy flow chart"}),(0,M.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[ge||(ge=(0,M.jsx)(je.Z,{})),(0,M.jsxs)(be.Z,{className:n.card,children:[me||(me=(0,M.jsx)(be.Z.Heading,{children:"Root route – default for all alerts"})),ve||(ve=(0,M.jsxs)(be.Z.Description,{children:["Without custom labels, your alert will be routed through the root route. To view and edit the root route, go to ",(0,M.jsx)(ye.r,{href:"/alerting/routes",children:"notification policies"})," or contact your admin in case you are using non-Grafana alert management."]}))]})]})]})]})},Ce=e=>({contentWrapper:r.css`
    display: flex;
    align-items: center;
  `,hideButton:r.css`
    color: ${e.colors.text.secondary};
    cursor: pointer;
    margin-bottom: ${e.spacing(1)};
  `,card:r.css`
    max-width: 500px;
  `,flowChart:r.css`
    margin-right: ${e.spacing(3)};
  `});function Ae(e){return null==e}var ke={isNothing:Ae,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:Ae(e)?[]:[e]},repeat:function(e,t){var n,i="";for(n=0;n<t;n+=1)i+=e;return i},isNegativeZero:function(e){return 0===e&&Number.NEGATIVE_INFINITY===1/e},extend:function(e,t){var n,i,r,a;if(t)for(n=0,i=(a=Object.keys(t)).length;n<i;n+=1)e[r=a[n]]=t[r];return e}};function Ie(e,t){var n="",i=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+="\n\n"+e.mark.snippet),i+" "+n):i}function Se(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=Ie(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack||""}Se.prototype=Object.create(Error.prototype),Se.prototype.constructor=Se,Se.prototype.toString=function(e){return this.name+": "+Ie(this,e)};var Oe=Se;function Re(e,t,n,i,r){var a="",o="",s=Math.floor(r/2)-1;return i-t>s&&(t=i-s+(a=" ... ").length),n-i>s&&(n=i+s-(o=" ...").length),{str:a+e.slice(t,n).replace(/\t/g,"→")+o,pos:i-t+a.length}}function Ne(e,t){return ke.repeat(" ",t-e.length)+e}var Te=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var n,i=/\r?\n|\r|\0/g,r=[0],a=[],o=-1;n=i.exec(e.buffer);)a.push(n.index),r.push(n.index+n[0].length),e.position<=n.index&&o<0&&(o=r.length-2);o<0&&(o=r.length-1);var s,l,c="",u=Math.min(e.line+t.linesAfter,a.length).toString().length,d=t.maxLength-(t.indent+u+3);for(s=1;s<=t.linesBefore&&!(o-s<0);s++)l=Re(e.buffer,r[o-s],a[o-s],e.position-(r[o]-r[o-s]),d),c=ke.repeat(" ",t.indent)+Ne((e.line-s+1).toString(),u)+" | "+l.str+"\n"+c;for(l=Re(e.buffer,r[o],a[o],e.position,d),c+=ke.repeat(" ",t.indent)+Ne((e.line+1).toString(),u)+" | "+l.str+"\n",c+=ke.repeat("-",t.indent+u+3+l.pos)+"^\n",s=1;s<=t.linesAfter&&!(o+s>=a.length);s++)l=Re(e.buffer,r[o+s],a[o+s],e.position-(r[o]-r[o+s]),d),c+=ke.repeat(" ",t.indent)+Ne((e.line+s+1).toString(),u)+" | "+l.str+"\n";return c.replace(/\n$/,"")},$e=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],qe=["scalar","sequence","mapping"];var Fe=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===$e.indexOf(t))throw new Oe('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[String(e)]=n}))})),t}(t.styleAliases||null),-1===qe.indexOf(this.kind))throw new Oe('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function Ee(e,t){var n=[];return e[t].forEach((function(e){var t=n.length;n.forEach((function(n,i){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=i)})),n[t]=e})),n}function Me(e){return this.extend(e)}Me.prototype.extend=function(e){var t=[],n=[];if(e instanceof Fe)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new Oe("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof Fe))throw new Oe("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new Oe("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new Oe("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),n.forEach((function(e){if(!(e instanceof Fe))throw new Oe("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var i=Object.create(Me.prototype);return i.implicit=(this.implicit||[]).concat(t),i.explicit=(this.explicit||[]).concat(n),i.compiledImplicit=Ee(i,"implicit"),i.compiledExplicit=Ee(i,"explicit"),i.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function i(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e<t;e+=1)arguments[e].forEach(i);return n}(i.compiledImplicit,i.compiledExplicit),i};var Le=Me,De=new Fe("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return null!==e?e:""}}),Qe=new Fe("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return null!==e?e:[]}}),_e=new Fe("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return null!==e?e:{}}}),We=new Le({explicit:[De,Qe,_e]});var Pe=new Fe("tag:yaml.org,2002:null",{kind:"scalar",resolve:function(e){if(null===e)return!0;var t=e.length;return 1===t&&"~"===e||4===t&&("null"===e||"Null"===e||"NULL"===e)},construct:function(){return null},predicate:function(e){return null===e},represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});var Ue=new Fe("tag:yaml.org,2002:bool",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)},construct:function(e){return"true"===e||"True"===e||"TRUE"===e},predicate:function(e){return"[object Boolean]"===Object.prototype.toString.call(e)},represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function Ge(e){return 48<=e&&e<=55}function ze(e){return 48<=e&&e<=57}var Ve=new Fe("tag:yaml.org,2002:int",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i=e.length,r=0,a=!1;if(!i)return!1;if("-"!==(t=e[r])&&"+"!==t||(t=e[++r]),"0"===t){if(r+1===i)return!0;if("b"===(t=e[++r])){for(r++;r<i;r++)if("_"!==(t=e[r])){if("0"!==t&&"1"!==t)return!1;a=!0}return a&&"_"!==t}if("x"===t){for(r++;r<i;r++)if("_"!==(t=e[r])){if(!(48<=(n=e.charCodeAt(r))&&n<=57||65<=n&&n<=70||97<=n&&n<=102))return!1;a=!0}return a&&"_"!==t}if("o"===t){for(r++;r<i;r++)if("_"!==(t=e[r])){if(!Ge(e.charCodeAt(r)))return!1;a=!0}return a&&"_"!==t}}if("_"===t)return!1;for(;r<i;r++)if("_"!==(t=e[r])){if(!ze(e.charCodeAt(r)))return!1;a=!0}return!(!a||"_"===t)},construct:function(e){var t,n=e,i=1;if(-1!==n.indexOf("_")&&(n=n.replace(/_/g,"")),"-"!==(t=n[0])&&"+"!==t||("-"===t&&(i=-1),t=(n=n.slice(1))[0]),"0"===n)return 0;if("0"===t){if("b"===n[1])return i*parseInt(n.slice(2),2);if("x"===n[1])return i*parseInt(n.slice(2),16);if("o"===n[1])return i*parseInt(n.slice(2),8)}return i*parseInt(n,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&e%1==0&&!ke.isNegativeZero(e)},represent:{binary:function(e){return e>=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),Be=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var Ze=/^[-+]?[0-9]+e/;var Ye=new Fe("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!Be.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||ke.isNegativeZero(e))},represent:function(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(ke.isNegativeZero(e))return"-0.0";return n=e.toString(10),Ze.test(n)?n.replace("e",".e"):n},defaultStyle:"lowercase"}),Ke=We.extend({implicit:[Pe,Ue,Ve,Ye]}),Je=Ke,He=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),Xe=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var et=new Fe("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==He.exec(e)||null!==Xe.exec(e))},construct:function(e){var t,n,i,r,a,o,s,l,c=0,u=null;if(null===(t=He.exec(e))&&(t=Xe.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],i=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(n,i,r));if(a=+t[4],o=+t[5],s=+t[6],t[7]){for(c=t[7].slice(0,3);c.length<3;)c+="0";c=+c}return t[9]&&(u=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(u=-u)),l=new Date(Date.UTC(n,i,r,a,o,s,c)),u&&l.setTime(l.getTime()-u),l},instanceOf:Date,represent:function(e){return e.toISOString()}});var tt=new Fe("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),nt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var it=new Fe("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i=0,r=e.length,a=nt;for(n=0;n<r;n++)if(!((t=a.indexOf(e.charAt(n)))>64)){if(t<0)return!1;i+=6}return i%8==0},construct:function(e){var t,n,i=e.replace(/[\r\n=]/g,""),r=i.length,a=nt,o=0,s=[];for(t=0;t<r;t++)t%4==0&&t&&(s.push(o>>16&255),s.push(o>>8&255),s.push(255&o)),o=o<<6|a.indexOf(i.charAt(t));return 0===(n=r%4*6)?(s.push(o>>16&255),s.push(o>>8&255),s.push(255&o)):18===n?(s.push(o>>10&255),s.push(o>>2&255)):12===n&&s.push(o>>4&255),new Uint8Array(s)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,i="",r=0,a=e.length,o=nt;for(t=0;t<a;t++)t%3==0&&t&&(i+=o[r>>18&63],i+=o[r>>12&63],i+=o[r>>6&63],i+=o[63&r]),r=(r<<8)+e[t];return 0===(n=a%3)?(i+=o[r>>18&63],i+=o[r>>12&63],i+=o[r>>6&63],i+=o[63&r]):2===n?(i+=o[r>>10&63],i+=o[r>>4&63],i+=o[r<<2&63],i+=o[64]):1===n&&(i+=o[r>>2&63],i+=o[r<<4&63],i+=o[64],i+=o[64]),i}}),rt=Object.prototype.hasOwnProperty,at=Object.prototype.toString;var ot=new Fe("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,a,o=[],s=e;for(t=0,n=s.length;t<n;t+=1){if(i=s[t],a=!1,"[object Object]"!==at.call(i))return!1;for(r in i)if(rt.call(i,r)){if(a)return!1;a=!0}if(!a)return!1;if(-1!==o.indexOf(r))return!1;o.push(r)}return!0},construct:function(e){return null!==e?e:[]}}),st=Object.prototype.toString;var lt=new Fe("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,a,o=e;for(a=new Array(o.length),t=0,n=o.length;t<n;t+=1){if(i=o[t],"[object Object]"!==st.call(i))return!1;if(1!==(r=Object.keys(i)).length)return!1;a[t]=[r[0],i[r[0]]]}return!0},construct:function(e){if(null===e)return[];var t,n,i,r,a,o=e;for(a=new Array(o.length),t=0,n=o.length;t<n;t+=1)i=o[t],r=Object.keys(i),a[t]=[r[0],i[r[0]]];return a}}),ct=Object.prototype.hasOwnProperty;var ut=new Fe("tag:yaml.org,2002:set",{kind:"mapping",resolve:function(e){if(null===e)return!0;var t,n=e;for(t in n)if(ct.call(n,t)&&null!==n[t])return!1;return!0},construct:function(e){return null!==e?e:{}}}),dt=Je.extend({implicit:[et,tt],explicit:[it,ot,lt,ut]}),pt=Object.prototype.hasOwnProperty,ft=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,ht=/[\x85\u2028\u2029]/,gt=/[,\[\]\{\}]/,mt=/^(?:!|!!|![a-z\-]+!)$/i,vt=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function xt(e){return Object.prototype.toString.call(e)}function bt(e){return 10===e||13===e}function yt(e){return 9===e||32===e}function jt(e){return 9===e||32===e||10===e||13===e}function wt(e){return 44===e||91===e||93===e||123===e||125===e}function Ct(e){var t;return 48<=e&&e<=57?e-48:97<=(t=32|e)&&t<=102?t-97+10:-1}function At(e){return 48===e?"\0":97===e?"":98===e?"\b":116===e||9===e?"\t":110===e?"\n":118===e?"\v":102===e?"\f":114===e?"\r":101===e?"":32===e?" ":34===e?'"':47===e?"/":92===e?"\\":78===e?"":95===e?" ":76===e?"\u2028":80===e?"\u2029":""}function kt(e){return e<=65535?String.fromCharCode(e):String.fromCharCode(55296+(e-65536>>10),56320+(e-65536&1023))}for(var It=new Array(256),St=new Array(256),Ot=0;Ot<256;Ot++)It[Ot]=At(Ot)?1:0,St[Ot]=At(Ot);function Rt(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||dt,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Nt(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=Te(n),new Oe(t,n)}function Tt(e,t){throw Nt(e,t)}function $t(e,t){e.onWarning&&e.onWarning.call(null,Nt(e,t))}var qt={YAML:function(e,t,n){var i,r,a;null!==e.version&&Tt(e,"duplication of %YAML directive"),1!==n.length&&Tt(e,"YAML directive accepts exactly one argument"),null===(i=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&Tt(e,"ill-formed argument of the YAML directive"),r=parseInt(i[1],10),a=parseInt(i[2],10),1!==r&&Tt(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=a<2,1!==a&&2!==a&&$t(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var i,r;2!==n.length&&Tt(e,"TAG directive accepts exactly two arguments"),i=n[0],r=n[1],mt.test(i)||Tt(e,"ill-formed tag handle (first argument) of the TAG directive"),pt.call(e.tagMap,i)&&Tt(e,'there is a previously declared suffix for "'+i+'" tag handle'),vt.test(r)||Tt(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(t){Tt(e,"tag prefix is malformed: "+r)}e.tagMap[i]=r}};function Ft(e,t,n,i){var r,a,o,s;if(t<n){if(s=e.input.slice(t,n),i)for(r=0,a=s.length;r<a;r+=1)9===(o=s.charCodeAt(r))||32<=o&&o<=1114111||Tt(e,"expected valid JSON character");else ft.test(s)&&Tt(e,"the stream contains non-printable characters");e.result+=s}}function Et(e,t,n,i){var r,a,o,s;for(ke.isObject(n)||Tt(e,"cannot merge mappings; the provided source object is unacceptable"),o=0,s=(r=Object.keys(n)).length;o<s;o+=1)a=r[o],pt.call(t,a)||(t[a]=n[a],i[a]=!0)}function Mt(e,t,n,i,r,a,o,s,l){var c,u;if(Array.isArray(r))for(c=0,u=(r=Array.prototype.slice.call(r)).length;c<u;c+=1)Array.isArray(r[c])&&Tt(e,"nested arrays are not supported inside keys"),"object"==typeof r&&"[object Object]"===xt(r[c])&&(r[c]="[object Object]");if("object"==typeof r&&"[object Object]"===xt(r)&&(r="[object Object]"),r=String(r),null===t&&(t={}),"tag:yaml.org,2002:merge"===i)if(Array.isArray(a))for(c=0,u=a.length;c<u;c+=1)Et(e,t,a[c],n);else Et(e,t,a,n);else e.json||pt.call(n,r)||!pt.call(t,r)||(e.line=o||e.line,e.lineStart=s||e.lineStart,e.position=l||e.position,Tt(e,"duplicated mapping key")),"__proto__"===r?Object.defineProperty(t,r,{configurable:!0,enumerable:!0,writable:!0,value:a}):t[r]=a,delete n[r];return t}function Lt(e){var t;10===(t=e.input.charCodeAt(e.position))?e.position++:13===t?(e.position++,10===e.input.charCodeAt(e.position)&&e.position++):Tt(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function Dt(e,t,n){for(var i=0,r=e.input.charCodeAt(e.position);0!==r;){for(;yt(r);)9===r&&-1===e.firstTabInLine&&(e.firstTabInLine=e.position),r=e.input.charCodeAt(++e.position);if(t&&35===r)do{r=e.input.charCodeAt(++e.position)}while(10!==r&&13!==r&&0!==r);if(!bt(r))break;for(Lt(e),r=e.input.charCodeAt(e.position),i++,e.lineIndent=0;32===r;)e.lineIndent++,r=e.input.charCodeAt(++e.position)}return-1!==n&&0!==i&&e.lineIndent<n&&$t(e,"deficient indentation"),i}function Qt(e){var t,n=e.position;return!(45!==(t=e.input.charCodeAt(n))&&46!==t||t!==e.input.charCodeAt(n+1)||t!==e.input.charCodeAt(n+2)||(n+=3,0!==(t=e.input.charCodeAt(n))&&!jt(t)))}function _t(e,t){1===t?e.result+=" ":t>1&&(e.result+=ke.repeat("\n",t-1))}function Wt(e,t){var n,i,r=e.tag,a=e.anchor,o=[],s=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=o),i=e.input.charCodeAt(e.position);0!==i&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,Tt(e,"tab characters must not be used in indentation")),45===i)&&jt(e.input.charCodeAt(e.position+1));)if(s=!0,e.position++,Dt(e,!0,-1)&&e.lineIndent<=t)o.push(null),i=e.input.charCodeAt(e.position);else if(n=e.line,Gt(e,t,3,!1,!0),o.push(e.result),Dt(e,!0,-1),i=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==i)Tt(e,"bad indentation of a sequence entry");else if(e.lineIndent<t)break;return!!s&&(e.tag=r,e.anchor=a,e.kind="sequence",e.result=o,!0)}function Pt(e){var t,n,i,r,a=!1,o=!1;if(33!==(r=e.input.charCodeAt(e.position)))return!1;if(null!==e.tag&&Tt(e,"duplication of a tag property"),60===(r=e.input.charCodeAt(++e.position))?(a=!0,r=e.input.charCodeAt(++e.position)):33===r?(o=!0,n="!!",r=e.input.charCodeAt(++e.position)):n="!",t=e.position,a){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&62!==r);e.position<e.length?(i=e.input.slice(t,e.position),r=e.input.charCodeAt(++e.position)):Tt(e,"unexpected end of the stream within a verbatim tag")}else{for(;0!==r&&!jt(r);)33===r&&(o?Tt(e,"tag suffix cannot contain exclamation marks"):(n=e.input.slice(t-1,e.position+1),mt.test(n)||Tt(e,"named tag handle cannot contain such characters"),o=!0,t=e.position+1)),r=e.input.charCodeAt(++e.position);i=e.input.slice(t,e.position),gt.test(i)&&Tt(e,"tag suffix cannot contain flow indicator characters")}i&&!vt.test(i)&&Tt(e,"tag name cannot contain such characters: "+i);try{i=decodeURIComponent(i)}catch(t){Tt(e,"tag name is malformed: "+i)}return a?e.tag=i:pt.call(e.tagMap,n)?e.tag=e.tagMap[n]+i:"!"===n?e.tag="!"+i:"!!"===n?e.tag="tag:yaml.org,2002:"+i:Tt(e,'undeclared tag handle "'+n+'"'),!0}function Ut(e){var t,n;if(38!==(n=e.input.charCodeAt(e.position)))return!1;for(null!==e.anchor&&Tt(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!jt(n)&&!wt(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&Tt(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function Gt(e,t,n,i,r){var a,o,s,l,c,u,d,p,f,h=1,g=!1,m=!1;if(null!==e.listener&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,a=o=s=4===n||3===n,i&&Dt(e,!0,-1)&&(g=!0,e.lineIndent>t?h=1:e.lineIndent===t?h=0:e.lineIndent<t&&(h=-1)),1===h)for(;Pt(e)||Ut(e);)Dt(e,!0,-1)?(g=!0,s=a,e.lineIndent>t?h=1:e.lineIndent===t?h=0:e.lineIndent<t&&(h=-1)):s=!1;if(s&&(s=g||r),1!==h&&4!==n||(p=1===n||2===n?t:t+1,f=e.position-e.lineStart,1===h?s&&(Wt(e,f)||function(e,t,n){var i,r,a,o,s,l,c,u=e.tag,d=e.anchor,p={},f=Object.create(null),h=null,g=null,m=null,v=!1,x=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=p),c=e.input.charCodeAt(e.position);0!==c;){if(v||-1===e.firstTabInLine||(e.position=e.firstTabInLine,Tt(e,"tab characters must not be used in indentation")),i=e.input.charCodeAt(e.position+1),a=e.line,63!==c&&58!==c||!jt(i)){if(o=e.line,s=e.lineStart,l=e.position,!Gt(e,n,2,!1,!0))break;if(e.line===a){for(c=e.input.charCodeAt(e.position);yt(c);)c=e.input.charCodeAt(++e.position);if(58===c)jt(c=e.input.charCodeAt(++e.position))||Tt(e,"a whitespace character is expected after the key-value separator within a block mapping"),v&&(Mt(e,p,f,h,g,null,o,s,l),h=g=m=null),x=!0,v=!1,r=!1,h=e.tag,g=e.result;else{if(!x)return e.tag=u,e.anchor=d,!0;Tt(e,"can not read an implicit mapping pair; a colon is missed")}}else{if(!x)return e.tag=u,e.anchor=d,!0;Tt(e,"can not read a block mapping entry; a multiline key may not be an implicit key")}}else 63===c?(v&&(Mt(e,p,f,h,g,null,o,s,l),h=g=m=null),x=!0,v=!0,r=!0):v?(v=!1,r=!0):Tt(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,c=i;if((e.line===a||e.lineIndent>t)&&(v&&(o=e.line,s=e.lineStart,l=e.position),Gt(e,t,4,!0,r)&&(v?g=e.result:m=e.result),v||(Mt(e,p,f,h,g,m,o,s,l),h=g=m=null),Dt(e,!0,-1),c=e.input.charCodeAt(e.position)),(e.line===a||e.lineIndent>t)&&0!==c)Tt(e,"bad indentation of a mapping entry");else if(e.lineIndent<t)break}return v&&Mt(e,p,f,h,g,null,o,s,l),x&&(e.tag=u,e.anchor=d,e.kind="mapping",e.result=p),x}(e,f,p))||function(e,t){var n,i,r,a,o,s,l,c,u,d,p,f,h=!0,g=e.tag,m=e.anchor,v=Object.create(null);if(91===(f=e.input.charCodeAt(e.position)))o=93,c=!1,a=[];else{if(123!==f)return!1;o=125,c=!0,a={}}for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),f=e.input.charCodeAt(++e.position);0!==f;){if(Dt(e,!0,t),(f=e.input.charCodeAt(e.position))===o)return e.position++,e.tag=g,e.anchor=m,e.kind=c?"mapping":"sequence",e.result=a,!0;h?44===f&&Tt(e,"expected the node content, but found ','"):Tt(e,"missed comma between flow collection entries"),p=null,s=l=!1,63===f&&jt(e.input.charCodeAt(e.position+1))&&(s=l=!0,e.position++,Dt(e,!0,t)),n=e.line,i=e.lineStart,r=e.position,Gt(e,t,1,!1,!0),d=e.tag,u=e.result,Dt(e,!0,t),f=e.input.charCodeAt(e.position),!l&&e.line!==n||58!==f||(s=!0,f=e.input.charCodeAt(++e.position),Dt(e,!0,t),Gt(e,t,1,!1,!0),p=e.result),c?Mt(e,a,v,d,u,p,n,i,r):s?a.push(Mt(e,null,v,d,u,p,n,i,r)):a.push(u),Dt(e,!0,t),44===(f=e.input.charCodeAt(e.position))?(h=!0,f=e.input.charCodeAt(++e.position)):h=!1}Tt(e,"unexpected end of the stream within a flow collection")}(e,p)?m=!0:(o&&function(e,t){var n,i,r,a,o,s=1,l=!1,c=!1,u=t,d=0,p=!1;if(124===(a=e.input.charCodeAt(e.position)))i=!1;else{if(62!==a)return!1;i=!0}for(e.kind="scalar",e.result="";0!==a;)if(43===(a=e.input.charCodeAt(++e.position))||45===a)1===s?s=43===a?3:2:Tt(e,"repeat of a chomping mode identifier");else{if(!((r=48<=(o=a)&&o<=57?o-48:-1)>=0))break;0===r?Tt(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):c?Tt(e,"repeat of an indentation width identifier"):(u=t+r-1,c=!0)}if(yt(a)){do{a=e.input.charCodeAt(++e.position)}while(yt(a));if(35===a)do{a=e.input.charCodeAt(++e.position)}while(!bt(a)&&0!==a)}for(;0!==a;){for(Lt(e),e.lineIndent=0,a=e.input.charCodeAt(e.position);(!c||e.lineIndent<u)&&32===a;)e.lineIndent++,a=e.input.charCodeAt(++e.position);if(!c&&e.lineIndent>u&&(u=e.lineIndent),bt(a))d++;else{if(e.lineIndent<u){3===s?e.result+=ke.repeat("\n",l?1+d:d):1===s&&l&&(e.result+="\n");break}for(i?yt(a)?(p=!0,e.result+=ke.repeat("\n",l?1+d:d)):p?(p=!1,e.result+=ke.repeat("\n",d+1)):0===d?l&&(e.result+=" "):e.result+=ke.repeat("\n",d):e.result+=ke.repeat("\n",l?1+d:d),l=!0,c=!0,d=0,n=e.position;!bt(a)&&0!==a;)a=e.input.charCodeAt(++e.position);Ft(e,n,e.position,!1)}}return!0}(e,p)||function(e,t){var n,i,r;if(39!==(n=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,i=r=e.position;0!==(n=e.input.charCodeAt(e.position));)if(39===n){if(Ft(e,i,e.position,!0),39!==(n=e.input.charCodeAt(++e.position)))return!0;i=e.position,e.position++,r=e.position}else bt(n)?(Ft(e,i,r,!0),_t(e,Dt(e,!1,t)),i=r=e.position):e.position===e.lineStart&&Qt(e)?Tt(e,"unexpected end of the document within a single quoted scalar"):(e.position++,r=e.position);Tt(e,"unexpected end of the stream within a single quoted scalar")}(e,p)||function(e,t){var n,i,r,a,o,s,l;if(34!==(s=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,n=i=e.position;0!==(s=e.input.charCodeAt(e.position));){if(34===s)return Ft(e,n,e.position,!0),e.position++,!0;if(92===s){if(Ft(e,n,e.position,!0),bt(s=e.input.charCodeAt(++e.position)))Dt(e,!1,t);else if(s<256&&It[s])e.result+=St[s],e.position++;else if((o=120===(l=s)?2:117===l?4:85===l?8:0)>0){for(r=o,a=0;r>0;r--)(o=Ct(s=e.input.charCodeAt(++e.position)))>=0?a=(a<<4)+o:Tt(e,"expected hexadecimal character");e.result+=kt(a),e.position++}else Tt(e,"unknown escape sequence");n=i=e.position}else bt(s)?(Ft(e,n,i,!0),_t(e,Dt(e,!1,t)),n=i=e.position):e.position===e.lineStart&&Qt(e)?Tt(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}Tt(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?m=!0:!function(e){var t,n,i;if(42!==(i=e.input.charCodeAt(e.position)))return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!jt(i)&&!wt(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&Tt(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),pt.call(e.anchorMap,n)||Tt(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],Dt(e,!0,-1),!0}(e)?function(e,t,n){var i,r,a,o,s,l,c,u,d=e.kind,p=e.result;if(jt(u=e.input.charCodeAt(e.position))||wt(u)||35===u||38===u||42===u||33===u||124===u||62===u||39===u||34===u||37===u||64===u||96===u)return!1;if((63===u||45===u)&&(jt(i=e.input.charCodeAt(e.position+1))||n&&wt(i)))return!1;for(e.kind="scalar",e.result="",r=a=e.position,o=!1;0!==u;){if(58===u){if(jt(i=e.input.charCodeAt(e.position+1))||n&&wt(i))break}else if(35===u){if(jt(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&Qt(e)||n&&wt(u))break;if(bt(u)){if(s=e.line,l=e.lineStart,c=e.lineIndent,Dt(e,!1,-1),e.lineIndent>=t){o=!0,u=e.input.charCodeAt(e.position);continue}e.position=a,e.line=s,e.lineStart=l,e.lineIndent=c;break}}o&&(Ft(e,r,a,!1),_t(e,e.line-s),r=a=e.position,o=!1),yt(u)||(a=e.position+1),u=e.input.charCodeAt(++e.position)}return Ft(e,r,a,!1),!!e.result||(e.kind=d,e.result=p,!1)}(e,p,1===n)&&(m=!0,null===e.tag&&(e.tag="?")):(m=!0,null===e.tag&&null===e.anchor||Tt(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===h&&(m=s&&Wt(e,f))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&Tt(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"'),l=0,c=e.implicitTypes.length;l<c;l+=1)if((d=e.implicitTypes[l]).resolve(e.result)){e.result=d.construct(e.result),e.tag=d.tag,null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);break}}else if("!"!==e.tag){if(pt.call(e.typeMap[e.kind||"fallback"],e.tag))d=e.typeMap[e.kind||"fallback"][e.tag];else for(d=null,l=0,c=(u=e.typeMap.multi[e.kind||"fallback"]).length;l<c;l+=1)if(e.tag.slice(0,u[l].tag.length)===u[l].tag){d=u[l];break}d||Tt(e,"unknown tag !<"+e.tag+">"),null!==e.result&&d.kind!==e.kind&&Tt(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+d.kind+'", not "'+e.kind+'"'),d.resolve(e.result,e.tag)?(e.result=d.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):Tt(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||m}function zt(e){var t,n,i,r,a=e.position,o=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(Dt(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(o=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!jt(r);)r=e.input.charCodeAt(++e.position);for(i=[],(n=e.input.slice(t,e.position)).length<1&&Tt(e,"directive name must not be less than one character in length");0!==r;){for(;yt(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!bt(r));break}if(bt(r))break;for(t=e.position;0!==r&&!jt(r);)r=e.input.charCodeAt(++e.position);i.push(e.input.slice(t,e.position))}0!==r&&Lt(e),pt.call(qt,n)?qt[n](e,n,i):$t(e,'unknown document directive "'+n+'"')}Dt(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,Dt(e,!0,-1)):o&&Tt(e,"directives end mark is expected"),Gt(e,e.lineIndent-1,4,!1,!0),Dt(e,!0,-1),e.checkLineBreaks&&ht.test(e.input.slice(a,e.position))&&$t(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&Qt(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,Dt(e,!0,-1)):e.position<e.length-1&&Tt(e,"end of the stream or a document separator is expected")}function Vt(e,t){t=t||{},0!==(e=String(e)).length&&(10!==e.charCodeAt(e.length-1)&&13!==e.charCodeAt(e.length-1)&&(e+="\n"),65279===e.charCodeAt(0)&&(e=e.slice(1)));var n=new Rt(e,t),i=e.indexOf("\0");for(-1!==i&&(n.position=i,Tt(n,"null byte is not allowed in input")),n.input+="\0";32===n.input.charCodeAt(n.position);)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)zt(n);return n.documents}var Bt={loadAll:function(e,t,n){null!==t&&"object"==typeof t&&void 0===n&&(n=t,t=null);var i=Vt(e,n);if("function"!=typeof t)return i;for(var r=0,a=i.length;r<a;r+=1)t(i[r])},load:function(e,t){var n=Vt(e,t);if(0!==n.length){if(1===n.length)return n[0];throw new Oe("expected a single document in the stream, but found more")}}},Zt=Object.prototype.toString,Yt=Object.prototype.hasOwnProperty,Kt=65279,Jt={0:"\\0",7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r",27:"\\e",34:'\\"',92:"\\\\",133:"\\N",160:"\\_",8232:"\\L",8233:"\\P"},Ht=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],Xt=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function en(e){var t,n,i;if(t=e.toString(16).toUpperCase(),e<=255)n="x",i=2;else if(e<=65535)n="u",i=4;else{if(!(e<=4294967295))throw new Oe("code point within a string may not be greater than 0xFFFFFFFF");n="U",i=8}return"\\"+n+ke.repeat("0",i-t.length)+t}function tn(e){this.schema=e.schema||dt,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=ke.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=function(e,t){var n,i,r,a,o,s,l;if(null===t)return{};for(n={},r=0,a=(i=Object.keys(t)).length;r<a;r+=1)o=i[r],s=String(t[o]),"!!"===o.slice(0,2)&&(o="tag:yaml.org,2002:"+o.slice(2)),(l=e.compiledTypeMap.fallback[o])&&Yt.call(l.styleAliases,s)&&(s=l.styleAliases[s]),n[o]=s;return n}(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType='"'===e.quotingType?2:1,this.forceQuotes=e.forceQuotes||!1,this.replacer="function"==typeof e.replacer?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result="",this.duplicates=[],this.usedDuplicates=null}function nn(e,t){for(var n,i=ke.repeat(" ",t),r=0,a=-1,o="",s=e.length;r<s;)-1===(a=e.indexOf("\n",r))?(n=e.slice(r),r=s):(n=e.slice(r,a+1),r=a+1),n.length&&"\n"!==n&&(o+=i),o+=n;return o}function rn(e,t){return"\n"+ke.repeat(" ",e.indent*t)}function an(e){return 32===e||9===e}function on(e){return 32<=e&&e<=126||161<=e&&e<=55295&&8232!==e&&8233!==e||57344<=e&&e<=65533&&e!==Kt||65536<=e&&e<=1114111}function sn(e){return on(e)&&e!==Kt&&13!==e&&10!==e}function ln(e,t,n){var i=sn(e),r=i&&!an(e);return(n?i:i&&44!==e&&91!==e&&93!==e&&123!==e&&125!==e)&&35!==e&&!(58===t&&!r)||sn(t)&&!an(t)&&35===e||58===t&&r}function cn(e,t){var n,i=e.charCodeAt(t);return i>=55296&&i<=56319&&t+1<e.length&&(n=e.charCodeAt(t+1))>=56320&&n<=57343?1024*(i-55296)+n-56320+65536:i}function un(e){return/^\n* /.test(e)}function dn(e,t,n,i,r,a,o,s){var l,c,u=0,d=null,p=!1,f=!1,h=-1!==i,g=-1,m=on(c=cn(e,0))&&c!==Kt&&!an(c)&&45!==c&&63!==c&&58!==c&&44!==c&&91!==c&&93!==c&&123!==c&&125!==c&&35!==c&&38!==c&&42!==c&&33!==c&&124!==c&&61!==c&&62!==c&&39!==c&&34!==c&&37!==c&&64!==c&&96!==c&&function(e){return!an(e)&&58!==e}(cn(e,e.length-1));if(t||o)for(l=0;l<e.length;u>=65536?l+=2:l++){if(!on(u=cn(e,l)))return 5;m=m&&ln(u,d,s),d=u}else{for(l=0;l<e.length;u>=65536?l+=2:l++){if(10===(u=cn(e,l)))p=!0,h&&(f=f||l-g-1>i&&" "!==e[g+1],g=l);else if(!on(u))return 5;m=m&&ln(u,d,s),d=u}f=f||h&&l-g-1>i&&" "!==e[g+1]}return p||f?n>9&&un(e)?5:o?2===a?5:2:f?4:3:!m||o||r(e)?2===a?5:2:1}function pn(e,t,n,i,r){e.dump=function(){if(0===t.length)return 2===e.quotingType?'""':"''";if(!e.noCompatMode&&(-1!==Ht.indexOf(t)||Xt.test(t)))return 2===e.quotingType?'"'+t+'"':"'"+t+"'";var a=e.indent*Math.max(1,n),o=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-a),s=i||e.flowLevel>-1&&n>=e.flowLevel;switch(dn(t,s,e.indent,o,(function(t){return function(e,t){var n,i;for(n=0,i=e.implicitTypes.length;n<i;n+=1)if(e.implicitTypes[n].resolve(t))return!0;return!1}(e,t)}),e.quotingType,e.forceQuotes&&!i,r)){case 1:return t;case 2:return"'"+t.replace(/'/g,"''")+"'";case 3:return"|"+fn(t,e.indent)+hn(nn(t,a));case 4:return">"+fn(t,e.indent)+hn(nn(function(e,t){var n,i,r=/(\n+)([^\n]*)/g,a=(s=e.indexOf("\n"),s=-1!==s?s:e.length,r.lastIndex=s,gn(e.slice(0,s),t)),o="\n"===e[0]||" "===e[0];var s;for(;i=r.exec(e);){var l=i[1],c=i[2];n=" "===c[0],a+=l+(o||n||""===c?"":"\n")+gn(c,t),o=n}return a}(t,o),a));case 5:return'"'+function(e){for(var t,n="",i=0,r=0;r<e.length;i>=65536?r+=2:r++)i=cn(e,r),!(t=Jt[i])&&on(i)?(n+=e[r],i>=65536&&(n+=e[r+1])):n+=t||en(i);return n}(t)+'"';default:throw new Oe("impossible error: invalid scalar style")}}()}function fn(e,t){var n=un(e)?String(t):"",i="\n"===e[e.length-1];return n+(i&&("\n"===e[e.length-2]||"\n"===e)?"+":i?"":"-")+"\n"}function hn(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function gn(e,t){if(""===e||" "===e[0])return e;for(var n,i,r=/ [^ ]/g,a=0,o=0,s=0,l="";n=r.exec(e);)(s=n.index)-a>t&&(i=o>a?o:s,l+="\n"+e.slice(a,i),a=i+1),o=s;return l+="\n",e.length-a>t&&o>a?l+=e.slice(a,o)+"\n"+e.slice(o+1):l+=e.slice(a),l.slice(1)}function mn(e,t,n,i){var r,a,o,s="",l=e.tag;for(r=0,a=n.length;r<a;r+=1)o=n[r],e.replacer&&(o=e.replacer.call(n,String(r),o)),(xn(e,t+1,o,!0,!0,!1,!0)||void 0===o&&xn(e,t+1,null,!0,!0,!1,!0))&&(i&&""===s||(s+=rn(e,t)),e.dump&&10===e.dump.charCodeAt(0)?s+="-":s+="- ",s+=e.dump);e.tag=l,e.dump=s||"[]"}function vn(e,t,n){var i,r,a,o,s,l;for(a=0,o=(r=n?e.explicitTypes:e.implicitTypes).length;a<o;a+=1)if(((s=r[a]).instanceOf||s.predicate)&&(!s.instanceOf||"object"==typeof t&&t instanceof s.instanceOf)&&(!s.predicate||s.predicate(t))){if(n?s.multi&&s.representName?e.tag=s.representName(t):e.tag=s.tag:e.tag="?",s.represent){if(l=e.styleMap[s.tag]||s.defaultStyle,"[object Function]"===Zt.call(s.represent))i=s.represent(t,l);else{if(!Yt.call(s.represent,l))throw new Oe("!<"+s.tag+'> tag resolver accepts not "'+l+'" style');i=s.represent[l](t,l)}e.dump=i}return!0}return!1}function xn(e,t,n,i,r,a,o){e.tag=null,e.dump=n,vn(e,n,!1)||vn(e,n,!0);var s,l=Zt.call(e.dump),c=i;i&&(i=e.flowLevel<0||e.flowLevel>t);var u,d,p="[object Object]"===l||"[object Array]"===l;if(p&&(d=-1!==(u=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||d||2!==e.indent&&t>0)&&(r=!1),d&&e.usedDuplicates[u])e.dump="*ref_"+u;else{if(p&&d&&!e.usedDuplicates[u]&&(e.usedDuplicates[u]=!0),"[object Object]"===l)i&&0!==Object.keys(e.dump).length?(!function(e,t,n,i){var r,a,o,s,l,c,u="",d=e.tag,p=Object.keys(n);if(!0===e.sortKeys)p.sort();else if("function"==typeof e.sortKeys)p.sort(e.sortKeys);else if(e.sortKeys)throw new Oe("sortKeys must be a boolean or a function");for(r=0,a=p.length;r<a;r+=1)c="",i&&""===u||(c+=rn(e,t)),s=n[o=p[r]],e.replacer&&(s=e.replacer.call(n,o,s)),xn(e,t+1,o,!0,!0,!0)&&((l=null!==e.tag&&"?"!==e.tag||e.dump&&e.dump.length>1024)&&(e.dump&&10===e.dump.charCodeAt(0)?c+="?":c+="? "),c+=e.dump,l&&(c+=rn(e,t)),xn(e,t+1,s,!0,l)&&(e.dump&&10===e.dump.charCodeAt(0)?c+=":":c+=": ",u+=c+=e.dump));e.tag=d,e.dump=u||"{}"}(e,t,e.dump,r),d&&(e.dump="&ref_"+u+e.dump)):(!function(e,t,n){var i,r,a,o,s,l="",c=e.tag,u=Object.keys(n);for(i=0,r=u.length;i<r;i+=1)s="",""!==l&&(s+=", "),e.condenseFlow&&(s+='"'),o=n[a=u[i]],e.replacer&&(o=e.replacer.call(n,a,o)),xn(e,t,a,!1,!1)&&(e.dump.length>1024&&(s+="? "),s+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),xn(e,t,o,!1,!1)&&(l+=s+=e.dump));e.tag=c,e.dump="{"+l+"}"}(e,t,e.dump),d&&(e.dump="&ref_"+u+" "+e.dump));else if("[object Array]"===l)i&&0!==e.dump.length?(e.noArrayIndent&&!o&&t>0?mn(e,t-1,e.dump,r):mn(e,t,e.dump,r),d&&(e.dump="&ref_"+u+e.dump)):(!function(e,t,n){var i,r,a,o="",s=e.tag;for(i=0,r=n.length;i<r;i+=1)a=n[i],e.replacer&&(a=e.replacer.call(n,String(i),a)),(xn(e,t,a,!1,!1)||void 0===a&&xn(e,t,null,!1,!1))&&(""!==o&&(o+=","+(e.condenseFlow?"":" ")),o+=e.dump);e.tag=s,e.dump="["+o+"]"}(e,t,e.dump),d&&(e.dump="&ref_"+u+" "+e.dump));else{if("[object String]"!==l){if("[object Undefined]"===l)return!1;if(e.skipInvalid)return!1;throw new Oe("unacceptable kind of an object to dump "+l)}"?"!==e.tag&&pn(e,e.dump,t,a,c)}null!==e.tag&&"?"!==e.tag&&(s=encodeURI("!"===e.tag[0]?e.tag.slice(1):e.tag).replace(/!/g,"%21"),s="!"===e.tag[0]?"!"+s:"tag:yaml.org,2002:"===s.slice(0,18)?"!!"+s.slice(18):"!<"+s+">",e.dump=s+" "+e.dump)}return!0}function bn(e,t){var n,i,r=[],a=[];for(yn(e,r,a),n=0,i=a.length;n<i;n+=1)t.duplicates.push(r[a[n]]);t.usedDuplicates=new Array(i)}function yn(e,t,n){var i,r,a;if(null!==e&&"object"==typeof e)if(-1!==(r=t.indexOf(e)))-1===n.indexOf(r)&&n.push(r);else if(t.push(e),Array.isArray(e))for(r=0,a=e.length;r<a;r+=1)yn(e[r],t,n);else for(r=0,a=(i=Object.keys(e)).length;r<a;r+=1)yn(e[i[r]],t,n)}function jn(e,t){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+t+" instead, which is now safe by default.")}}var wn=Bt.load,Cn={dump:function(e,t){var n=new tn(t=t||{});n.noRefs||bn(e,n);var i=e;return n.replacer&&(i=n.replacer.call({"":i},"",i)),xn(n,0,i,!0,!0)?n.dump+"\n":""}}.dump;jn("safeLoad","load"),jn("safeLoadAll","loadAll"),jn("safeDump","dump");var An,kn,In=n(87723),Sn=n(77609),On=n(83971),Rn=n(22583),Nn=n(38465),Tn=n(86647);const $n=[{label:"Yaml",value:"yaml"}],qn=e=>{let{onClose:t}=e;const[n,i]=(0,a.useState)("yaml"),{setValue:r}=(0,g.Gc)(),o=(0,c.wW)(Dn);return(0,M.jsx)(Sn.d,{title:"Inspect Alert rule",subtitle:(0,M.jsx)("div",{className:o.subtitle,children:(0,M.jsx)(Fn,{setActiveTab:i,activeTab:n})}),onClose:t,children:"yaml"===n&&(0,M.jsx)(En,{onSubmit:e=>{for(const t in e)r(t,e[t]);t()}})})},Fn=e=>{let{activeTab:t,setActiveTab:n}=e;return(0,M.jsx)(On.J,{children:$n.map(((e,i)=>(0,M.jsx)(Rn.O,{label:e.label,value:e.value,onChangeTab:()=>n(e.value),active:t===e.value},`${e.value}-${i}`)))})},En=e=>{let{onSubmit:t}=e;const n=(0,c.wW)(Ln),{getValues:i}=(0,g.Gc)(),r=(0,S.yh)(i()),[o,s]=(0,a.useState)(Cn(r));return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("div",{className:n.applyButton,children:[(0,M.jsx)(u.zx,{type:"button",onClick:()=>{const e=wn(o),n=i(),r=function(e){if((0,Tn.cG)(e))return(0,S.WL)(e);if((0,Tn.yF)(e))return(0,S.lN)(e);return{}}(e);t(Object.assign({},n,r))},children:"Apply"}),An||(An=(0,M.jsx)(G.u,{content:(0,M.jsx)(Mn,{}),theme:"info",placement:"left-start",interactive:!0,children:(0,M.jsx)(z.J,{name:"exclamation-triangle",size:"xl"})}))]}),(0,M.jsx)("div",{className:n.content,children:(0,M.jsx)(In.Z,{disableWidth:!0,children:e=>{let{height:t}=e;return(0,M.jsx)(Nn.p,{width:"100%",height:t,language:"yaml",value:o,onBlur:s,monacoOptions:{minimap:{enabled:!1}}})}})})]})};function Mn(){return kn||(kn=(0,M.jsxs)("div",{children:["The YAML content in the editor only contains alert rule configuration ",(0,M.jsx)("br",{}),"To configure Prometheus, you need to provide the rest of the"," ",(0,M.jsx)("a",{href:"https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/",target:"_blank",rel:"noreferrer",children:"configuration file content."})]}))}const Ln=e=>({content:r.css`
    flex-grow: 1;
    height: 100%;
    padding-bottom: 16px;
    margin-bottom: ${e.spacing(2)};
  `,applyButton:r.css`
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-grow: 0;
    margin-bottom: ${e.spacing(2)};
  `}),Dn=()=>({subtitle:r.css`
    display: flex;
    align-items: center;
    justify-content: space-between;
  `});var Qn=n(82897),_n=n(10829),Wn=n(86551);const Pn=["onChange","ref"];var Un,Gn;const zn=e=>{var t,n;let{existing:i=!1}=e;const{watch:r,setValue:o,formState:{errors:s}}=(0,g.Gc)(),u=r("queries"),d=r("condition"),p=(0,a.useMemo)((()=>u.filter((e=>e.datasourceUid===Wn.Yq))),[u]),f=(0,a.useMemo)((()=>u.filter((e=>!!e.refId)).map((e=>({value:e.refId,label:`${e.refId} - ${p.includes(e)?"expression":"query"}`})))),[u,p]);(0,a.useEffect)((()=>{const e=(0,Qn.last)(p);e&&!i&&o("condition",e.refId,{shouldValidate:!0})}),[p,o,i]),(0,a.useEffect)((()=>{const e=(0,Qn.last)(p),t=f.find((e=>{let{value:t}=e;return t===d}));var n;d&&!t?o("condition",null!==(n=null==e?void 0:e.refId)&&void 0!==n?n:null):!d&&e&&o("condition",e.refId,{shouldValidate:!0})}),[d,p,f,o]);const h=(0,c.wW)(Vn);return f.length?(0,M.jsxs)(be.Z,{className:h.container,children:[Un||(Un=(0,M.jsx)(be.Z.Heading,{children:"Set alert condition"})),Gn||(Gn=(0,M.jsx)(be.Z.Meta,{children:"Select one of your queries or expressions set above that contains your alert condition."})),(0,M.jsx)(be.Z.Actions,{children:(0,M.jsx)(R.g,{error:null===(t=s.condition)||void 0===t?void 0:t.message,invalid:!(null===(n=s.condition)||void 0===n||!n.message),children:(0,M.jsx)(T.g,{name:"condition",render:e=>{let{field:{onChange:t}}=e,n=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,Pn);return(0,M.jsx)(_n.x,Object.assign({options:f,onChange:t},n))},rules:{required:{value:!0,message:"Please select the condition to alert on"}}})})})]}):(0,M.jsx)(l.b,{title:"No queries or expressions have been configured",severity:"warning",className:h.container,children:"Create at least one query or expression to be alerted on"})},Vn=e=>({container:r.css`
    max-width: ${e.breakpoints.values.sm}px;
  `});var Bn=n(63672),Zn=n(19462);function Yn(){const e=(0,C._)((e=>e.dataSources));return Object.values(e).map((e=>e.result)).filter((e=>Boolean(null==e?void 0:e.rulerConfig))).map((e=>(0,Zn.c$)(e.name))).filter((e=>Boolean(e)))}const Kn=["value"];function Jn(e){let{value:t}=e,n=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,Kn);const i=Yn(),r=(0,a.useCallback)((e=>!!i.find((t=>{let{id:n}=t;return n===e.id}))),[i]);return(0,M.jsx)(Bn.q,Object.assign({noDefault:!0,alerting:!0,filter:r,current:t},n))}const Hn=e=>{const{name:t,description:n,image:i,selected:a=!1,value:o,onClick:s,disabled:l=!1}=e,u=(0,c.wW)(Xn),d=(0,r.cx)({[u.wrapper]:!0,[u.disabled]:l});return(0,M.jsxs)(be.Z,{className:d,isSelected:a,onClick:()=>s(o),disabled:l,children:[(0,M.jsx)(be.Z.Figure,{children:(0,M.jsx)("img",{src:i})}),(0,M.jsx)(be.Z.Heading,{children:t}),(0,M.jsx)(be.Z.Description,{children:n})]})},Xn=e=>({wrapper:r.css`
    width: 380px;
    cursor: pointer;
    user-select: none;
  `,disabled:r.css`
    opacity: 0.5;
  `});var ei;const ti=e=>{let{selected:t=!1,disabled:n,onClick:i}=e;return(0,M.jsx)(Hn,{name:"Grafana managed alert",description:ei||(ei=(0,M.jsxs)("span",{children:["Supports multiple data sources of any kind.",(0,M.jsx)("br",{}),"Transform data with expressions."]})),image:"public/img/grafana_icon.svg",selected:t,disabled:n,value:k.$.grafana,onClick:i})},ni=e=>{let{children:t,visible:n=!1}=e;return n?(0,M.jsx)(G.u,{content:"You do not appear to have any compatible datasources.",placement:"top",children:(0,M.jsx)("div",{children:t})}):(0,M.jsx)(M.Fragment,{children:t})};var ii;const ri=e=>{let{selected:t=!1,disabled:n=!1,onClick:i}=e;return(0,M.jsx)(ni,{visible:n,children:(0,M.jsx)(Hn,{name:"Mimir or Loki alert",description:ii||(ii=(0,M.jsxs)("span",{children:["Use a Mimir, Loki or Cortex datasource.",(0,M.jsx)("br",{}),"Expressions are not supported."]})),image:"public/img/alerting/mimir_logo.svg",selected:t,disabled:n,value:k.$.cloudAlerting,onClick:i})})};var ai;const oi=e=>{let{selected:t=!1,disabled:n=!1,onClick:i}=e;return(0,M.jsx)(ni,{visible:n,children:(0,M.jsx)(Hn,{name:"Mimir or Loki recording rule",description:ai||(ai=(0,M.jsxs)("span",{children:["Precompute expressions.",(0,M.jsx)("br",{}),"Should be combined with an alert rule."]})),image:"public/img/alerting/mimir_logo_recording.svg",selected:t,disabled:n,value:k.$.cloudRecording,onClick:i})})},si=e=>{let{selected:t,onChange:n,enabledTypes:i}=e;const r=Yn(),a=!(0,Qn.isEmpty)(r),o=(0,c.wW)(li);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(U.K,{direction:"row",gap:2,children:[i.includes(k.$.grafana)&&(0,M.jsx)(ti,{selected:t===k.$.grafana,onClick:n}),i.includes(k.$.cloudAlerting)&&(0,M.jsx)(ri,{selected:t===k.$.cloudAlerting,onClick:n,disabled:!a}),i.includes(k.$.cloudRecording)&&(0,M.jsx)(oi,{selected:t===k.$.cloudRecording,onClick:n,disabled:!a})]}),i.includes(k.$.grafana)&&(0,M.jsx)("small",{className:o.meta,children:"Select “Grafana managed” unless you have a Mimir, Loki or Cortex data source with the Ruler API enabled."})]})},li=e=>({meta:r.css`
    color: ${e.colors.text.disabled};
  `}),ci=["onChange","ref"];const ui=e=>{var t,n,i,r;let{editingExistingRule:a}=e;const{enabledRuleTypes:o,defaultRuleType:s}=function(){const e=V.Vt.hasAccess(h.bW.AlertingRuleCreate,V.Vt.hasEditPermissionInFolders),t=V.Vt.hasAccess(h.bW.AlertingRuleExternalWrite,V.Vt.isEditor),n=e?k.$.grafana:k.$.cloudAlerting,i=[];e&&i.push(k.$.grafana);t&&i.push(k.$.cloudAlerting,k.$.cloudRecording);return{enabledRuleTypes:i,defaultRuleType:n}}(),{control:l,formState:{errors:u},getValues:d,setValue:p,watch:f}=(0,g.Gc)(),m=(0,c.wW)(di),v=f("type");return(0,M.jsxs)(M.Fragment,{children:[!a&&(0,M.jsx)(R.g,{error:null===(t=u.type)||void 0===t?void 0:t.message,invalid:!(null===(n=u.type)||void 0===n||!n.message),"data-testid":"alert-type-picker",children:(0,M.jsx)(T.g,{render:e=>{var t;let{field:{onChange:n}}=e;return(0,M.jsx)(si,{"aria-label":"Rule type",selected:null!==(t=d("type"))&&void 0!==t?t:s,onChange:n,enabledTypes:o})},name:"type",control:l,rules:{required:{value:!0,message:"Please select alert type"}}})}),(0,M.jsx)("div",{className:m.flexRow,children:(v===k.$.cloudRecording||v===k.$.cloudAlerting)&&(0,M.jsx)(R.g,{className:m.formInput,label:"Select data source",error:null===(i=u.dataSourceName)||void 0===i?void 0:i.message,invalid:!(null===(r=u.dataSourceName)||void 0===r||!r.message),"data-testid":"datasource-picker",children:(0,M.jsx)(T.g,{render:e=>{let{field:{onChange:t}}=e,n=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,ci);return(0,M.jsx)(Jn,Object.assign({},n,{onChange:e=>{var n;p("location",void 0),t(null!==(n=null==e?void 0:e.name)&&void 0!==n?n:null)}}))},name:"dataSourceName",control:l,rules:{required:{value:!0,message:"Please select a data source"}}})})})]})};const di=e=>({formInput:r.css`
    width: 330px;
    & + & {
      margin-left: ${e.spacing(3)};
    }
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-end;
  `});var pi=n(5937),fi=n(38536),hi=n(7501),gi=n(58760);var mi,vi,xi,bi=n(69357),yi=n(51542);function ji(e){let{preview:t}=e;const n=(0,c.wW)(wi),i=function(e){var t,n;let{fields:i}=e;const r=i.filter((e=>!["State","Info"].includes(e.name))),a=i.findIndex((e=>"State"===e.name)),o=i.findIndex((e=>"Info"===e.name)),s=r.map((e=>i.indexOf(e))),l=null!==(t=null===(n=i[a])||void 0===n?void 0:n.values.length)&&void 0!==t?t:0,c=[];for(let e=0;e<l;e++){var u,d,p,f;const t=s.map((t=>[i[t].name,i[t].values.get(e)])),n=null===(u=i[a])||void 0===u||null===(d=u.values)||void 0===d?void 0:d.get(e),r=null===(p=i[o])||void 0===p||null===(f=p.values)||void 0===f?void 0:f.get(e);(0,yi.Yb)(n)&&c.push({state:n,info:r,labels:Object.fromEntries(t)})}return{instances:c}}(t);return(0,M.jsxs)("table",{className:n.table,children:[mi||(mi=(0,M.jsxs)("caption",{children:[(0,M.jsx)("div",{children:"Alerts preview"}),(0,M.jsx)("span",{children:"Preview based on the result of running the query for this moment."})]})),vi||(vi=(0,M.jsx)("thead",{children:(0,M.jsxs)("tr",{children:[(0,M.jsx)("th",{children:"State"}),(0,M.jsx)("th",{children:"Labels"}),(0,M.jsx)("th",{children:"Info"})]})})),(0,M.jsx)("tbody",{children:i.instances.map(((e,t)=>{let{state:i,info:r,labels:a}=e;const o=function(e){return Object.entries(e).map((e=>{let[t,n]=e;return`${t}=${n}`})).sort()}(a);return(0,M.jsxs)("tr",{children:[(0,M.jsx)("td",{children:(0,M.jsx)(bi.l,{state:i})}),(0,M.jsx)("td",{children:(0,M.jsx)(gi.P,{tags:o,className:n.tagList})}),(0,M.jsx)("td",{children:r&&(0,M.jsx)(G.u,{content:r,children:xi||(xi=(0,M.jsx)(z.J,{name:"info-circle"}))})})]},t)}))})]})}const wi=e=>({table:r.css`
    width: 100%;
    margin: ${e.spacing(2,0)};

    caption {
      caption-side: top;
      color: ${e.colors.text.primary};

      & > span {
        font-size: ${e.typography.bodySmall.fontSize};
        color: ${e.colors.text.secondary};
      }
    }

    td,
    th {
      padding: ${e.spacing(1,1)};
    }

    td + td,
    th + th {
      padding-left: ${e.spacing(3)};
    }

    thead th {
      &:nth-child(1) {
        width: 80px;
      }

      &:nth-child(2) {
        width: auto;
      }

      &:nth-child(3) {
        width: 40px;
      }
    }

    td:nth-child(3) {
      text-align: center;
    }

    tbody tr:nth-child(2n + 1) {
      background-color: ${e.colors.background.secondary};
    }
  `,tagList:r.css`
    justify-content: flex-start;
  `}),Ci=e=>{var t,n,i,r;let{value:s,onChange:d,dataSourceName:p}=e;const f=(0,c.wW)(Ai),{mapToValue:h,mapToQuery:g}=function(e){return(0,a.useMemo)((()=>{const t=(0,hi.F)().getInstanceSettings(e);switch(null==t?void 0:t.type){case"loki":case"prometheus":return{mapToValue:e=>e.expr,mapToQuery:(e,t)=>Object.assign({},e,{expr:t})};default:throw new Error(`${e} is not supported as an expression editor`)}}),[e])}(p),m=g({refId:"A",hide:!1},s),{error:v,loading:x,value:b}=(0,o.Z)((()=>(0,hi.F)().get(p)),[p]),y=(0,a.useCallback)((e=>{d(h(e))}),[d,h]),[j,w]=(0,F.u)();if(x||(null==b?void 0:b.name)!==p)return null;if(v||!b||null==b||null===(t=b.components)||void 0===t||!t.QueryEditor){const e=(null==v?void 0:v.message)||"Data source plugin does not export any Query Editor component";return(0,M.jsxs)("div",{children:["Could not load query editor due to: ",e]})}const C=(null==j?void 0:j.data.state)===pi.Gu.Done,A=null==b||null===(n=b.components)||void 0===n?void 0:n.QueryEditor,k=null==j||null===(i=j.data)||void 0===i||null===(r=i.series)||void 0===r?void 0:r.find((e=>"evaluation results"===e.name)),I=k&&k.fields.some((e=>e.values.length>0));return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(A,{query:m,queries:[m],app:fi.zj.CloudAlerting,onChange:y,onRunQuery:Qn.noop,datasource:b}),(0,M.jsxs)("div",{className:f.preview,children:[(0,M.jsx)(u.zx,{type:"button",onClick:async()=>{w()},disabled:(null==j?void 0:j.data.state)===pi.Gu.Loading,children:"Preview alerts"}),C&&!I&&(0,M.jsx)(l.b,{title:"Alerts preview",severity:"info",className:f.previewAlert,children:"There are no firing alerts for your query."}),I&&(0,M.jsx)(ji,{preview:k})]})]})},Ai=e=>({preview:r.css`
    padding: ${e.spacing(2,0)};
    max-width: ${e.breakpoints.values.xl}px;
  `,previewAlert:r.css`
    margin: ${e.spacing(1,0)};
  `});var ki=n(75414),Ii=n(68694),Si=n(48147),Oi=n(25049),Ri=n(40882),Ni=n(65184),Ti=n(22912),$i=n(95450),qi=n(20910),Fi=n(99464),Ei=n(47837),Mi=n(71623);const Li=(e,t)=>{if((e=>{try{return JSON.stringify(e),!1}catch(e){return!0}})(e))return null;if(t.datasourceUid!==Wn.Yq)return t;{const n=e.find((e=>e.refId===t.model.expression));return n?Li(e,n):null}};var Di=n(67436),Qi=n(68896),_i=n(359),Wi=n(85464),Pi=n(4293),Ui=n(23357),Gi=n(14877),zi=n(5831);var Vi=n(95910);const Bi=e=>{let{data:t,currentPanel:n,changePanel:i,onThresholdsChange:r,thresholds:o}=e;const[s,l]=(0,a.useState)({frameIndex:0,showHeader:!0}),u=function(e,t,n){const i=(0,c.l4)();if(t===Wi.GC||t===Wi.Kd||function(e){return!(e&&e.series[0]&&e.series[0].fields[0]&&e.series[0].fields[0].values)}(e))return 200;const r=e.series[n].fields[0].values.length,a=5*i.spacing.gridSize,o=r*a+a;return o>=200?200:o}(t,n,s.frameIndex),d=(0,c.wW)(Zi(u)),[p,f]=(0,a.useState)(function(e,t){if(!e)return{defaults:{},overrides:[]};return{defaults:{thresholds:e,unit:Yi(t),custom:{thresholdsStyle:{mode:Ui.i3.Line}}},overrides:[]}}(o,t));(0,a.useEffect)((()=>{f((e=>Object.assign({},e,{defaults:Object.assign({},e.defaults,{thresholds:o,unit:Yi(t),custom:Object.assign({},e.defaults.custom,{thresholdsStyle:{mode:Ui.i3.Line}})})})))}),[o,f,t]);const h=(0,a.useMemo)((()=>({eventBus:zi.Z,canEditThresholds:!0,onThresholdsChange:r})),[r]);return s&&t?(0,M.jsxs)("div",{className:d.wrapper,children:[(0,M.jsx)("div",{className:d.buttonGroup,children:(0,M.jsx)(Vi.j,{onChange:i,value:n})}),(0,M.jsx)(In.Z,{children:e=>{let{width:i}=e;return 0===i?null:(0,M.jsx)("div",{style:{height:`${u}px`,width:`${i}px`},children:(0,M.jsx)(Gi._w,{value:h,children:(0,M.jsx)(Pi.$,{height:u,width:i,data:t,pluginId:n,title:"title",onOptionsChange:l,options:s,fieldConfig:p})})})}})]}):null},Zi=e=>t=>({wrapper:r.css`
    padding: 0 ${t.spacing(2)};
    height: ${e+4*t.spacing.gridSize}px;
  `,buttonGroup:r.css`
    display: flex;
    justify-content: flex-end;
  `});function Yi(e){var t,n;return null===(t=e.series[0])||void 0===t||null===(n=t.fields.find((e=>"number"===e.type)))||void 0===n?void 0:n.config.unit}const Ki=e=>{var t,n;let{data:i,dsSettings:r,index:o,onChangeDataSource:s,onChangeQuery:l,onChangeTimeRange:u,onRunQueries:d,onRemoveQuery:p,onDuplicateQuery:f,query:h,queries:g,thresholds:m,onChangeThreshold:v}=e;const x=(0,c.wW)(Hi),b=(0,Y.j)(h.model),[y,j]=(0,a.useState)(b?Wi.Fe:Wi.GC);function w(){const e=(0,c.wW)(Hi);return(0,M.jsx)("div",{className:e.dsTooltip,children:(0,M.jsx)(G.u,{content:(0,M.jsx)(M.Fragment,{children:"Not finding the data source you want? Some data sources are not supported for alerting. Click on the icon for more information."}),children:(0,M.jsx)(z.J,{name:"info-circle",onClick:()=>window.open(" https://grafana.com/docs/grafana/latest/alerting/fundamentals/data-source-alerting/","_blank")})})})}function C(e){let{query:n,index:i}=e;return(0,Y.j)(n.model)?null:(0,M.jsxs)(M.Fragment,{children:[t||(t=(0,M.jsx)(w,{})),u&&(0,M.jsx)(Qi.x,{timeRange:null!==(r=n.relativeTimeRange)&&void 0!==r?r:(0,ki.Rr)(),onChange:e=>u(e,i)})]});var r}return(0,M.jsx)("div",{className:x.wrapper,children:(0,M.jsx)(_i.x,{alerting:!0,dataSource:r,onChangeDataSource:b?void 0:e=>s(e,o),id:h.refId,index:o,data:i,query:(0,Qn.cloneDeep)(h.model),onChange:e=>l(e,o),onRemoveQuery:p,onAddQuery:()=>f((0,Qn.cloneDeep)(h)),onRunQuery:d,queries:g,renderHeaderExtras:()=>n||(n=(0,M.jsx)(C,{query:h,index:o})),app:fi.zj.UnifiedAlerting,visualization:i.state!==pi.Gu.NotStarted?(0,M.jsx)(Bi,{data:i,changePanel:j,currentPanel:y,thresholds:m,onThresholdsChange:e=>v(e,o)}):null,hideDisableQuery:!0},h.refId)})},Ji=e=>{let{children:t}=e;const n=(0,c.wW)(Hi);return(0,M.jsx)("div",{className:n.wrapper,children:t})},Hi=e=>({wrapper:r.css`
    label: AlertingQueryWrapper;
    margin-bottom: ${e.spacing(1)};
    border: 1px solid ${e.colors.border.medium};
    border-radius: ${e.shape.borderRadius(1)};
  `,dsTooltip:r.css`
    display: flex;
    align-items: center;
    margin-right: ${e.spacing(2)};
    &:hover {
      opacity: 0.85;
      cursor: pointer;
    }
  `});var Xi,er,tr;function nr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class ir extends a.PureComponent{constructor(e){super(e),nr(this,"onRemoveQuery",(e=>{this.props.onQueriesChange(this.props.queries.filter((t=>t.model.refId!==e.refId)))})),nr(this,"onChangeTimeRange",((e,t)=>{const{queries:n,onQueriesChange:i}=this.props;i(n.map(((i,r)=>{if(r!==t){if(i.datasourceUid===Wn.Yq){var a;const r=this.findDataSourceFromExpression(n,i.model.expression),o=(null==r?void 0:r.datasourceUid)===n[t].datasourceUid?e:null!==(a=null==r?void 0:r.relativeTimeRange)&&void 0!==a?a:(0,ki.Rr)();return Object.assign({},i,{relativeTimeRange:o})}return i}return Object.assign({},i,{relativeTimeRange:e})})))})),nr(this,"onChangeThreshold",((e,t)=>{const{queries:n,onQueriesChange:i}=this.props,r=n[t].refId;i(n.map((t=>(0,Y.j)(t.model)&&t.model.conditions&&t.model.conditions[0].query.params[0]===r?Object.assign({},t,{model:Object.assign({},t.model,{conditions:t.model.conditions.map(((t,n)=>t.query.params[0]===r&&0===n?Object.assign({},t,{evaluator:Object.assign({},t.evaluator,{params:[parseFloat(e.steps[1].value.toPrecision(3))]})}):t))})}):t)))})),nr(this,"onChangeDataSource",((e,t)=>{const{queries:n,onQueriesChange:i}=this.props;i(n.map(((n,i)=>i!==t?n:function(e,t){return Object.assign({},e,{model:(0,Qn.omit)(e.model,"datasource"),datasourceUid:t})}(n,e.uid))))})),nr(this,"onChangeQuery",((e,t)=>{const{queries:n,onQueriesChange:i}=this.props,r=n[t].refId,a=e.refId;i(function(e,t,n){return e.map((e=>{if(t===n)return e;if(!(0,Y.j)(e.model))return e;const i="math"===e.model.type,r="reduce"===e.model.type,a="resample"===e.model.type,o="classic_conditions"===e.model.type;var s;if(i)return Object.assign({},e,{model:Object.assign({},e.model,{expression:K(null!==(s=e.model.expression)&&void 0!==s?s:"",t,n)})});if(a||r){const i=e.model.expression===t;return Object.assign({},e,{model:Object.assign({},e.model,{expression:i?n:e.model.expression})})}if(o){var l;const i=null===(l=e.model.conditions)||void 0===l?void 0:l.map((e=>Object.assign({},e,{query:Object.assign({},e.query,{params:e.query.params.map((e=>e===t?n:e))})})));return Object.assign({},e,{model:Object.assign({},e.model,{conditions:i})})}return e}))}(n,r,a).map(((i,r)=>{var a;if(r!==t)return i;const o=this.findDataSourceFromExpression(n,i.refId),s=o?o.relativeTimeRange:(0,ki.Rr)();return Object.assign({},i,{refId:e.refId,queryType:null!==(a=i.model.queryType)&&void 0!==a?a:"",model:Object.assign({},i.model,e,{datasource:e.datasource}),relativeTimeRange:s})})))})),nr(this,"onDragEnd",(e=>{const{queries:t,onQueriesChange:n}=this.props;if(!e||!e.destination)return;const i=e.source.index,r=e.destination.index;if(i===r)return;const a=Array.from(t),[o]=a.splice(i,1);a.splice(r,0,o),n(a)})),nr(this,"onDuplicateQuery",((e,t)=>{this.props.onDuplicateQuery(Object.assign({},t,{model:e}))})),nr(this,"getDataSourceSettings",(e=>(0,hi.F)().getInstanceSettings(e.datasourceUid))),nr(this,"getThresholdsForQueries",(e=>{const t={};for(const n of e)(0,Y.j)(n.model)&&Array.isArray(n.model.conditions)&&n.model.conditions.forEach(((e,n)=>{if(n>0)return;const i=e.evaluator.params[0],r=e.query.params[0];"outside_range"!==e.evaluator.type&&"within_range"!==e.evaluator.type&&(t[r]||(t[r]={mode:Ei.H.Absolute,steps:[{value:-1/0,color:Si.v.theme2.colors.success.main}]}),t[r].steps.push({value:i,color:Si.v.theme2.colors.error.main}))}));return t})),this.state={dataPerQuery:{}}}findDataSourceFromExpression(e,t){const n=e.find((e=>e.refId===t));return n&&Li(e,n)}render(){const{onDuplicateQuery:e,onRunQueries:t,queries:n}=this.props,i=this.getThresholdsForQueries(n);return(0,M.jsx)(Fi.Z5,{onDragEnd:this.onDragEnd,children:(0,M.jsx)(Fi.bK,{droppableId:"alerting-queries",direction:"vertical",children:r=>(0,M.jsxs)("div",Object.assign({ref:r.innerRef},r.droppableProps,{children:[n.map(((r,a)=>{var o,s;const l=null!==(o=null===(s=this.props.data)||void 0===s?void 0:s[r.refId])&&void 0!==o?o:{series:[],state:pi.Gu.NotStarted},c=this.getDataSourceSettings(r);return c?(0,M.jsx)(Ki,{index:a,dsSettings:c,data:l,query:r,onChangeQuery:this.onChangeQuery,onRemoveQuery:this.onRemoveQuery,queries:n,onChangeDataSource:this.onChangeDataSource,onDuplicateQuery:e,onRunQueries:t,onChangeTimeRange:this.onChangeTimeRange,thresholds:i[r.refId],onChangeThreshold:this.onChangeThreshold},r.refId):(0,M.jsx)(rr,{index:a,model:r.model,onUpdateDatasource:()=>{const e=(0,Di.ak)().getInstanceSettings(null);e&&this.onChangeDataSource(e,a)},onRemoveQuery:()=>{this.onRemoveQuery(r)}},`${r.refId}-${a}`)})),r.placeholder]}))})})}}const rr=e=>{let{index:t,onUpdateDatasource:n,onRemoveQuery:i,model:r}=e;const o=r.refId,[s,l]=(0,a.useState)(!1);return(0,M.jsx)(Ji,{children:(0,M.jsxs)(Mi.t,{title:o,draggable:!0,index:t,id:o,isOpen:!0,children:[(0,M.jsxs)(be.Z,{children:[Xi||(Xi=(0,M.jsx)(be.Z.Heading,{children:"This datasource has been removed"})),er||(er=(0,M.jsx)(be.Z.Description,{children:"The datasource for this query was not found, it was either removed or is not installed correctly."})),tr||(tr=(0,M.jsx)(be.Z.Figure,{children:(0,M.jsx)(z.J,{name:"question-circle"})})),(0,M.jsxs)(be.Z.Actions,{children:[(0,M.jsx)(u.zx,{variant:"secondary",onClick:()=>{n()},children:"Update datasource"},"update"),(0,M.jsx)(u.zx,{variant:"destructive",onClick:i,children:"Remove query"},"remove")]}),(0,M.jsx)(be.Z.SecondaryActions,{children:(0,M.jsx)(u.zx,{onClick:()=>{l((e=>!e))},icon:s?"angle-up":"angle-down",fill:"text",size:"sm",children:"Show details"},"details")})]}),s&&(0,M.jsx)("div",{children:(0,M.jsx)("pre",{children:(0,M.jsx)("code",{children:JSON.stringify(r,null,2)})})})]})})};function ar(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class or extends a.PureComponent{constructor(e){var t;super(e),ar(this,"runner",void 0),ar(this,"queries",void 0),ar(this,"onRunQueries",(()=>{const{queries:e}=this;this.runner.run(e)})),ar(this,"onCancelQueries",(()=>{this.runner.cancel()})),ar(this,"onChangeQueries",(e=>{this.queries=e,this.props.onChange(e)})),ar(this,"onDuplicateQuery",(e=>{const{queries:t}=this;this.onChangeQueries(sr(t,e))})),ar(this,"onNewAlertingQuery",(()=>{const{queries:e}=this,t=(0,Zn.P)();t&&this.onChangeQueries(sr(e,{datasourceUid:t.uid,model:{refId:"",datasource:{type:t.type,uid:t.uid}}}))})),ar(this,"onNewExpressionQuery",(()=>{const{queries:e}=this,t=e.at(-1),n=t?[t.refId]:[];this.onChangeQueries(sr(e,{datasourceUid:Wn.Yq,model:Wn.mV.newQuery({type:Ti.Us.classic,conditions:[Object.assign({},$i.R,{query:{params:n}})],expression:null==t?void 0:t.refId})}))})),this.state={panelDataByRefId:{}},this.runner=new qi.v,this.queries=null!==(t=e.value)&&void 0!==t?t:[]}componentDidMount(){this.runner.get().subscribe((e=>{this.setState({panelDataByRefId:e})}))}componentWillUnmount(){this.runner.destroy()}isRunning(){const e=Object.values(this.state.panelDataByRefId).find((e=>Boolean(e)));return(null==e?void 0:e.state)===pi.Gu.Loading}renderRunQueryButton(){return this.isRunning()?(0,M.jsx)(u.zx,{icon:"fa fa-spinner",type:"button",variant:"destructive",onClick:this.onCancelQueries,children:"Cancel"}):(0,M.jsx)(u.zx,{icon:"sync",type:"button",onClick:this.onRunQueries,children:"Run queries"})}render(){const{value:e=[]}=this.props,{panelDataByRefId:t}=this.state,n=cr(Si.v.theme2),i=void 0===(0,Zn.P)();return(0,M.jsxs)("div",{className:n.container,children:[(0,M.jsx)(ir,{data:t,queries:e,onQueriesChange:this.onChangeQueries,onDuplicateQuery:this.onDuplicateQuery,onRunQueries:this.onRunQueries}),(0,M.jsxs)(Oi.Lh,{spacing:"sm",align:"flex-start",children:[(0,M.jsx)(G.u,{content:"You appear to have no compatible data sources",show:i,children:(0,M.jsx)(u.zx,{type:"button",icon:"plus",onClick:this.onNewAlertingQuery,variant:"secondary","aria-label":Ii.wl.components.QueryTab.addQuery,disabled:i,children:"Add query"})}),Si.v.expressionsEnabled&&(0,M.jsx)(u.zx,{type:"button",icon:"plus",onClick:this.onNewExpressionQuery,variant:"secondary",children:"Add expression"}),this.renderRunQueryButton()]})]})}}const sr=(e,t)=>{const n=(0,Ni.Hs)(e),i=Object.assign({},t,{refId:n,queryType:"",model:Object.assign({},t.model,{hide:!1,refId:n}),relativeTimeRange:t.relativeTimeRange||lr(t.model)});return[...e,i]},lr=e=>{if(!(0,Y.j)(e))return(0,ki.Rr)()},cr=(0,Ri.B)((e=>({container:r.css`
      background-color: ${e.colors.background.primary};
      height: 100%;
      max-width: ${e.breakpoints.values.xxl}px;
    `,runWrapper:r.css`
      margin-top: ${e.spacing(1)};
    `,editorWrapper:r.css`
      border: 1px solid ${e.colors.border.medium};
      border-radius: ${e.shape.borderRadius()};
    `}))),ur=["ref"],dr=["ref"];function pr(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}const fr=()=>{var e,t;const{control:n,watch:i,formState:{errors:r}}=(0,g.Gc)(),[a,o]=i(["type","dataSourceName"]),s=a===k.$.grafana,l=a===k.$.cloudAlerting,c=(a===k.$.cloudRecording||l)&&o;return(0,M.jsxs)("div",{children:[c&&(0,M.jsx)(R.g,{error:null===(e=r.expression)||void 0===e?void 0:e.message,invalid:!(null===(t=r.expression)||void 0===t||!t.message),children:(0,M.jsx)(T.g,{name:"expression",render:e=>{let{}=e,t=pr(e.field,ur);return(0,M.jsx)(Ci,Object.assign({},t,{dataSourceName:o}))},control:n,rules:{required:{value:!0,message:"A valid expression is required"}}})}),s&&(0,M.jsx)(R.g,{invalid:!!r.queries,error:!r.queries?void 0:"Must provide at least one valid query.",children:(0,M.jsx)(T.g,{name:"queries",render:e=>{let{}=e,t=pr(e.field,dr);return(0,M.jsx)(or,Object.assign({},t))},control:n,rules:{validate:e=>Array.isArray(e)&&!!e.length}})})]})};var hr;const gr=e=>{let{editingExistingRule:t}=e;const{watch:n}=(0,g.Gc)(),i=n("type"),r=i===k.$.grafana;return(0,M.jsxs)(E.z,{stepNo:1,title:"Set a query and alert condition",children:[(0,M.jsx)(ui,{editingExistingRule:t}),i&&(hr||(hr=(0,M.jsx)(fr,{}))),r&&(0,M.jsx)(zn,{existing:t})]})};var mr,vr,xr;const br=e=>{var t;let{existing:n}=e;const i=(0,c.wW)(jr),r=(0,h.I0)(),o=(0,j.iG)(),[s]=(0,w.K)(),[l,d]=(0,a.useState)(!1),p=null!==(t=s.returnTo)&&void 0!==t?t:"/alerting/list",[R,N]=(0,a.useState)(!1),T=(0,a.useMemo)((()=>n?(0,S.DQ)(n):Object.assign({},(0,S.uZ)(),{queries:(0,S.s0)()},s.defaults?JSON.parse(s.defaults):{},{type:k.$.grafana})),[n,s]),$=(0,g.cI)({mode:"onSubmit",defaultValues:T,shouldFocusError:!0}),{handleSubmit:q,watch:F}=$,E=F("type"),L=F("dataSourceName"),Q=Boolean(E&&(E===k.$.grafana||!!L)),_=(0,C._)((e=>e.ruleForm.saveRule))||I.oq;(0,f.x)((e=>e.unifiedAlerting.ruleForm.saveRule=I.oq));const W=(e,t)=>{var i,a,o,s;r((0,A.wy)({values:Object.assign({},T,e,{annotations:null!==(i=null===(a=e.annotations)||void 0===a?void 0:a.map((e=>{let{key:t,value:n}=e;return{key:t.trim(),value:n.trim()}})).filter((e=>{let{key:t,value:n}=e;return!!t&&!!n})))&&void 0!==i?i:[],labels:null!==(o=null===(s=e.labels)||void 0===s?void 0:s.map((e=>{let{key:t,value:n}=e;return{key:t.trim(),value:n.trim()}})).filter((e=>{let{key:t}=e;return!!t})))&&void 0!==o?o:[]}),existing:n,redirectOnSave:t?p:void 0}))},P=()=>{o.error("There are errors in the form. Please correct them and try again!")};return(0,M.jsxs)(g.RV,Object.assign({},$,{children:[(0,M.jsxs)("form",{onSubmit:e=>e.preventDefault(),className:i.form,children:[(0,M.jsxs)(v.X,{title:(n?"Edit":"Create")+" alert rule",pageIcon:"bell",children:[(0,M.jsx)(m.Link,{to:p,children:(0,M.jsx)(u.zx,{variant:"secondary",disabled:_.loading,type:"button",fill:"outline",children:"Cancel"})}),n?(0,M.jsx)(u.zx,{variant:"destructive",type:"button",onClick:()=>N(!0),children:"Delete"}):null,yr(F)&&(0,M.jsx)(u.zx,{variant:"secondary",type:"button",onClick:()=>d(!0),disabled:_.loading,children:"Edit yaml"}),(0,M.jsxs)(u.zx,{variant:"primary",type:"button",onClick:q((e=>W(e,!1)),P),disabled:_.loading,children:[_.loading&&(0,M.jsx)(x.$,{className:i.buttonSpinner,inline:!0}),"Save"]}),(0,M.jsxs)(u.zx,{variant:"primary",type:"button",onClick:q((e=>W(e,!0)),P),disabled:_.loading,children:[_.loading&&(0,M.jsx)(x.$,{className:i.buttonSpinner,inline:!0}),"Save and exit"]})]}),(0,M.jsx)("div",{className:i.contentOuter,children:(0,M.jsx)(b.$,{autoHeightMin:"100%",hideHorizontalTrack:!0,children:(0,M.jsxs)("div",{className:i.contentInner,children:[(0,M.jsx)(gr,{editingExistingRule:!!n}),Q&&(0,M.jsxs)(M.Fragment,{children:[E===k.$.grafana?mr||(mr=(0,M.jsx)(xe.wO,{})):vr||(vr=(0,M.jsx)(D,{})),(0,M.jsx)(pe,{initialFolder:T.folder}),xr||(xr=(0,M.jsx)(we,{}))]})]})})})]}),R?(0,M.jsx)(y.s,{isOpen:!0,title:"Delete rule",body:"Deleting this rule will permanently remove it. Are you sure you want to delete this rule?",confirmText:"Yes, delete",icon:"exclamation-triangle",onConfirm:()=>{if(n){const e=O.Zk(n.ruleSourceName,n.namespace,n.group.name,n.rule);r((0,A.hS)(e,{navigateTo:"/alerting/list"}))}},onDismiss:()=>N(!1)}):null,l?(0,M.jsx)(qn,{onClose:()=>d(!1)}):null]}))},yr=e=>{const[t,n]=e(["type","dataSourceName"]);return(t===k.$.cloudAlerting||t===k.$.cloudRecording)&&""!==n},jr=e=>({buttonSpinner:r.css`
      margin-right: ${e.spacing(1)};
    `,form:r.css`
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
    `,contentInner:r.css`
      flex: 1;
      padding: ${e.spacing(2)};
    `,contentOuter:r.css`
      background: ${e.colors.background.primary};
      border: 1px solid ${e.colors.border.weak};
      border-radius: ${e.shape.borderRadius()};
      margin: ${e.spacing(0,2,2)};
      overflow: hidden;
      flex: 1;
    `,flexRow:r.css`
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
    `});var wr,Cr,Ar,kr,Ir,Sr,Or,Rr,Nr=n(78567),Tr=n(69450);const $r=e=>{let{identifier:t}=e;(0,f.x)((e=>e.unifiedAlerting.ruleForm.existingRule=I.oq));const{loading:n,result:i,error:r,dispatched:o}=(0,C._)((e=>e.ruleForm.existingRule)),c=(0,h.I0)(),{isEditable:u}=(0,Nr.M)(O.s0(t),null==i?void 0:i.rule);return(0,a.useEffect)((()=>{o||c((0,A.on)(t))}),[o,c,t]),n||void 0===u?wr||(wr=(0,M.jsx)(p.T.Contents,{children:(0,M.jsx)(s.u,{text:"Loading rule..."})})):r?(0,M.jsx)(p.T.Contents,{children:(0,M.jsx)(l.b,{severity:"error",title:"Failed to load rule",children:r.message})}):i?!1===u?Ar||(Ar=(0,M.jsx)(qr,{title:"Cannot edit rule",children:"Sorry! You do not have permission to edit this rule."})):(0,M.jsx)(br,{existing:i}):Cr||(Cr=(0,M.jsx)(qr,{title:"Rule not found",children:"Sorry! This rule does not exist."}))},qr=e=>{let{title:t,children:n}=e;return(0,M.jsxs)(l.b,{className:(0,c.wW)(Fr).warning,severity:"warning",title:t,children:[(0,M.jsx)("p",{children:n}),Rr||(Rr=(0,M.jsx)(u.Qj,{href:"alerting/list",children:"To rule list"}))]})},Fr=e=>({warning:r.css`
    margin: ${e.spacing(4)};
  `}),Er=(0,d.Pf)((e=>{let{match:t}=e;const n=(0,h.I0)(),{id:i}=t.params,r=O.OA(i,!0),{loading:a}=(0,o.Z)((async()=>{await n((0,A.dV)())}),[n]),{canCreateGrafanaRules:l,canCreateCloudRules:c,canEditRules:u}=(0,Tr.B)();return r||l||c?r&&!u(r.ruleSourceName)?Ir||(Ir=(0,M.jsx)(qr,{title:"Cannot edit rules",children:"Sorry! You are not allowed to edit rules."})):a?Sr||(Sr=(0,M.jsx)(p.T.Contents,{children:(0,M.jsx)(s.u,{text:"Loading..."})})):r?(0,M.jsx)($r,{identifier:r},i):Or||(Or=(0,M.jsx)(br,{})):kr||(kr=(0,M.jsx)(qr,{title:"Cannot create rules",children:"Sorry! You are not allowed to create rules."}))}),{style:"page"})},95910:(e,t,n)=>{n.d(t,{j:()=>l});var i=n(68404),r=n(48147),a=n(96380),o=n(85464),s=n(45916);function l(e){const{value:t,onChange:n,size:l="md"}=e,c=(0,i.useMemo)((()=>Object.values(r.v.panels).reduce(((e,t)=>(function(e){switch(e){case o.GC:case o.Fe:case o.Kd:return!0;default:return!1}}(t.id)&&e.push({value:t.id,label:t.name,imgUrl:t.info.logos.small}),e)),[])),[]);return(0,s.jsx)(a.S,{options:c,value:t,onChange:n,size:l})}},93783:(e,t,n)=>{n.d(t,{Z:()=>j});var i=n(27549),r=n(68404),a=n(59052),o=n(9617),s=n(4546),l=n(1652),c=n(63639),u=n(84719),d=n(65586),p=n(40920),f=n(85464),h=n(19854),g=n(45916);const m=["value","existingKeys","aria-label"];const v=e=>{let{value:t,existingKeys:n,"aria-label":i}=e,a=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,m);const o=(0,r.useMemo)((()=>Object.values(f.q6).filter((e=>!n.includes(e))).map((e=>({value:e,label:f.vY[e]})))),[n]);return(0,g.jsx)(h.P,Object.assign({"aria-label":i,value:t,options:o,custom:!!t&&!Object.values(f.q6).includes(t)},a))},x=["ref"];var b;const y=e=>({annotationValueInput:i.css`
    width: 426px;
  `,textarea:i.css`
    height: 76px;
  `,addAnnotationsButton:i.css`
    flex-grow: 0;
    align-self: flex-start;
    margin-left: 148px;
  `,flexColumn:i.css`
    display: flex;
    flex-direction: column;
  `,field:i.css`
    margin-bottom: ${e.spacing.xs};
  `,flexRow:i.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  `,flexRowItemMargin:i.css`
    margin-left: ${e.spacing.xs};
  `}),j=()=>{const e=(0,o.yK)(y),{control:t,register:n,watch:f,formState:{errors:h}}=(0,a.Gc)(),m=f("annotations"),j=(0,r.useCallback)((e=>m.filter(((t,n)=>n!==e)).map((e=>{let{key:t}=e;return t}))),[m]),{fields:w,append:C,remove:A}=(0,a.Dq)({control:t,name:"annotations"});return(0,g.jsxs)(g.Fragment,{children:[b||(b=(0,g.jsx)(s._,{children:"Summary and annotations"})),(0,g.jsxs)("div",{className:e.flexColumn,children:[w.map(((r,a)=>{var o,s,f,b,y,w,C,k,I,S,O,R,N,T,$;const q=null===(o=m[a])||void 0===o||null===(s=o.key)||void 0===s?void 0:s.toLocaleLowerCase().endsWith("url"),F=q?l.I:c.K;return(0,g.jsxs)("div",{className:e.flexRow,children:[(0,g.jsx)(u.g,{className:e.field,invalid:!(null===(f=h.annotations)||void 0===f||null===(b=f[a])||void 0===b||null===(y=b.key)||void 0===y||!y.message),error:null===(w=h.annotations)||void 0===w||null===(C=w[a])||void 0===C||null===(k=C.key)||void 0===k?void 0:k.message,"data-testid":`annotation-key-${a}`,children:(0,g.jsx)(d.g,{name:`annotations.${a}.key`,defaultValue:r.key,render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,i,r={},a=Object.keys(e);for(i=0;i<a.length;i++)n=a[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,x);return(0,g.jsx)(v,Object.assign({},t,{"aria-label":`Annotation detail ${a+1}`,existingKeys:j(a),width:18}))},control:t,rules:{required:{value:!(null===(I=m[a])||void 0===I||!I.value),message:"Required."}}})}),(0,g.jsx)(u.g,{className:(0,i.cx)(e.flexRowItemMargin,e.field),invalid:!(null===(S=h.annotations)||void 0===S||null===(O=S[a])||void 0===O||null===(R=O.value)||void 0===R||!R.message),error:null===(N=h.annotations)||void 0===N||null===(T=N[a])||void 0===T||null===($=T.value)||void 0===$?void 0:$.message,children:(0,g.jsx)(F,Object.assign({"data-testid":`annotation-value-${a}`,className:(0,i.cx)(e.annotationValueInput,{[e.textarea]:!q})},n(`annotations.${a}.value`),{placeholder:q?"https://":"Text",defaultValue:r.value}))}),(0,g.jsx)(p.zx,{type:"button",className:e.flexRowItemMargin,"aria-label":"delete annotation",icon:"trash-alt",variant:"secondary",onClick:()=>A(a)})]},r.id)})),(0,g.jsx)(p.zx,{className:e.addAnnotationsButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{C({key:"",value:""})},children:"Add info"})]})]})}},2394:(e,t,n)=>{n.d(t,{Z:()=>g});var i,r,a=n(27549),o=(n(68404),n(59052)),s=n(9617),l=n(4546),c=n(8397),u=n(84719),d=n(1652),p=n(40920),f=n(45916);const h=e=>({wrapper:a.css`
      margin-bottom: ${e.spacing.xl};
    `,flexColumn:a.css`
      display: flex;
      flex-direction: column;
    `,flexRow:a.css`
      display: flex;
      flex-direction: row;
      justify-content: flex-start;

      & + button {
        margin-left: ${e.spacing.xs};
      }
    `,deleteLabelButton:a.css`
      margin-left: ${e.spacing.xs};
      align-self: flex-start;
    `,addLabelButton:a.css`
      flex-grow: 0;
      align-self: flex-start;
    `,centerAlignRow:a.css`
      align-items: baseline;
    `,equalSign:a.css`
      align-self: flex-start;
      width: 28px;
      justify-content: center;
      margin-left: ${e.spacing.xs};
    `,labelInput:a.css`
      width: 175px;
      margin-bottom: ${e.spacing.sm};
      & + & {
        margin-left: ${e.spacing.sm};
      }
    `}),g=e=>{let{className:t}=e;const n=(0,s.yK)(h),{register:g,control:m,watch:v,formState:{errors:x}}=(0,o.Gc)(),b=v("labels"),{fields:y,append:j,remove:w}=(0,o.Dq)({control:m,name:"labels"});return(0,f.jsxs)("div",{className:(0,a.cx)(t,n.wrapper),children:[i||(i=(0,f.jsx)(l._,{children:"Custom Labels"})),(0,f.jsx)(f.Fragment,{children:(0,f.jsxs)("div",{className:n.flexRow,children:[r||(r=(0,f.jsx)(c.W,{width:18,children:"Labels"})),(0,f.jsxs)("div",{className:n.flexColumn,children:[y.map(((e,t)=>{var i,r,o,s,l,h,m,v,y,j,C,A,k,I;return(0,f.jsx)("div",{children:(0,f.jsxs)("div",{className:(0,a.cx)(n.flexRow,n.centerAlignRow),children:[(0,f.jsx)(u.g,{className:n.labelInput,invalid:!(null===(i=x.labels)||void 0===i||null===(r=i[t])||void 0===r||null===(o=r.key)||void 0===o||!o.message),error:null===(s=x.labels)||void 0===s||null===(l=s[t])||void 0===l||null===(h=l.key)||void 0===h?void 0:h.message,children:(0,f.jsx)(d.I,Object.assign({},g(`labels.${t}.key`,{required:{value:!(null===(m=b[t])||void 0===m||!m.value),message:"Required."}}),{placeholder:"key","data-testid":`label-key-${t}`,defaultValue:e.key}))}),(0,f.jsx)(c.W,{className:n.equalSign,children:"="}),(0,f.jsx)(u.g,{className:n.labelInput,invalid:!(null===(v=x.labels)||void 0===v||null===(y=v[t])||void 0===y||null===(j=y.value)||void 0===j||!j.message),error:null===(C=x.labels)||void 0===C||null===(A=C[t])||void 0===A||null===(k=A.value)||void 0===k?void 0:k.message,children:(0,f.jsx)(d.I,Object.assign({},g(`labels.${t}.value`,{required:{value:!(null===(I=b[t])||void 0===I||!I.key),message:"Required."}}),{placeholder:"value","data-testid":`label-value-${t}`,defaultValue:e.value}))}),(0,f.jsx)(p.zx,{className:n.deleteLabelButton,"aria-label":"delete label",icon:"trash-alt",variant:"secondary",onClick:()=>{w(t)}})]})},e.id)})),(0,f.jsx)(p.zx,{className:n.addLabelButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{j({})},children:"Add label"})]})]})})]})}},19854:(e,t,n)=>{n.d(t,{P:()=>s});var i=n(68404),r=n(1652),a=n(2563),o=n(45916);const s=e=>{let{value:t,onChange:n,options:s,className:l,placeholder:c,width:u,custom:d,onCustomChange:p,disabled:f=!1,addLabel:h="+ Add new","aria-label":g}=e;const[m,v]=(0,i.useState)(d);(0,i.useEffect)((()=>{d&&v(d)}),[d]);const x=(0,i.useMemo)((()=>[...s,{value:"__add__",label:h}]),[s,h]);return m?(0,o.jsx)(r.I,{"aria-label":g,width:u,autoFocus:!d,value:t||"",placeholder:c,className:l,disabled:f,onChange:e=>n(e.target.value)}):(0,o.jsx)(a.Ph,{"aria-label":g,width:u,options:x,value:t,className:l,placeholder:c,disabled:f,onChange:e=>{const t=null==e?void 0:e.value;"__add__"===t?(v(!0),p&&p(!0),n("")):n(t)}})}},13309:(e,t,n)=>{n.d(t,{W:()=>l});var i=n(68404),r=n(47570),a=n(83809),o=n(8455),s=n(33899);function l(e){const t=(0,r.I0)(),n=(0,s._)((e=>e.folders));if((0,i.useEffect)((()=>{e&&t((0,a.sw)(e))}),[t,e]),e){const t=n[e]||o.oq;return{folder:t.result,loading:t.loading}}return{loading:!1}}},78567:(e,t,n)=>{n.d(t,{M:()=>l});var i=n(61959),r=n(82969),a=n(86647),o=n(13309),s=n(33899);function l(e,t){var n,l,c;const u=(0,s._)((e=>e.dataSources)),d=t&&(0,a.Pc)(t)?t.grafana_alert.namespace_uid:void 0,p=(0,r.Bz)(e),{folder:f,loading:h}=(0,o.W)(d);if(!t)return{isEditable:!1,isRemovable:!1,loading:!1};if((0,a.Pc)(t)){if(!d)throw new Error(`Rule ${t.grafana_alert.title} does not have a folder uid, cannot determine if it is editable.`);if(!f)return{isEditable:!1,isRemovable:!1,loading:h};const e=f.canSave;return{isEditable:i.Vt.hasAccessInMetadata(p.update,f,e),isRemovable:i.Vt.hasAccessInMetadata(p.delete,f,e),loading:h}}const g=Boolean(null===(n=u[e])||void 0===n||null===(l=n.result)||void 0===l?void 0:l.rulerConfig);return{isEditable:i.Vt.hasAccess(p.update,i.Vt.isEditor)&&g,isRemovable:i.Vt.hasAccess(p.delete,i.Vt.isEditor)&&g,loading:null===(c=u[e])||void 0===c?void 0:c.loading}}},20910:(e,t,n)=>{n.d(t,{v:()=>R});var i=n(25918),r=n(71808),a=n(14444),o=n(2027),s=n(35778),l=n(34110),c=n(5937),u=n(2944),d=n(23541),p=n(75414),f=n(83044),h=n(7501),g=n(54801),m=n(28659),v=n(73389),x=n(45418),b=n(86452),y=n(392),j=n(22912);const w={from:21600,to:0},C=(e,t)=>{switch(e.type){case j.Us.classic:return A(e);case j.Us.math:return I(e,t);case j.Us.resample:case j.Us.reduce:return S(e)}},A=e=>{var t;return null===(t=e.conditions)||void 0===t?void 0:t.map((e=>e.query.params[0]))},k=(e,t)=>{let n=[],i=[w.to];for(const r of e){const e=t.find((e=>e.refId===r));e&&e.relativeTimeRange&&(n.push(e.relativeTimeRange.from),i.push(e.relativeTimeRange.to))}return{from:n,to:i}},I=(e,t)=>t.filter((t=>{var n;return"query"===t.queryType&&(null===(n=e.expression)||void 0===n?void 0:n.includes(t.refId))})).map((e=>e.refId)),S=e=>e.expression?[e.expression]:void 0;function O(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class R{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:(0,m.i)(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,h.F)();O(this,"subject",void 0),O(this,"subscription",void 0),O(this,"lastResult",void 0),this.backendSrv=e,this.dataSourceSrv=t,this.subject=new i.t(1),this.lastResult={}}get(){return this.subject.asObservable()}async run(e){if(0===e.length){const t=T(e,c.Gu.Done);return this.subject.next(t)}for(const t of e)if(!(0,v.j)(t.model)){const n=await this.dataSourceSrv.get(t.datasourceUid);if(n.filterQuery&&!n.filterQuery(t.model)){const t=T(e,c.Gu.Done);return this.subject.next(t)}}this.subscription=N(this.backendSrv,e).subscribe({next:e=>{const t=E(e,((e,t)=>{const n=this.lastResult[e],i=(0,y.zR)(t,n);return(0,b.C)(i,n)}));this.lastResult=t,this.subject.next(this.lastResult)},error:e=>{this.lastResult=F(this.lastResult,e),this.subject.next(this.lastResult)}})}cancel(){if(!this.subscription)return;this.subscription.unsubscribe();let e=!1;const t=E(this.lastResult,((t,n)=>(n.state===c.Gu.Loading&&(e=!0),Object.assign({},n,{state:c.Gu.Done}))));e&&this.subject.next(t)}destroy(){this.subject&&this.subject.complete(),this.cancel()}}const N=(e,t)=>{const n=T(t,c.Gu.Loading),i={data:{data:t},url:"/api/v1/eval",method:"POST",requestId:(0,l.Z)()};return(0,u.x)({whileLoading:n,source:e.fetch(i).pipe(q(n),(0,a.K)((e=>(0,r.of)(F(n,e)))),(0,x.V)(e,i.requestId),(0,o.B)())})},T=(e,t)=>e.reduce(((n,i)=>(n[i.refId]={state:t,series:[],timeRange:$(i,e)},n)),{}),$=(e,t)=>{if((0,v.j)(e.model)){const n=((e,t)=>{const n=C(e,t);if(!n)return w;const{from:i,to:r}=k(n,t);return i.length||r.length?{from:Math.max(...i),to:Math.min(...r)}:w})(e.model,t);return d.relativeToTimeRange(n)}return e.relativeTimeRange?d.relativeToTimeRange(e.relativeTimeRange):(console.warn(`Query with refId: ${e.refId} did not have any relative time range, using default.`),(0,p.JK)())},q=e=>(0,s.U)((t=>{const{data:n}=t,i={};for(const[t,r]of Object.entries(n.results))i[t]={timeRange:e[t].timeRange,state:c.Gu.Done,series:r.frames.map(f.vP)};return i})),F=(e,t)=>{const n=(0,g.P)(t);return E(e,((e,t)=>Object.assign({},t,{state:c.Gu.Error,error:n})))},E=(e,t)=>{const n={};for(const[i,r]of Object.entries(e))n[i]=t(i,r);return n}},73389:(e,t,n)=>{n.d(t,{j:()=>a});var i=n(13924),r=n(22912);const a=e=>{if(!e)return!1;if((0,i.Pr)(e.datasource))return!0;const t=e;return"string"==typeof t.type&&Object.values(r.Us).includes(t.type)}}}]);
//# sourceMappingURL=AlertingRuleForm.9e1b485e0020c58a325b.js.map