import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

/**
 * TableHeaderRow.jsx
 *
 * @Author: apple
 * @Date: 2018/3/8 15:19
 */
import React from 'react';
import classNames from 'classnames';
import ExpandMore from '../icons/internals/ExpandMore';
import ExpandLess from '../icons/internals/ExpandLess';
import UnfoldMore from '../icons/internals/UnfoldMore';
import TableFilter from './TableFilter';
import judgeBroswer from '../util/judgeBroswer';
var sortIcons = {
  sort: UnfoldMore,
  'sort-up': ExpandLess,
  'sort-down': ExpandMore
};
/**
 * @ignore
 * */

var TableHeaderRow =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(TableHeaderRow, _React$PureComponent);

  function TableHeaderRow() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, TableHeaderRow);

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

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(TableHeaderRow)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "getTableHeader", function (el) {
      var tableHeaderRef = _this.props.tableHeaderRef;
      tableHeaderRef && tableHeaderRef(el);
    });

    return _this;
  }

  _createClass(TableHeaderRow, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          theadClassName = _this$props.theadClassName,
          renderColumns = _this$props.renderColumns,
          handleSetSort = _this$props.handleSetSort,
          sortState = _this$props.sortState,
          onClickTh = _this$props.onClickTh,
          prefixCls = _this$props.prefixCls,
          expandRow = _this$props.expandRow,
          height = _this$props.height,
          textCenter = _this$props.textCenter;
      var isIE = judgeBroswer.isIE,
          isIE11 = judgeBroswer.isIE11;
      return React.createElement("thead", {
        className: theadClassName,
        style: {
          height: height
        },
        ref: this.getTableHeader
      }, React.createElement("tr", {
        onClick: function onClick() {
          return expandRow;
        }
      }, 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
        });
        var Component = sortIcons[sortState[key]];
        return React.createElement("th", {
          key: "th-".concat(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);
          }
        }, title, sort && React.createElement(Component, {
          className: "".concat(prefixCls, "-icon"),
          "data-sort": i,
          style: {
            userSelect: 'none'
          },
          onClick: function onClick() {
            return handleSetSort(elm.key, i);
          }
        }), filters && React.createElement(TableFilter, {
          prefixCls: prefixCls,
          filters: filters,
          filterMultiple: filterMultiple,
          filterMethod: filterMethod,
          id: i
        }), elm.renderHeader && elm.renderHeader('header', elm, elm.key));
      })));
    }
  }]);

  return TableHeaderRow;
}(React.PureComponent);

export default TableHeaderRow;