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 __());
    };
})();
/**
 * @file index
 * @author lvzhiyi
 *
 * 包含两中类型的开关组件 Switch CheckBox
 */
import React, { Component } from 'react';
import classNames from 'classnames';
import Icon from '../../Icon/index';
import './index.styl';
var Switch = /** @class */ (function (_super) {
    __extends(Switch, _super);
    function Switch(props) {
        var _this = _super.call(this, props) || this;
        _this.checkedChange = function (value) {
            _this.props.onChange(value);
        };
        _this.state = {
            checked: _this.props.checked
        };
        return _this;
    }
    Switch.prototype.componentWillReceiveProps = function (_a) {
        var checked = _a.checked;
        this.setState({ checked: checked });
    };
    Switch.prototype.render = function () {
        var checked = this.state.checked;
        var type = this.props.type;
        var swichClass = classNames({
            'switch-main': true,
            'checked-true': checked,
            'checked-false': !checked
        });
        return type === 'switch' ? (<div className={swichClass}>
                <div className="switch-dot" onTouchStart={this.checkedChange.bind(this, checked)}/>
            </div>) : (<div className="checked-box" onTouchStart={this.checkedChange.bind(this, checked)}>
                {checked ? (<Icon type="xuanzhongduigou"/>) : (<Icon type="unchecked"/>)}
            </div>);
    };
    /**
     * 开关类型，默认Switch
     *
     * type: String;
     */
    /**
     * 开关状态，默认选中
     *
     * checked: bool;
     */
    /**
     * 点击开关回调，
     *
     * onChange: () => {};
     */
    Switch.defaultProps = {
        checked: true,
        type: 'switch'
    };
    return Switch;
}(Component));
export default Switch;
