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