import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _jsxFileName = 'src/tag/CheckableTag.jsx';
/**
 * CheckableTag.jsx
 *
 * @Author: zhangce
 * @Date: 17/8/23 上午11:37
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

/**
 * CheckableTag
 * */

var CheckableTag = function (_React$PureComponent) {
    _inherits(CheckableTag, _React$PureComponent);

    function CheckableTag() {
        var _ref;

        var _temp, _this, _ret;

        _classCallCheck(this, CheckableTag);

        for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
        }

        return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = CheckableTag.__proto__ || Object.getPrototypeOf(CheckableTag)).call.apply(_ref, [this].concat(args))), _this), _this.handleClick = function () {
            var _this$props = _this.props,
                checked = _this$props.checked,
                onChange = _this$props.onChange,
                disabled = _this$props.disabled;

            if (onChange && !disabled) {
                onChange(!checked);
            }
        }, _temp), _possibleConstructorReturn(_this, _ret);
    }

    _createClass(CheckableTag, [{
        key: 'render',
        value: function render() {
            var _classNames;

            var _props = this.props,
                children = _props.children,
                prefixCls = _props.prefixCls,
                checked = _props.checked,
                className = _props.className,
                size = _props.size,
                disabled = _props.disabled,
                other = _objectWithoutProperties(_props, ['children', 'prefixCls', 'checked', 'className', 'size', 'disabled']);

            var classString = classNames(prefixCls, prefixCls + '-checkable', prefixCls + '-' + size, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-checked', checked), _defineProperty(_classNames, prefixCls + '-disabled', disabled), _classNames), className);
            return React.createElement(
                'span',
                Object.assign({ className: classString, onClick: this.handleClick }, other, {
                    __source: {
                        fileName: _jsxFileName,
                        lineNumber: 70
                    },
                    __self: this
                }),
                children
            );
        }
    }]);

    return CheckableTag;
}(React.PureComponent);

CheckableTag.propTypes = {
    /**
     * 类前缀
     * */
    prefixCls: PropTypes.string,
    /**
     * 类名
     * */
    className: PropTypes.string,
    /**
     * 是否被选中
     * */
    checked: PropTypes.bool,
    /**
     * 是否禁用
     * */
    disabled: PropTypes.bool,
    /**
     * 标签大小
     * */
    size: PropTypes.oneOf(['small', 'medium', 'large']),
    /**
     * 选中状态改变回调
     * */
    onChange: PropTypes.func
};
CheckableTag.defaultProps = {
    prefixCls: 'ne-tag',
    checked: false,
    size: 'medium',
    disabled: false
};


export default CheckableTag;