import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["icon", "caption", "children", "className", "style", "destructive", "element", "label", "selected", "disabled"];

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Box, { omitBoxProps, pickBoxProps } from '../box';
import Icon from '../icon';
import { TextBody } from '../typography';
import cx from 'classnames';
import theme from './theme.css';
/** @type {React.ComponentType<any>} */

var MenuItem = /*#__PURE__*/function (_PureComponent) {
  _inherits(MenuItem, _PureComponent);

  var _super = _createSuper(MenuItem);

  function MenuItem() {
    var _this;

    _classCallCheck(this, MenuItem);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "handleClick", function (event) {
      var _this$props = _this.props,
          disabled = _this$props.disabled,
          onClick = _this$props.onClick;

      if (onClick && !disabled) {
        onClick(event, _assertThisInitialized(_this));
      }
    });

    return _this;
  }

  _createClass(MenuItem, [{
    key: "render",
    value: function render() {
      var _cx;

      var _this$props2 = this.props,
          icon = _this$props2.icon,
          caption = _this$props2.caption,
          children = _this$props2.children,
          className = _this$props2.className,
          style = _this$props2.style,
          destructive = _this$props2.destructive,
          element = _this$props2.element,
          label = _this$props2.label,
          selected = _this$props2.selected,
          disabled = _this$props2.disabled,
          others = _objectWithoutProperties(_this$props2, _excluded);

      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: this.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, {
        className: cx(_defineProperty({}, theme['menu-item-text-container'], element === 'a')),
        flex: "1 1 auto"
      }, children, label && /*#__PURE__*/React.createElement(TextBody, {
        color: color,
        tint: tint
      }, label), caption && /*#__PURE__*/React.createElement(TextBody, {
        color: "neutral",
        tint: "darkest"
      }, caption))));
    }
  }]);

  return MenuItem;
}(PureComponent);

MenuItem.defaultProps = {
  className: '',
  destructive: false,
  disabled: false,
  element: 'button',
  selected: false
};
export default MenuItem;