"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

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

var React = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _components = require("../components");

var _ref = require("../components/rc-util/ref");

var _context = require("../config-provider/context");

var _context2 = _interopRequireDefault(require("./context"));

var InternalRadio = function InternalRadio(props, ref) {
  var context = React.useContext(_context2.default);

  var _React$useContext = React.useContext(_context.ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var innerRef = React.useRef();
  var mergedRef = (0, _ref.composeRef)(ref, innerRef);

  var handleChange = function handleChange(evt) {
    var _props$onChange, _context$onChange;

    (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, evt);
    context === null || context === void 0 ? void 0 : (_context$onChange = context.onChange) === null || _context$onChange === void 0 ? void 0 : _context$onChange.call(context, evt);
  };

  var className = props.className,
      children = props.children,
      style = props.style,
      prefixCls = props.prefixCls,
      restProps = (0, _objectWithoutProperties2.default)(props, ["className", "children", "style", "prefixCls"]);
  var radioCls = getPrefixClassName('radio', prefixCls);
  var radioProps = (0, _objectSpread2.default)({}, restProps);

  if (context) {
    radioProps.name = context.name;
    radioProps.onChange = handleChange;
    radioProps.checked = props.value === context.value;
    radioProps.disabled = props.disabled || context.disabled;
  }

  return /*#__PURE__*/React.createElement("label", {
    className: (0, _classnames.default)("".concat(radioCls, "-wrapper"), radioProps.checked && "".concat(radioCls, "-wrapper-checked"), radioProps.disabled && "".concat(radioCls, "-wrapper-disabled"), radioProps.showType && "".concat(radioCls, "-wrapper-show-type-").concat(radioProps.showType), className),
    style: style,
    onMouseEnter: props.onMouseEnter,
    onMouseLeave: props.onMouseLeave
  }, /*#__PURE__*/React.createElement(_components.RcCheckbox, Object.assign({}, radioProps, {
    prefixCls: radioCls,
    ref: mergedRef
  })), children !== undefined ? /*#__PURE__*/React.createElement("span", null, children) : null);
};

var Radio = /*#__PURE__*/React.forwardRef(InternalRadio);
Radio.displayName = 'Radio';
Radio.defaultProps = {
  type: 'radio'
};
var _default = Radio;
exports.default = _default;