/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.exploratoryView_bundle_jsonpfunction=window.exploratoryView_bundle_jsonpfunction||[]).push([[4,8],{62:function(e,l,t){"use strict";t.d(l,"a",(function(){return c}));var n=t(19),a=t(1),i=t(66),o=t.n(i),u=t(8),r=t(4);const c=({sourceField:e,dataViewTitle:l,query:t="",filters:i,time:c,label:s,keepHistory:d,cardinalityField:p})=>{const[f,b]=Object(a.useState)(t),[m,g]=Object(a.useState)([]),{from:h,to:y}=null!=c?c:{};o()((()=>{b(t)}),350,[t]),Object(a.useEffect)((()=>{t||b(t)}),[t]);const E=((e,l)=>{if(!l)return"";let t="";return t=e===r.o?`*.${l.toLowerCase()}.*`:l[0].toLowerCase()===l[0]?`(${l}|${Object(n.capitalize)(l)}).*`:`(${l}|${l.toLowerCase()}).*`,t})(e,t),{data:v,loading:w}=Object(u.useEsSearch)(Object(u.createEsParams)({index:l,body:{query:{bool:{filter:[...null!=i?i:[],...h&&y?[{range:{"@timestamp":{gte:h,lte:y}}}]:[]]}},size:0,aggs:{values:{terms:{field:e,size:50,...t?{include:E}:{}},...p?{aggs:{count:{cardinality:{field:p}}}}:{}}}}}),[f,h,y,JSON.stringify(i),l,e],{name:`get${s.replace(/\s/g,"")}ValuesList`});return Object(a.useEffect)((()=>{var e,l;const t=null==v||null===(e=v.aggregations)||void 0===e?void 0:e.values.buckets,a=null!==(l=null==t?void 0:t.map((({key:e,doc_count:l,count:t})=>t?{count:t.value,label:String(e)}:{count:l,label:String(e)})))&&void 0!==l?l:[];g(d?e=>((e,l)=>Object(n.uniqBy)([...e,...l],"label"))(a,e):a)}),[v,d,w,t]),{values:m,loading:w}}},63:function(e,l,t){"use strict";t.r(l),t.d(l,"FieldValueSelection",(function(){return p}));var n=t(14),a=t.n(n),i=t(1),o=t.n(i),u=t(7),r=t(0),c=t(19);const s=t(21).euiStyled.div` border-radius: ${({theme:e})=>e.eui.euiBorderRadius}; background: ${({theme:e})=>e.eui.euiColorLightShade}; padding: 0 ${({theme:e})=>e.eui.euiSizeXS}; `,d=(e,l,t,n)=>{const a={};return null==e||e.forEach((({label:e,count:l})=>{a[e]=l})),Object.entries(a).map((([e,a])=>({label:e,append:n?o.a.createElement(s,null,o.a.createElement(u.EuiText,{size:"xs"},a)):null,...null!=l&&l.includes(e)?{checked:"on"}:{},...null!=t&&t.includes(e)?{checked:"off"}:{}})))};function p({fullWidth:e,label:l,loading:t,query:n,setQuery:a,button:s,width:p,forceOpen:g,setForceOpen:h,anchorPosition:y,singleSelection:E,asFilterButton:v,showCount:w=!0,values:S=[],selectedValue:x,excludedValue:O,allowExclusions:j=!0,compressed:C=!0,useLogicalAND:V,showLogicalConditionSwitch:F=!1,onChange:k}){const{euiTheme:L}=Object(u.useEuiTheme)(),[_,P]=Object(i.useState)((()=>d(S,x,O,w))),[B,A]=Object(i.useState)(!1),[T,z]=Object(i.useState)(V);Object(i.useEffect)((()=>{z(V)}),[V]),Object(i.useEffect)((()=>{P(d(S,x,O,w))}),[JSON.stringify(S),JSON.stringify(x),w,O]);const $=()=>{A(!B)},N=o.a.createElement(u.EuiButton,{style:p?{width:p}:{},size:"m",color:"text",iconType:"arrowDown",iconSide:"right",onClick:$,"data-test-subj":"fieldValueSelectionBtn",fullWidth:e},l),q=(x||[]).length+(O||[]).length,W=o.a.createElement(u.EuiFilterButton,{"aria-label":r.i18n.translate("xpack.exploratoryView.filterButton.label",{defaultMessage:"expands filter group for {label} filter",values:{label:l}}),hasActiveFilters:q>0,iconType:"arrowDown",numActiveFilters:q,numFilters:_.length,onClick:$},l),D=()=>{const e=(null!=_?_:[]).filter((e=>"on"===(null==e?void 0:e.checked))).map((({label:e})=>e)),l=(null!=_?_:[]).filter((e=>"off"===(null==e?void 0:e.checked))).map((({label:e})=>e)),t=(null!=x?x:[]).length>0||(null!=O?O:[]).length>0;return Object(c.isEqual)(null!=x?x:[],e)&&Object(c.isEqual)(null!=O?O:[],l)&&!(T!==V&&t)};return o.a.createElement(f,null,o.a.createElement(u.EuiPopover,{id:"popover",panelPaddingSize:"none",button:s||(v?W:N),isOpen:B||g,closePopover:()=>{A(!1),null==h||h(!1)},anchorPosition:y,style:{width:"100%"}},o.a.createElement(u.EuiSelectable,{searchable:!0,singleSelection:E,searchProps:{placeholder:r.i18n.translate("xpack.exploratoryView.fieldValueSelection.placeholder",{defaultMessage:"Filter {label}",values:{label:l}}),compressed:C,onInput:e=>{a(e.target.value)},"data-test-subj":"suggestionInputField"},listProps:{onFocusBadge:!1},options:_,onChange:e=>{P(e)},allowExclusions:j,isLoading:t&&!n&&0===_.length},((e,a)=>o.a.createElement("div",{style:{width:240}},o.a.createElement(u.EuiPopoverTitle,{paddingSize:"s"},a),e,t&&n&&o.a.createElement(u.EuiText,{className:"eui-textCenter",color:"subdued"},r.i18n.translate("xpack.exploratoryView.fieldValueSelection.loading",{defaultMessage:"Loading"})," ",o.a.createElement(u.EuiLoadingSpinner,{size:"m"})),o.a.createElement(u.EuiPopoverFooter,{paddingSize:"s"},F&&o.a.createElement(o.a.Fragment,null,o.a.createElement(u.EuiSpacer,{size:"xs"}),o.a.createElement(b,null,o.a.createElement(m,{label:r.i18n.translate("xpack.exploratoryView.fieldValueSelection.logicalAnd",{defaultMessage:"Use logical AND"}),"data-test-subj":"tagsLogicalOperatorSwitch",checked:Boolean(T),compressed:!0,onChange:e=>{z(e.target.checked)},$_css:L.size.s,$_css2:L.colors.subduedText})),o.a.createElement(u.EuiSpacer,{size:"m"})),o.a.createElement(u.EuiButton,{"data-test-subj":"o11yFieldValueSelectionApplyButton","aria-label":r.i18n.translate("xpack.exploratoryView.fieldValueSelection.apply.label",{defaultMessage:"Apply the selected filters for {label}",values:{label:l}}),fill:!0,fullWidth:!0,size:"s",isDisabled:D(),onClick:()=>{const e=_.filter((e=>"on"===(null==e?void 0:e.checked))),l=_.filter((e=>"off"===(null==e?void 0:e.checked)));F?k(Object(c.map)(e,"label"),Object(c.map)(l,"label"),T):k(Object(c.map)(e,"label"),Object(c.map)(l,"label")),A(!1),null==h||h(!1)}},r.i18n.translate("xpack.exploratoryView.fieldValueSelection.apply",{defaultMessage:"Apply"}))))))))}l.default=p;const f=a.a.div.withConfig({displayName:"Wrapper",componentId:"sc-1tl88yj-0"})(["&&&{div.euiPopover__anchor{width:100%;.euiButton{width:100%;}}}"]);var b=a()("div").withConfig({displayName:"_StyledDiv",componentId:"sc-1tl88yj-1"})({display:"flex",justifyContent:"flex-end"}),m=a()(u.EuiSwitch).withConfig({displayName:"_StyledEuiSwitch",componentId:"sc-1tl88yj-2"})((e=>({flexDirection:"row-reverse",gap:e.$_css,color:e.$_css2})))},66:function(e,l,t){"use strict";Object.defineProperty(l,"__esModule",{value:!0});var n=t(30),a=t(1),i=n.__importDefault(t(67));l.default=function(e,l,t){void 0===l&&(l=0),void 0===t&&(t=[]);var n=i.default(e,l),o=n[0],u=n[1],r=n[2];return a.useEffect(r,t),[o,u]}},67:function(e,l,t){"use strict";Object.defineProperty(l,"__esModule",{value:!0});var n=t(1);l.default=function(e,l){void 0===l&&(l=0);var t=n.useRef(!1),a=n.useRef(),i=n.useRef(e),o=n.useCallback((function(){return t.current}),[]),u=n.useCallback((function(){t.current=!1,a.current&&clearTimeout(a.current),a.current=setTimeout((function(){t.current=!0,i.current()}),l)}),[l]),r=n.useCallback((function(){t.current=null,a.current&&clearTimeout(a.current)}),[]);return n.useEffect((function(){i.current=e}),[e]),n.useEffect((function(){return u(),r}),[l]),[o,r,u]}},70:function(e,l,t){"use strict";t.r(l),t.d(l,"FieldValueSuggestions",(function(){return b}));var n=t(1),a=t.n(n),i=t(62),o=t(63),u=t(19),r=t(7),c=t(0),s=t(14);const d=(e,l)=>{const t=Array.from(new Set(l&&(null!=e?e:[]).length>0?["ALL_VALUES",...null!=e?e:[]]:e));return(null!=t?t:[]).map((e=>({label:e})))};function p({label:e,selectedValue:l,loading:t,values:i,setQuery:o,usePrependLabel:s=!0,compressed:p=!0,required:b=!0,singleSelection:m=!1,allowAllValuesSelection:g,onChange:h}){const[y,E]=Object(n.useState)((()=>{var e;return d(Object(u.union)(null!==(e=null==i?void 0:i.map((({label:e})=>e)))&&void 0!==e?e:[],null!=l?l:[]),g)}));Object(n.useEffect)((()=>{var e;E(d(Object(u.union)(null!==(e=null==i?void 0:i.map((({label:e})=>e)))&&void 0!==e?e:[],null!=l?l:[]),g))}),[g,l,i]);const v=a.a.createElement(r.EuiComboBox,{fullWidth:!0,singleSelection:!!m&&{asPlainText:!0},compressed:p,placeholder:c.i18n.translate("xpack.exploratoryView.fieldValueSelection.placeholder.search",{defaultMessage:"Search {label}",values:{label:e}}),isLoading:t,onSearchChange:e=>{o(e)},options:y,selectedOptions:y.filter((e=>null==l?void 0:l.includes(e.label))),onChange:e=>{h(e.map((({label:e})=>e)))},isInvalid:b&&Object(u.isEmpty)(l)});return s?a.a.createElement(f,null,a.a.createElement(r.EuiFormControlLayout,{fullWidth:!0,prepend:e,compressed:!0},v)):a.a.createElement(r.EuiFormRow,{label:e,display:"center",fullWidth:!0},v)}const f=t.n(s).a.div.withConfig({displayName:"ComboWrapper",componentId:"sc-1byw5y3-0"})(["&&&{.euiFormControlLayout{height:auto;.euiFormControlLayout__prepend{margin:auto;}.euiComboBoxPill{max-width:250px;}.euiComboBox__inputWrap{border-radius:0;}}}"]);function b({fullWidth:e,sourceField:l,label:t,dataViewTitle:u,selectedValue:r,excludedValue:c,filters:s,button:d,time:f,width:b,forceOpen:m,setForceOpen:g,anchorPosition:h,singleSelection:y,compressed:E,asFilterButton:v,usePrependLabel:w,allowAllValuesSelection:S,required:x,allowExclusions:O=!0,cardinalityField:j,inspector:C,asCombobox:V=!0,keepHistory:F=!0,showLogicalConditionSwitch:k,useLogicalAND:L,onChange:_}){const[P,B]=Object(n.useState)(""),{values:A,loading:T}=Object(i.a)({dataViewTitle:u,query:P,sourceField:l,filters:s,time:f,inspector:C,cardinalityField:j,keepHistory:F,label:t}),z=V?p:o.FieldValueSelection;return a.a.createElement(z,{fullWidth:e,singleSelection:y,values:A,label:t,onChange:_,query:P,setQuery:B,loading:T,selectedValue:r,excludedValue:c,button:d,forceOpen:m,setForceOpen:g,anchorPosition:h,width:b,compressed:E,asFilterButton:v,usePrependLabel:w,allowExclusions:O,allowAllValuesSelection:!y&&S,required:x,showLogicalConditionSwitch:k,useLogicalAND:L})}l.default=b}}]);