import { jsx as _jsx } from "react/jsx-runtime";
/* eslint-disable no-console */

import { useContext } from 'react';
import clsx from 'clsx';
import useMergedState from '../hooks/use-merged-state';
import RadioContext from './RadioContext';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

const RadioGroup = props => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace('radio-group', prefixCls);
  const [checked, setChecked] = useMergedState({
    value: props.value,
    defaultValue: props.defaultValue
  });

  const toggle = name => {
    var _a;

    setChecked(name);
    (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, name);
  };

  return _jsx(RadioContext.Provider, Object.assign({
    value: {
      parent: {
        props
      },
      toggle,
      checked
    }
  }, {
    children: _jsx("div", Object.assign({
      className: clsx(props.className, bem([props.direction])),
      style: props.style,
      role: "radiogroup"
    }, {
      children: props.children
    }))
  }));
};

export default RadioGroup;