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 __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "react", "../../Utilities", "./Checkbox.scss"], function (require, exports, React, Utilities_1, Checkbox_scss_1) {
    "use strict";
    var Checkbox = (function (_super) {
        __extends(Checkbox, _super);
        function Checkbox(props) {
            var _this = _super.call(this, props) || this;
            _this._id = Utilities_1.getId('checkbox-');
            _this.state = {
                isFocused: false,
                isChecked: !!(props.checked !== undefined ? props.checked : props.defaultChecked)
            };
            return _this;
        }
        Checkbox.prototype.render = function () {
            var _a = this.props, checked = _a.checked, className = _a.className, defaultChecked = _a.defaultChecked, disabled = _a.disabled, inputProps = _a.inputProps, label = _a.label, name = _a.name;
            var isFocused = this.state.isFocused;
            var isChecked = checked === undefined ? this.state.isChecked : checked;
            return (React.createElement("div", { className: Utilities_1.css('ms-Checkbox', Checkbox_scss_1.default.root, className, (_b = {
                        'is-inFocus': isFocused
                    },
                    _b[Checkbox_scss_1.default.rootIsInFocus] = isFocused,
                    _b)) },
                React.createElement("input", __assign({}, inputProps, (checked !== undefined && { checked: checked }), (defaultChecked !== undefined && { defaultChecked: defaultChecked }), { disabled: disabled, ref: this._resolveRef('_checkBox'), id: this._id, name: name || this._id, className: Utilities_1.css('ms-Checkbox-input', Checkbox_scss_1.default.input), type: 'checkbox', onChange: this._onChange, onFocus: this._onFocus, onBlur: this._onBlur, "aria-checked": isChecked })),
                this.props.children,
                React.createElement("label", { htmlFor: this._id, className: Utilities_1.css('ms-Checkbox-label', Checkbox_scss_1.default.label, (_c = {},
                        _c['is-checked ' + Checkbox_scss_1.default.labelIsChecked] = isChecked,
                        _c['is-disabled ' + Checkbox_scss_1.default.labelIsDisabled] = disabled,
                        _c[Checkbox_scss_1.default.labelIsInFocus] = isFocused,
                        _c)) }, label && React.createElement("span", { className: Checkbox_scss_1.default.textLabel }, label))));
            var _b, _c;
        };
        Object.defineProperty(Checkbox.prototype, "checked", {
            get: function () {
                return this._checkBox ? this._checkBox.checked : false;
            },
            enumerable: true,
            configurable: true
        });
        Checkbox.prototype.focus = function () {
            if (this._checkBox) {
                this._checkBox.focus();
            }
        };
        Checkbox.prototype._onFocus = function (ev) {
            var inputProps = this.props.inputProps;
            if (inputProps && inputProps.onFocus) {
                inputProps.onFocus(ev);
            }
            this.setState({ isFocused: true });
        };
        Checkbox.prototype._onBlur = function (ev) {
            var inputProps = this.props.inputProps;
            if (inputProps && inputProps.onBlur) {
                inputProps.onBlur(ev);
            }
            this.setState({ isFocused: false });
        };
        Checkbox.prototype._onChange = function (ev) {
            var onChange = this.props.onChange;
            var isChecked = ev.target.checked;
            if (onChange) {
                onChange(ev, isChecked);
            }
            if (this.props.checked === undefined) {
                this.setState({ isChecked: isChecked });
            }
        };
        return Checkbox;
    }(Utilities_1.BaseComponent));
    Checkbox.defaultProps = {};
    __decorate([
        Utilities_1.autobind
    ], Checkbox.prototype, "_onFocus", null);
    __decorate([
        Utilities_1.autobind
    ], Checkbox.prototype, "_onBlur", null);
    __decorate([
        Utilities_1.autobind
    ], Checkbox.prototype, "_onChange", null);
    exports.Checkbox = Checkbox;
});

//# sourceMappingURL=Checkbox.js.map
