"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _theme = _interopRequireDefault(require("./theme.css"));

var _Cell = _interopRequireDefault(require("./Cell"));

var _icon = _interopRequireDefault(require("../icon"));

var _typography = require("../typography");

var _classnames = _interopRequireDefault(require("classnames"));

var _uiIcons = require("@teamleader/ui-icons");

var _excluded = ["align", "children", "className", "onClick", "sortable", "sorted"];

var HeaderCell = function HeaderCell(_ref) {
  var _cx;

  var _ref$align = _ref.align,
      align = _ref$align === void 0 ? 'left' : _ref$align,
      children = _ref.children,
      className = _ref.className,
      onClick = _ref.onClick,
      sortable = _ref.sortable,
      sorted = _ref.sorted,
      others = (0, _objectWithoutProperties2.default)(_ref, _excluded);

  var renderSortedIndicators = function renderSortedIndicators() {
    if (sorted === 'asc' || !sorted && sortable) {
      return /*#__PURE__*/_react.default.createElement(_uiIcons.IconArrowUpSmallOutline, null);
    }

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

    return null;
  };

  var classNames = (0, _classnames.default)(_theme.default['header-cell'], (_cx = {}, (0, _defineProperty2.default)(_cx, _theme.default['is-sortable'], sortable), (0, _defineProperty2.default)(_cx, _theme.default['is-sorted'], sorted === 'asc' || sorted === 'desc'), _cx), className);
  return /*#__PURE__*/_react.default.createElement(_Cell.default, (0, _extends2.default)({
    align: align,
    className: classNames,
    onClick: onClick
  }, others, {
    preventOverflow: false
  }), sortable && align === 'right' && /*#__PURE__*/_react.default.createElement(_icon.default, {
    marginRight: 1
  }, renderSortedIndicators()), /*#__PURE__*/_react.default.createElement(_typography.UITextBody, {
    element: "span",
    maxLines: 1
  }, children), sortable && align === 'left' && /*#__PURE__*/_react.default.createElement(_icon.default, {
    marginLeft: 1
  }, renderSortedIndicators()));
};

HeaderCell.displayName = 'DataGrid.HeaderCell';
var _default = HeaderCell;
exports.default = _default;