(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", "../typography/P2", "./style"], 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 P2_1 = (0, tslib_1.__importDefault)(require("../typography/P2"));
    var style_1 = require("./style");
    var RadioButton = (0, react_1.forwardRef)(function (props, ref) {
        var label = props.label, name = props.name, value = props.value, isChecked = props.isChecked, isDisabled = props.isDisabled, isError = props.isError, onClick = props.onClick, onChange = props.onChange, className = props.className, inputRef = props.inputRef, inputId = props.inputId, onBlur = props.onBlur, onFocus = props.onFocus, otherProps = (0, tslib_1.__rest)(props, ["label", "name", "value", "isChecked", "isDisabled", "isError", "onClick", "onChange", "className", "inputRef", "inputId", "onBlur", "onFocus"]);
        var handleClick = function (event) {
            onClick === null || onClick === void 0 ? void 0 : onClick(event, value);
            !isChecked && (onChange === null || onChange === void 0 ? void 0 : onChange(event, value));
        };
        var handlePressEnter = function (event) {
            if (!isChecked && event.key === "Enter") {
                onChange === null || onChange === void 0 ? void 0 : onChange(event, value);
            }
        };
        return (react_1.default.createElement(style_1.RadioButtonComponent, (0, tslib_1.__assign)({ ref: ref, "data-element": "radioButton", tabIndex: 1, isError: !isChecked && isError, onKeyUp: handlePressEnter, onClick: handleClick, isDisabled: isDisabled, onFocus: onFocus, onBlur: onBlur, isChecked: isChecked, className: className }, otherProps),
            react_1.default.createElement(style_1.Input, { ref: inputRef, "data-element": "radioButton-input", tabIndex: -1, type: "radio", checked: isChecked, name: name, value: value, readOnly: true, isDisabled: isDisabled, id: inputId }),
            react_1.default.createElement(style_1.Mark, { "data-element": "radioButton-mark", tabIndex: -1, isDisabled: isDisabled }),
            react_1.default.createElement(P2_1.default, { type: "corvus", "data-element": "radioButton-label", tabIndex: -1 }, label)));
    });
    RadioButton.displayName = "RadioButton";
    exports.default = RadioButton;
});
