"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.FocusControlWrapper = FocusControlWrapper;var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));

var _CommonWrapper = require("../CommonWrapper");

var _useFocusControl2 = require("./useFocusControl");var _excluded = ["disabled", "children", "onBlurWhenDisabled"];













function FocusControlWrapper(_ref) {var disabled = _ref.disabled,children = _ref.children,onBlurWhenDisabled = _ref.onBlurWhenDisabled,rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
  var isValidChildren = children && /*#__PURE__*/(0, _react.isValidElement)(children);

  var _useFocusControl = (0, _useFocusControl2.useFocusControl)({
      disabled: disabled != null ? disabled : isValidChildren ? children.props.disabled : undefined,
      onFocus: isValidChildren ? children.props.onFocus : undefined,
      onBlur: isValidChildren ? children.props.onBlur : undefined,
      onBlurWhenDisabled: onBlurWhenDisabled
    }),handleFocus = _useFocusControl.handleFocus,handleBlur = _useFocusControl.handleBlur;

  if (!isValidChildren) {
    return null;
  }

  return /*#__PURE__*/(
    _react.default.createElement(_CommonWrapper.CommonWrapper, rest,
    _react.default.Children.only( /*#__PURE__*/
      (0, _react.cloneElement)(children, {
        onFocus: handleFocus,
        onBlur: handleBlur
      })
    )
    ));

}

FocusControlWrapper.__KONTUR_REACT_UI__ = 'FocusControlWrapper';
FocusControlWrapper.displayName = 'FocusControlWrapper';