import { __assign, __rest } from "tslib";
import React, { useContext, useEffect, useState } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { RadioGroupContext } from './radio-group-context';
var RadioGroup = React.forwardRef(function (props, ref) {
    var _a = props.defaultValue, defaultValue = _a === void 0 ? '' : _a, _b = props.disabled, disabled = _b === void 0 ? false : _b, name = props.name, onChange = props.onChange, className = props.className, children = props.children, customisedCls = props.prefixCls, otherProps = __rest(props, ["defaultValue", "disabled", "name", "onChange", "className", "children", "prefixCls"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('radio-group', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className);
    var _c = useState('value' in props ? props.value : defaultValue), value = _c[0], setValue = _c[1];
    var radioOnChange = function (e) {
        if (!disabled) {
            var val = e.currentTarget.value;
            !('value' in props) && setValue(val);
            onChange && onChange(val);
        }
    };
    useEffect(function () {
        'value' in props && setValue(props.value);
    }, [props]);
    return (React.createElement(RadioGroupContext.Provider, { value: {
            name: name,
            disabled: disabled,
            value: value,
            onChange: radioOnChange,
        } },
        React.createElement("div", __assign({}, otherProps, { ref: ref, role: "radiogroup", className: cls }), children)));
});
RadioGroup.displayName = 'RadioGroup';
export default RadioGroup;
//# sourceMappingURL=radio-group.js.map