"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* @flow */
const React = __importStar(require("react"));
{
    RadioButtonProps;
}
from;
'./types';
const classnames_1 = __importDefault(require("classnames"));
const withStyles_1 = __importDefault(require("components/hoc/withStyles"));
const ErrorBoundary_1 = __importDefault(require("components/hoc/ErrorBoundary"));
const styles_1 = __importDefault(require("./styles"));
class RadioButton extends React.Component {
    constructor(props) {
        super(props);
        this.changeValue = value => {
            this.setState({ value });
            if (this.props.onChange) {
                this.props.onChange(value);
            }
        };
        this._select = () => {
            this.setState({ value: true });
            if (this.props.onChange) {
                this.props.onChange(this.state.value);
            }
        };
        this._renderRadio = () => {
            const { classes, label, disabled } = this.props;
            return (React.createElement("div", { className: classnames_1.default(classes.radioWrapper, { disabled }), onClick: this._select },
                React.createElement("div", { className: classnames_1.default(classes.radioOuterCircle, {
                        selected: this.state.value,
                    }) },
                    React.createElement("div", { className: classes.radioInnerCircle })),
                Boolean(label) && React.createElement("div", { className: classes.radioLabel }, label)));
        };
        this.state = {
            value: props.value,
        };
    }
    componentDidUpdate(prevProps) {
        const props = this.props;
        if (props.value !== prevProps.value) {
            this.setState({
                value: props.value,
            });
        }
    }
    render() {
        let { classes, id } = this.props;
        let componentClass = classnames_1.default(classes.radioComponent);
        return (React.createElement(ErrorBoundary_1.default, null,
            React.createElement("div", { className: componentClass, id: id }, this._renderRadio())));
    }
}
RadioButton.defaultProps = {
    label: '',
    id: '',
    onChange: () => { },
    disabled: false,
    value: false,
};
exports.default = withStyles_1.default(styles_1.default)(RadioButton);
//# sourceMappingURL=index.js.map