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