"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "RadioGroup", {
    enumerable: true,
    get: function() {
        return RadioGroup;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _define_property = require("@swc/helpers/_/_define_property");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _components = require("@tarojs/components");
var _context = /*#__PURE__*/ _interop_require_default._(require("./context"));
var _index = /*#__PURE__*/ _interop_require_default._(require("../radio/index"));
var _usepropsvalue = require("../../hooks/use-props-value");
var defaultProps = {
    labelPosition: 'right',
    onChange: function onChange(value) {},
    direction: 'vertical',
    options: []
};
var classPrefix = 'nut-radiogroup';
var RadioGroup = /*#__PURE__*/ _react.default.forwardRef(function(props, ref) {
    var _ref = (0, _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 = (0, _object_without_properties._)(_ref, [
        "children",
        "className",
        "value",
        "defaultValue",
        "onChange",
        "shape",
        "labelPosition",
        "direction",
        "options",
        "disabled"
    ]);
    var cls = (0, _classnames.default)(classPrefix, (0, _define_property._)({}, "".concat(classPrefix, "-").concat(direction), direction), className);
    var _usePropsValue = (0, _sliced_to_array._)((0, _usepropsvalue.usePropsValue)({
        defaultValue: props.defaultValue,
        value: props.value,
        finalValue: '',
        onChange: onChange
    }), 2), val2State = _usePropsValue[0], setVal2State = _usePropsValue[1];
    var renderOptionsChildren = (0, _react.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 = (0, _object_without_properties._)(_param, [
                "label",
                "value",
                "disabled",
                "onChange"
            ]);
            return /*#__PURE__*/ _react.default.createElement(_index.default, (0, _object_spread_props._)((0, _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.default.createElement(_context.default.Provider, {
        value: {
            labelPosition: labelPosition || 'right',
            disabled: disabled,
            shape: shape,
            value: val2State,
            check: function check(value) {
                setVal2State(value);
            },
            uncheck: function uncheck() {
                setVal2State('');
            }
        }
    }, /*#__PURE__*/ _react.default.createElement(_components.View, (0, _object_spread._)({
        className: cls
    }, rest), (options === null || options === void 0 ? void 0 : options.length) ? renderOptionsChildren() : children));
});
RadioGroup.displayName = 'NutRadioGroup';
