/*! 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([[8],{63:function(e,l,t){"use strict";t.r(l),t.d(l,"FieldValueSelection",(function(){return p}));var a=t(14),i=t.n(a),n=t(1),o=t.n(n),s=t(7),c=t(0),u=t(19);const r=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,a)=>{const i={};return null==e||e.forEach((({label:e,count:l})=>{i[e]=l})),Object.entries(i).map((([e,i])=>({label:e,append:a?o.a.createElement(r,null,o.a.createElement(s.EuiText,{size:"xs"},i)):null,...null!=l&&l.includes(e)?{checked:"on"}:{},...null!=t&&t.includes(e)?{checked:"off"}:{}})))};function p({fullWidth:e,label:l,loading:t,query:a,setQuery:i,button:r,width:p,forceOpen:g,setForceOpen:m,anchorPosition:E,singleSelection:w,asFilterButton:y,showCount:S=!0,values:x=[],selectedValue:v,excludedValue:j,allowExclusions:O=!0,compressed:k=!0,useLogicalAND:V,showLogicalConditionSwitch:C=!1,onChange:F}){const{euiTheme:_}=Object(s.useEuiTheme)(),[z,B]=Object(n.useState)((()=>d(x,v,j,S))),[P,A]=Object(n.useState)(!1),[N,T]=Object(n.useState)(V);Object(n.useEffect)((()=>{T(V)}),[V]),Object(n.useEffect)((()=>{B(d(x,v,j,S))}),[JSON.stringify(x),JSON.stringify(v),S,j]);const D=()=>{A(!P)},L=o.a.createElement(s.EuiButton,{style:p?{width:p}:{},size:"m",color:"text",iconType:"arrowDown",iconSide:"right",onClick:D,"data-test-subj":"fieldValueSelectionBtn",fullWidth:e},l),$=(v||[]).length+(j||[]).length,M=o.a.createElement(s.EuiFilterButton,{"aria-label":c.i18n.translate("xpack.exploratoryView.filterButton.label",{defaultMessage:"expands filter group for {label} filter",values:{label:l}}),hasActiveFilters:$>0,iconType:"arrowDown",numActiveFilters:$,numFilters:z.length,onClick:D},l),I=()=>{const e=(null!=z?z:[]).filter((e=>"on"===(null==e?void 0:e.checked))).map((({label:e})=>e)),l=(null!=z?z:[]).filter((e=>"off"===(null==e?void 0:e.checked))).map((({label:e})=>e)),t=(null!=v?v:[]).length>0||(null!=j?j:[]).length>0;return Object(u.isEqual)(null!=v?v:[],e)&&Object(u.isEqual)(null!=j?j:[],l)&&!(N!==V&&t)};return o.a.createElement(h,null,o.a.createElement(s.EuiPopover,{id:"popover",panelPaddingSize:"none",button:r||(y?M:L),isOpen:P||g,closePopover:()=>{A(!1),null==m||m(!1)},anchorPosition:E,style:{width:"100%"}},o.a.createElement(s.EuiSelectable,{searchable:!0,singleSelection:w,searchProps:{placeholder:c.i18n.translate("xpack.exploratoryView.fieldValueSelection.placeholder",{defaultMessage:"Filter {label}",values:{label:l}}),compressed:k,onInput:e=>{i(e.target.value)},"data-test-subj":"suggestionInputField"},listProps:{onFocusBadge:!1},options:z,onChange:e=>{B(e)},allowExclusions:O,isLoading:t&&!a&&0===z.length},((e,i)=>o.a.createElement("div",{style:{width:240}},o.a.createElement(s.EuiPopoverTitle,{paddingSize:"s"},i),e,t&&a&&o.a.createElement(s.EuiText,{className:"eui-textCenter",color:"subdued"},c.i18n.translate("xpack.exploratoryView.fieldValueSelection.loading",{defaultMessage:"Loading"})," ",o.a.createElement(s.EuiLoadingSpinner,{size:"m"})),o.a.createElement(s.EuiPopoverFooter,{paddingSize:"s"},C&&o.a.createElement(o.a.Fragment,null,o.a.createElement(s.EuiSpacer,{size:"xs"}),o.a.createElement(f,null,o.a.createElement(b,{label:c.i18n.translate("xpack.exploratoryView.fieldValueSelection.logicalAnd",{defaultMessage:"Use logical AND"}),"data-test-subj":"tagsLogicalOperatorSwitch",checked:Boolean(N),compressed:!0,onChange:e=>{T(e.target.checked)},$_css:_.size.s,$_css2:_.colors.subduedText})),o.a.createElement(s.EuiSpacer,{size:"m"})),o.a.createElement(s.EuiButton,{"data-test-subj":"o11yFieldValueSelectionApplyButton","aria-label":c.i18n.translate("xpack.exploratoryView.fieldValueSelection.apply.label",{defaultMessage:"Apply the selected filters for {label}",values:{label:l}}),fill:!0,fullWidth:!0,size:"s",isDisabled:I(),onClick:()=>{const e=z.filter((e=>"on"===(null==e?void 0:e.checked))),l=z.filter((e=>"off"===(null==e?void 0:e.checked)));C?F(Object(u.map)(e,"label"),Object(u.map)(l,"label"),N):F(Object(u.map)(e,"label"),Object(u.map)(l,"label")),A(!1),null==m||m(!1)}},c.i18n.translate("xpack.exploratoryView.fieldValueSelection.apply",{defaultMessage:"Apply"}))))))))}l.default=p;const h=i.a.div.withConfig({displayName:"Wrapper",componentId:"sc-1tl88yj-0"})(["&&&{div.euiPopover__anchor{width:100%;.euiButton{width:100%;}}}"]);var f=i()("div").withConfig({displayName:"_StyledDiv",componentId:"sc-1tl88yj-1"})({display:"flex",justifyContent:"flex-end"}),b=i()(s.EuiSwitch).withConfig({displayName:"_StyledEuiSwitch",componentId:"sc-1tl88yj-2"})((e=>({flexDirection:"row-reverse",gap:e.$_css,color:e.$_css2})))}}]);