var __extends = (this && this.__extends) || (function () {
    var 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 function (d, b) {
        extendStatics(d, b);
        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", "../../Label", "./Toggle.scss"], function (require, exports, React, Utilities_1, Label_1, styles) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Toggle = (function (_super) {
        __extends(Toggle, _super);
        function Toggle(props) {
            var _this = _super.call(this) || this;
            _this._warnMutuallyExclusive({
                checked: 'defaultChecked'
            });
            _this.state = {
                isChecked: !!(props.checked || props.defaultChecked)
            };
            _this._id = props.id || Utilities_1.getId('Toggle');
            return _this;
        }
        Object.defineProperty(Toggle.prototype, "checked", {
            /**
             * Gets the current checked state of the toggle.
             */
            get: function () {
                return this.state.isChecked;
            },
            enumerable: true,
            configurable: true
        });
        Toggle.prototype.componentWillReceiveProps = function (newProps) {
            if (newProps.checked !== undefined) {
                this.setState({
                    isChecked: newProps.checked
                });
            }
        };
        Toggle.prototype.render = function () {
            var _this = this;
            var _a = this.props, label = _a.label, onText = _a.onText, offText = _a.offText, className = _a.className, disabled = _a.disabled;
            var isChecked = this.state.isChecked;
            var stateText = isChecked ? onText : offText;
            var toggleNativeProps = Utilities_1.getNativeProps(this.props, Utilities_1.buttonProperties);
            return (React.createElement("div", { className: Utilities_1.css(styles.root, 'ms-Toggle', className, (_b = {
                        'is-checked': isChecked,
                        'is-enabled': !disabled,
                        'is-disabled': disabled
                    },
                    _b[styles.isChecked] = isChecked,
                    _b[styles.isEnabled] = !disabled,
                    _b[styles.isDisabled] = disabled,
                    _b)) },
                React.createElement("div", { className: Utilities_1.css(styles.innerContainer, 'ms-Toggle-innerContainer') },
                    label && (React.createElement(Label_1.Label, { className: 'ms-Toggle-label', htmlFor: this._id }, label)),
                    React.createElement("div", { className: Utilities_1.css(styles.slider, 'ms-Toggle-slider') },
                        React.createElement("button", __assign({ ref: function (c) { return _this._toggleButton = c; }, type: 'button', id: this._id }, toggleNativeProps, { name: this._id, className: Utilities_1.css(styles.button, 'ms-Toggle-button'), disabled: disabled, "aria-pressed": isChecked, onClick: this._onClick })),
                        React.createElement("div", { className: Utilities_1.css(styles.background, 'ms-Toggle-background') },
                            React.createElement("div", { className: Utilities_1.css(styles.focus, 'ms-Toggle-focus') }),
                            React.createElement("div", { className: Utilities_1.css(styles.thumb, 'ms-Toggle-thumb') })),
                        stateText && (React.createElement(Label_1.Label, { className: Utilities_1.css(styles.stateText, 'ms-Toggle-stateText') }, stateText))))));
            var _b;
        };
        Toggle.prototype.focus = function () {
            if (this._toggleButton) {
                this._toggleButton.focus();
            }
        };
        Toggle.prototype._onClick = function () {
            var _a = this.props, checked = _a.checked, onChanged = _a.onChanged;
            var isChecked = this.state.isChecked;
            // Only update the state if the user hasn't provided it.
            if (checked === undefined) {
                this.setState({
                    isChecked: !isChecked
                });
            }
            if (onChanged) {
                onChanged(!isChecked);
            }
        };
        return Toggle;
    }(Utilities_1.BaseComponent));
    __decorate([
        Utilities_1.autobind
    ], Toggle.prototype, "_onClick", null);
    exports.Toggle = Toggle;
});

//# sourceMappingURL=Toggle.js.map
