import React, { useCallback, useMemo } from 'react';
import classNames from 'classnames';
import { jsx as _jsx } from "react/jsx-runtime";
const SelectableTableRow = ({
  onRowClick,
  onRowDblClick,
  isRowEnabled,
  className,
  item,
  selectedItemId,
  rowIdAccessor,
  TrComponent,
  highlightRow,
  ...props
}) => {
  const isClickable = useMemo(() => !isRowEnabled || isRowEnabled(item), [item]);
  const clickCallback = useCallback(e => isClickable && onRowClick(item, e), [item, onRowClick, isClickable]);
  const doubleClickCallback = useCallback(e => isClickable && onRowDblClick && onRowDblClick(item, e), [item, onRowClick, isClickable]);
  const isSelected = useMemo(() => item && selectedItemId && item[rowIdAccessor] === selectedItemId, [item, selectedItemId]);
  const {
    testId,
    ...restProps
  } = props;
  const rowProps = {
    ...restProps,
    className: classNames(className, 'selectable-table-row', {
      clickable: isClickable
    }, {
      selected: isSelected
    }, {
      'highlight-selected-row': isSelected && highlightRow
    }),
    onClick: clickCallback,
    onDoubleClick: doubleClickCallback
  };
  if (TrComponent) {
    return /*#__PURE__*/React.createElement(TrComponent, rowProps, rowProps.children);
  }
  return /*#__PURE__*/_jsx("div", {
    ...rowProps,
    className: classNames('r-tr', rowProps.className),
    "test-id": testId
  });
};
export default SelectableTableRow;