"use strict";

exports.__esModule = true;
exports.useAutoFocusAndSelect = useAutoFocusAndSelect;
var _react = require("react");
function useAutoFocusAndSelect(_ref) {
  var {
    autoFocus,
    autoSelect,
    onFocus,
    onBlur,
    localInputRef,
    value
  } = _ref;
  var [isFocused, setIsFocused] = (0, _react.useState)(false);
  var autoFocusTriggered = (0, _react.useRef)(false);
  var _onFocus = (0, _react.useCallback)(event => {
    setIsFocused(true);
    if (autoSelect) {
      var _localInputRef$curren;
      (_localInputRef$curren = localInputRef.current) == null || _localInputRef$curren.select();
    }
    onFocus == null || onFocus(event);
  }, [onFocus, localInputRef, autoSelect]);
  var _onBlur = (0, _react.useCallback)(event => {
    setIsFocused(false);
    onBlur == null || onBlur(event);
  }, [onBlur]);
  (0, _react.useEffect)(() => {
    if (autoFocus && !autoFocusTriggered.current && localInputRef.current) {
      localInputRef.current.focus();
      if (autoSelect) {
        localInputRef.current.select();
      } else if (value !== undefined) {
        var length = String(value).length;
        localInputRef.current.setSelectionRange(length, length);
      }
      autoFocusTriggered.current = true;
    }
  }, [autoFocus, autoSelect, localInputRef, value]);
  return {
    isFocused,
    _onFocus,
    _onBlur
  };
}
//# sourceMappingURL=useAutoFocusAndSelect.js.map