import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React, { cloneElement } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Tooltip from '../Tooltip';
import { CLS_PREFIX } from '../../constants';
import { createProxyProps } from '../utils';
import MenuBaseItem from './MenuBaseItem';
/**
 * `MenuItem` is a part of [Menu](#!/Menu) component.
 * @since 0.0.55
 */

const MenuItem = ({
  baseClassName,
  className,
  children,
  onClick,
  active,
  disabled,
  icon,
  label,
  tooltip,
  ...props
}) => {
  const element = /*#__PURE__*/React.createElement(MenuBaseItem, _extends({
    className: classNames(baseClassName, className, {
      ["".concat(baseClassName, "--active")]: active,
      ["".concat(baseClassName, "--disabled")]: disabled
    }),
    onClick: e => {
      if (onClick && !disabled) {
        onClick(e);
      }
    },
    role: "menuitem",
    "aria-disabled": disabled ? 'true' : undefined,
    tabIndex: disabled ? -1 : 0,
    icon: icon,
    label: label
  }, props), children);

  if (tooltip) {
    return createProxyProps(props => /*#__PURE__*/React.createElement(Tooltip, {
      title: tooltip
    }, /*#__PURE__*/cloneElement(element, props)));
  }

  return element;
};

MenuItem.propTypes = {
  /**
   * Whether item is active.
   * @since 0.0.55
   */
  active: PropTypes.bool,

  /**
   * Whether item is disabled.
   * @since 0.0.55
   */
  disabled: PropTypes.bool,

  /**
   * Icon
   * @since 0.0.55
   */
  icon: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.element]),

  /**
   * Right label of item.
   * @since 0.0.57
   */
  label: PropTypes.node,

  /**
   * Tooltip for component.
   * @since 2.6.1
   */
  tooltip: PropTypes.node,

  /**
   * Content of the `MenuItem`.
   * @since 0.0.55
   */
  children: PropTypes.node,

  /**
   * @ignore
   */
  className: PropTypes.string,

  /**
   * @ignore
   */
  baseClassName: PropTypes.string,

  /**
   * @ignore
   */
  onClick: PropTypes.func
};
MenuItem.defaultProps = {
  active: false,
  disabled: false,
  icon: null,
  label: null,
  children: null,
  className: null,
  baseClassName: "".concat(CLS_PREFIX, "menu__item"),
  onClick: null
};
export default MenuItem;