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/select/TagsInput.jsx';
/**
 * Select.jsx
 *
 * @Author: wang yinan
 * @Date: 2018/3/08 下午5:12
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Input from '../input';
import Tag from '../tag';

/**
 * @ignore
 * */

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

    function TagsInput() {
        var _ref;

        var _temp, _this, _ret;

        _classCallCheck(this, TagsInput);

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

        return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TagsInput.__proto__ || Object.getPrototypeOf(TagsInput)).call.apply(_ref, [this].concat(args))), _this), _this.tagClickHandle = function (e) {
            e.stopPropagation();
        }, _temp), _possibleConstructorReturn(_this, _ret);
    }

    _createClass(TagsInput, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                prefixCls = _props.prefixCls,
                className = _props.className,
                children = _props.children,
                placeholder = _props.placeholder,
                inputProps = _props.inputProps,
                tags = _props.tags,
                onTagDelete = _props.onTagDelete,
                size = _props.size,
                defaultSearchText = _props.defaultSearchText,
                searchText = _props.searchText,
                searchable = _props.searchable,
                tagRender = _props.tagRender,
                disabled = _props.disabled,
                other = _objectWithoutProperties(_props, ['prefixCls', 'className', 'children', 'placeholder', 'inputProps', 'tags', 'onTagDelete', 'size', 'defaultSearchText', 'searchText', 'searchable', 'tagRender', 'disabled']);

            var content = React.createElement(
                'div',
                { className: prefixCls + '-content', __source: {
                        fileName: _jsxFileName,
                        lineNumber: 62
                    },
                    __self: this
                },
                searchText
            );
            return React.createElement(Input, Object.assign({
                className: classNames(className, _defineProperty({}, prefixCls + '-searchable', searchable), prefixCls),
                'aria-haspopup': 'true',
                noWrapper: true,
                disabled: disabled,
                prefix: tags.map(function (tag) {
                    return tagRender ? tagRender(tag, size, _this2.tagClickHandle) : React.createElement(
                        Tag,
                        {
                            key: tag.value,
                            closable: true,
                            onDelete: function onDelete() {
                                onTagDelete(tag.value);
                            },
                            disabled: disabled,
                            size: size,
                            onClick: _this2.tagClickHandle, __source: {
                                fileName: _jsxFileName,
                                lineNumber: 80
                            },
                            __self: _this2
                        },
                        tag.label
                    );
                }),
                inputProps: inputProps,
                value: !searchable ? '' : searchText,
                mask: !searchable && searchText ? content : null,
                placeholder: tags.length > 0 ? null : placeholder || '',
                size: size
            }, other, {
                __source: {
                    fileName: _jsxFileName,
                    lineNumber: 64
                },
                __self: this
            }));
        }
    }]);

    return TagsInput;
}(React.PureComponent);

TagsInput.displayName = 'NeatUI.TagInput';
TagsInput.propTypes = {
    placeholder: PropTypes.node,
    tags: PropTypes.array,
    searchText: PropTypes.node,
    readOnly: PropTypes.bool,
    disabled: PropTypes.bool,
    inputProps: PropTypes.object,
    tagRender: PropTypes.func,
    size: PropTypes.oneOf(['large', 'medium', 'small', 'base']) };
TagsInput.defaultProps = {
    multiple: true,
    prefixCls: 'ne-tags-input',
    readOnly: false,
    disabled: false,
    size: 'medium',
    tags: [],
    searchText: ''
};


export default TagsInput;