/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("./index.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _react = _interopRequireWildcard(require("react"));
var _button = require("@atlaskit/button");
var _new = _interopRequireWildcard(require("@atlaskit/button/new"));
var _compiled = require("@atlaskit/primitives/compiled");
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
var _constants = require("../../../../../../constants");
var _flexibleUiContext = require("../../../../../../state/flexible-ui-context");
var _withOverrideCss = require("../../../common/with-override-css");
var _utils = require("../../../utils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var IconOnlyLarge = null;
var SizeSmall = null;
var SizeSmallIconOnly = null;
var SizeSmallNotIconOnly = null;
var IconButtonAppearanceMap = {
  default: 'default',
  danger: undefined,
  link: 'default',
  primary: 'primary',
  subtle: 'subtle',
  'subtle-link': 'subtle',
  warning: undefined
};
var ButtonAppearanceMap = {
  default: 'default',
  danger: 'danger',
  link: 'default',
  primary: 'primary',
  subtle: 'subtle',
  'subtle-link': 'subtle',
  warning: 'warning'
};
var tooltipOptions = {
  hideTooltipOnClick: true
};
var ActionButtonRefresh = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var _ref$appearance = _ref.appearance,
    appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
    content = _ref.content,
    iconAfter = _ref.iconAfter,
    iconBefore = _ref.iconBefore,
    isLoading = _ref.isLoading,
    onClick = _ref.onClick,
    size = _ref.size,
    testId = _ref.testId,
    tooltipMessage = _ref.tooltipMessage,
    isDisabled = _ref.isDisabled,
    href = _ref.href,
    ariaLabel = _ref.ariaLabel;
  var iconOnly = !content;
  var onButtonClick = (0, _react.useCallback)(function (handler) {
    return function (e) {
      e.preventDefault();
      handler();
    };
  }, []);
  var button = (0, _react.useMemo)(function () {
    var isLinkButton = !!href;
    var spacing = size === _constants.SmartLinkSize.Large || size === _constants.SmartLinkSize.XLarge ? 'default' : 'compact';
    var icon = iconBefore || iconAfter;
    var iconFn = icon ? function () {
      return icon;
    } : undefined;
    if (iconOnly && iconFn) {
      if (isLinkButton && iconFn) {
        return /*#__PURE__*/_react.default.createElement(_new.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.default.createElement(_new.IconButton, {
        appearance: IconButtonAppearanceMap[appearance],
        icon: iconFn,
        isDisabled: isDisabled,
        isLoading: isLoading,
        isTooltipDisabled: false,
        label: tooltipMessage,
        onClick: onButtonClick(onClick),
        spacing: spacing,
        testId: testId,
        tooltip: tooltipOptions
      });
    }
    var iconBeforeFn = iconBefore ? function () {
      return iconBefore;
    } : undefined;
    var iconAfterFn = iconAfter ? function () {
      return iconAfter;
    } : undefined;
    if (isLinkButton) {
      return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
        content: tooltipMessage,
        hideTooltipOnClick: true,
        testId: "".concat(testId, "-tooltip")
      }, /*#__PURE__*/_react.default.createElement(_new.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.default.createElement(_tooltip.default, {
      content: tooltipMessage,
      hideTooltipOnClick: true,
      testId: "".concat(testId, "-tooltip")
    }, /*#__PURE__*/_react.default.createElement(_new.default, {
      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.default.createElement(_compiled.Box, {
    testId: "".concat(testId, "-button-wrapper"),
    ref: ref
  }, button);
});
var ActionButtonRefreshWithOverrideCss = (0, _withOverrideCss.withOverrideCss)(ActionButtonRefresh);
var ActionButtonNew = function ActionButtonNew(_ref2) {
  var _ref2$appearance = _ref2.appearance,
    appearance = _ref2$appearance === void 0 ? 'default' : _ref2$appearance,
    content = _ref2.content,
    iconAfter = _ref2.iconAfter,
    iconBefore = _ref2.iconBefore,
    isLoading = _ref2.isLoading,
    onClick = _ref2.onClick,
    size = _ref2.size,
    testId = _ref2.testId,
    tooltipMessage = _ref2.tooltipMessage,
    isDisabled = _ref2.isDisabled,
    href = _ref2.href,
    ariaLabel = _ref2.ariaLabel,
    className = _ref2.className;
  var iconOnly = !content;
  var onButtonClick = (0, _react.useCallback)(function (handler) {
    return function (e) {
      e.preventDefault();
      handler();
    };
  }, []);
  return /*#__PURE__*/_react.default.createElement("div", {
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    className: (0, _runtime.ax)([size === _constants.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 === _constants.SmartLinkSize.Small && "_11c8wadc _k48p1wq8", size === _constants.SmartLinkSize.Small && iconOnly && "_1gfl1xvx _or3f1xvx _1ddv1xvx _1hha1xvx _yhjm1xvx _1trn1xvx _1fst1xvx _1xce1xvx _1gqn1xvx _1qdm1xvx _df2r1xvx _j1tw1xvx _11lv1xvx _192b1xvx _vbn71xvx _wfu31xvx", size === _constants.SmartLinkSize.Small && !iconOnly && "_11lvpdf9 _192bpdf9 _vbn7pdf9 _wfu3pdf9 _yhjmpdf9 _1trnpdf9 _1fstpdf9 _1xcepdf9", className]),
    "data-testid": "".concat(testId, "-button-wrapper")
  }, /*#__PURE__*/_react.default.createElement(_tooltip.default, {
    content: tooltipMessage,
    hideTooltipOnClick: true,
    testId: "".concat(testId, "-tooltip")
  }, /*#__PURE__*/_react.default.createElement(_button.LoadingButton, {
    appearance: appearance,
    iconAfter: iconAfter,
    iconBefore: iconBefore,
    isDisabled: isDisabled,
    isLoading: isLoading,
    onClick: onButtonClick(onClick),
    spacing: _utils.sizeToButtonSpacing[size],
    testId: testId,
    href: href,
    "aria-label": ariaLabel
  }, content)));
};
var ActionButton = function ActionButton(props) {
  var ui = (0, _flexibleUiContext.useFlexibleUiOptionContext)();
  if (ui !== null && ui !== void 0 && ui.hideLegacyButton || ui !== null && ui !== void 0 && ui.removeBlockRestriction) {
    return /*#__PURE__*/_react.default.createElement(ActionButtonRefreshWithOverrideCss, props);
  }
  return /*#__PURE__*/_react.default.createElement(ActionButtonNew, props);
};
var _default = exports.default = ActionButton;