/**
 * Support Form Component to focus when inline errors happen and guarantee focus order.
 * @param {*} Component
 */
'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.FormErrorAutoFocusContainer = void 0;

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var FormErrorAutoFocusContainer =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(FormErrorAutoFocusContainer, _React$Component);

  function FormErrorAutoFocusContainer(props, context) {
    var _this;

    _this = _React$Component.call(this, props, context) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getNeededAutoFocus", function () {
      return _this.isNeededAutoFocus;
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setNeededAutoFocus", function (value) {
      _this.isNeededAutoFocus = value;
    });
    _this.isNeededAutoFocus = false;
    return _this;
  }

  var _proto = FormErrorAutoFocusContainer.prototype;

  _proto.getChildContext = function getChildContext() {
    return {
      setNeededAutoFocus: this.context.setNeededAutoFocus || this.setNeededAutoFocus,
      getNeededAutoFocus: this.context.getNeededAutoFocus || this.getNeededAutoFocus
    };
  };

  _proto.render = function render() {
    var children = this.props.children;

    if (!children) {
      return null;
    }

    if (Array.isArray(children)) {
      return _react.default.createElement("div", {
        "data-test-automation-id": this.props.testAutomationId
      }, children);
    }

    return children;
  };

  return FormErrorAutoFocusContainer;
}(_react.default.Component);

exports.FormErrorAutoFocusContainer = FormErrorAutoFocusContainer;
(0, _defineProperty2.default)(FormErrorAutoFocusContainer, "propTypes", {
  children: _propTypes.default.node,
  testAutomationId: _propTypes.default.string
});
(0, _defineProperty2.default)(FormErrorAutoFocusContainer, "defaultProps", {
  children: null,
  testAutomationId: null
});
(0, _defineProperty2.default)(FormErrorAutoFocusContainer, "contextTypes", {
  getNeededAutoFocus: _propTypes.default.func,
  setNeededAutoFocus: _propTypes.default.func
});
(0, _defineProperty2.default)(FormErrorAutoFocusContainer, "childContextTypes", {
  getNeededAutoFocus: _propTypes.default.func,
  setNeededAutoFocus: _propTypes.default.func
});