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; }

/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import Blank from '../icon/blank';
import ChevronDown from '../icon/chevron-down';
import ChevronUp from '../icon/chevron-up';
import { styled, withStyle, expandBorderStyles } from '../styles';
import { SIZE, DIVIDER } from './constants';

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

  return $theme.sizing.scale600;
}

export var StyledRoot = styled('div', function (_ref) {
  var $theme = _ref.$theme,
      $divider = _ref.$divider;
  var borderStyles = $divider === DIVIDER.grid || $divider === DIVIDER.vertical ? expandBorderStyles($theme.borders.border300) : {};
  return _objectSpread(_objectSpread(_objectSpread({}, borderStyles), $divider === 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)'
  });
});
StyledRoot.displayName = "StyledRoot";
StyledRoot.displayName = 'StyledRoot';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// @ts-ignore
export var StyledTable = styled('table', function (_ref2) {
  var $theme = _ref2.$theme,
      $width = _ref2.$width;
  return {
    borderSpacing: '0',
    boxSizing: 'border-box',
    minWidth: '100%',
    width: $width || null
  };
});
StyledTable.displayName = "StyledTable";
StyledTable.displayName = 'StyledTable'; // eslint-disable-next-line @typescript-eslint/no-unused-vars

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

export var StyledTableHeadRow = styled('tr', function (_ref4) {
  var $theme = _ref4.$theme;
  return {};
});
StyledTableHeadRow.displayName = "StyledTableHeadRow";
StyledTableHeadRow.displayName = 'StyledTableHeadRow';
export var StyledTableHeadCell = 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 === DIVIDER.grid || $divider === 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 === 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)
  });
});
StyledTableHeadCell.displayName = "StyledTableHeadCell";
StyledTableHeadCell.displayName = 'StyledTableHeadCell';
export var StyledTableHeadCellSortable = 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
    }
  };
});
StyledTableHeadCellSortable.displayName = "StyledTableHeadCellSortable";
StyledTableHeadCellSortable.displayName = 'StyledTableHeadCellSortable';
export var StyledSortIconContainer = styled('span', function (_ref7) {
  var $theme = _ref7.$theme;
  return {
    display: 'flex',
    alignItems: 'center',
    position: 'absolute',
    top: '50%',
    right: $theme.sizing.scale500,
    transform: 'translateY(-50%)'
  };
});
StyledSortIconContainer.displayName = "StyledSortIconContainer";
StyledSortIconContainer.displayName = 'StyledSortIconContainer'; // No longer used, but will maintain for some time to support existing usage

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

export var StyledTableBody = styled('tbody', function (_ref11) {
  var $theme = _ref11.$theme;
  return {};
});
StyledTableBody.displayName = "StyledTableBody";
StyledTableBody.displayName = 'StyledTableBody';
export var StyledTableBodyRow = styled('tr', function (_ref12) {
  var $theme = _ref12.$theme;
  return {
    ':hover': {
      backgroundColor: $theme.colors.tableStripedBackground
    }
  };
});
StyledTableBodyRow.displayName = "StyledTableBodyRow";
StyledTableBodyRow.displayName = 'StyledTableBodyRow';
export var StyledTableBodyCell = 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 === DIVIDER.vertical || $divider === DIVIDER.grid;
  var borderHorizontal = $divider === undefined || $divider === DIVIDER.horizontal || $divider === 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)
  });
});
StyledTableBodyCell.displayName = "StyledTableBodyCell";
StyledTableBodyCell.displayName = 'StyledTableBodyCell';
export var StyledTableLoadingMessage = styled('div', function (_ref14) {
  var $theme = _ref14.$theme;
  return _objectSpread(_objectSpread({}, $theme.typography.ParagraphSmall), {}, {
    color: $theme.colors.contentPrimary,
    padding: $theme.sizing.scale600
  });
});
StyledTableLoadingMessage.displayName = "StyledTableLoadingMessage";
StyledTableLoadingMessage.displayName = 'StyledTableLoadingMessage';
export var StyledTableEmptyMessage = StyledTableLoadingMessage;