var _excluded = ["children", "inline", "variant"],
  _excluded2 = ["expanded"],
  _excluded3 = ["children", "shelf"],
  _excluded4 = ["children"],
  _excluded5 = ["children"],
  _excluded6 = ["sortOrder", "onClick", "onKeyUp", "onSortOrderChange", "sortable", "children", "snugfit", "variant"],
  _excluded7 = ["children"],
  _excluded8 = ["children"],
  _excluded9 = ["children", "colSpan", "depth"],
  _excluded10 = ["children", "overdue"],
  _excluded11 = ["children", "snugfit", "variant"],
  _excluded12 = ["children"],
  _excluded13 = ["children", "className", "disabled", "errorMessage", "processing"],
  _excluded14 = ["children"],
  _excluded15 = ["disabled", "errorMessage", "processing", "size"],
  _excluded16 = ["children", "href"],
  _excluded17 = ["children"],
  _excluded18 = ["block", "children", "disabled", "errorMessage", "className", "processing"],
  _excluded19 = ["disabled", "errorMessage", "processing", "resizable"],
  _excluded20 = ["children"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { useId } from '@react-aria/utils';
import { VisuallyHidden } from '@react-aria/visually-hidden';
import cx from 'classnames';
import React from 'react';
import { Link as LinkElement } from '../Link';
import { tableSelectClassName } from '../Select/Select.styles';
import { Spinner } from '../Spinner';
import { useI18nContext } from '../_hooks/I18n';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { StyledCarat, StyledCaratWrapper, StyledCheckbox, StyledHead, StyledIconCell, StyledLoadingContainer, StyledSelectCellWrapper, StyledTable, StyledTableBodyCell, StyledTableBodyRow, StyledTableCellDateInput, StyledTableCellInput, StyledTableCellSelect, StyledTableCellText, StyledTableCellTextArea, StyledTableGroupRow, StyledTableGroupRowContent, StyledTableGroupRowHeader, StyledTableGroupRowTitle, StyledTableHeaderCell, StyledTableHeaderCellIconWrapper, StyledTableHeaderCellLabel, StyledTableHeaderCellSortableContainer, StyledTableHeaderCellSortIconAsc, StyledTableHeaderCellSortIconDesc, StyledTableInlineEditContainer, StyledTableInlineEditErrorBox, StyledTableWrapper } from './Table.styles';
export var Table_ = /*#__PURE__*/React.forwardRef(function Table(_ref, ref) {
  var children = _ref.children,
    inline = _ref.inline,
    variant = _ref.variant,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React.createElement(StyledTable, _extends({
    ref: ref
  }, props, {
    $inline: inline,
    $fixed: variant === 'fixed'
  }), children);
});
export var Carat = /*#__PURE__*/React.forwardRef(function Carat(_ref2, ref) {
  var _ref2$expanded = _ref2.expanded,
    expanded = _ref2$expanded === void 0 ? false : _ref2$expanded,
    props = _objectWithoutProperties(_ref2, _excluded2);
  return /*#__PURE__*/React.createElement(StyledCaratWrapper, {
    ref: ref
  }, /*#__PURE__*/React.createElement(StyledCarat, _extends({
    $expanded: expanded
  }, props)));
});
export var Container = /*#__PURE__*/React.forwardRef(function Container(_ref3, ref) {
  var children = _ref3.children,
    _ref3$shelf = _ref3.shelf,
    shelf = _ref3$shelf === void 0 ? false : _ref3$shelf,
    props = _objectWithoutProperties(_ref3, _excluded3);
  return /*#__PURE__*/React.createElement(StyledTableWrapper, _extends({}, props, {
    ref: ref,
    shadowStrength: 0,
    $withShelf: shelf
  }), children);
});
export var Header = /*#__PURE__*/React.forwardRef(function Header(_ref4, ref) {
  var children = _ref4.children,
    props = _objectWithoutProperties(_ref4, _excluded4);
  return /*#__PURE__*/React.createElement(StyledHead, _extends({
    ref: ref
  }, props), children);
});
export var HeaderRow = /*#__PURE__*/React.forwardRef(function HeaderRow(_ref5, ref) {
  var children = _ref5.children,
    props = _objectWithoutProperties(_ref5, _excluded5);
  return /*#__PURE__*/React.createElement("tr", _extends({
    ref: ref
  }, props), children);
});
export var HeaderCell = /*#__PURE__*/React.forwardRef(function HeaderCell(_ref6, ref) {
  var sortOrder_ = _ref6.sortOrder,
    _onClick = _ref6.onClick,
    _onKeyUp = _ref6.onKeyUp,
    onSortOrderChange_ = _ref6.onSortOrderChange,
    sortable = _ref6.sortable,
    children = _ref6.children,
    _ref6$snugfit = _ref6.snugfit,
    snugfit = _ref6$snugfit === void 0 ? false : _ref6$snugfit,
    variant = _ref6.variant,
    props = _objectWithoutProperties(_ref6, _excluded6);
  var I18n = useI18nContext();
  var descriptionId = useId();
  var sortOrder = sortOrder_ !== null && sortOrder_ !== void 0 ? sortOrder_ : variant !== 'snugfit' ? variant : undefined;
  var isSortable = sortOrder !== undefined && sortable !== false;
  var ariaSortValues = {
    asc: 'ascending',
    desc: 'descending',
    '': 'none'
  };
  var onSortOrderChange = function onSortOrderChange() {
    if (!onSortOrderChange_) {
      return;
    }
    var nextValue = sortOrder === '' ? 'asc' : sortOrder === 'asc' ? 'desc' : '';
    onSortOrderChange_(nextValue);
  };
  return /*#__PURE__*/React.createElement(StyledTableHeaderCell, _extends({
    ref: ref
  }, props, {
    role: "columnheader",
    "aria-sort": isSortable ? ariaSortValues[sortOrder !== null && sortOrder !== void 0 ? sortOrder : ''] : undefined,
    tabIndex: isSortable ? 0 : undefined,
    "aria-describedby": isSortable ? descriptionId : undefined,
    $sortable: isSortable,
    $sortOrder: sortOrder,
    $snugfit: snugfit || variant === 'snugfit',
    onKeyUp: function onKeyUp(e) {
      if (['Space', 'Enter'].includes(e.code) && isSortable) {
        onSortOrderChange();
      }
      return _onKeyUp === null || _onKeyUp === void 0 ? void 0 : _onKeyUp(e);
    },
    onClick: function onClick(e) {
      if (isSortable) {
        onSortOrderChange();
      }
      return _onClick === null || _onClick === void 0 ? void 0 : _onClick(e);
    }
  }), /*#__PURE__*/React.createElement(StyledTableHeaderCellSortableContainer, null, /*#__PURE__*/React.createElement(StyledTableHeaderCellLabel, null, children), isSortable && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledTableHeaderCellIconWrapper, {
    "aria-hidden": "true"
  }, /*#__PURE__*/React.createElement(StyledTableHeaderCellSortIconAsc, null), /*#__PURE__*/React.createElement(StyledTableHeaderCellSortIconDesc, null)), /*#__PURE__*/React.createElement(VisuallyHidden, {
    "aria-hidden": "true",
    id: descriptionId
  }, I18n.t('core.table.sortableColumn')))));
});
export var Body = /*#__PURE__*/React.forwardRef(function Body(_ref7, ref) {
  var children = _ref7.children,
    props = _objectWithoutProperties(_ref7, _excluded7);
  return /*#__PURE__*/React.createElement("tbody", _extends({
    ref: ref
  }, props), children);
});
export var Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(props, ref) {
  return /*#__PURE__*/React.createElement(StyledCheckbox, _extends({
    ref: ref
  }, props));
});
export var GroupTitle = /*#__PURE__*/React.forwardRef(function GroupTitle(_ref8, ref) {
  var children = _ref8.children,
    props = _objectWithoutProperties(_ref8, _excluded8);
  return /*#__PURE__*/React.createElement(StyledTableGroupRowTitle, _extends({
    ref: ref
  }, props), children);
});
export var Group = /*#__PURE__*/React.forwardRef(function Group(_ref9, ref) {
  var children = _ref9.children,
    _ref9$colSpan = _ref9.colSpan,
    colSpan = _ref9$colSpan === void 0 ? 1000 : _ref9$colSpan,
    _ref9$depth = _ref9.depth,
    depth = _ref9$depth === void 0 ? false : _ref9$depth,
    props = _objectWithoutProperties(_ref9, _excluded9);
  return /*#__PURE__*/React.createElement(StyledTableGroupRow, _extends({
    ref: ref,
    $depth: depth
  }, props), /*#__PURE__*/React.createElement("td", {
    colSpan: colSpan
  }, /*#__PURE__*/React.createElement(StyledTableGroupRowContent, null, /*#__PURE__*/React.createElement(StyledTableGroupRowHeader, null, children))));
});
export var BodyRow = /*#__PURE__*/React.forwardRef(function BodyRow(_ref10, ref) {
  var children = _ref10.children,
    _ref10$overdue = _ref10.overdue,
    overdue = _ref10$overdue === void 0 ? false : _ref10$overdue,
    props = _objectWithoutProperties(_ref10, _excluded10);
  return /*#__PURE__*/React.createElement(StyledTableBodyRow, _extends({
    ref: ref,
    $overdue: overdue
  }, props), children);
});
export var BodyCell = /*#__PURE__*/React.forwardRef(function BodyCell(_ref11, ref) {
  var children = _ref11.children,
    _ref11$snugfit = _ref11.snugfit,
    snugfit = _ref11$snugfit === void 0 ? false : _ref11$snugfit,
    _ref11$variant = _ref11.variant,
    variant = _ref11$variant === void 0 ? '' : _ref11$variant,
    props = _objectWithoutProperties(_ref11, _excluded11);
  return /*#__PURE__*/React.createElement(StyledTableBodyCell, _extends({
    ref: ref,
    $snugfit: snugfit || variant === 'snugfit'
  }, props), children);
});
export var CurrencyCell = /*#__PURE__*/React.forwardRef(function CurrencyCell(_ref12, ref) {
  var children = _ref12.children,
    props = _objectWithoutProperties(_ref12, _excluded12);
  return /*#__PURE__*/React.createElement(StyledTableCellText, _extends({
    $currency: true,
    ref: ref
  }, props), children);
});
export var DateSelectCell = /*#__PURE__*/React.forwardRef(function DateSelectCell(_ref13, ref) {
  var children = _ref13.children,
    className = _ref13.className,
    _ref13$disabled = _ref13.disabled,
    disabled = _ref13$disabled === void 0 ? false : _ref13$disabled,
    errorMessage = _ref13.errorMessage,
    _ref13$processing = _ref13.processing,
    processing = _ref13$processing === void 0 ? false : _ref13$processing,
    props = _objectWithoutProperties(_ref13, _excluded13);
  var error = Boolean(errorMessage);
  return /*#__PURE__*/React.createElement(StyledTableInlineEditContainer, {
    $disabled: disabled,
    $error: error,
    $size: "block",
    className: cx({
      disabled: disabled,
      error: error
    })
  }, processing && /*#__PURE__*/React.createElement(StyledLoadingContainer, null, /*#__PURE__*/React.createElement(Spinner, {
    loading: processing,
    size: "md"
  })), /*#__PURE__*/React.createElement(StyledTableCellDateInput, _extends({}, props, {
    disabled: processing || disabled,
    ref: ref,
    variant: error ? 'error' : ''
  })), !processing && error && /*#__PURE__*/React.createElement(StyledTableInlineEditErrorBox, null, errorMessage));
});
export var IconCell = /*#__PURE__*/React.forwardRef(function IconCell(_ref14, ref) {
  var children = _ref14.children,
    props = _objectWithoutProperties(_ref14, _excluded14);
  return /*#__PURE__*/React.createElement(StyledIconCell, _extends({
    ref: ref
  }, props), children);
});
export var InputCell = /*#__PURE__*/React.forwardRef(function InputCell(_ref15, ref) {
  var _ref15$disabled = _ref15.disabled,
    disabled = _ref15$disabled === void 0 ? false : _ref15$disabled,
    _ref15$errorMessage = _ref15.errorMessage,
    errorMessage = _ref15$errorMessage === void 0 ? '' : _ref15$errorMessage,
    _ref15$processing = _ref15.processing,
    processing = _ref15$processing === void 0 ? false : _ref15$processing,
    _ref15$size = _ref15.size,
    size = _ref15$size === void 0 ? 'block' : _ref15$size,
    props = _objectWithoutProperties(_ref15, _excluded15);
  var error = Boolean(errorMessage);
  return /*#__PURE__*/React.createElement(StyledTableInlineEditContainer, {
    $disabled: disabled,
    $error: error,
    $size: size,
    className: cx({
      disabled: disabled,
      error: error
    })
  }, processing && /*#__PURE__*/React.createElement(StyledLoadingContainer, null, /*#__PURE__*/React.createElement(Spinner, {
    loading: processing,
    size: "md"
  })), /*#__PURE__*/React.createElement(StyledTableCellInput, _extends({}, props, {
    ref: ref,
    disabled: processing || disabled
  })), !processing && error && /*#__PURE__*/React.createElement(StyledTableInlineEditErrorBox, {
    $size: size
  }, errorMessage));
});
export var LinkCell = /*#__PURE__*/React.forwardRef(function LinkCell(_ref16, ref) {
  var children = _ref16.children,
    _ref16$href = _ref16.href,
    href = _ref16$href === void 0 ? '' : _ref16$href,
    props = _objectWithoutProperties(_ref16, _excluded16);
  return /*#__PURE__*/React.createElement(TextCell, {
    ref: ref
  }, /*#__PURE__*/React.createElement(LinkElement, _extends({
    href: href
  }, props), children));
});
export var PercentCell = /*#__PURE__*/React.forwardRef(function PercentCell(_ref17, ref) {
  var children = _ref17.children,
    props = _objectWithoutProperties(_ref17, _excluded17);
  return /*#__PURE__*/React.createElement(StyledTableCellText, _extends({
    $percent: true,
    ref: ref
  }, props), children);
});
export var SelectCell = /*#__PURE__*/React.forwardRef(function SelectCell(_ref18, ref) {
  var _ref18$block = _ref18.block,
    block = _ref18$block === void 0 ? true : _ref18$block,
    children = _ref18.children,
    disabled = _ref18.disabled,
    errorMessage = _ref18.errorMessage,
    className = _ref18.className,
    _ref18$processing = _ref18.processing,
    processing = _ref18$processing === void 0 ? false : _ref18$processing,
    props = _objectWithoutProperties(_ref18, _excluded18);
  var error = Boolean(errorMessage);
  var hasClearIcon = !disabled && !props.loading && Boolean(props.label);
  return /*#__PURE__*/React.createElement(StyledTableInlineEditContainer, {
    $disabled: disabled,
    $error: error,
    $size: "block",
    className: cx({
      disabled: disabled,
      error: error
    })
  }, processing && /*#__PURE__*/React.createElement(StyledLoadingContainer, null, /*#__PURE__*/React.createElement(Spinner, {
    loading: processing,
    size: "md"
  })), /*#__PURE__*/React.createElement(StyledSelectCellWrapper, null, /*#__PURE__*/React.createElement(StyledTableCellSelect, _extends({}, props, {
    $placeholder: !props.label,
    $hasClearIcon: hasClearIcon,
    block: block,
    className: cx(tableSelectClassName, className),
    disabled: processing || disabled,
    error: error,
    ref: ref
  }), children)), !processing && errorMessage && /*#__PURE__*/React.createElement(StyledTableInlineEditErrorBox, null, errorMessage));
});
export var TextAreaCell = /*#__PURE__*/React.forwardRef(function TextAreaCell(_ref19, ref) {
  var disabled = _ref19.disabled,
    _ref19$errorMessage = _ref19.errorMessage,
    errorMessage = _ref19$errorMessage === void 0 ? '' : _ref19$errorMessage,
    _ref19$processing = _ref19.processing,
    processing = _ref19$processing === void 0 ? false : _ref19$processing,
    _ref19$resizable = _ref19.resizable,
    resizable = _ref19$resizable === void 0 ? false : _ref19$resizable,
    props = _objectWithoutProperties(_ref19, _excluded19);
  var textareaRef = ref || /*#__PURE__*/React.createRef();
  var setHeight = function setHeight() {
    if (textareaRef && textareaRef.current) {
      textareaRef.current.style.height = 'auto';
      textareaRef.current.style.height = "".concat(textareaRef.current.scrollHeight, "px");
    }
  };
  var error = Boolean(errorMessage);
  return /*#__PURE__*/React.createElement(StyledTableInlineEditContainer, {
    $disabled: disabled,
    $error: error,
    $size: "block",
    className: cx({
      disabled: disabled,
      error: error
    })
  }, processing && /*#__PURE__*/React.createElement(StyledLoadingContainer, null, /*#__PURE__*/React.createElement(Spinner, {
    loading: processing,
    size: "md"
  })), /*#__PURE__*/React.createElement(StyledTableCellTextArea, _extends({}, props, {
    $resizable: resizable,
    disabled: processing || disabled,
    onBlur: function onBlur(event) {
      setHeight();
      props.onBlur && props.onBlur(event);
    },
    ref: textareaRef,
    resize: "none",
    rows: 1
  })), !processing && error && /*#__PURE__*/React.createElement(StyledTableInlineEditErrorBox, null, errorMessage));
});
export var TextCell = /*#__PURE__*/React.forwardRef(function TextCell(_ref20, ref) {
  var children = _ref20.children,
    props = _objectWithoutProperties(_ref20, _excluded20);
  return /*#__PURE__*/React.createElement(StyledTableCellText, _extends({
    ref: ref
  }, props), children);
});
Table_.displayName = 'Table';
Body.displayName = 'Table.Body';
BodyCell.displayName = 'Table.BodyCell';
BodyRow.displayName = 'Table.BodyRow';
Carat.displayName = 'Table.Carat';
Checkbox.displayName = 'Table.Checkbox';
Container.displayName = 'Table.Container';
CurrencyCell.displayName = 'Table.CurrencyCell';
DateSelectCell.displayName = 'Table.DateSelect';
Group.displayName = 'Table.Group';
GroupTitle.displayName = 'Table.GroupTitle';
Header.displayName = 'Table.Header';
HeaderCell.displayName = 'Table.HeaderCell';
HeaderRow.displayName = 'Table.HeaderRow';
IconCell.displayName = 'Table.IconCell';
InputCell.displayName = 'Table.InputCell';
LinkCell.displayName = 'Table.LinkCell';
PercentCell.displayName = 'Table.ParentCell';
TextAreaCell.displayName = 'Table.TextAreaCell';
TextCell.displayName = 'Table.TextCell';

/**

 @since 10.19.0

 @see [Storybook](https://procore.github.io/core/core-react/latest/?path=/story/demos-table--demo)

 */
export var Table = addSubcomponents({
  Body: Body,
  BodyCell: BodyCell,
  BodyRow: BodyRow,
  Carat: Carat,
  Checkbox: Checkbox,
  Container: Container,
  CurrencyCell: CurrencyCell,
  DateSelectCell: DateSelectCell,
  Group: Group,
  GroupTitle: GroupTitle,
  Header: Header,
  HeaderCell: HeaderCell,
  HeaderRow: HeaderRow,
  IconCell: IconCell,
  InputCell: InputCell,
  LinkCell: LinkCell,
  PercentCell: PercentCell,
  SelectCell: SelectCell,
  TextAreaCell: TextAreaCell,
  TextCell: TextCell
}, Table_);
//# sourceMappingURL=Table.js.map