import { useCallback, useRef } from 'react';
export function useToggleButton(inputRef) {
  var buttonRef = useRef(null);
  function focusToggleButton() {
    var _buttonRef$current;
    (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.focus();
  }
  var onInputEscapeKeyHandler = useCallback(function (e) {
    if (e.key === 'Escape') {
      var _buttonRef$current2;
      (_buttonRef$current2 = buttonRef.current) === null || _buttonRef$current2 === void 0 ? void 0 : _buttonRef$current2.focus();
    }
  }, []);
  var onToggleButtonKeyDownHandler = useCallback(function (e) {
    if (e.key === 'ArrowDown') {
      var _inputRef$current;
      (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
    }
  }, [inputRef]);
  return {
    buttonRef: buttonRef,
    focusToggleButton: focusToggleButton,
    onInputEscapeKeyHandler: onInputEscapeKeyHandler,
    onToggleButtonKeyDownHandler: onToggleButtonKeyDownHandler
  };
}