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

import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
export var FormErrorAutoFocusContainer =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(FormErrorAutoFocusContainer, _React$Component);

  function FormErrorAutoFocusContainer(props, context) {
    var _this;

    _this = _React$Component.call(this, props, context) || this;

    _defineProperty(_assertThisInitialized(_this), "getNeededAutoFocus", function () {
      return _this.isNeededAutoFocus;
    });

    _defineProperty(_assertThisInitialized(_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.createElement("div", {
        "data-test-automation-id": this.props.testAutomationId
      }, children);
    }

    return children;
  };

  return FormErrorAutoFocusContainer;
}(React.Component);

_defineProperty(FormErrorAutoFocusContainer, "propTypes", {
  children: PropTypes.node,
  testAutomationId: PropTypes.string
});

_defineProperty(FormErrorAutoFocusContainer, "defaultProps", {
  children: null,
  testAutomationId: null
});

_defineProperty(FormErrorAutoFocusContainer, "contextTypes", {
  getNeededAutoFocus: PropTypes.func,
  setNeededAutoFocus: PropTypes.func
});

_defineProperty(FormErrorAutoFocusContainer, "childContextTypes", {
  getNeededAutoFocus: PropTypes.func,
  setNeededAutoFocus: PropTypes.func
});