import{useMemo as e,useCallback as t}from"react";import n from"./useDropdownFiltering.js";import{useMultipleSelection as i,useCombobox as l}from"downshift";function o(o,s,u,r,a,p,d,g,c,I,m,f,h,v,O,P){var S=void 0!==d?d:s,b=n(o,v,O,S),M=b.filteredOptions,C=b.filterOptions,V=e((function(){return M.flatMap((function(e){return e.options}))}),[M]),w=i({selectedItems:S,initialSelectedItems:p,onSelectedItemsChange:function(e){var t=e.selectedItems;void 0===d&&u(t||[]),null==c||c(t||[])}}),T=w.getSelectedItemProps,j=w.getDropdownProps,x=w.addSelectedItem,y=w.removeSelectedItem,D=l({items:V,itemToString:function(e){var t;return null!==(t=null==e?void 0:e.label)&&void 0!==t?t:""},isItemDisabled:function(e){return!!e.disabled},isOpen:r,initialIsOpen:a,initialInputValue:g||"",id:P,onIsOpenChange:function(e){e.isOpen?null==f||f():null==m||m()},onInputValueChange:function(e){var t=e.inputValue;C(t||""),null==I||I(t)},onSelectedItemChange:function(e){var t=e.selectedItem;if(t){var n=S.find((function(e){return e.value===t.value}));n?y(n):x(t),null==h||h(t),C("")}},stateReducer:function(e,t){var n,i;switch(t.type){case l.stateChangeTypes.InputKeyDownEnter:case l.stateChangeTypes.ItemClick:return Object.assign(Object.assign({},t.changes),{inputValue:null,isOpen:!0,highlightedIndex:null!==(i=null===(n=t.changes.selectedItem)||void 0===n?void 0:n.index)&&void 0!==i?i:0});case l.stateChangeTypes.InputBlur:return Object.assign(Object.assign({},t.changes),{inputValue:null});default:return t.changes}}}),B=D.isOpen,L=D.inputValue,k=D.highlightedIndex,E=D.getToggleButtonProps,F=D.getLabelProps,K=D.getMenuProps,R=D.getInputProps,q=D.getItemProps,z=D.reset,A=D.openMenu,G=D.toggleMenu,H=D.closeMenu,J=t((function(){void 0===d&&u([]),z(),null==c||c([])}),[d,u,z,c]);return{isOpen:B,inputValue:L,highlightedIndex:k,selectedItems:S,getSelectedItemProps:T,getDropdownProps:j,addSelectedItem:x,getToggleButtonProps:E,getLabelProps:F,getMenuProps:K,getInputProps:R,getItemProps:q,reset:J,removeSelectedItem:y,filteredOptions:M,openMenu:A,toggleMenu:G,closeMenu:H}}export{o as default};
//# sourceMappingURL=useDropdownMultiCombobox.js.map
