import{slicedToArray as e}from"../../../../../_virtual/_rollupPluginBabelHelpers.js";import{useState as n,useMemo as t,useCallback as l}from"react";import{useCombobox as u}from"downshift";import i from"./useDropdownFiltering.js";function o(o,s,r,a,p,g,c,d,f,m,I,h,v,O,P){var b=n(p||null),M=e(b,2),T=M[1],y=void 0!==g?g:M[0],C=t((function(){return y?[y]:[]}),[y]),V=i(o,v,O,C),j=V.filteredOptions,w=V.filterOptions,B=t((function(){return j.flatMap((function(e){return e.options}))}),[j]),x=u({items:B,itemToString:function(e){var n;return null!==(n=null==e?void 0:e.label)&&void 0!==n?n:""},itemToKey:function(e){return void 0!==(null==e?void 0:e.value)?e.value+"":""},isItemDisabled:function(e){return!!e.disabled},initialInputValue:c||"",selectedItem:y,isOpen:s,initialIsOpen:r,id:P,onIsOpenChange:function(e){e.isOpen?null==I||I():null==m||m()},onInputValueChange:l((function(e){var n=e.inputValue;w(n||""),null==f||f(n)}),[f,w]),onSelectedItemChange:l((function(e){var n=e.selectedItem;void 0===g&&T(n||null),n?(null==h||h(n),null==d||d(n),w("")):(null==d||d(null),w(""))}),[g,h,w,d]),stateReducer:function(e,n){switch(n.type){case u.stateChangeTypes.InputKeyDownEnter:case u.stateChangeTypes.ItemClick:return Object.assign(Object.assign({},n.changes),{inputValue:null,isOpen:!a});case u.stateChangeTypes.InputBlur:return Object.assign(Object.assign({},n.changes),{inputValue:null});default:return n.changes}}}),D=x.reset;return{isOpen:x.isOpen,inputValue:x.inputValue,highlightedIndex:x.highlightedIndex,selectedItem:y,getToggleButtonProps:x.getToggleButtonProps,getLabelProps:x.getLabelProps,getMenuProps:x.getMenuProps,getInputProps:x.getInputProps,getItemProps:x.getItemProps,reset:function(){void 0===g&&T(null),D(),w("")},filteredOptions:j,openMenu:x.openMenu,toggleMenu:x.toggleMenu,closeMenu:x.closeMenu}}export{o as default};
//# sourceMappingURL=useDropdownCombobox.js.map
