import React from 'react';
import { SmartLinkSize } from '../../../../../constants';
import ActionButton from './action-button';
import ActionDropdownItem from './action-dropdown-item';
import ActionIcon from './action-icon';
import ActionStackItem from './action-stack-item';
/**
 * A base action that can be triggered with an on click.
 * @internal
 * @param {ActionProps} ActionProps - The props necessary for the Action.
 */
var Action = function Action(_ref) {
  var as = _ref.as,
    _ref$appearance = _ref.appearance,
    appearance = _ref$appearance === void 0 ? 'subtle' : _ref$appearance,
    content = _ref.content,
    _ref$isLoading = _ref.isLoading,
    isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
    onClick = _ref.onClick,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? SmartLinkSize.Medium : _ref$size,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-action' : _ref$testId,
    icon = _ref.icon,
    _ref$iconPosition = _ref.iconPosition,
    iconPosition = _ref$iconPosition === void 0 ? 'before' : _ref$iconPosition,
    spaceInline = _ref.spaceInline,
    tooltipMessage = _ref.tooltipMessage,
    tooltipOnHide = _ref.tooltipOnHide,
    hideTooltip = _ref.hideTooltip,
    hideTooltipOnMouseDown = _ref.hideTooltipOnMouseDown,
    style = _ref.style,
    asDropDownItem = _ref.asDropDownItem,
    className = _ref.className,
    isDisabled = _ref.isDisabled,
    href = _ref.href,
    ariaLabel = _ref.ariaLabel,
    Wrapper = _ref.wrapper;
  if (!onClick) {
    return null;
  }
  var isStackItem = as === 'stack-item';
  var isDropdownItem = as === 'dropdown-item' || asDropDownItem;
  var actionIcon = icon ? /*#__PURE__*/React.createElement(ActionIcon, {
    icon: icon,
    testId: testId
  }) : undefined;
  var iconBefore = icon && iconPosition === 'before' ? actionIcon : undefined;
  var iconAfter = icon && iconPosition === 'after' ? actionIcon : undefined;
  if (isStackItem) {
    return /*#__PURE__*/React.createElement(ActionStackItem, {
      content: content,
      icon: actionIcon,
      space: spaceInline,
      isDisabled: isDisabled,
      isLoading: isLoading,
      onClick: onClick,
      size: size,
      testId: testId,
      tooltipMessage: tooltipMessage || content
      // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
      ,
      style: style,
      tooltipOnHide: tooltipOnHide,
      hideTooltipOnMouseDown: hideTooltipOnMouseDown,
      hideTooltip: hideTooltip
    });
  }
  if (isDropdownItem) {
    return /*#__PURE__*/React.createElement(ActionDropdownItem, {
      content: content,
      iconAfter: iconAfter,
      iconBefore: iconBefore,
      isLoading: isLoading,
      onClick: onClick,
      testId: testId
    });
  }
  var button = /*#__PURE__*/React.createElement(ActionButton, {
    appearance: appearance,
    content: content,
    iconAfter: iconAfter,
    iconBefore: iconBefore,
    isLoading: isLoading,
    onClick: onClick
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: className,
    size: size,
    testId: testId,
    tooltipMessage: tooltipMessage || content,
    isDisabled: isDisabled,
    href: href,
    ariaLabel: ariaLabel
  });
  return Wrapper !== undefined ? /*#__PURE__*/React.createElement(Wrapper, null, button) : button;
};
export default Action;