import { __assign } from "tslib";
import React, { useContext, cloneElement } from "react";
import RadioButton from "../../RadioButton";
import { RadioGroupContext } from "./RadioGroupContext";
var RadioGroupOption = function (props) {
    var label = props.label, name = props.name, value = props.value, isDisabled = props.isDisabled, isError = props.isError, className = props.className, children = props.children;
    var _a = useContext(RadioGroupContext), groupValue = _a.groupValue, onClick = _a.onClick, onChange = _a.onChange;
    if (children) {
        return cloneElement(children, __assign(__assign({}, children.props), { isChecked: children.props.value === groupValue, isError: children.props.value !== groupValue && isError, onChange: onChange, onClick: onClick, name: name, isDisabled: children.props.isDisabled || isDisabled }));
    }
    return (React.createElement(RadioButton, { isChecked: value === groupValue, name: name, isDisabled: isDisabled, isError: value !== groupValue && isError, label: label, value: value, onChange: onChange, onClick: onClick, className: className }));
};
export default RadioGroupOption;
