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,u,s,r,a,p,d,g,c,m,I,f,v,h,O,P){var S=void 0!==d?d:u,b=n(o,h,O,S),M=b.filteredOptions,C=b.filterOptions,T=e((function(){return M.flatMap((function(e){return e.options}))}),[M]),V=i({selectedItems:S,initialSelectedItems:p,onSelectedItemsChange:function(e){var t=e.selectedItems;void 0===d&&s(t||[]),null==c||c(t||[])}}),w=V.getSelectedItemProps,y=V.getDropdownProps,j=V.addSelectedItem,x=V.removeSelectedItem,D=l({items:T,itemToString:function(e){var t;return null!==(t=null==e?void 0:e.label)&&void 0!==t?t:""},itemToKey:function(e){return void 0!==(null==e?void 0:e.value)?e.value+"":""},isItemDisabled:function(e){return!!e.disabled},isOpen:r,initialIsOpen:a,initialInputValue:g||"",id:P,onIsOpenChange:function(e){e.isOpen?null==f||f():null==I||I()},onInputValueChange:function(e){var t=e.inputValue;C(t||""),null==m||m(t)},onSelectedItemChange:function(e){var t=e.selectedItem;if(t){var n=S.find((function(e){return e.value===t.value}));n?x(n):j(t),null==v||v(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,K=D.inputValue,L=D.highlightedIndex,k=D.getToggleButtonProps,E=D.getLabelProps,F=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&&s([]),z(),null==c||c([])}),[d,s,z,c]);return{isOpen:B,inputValue:K,highlightedIndex:L,selectedItems:S,getSelectedItemProps:w,getDropdownProps:y,addSelectedItem:j,getToggleButtonProps:k,getLabelProps:E,getMenuProps:F,getInputProps:R,getItemProps:q,reset:J,removeSelectedItem:x,filteredOptions:M,openMenu:A,toggleMenu:G,closeMenu:H}}export{o as default};
//# sourceMappingURL=useDropdownMultiCombobox.js.map
