/**
 * Support Form Component to focus when inline errors happen and guarantee focus order.
 * @param {*} Component
 */
'use strict';
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var FormErrorAutoFocusContainer = /** @class */ (function (_super) {
    __extends(FormErrorAutoFocusContainer, _super);
    function FormErrorAutoFocusContainer(props, context) {
        var _this = _super.call(this, props, context) || this;
        _this.getNeededAutoFocus = function () { return _this.isNeededAutoFocus; };
        /**
         * Set isNeededAutoFocus to 'true' when Form need focus.
         * @param {boolean} value
         */
        _this.setNeededAutoFocus = function (value) {
            _this.isNeededAutoFocus = value;
        };
        _this.isNeededAutoFocus = false;
        return _this;
    }
    FormErrorAutoFocusContainer.prototype.getChildContext = function () {
        return {
            setNeededAutoFocus: this.context.setNeededAutoFocus || this.setNeededAutoFocus,
            getNeededAutoFocus: this.context.getNeededAutoFocus || this.getNeededAutoFocus
        };
    };
    FormErrorAutoFocusContainer.prototype.render = function () {
        var children = this.props.children;
        if (!children) {
            return null;
        }
        if (Array.isArray(children)) {
            return react_1.default.createElement("div", { "data-test-automation-id": this.props.testAutomationId }, children);
        }
        return children;
    };
    FormErrorAutoFocusContainer.propTypes = {
        children: prop_types_1.default.node,
        testAutomationId: prop_types_1.default.string
    };
    FormErrorAutoFocusContainer.defaultProps = {
        children: null,
        testAutomationId: null
    };
    FormErrorAutoFocusContainer.contextTypes = {
        getNeededAutoFocus: prop_types_1.default.func,
        setNeededAutoFocus: prop_types_1.default.func
    };
    FormErrorAutoFocusContainer.childContextTypes = {
        getNeededAutoFocus: prop_types_1.default.func,
        setNeededAutoFocus: prop_types_1.default.func
    };
    return FormErrorAutoFocusContainer;
}(react_1.default.Component));
exports.FormErrorAutoFocusContainer = FormErrorAutoFocusContainer;
//# sourceMappingURL=FormErrorAutoFocusContainer.js.map