import { __assign, __rest } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import cx from 'classnames';
import getWidth from '../utils/getWidth';
import { getRadioState, useRadioHandler } from './AbstractRadio';
import RadioGroup from './Group';
import RadioButton from './RadioButton';
import { DisabledContext } from '../disabled';
import GroupContext from './GroupContext';
import { useContext } from 'react';
function Radio(props) {
    var className = props.className, style = props.style, children = props.children, value = props.value, width = props.width, labelStyle = props.labelStyle, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, others = __rest(props, ["className", "style", "children", "value", "width", "labelStyle", "onMouseEnter", "onMouseLeave"]);
    var disabledCtx = useContext(DisabledContext);
    var groupCtx = useContext(GroupContext);
    var _a = getRadioState(disabledCtx, groupCtx, props), checked = _a.checked, disabled = _a.disabled, readOnly = _a.readOnly;
    var onChange = useRadioHandler(groupCtx, props);
    var classString = cx(className, 'zent-radio-wrap', {
        'zent-radio-checked': !!checked,
        'zent-radio-disabled': disabled || readOnly,
    });
    var widthStyle = getWidth(width);
    var wrapStyle = __assign(__assign({}, style), widthStyle);
    return (_jsxs("label", __assign({ className: classString, style: wrapStyle, onMouseEnter: props.onMouseEnter, onMouseLeave: props.onMouseLeave, "data-zv": 'v10.0.12' }, { children: [_jsxs("span", __assign({ className: "zent-radio", "data-zv": 'v10.0.12' }, { children: [_jsx("span", { className: "zent-radio-inner", "data-zv": 'v10.0.12' }, void 0), _jsx("input", __assign({}, others, { type: "radio", checked: !!checked, disabled: disabled, readOnly: readOnly, onChange: onChange, "data-zv": 'v10.0.12' }), void 0)] }), void 0), children !== undefined && (_jsx("span", __assign({ className: "zent-radio-label", style: labelStyle, "data-zv": 'v10.0.12' }, { children: children }), void 0))] }), void 0));
}
Radio.Button = RadioButton;
Radio.Group = RadioGroup;
export { Radio };
export default Radio;
