/*!
 * 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={397:(e,t,o)=>{o.r(t),o.d(t,{default:()=>S});var l=o(9497),r=o.n(l),a=o(23),n=o.n(a),i=o(232),u=o.n(i),s=o(4793),d=o(3563),c=o(7408),p=o.n(c),f=o(4082),b=o.n(f),h=o(8987),g=o(6649),m=o(2621),v=o.n(m);const y=require("@splunk/visualizations-shared/colorConstants");var C=o(3283),x=o(4008),_=o.n(x);const O=u().div`
    max-height: ${d.variables.inputHeight};
    width: 100%;
    min-width: 0;
`,E=u()(b())`
    max-height: ${d.variables.inputHeight};
`,k=({color:e,defaultColor:t,prevColor:o})=>{const l="string"==typeof e?e.trim():e;return(0,C.isColor)(l)||null===l?l:(0,C.isColor)(t)?t:(0,C.isColor)(o)||null===o?o:"transparent"},j=({id:e,showTextInput:t,color:o,palette:a,handleColorChange:n,labelledBy:i,textWidth:u,value:s,name:d,handleTextColorChange:c,handleKeyPress:f,handleBlur:b,isDisabled:m})=>{const y=(0,l.useMemo)((()=>(0,h.createDOMID)("color-code")),[]);return r().createElement(r().Fragment,null,r().createElement("div",null,r().createElement(p(),{key:"color-editor",append:t,value:k({color:o}),palette:a,onChange:n,"data-test":`color-picker-${d}`,disabled:m,hideInput:!0,labelledBy:i})),t&&r().createElement(O,{"data-test":"text-container",textWidth:u},r().createElement(v(),{id:y},(0,g._)("Color code input")),r().createElement(E,{key:s,"data-test":d,prepend:!0,value:null===o?"N/A":o,onChange:c,onKeyDown:f,onBlur:b,disabled:m,style:{height:"32px"},labelledBy:`${i} ${y}`,inputId:e})))};j.propTypes={id:n().string,showTextInput:n().bool,color:n().string,palette:n().arrayOf(n().string),handleColorChange:n().func,labelledBy:n().string,textWidth:n().oneOfType([n().string,n().number]),value:n().string,name:n().string.isRequired,handleTextColorChange:n().func,handleKeyPress:n().func,handleBlur:n().func,isDisabled:n().bool};const M={default:"transparent"},P={},w=({name:e="color",value:t="transparent",label:o="",labelPosition:a="top",labelWidth:n,palette:i=y.COLOR_EDITOR_PALETTE,onChange:u=s.noop,itemSchema:d=M,isDisabled:c=!1,textWidth:p="auto",hideLabel:f=!1,showTextInput:b=!0,style:h=P})=>{const[g,m]=(0,l.useState)(t);(0,l.useEffect)((()=>{m(t)}),[t]);const v=(0,l.useMemo)((()=>(0,s.debounce)(u,250)),[u]),C=(0,l.useCallback)((({value:o})=>{const l=k({color:o,defaultColor:d.default,prevColor:t});m(l),t!==l&&v(null,e,l)}),[v,d.default,e,t]),x=(0,l.useCallback)(((e,{value:t})=>{const o="n/a"===(0,s.toLower)(t).trim()?null:t;m(o)}),[]),O=(0,l.useCallback)((o=>{if("Escape"!==o.key){if("Enter"===o.key&&t!==g){const l=k({color:g,defaultColor:d.default,prevColor:t});m(l),l!==t&&u(o,e,l)}}else m(t)}),[e,g,t,u,d.default]),E=(0,l.useCallback)((o=>{if(g!==t){const l=k({color:g,defaultColor:d.default,prevColor:t});m(l),l!==t&&u(o,e,l)}}),[e,g,t,u,d.default]);return r().createElement(_(),{label:o,labelPosition:a,labelWidth:n,style:h,hideLabel:f,controlsLayout:"fillJoin"},r().createElement(j,{showTextInput:b,color:g,palette:i,handleColorChange:C,name:e,isDisabled:c,textWidth:p,value:t,handleTextColorChange:x,handleKeyPress:O,handleBlur:E}))};w.propTypes={name:n().string.isRequired,value:n().string,itemSchema:n().object,label:n().string.isRequired,hideLabel:n().bool,showTextInput:n().bool,style:n().object,labelPosition:n().oneOf(["top","left"]),labelWidth:n().number,palette:n().arrayOf(n().string),onChange:n().func.isRequired,isDisabled:n().bool,textWidth:n().oneOfType([n().string,n().number])};const S=w},2965:function(e,t,o){var l=this&&this.__createBinding||(Object.create?function(e,t,o,l){void 0===l&&(l=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,l,r)}:function(e,t,o,l){void 0===l&&(l=o),e[l]=t[o]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&l(t,e,o);return r(t,e),t},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ColorFlyoutEditor=void 0;const i=a(o(9497)),u=a(o(23)),s=n(o(232)),d=o(4793),c=n(o(4566)),p=o(6649),f=n(o(8965)),b=o(8987),h=n(o(7020)),g=n(o(1551)),m=o(3850),v=o(6801),y=n(o(4008)),C=n(o(397)),x={padding:"10px"},_={width:"314px"},O=(0,s.default)(h.default)`
    padding: 8px;
    width: 100%;
    min-height: 40px;
    & > span {
        display: grid;
        grid-template-columns: repeat(auto-fill, 26px);
        justify-content: space-evenly;
        grid-gap: 4px;
    }
    background-color: ${c.default.interactiveColorBackground};
`,E=s.default.div`
    width: 26px;
    height: 24px;
    background-color: ${e=>e.color};
    border-radius: 2px;
    border: 1px solid ${c.default.neutral100};
`,k=s.default.div`
    box-sizing: border-box;
    padding: 8px;
    width: 312px;
    max-height: 484px;
    background-color: ${c.default.backgroundColorPopup};
`,j=s.default.div`
    font-weight: 500;
    font-size: 14px;
    line-height: 20px;
    padding: 8px 8px 0 8px;
    font-family: ${c.default.fontFamily};
    color: ${c.default.contentColorActive};
`,M=s.default.div`
    height: 412px;
    overflow-y: auto;
    padding: 8px 10px;
`;t.ColorFlyoutEditor=({colors:e,CustomColorMatchEditor:t,handleColorRemove:o,handleColorChange:l,flyoutTitle:r,addColorButtonLabel:a,handleColorAdd:n,handleColorMove:u})=>{const s=(0,i.useMemo)((()=>e.map(((e,r)=>{const a=null==t;return i.default.createElement(f.default.Row,{index:r,key:(0,b.createDOMID)(),"data-color":e,onRequestRemove:o},i.default.createElement("div",{style:{display:"flex",justifyContent:"space-between"}},i.default.createElement(C.default,{value:e,key:(0,b.createDOMID)(),onChange:l(r),hideLabel:!0,label:" ",name:"color",style:{marginBottom:0,marginTop:0,width:a?"100%":32},showTextInput:a}),"function"==typeof t&&i.default.createElement(t,{index:r})))}))),[e,t,o,l]);return i.default.createElement(k,{"data-test":"MultiColorPickerFlyoutContent"},i.default.createElement(j,{"data-test":"MultiColorPickerFlyoutTitle"},r),i.default.createElement(M,null,i.default.createElement(f.default,{addLabel:a,onRequestAdd:n,onRequestMove:u,"data-test":"ColorListEditor"},s)))};const P=({CustomColorMatchEditor:e,onChange:o=d.noop,canReorderColors:l=!0,value:r=m.VIZ_CATEGORICAL,flyoutTitle:a=(0,p._)("Customize colors"),addColorButtonLabel:n=(0,p._)("Add color"),name:u="seriesColors",label:s="",labelPosition:c="top",labelWidth:f,isDisabled:h=!1,hideLabel:v=!0,canAddNewColors:C=!0})=>{const[k,j]=(0,i.useState)(!1),[M,P]=(0,i.useState)(r),w=(0,i.useRef)(null);(0,i.useEffect)((()=>{P(r)}),[r]);const S=(0,i.useCallback)((()=>{const e=new Set(M);let t=m.VIZ_CATEGORICAL.find((t=>!e.has(t)));if(!t){const e=new Map;m.VIZ_CATEGORICAL.forEach((t=>e.set(t,0))),M.forEach((t=>{e.set(t,(e.get(t)||0)+1)}));let o=1/0;m.VIZ_CATEGORICAL.forEach((l=>{const r=e.get(l)||0;r<o&&(o=r,t=l)}))}o(null,u,[...M,t])}),[u,o,M]),T=(0,i.useCallback)((e=>(t,l,r)=>{const a=[...M];a.splice(e,1,r),o(null,u,a)}),[u,o,M]),D=(0,i.useCallback)(((e,{index:t})=>{const l=[...M];l.splice(t,1),o(null,u,l)}),[u,o,M]),B=(0,i.useCallback)((({fromIndex:e,toIndex:t})=>{const l=[...M],r=l[e];l.splice(e,1),l.splice(t,0,r),o(null,u,l)}),[u,o,M]),A=(0,i.useCallback)((({event:e,reason:t})=>{var o;(null===(o=null==e?void 0:e.srcElement)||void 0===o?void 0:o.sortableHandle)||j(!1),"escapeKey"===t&&w.current.focus()}),[]),q=(0,i.useMemo)((()=>M.map((e=>i.default.createElement(E,{color:e,key:(0,b.createDOMID)()})))),[M]),L=(0,i.useCallback)((()=>{j((e=>!e))}),[]);return i.default.createElement(y.default,{label:s,labelPosition:c,labelWidth:f,hideLabel:v,"data-test":"MultiColorPickerEditor"},i.default.createElement(O,{inline:!1,"data-test":"MultiColorPickerButton",appearance:"default",ref:w,onClick:L,disabled:h,style:_},q),i.default.createElement(g.default,{"data-test":"MultiColorPickerFlyout",open:k,anchor:w.current,defaultPlacement:"horizontal",style:x,onRequestClose:A,takeFocus:!0},i.default.createElement(t.ColorFlyoutEditor,{colors:M,CustomColorMatchEditor:e,handleColorRemove:D,handleColorChange:T,handleColorAdd:C?S:void 0,handleColorMove:l?B:void 0,flyoutTitle:a,addColorButtonLabel:n})))};P.propTypes=Object.assign(Object.assign({},v.BaseEditorPropTypes),{canReorderColors:u.bool,canAddNewColors:u.bool,value:u.arrayOf(u.string),flyoutTitle:u.string,addColorButtonLabel:u.string,CustomColorMatchEditor:u.func,hideLabel:u.bool}),t.default=P},7364:function(e,t,o){var l=this&&this.__createBinding||(Object.create?function(e,t,o,l){void 0===l&&(l=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,l,r)}:function(e,t,o,l){void 0===l&&(l=o),e[l]=t[o]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&l(t,e,o);return r(t,e),t},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=a(o(9497)),u=a(o(23)),s=o(4793),d=o(6649),c=o(8987),p=n(o(2373)),f=o(2687),b=n(o(3453)),h=o(9033),g=n(o(2965)),m=n(o(4008)),v=o(6801),y=o(1385),C={},x={},_={},O=({name:e,value:t=C,dataSourceBindings:o,onChange:l,options:r=x,isCategorical:a=!1,context:n,optionsSchema:v=_})=>{var O;const[E,k]=(0,i.useState)(Object.values(t)),[j,M]=(0,i.useState)(Object.keys(t));(0,i.useEffect)((()=>{k(Object.values(t)),M(Object.keys(t))}),[JSON.stringify(t)]);const P=(0,y.useDataSource)({dataSourceBindings:o,dataSourceKey:"primary"}),{isLoading:w}=(0,i.useMemo)((()=>(0,h.getDataSourceStateInfo)(P)),[P]),{category:S=(null===(O=null==v?void 0:v.category)||void 0===O?void 0:O.default)}=null!=r?r:{},T=(0,i.useMemo)((()=>{var e,t;if(a){if(!S)return[];if(Array.isArray(S))return[...new Set(S.map((e=>null==e?void 0:e.toString())).filter((e=>!(0,s.isEmpty)(e))))];if(!w&&b.default.isDslString(S)){const e=f.Options.evaluate({context:n,options:Object.assign(Object.assign({},r),{category:S})},{primary:P});if(Array.isArray(e.category))return[...new Set(e.category.map((e=>null==e?void 0:e.toString())).filter((e=>!(0,s.isEmpty)(e))))]}return[]}return null!==(t=null===(e=null==P?void 0:P.data)||void 0===e?void 0:e.fields.map((e=>e.name)))&&void 0!==t?t:[]}),[n,P,a,r,S,w]),{editorLabel:D,flyoutTitle:B,addColorButtonLabel:A}=(0,i.useMemo)((()=>a?{editorLabel:(0,d._)("Series colors by category name"),flyoutTitle:(0,d._)("Color by category name"),addColorButtonLabel:(0,d._)("Add category")}:{editorLabel:(0,d._)("Series colors by field name"),flyoutTitle:(0,d._)("Color by field name"),addColorButtonLabel:(0,d._)("Add field")}),[a]),q=({updatedColors:e,updatedFields:t})=>{const o={};return t.forEach(((t,l)=>{o[t]=e[l]})),o},L=(0,i.useCallback)(((t,o,r)=>{if(r.length>T.length)return;const a=j;if(r.length>E.length){const e=T.find((e=>!j.includes(e)));a.push(e)}if(r.length<E.length){const e=E.findIndex((e=>!r.includes(e)));a.splice(e,1)}l(null,e,q({updatedColors:r,updatedFields:a}))}),[T,l,e,j,E]),I=(0,i.useCallback)((({newFieldIndex:t,currFieldIndex:o})=>{const r=j.includes(T[t]),a=j;if(r){const e=j.indexOf(T[t]),l=j[o];a[o]=j[e],a[e]=l}else a[o]=T[t];l(null,e,q({updatedColors:E,updatedFields:a}))}),[j,T,E,e,l]),R=(0,i.useMemo)((()=>(({fields:e,dsFields:t,handleFieldChange:o})=>{const l=({index:l})=>{const r=(0,i.useMemo)((()=>t.map(((e,t)=>i.default.createElement(p.default.Option,{label:e,value:t,key:(0,c.createDOMID)(),"data-test":`${e}-${l}`})))),[l]),a=(0,i.useCallback)(((e,{value:t})=>{o({newFieldIndex:t,currFieldIndex:l})}),[l]),n=t.indexOf(e[l]);return i.default.createElement(p.default,{value:n,onChange:a,style:{width:190},"data-test":"field-select"},r)};return l.propTypes={index:u.number},l})({fields:j,dsFields:T,handleFieldChange:I})),[T,j,I]);return i.default.createElement(m.default,{label:D,labelPosition:"top","data-test":"SeriesColorsByFieldEditor"},i.default.createElement(g.default,{value:E,onChange:L,name:"series",canReorderColors:!1,flyoutTitle:B,addColorButtonLabel:A,CustomColorMatchEditor:R,isDisabled:T.length<1,canAddNewColors:j.length<T.length}))};O.propTypes=Object.assign(Object.assign({},v.BaseEditorPropTypes),{isCategorical:u.bool}),t.default=O},1385:function(e,t,o){var l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.useDataSource=void 0;const r=o(9497),a=l(o(4853)),n=o(4793);t.useDataSource=({dataSourceBindings:e,dataSourceKey:t})=>{const o=(0,r.useContext)(a.default),[l,i]=(0,r.useState)();return(0,r.useEffect)((()=>{if(!(0,n.get)(e,t))return i(null),()=>{};const l=(0,n.isFunction)(o.subscribe)&&o.subscribe(t,(e=>i(e)));return()=>{l&&l()}}),[e]),l}},6801:function(e,t,o){var l=this&&this.__createBinding||(Object.create?function(e,t,o,l){void 0===l&&(l=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,l,r)}:function(e,t,o,l){void 0===l&&(l=o),e[l]=t[o]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&l(t,e,o);return r(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.BaseEditorPropTypes=void 0;const n=a(o(23));t.BaseEditorPropTypes={name:n.string.isRequired,value:n.oneOfType([n.string,n.object,n.arrayOf(n.string)]),context:n.object,label:n.string,labelPosition:n.oneOf(["top","left"]),labelWidth:n.number,onChange:n.func,isAdvanced:n.bool,isDisabled:n.bool,dataSourceBindings:n.object,options:n.object,optionsSchema:n.object}},4008:function(e,t,o){var l=this&&this.__createBinding||(Object.create?function(e,t,o,l){void 0===l&&(l=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,l,r)}:function(e,t,o,l){void 0===l&&(l=o),e[l]=t[o]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&l(t,e,o);return r(t,e),t},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.AdvancedConfigButton=void 0;const i=a(o(9497)),u=a(o(23)),s=n(o(232)),d=o(6649),c=n(o(6643)),p=o(3563),f=n(o(6379)),b=n(o(7020)),h=n(o(9250)),g=(0,s.default)(h.default)`
    margin-top: 0;
    padding: 0;
    // adjust bottom margin according to theme
    margin-bottom: ${p.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;
    }
`,m=(0,s.default)(f.default)`
    display: flex;
    > span {
        display: flex;
        width: 35px;
    }
`,v=(0,s.default)(b.default)`
    color: ${p.variables.contentColorActive} !important;
    &:hover {
        background-color: ${p.variables.interactiveColorOverlayDrag} !important;
    }
`;t.AdvancedConfigButton=({label:e="",onClick:t})=>i.default.createElement(m,{"data-test":`${e}-advanced-config-button-tooltip`,content:(0,d._)("Advanced configurations")},i.default.createElement(v,{"data-test":`${e}-advanced-config-button`,icon:i.default.createElement(c.default,{"data-test":`${e}-advanced-config-button-icon`}),appearance:"subtle",onClick:t}));const y=({"data-test":e,children:o,isAdvanced:l=!1,label:r,hideLabel:a,labelPosition:n,labelWidth:u,tooltip:s,help:d,style:c,error:p,controlsLayout:f,onClick:b,onAdvancedConfigButtonClick:h})=>i.default.createElement(g,{"data-test":null!=e?e:"control-group",label:r,hideLabel:a,labelPosition:n,labelWidth:u,tooltip:s,help:d,error:p,style:c,onClick:b,controlsLayout:f},l?i.Children.toArray(o).filter(Boolean).map((e=>(0,i.cloneElement)(e,{style:{flex:1}}))):o,l?i.default.createElement(t.AdvancedConfigButton,{label:r,onClick:h}):null);y.propTypes={style:u.object,isAdvanced:u.bool,onClick:u.func,onAdvancedConfigButtonClick:u.func},t.default=y},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")},8965:e=>{e.exports=require("@splunk/react-ui/FormRows")},1551:e=>{e.exports=require("@splunk/react-ui/Popover")},2621:e=>{e.exports=require("@splunk/react-ui/ScreenReaderContent")},2373:e=>{e.exports=require("@splunk/react-ui/Select")},4082:e=>{e.exports=require("@splunk/react-ui/Text")},6379:e=>{e.exports=require("@splunk/react-ui/Tooltip")},3563:e=>{e.exports=require("@splunk/themes")},4566:e=>{e.exports=require("@splunk/themes/variables")},6649:e=>{e.exports=require("@splunk/ui-utils/i18n")},8987:e=>{e.exports=require("@splunk/ui-utils/id")},3850:e=>{e.exports=require("@splunk/visualization-color-palettes")},4853:e=>{e.exports=require("@splunk/visualization-context/DataSourceContext")},3453:e=>{e.exports=require("@splunk/visualization-encoding/EncodingParser")},2687:e=>{e.exports=require("@splunk/visualization-encoding/Options")},3283:e=>{e.exports=require("@splunk/visualizations-shared/colorUtils")},9033:e=>{e.exports=require("@splunk/visualizations-shared/dataSourceUtils")},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 o(l){var r=t[l];if(void 0!==r)return r.exports;var a=t[l]={exports:{}};return e[l].call(a.exports,a,a.exports,o),a.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var l in t)o.o(t,l)&&!o.o(e,l)&&Object.defineProperty(e,l,{enumerable:!0,get:t[l]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var l=o(7364);module.exports=l})();
//# sourceMappingURL=SeriesColorsByFieldEditor.js.map