"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require('react');
var css_1 = require('../../utilities/css');
require('./Checkbox.scss');
var _instance = 0;
var Checkbox = (function (_super) {
    __extends(Checkbox, _super);
    function Checkbox(props) {
        _super.call(this, props);
        this.state = {
            isChecked: props.isChecked
        };
        this._id = "checkbox-" + _instance++;
        this._handleInputChange = this._handleInputChange.bind(this);
    }
    Checkbox.prototype.componentWillReceiveProps = function (newProps) {
        if (newProps.isChecked !== this.props.isChecked) {
            this.setState({
                isChecked: newProps.isChecked
            });
        }
    };
    Checkbox.prototype.render = function () {
        var _this = this;
        var _a = this.props, text = _a.text, isEnabled = _a.isEnabled, className = _a.className;
        var isChecked = this.state.isChecked;
        return (React.createElement("div", {className: css_1.css('ms-ChoiceField', className)}, React.createElement("input", {ref: function (c) { return _this._checkBox = c; }, id: this._id, name: this._id, className: 'ms-ChoiceField-input', type: 'checkbox', role: 'checkbox', checked: isChecked, disabled: !isEnabled, onChange: this._handleInputChange, "aria-checked": isChecked}), React.createElement("label", {htmlFor: this._id, className: 'ms-ChoiceField-field'}, React.createElement("span", {className: 'ms-Label'}, text))));
    };
    Checkbox.prototype.focus = function () {
        if (this._checkBox) {
            this._checkBox.focus();
        }
    };
    Checkbox.prototype._handleInputChange = function (evt) {
        var onChanged = this.props.onChanged;
        var isChecked = evt.target.checked;
        this.setState({
            isChecked: isChecked
        });
        if (onChanged) {
            onChanged(isChecked);
        }
    };
    Checkbox.defaultProps = {
        isSelected: false,
        isEnabled: true
    };
    return Checkbox;
}(React.Component));
exports.Checkbox = Checkbox;

//# sourceMappingURL=Checkbox.js.map
