/*!
 * Copyright © 2018 Splunk Inc.
 * SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
 * in part without a valid written license from Splunk Inc. is PROHIBITED.
 */(()=>{"use strict";var e={4008:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),l=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AdvancedConfigButton=void 0;const s=l(r(9497)),i=l(r(23)),d=a(r(232)),u=r(6649),c=a(r(6643)),b=r(3563),p=a(r(6379)),h=a(r(7020)),f=a(r(9250)),m=(0,d.default)(f.default)`
    margin-top: 0;
    padding: 0;
    // adjust bottom margin according to theme
    margin-bottom: ${b.variables.spacingMedium};
    width: 100%;

    // remove top margin of the first component in control group
    &:first-child {
        margin-top: 0;
    }

    // remove bottom margin of the last component in control group
    &:last-child {
        margin-bottom: 0;
    }
    // remove top padding on label of the first control group
    [data-test='label']:first-of-type {
        padding-top: 0;
    }
`,g=(0,d.default)(p.default)`
    display: flex;
    > span {
        display: flex;
        width: 35px;
    }
`,v=(0,d.default)(h.default)`
    color: ${b.variables.contentColorActive} !important;
    &:hover {
        background-color: ${b.variables.interactiveColorOverlayDrag} !important;
    }
`;t.AdvancedConfigButton=({label:e="",onClick:t})=>s.default.createElement(g,{"data-test":`${e}-advanced-config-button-tooltip`,content:(0,u._)("Advanced configurations")},s.default.createElement(v,{"data-test":`${e}-advanced-config-button`,icon:s.default.createElement(c.default,{"data-test":`${e}-advanced-config-button-icon`}),appearance:"subtle",onClick:t}));const y=({"data-test":e,children:r,isAdvanced:o=!1,label:n,hideLabel:l,labelPosition:a,labelWidth:i,tooltip:d,help:u,style:c,error:b,controlsLayout:p,onClick:h,onAdvancedConfigButtonClick:f})=>s.default.createElement(m,{"data-test":null!=e?e:"control-group",label:n,hideLabel:l,labelPosition:a,labelWidth:i,tooltip:d,help:u,error:b,style:c,onClick:h,controlsLayout:p},o?s.Children.toArray(r).filter(Boolean).map((e=>(0,s.cloneElement)(e,{style:{flex:1}}))):r,o?s.default.createElement(t.AdvancedConfigButton,{label:n,onClick:f}):null);y.propTypes={style:i.object,isAdvanced:i.bool,onClick:i.func,onAdvancedConfigButtonClick:i.func},t.default=y},6195:e=>{e.exports=require("@babel/runtime/helpers/defineProperty")},8855:e=>{e.exports=require("@splunk/react-icons/Cross")},6643:e=>{e.exports=require("@splunk/react-icons/SlidersDoubleHorizontal")},7020:e=>{e.exports=require("@splunk/react-ui/Button")},7408:e=>{e.exports=require("@splunk/react-ui/Color")},9250:e=>{e.exports=require("@splunk/react-ui/ControlGroup")},2782:e=>{e.exports=require("@splunk/react-ui/Number")},5777:e=>{e.exports=require("@splunk/react-ui/Switch")},6379:e=>{e.exports=require("@splunk/react-ui/Tooltip")},3563:e=>{e.exports=require("@splunk/themes")},4566:e=>{e.exports=require("@splunk/themes/variables")},3773:e=>{e.exports=require("@splunk/ui-utils/format")},6649:e=>{e.exports=require("@splunk/ui-utils/i18n")},8987:e=>{e.exports=require("@splunk/ui-utils/id")},3283:e=>{e.exports=require("@splunk/visualizations-shared/colorUtils")},4793:e=>{e.exports=require("lodash")},23:e=>{e.exports=require("prop-types")},9497:e=>{e.exports=require("react")},232:e=>{e.exports=require("styled-components")}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var l=t[o]={exports:{}};return e[o].call(l.exports,l,l.exports,r),l.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};(()=>{r.r(o),r.d(o,{default:()=>fe});var e=r(9497),t=r.n(e),n=r(23),l=r.n(n),a=r(4793),s=r(232),i=r.n(s),d=r(6649),u=r(5777),c=r.n(u),b=r(4008),p=r.n(b),h=r(7020),f=r.n(h),m=r(4566),g=r.n(m),v=r(3773);const y=i().div.attrs((()=>({"data-test":"threshold-error"})))`
    color: ${g().contentColorNegative};
    padding-top: 5px;
    font-size: 12px;
    display: block;
`,C=({error:e,id:r,thresholdIndex:o})=>e?t().createElement(y,{id:r},"number"==typeof o?(0,v.sprintf)((0,d._)("Error for threshold %(thresholdIndex)d : %(error)s"),{thresholdIndex:o,error:e}):(0,v.sprintf)((0,d._)("Error: %(error)s"),{error:e})):null;C.propTypes={id:l().string,error:l().string,thresholdIndex:l().number};const E=C;var x=r(2782),k=r.n(x);const O=({"data-test":r="threshold-boundary-input",boundary:o,isDisabled:n=!1,isEditable:l=!0,errorId:s,onChange:i=a.noop,onRequestClose:u=a.noop,onValidate:c=a.noop,index:b})=>{const[p,h]=(0,e.useState)(o);(0,e.useEffect)((()=>{h(o)}),[o]);const f=(0,e.useCallback)(((e,{value:t})=>{h(t),c(t)}),[c]),m=(0,e.useCallback)((e=>{"Enter"===e.key&&i(p),"Escape"===e.key&&u()}),[p,i,u]),g=(0,e.useCallback)((()=>{i(p)}),[i,p]),y="number"==typeof b?(0,v.sprintf)((0,d._)("Threshold number %(index)d"),{index:b}):(0,d._)("Threshold");return l?t().createElement(k(),{"aria-label":p?(0,v.sprintf)((0,d._)("%(label)s, value %(boundaryValue)d"),{label:y,boundaryValue:p}):(0,v.sprintf)((0,d._)("%(label)s, no value"),{label:y}),inline:!0,hideStepButtons:!0,disabled:n,value:p||0===p?p:null,onChange:f,onBlur:g,onKeyDown:m,error:!!s,"data-test":r,describedBy:s}):null};O.propTypes={"data-test":l().string,boundary:l().number,isDisabled:l().bool,isEditable:l().bool,errorId:l().string,onChange:l().func,onRequestClose:l().func,onValidate:l().func,index:l().number};const D=O;var w=r(6195),j=r.n(w);function _(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function T(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?_(Object(r),!0).forEach((function(t){j()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):_(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const q=["#dc4e41","#f1813f","#f8be34","#53a051","#0877a6","#006d9c","#ec9960","#af575a","#62b3b2","#4fa484","#f8be44","#5a4575","#708794","#294e70","#b6c75a"];function P(e=[]){if(e.length<2)return console.warn("Invalid threshold configuration: at least 2 thresholds required"),e;const t=e.map((e=>{const t=T({},e);return e.from&&(t.from=+e.from),e.to&&(t.to=+e.to),t})),r=t.filter((e=>void 0===e.from));r.length>1&&console.warn("Invalid threshold configuration: multiple open lower boundaries");const o=t.filter((e=>void 0!==e.from));o.length!==(0,a.uniqBy)(o,"from").length&&console.warn("Invalid threshold configuration: duplicate from values");const n=o.sort(((e,t)=>+t.from-+e.from));if(r.length){const e=r[0];return e.to!==n[n.length-1].from&&(e.to=n[n.length-1].from),n.forEach(((e,t)=>{const r=T({},e);t>0?r.to=n[t-1].from:delete r.to,n[t]=r})),[...n,e]}return n.forEach(((e,t)=>{const r=T({},e);t>0&&(r.to=n[t-1].from),n[t]=r})),n}function M(e="",t=[]){const r=parseFloat(e);return(0,a.isNaN)(r)||(0,a.isNaN)(+e)?{error:!0,errorMessage:(0,d._)("Not a valid threshold. Must be a number")}:t.filter((e=>e.from===r)).length>0?{error:!0,errorMessage:(0,d._)("Value already exists")}:{error:!1,errorMessage:null}}const R=i().div.attrs((()=>({"data-test":"add-threshold-level"})))`
    margin-bottom: 10px;
`,$=({thresholds:r,onAddThreshold:o=a.noop})=>{const[n,l]=(0,e.useState)(!1),[s,i]=(0,e.useState)(null),u=(0,e.useCallback)((()=>{l(!n)}),[n]),c=(0,e.useCallback)((e=>{const t=M(e,r);t.error?i(t.errorMessage):o(e)}),[r,o]),b=(0,e.useCallback)((e=>{const t=M(e,r);t.error&&i(t.errorMessage)}),[r]);return t().createElement(R,null,n?t().createElement(t().Fragment,null,t().createElement(D,{"data-test":"add-threshold-input",isError:!!s,onChange:c,onRequestClose:u,onValidate:b}),t().createElement(E,{error:s})):t().createElement(f(),{appearance:"secondary",onClick:u,label:`+ ${(0,d._)("Add threshold level")}`}))};$.propTypes={onAddThreshold:l().func,thresholds:l().array};const S=$;var V=r(8855),A=r.n(V),I=r(8987),N=r(3563),B=r(6379),F=r.n(B);const L=i().div`
    margin-right: 10px;
    width: 100px;
    display: inline-block;
`,W=i().div.attrs((()=>({"data-test":"threshold-boundary-label"})))`
    flex-grow: 1;
    flex-direction: row;
`,z=i().span`
    line-height: 36px;
    margin-right: 10px;
    color: ${e=>e.isDisabled?g().contentColorDisabled:g().contentColorMuted};
`,X=i().span`
    display: inline-block;
    color: ${e=>e.isDisabled?g().contentColorDisabled:g().contentColorMuted};
    width: 30px;
    text-overflow: ellipsis;
    vertical-align: bottom;
    overflow: hidden;
    white-space: nowrap;
`,U=({describedBy:e,isDisabled:r,to:o})=>t().createElement(X,{"aria-describedby":e,isDisabled:r},o);U.propTypes={describedBy:l().any,isDisabled:l().bool,to:l().number};const G=({isDisabled:e,to:r})=>t().createElement(F(),{content:`${r}`},t().createElement(U,{to:r,isDisabled:e}));G.propTypes={isDisabled:l().bool,to:l().number};const H=({index:e,to:r,isRemovable:o,isEditable:n,onChange:l,isDisabled:a,errorId:s})=>{const i=0===e,u=o?`${(0,d._)("and")} `:"";return n?t().createElement(W,null,t().createElement(z,{isDisabled:a},(0,d._)("to")),t().createElement(L,null,t().createElement(D,{"data-test":"threshold-to-level",boundary:r,isDisabled:a,isEditable:!0,errorId:s,onChange:l}))):t().createElement(W,null,i&&t().createElement(z,{isDisabled:a},(0,d._)("and above")),!i&&t().createElement(t().Fragment,null,t().createElement(z,{isDisabled:a},`${u}${(0,d._)("below")}`),t().createElement(G,{isDisabled:a,to:r})))};H.propTypes={to:l().number,index:l().number,isRemovable:l().bool,isEditable:l().bool,isDisabled:l().bool,onChange:l().func,errorId:l().string};const K=H,J=i().div.attrs((()=>({"data-test":"threshold-level"})))`
    width: 100%;
    position: relative;
    display: flex;
    align-items: flex-end;
    margin-bottom: 5px;
`,Q=i().div`
    margin-right: 10px;
    width: 100px;
    display: inline-block;
`,Y=i().div`
    display: flex;
    margin-left: auto;
`,Z=i().div`
    margin-left: ${N.variables.spacingXSmall};
    width: ${N.variables.spacingXXLarge};
`,ee=i()(f())`
    color: ${e=>e.disabled?N.variables.contentColorDisabled:N.variables.contentColorActive} !important;
    &:hover {
        background-color: ${e=>!e.disabled&&N.variables.interactiveColorOverlayDrag} !important;
    }
`,te=({editFrom:r,editTo:o,editValue:n,error:l,from:a,index:s,isDisabled:i=!1,isRemovable:d=!1,onChange:u,onRemove:c,renderThresholdValueEditor:b,to:p,value:h})=>{const f=(0,e.useCallback)((e=>{(l||e!==a)&&u(s,{from:e,value:h,to:p})}),[u,a,h,p,s,l]),m=(0,e.useCallback)((e=>{(l||e!==p)&&u(s,{from:a,value:h,to:e})}),[u,a,h,p,s,l]),g=(0,e.useCallback)((({value:e})=>{u(s,{from:a,value:e,to:p})}),[u,s,a,p]),v=(0,e.useCallback)((()=>c(s)),[c,s]),y=(0,e.useMemo)((()=>l?(0,I.createDOMID)("threshold-error"):void 0),[l]);return t().createElement(t().Fragment,null,t().createElement(J,null,t().createElement(Q,null,t().createElement(D,{"data-test":"threshold-from-level",boundary:a,isDisabled:i,isEditable:r,errorId:y,onChange:f,index:s})),t().createElement(K,{to:p,index:s,isRemovable:d,isEditable:o,isDisabled:i,onChange:m,errorId:y}),t().createElement(Y,null,b({value:h,onChange:g,isDisabled:i||!!l,editValue:n})),t().createElement(Z,null,d&&t().createElement(ee,{"data-test":"threshold-remove-button",icon:t().createElement(A(),null),appearance:"subtle",onClick:v,disabled:i}))),t().createElement(E,{error:l,id:y,thresholdIndex:s}))};te.propTypes={editFrom:l().bool,editTo:l().bool,editValue:l().bool,error:l().string,from:l().number,index:l().number,isDisabled:l().bool,isRemovable:l().bool,onChange:l().func,onRemove:l().func,renderThresholdValueEditor:l().elementType.isRequired,to:l().number,value:l().string};const re=te;function oe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function ne(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?oe(Object(r),!0).forEach((function(t){j()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):oe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const le=[],ae=({ranges:r=le,openRanges:o=!0,isDisabled:n=!1,onChange:l,renderThresholdValueEditor:s})=>{const[i,u]=(0,e.useState)({}),c=(0,e.useCallback)((e=>{const t=(0,a.cloneDeep)(r);t.splice(e,1),l(P(t));const o=ne({},i);delete o[e],u(o)}),[i,r,l]),b=(0,e.useCallback)(((e,t)=>{const n=(0,a.cloneDeep)(r),s=ne({},i);if(n.splice(e,1,t),delete s[e],!o&&0===e){const r=function(e="",t=""){const r=parseFloat(e),o=parseFloat(t);return(0,a.isNaN)(r)||(0,a.isNaN)(+e)||(0,a.isNaN)(o)||(0,a.isNaN)(+t)?{error:!0,errorMessage:(0,d._)("Not a valid threshold. Must be a number")}:r<o?{error:!0,errorMessage:(0,d._)("Upper boundary must exceed lower boundary")}:{error:!1,errorMessage:null}}(t.to,t.from);r.error&&(s[e]=r.errorMessage)}if(!o&&0!==e&&t.to<t.from&&t.from>r[0].from&&(n[e].to=t.from+10),!o||e<r.length-1){const o=(0,a.cloneDeep)(r);o.splice(e,1);const n=M(t.from,o);n.error&&(s[e]=n.errorMessage)}u(s),Object.keys(s).length||l(P(n))}),[i,r,l,o]),p=!!Object.keys(i).length,h=(0,e.useCallback)((e=>!o&&r.length>1||o&&r.length>2&&e!==r.length-1),[o,r]);return r.map(((e,l)=>t().createElement(re,{key:`threshold-${e.from}-${e.to}-${e.value}`,onRemove:c,onChange:b,index:l,from:e.from,to:e.to,value:e.value,error:i[l],editFrom:!o||l!==r.length-1,editTo:!o&&0===l,editValue:!p,isRemovable:h(l),isDisabled:n,renderThresholdValueEditor:s})))};ae.propTypes={onChange:l().func.isRequired,ranges:l().arrayOf(l().shape({from:l().number,to:l().number,value:l().string})),isDisabled:l().bool,renderThresholdValueEditor:l().elementType.isRequired,openRanges:l().bool};const se=ae;var ie=r(7408),de=r.n(ie),ue=r(3283);const ce=({isDisabled:e,value:r,onChange:o})=>{const n=t().useCallback((({value:e})=>{o({value:null==e||""===e?"transparent":e})}),[o]);return t().createElement(de(),{disabled:e,value:(0,ue.isColor)(r)?r:"transparent",onChange:n,hideInput:!0,palette:q,"data-test":"threshold-level-value"})};ce.propTypes={isDisabled:l().bool,value:l().string,onChange:l().func.isRequired};const be=ce,pe=i().div`
    flex-direction: column;
    flex-grow: 1;
`,he=({onChange:r,name:o,itemSchema:n,value:l,labelPosition:s="top",labelWidth:i,label:u,isDisabled:b=!1,isTogglable:h=!0,openRanges:f=!0,renderThresholdValueEditor:m=be})=>{const g=Array.isArray(l)&&l.length>0,v=(0,e.useCallback)((()=>{r(null,o,n.default)}),[n,o,r]),y=(0,e.useCallback)((()=>{r(null,o,null)}),[o,r]),C=(0,e.useCallback)((()=>g?y():v()),[g,v,y]),E=(0,e.useCallback)((e=>{const t=(0,a.cloneDeep)(l),n={from:e,value:function(e=[]){const t=(0,a.difference)(q,e);return t.length>0?t[0]:"#444000"}(t.map((e=>e.value)))};f||(n.to=e+10),t.push(n);const s=P(t);r(null,o,s)}),[o,l,r,f]),x=(0,e.useCallback)((e=>{r(null,o,e)}),[r,o]);return t().createElement(p(),{label:u,labelPosition:s,labelWidth:i},t().createElement(pe,{"data-test":o},h&&t().createElement(c(),{appearance:"toggle",selected:g,onClick:C,disabled:b,role:"switch"},(0,d._)("Threshold")),g&&t().createElement(t().Fragment,null,!b&&t().createElement(S,{onAddThreshold:E,thresholds:l}),t().createElement(se,{onChange:x,ranges:l,isDisabled:b,openRanges:f,renderThresholdValueEditor:m}))))};he.propTypes={onChange:l().func.isRequired,name:l().string.isRequired,itemSchema:l().object,value:l().arrayOf(l().shape({from:l().number,to:l().number,value:l().string})),label:l().string.isRequired,labelPosition:l().oneOf(["left","top"]),labelWidth:l().number,isDisabled:l().bool,openRanges:l().bool,renderThresholdValueEditor:l().elementType,isTogglable:l().bool};const fe=he})(),module.exports=o})();
//# sourceMappingURL=ThresholdEditor.js.map