import { useEffect, useState } from 'react';
export function useFocusControl(_ref) {
  var disabled = _ref.disabled,
    onFocus = _ref.onFocus,
    onBlur = _ref.onBlur,
    onBlurWhenDisabled = _ref.onBlurWhenDisabled;
  var _useState = useState(false),
    isFocused = _useState[0],
    setFocused = _useState[1];
  useEffect(function () {
    if (disabled && isFocused && onBlurWhenDisabled) {
      // force calling custom blur event, try "fix" bug in react https://github.com/facebook/react/issues/9142
      onBlurWhenDisabled();
    }
  }, [disabled, isFocused]);
  var handleFocus = function handleFocus(e) {
    setFocused(true);
    onFocus == null || onFocus(e);
  };
  var handleBlur = function handleBlur(e) {
    setFocused(false);
    onBlur == null || onBlur(e);
  };
  return {
    handleFocus: handleFocus,
    handleBlur: handleBlur
  };
}