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 s(s,o,r,a,p,g,c,d,f,m,I,h,O,P,b){var v=n(p||null),M=e(v,2),C=M[1],T=void 0!==g?g:M[0],V=t((function(){return T?[T]:[]}),[T]),j=i(s,O,P,V),y=j.filteredOptions,w=j.filterOptions,B=t((function(){return y.flatMap((function(e){return e.options}))}),[y]),x=u({items:B,itemToString:function(e){var n;return null!==(n=null==e?void 0:e.label)&&void 0!==n?n:""},isItemDisabled:function(e){return!!e.disabled},initialInputValue:c||"",selectedItem:T,isOpen:o,initialIsOpen:r,id:b,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&&C(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:T,getToggleButtonProps:x.getToggleButtonProps,getLabelProps:x.getLabelProps,getMenuProps:x.getMenuProps,getInputProps:x.getInputProps,getItemProps:x.getItemProps,reset:function(){void 0===g&&C(null),D(),w("")},filteredOptions:y,openMenu:x.openMenu,toggleMenu:x.toggleMenu,closeMenu:x.closeMenu}}export{s as default};
//# sourceMappingURL=useDropdownCombobox.js.map
