import _extends from "@babel/runtime/helpers/extends";
import React, { lazy, useCallback } from 'react';
import { FormattedMessage } from 'react-intl';
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 { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
import { useSmartLinkModal } from '../../../../../state/modal';
import Action from '../action';
import RelatedLinksActionIcon from './related-links-action-icon';
const RelatedLinksModal = /*#__PURE__*/lazy(() => import( /* webpackChunkName: "@atlaskit-internal_smartcard-RelatedLinksModal" */'../../../../RelatedLinksModal'));
const ViewRelatedLinksAction = ({
  onClick: onClickCallback,
  ...props
}) => {
  var _context$actions;
  const modal = useSmartLinkModal();
  const context = useFlexibleUiContext();
  const actionData = context === null || context === void 0 ? void 0 : (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions.ViewRelatedLinksAction;
  const {
    fireEvent
  } = useAnalyticsEvents();
  const onClick = useCallback(() => {
    const ari = actionData === null || actionData === void 0 ? void 0 : actionData.ari;
    if (ari) {
      modal.open( /*#__PURE__*/React.createElement(RelatedLinksModal, {
        ari: ari,
        showModal: true,
        onClose: () => modal.close()
      }));
    }
    fireEvent('ui.button.clicked.relatedLinks', {});
    onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback();
  }, [actionData === null || actionData === void 0 ? void 0 : actionData.ari, fireEvent, modal, onClickCallback]);
  return actionData ? /*#__PURE__*/React.createElement(Action, _extends({
    content: /*#__PURE__*/React.createElement(FormattedMessage, messages.related_links_view_related_links)
  }, fg('platform_sl_3p_auth_rovo_action_kill_switch') || expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true) ? {
    tooltipMessage: /*#__PURE__*/React.createElement(FormattedMessage, messages.related_links_view_related_links)
  } : {}, {
    icon: /*#__PURE__*/React.createElement(RelatedLinksActionIcon, fg('platform_sl_3p_auth_rovo_action_kill_switch') || expValEqualsNoExposure('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true) ? {
      iconSize: props.iconSize
    } : {}),
    onClick: onClick,
    testId: "smart-action-view-related-links-action",
    ariaLabel: "View most recent pages or content types coming from or found on this link"
  }, props)) : null;
};
export default ViewRelatedLinksAction;