text: import { useCallback, useMemo } from "react";
  import { DEFAULT_VALUE_KEY, DEFAULT_GET_ITEM_VALUE, DEFAULT_SEARCH_RESET_TIME, } from "./utils";
  import DEFAULT_FIND_MATCH_INDEX from "./findMatchIndex";
  import useTempValue from "../useTempValue";
  /**
   * Adds the accessibility functionality to search a list of items as the user
   * types to trigger `aria-activedescendant` focus or manual DOM focus events.
   */
  export default function useKeyboardSearch(_a) {
      var items = _a.items, onChange = _a.onChange, onKeyDown = _a.onKeyDown, _b = _a.resetTime, resetTime = _b === void 0 ? DEFAULT_SEARCH_RESET_TIME : _b, searchIndex = _a.searchIndex, _c = _a.valueKey, valueKey = _c === void 0 ? DEFAULT_VALUE_KEY : _c, _d = _a.getItemValue, getItemValue = _d === void 0 ? DEFAULT_GET_ITEM_VALUE : _d, _e = _a.findMatchIndex, findMatchIndex = _e === void 0 ? DEFAULT_FIND_MATCH_INDEX : _e;
      var _f = useTempValue("", resetTime), value = _f[0], setValue = _f[1];
      var values = useMemo(function () { return items.map(function (item) { return getItemValue(item, valueKey); }); }, [items, getItemValue, valueKey]);
      var handleKeyDown = useCallback(function (event) {
          if (onKeyDown) {
              onKeyDown(event);
          }
          var key = event.key, altKey = event.altKey, ctrlKey = event.ctrlKey, metaKey = event.metaKey;
          if (altKey ||
              ctrlKey ||
              metaKey ||
              key.length > 1 ||
              (!value.current && key === " ")) {
              // might need to change this later if other languages have non-meta keys
              // that are more than 1 letter
              return;
          }
          var nextValue = key;
          if (value.current !== key) {
              nextValue = "" + value.current + key;
          }
          setValue(nextValue);
          var index = findMatchIndex(nextValue, values, searchIndex, true);
          // don't want to trigger change events if the search didn't match anything
          // since you normally don't really care about failed matches
          if (index === searchIndex || index === -1) {
              return;
          }
          var data = {
              index: index,
              item: items[index],
              items: items,
              query: nextValue,
              target: event.currentTarget,
          };
          onChange(data);
      }, [
          searchIndex,
          findMatchIndex,
          items,
          onChange,
          onKeyDown,
          setValue,
          value,
          values,
      ]);
      return handleKeyDown;
  }
  //# sourceMappingURL=useKeyboardSearch.js.map