"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StyledTableLoadingMessage = exports.StyledTableHeadRow = exports.StyledTableHeadCellSortable = exports.StyledTableHeadCell = exports.StyledTableHead = exports.StyledTableEmptyMessage = exports.StyledTableBodyRow = exports.StyledTableBodyCell = exports.StyledTableBody = exports.StyledTable = exports.StyledSortNoneIcon = exports.StyledSortIconContainer = exports.StyledSortDescIcon = exports.StyledSortAscIcon = exports.StyledRoot = void 0;

var _blank = _interopRequireDefault(require("../icon/blank"));

var _chevronDown = _interopRequireDefault(require("../icon/chevron-down"));

var _chevronUp = _interopRequireDefault(require("../icon/chevron-up"));

var _styles = require("../styles");

var _constants = require("./constants");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

// @ts-ignore
function sizeToCellPadding($theme, $size) {
  if ($size === _constants.SIZE.compact) {
    return $theme.sizing.scale500;
  } else if ($size === _constants.SIZE.spacious) {
    return $theme.sizing.scale800;
  }

  return $theme.sizing.scale600;
}

var StyledRoot = (0, _styles.styled)('div', function (_ref) {
  var $theme = _ref.$theme,
      $divider = _ref.$divider;
  var borderStyles = $divider === _constants.DIVIDER.grid || $divider === _constants.DIVIDER.vertical ? (0, _styles.expandBorderStyles)($theme.borders.border300) : {};
  return _objectSpread(_objectSpread(_objectSpread({}, borderStyles), $divider === _constants.DIVIDER.horizontal ? {
    borderBottomWidth: $theme.borders.border300.borderWidth,
    borderBottomStyle: $theme.borders.border300.borderStyle,
    borderBottomColor: $theme.borders.border300.borderColor
  } : {}), {}, {
    position: 'relative',
    overflow: 'auto',
    WebkitOverflowScrolling: 'touch',
    backgroundColor: $theme.colors.tableBackground,
    // Creates a stacking context so we can use z-index on the StyledTableHeadCell
    // without affecting anything outside of this component.
    transform: 'scale(1)'
  });
});
exports.StyledRoot = StyledRoot;
StyledRoot.displayName = "StyledRoot";
StyledRoot.displayName = 'StyledRoot';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// @ts-ignore
var StyledTable = (0, _styles.styled)('table', function (_ref2) {
  var $theme = _ref2.$theme,
      $width = _ref2.$width;
  return {
    borderSpacing: '0',
    boxSizing: 'border-box',
    minWidth: '100%',
    width: $width || null
  };
});
exports.StyledTable = StyledTable;
StyledTable.displayName = "StyledTable";
StyledTable.displayName = 'StyledTable'; // eslint-disable-next-line @typescript-eslint/no-unused-vars

var StyledTableHead = (0, _styles.styled)('thead', function (_ref3) {
  var $theme = _ref3.$theme;
  return {};
});
exports.StyledTableHead = StyledTableHead;
StyledTableHead.displayName = "StyledTableHead";
StyledTableHead.displayName = 'StyledTableHead'; // eslint-disable-next-line @typescript-eslint/no-unused-vars

