import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React from 'react';
import Button from '../Button';
import { MenuItem } from '../Menu';

/**
 * `ListAction` component is a part of [ListActions](#!/ListActions) component.
 * It accepts the props of [Button](#!/Button) and [MenuItem](#!/MenuItem) components.
 * @since 3.3.0
 */
const ListAction = ({
  primary,
  children,
  tooltip,
  ...props
}) => {
  const render = children => {
    if (primary) {
      return /*#__PURE__*/React.createElement(Button, _extends({
        ghost: true,
        tooltip: children
      }, props));
    }

    return /*#__PURE__*/React.createElement(MenuItem, _extends({
      tooltip: tooltip
    }, props), children);
  };

  const unwrap = cb => cb({
    wrap: children => render(children)
  });

  if (typeof children === 'function') {
    return unwrap(children);
  }

  return render(children);
};

export default ListAction;