/* eslint-disable no-console */
import React, { useContext } from 'react';
import clsx from 'clsx';
import useMergedState from '../hooks/use-merged-state';
import RadioContext from './RadioContext';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

var RadioGroup = function RadioGroup(props) {
  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('radio-group', prefixCls),
      bem = _createNamespace[0];

  var _useMergedState = useMergedState({
    value: props.value,
    defaultValue: props.defaultValue
  }),
      checked = _useMergedState[0],
      setChecked = _useMergedState[1];

  var toggle = function toggle(name) {
    setChecked(name);
    props.onChange == null ? void 0 : props.onChange(name);
  };

  return /*#__PURE__*/React.createElement(RadioContext.Provider, {
    value: {
      parent: {
        props: props
      },
      toggle: toggle,
      checked: checked
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: clsx(props.className, bem([props.direction])),
    style: props.style,
    role: "radiogroup"
  }, props.children));
};

export default RadioGroup;