var StyledTableHeadRow = (0, _styles.styled)('tr', function (_ref4) {
  var $theme = _ref4.$theme;
  return {};
});
exports.StyledTableHeadRow = StyledTableHeadRow;
StyledTableHeadRow.displayName = "StyledTableHeadRow";
StyledTableHeadRow.displayName = 'StyledTableHeadRow';
var StyledTableHeadCell = (0, _styles.styled)('th', function (_ref5) {
  var _notLastChild;

  var $theme = _ref5.$theme,
      $size = _ref5.$size,
      $divider = _ref5.$divider;
  var borderDir = $theme.direction === 'rtl' ? 'Left' : 'Right';
  var borderVertical = $divider === _constants.DIVIDER.grid || $divider === _constants.DIVIDER.vertical;
  var padding = sizeToCellPadding($theme, $size);
  return _objectSpread(_objectSpread(_objectSpread({}, $theme.typography.font350), {}, {
    position: 'sticky',
    top: 0,
    paddingTop: padding,
    paddingRight: padding,
    paddingBottom: padding,
    paddingLeft: padding,
    backgroundColor: $theme.colors.tableHeadBackgroundColor,
    color: $theme.colors.contentPrimary,
    textAlign: $theme.direction === 'rtl' ? 'right' : 'left',
    whiteSpace: 'nowrap',
    zIndex: 1
  }, $divider === _constants.DIVIDER.clean ? {} : {
    borderBottomColor: $theme.borders.border300.borderColor,
    borderBottomStyle: $theme.borders.border300.borderStyle,
    borderBottomWidth: $theme.borders.border300.borderWidth
  }), {}, {
    ':not(:last-child)': (_notLastChild = {}, _defineProperty(_notLastChild, "border".concat(borderDir, "Color"), borderVertical ? $theme.borders.border300.borderColor : null), _defineProperty(_notLastChild, "border".concat(borderDir, "Style"), borderVertical ? $theme.borders.border300.borderStyle : null), _defineProperty(_notLastChild, "border".concat(borderDir, "Width"), borderVertical ? $theme.borders.border300.borderWidth : null), _notLastChild)
  });
});
exports.StyledTableHeadCell = StyledTableHeadCell;
StyledTableHeadCell.displayName = "StyledTableHeadCell";
StyledTableHeadCell.displayName = 'StyledTableHeadCell';
var StyledTableHeadCellSortable = (0, _styles.withStyle)(StyledTableHeadCell, function (_ref6) {
  var $theme = _ref6.$theme,
      $isFocusVisible = _ref6.$isFocusVisible;
  return {
    cursor: 'pointer',
    outline: 'none',
    ':focus': {
      outline: $isFocusVisible ? "3px solid ".concat($theme.colors.borderAccent) : 'none',
      outlineOffset: '-3px'
    },
    ':hover': {
      backgroundColor: $theme.colors.tableStripedBackground
    }
  };
});
exports.StyledTableHeadCellSortable = StyledTableHeadCellSortable;
StyledTableHeadCellSortable.displayName = "StyledTableHeadCellSortable";
StyledTableHeadCellSortable.displayName = 'StyledTableHeadCellSortable';
var StyledSortIconContainer = (0, _styles.styled)('span', function (_ref7) {
  var $theme = _ref7.$theme;
  return {
    display: 'flex',
    alignItems: 'center',
    position: 'absolute',
    top: '50%',
    right: $theme.sizing.scale500,
    transform: 'translateY(-50%)'
  };
});
exports.StyledSortIconContainer = StyledSortIconContainer;
StyledSortIconContainer.displayName = "StyledSortIconContainer";
StyledSortIconContainer.displayName = 'StyledSortIconContainer'; // No longer used, but will maintain for some time to support existing usage

var StyledSortAscIcon = (0, _styles.styled)(_chevronUp.default, function (_ref8) {
  var $theme = _ref8.$theme;
  return {
    position: 'absolute',
    top: '50%',
    right: $theme.sizing.scale500,
    transform: 'translateY(-50%)'
  };
});
exports.StyledSortAscIcon = StyledSortAscIcon;
StyledSortAscIcon.displayName = "StyledSortAscIcon";
StyledSortAscIcon.displayName = 'StyledSortAscIcon';
var StyledSortDescIcon = (0, _styles.styled)(_chevronDown.default, function (_ref9) {
  var $theme = _ref9.$theme;
  return {
    position: 'absolute',
    top: '50%',
    right: $theme.sizing.scale500,
    transform: 'translateY(-50%)'
  };
});
exports.StyledSortDescIcon = StyledSortDescIcon;
StyledSortDescIcon.displayName = "StyledSortDescIcon";
StyledSortDescIcon.displayName = 'StyledSortDescIcon';
var StyledSortNoneIcon = (0, _styles.styled)(_blank.default, function (_ref10) {
  var $theme = _ref10.$theme;
  return {
    position: 'absolute',
    top: '50%',
    right: $theme.sizing.scale500,
    transform: 'translateY(-50%)'
  };
});
exports.StyledSortNoneIcon = StyledSortNoneIcon;
StyledSortNoneIcon.displayName = "StyledSortNoneIcon";
StyledSortNoneIcon.displayName = 'StyledSortNoneIcon'; // eslint-disable-next-line @typescript-eslint/no-unused-vars

