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/tabs/Tab.jsx';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

/**
 * Tab
 * */

var Tab = function (_PureComponent) {
    _inherits(Tab, _PureComponent);

    function Tab() {
        var _ref;

        var _temp, _this, _ret;

        _classCallCheck(this, Tab);

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

        return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Tab.__proto__ || Object.getPrototypeOf(Tab)).call.apply(_ref, [this].concat(args))), _this), _this.getEl = function (el) {
            _this.el = el;
        }, _this.onClick = function (e) {
            var _this$props = _this.props,
                disabled = _this$props.disabled,
                value = _this$props.value,
                onSelect = _this$props.onSelect,
                onClick = _this$props.onClick,
                index = _this$props.index;

            if (!disabled) {
                onSelect && onSelect(e, value != null ? value : index);
            }
            onClick && onClick(e);
        }, _this.onKeyDown = function (event) {
            var onKeyDown = _this.props.onKeyDown;

            var key = event.key;
            if (!_this.keyDown && key === ' ') {
                _this.keyDown = true;
                event.persist();
            }

            if (onKeyDown) {
                onKeyDown(event);
            }
            if (event.target === _this.el && (key === ' ' || key === 'Enter')) {
                event.preventDefault();
                _this.onClick(event);
            }
        }, _this.onKeyUp = function (event) {
            if (event === ' ') {
                _this.keyDown = false;
                event.persist();
            }
            if (_this.props.onKeyUp) {
                _this.props.onKeyUp(event);
            }
        }, _temp), _possibleConstructorReturn(_this, _ret);
    }

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

            var _props = this.props,
                className = _props.className,
                index = _props.index,
                disabled = _props.disabled,
                prefixCls = _props.prefixCls,
                value = _props.value,
                selected = _props.selected,
                fullWidth = _props.fullWidth,
                other = _objectWithoutProperties(_props, ['className', 'index', 'disabled', 'prefixCls', 'value', 'selected', 'fullWidth']);

            var classes = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-full-width', fullWidth), _defineProperty(_classNames, prefixCls + '-selected', !disabled && selected), _defineProperty(_classNames, prefixCls + '-disabled', disabled), _classNames), className);
            return React.createElement('div', Object.assign({}, other, {
                onKeyDown: this.onKeyDown,
                onKeyUp: this.onKeyUp,
                ref: this.getEl,
                tabIndex: disabled ? -1 : 0,
                role: 'tab',
                className: classes,
                onClick: this.onClick,
                'aria-selected': selected,
                __source: {
                    fileName: _jsxFileName,
                    lineNumber: 83
                },
                __self: this
            }));
        }
    }]);

    return Tab;
}(PureComponent);

Tab.propTypes = {
    prefixCls: PropTypes.string,
    className: PropTypes.string,
    /** tab值 */
    value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
    /** 序号 */
    index: PropTypes.number,
    /** 选中回调 */
    onSelect: PropTypes.func,
    /** 是否选中 */
    selected: PropTypes.bool,
    /** 是否禁用 */
    disabled: PropTypes.bool,
    /** 是否撑满宽度 */
    fullWidth: PropTypes.bool
};
Tab.defaultProps = {
    prefixCls: 'ne-tab',
    selected: false,
    disabled: false,
    fullWidth: false
};
export default Tab;