import { __assign, __rest } from "tslib";
import React, { forwardRef } from "react";
import P2 from "../typography/P2";
import { RadioButtonComponent, Input, Mark } from "./style";
var RadioButton = 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 = __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.createElement(RadioButtonComponent, __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.createElement(Input, { ref: inputRef, "data-element": "radioButton-input", tabIndex: -1, type: "radio", checked: isChecked, name: name, value: value, readOnly: true, isDisabled: isDisabled, id: inputId }),
        React.createElement(Mark, { "data-element": "radioButton-mark", tabIndex: -1, isDisabled: isDisabled }),
        React.createElement(P2, { type: "corvus", "data-element": "radioButton-label", tabIndex: -1 }, label)));
});
RadioButton.displayName = "RadioButton";
export default RadioButton;
