import * as tslib_1 from "tslib";
import React, { useEffect, useState } from 'react';
import classnames from 'classnames';
var defaultProps = {
    prefixCls: 'ty-radio-group',
};
var RadioGroup = function (props) {
    var name = props.name, onChange = props.onChange, disabled = props.disabled, prefixCls = props.prefixCls, className = props.className, style = props.style, children = props.children;
    var cls = classnames(prefixCls, className);
    var _a = useState(('value' in props) ? props.value : props.defaultValue), value = _a[0], setValue = _a[1];
    var _onChange = function (checked, e) {
        if (!disabled) {
            !('value' in props) && setValue(e.currentTarget.value);
            onChange && onChange(e.currentTarget.value, e);
        }
    };
    useEffect(function () {
        ('value' in props) && setValue(props.value);
    });
    return (React.createElement("div", { className: cls, style: style }, React.Children.map(children, function (child) {
        var childProps = tslib_1.__assign({}, child.props, { name: name, disabled: child.props.disabled || disabled, checked: value === child.props.value, onChange: _onChange });
        return React.cloneElement(child, childProps);
    })));
};
RadioGroup.defaultProps = defaultProps;
export default RadioGroup;
//# sourceMappingURL=radio-group.js.map