"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useAutofocus = exports.default = void 0;
var _compat = require("preact/compat");
/**
 * Returns a ref and will focus on the element that ref is attached to
 * if the `autoFocus` boolean parameter is truthy.
 */
var useAutofocus = function useAutofocus(autoFocus) {
  var ref = (0, _compat.useRef)();
  (0, _compat.useEffect)(function () {
    var _ref$current;
    if (autoFocus && (_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.focus) {
      var _ref$current2;
      (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
    }
  }, [ref, autoFocus]);
  return ref;
};
exports.useAutofocus = useAutofocus;
var _default = useAutofocus;
exports.default = _default;