/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React, { forwardRef, useCallback, useMemo } from 'react';
import { LoadingButton } from '@atlaskit/button';
import Button, { IconButton, LinkButton, LinkIconButton } from '@atlaskit/button/new';
import { Box } from '@atlaskit/primitives/compiled';
import Tooltip from '@atlaskit/tooltip';
import { SmartLinkSize } from '../../../../../../constants';
import { useFlexibleUiOptionContext } from '../../../../../../state/flexible-ui-context';
import { withOverrideCss } from '../../../common/with-override-css';
import { sizeToButtonSpacing } from '../../../utils';
const IconOnlyLarge = null;
const SizeSmall = null;
const SizeSmallIconOnly = null;
const SizeSmallNotIconOnly = null;
const IconButtonAppearanceMap = {
  default: 'default',
  danger: undefined,
  link: 'default',
  primary: 'primary',
  subtle: 'subtle',
  'subtle-link': 'subtle',
  warning: undefined
};
const ButtonAppearanceMap = {
  default: 'default',
  danger: 'danger',
  link: 'default',
  primary: 'primary',
  subtle: 'subtle',
  'subtle-link': 'subtle',
  warning: 'warning'
};
const tooltipOptions = {
  hideTooltipOnClick: true
};
const ActionButtonRefresh = /*#__PURE__*/forwardRef(({
  appearance = 'default',
  content,
  iconAfter,
  iconBefore,
  isLoading,
  onClick,
  size,
  testId,
  tooltipMessage,
  isDisabled,
  href,
  ariaLabel
}, ref) => {
  const iconOnly = !content;
  const onButtonClick = useCallback(handler => e => {
    e.preventDefault();
    handler();
  }, []);
  const button = useMemo(() => {
    const isLinkButton = !!href;
    const spacing = size === SmartLinkSize.Large || size === SmartLinkSize.XLarge ? 'default' : 'compact';
    const icon = iconBefore || iconAfter;
    const iconFn = icon ? () => icon : undefined;
    if (iconOnly && iconFn) {
      if (isLinkButton && iconFn) {
        return /*#__PURE__*/React.createElement(LinkIconButton, {
          appearance: IconButtonAppearanceMap[appearance],
          icon: iconFn,
          href: href,
          isDisabled: isDisabled,
          isTooltipDisabled: false,
          label: tooltipMessage,
          onClick: onButtonClick(onClick),
          spacing: spacing,
          testId: testId,
          tooltip: tooltipOptions
        });
      }
      return /*#__PURE__*/React.createElement(IconButton, {
        appearance: IconButtonAppearanceMap[appearance],
        icon: iconFn,
        isDisabled: isDisabled,
        isLoading: isLoading,
        isTooltipDisabled: false,
        label: tooltipMessage,
        onClick: onButtonClick(onClick),
        spacing: spacing,
        testId: testId,
        tooltip: tooltipOptions
      });
    }
    const iconBeforeFn = iconBefore ? () => iconBefore : undefined;
    const iconAfterFn = iconAfter ? () => iconAfter : undefined;
    if (isLinkButton) {
      return /*#__PURE__*/React.createElement(Tooltip, {
        content: tooltipMessage,
        hideTooltipOnClick: true,
        testId: `${testId}-tooltip`
      }, /*#__PURE__*/React.createElement(LinkButton, {
        appearance: ButtonAppearanceMap[appearance],
        "aria-label": ariaLabel,
        iconAfter: iconAfterFn,
        iconBefore: iconBeforeFn,
        isDisabled: isDisabled,
        href: href,
        onClick: onButtonClick(onClick),
        spacing: spacing,
        testId: testId
      }, content));
    }
    return /*#__PURE__*/React.createElement(Tooltip, {
      content: tooltipMessage,
      hideTooltipOnClick: true,
      testId: `${testId}-tooltip`
    }, /*#__PURE__*/React.createElement(Button, {
      appearance: ButtonAppearanceMap[appearance],
      "aria-label": ariaLabel,
      iconAfter: iconAfterFn,
      iconBefore: iconBeforeFn,
      isDisabled: isDisabled,
      isLoading: isLoading,
      onClick: onButtonClick(onClick),
      spacing: spacing,
      testId: testId
    }, content));
  }, [appearance, ariaLabel, content, href, iconAfter, iconBefore, iconOnly, isDisabled, isLoading, onButtonClick, onClick, size, testId, tooltipMessage]);
  return /*#__PURE__*/React.createElement(Box, {
    testId: `${testId}-button-wrapper`,
    ref: ref
  }, button);
});
const ActionButtonRefreshWithOverrideCss = withOverrideCss(ActionButtonRefresh);
const ActionButtonNew = ({
  appearance = 'default',
  content,
  iconAfter,
  iconBefore,
  isLoading,
  onClick,
  size,
  testId,
  tooltipMessage,
  isDisabled,
  href,
  ariaLabel,
  className
}) => {
  const iconOnly = !content;
  const onButtonClick = useCallback(handler => e => {
    e.preventDefault();
    handler();
  }, []);
  return /*#__PURE__*/React.createElement("div", {
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    className: ax([size === SmartLinkSize.Large && iconOnly && "_1gflidpf _or3fidpf _1ddvidpf _1hhaidpf _yhjmidpf _1trnidpf _1fstidpf _1xceidpf _1gqnidpf _1qdmidpf _df2ridpf _j1twidpf _11lvidpf _192bidpf _vbn7idpf _wfu3idpf _1i3bidpf _13gwidpf _4wlcidpf _rehaidpf _mp2fidpf _ro8midpf _1l0qidpf _1bnaidpf _3kh9idpf _i2vxidpf _8pvjidpf _1e1oidpf _1vtwidpf _ijvwidpf _tpwpidpf _1ad8idpf", size === SmartLinkSize.Small && "_11c8wadc _k48p1wq8", size === SmartLinkSize.Small && iconOnly && "_1gfl1xvx _or3f1xvx _1ddv1xvx _1hha1xvx _yhjm1xvx _1trn1xvx _1fst1xvx _1xce1xvx _1gqn1xvx _1qdm1xvx _df2r1xvx _j1tw1xvx _11lv1xvx _192b1xvx _vbn71xvx _wfu31xvx", size === SmartLinkSize.Small && !iconOnly && "_11lvpdf9 _192bpdf9 _vbn7pdf9 _wfu3pdf9 _yhjmpdf9 _1trnpdf9 _1fstpdf9 _1xcepdf9", className]),
    "data-testid": `${testId}-button-wrapper`
  }, /*#__PURE__*/React.createElement(Tooltip, {
    content: tooltipMessage,
    hideTooltipOnClick: true,
    testId: `${testId}-tooltip`
  }, /*#__PURE__*/React.createElement(LoadingButton, {
    appearance: appearance,
    iconAfter: iconAfter,
    iconBefore: iconBefore,
    isDisabled: isDisabled,
    isLoading: isLoading,
    onClick: onButtonClick(onClick),
    spacing: sizeToButtonSpacing[size],
    testId: testId,
    href: href,
    "aria-label": ariaLabel
  }, content)));
};
const ActionButton = props => {
  const ui = useFlexibleUiOptionContext();
  if (ui !== null && ui !== void 0 && ui.hideLegacyButton || ui !== null && ui !== void 0 && ui.removeBlockRestriction) {
    return /*#__PURE__*/React.createElement(ActionButtonRefreshWithOverrideCss, props);
  }
  return /*#__PURE__*/React.createElement(ActionButtonNew, props);
};
export default ActionButton;