"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("../../hooks/useMultiSelectDraftValue.js"),i=require("../VirtualizedListBox/VirtualizedListBox.js"),l=require("../../Filter.module.css.js"),r=require("../../../../../../componentsV2/Autocomplete/Autocomplete.js"),o=require("../../../../../../componentsV2/Chip/Chip.js"),u=require("../../../../../../componentsV2/TextMiddleTruncated/TextMiddleTruncated.js");require("../../../../../../componentsV2/TextMiddleTruncated/TextMiddleTruncated.constants.js");var a=require("../../../../../../effects/useOutsideClick.js"),s=function(s){var c=s.label,d=s.options,p=s.value,f=s.onChange,m=s.renderOptionPrefix,x=s.testId,C=s.dropdownClassName,j=s.loading,h=s.disabled,v=t.useMemo((function(){return d.map((function(e){return{id:e.id,title:e.title,prefix:null==m?void 0:m(e)}}))}),[d,m]),b=t.useMemo((function(){return v.map((function(e){return e.id}))}),[v]),M=t.useRef(null),T=n.useMultiSelectDraftValue({value:p,optionIds:b,onChange:f}),q=T.value,k=T.onChange,V=T.startInteraction,N=T.endInteraction;a(M,(function(){return N()}),[".MuiAutocomplete-popper"]),t.useEffect((function(){h&&N()}),[h,N]);var g=t.useCallback((function(){h||V()}),[h,V]),y=t.useCallback((function(e){var t=e.map((function(e){return e.id}));k(t)}),[k]),A=t.useCallback((function(e){return function(t){t.stopPropagation(),k([e])}}),[k]),I=t.useCallback((function(t){return e.jsxs("div",{className:l.optionRow,children:[e.jsx(u.TextMiddleTruncated,{className:l.optionTitle,children:t.title}),e.jsx(o.Chip,{state:"neutral",size:"small",shape:"square",className:l.onlyButton,onClick:A(t.id),children:"Only"})]})}),[A]),O=t.useCallback((function(e){"Escape"!==e.key&&"Tab"!==e.key||N()}),[N]);return e.jsx("div",{ref:M,onFocusCapture:g,onKeyDownCapture:O,children:e.jsx(r.AutocompleteNext,{label:c,options:v,value:h?[]:q,onChange:y,renderOption:I,multiple:!0,useAllOption:!0,clearable:!1,testId:x,dropdownClassName:C,listboxComponent:i.VirtualizedListBox,elementsClassNames:{input:l.filterInput},loading:j,disabled:h,placeholder:h?"All":void 0})})};s.displayName="MultiFilterSelect",exports.MultiFilterSelect=s;
//# sourceMappingURL=MultiFilterSelect.js.map
