/* action-button.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import "./action-button.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useCallback } from 'react';
import { cx } from '@atlaskit/css';
import { fg } from '@atlaskit/platform-feature-flags';
import { Box, Inline, Pressable } from '@atlaskit/primitives/compiled';
import Spinner from '@atlaskit/spinner';
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
import { ActionName } from '../../../../../../constants';
import { useFlexibleUiContext } from '../../../../../../state/flexible-ui-context';
import { getPrimitivesInlineSpaceBySize } from '../../../utils';
import ActionIcon from '../action-icon';
const styles = {
  button: "_bfhksm61 _ca0q1b66 _u5f31b66 _n3td1b66 _19bv1b66 _1bsb1osq _1ah31i6y _irr31dpa _1di6fcek",
  pillButton: "_2rko1qi0 _189ee4h9 _1dqonqa1 _1h6d1l7x _kqswh2mm _bfhksm61 _u5f3u2gc _19bvv77o _1bsb1osq _1ah31i6y _irr31dpa _1di6fcek",
  content: "_11c8wadc _syazi7uo",
  pillContent: "_11c8wadc _syazi7uo _o5721q9c",
  spinner: "_1bsb1tcg _4t3i1tcg _1e0c116y _4cvr1h6o _1bah1h6o"
};
const pillIconWrapperStyles = null;
const ActionButton = ({
  content,
  icon: iconOption,
  isDisabled,
  isLoading,
  onClick: onClickCallback,
  size,
  space: spaceOption,
  testId,
  tooltipProps,
  style,
  ariaLabel
}) => {
  var _flexibleUiContext$ac;
  const space = spaceOption !== null && spaceOption !== void 0 ? spaceOption : getPrimitivesInlineSpaceBySize(size);
  const onClick = useCallback(() => {
    if (!isDisabled && !isLoading && onClickCallback) {
      onClickCallback();
    }
  }, [isDisabled, isLoading, onClickCallback]);
  const is3pExperimentEnabled =
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
  fg('platform_sl_3p_auth_rovo_action_kill_switch') && expValEqualsNoExposure('platform_sl_3p_auth_rovo_action', 'isEnabled', true) ||
  // eslint-disable-next-line @atlaskit/platform/no-preconditioning
  fg('rovogrowth-640-inline-action-nudge-fg') && expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);

  /**
   * NOTE: We only apply the pill variant when there's text label
   * (textual `content`). Icon-only stack-item buttons (e.g. the link/expand
   * icons in the hover card footer) are also rendered with `as="stack-item"`
   * but pass `content=""` and should keep their original borderless styling.
   */
  const hasTextualContent = typeof content === 'string' ? content.trim().length > 0 : Boolean(content);
  const flexibleUiContext = useFlexibleUiContext();
  const isInRovoActionStack = !!(flexibleUiContext !== null && flexibleUiContext !== void 0 && (_flexibleUiContext$ac = flexibleUiContext.actions) !== null && _flexibleUiContext$ac !== void 0 && _flexibleUiContext$ac[ActionName.RovoChatAction]);
  const isInlineActionNudgeExperiment = hasTextualContent && isInRovoActionStack && fg('rovogrowth-640-inline-action-nudge-fg') && expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
  const icon = iconOption && isLoading ? /*#__PURE__*/React.createElement(ActionIcon, {
    icon: is3pExperimentEnabled ? /*#__PURE__*/React.createElement(Box, {
      xcss: styles.spinner
    }, /*#__PURE__*/React.createElement(Spinner, {
      size: 16,
      testId: `${testId}-loading`
    })) : /*#__PURE__*/React.createElement(Spinner, {
      testId: `${testId}-loading`
    })
  }) : iconOption;
  return /*#__PURE__*/React.createElement(Pressable, _extends({
    xcss: cx(isInlineActionNudgeExperiment ? styles.pillButton : styles.button)
  }, tooltipProps, {
    onClick: onClick,
    testId: testId
    // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
    ,
    style: style
  }, fg('platform_sl_3p_auth_rovo_action_kill_switch') || expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true) ? {
    'aria-label': ariaLabel
  } : {}), /*#__PURE__*/React.createElement(Inline, {
    alignBlock: "center",
    grow: isInlineActionNudgeExperiment ? 'hug' : 'fill',
    space: isInlineActionNudgeExperiment ? 'space.050' : space
  }, isInlineActionNudgeExperiment ? /*#__PURE__*/React.createElement("span", {
    className: ax(["_1e0c116y _4cvr1h6o _1bah1h6o _1bsb1tcg _4t3i1tcg _1o9zidpf"])
  }, icon) : icon, /*#__PURE__*/React.createElement(Box, {
    xcss: cx(isInlineActionNudgeExperiment ? styles.pillContent : styles.content)
  }, content)));
};
export default ActionButton;