import React, { useContext } from 'react';
import { faChevronRight } from '@fortawesome/free-solid-svg-icons/faChevronRight';
import classnames from 'classnames';
import { ACCENT_TYPES, Button } from '../../../button';
import { FontAwesomeIcon } from '../../../font-awesome-icon';
import { TableKeyboardNavigationContext } from '../../../hooks/use-table-keyboard-navigation';
import { useTranslation } from '../../../hooks/use-translation';
import { jsx as _jsx } from "react/jsx-runtime";
export function RowExpandCell({
  row,
  keyboardNavCellId,
  expandRowButtonAriaLabel
}) {
  const {
    t
  } = useTranslation();
  const keyboardNavContext = useContext(TableKeyboardNavigationContext);
  keyboardNavContext?.registerCustomCellAction(keyboardNavCellId, e => {
    e.stopPropagation();
    row.getToggleExpandedHandler()();
  });
  const isRowExpanded = row.getIsExpanded();
  return /*#__PURE__*/_jsx(Button, {
    accentType: ACCENT_TYPES.COMMAND,
    className: classnames('row-expand-button', {
      'row-expanded': isRowExpanded
    }),
    onClick: e => {
      e.stopPropagation();
      row.getToggleExpandedHandler()();
    },
    testId: "row-expand-button",
    "aria-label": expandRowButtonAriaLabel ?? t('Expand Row'),
    "aria-expanded": isRowExpanded,
    tabIndex: -1,
    children: /*#__PURE__*/_jsx(FontAwesomeIcon, {
      icon: faChevronRight
    })
  });
}