import { __assign, __read, __rest } from "tslib";
import React, { forwardRef } from "react";
import ListItem from "../ListItem";
import { useStateProps } from "../../../hooks/useStateProps";
import RadioButton from "../../../RadioButton";
import List from "../List";
var ListRadioButtons = forwardRef(function (_a, ref) {
    var dataSource = _a.dataSource, onChange = _a.onChange, defaultValue = _a.defaultValue, className = _a.className, style = _a.style, isDisabled = _a.isDisabled, header = _a.header, height = _a.height, width = _a.width, viewType = _a.viewType, isSelected = _a.isSelected, styleItem = _a.styleItem, classNameItem = _a.classNameItem, _b = _a.size, size = _b === void 0 ? "l" : _b, onClickItem = _a.onClickItem, props = __rest(_a, ["dataSource", "onChange", "defaultValue", "className", "style", "isDisabled", "header", "height", "width", "viewType", "isSelected", "styleItem", "classNameItem", "size", "onClickItem"]);
    var _c = __read(useStateProps(defaultValue), 2), value = _c[0], setValue = _c[1];
    var handleCLick = function (event, val) {
        setValue(val);
        onChange === null || onChange === void 0 ? void 0 : onChange(event, val);
        onClickItem === null || onClickItem === void 0 ? void 0 : onClickItem(event, val);
    };
    var renderItem = function (item) { return (React.createElement(ListItem, __assign({}, item, { key: item.label, size: size, className: classNameItem, style: styleItem, isDisabled: isDisabled || item.isDisabled, onClick: function (event) { return handleCLick(event, item.value); }, isSelected: item.value === value, leadContent: React.createElement(RadioButton, { isDisabled: isDisabled || item.isDisabled, value: item.value, name: item.name, isChecked: item.value === value }) }), item.label)); };
    return (React.createElement(List, __assign({ ref: ref, header: header, height: height, width: width, viewType: viewType, isSelected: isSelected, className: className, style: style, size: size, dataSource: dataSource, renderItem: renderItem, isDisabled: isDisabled }, props)));
});
ListRadioButtons.displayName = "ListRadioButtons";
export default ListRadioButtons;
