(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../../hooks/useStateProps", "../styles", "./RadioGroupContext"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var useStateProps_1 = require("../../hooks/useStateProps");
    var styles_1 = require("../styles");
    var RadioGroupContext_1 = require("./RadioGroupContext");
    var RadioGroup = function (props) {
        var value = props.value, onChange = props.onChange, onClick = props.onClick, children = props.children, classNameButton = props.classNameButton, options = props.options, className = props.className, name = props.name, isDisabled = props.isDisabled, _a = props.direction, direction = _a === void 0 ? "column" : _a, otherProps = (0, tslib_1.__rest)(props, ["value", "onChange", "onClick", "children", "classNameButton", "options", "className", "name", "isDisabled", "direction"]);
        var _b = (0, tslib_1.__read)((0, useStateProps_1.useStateProps)(value), 2), groupValue = _b[0], setGroupValue = _b[1];
        var handleClick = function (event, _value) {
            onClick && onClick(event, _value);
        };
        var handleChange = function (event, _value) {
            if (groupValue !== _value) {
                onChange && onChange(event, _value);
                setGroupValue(_value || null);
            }
        };
        return (react_1.default.createElement(RadioGroupContext_1.RadioGroupContext.Provider, { value: {
                groupValue: groupValue,
                onChange: handleChange,
                onClick: handleClick
            } },
            react_1.default.createElement(styles_1.RadioGroupStyled, (0, tslib_1.__assign)({ className: className, direction: direction }, otherProps), options
                ? options.map(function (option) { return (react_1.default.createElement(styles_1.RadioOptionStyled, { key: option.value, value: option.value, label: option.label, className: classNameButton, isDisabled: option.isDisabled || isDisabled, name: name })); })
                : react_1.Children.map(children, function (child) { return (react_1.default.createElement(styles_1.RadioOptionStyled, { name: name, isDisabled: isDisabled, className: classNameButton }, child)); }))));
    };
    exports.default = RadioGroup;
});
