import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback } from 'react';
import { FormattedMessage } from 'react-intl';
import AiIcon from '@atlaskit/icon/core/atlassian-intelligence';
import { fg } from '@atlaskit/platform-feature-flags';
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
import { useAnalyticsEvents } from '../../../../../common/analytics/generated/use-analytics-events';
import { messages } from '../../../../../messages';
import Action from '../action';
import { getErrorMessage } from './utils';
export function AISummariseAction({
  onClick: onClickCallback,
  onError: onErrorCallback,
  testId,
  status,
  summariseUrl,
  ...props
}) {
  const {
    fireEvent
  } = useAnalyticsEvents();
  const onCompleted = useCallback(state => {
    if ((state === null || state === void 0 ? void 0 : state.status) === 'error') {
      onErrorCallback === null || onErrorCallback === void 0 ? void 0 : onErrorCallback(getErrorMessage(state.error));
    }
  }, [onErrorCallback]);
  const handleActionClick = useCallback(() => {
    var _summariseUrl;
    fireEvent('ui.button.clicked.aiSummary', {});
    fireEvent('track.aiInteraction.initiated', {
      aiFeatureName: 'Smart Links Summary',
      proactiveAIGenerated: 0,
      userGeneratedAI: 1
    });
    (_summariseUrl = summariseUrl()) === null || _summariseUrl === void 0 ? void 0 : _summariseUrl.then(onCompleted, onCompleted);
    onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback();
  }, [fireEvent, onClickCallback, onCompleted, summariseUrl]);
  return /*#__PURE__*/React.createElement(Action, _extends({
    content: /*#__PURE__*/React.createElement(FormattedMessage, messages.ai_summary_action),
    icon: /*#__PURE__*/React.createElement(AiIcon, _extends({
      spacing: "spacious",
      color: "currentColor",
      label: "Summarise with AI"
    }, fg('platform_sl_3p_auth_rovo_action_kill_switch') || fg('platform_sl_3p_auth_rovo_block_card_kill_switch') || expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true) ? {
      size: props.iconSize
    } : {})),
    onClick: handleActionClick,
    testId: `${testId}-summarise-action`,
    isLoading: status === 'loading',
    tooltipMessage: /*#__PURE__*/React.createElement(FormattedMessage, messages.ai_summary_action_description)
  }, props));
}