import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useCallback } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import RadioContext from "./context";
import Radio from "../radio/index";
import { usePropsValue } from "../../hooks/use-props-value";
var defaultProps = {
    labelPosition: 'right',
    onChange: function(value) {},
    direction: 'vertical',
    options: []
};
var classPrefix = 'nut-radiogroup';
export var RadioGroup = /*#__PURE__*/ React.forwardRef(function(props, ref) {
    var _ref = _object_spread({}, defaultProps, props), children = _ref.children, className = _ref.className, value = _ref.value, defaultValue = _ref.defaultValue, onChange = _ref.onChange, shape = _ref.shape, labelPosition = _ref.labelPosition, direction = _ref.direction, options = _ref.options, disabled = _ref.disabled, rest = _object_without_properties(_ref, [
        "children",
        "className",
        "value",
        "defaultValue",
        "onChange",
        "shape",
        "labelPosition",
        "direction",
        "options",
        "disabled"
    ]);
    var cls = classNames(classPrefix, _define_property({}, "".concat(classPrefix, "-").concat(direction), direction), className);
    var _usePropsValue = _sliced_to_array(usePropsValue({
        defaultValue: props.defaultValue,
        value: props.value,
        finalValue: '',
        onChange: onChange
    }), 2), val2State = _usePropsValue[0], setVal2State = _usePropsValue[1];
    var renderOptionsChildren = useCallback(function() {
        return options === null || options === void 0 ? void 0 : options.map(function(_param) {
            var label = _param.label, value = _param.value, disabled = _param.disabled, onChange = _param.onChange, rest = _object_without_properties(_param, [
                "label",
                "value",
                "disabled",
                "onChange"
            ]);
            return /*#__PURE__*/ React.createElement(Radio, _object_spread_props(_object_spread({}, rest), {
                key: value === null || value === void 0 ? void 0 : value.toString(),
                children: label,
                value: value,
                disabled: disabled,
                onChange: onChange,
                labelPosition: labelPosition,
                checked: value === val2State
            }));
        });
    }, [
        options,
        labelPosition,
        val2State
    ]);
    return /*#__PURE__*/ React.createElement(RadioContext.Provider, {
        value: {
            labelPosition: labelPosition || 'right',
            disabled: disabled,
            shape: shape,
            value: val2State,
            check: function(value) {
                setVal2State(value);
            },
            uncheck: function() {
                setVal2State('');
            }
        }
    }, /*#__PURE__*/ React.createElement(View, _object_spread({
        className: cls
    }, rest), (options === null || options === void 0 ? void 0 : options.length) ? renderOptionsChildren() : children));
});
RadioGroup.displayName = 'NutRadioGroup';
