import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["align", "children", "className", "onClick", "sortable", "sorted"];

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import theme from './theme.css';
import Cell from './Cell';
import Icon from '../icon';
import { UITextBody } from '../typography';
import cx from 'classnames';
import { IconArrowDownSmallOutline, IconArrowUpSmallOutline } from '@teamleader/ui-icons';

var HeaderCell = /*#__PURE__*/function (_PureComponent) {
  _inherits(HeaderCell, _PureComponent);

  var _super = _createSuper(HeaderCell);

  function HeaderCell() {
    var _this;

    _classCallCheck(this, HeaderCell);

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

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "renderSortedIndicators", function () {
      var _this$props = _this.props,
          sortable = _this$props.sortable,
          sorted = _this$props.sorted;

      if (sorted === 'asc' || !sorted && sortable) {
        return /*#__PURE__*/React.createElement(IconArrowUpSmallOutline, null);
      }

      if (sorted === 'desc') {
        return /*#__PURE__*/React.createElement(IconArrowDownSmallOutline, null);
      }

      return null;
    });

    return _this;
  }

  _createClass(HeaderCell, [{
    key: "render",
    value: function render() {
      var _cx;

      var _this$props2 = this.props,
          align = _this$props2.align,
          children = _this$props2.children,
          className = _this$props2.className,
          onClick = _this$props2.onClick,
          sortable = _this$props2.sortable,
          sorted = _this$props2.sorted,
          others = _objectWithoutProperties(_this$props2, _excluded);

      var classNames = cx(theme['header-cell'], (_cx = {}, _defineProperty(_cx, theme['is-sortable'], sortable), _defineProperty(_cx, theme['is-sorted'], sorted === 'asc' || sorted === 'desc'), _cx), className);
      return /*#__PURE__*/React.createElement(Cell, _extends({
        align: align,
        className: classNames,
        onClick: onClick
      }, others, {
        preventOverflow: false
      }), sortable && align === 'right' && /*#__PURE__*/React.createElement(Icon, {
        marginRight: 1
      }, this.renderSortedIndicators()), /*#__PURE__*/React.createElement(UITextBody, {
        element: "span",
        maxLines: 1
      }, children), sortable && align === 'left' && /*#__PURE__*/React.createElement(Icon, {
        marginLeft: 1
      }, this.renderSortedIndicators()));
    }
  }]);

  return HeaderCell;
}(PureComponent);

HeaderCell.defaultProps = {
  align: 'left'
};
export default HeaderCell;