import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["align", "children", "className", "onClick", "sortable", "sorted"];
import React from 'react';
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 = 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 = _objectWithoutProperties(_ref, _excluded);

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

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

    return null;
  };

  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
  }, renderSortedIndicators()), /*#__PURE__*/React.createElement(UITextBody, {
    element: "span",
    maxLines: 1
  }, children), sortable && align === 'left' && /*#__PURE__*/React.createElement(Icon, {
    marginLeft: 1
  }, renderSortedIndicators()));
};

HeaderCell.displayName = 'DataGrid.HeaderCell';
export default HeaderCell;