"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _box = _interopRequireWildcard(require("../box"));

var _icon = _interopRequireDefault(require("../icon"));

var _typography = require("../typography");

var _classnames = _interopRequireDefault(require("classnames"));

var _theme = _interopRequireDefault(require("./theme.css"));

var _excluded = ["onClick", "disabled", "icon", "caption", "children", "className", "style", "destructive", "element", "label", "selected"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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 = (0, _objectWithoutProperties2.default)(_ref, _excluded);

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

  var classNames = (0, _classnames.default)(_theme.default['menu-item'], (_cx = {}, (0, _defineProperty2.default)(_cx, _theme.default['is-selected'], selected), (0, _defineProperty2.default)(_cx, _theme.default['is-disabled'], disabled), _cx), className);
  var color = destructive ? 'ruby' : disabled ? 'neutral' : 'teal';
  var tint = disabled && destructive ? 'light' : disabled || destructive ? 'dark' : 'darkest';
  var boxProps = (0, _box.pickBoxProps)(others);
  var restProps = (0, _box.omitBoxProps)(others);
  return /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({}, boxProps, {
    "data-teamleader-ui": "menu-item",
    display: "flex",
    element: "li"
  }), /*#__PURE__*/_react.default.createElement(_box.default, (0, _extends2.default)({
    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.default.createElement(_icon.default, {
    color: color,
    tint: tint,
    marginRight: 3
  }, icon), /*#__PURE__*/_react.default.createElement(_box.default, {
    flex: "1 1 auto",
    className: (0, _classnames.default)((0, _defineProperty2.default)({}, _theme.default['menu-item-text-container'], element === 'a'))
  }, children, label && /*#__PURE__*/_react.default.createElement(_typography.TextBody, {
    color: color,
    tint: tint
  }, label), caption && /*#__PURE__*/_react.default.createElement(_typography.TextBody, {
    color: "neutral",
    tint: "darkest"
  }, caption))));
};

var _default = MenuItem;
exports.default = _default;