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.
 */
const Action = ({
  as,
  appearance = 'subtle',
  content,
  isLoading = false,
  onClick,
  size = SmartLinkSize.Medium,
  testId = 'smart-action',
  icon,
  iconPosition = 'before',
  spaceInline,
  tooltipMessage,
  tooltipOnHide,
  hideTooltip,
  hideTooltipOnMouseDown,
  style,
  asDropDownItem,
  className,
  isDisabled,
  href,
  ariaLabel,
  wrapper: Wrapper
}) => {
  if (!onClick) {
    return null;
  }
  const isStackItem = as === 'stack-item';
  const isDropdownItem = as === 'dropdown-item' || asDropDownItem;
  const actionIcon = icon ? /*#__PURE__*/React.createElement(ActionIcon, {
    icon: icon,
    testId: testId
  }) : undefined;
  const iconBefore = icon && iconPosition === 'before' ? actionIcon : undefined;
  const 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,
      ariaLabel: ariaLabel
    });
  }
  if (isDropdownItem) {
    return /*#__PURE__*/React.createElement(ActionDropdownItem, {
      content: content,
      iconAfter: iconAfter,
      iconBefore: iconBefore,
      isLoading: isLoading,
      onClick: onClick,
      testId: testId
    });
  }
  const 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;