var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import * as classnames from "classnames";
import * as React from "react";
import * as ReactDOM from "react-dom";
import "./Radio.less";
var cssClass = {
    CHECKED: "Radio--checked",
    CONTAINER: "Radio",
    DISABLED: "Radio--disabled",
    INNER: "Radio--inner",
    LABEL: "Radio--label",
    OUTER: "Radio--outer",
};
var LABEL_ID_PREFIX = "Radio--label";
var nextLabelIDSuffix = 0;
var getNextLabelID = function () { return LABEL_ID_PREFIX + "--" + nextLabelIDSuffix++; };
/**
 * Single radio button input.
 * Usually used in a RadioGroup for providing a list of mutually-exclusive options to the user.
 */
var Radio = /** @class */ (function (_super) {
    __extends(Radio, _super);
    function Radio() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._element = null;
        _this._labelID = getNextLabelID();
        _this._onClick = function () {
            var _a = _this.props, disabled = _a.disabled, id = _a.id, onSelect = _a.onSelect, value = _a.value;
            if (disabled) {
                return;
            }
            if (onSelect) {
                onSelect(id, value);
            }
        };
        return _this;
    }
    Radio.prototype.focus = function () {
        if (this._element) {
            this._element.focus();
        }
    };
    Radio.prototype.componentDidMount = function () {
        this._element = ReactDOM.findDOMNode(this);
    };
    Radio.prototype.render = function () {
        var _a = this.props, checked = _a.checked, children = _a.children, className = _a.className, disabled = _a.disabled, tabIndex = _a.tabIndex, lang = _a.lang;
        return (React.createElement("button", { "aria-checked": !!checked, "aria-labelledby": this._labelID, className: classnames(cssClass.CONTAINER, checked && cssClass.CHECKED, disabled && cssClass.DISABLED, className), disabled: disabled, onClick: this._onClick, onFocus: this._onClick, role: "radio", tabIndex: tabIndex, lang: lang },
            React.createElement("div", { className: cssClass.OUTER },
                React.createElement("div", { className: cssClass.INNER })),
            React.createElement("span", { className: cssClass.LABEL, id: this._labelID }, children)));
    };
    return Radio;
}(React.PureComponent));
export default Radio;
