import { objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { forwardRef, useContext } from 'react';
import cls from 'classnames';
import { classes } from '../List.tokens.js';
import { ListContext } from '../List.context.js';
import { StyledListItem, CellItem } from './ListItem.styles.js';

var _excluded = ["children", "contentLeft", "contentRight", "disabled", "onClick", "className"];
var ListItem = /*#__PURE__*/forwardRef(function (_ref, outerRef) {
  var children = _ref.children,
    contentLeft = _ref.contentLeft,
    contentRight = _ref.contentRight,
    disabled = _ref.disabled,
    onClick = _ref.onClick,
    className = _ref.className,
    rest = _objectWithoutProperties(_ref, _excluded);
  var _useContext = useContext(ListContext),
    contextDisabled = _useContext.disabled,
    hasItemBackground = _useContext.hasItemBackground,
    hasDivider = _useContext.hasDivider;
  var isDisabled = disabled || contextDisabled;
  var handleClick = function handleClick(event) {
    if (isDisabled || !onClick) {
      return;
    }
    onClick(event);
  };
  return /*#__PURE__*/React__default.createElement(StyledListItem, _extends({
    ref: outerRef,
    className: cls(className, isDisabled && classes.disabledListItem, hasItemBackground && classes.hasItemBackground, hasDivider && classes.hasItemDivider),
    onClick: handleClick,
    tabIndex: isDisabled ? -1 : 0
  }, rest), /*#__PURE__*/React__default.createElement(CellItem, {
    contentLeft: contentLeft,
    contentRight: contentRight
  }, children));
});

export { ListItem };