var StyledTableBody = (0, _styles.styled)('tbody', function (_ref11) {
  var $theme = _ref11.$theme;
  return {};
});
exports.StyledTableBody = StyledTableBody;
StyledTableBody.displayName = "StyledTableBody";
StyledTableBody.displayName = 'StyledTableBody';
var StyledTableBodyRow = (0, _styles.styled)('tr', function (_ref12) {
  var $theme = _ref12.$theme;
  return {
    ':hover': {
      backgroundColor: $theme.colors.tableStripedBackground
    }
  };
});
exports.StyledTableBodyRow = StyledTableBodyRow;
StyledTableBodyRow.displayName = "StyledTableBodyRow";
StyledTableBodyRow.displayName = 'StyledTableBodyRow';
var StyledTableBodyCell = (0, _styles.styled)('td', // @ts-ignore
function (_ref13) {
  var _notLastChild2;

  var $theme = _ref13.$theme,
      $size = _ref13.$size,
      $divider = _ref13.$divider,
      $isNumeric = _ref13.$isNumeric,
      $isLastRow = _ref13.$isLastRow;
  var borderDir = $theme.direction === 'rtl' ? 'Left' : 'Right';
  var borderVertical = $divider === _constants.DIVIDER.vertical || $divider === _constants.DIVIDER.grid;
  var borderHorizontal = $divider === undefined || $divider === _constants.DIVIDER.horizontal || $divider === _constants.DIVIDER.grid;
  var padding = sizeToCellPadding($theme, $size);
  return _objectSpread(_objectSpread({}, $theme.typography.font200), {}, {
    paddingTop: padding,
    paddingRight: padding,
    paddingBottom: padding,
    paddingLeft: padding,
    color: $theme.colors.contentPrimary,
    textAlign: $isNumeric ? 'right' : null,
    verticalAlign: 'top',
    borderBottomColor: !$isLastRow && borderHorizontal ? $theme.borders.border300.borderColor : null,
    borderBottomStyle: !$isLastRow && borderHorizontal ? $theme.borders.border300.borderStyle : null,
    borderBottomWidth: !$isLastRow && borderHorizontal ? $theme.borders.border300.borderWidth : null,
    ':not(:last-child)': (_notLastChild2 = {}, _defineProperty(_notLastChild2, "border".concat(borderDir, "Color"), borderVertical ? $theme.borders.border300.borderColor : null), _defineProperty(_notLastChild2, "border".concat(borderDir, "Style"), borderVertical ? $theme.borders.border300.borderStyle : null), _defineProperty(_notLastChild2, "border".concat(borderDir, "Width"), borderVertical ? $theme.borders.border300.borderWidth : null), _notLastChild2)
  });
});
exports.StyledTableBodyCell = StyledTableBodyCell;
StyledTableBodyCell.displayName = "StyledTableBodyCell";
StyledTableBodyCell.displayName = 'StyledTableBodyCell';
var StyledTableLoadingMessage = (0, _styles.styled)('div', function (_ref14) {
  var $theme = _ref14.$theme;
  return _objectSpread(_objectSpread({}, $theme.typography.ParagraphSmall), {}, {
    color: $theme.colors.contentPrimary,
    padding: $theme.sizing.scale600
  });
});
exports.StyledTableLoadingMessage = StyledTableLoadingMessage;
StyledTableLoadingMessage.displayName = "StyledTableLoadingMessage";
StyledTableLoadingMessage.displayName = 'StyledTableLoadingMessage';
var StyledTableEmptyMessage = StyledTableLoadingMessage;
exports.StyledTableEmptyMessage = StyledTableEmptyMessage;