import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["onClick", "disabled", "icon", "caption", "children", "className", "style", "destructive", "element", "label", "selected"];
import React from 'react';
import Box, { omitBoxProps, pickBoxProps } from '../box';
import Icon from '../icon';
import { TextBody } from '../typography';
import cx from 'classnames';
import theme from './theme.css';

var MenuItem = function MenuItem(_ref) {
  var _cx;

  var onClick = _ref.onClick,
      _ref$disabled = _ref.disabled,
      disabled = _ref$disabled === void 0 ? false : _ref$disabled,
      icon = _ref.icon,
      caption = _ref.caption,
      children = _ref.children,
      _ref$className = _ref.className,
      className = _ref$className === void 0 ? '' : _ref$className,
      style = _ref.style,
      _ref$destructive = _ref.destructive,
      destructive = _ref$destructive === void 0 ? false : _ref$destructive,
      _ref$element = _ref.element,
      element = _ref$element === void 0 ? 'button' : _ref$element,
      label = _ref.label,
      _ref$selected = _ref.selected,
      selected = _ref$selected === void 0 ? false : _ref$selected,
      others = _objectWithoutProperties(_ref, _excluded);

  var handleClick = function handleClick(event) {
    if (onClick && !disabled) {
      onClick(event);
    }
  };

  var classNames = cx(theme['menu-item'], (_cx = {}, _defineProperty(_cx, theme['is-selected'], selected), _defineProperty(_cx, theme['is-disabled'], disabled), _cx), className);
  var color = destructive ? 'ruby' : disabled ? 'neutral' : 'teal';
  var tint = disabled && destructive ? 'light' : disabled || destructive ? 'dark' : 'darkest';
  var boxProps = pickBoxProps(others);
  var restProps = omitBoxProps(others);
  return /*#__PURE__*/React.createElement(Box, _extends({}, boxProps, {
    "data-teamleader-ui": "menu-item",
    display: "flex",
    element: "li"
  }), /*#__PURE__*/React.createElement(Box, _extends({
    onClick: handleClick,
    alignItems: "center",
    className: classNames,
    style: style,
    disabled: disabled,
    display: "flex",
    element: element,
    flex: "1 1 auto",
    paddingHorizontal: 3,
    paddingVertical: 2,
    textAlign: "left"
  }, element === 'a' && disabled && {
    tabIndex: -1
  }, restProps), icon && /*#__PURE__*/React.createElement(Icon, {
    color: color,
    tint: tint,
    marginRight: 3
  }, icon), /*#__PURE__*/React.createElement(Box, {
    flex: "1 1 auto",
    className: cx(_defineProperty({}, theme['menu-item-text-container'], element === 'a'))
  }, children, label && /*#__PURE__*/React.createElement(TextBody, {
    color: color,
    tint: tint
  }, label), caption && /*#__PURE__*/React.createElement(TextBody, {
    color: "neutral",
    tint: "darkest"
  }, caption))));
};

export default MenuItem;