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/table/TableHeaderRow.jsx';
/**
 * TableHeaderRow.jsx
 *
 * @Author: apple
 * @Date: 2018/3/8 15:19
 */

import React from 'react';
import Icon from '../icon';
import classNames from 'classnames';
import TableFilter from './TableFilter';
import judgeBroswer from '../util/judgeBroswer';

/**
 * @ignore
 * */

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

    function TableHeaderRow() {
        var _ref;

        var _temp, _this, _ret;

        _classCallCheck(this, TableHeaderRow);

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

        return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TableHeaderRow.__proto__ || Object.getPrototypeOf(TableHeaderRow)).call.apply(_ref, [this].concat(args))), _this), _this.getTableHeaderRow = function (el) {
            var tableHeaderRowRef = _this.props.tableHeaderRowRef;

            tableHeaderRowRef && tableHeaderRowRef(el);
        }, _temp), _possibleConstructorReturn(_this, _ret);
    }

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

            var _props = this.props,
                theadClassName = _props.theadClassName,
                renderColumns = _props.renderColumns,
                handleSetSort = _props.handleSetSort,
                sortState = _props.sortState,
                onClickTh = _props.onClickTh,
                prefixCls = _props.prefixCls,
                expandRow = _props.expandRow,
                height = _props.height,
                textCenter = _props.textCenter;
            var isIE = judgeBroswer.isIE,
                isIE11 = judgeBroswer.isIE11;

            return React.createElement(
                'thead',
                { className: theadClassName, style: { height: height }, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 37
                    },
                    __self: this
                },
                React.createElement(
                    'tr',
                    { onClick: function onClick() {
                            return expandRow;
                        }, ref: this.getTableHeaderRow, __source: {
                            fileName: _jsxFileName,
                            lineNumber: 38
                        },
                        __self: this
                    },
                    renderColumns.map(function (elm, i) {
                        var key = elm.key,
                            title = elm.title,
                            filters = elm.filters,
                            filterMultiple = elm.filterMultiple,
                            filterMethod = elm.filterMethod,
                            sort = elm.sort;

                        var style = Object.assign({}, elm.style, {
                            height: height
                        });
                        return React.createElement(
                            'th',
                            {
                                key: 'th-' + i,
                                style: style,
                                className: classNames(elm.className, {
                                    'text-left': !textCenter && !renderColumns[i].textCenter && (isIE() || isIE11())
                                }, { 'text-center': renderColumns[i].textCenter }),
                                onClick: function onClick(event) {
                                    return onClickTh(event, elm, i);
                                }, __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 45
                                },
                                __self: _this2
                            },
                            title,
                            sort && React.createElement(Icon, {
                                type: sortState[key],
                                'data-sort': i,
                                style: { userSelect: 'none' },
                                onClick: function onClick() {
                                    return handleSetSort(elm.key, i);
                                },
                                __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 59
                                },
                                __self: _this2
                            }),
                            filters && React.createElement(TableFilter, {
                                prefixCls: prefixCls,
                                filters: filters,
                                filterMultiple: filterMultiple,
                                filterMethod: filterMethod,
                                id: i,
                                __source: {
                                    fileName: _jsxFileName,
                                    lineNumber: 67
                                },
                                __self: _this2
                            }),
                            elm.renderHeader && elm.renderHeader('header', elm, elm.key)
                        );
                    })
                )
            );
        }
    }]);

    return TableHeaderRow;
}(React.PureComponent);

export default TableHeaderRow;