import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _excluded = ["disabled", "children", "onBlurWhenDisabled"];
import React, { isValidElement, cloneElement } from 'react';
import { CommonWrapper } from "../../CommonWrapper";
import { useFocusControl } from "../useFocusControl";
export function FocusControlWrapper(_ref) {
  var disabled = _ref.disabled,
    children = _ref.children,
    onBlurWhenDisabled = _ref.onBlurWhenDisabled,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var isValidChildren = children && /*#__PURE__*/isValidElement(children);
  var _useFocusControl = 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.createElement(CommonWrapper, rest, React.Children.only( /*#__PURE__*/
    cloneElement(children, {
      onFocus: handleFocus,
      onBlur: handleBlur
    })))
  );
}
FocusControlWrapper.__KONTUR_REACT_UI__ = 'FocusControlWrapper';
FocusControlWrapper.displayName = 'FocusControlWrapper';