'use strict';

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
require('core-js/modules/es.array.concat.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.array.find.js');
require('core-js/modules/es.array.find-index.js');
require('core-js/modules/es.array.iterator.js');
require('core-js/modules/es.array.map.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.iterator.js');
var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var classnames = require('classnames');
var Settings = require('../../../../constants/Settings.js');
var SharedPropTypes = require('../../../../constants/SharedPropTypes.js');
var RowActionsCell = require('../RowActionsCell/RowActionsCell.js');
var TableCellRenderer = require('../../TableCellRenderer/TableCellRenderer.js');
var TablePropTypes = require('../../TablePropTypes.js');
var componentUtilityFunctions = require('../../../../utils/componentUtilityFunctions.js');
var TableExpandRow = require('./TableExpandRow.js');
var TableDragHandle = require('./TableDragHandle.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var prefix = Settings.settings.prefix,
  iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /** What column ordering is currently applied to the table */
  ordering: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
    columnId: PropTypes__default.default.string.isRequired,
    /* Visibility of column in table, defaults to false */
    isHidden: PropTypes__default.default.bool,
    /** for each column you can register a render callback function that is called with this object payload
     * {
     *    value: PropTypes.any (current cell value),
     *    columnId: PropTypes.string,
     *    rowId: PropTypes.string,
     *    row: PropTypes.object like this {col: value, col2: value}
     * }, you should return the node that should render within that cell */
    renderDataFunction: PropTypes__default.default.func
  })).isRequired,
  /** internationalized label */
  selectRowAria: PropTypes__default.default.string,
  /** internationalized label  */
  overflowMenuAria: PropTypes__default.default.string,
  /** internationalized label */
  clickToExpandAria: PropTypes__default.default.string,
  /** internationalized label  */
  clickToCollapseAria: PropTypes__default.default.string,
  /** I18N label for drag handle tooltip */
  dragHandleTooltip: PropTypes__default.default.string,
  /** List of columns */
  columns: TablePropTypes.TableColumnsPropTypes.isRequired,
  /** table wide options */
  options: PropTypes__default.default.shape({
    hasRowSelection: PropTypes__default.default.oneOf(['multi', 'single', false]),
    hasRowExpansion: PropTypes__default.default.bool,
    hasRowNesting: PropTypes__default.default.oneOfType([PropTypes__default.default.bool, PropTypes__default.default.shape({
      /** If the hierarchy only has 1 nested level of children */
      hasSingleNestedHierarchy: PropTypes__default.default.bool
    })]),
    hasRowActions: PropTypes__default.default.bool,
    shouldExpandOnRowClick: PropTypes__default.default.bool,
    wrapCellText: SharedPropTypes.WrapCellTextPropTypes.isRequired,
    truncateCellText: PropTypes__default.default.bool.isRequired,
    /** use white-space: pre; css when true */
    preserveCellWhiteSpace: PropTypes__default.default.bool,
    /** use radio button on single selection */
    useRadioButtonSingleSelect: PropTypes__default.default.bool,
    hasDragAndDrop: PropTypes__default.default.bool
  }),
  /** The unique row id */
  id: PropTypes__default.default.string.isRequired,
  /** The unique id for the table */
  tableId: PropTypes__default.default.string.isRequired,
  /** some columns might be hidden, so total columns has the overall total */
  totalColumns: PropTypes__default.default.number.isRequired,
  /** contents of the row each object value is a render-able node keyed by column id */
  values: PropTypes__default.default.objectOf(PropTypes__default.default.oneOfType([PropTypes__default.default.node, PropTypes__default.default.bool, PropTypes__default.default.object, PropTypes__default.default.array])).isRequired,
  /** is the row currently selected */
  isSelected: PropTypes__default.default.bool,
  /** is the row currently in an indeterminate state, i.e. some but not all children are checked */
  isIndeterminate: PropTypes__default.default.bool,
  /** is the row currently expanded */
  isExpanded: PropTypes__default.default.bool,
  /** optional row details */
  rowDetails: PropTypes__default.default.node,
  /** offset level if row is nested */
  nestingLevel: PropTypes__default.default.number,
  /** number of child rows underneath this row */
  nestingChildCount: PropTypes__default.default.number,
  /** tableActions */
  tableActions: PropTypes__default.default.shape({
    onRowSelected: PropTypes__default.default.func,
    onRowClicked: PropTypes__default.default.func,
    onApplyRowAction: PropTypes__default.default.func,
    onRowExpanded: PropTypes__default.default.func,
    onClearRowError: PropTypes__default.default.func
  }).isRequired,
  /** optional per-row actions */
  rowActions: TablePropTypes.RowActionPropTypes,
  /** Is a row action actively running */
  isRowActionRunning: PropTypes__default.default.bool,
  /** has a row action errored out */
  rowActionsError: TablePropTypes.RowActionErrorPropTypes,
  /** I18N label for in progress */
  inProgressText: PropTypes__default.default.string,
  /** I18N label for action failed */
  actionFailedText: PropTypes__default.default.string,
  /** I18N label for learn more */
  learnMoreText: PropTypes__default.default.string,
  /** I18N label for dismiss */
  dismissText: PropTypes__default.default.string,
  locale: PropTypes__default.default.string,
  rowEditMode: PropTypes__default.default.bool,
  singleRowEditMode: PropTypes__default.default.bool,
  isSelectable: PropTypes__default.default.bool,
  singleRowEditButtons: PropTypes__default.default.element,
  /**
   * direction of document
   */
  langDir: PropTypes__default.default.oneOf(['ltr', 'rtl']),
  /** shows an additional column that can expand/shrink as the table is resized  */
  showExpanderColumn: PropTypes__default.default.bool,
  /**
   * the size passed to the table to set row height
   */
  size: PropTypes__default.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
  /** True if this is the last child of a nested group */
  isLastChild: PropTypes__default.default.bool,
  /** If this row supports drag and drop. Add space for a drag handle. */
  hasDragAndDrop: PropTypes__default.default.bool,
  /** Callback when a drag of this  row starts. */
  onStartDrag: PropTypes__default.default.func,
  /** Callback when the mouse enters this row during a drag. */
  onDragEnterRow: PropTypes__default.default.func,
  /** Callback when the mouse leaves this row during a drag. */
  onDragLeaveRow: PropTypes__default.default.func,
  /** If this row can be dragged. Shows a drag handle. */
  isDraggable: PropTypes__default.default.bool,
  /** If this row is being dragged. */
  isDragRow: PropTypes__default.default.bool,
  /** If a drag operation is currently in progress. */
  isDragging: PropTypes__default.default.bool,
  /** If all drag handles should be hidden. This happens when an undraggable row is in the selection. */
  hideDragHandles: PropTypes__default.default.bool,
  /** Attribute name to identify deleted rows */
  deletedAttribute: PropTypes__default.default.string
};
var defaultProps = {
  isSelected: false,
  isIndeterminate: false,
  isExpanded: false,
  selectRowAria: 'Select row',
  overflowMenuAria: 'More actions',
  clickToExpandAria: 'Click to expand.',
  clickToCollapseAria: 'Click to collapse.',
  dragHandleTooltip: 'Click and drag to new location',
  rowActions: null,
  rowDetails: null,
  nestingLevel: 0,
  nestingChildCount: 0,
  options: {},
  rowEditMode: false,
  singleRowEditMode: false,
  singleRowEditButtons: null,
  isRowActionRunning: false,
  rowActionsError: null,
  learnMoreText: 'Learn more',
  inProgressText: 'In progress',
  dismissText: 'Dismiss',
  actionFailedText: 'Action failed',
  showExpanderColumn: false,
  langDir: 'ltr',
  locale: 'en',
  isSelectable: undefined,
  size: undefined,
  isLastChild: false,
  hasDragAndDrop: false,
  hideDragHandles: false,
  onStartDrag: null,
  onDragEnterRow: null,
  onDragLeaveRow: null,
  isDraggable: false,
  isDragRow: false,
  isDragging: false,
  deletedAttribute: '_deleted'
};
var TableBodyRow = function TableBodyRow(_ref) {
  var id = _ref.id,
    tableId = _ref.tableId,
    langDir = _ref.langDir,
    totalColumns = _ref.totalColumns,
    ordering = _ref.ordering,
    columns = _ref.columns,
    locale = _ref.locale,
    _ref$options = _ref.options,
    hasRowSelection = _ref$options.hasRowSelection,
    hasRowExpansion = _ref$options.hasRowExpansion,
    hasRowActions = _ref$options.hasRowActions,
    hasRowNesting = _ref$options.hasRowNesting,
    shouldExpandOnRowClick = _ref$options.shouldExpandOnRowClick,
    wrapCellText = _ref$options.wrapCellText,
    truncateCellText = _ref$options.truncateCellText,
    preserveCellWhiteSpace = _ref$options.preserveCellWhiteSpace,
    useRadioButtonSingleSelect = _ref$options.useRadioButtonSingleSelect,
    _ref$tableActions = _ref.tableActions,
    onRowSelected = _ref$tableActions.onRowSelected,
    onRowExpanded = _ref$tableActions.onRowExpanded,
    onRowClicked = _ref$tableActions.onRowClicked,
    onApplyRowAction = _ref$tableActions.onApplyRowAction,
    onClearRowError = _ref$tableActions.onClearRowError,
    isExpanded = _ref.isExpanded,
    isSelected = _ref.isSelected,
    isIndeterminate = _ref.isIndeterminate,
    selectRowAria = _ref.selectRowAria,
    overflowMenuAria = _ref.overflowMenuAria,
    clickToExpandAria = _ref.clickToExpandAria,
    clickToCollapseAria = _ref.clickToCollapseAria,
    dragHandleTooltip = _ref.dragHandleTooltip,
    inProgressText = _ref.inProgressText,
    actionFailedText = _ref.actionFailedText,
    learnMoreText = _ref.learnMoreText,
    dismissText = _ref.dismissText,
    isSelectable = _ref.isSelectable,
    values = _ref.values,
    nestingLevel = _ref.nestingLevel,
    nestingChildCount = _ref.nestingChildCount,
    rowActions = _ref.rowActions,
    isRowActionRunning = _ref.isRowActionRunning,
    rowActionsError = _ref.rowActionsError,
    rowDetails = _ref.rowDetails,
    rowEditMode = _ref.rowEditMode,
    singleRowEditMode = _ref.singleRowEditMode,
    singleRowEditButtons = _ref.singleRowEditButtons,
    showExpanderColumn = _ref.showExpanderColumn,
    size = _ref.size,
    isLastChild = _ref.isLastChild,
    onStartDrag = _ref.onStartDrag,
    onDragEnterRow = _ref.onDragEnterRow,
    onDragLeaveRow = _ref.onDragLeaveRow,
    isDragRow = _ref.isDragRow,
    isDraggable = _ref.isDraggable,
    isDragging = _ref.isDragging,
    hasDragAndDrop = _ref.hasDragAndDrop,
    hideDragHandles = _ref.hideDragHandles,
    deletedAttribute = _ref.deletedAttribute;
  var isEditMode = rowEditMode || singleRowEditMode;
  var singleSelectionIndicatorWidth = hasRowSelection === 'single' ? 0 : 5;
  var nestingLevelPixels = nestingLevel * 32;

  // if this a single hierarchy (i.e. only 1 level of nested children), do NOT show the gray offset
  var nestingOffset = hasRowNesting !== null && hasRowNesting !== void 0 && hasRowNesting.hasSingleNestedHierarchy ? 0 : hasRowSelection === 'single' ? nestingLevelPixels - singleSelectionIndicatorWidth : nestingLevelPixels;
  var rowSelectionCell = hasRowSelection === 'multi' ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    className: "".concat(prefix, "--checkbox-table-cell"),
    key: "".concat(id, "-row-selection-cell"),
    onChange: isSelectable !== false ? function () {
      return onRowSelected(id, !isSelected);
    } : null,
    onClick: function onClick(e) {
      return e.stopPropagation();
    },
    onKeyDown: function onKeyDown(e) {
      if (isSelectable !== false && (e.key === ' ' || e.key === 'Enter')) {
        e.preventDefault();
        e.stopPropagation();
        onRowSelected(id, !isSelected);
      }
    }
  }, /*#__PURE__*/React__default.default.createElement("span", {
    className: "".concat(iotPrefix, "--table__cell__offset"),
    style: {
      '--row-nesting-offset': "".concat(nestingOffset, "px")
    }
  }, /*#__PURE__*/React__default.default.createElement(react.Checkbox, {
    id: "select-row-".concat(tableId, "-").concat(id),
    labelText: selectRowAria,
    hideLabel: true,
    indeterminate: isIndeterminate,
    checked: isSelected,
    disabled: isSelectable === false
  }))) : hasRowSelection === 'single' && useRadioButtonSingleSelect ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    className: "".concat(prefix, "--radiobutton-table-cell"),
    key: "".concat(id, "-row-selection-cell"),
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, /*#__PURE__*/React__default.default.createElement("span", {
    className: "".concat(iotPrefix, "--table__cell__offset"),
    style: {
      '--row-nesting-offset': "".concat(nestingOffset, "px")
    }
  }, /*#__PURE__*/React__default.default.createElement(react.RadioButton, {
    id: "select-row-".concat(tableId, "-").concat(id),
    name: "select-row-".concat(tableId, "-").concat(id),
    hideLabel: true,
    labelText: selectRowAria,
    checked: isSelected,
    onClick: isSelectable !== false ? function () {
      return onRowSelected(id, !isSelected);
    } : null,
    disabled: isSelectable === false
  }))) : null;
  var dragHandleCell = !hasDragAndDrop ? null : /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    className: "".concat(iotPrefix, "--table-grab-handle-cell")
  }, !isDraggable || hideDragHandles ? null : /*#__PURE__*/React__default.default.createElement(TableDragHandle.TableDragHandle, {
    onStartDrag: onStartDrag,
    rowId: id,
    isDragging: isDragging,
    tooltipText: dragHandleTooltip
  }));
  var firstVisibleColIndex = ordering.findIndex(function (col) {
    return !col.isHidden;
  });
  var tableCells = /*#__PURE__*/React__default.default.createElement(React.Fragment, {
    key: "".concat(tableId, "-").concat(id)
  }, dragHandleCell, rowSelectionCell, ordering.map(function (col, idx) {
    var _col$filter;
    var matchingColumnMeta = columns && columns.find(function (column) {
      return column.id === col.columnId;
    });
    // initialColumnWidth for the table body cells is needed for tables that have fixed column widths
    // and table-layout:auto combination so that cell content can be truncated
    var initialColumnWidth = matchingColumnMeta && matchingColumnMeta.width;
    // if this a single hierarchy (i.e. only 1 level of nested children), do NOT show the gray offset
    var offset = firstVisibleColIndex === idx ? nestingOffset : 0;
    var align = matchingColumnMeta && matchingColumnMeta.align ? matchingColumnMeta.align : 'start';
    var sortable = matchingColumnMeta && matchingColumnMeta.isSortable && matchingColumnMeta.align === 'end' ? matchingColumnMeta.isSortable : false;
    return !col.isHidden ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
      id: "cell-".concat(tableId, "-").concat(id, "-").concat(col.columnId),
      key: col.columnId,
      "data-column": col.columnId,
      "data-offset": offset,
      offset: offset,
      align: align,
      className: classnames__default.default("data-table-".concat(align), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--table__cell--truncate"), truncateCellText), "".concat(iotPrefix, "--table__cell--sortable"), sortable), "cds--table-cell--column-slug", col.decorator)),
      width: initialColumnWidth
    }, /*#__PURE__*/React__default.default.createElement("span", {
      className: classnames__default.default("".concat(iotPrefix, "--table__cell__offset"), _defineProperty__default.default({}, "".concat(iotPrefix, "--table__cell__offset__expand"), wrapCellText === 'expand')),
      style: {
        '--row-nesting-offset': "".concat(offset, "px")
      }
    }, col.editDataFunction && isEditMode ? col.editDataFunction({
      value: values[col.columnId],
      columnId: col.columnId,
      rowId: id,
      row: values
    }) : /*#__PURE__*/React__default.default.createElement(TableCellRenderer, {
      wrapText: wrapCellText,
      truncateCellText: truncateCellText,
      locale: locale,
      renderDataFunction: col.renderDataFunction,
      isSortable: col.isSortable,
      sortFunction: col.sortFunction,
      isFilterable: col.filter,
      filterFunction: (_col$filter = col.filter) === null || _col$filter === void 0 ? void 0 : _col$filter.filterFunction,
      columnId: col.columnId,
      rowId: id,
      row: values,
      preserveCellWhiteSpace: preserveCellWhiteSpace
    }, values[col.columnId]))) : null;
  }), showExpanderColumn ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    key: "".concat(tableId, "-").concat(id, "-row-expander-cell")
  }) : null, hasRowActions && rowActions ? /*#__PURE__*/React__default.default.createElement(RowActionsCell, {
    id: id,
    langDir: langDir,
    tableId: tableId,
    actions: rowActions,
    isRowActionRunning: isRowActionRunning,
    isRowExpanded: isExpanded && !hasRowNesting,
    showSingleRowEditButtons: singleRowEditMode,
    singleRowEditButtons: singleRowEditButtons,
    overflowMenuAria: overflowMenuAria,
    inProgressText: inProgressText,
    actionFailedText: actionFailedText,
    onApplyRowAction: onApplyRowAction,
    learnMoreText: learnMoreText,
    dismissText: dismissText,
    rowActionsError: rowActionsError,
    onClearError: onClearRowError ? function () {
      return onClearRowError(id);
    } : null,
    size: size
  }) : nestingLevel > 0 && hasRowActions ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    key: "".concat(tableId, "-").concat(id, "-row-actions-cell")
  }) : undefined);
  var dragEnterLeaveHandlers = {
    onMouseEnter: !onDragEnterRow ? undefined : function (e) {
      onDragEnterRow(id, e.currentTarget);
    },
    onMouseLeave: !onDragLeaveRow ? undefined : function (e) {
      onDragLeaveRow(id, e.currentTarget);
    }
  };
  return hasRowExpansion || hasRowNesting ? isExpanded ? /*#__PURE__*/React__default.default.createElement(React.Fragment, {
    key: id
  }, /*#__PURE__*/React__default.default.createElement(TableExpandRow, _extends__default.default({
    expandHeaderId: "".concat(tableId, "-expand"),
    className: classnames__default.default("".concat(iotPrefix, "--expandable-tablerow--expanded"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--expandable-tablerow--indented"), parseInt(nestingOffset, 10) > 0), "".concat(iotPrefix, "--expandable-tablerow--childless"), hasRowNesting && nestingChildCount === 0), "".concat(iotPrefix, "--table__row--dragging"), isDragRow), "".concat(iotPrefix, "--table__row--softdeleted"), values === null || values === void 0 ? void 0 : values[deletedAttribute]), "".concat(iotPrefix, "--table__row--updated"), values === null || values === void 0 ? void 0 : values._updated)),
    ariaLabel: clickToCollapseAria,
    expandIconDescription: clickToCollapseAria,
    isExpanded: true,
    isSelected: isSelected,
    hasRowSelection: hasRowSelection,
    "data-row-nesting": hasRowNesting,
    "data-nesting-offset": nestingOffset,
    onExpand: function onExpand(evt) {
      return componentUtilityFunctions.stopPropagationAndCallback(evt, onRowExpanded, id, false);
    },
    onClick: function onClick() {
      if (shouldExpandOnRowClick && (hasRowNesting && nestingChildCount || hasRowExpansion)) {
        onRowExpanded(id, false);
      }
      if (hasRowSelection === 'single' && isSelectable !== false) {
        onRowSelected(id, true);
      }
      if (isSelectable !== false) {
        onRowClicked(id);
      }
    },
    style: {
      '--row-nesting-offset': "".concat(nestingOffset, "px")
    },
    rowId: id,
    langDir: langDir
  }, dragEnterLeaveHandlers), tableCells), !hasRowNesting && /*#__PURE__*/React__default.default.createElement(react.TableRow, _extends__default.default({
    className: classnames__default.default("".concat(iotPrefix, "--expanded-tablerow"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--expanded-tablerow--singly-selected"), hasRowSelection === 'single' && isSelected && !useRadioButtonSingleSelect), "".concat(iotPrefix, "--table__row--dragging"), isDragRow), "".concat(iotPrefix, "--table__row--softdeleted"), values === null || values === void 0 ? void 0 : values[deletedAttribute]), "".concat(iotPrefix, "--table__row--updated"), values === null || values === void 0 ? void 0 : values._updated))
  }, dragEnterLeaveHandlers), /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    colSpan: totalColumns
  }, rowDetails))) : /*#__PURE__*/React__default.default.createElement(TableExpandRow, _extends__default.default({
    key: id,
    expandHeaderId: "".concat(tableId, "-expand"),
    className: classnames__default.default("".concat(iotPrefix, "--expandable-tablerow"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--expandable-tablerow--parent"), hasRowNesting && (hasRowNesting === null || hasRowNesting === void 0 ? void 0 : hasRowNesting.hasSingleNestedHierarchy) && nestingChildCount > 0), "".concat(iotPrefix, "--expandable-tablerow--childless"), hasRowNesting && nestingChildCount === 0), "".concat(iotPrefix, "--expandable-tablerow--indented"), parseInt(nestingOffset, 10) > 0), "".concat(iotPrefix, "--expandable-tablerow--singly-selected"), hasRowSelection === 'single' && isSelected && !useRadioButtonSingleSelect), "".concat(iotPrefix, "--expandable-tablerow--last-child"), isLastChild), "".concat(iotPrefix, "--table__row--dragging"), isDragRow), "".concat(iotPrefix, "--table__row--softdeleted"), values === null || values === void 0 ? void 0 : values[deletedAttribute]), "".concat(iotPrefix, "--table__row--updated"), values === null || values === void 0 ? void 0 : values._updated)),
    "data-row-nesting": hasRowNesting,
    "data-child-count": nestingChildCount,
    "data-nesting-offset": nestingOffset,
    ariaLabel: clickToExpandAria,
    expandIconDescription: clickToExpandAria,
    isExpanded: false,
    isSelected: isSelected,
    hasRowSelection: hasRowSelection,
    onExpand: function onExpand(evt) {
      return componentUtilityFunctions.stopPropagationAndCallback(evt, onRowExpanded, id, true);
    },
    onClick: function onClick() {
      if (shouldExpandOnRowClick && (hasRowNesting && nestingChildCount || hasRowExpansion)) {
        onRowExpanded(id, true);
      }
      if (hasRowSelection === 'single' && isSelectable !== false) {
        onRowSelected(id, true);
      }
      if (isSelectable !== false) {
        onRowClicked(id);
      }
    },
    style: {
      '--row-nesting-offset': "".concat(nestingOffset, "px")
    },
    rowId: id,
    langDir: langDir
  }, dragEnterLeaveHandlers), tableCells) : hasRowSelection === 'single' && isSelected ? /*#__PURE__*/React__default.default.createElement(react.TableRow, _extends__default.default({
    className: classnames__default.default("".concat(iotPrefix, "--table__row"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--table__row--singly-selected"), isSelected && !useRadioButtonSingleSelect), "".concat(iotPrefix, "--table__row--background"), isSelected), "".concat(iotPrefix, "--table__row--softdeleted"), values === null || values === void 0 ? void 0 : values[deletedAttribute]), "".concat(iotPrefix, "--table__row--updated"), values === null || values === void 0 ? void 0 : values._updated)),
    key: id,
    onClick: function onClick() {
      if (isSelectable !== false) {
        onRowClicked(id);
        if (hasRowSelection === 'single' && !useRadioButtonSingleSelect) {
          onRowSelected(id, !isSelected);
        }
      }
    }
  }, dragEnterLeaveHandlers), tableCells) : /*#__PURE__*/React__default.default.createElement(react.TableRow, _extends__default.default({
    className: classnames__default.default("".concat(iotPrefix, "--table__row"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--table__row--unselectable"), isSelectable === false), "".concat(iotPrefix, "--table__row--selectable"), isSelectable !== false), "".concat(iotPrefix, "--table__row--editing"), isEditMode), "".concat(iotPrefix, "--table__row--selected"), isSelected), "".concat(iotPrefix, "--table__row--dragging"), isDragRow), "".concat(iotPrefix, "--table__row--softdeleted"), values === null || values === void 0 ? void 0 : values[deletedAttribute]), "".concat(iotPrefix, "--table__row--updated"), values === null || values === void 0 ? void 0 : values._updated)),
    key: id,
    onClick: function onClick() {
      if (isSelectable !== false) {
        if (hasRowSelection === 'single' && !useRadioButtonSingleSelect) {
          onRowSelected(id, true);
        }
        onRowClicked(id);
      }
    }
  }, dragEnterLeaveHandlers), tableCells);
};
TableBodyRow.propTypes = propTypes;
TableBodyRow.defaultProps = defaultProps;
TableBodyRow.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TableBodyRow",
  "props": {
    "isSelected": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "is the row currently selected",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isIndeterminate": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "is the row currently in an indeterminate state, i.e. some but not all children are checked",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isExpanded": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "is the row currently expanded",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "selectRowAria": {
      "defaultValue": {
        "value": "'Select row'",
        "computed": false
      },
      "description": "internationalized label",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "overflowMenuAria": {
      "defaultValue": {
        "value": "'More actions'",
        "computed": false
      },
      "description": "internationalized label",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "clickToExpandAria": {
      "defaultValue": {
        "value": "'Click to expand.'",
        "computed": false
      },
      "description": "internationalized label",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "clickToCollapseAria": {
      "defaultValue": {
        "value": "'Click to collapse.'",
        "computed": false
      },
      "description": "internationalized label",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "dragHandleTooltip": {
      "defaultValue": {
        "value": "'Click and drag to new location'",
        "computed": false
      },
      "description": "I18N label for drag handle tooltip",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "rowActions": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "optional per-row actions",
      "type": {
        "name": "custom",
        "raw": "RowActionPropTypes"
      },
      "required": false
    },
    "rowDetails": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "optional row details",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "nestingLevel": {
      "defaultValue": {
        "value": "0",
        "computed": false
      },
      "description": "offset level if row is nested",
      "type": {
        "name": "number"
      },
      "required": false
    },
    "nestingChildCount": {
      "defaultValue": {
        "value": "0",
        "computed": false
      },
      "description": "number of child rows underneath this row",
      "type": {
        "name": "number"
      },
      "required": false
    },
    "options": {
      "defaultValue": {
        "value": "{}",
        "computed": false
      },
      "description": "table wide options",
      "type": {
        "name": "shape",
        "value": {
          "hasRowSelection": {
            "name": "enum",
            "value": [{
              "value": "'multi'",
              "computed": false
            }, {
              "value": "'single'",
              "computed": false
            }, {
              "value": "false",
              "computed": false
            }],
            "required": false
          },
          "hasRowExpansion": {
            "name": "bool",
            "required": false
          },
          "hasRowNesting": {
            "name": "union",
            "value": [{
              "name": "bool"
            }, {
              "name": "shape",
              "value": {
                "hasSingleNestedHierarchy": {
                  "name": "bool",
                  "description": "If the hierarchy only has 1 nested level of children",
                  "required": false
                }
              }
            }],
            "required": false
          },
          "hasRowActions": {
            "name": "bool",
            "required": false
          },
          "shouldExpandOnRowClick": {
            "name": "bool",
            "required": false
          },
          "wrapCellText": {
            "name": "custom",
            "raw": "WrapCellTextPropTypes.isRequired",
            "required": true
          },
          "truncateCellText": {
            "name": "bool",
            "required": true
          },
          "preserveCellWhiteSpace": {
            "name": "bool",
            "description": "use white-space: pre; css when true",
            "required": false
          },
          "useRadioButtonSingleSelect": {
            "name": "bool",
            "description": "use radio button on single selection",
            "required": false
          },
          "hasDragAndDrop": {
            "name": "bool",
            "required": false
          }
        }
      },
      "required": false
    },
    "rowEditMode": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "singleRowEditMode": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "singleRowEditButtons": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "element"
      },
      "required": false
    },
    "isRowActionRunning": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Is a row action actively running",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "rowActionsError": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "has a row action errored out",
      "type": {
        "name": "custom",
        "raw": "RowActionErrorPropTypes"
      },
      "required": false
    },
    "learnMoreText": {
      "defaultValue": {
        "value": "'Learn more'",
        "computed": false
      },
      "description": "I18N label for learn more",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "inProgressText": {
      "defaultValue": {
        "value": "'In progress'",
        "computed": false
      },
      "description": "I18N label for in progress",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "dismissText": {
      "defaultValue": {
        "value": "'Dismiss'",
        "computed": false
      },
      "description": "I18N label for dismiss",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "actionFailedText": {
      "defaultValue": {
        "value": "'Action failed'",
        "computed": false
      },
      "description": "I18N label for action failed",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "showExpanderColumn": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "shows an additional column that can expand/shrink as the table is resized",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "langDir": {
      "defaultValue": {
        "value": "'ltr'",
        "computed": false
      },
      "description": "direction of document",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'ltr'",
          "computed": false
        }, {
          "value": "'rtl'",
          "computed": false
        }]
      },
      "required": false
    },
    "locale": {
      "defaultValue": {
        "value": "'en'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isSelectable": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "the size passed to the table to set row height",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'xs'",
          "computed": false
        }, {
          "value": "'sm'",
          "computed": false
        }, {
          "value": "'md'",
          "computed": false
        }, {
          "value": "'lg'",
          "computed": false
        }, {
          "value": "'xl'",
          "computed": false
        }]
      },
      "required": false
    },
    "isLastChild": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "True if this is the last child of a nested group",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasDragAndDrop": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If this row supports drag and drop. Add space for a drag handle.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hideDragHandles": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If all drag handles should be hidden. This happens when an undraggable row is in the selection.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "onStartDrag": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback when a drag of this  row starts.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onDragEnterRow": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback when the mouse enters this row during a drag.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onDragLeaveRow": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback when the mouse leaves this row during a drag.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "isDraggable": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If this row can be dragged. Shows a drag handle.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isDragRow": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If this row is being dragged.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isDragging": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "If a drag operation is currently in progress.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "deletedAttribute": {
      "defaultValue": {
        "value": "'_deleted'",
        "computed": false
      },
      "description": "Attribute name to identify deleted rows",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "ordering": {
      "description": "What column ordering is currently applied to the table",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {
            "columnId": {
              "name": "string",
              "required": true
            },
            "isHidden": {
              "name": "bool",
              "required": false
            },
            "renderDataFunction": {
              "name": "func",
              "description": "for each column you can register a render callback function that is called with this object payload\n{\n   value: PropTypes.any (current cell value),\n   columnId: PropTypes.string,\n   rowId: PropTypes.string,\n   row: PropTypes.object like this {col: value, col2: value}\n}, you should return the node that should render within that cell",
              "required": false
            }
          }
        }
      },
      "required": true
    },
    "columns": {
      "description": "List of columns",
      "type": {
        "name": "custom",
        "raw": "TableColumnsPropTypes.isRequired"
      },
      "required": false
    },
    "id": {
      "description": "The unique row id",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "tableId": {
      "description": "The unique id for the table",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "totalColumns": {
      "description": "some columns might be hidden, so total columns has the overall total",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "values": {
      "description": "contents of the row each object value is a render-able node keyed by column id",
      "type": {
        "name": "objectOf",
        "value": {
          "name": "union",
          "value": [{
            "name": "node"
          }, {
            "name": "bool"
          }, {
            "name": "object"
          }, {
            "name": "array"
          }]
        }
      },
      "required": true
    },
    "tableActions": {
      "description": "tableActions",
      "type": {
        "name": "shape",
        "value": {
          "onRowSelected": {
            "name": "func",
            "required": false
          },
          "onRowClicked": {
            "name": "func",
            "required": false
          },
          "onApplyRowAction": {
            "name": "func",
            "required": false
          },
          "onRowExpanded": {
            "name": "func",
            "required": false
          },
          "onClearRowError": {
            "name": "func",
            "required": false
          }
        }
      },
      "required": true
    }
  }
};
var TableBodyRow$1 = TableBodyRow;

module.exports = TableBodyRow$1;
