"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _reactIntlNext = require("react-intl-next");
var _useAnalyticsEvents2 = require("../../../../../common/analytics/generated/use-analytics-events");
var _messages = require("../../../../../messages");
var _flexibleUiContext = require("../../../../../state/flexible-ui-context");
var _modal = require("../../../../../state/modal");
var _action = _interopRequireDefault(require("../action"));
var _relatedLinksActionIcon = _interopRequireDefault(require("./related-links-action-icon"));
var _excluded = ["onClick"];
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" != (0, _typeof2.default)(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 RelatedLinksModal = /*#__PURE__*/(0, _react.lazy)(function () {
  return Promise.resolve().then(function () {
    return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_smartcard-RelatedLinksModal" */'../../../../RelatedLinksModal'));
  });
});
var ViewRelatedLinksAction = function ViewRelatedLinksAction(_ref) {
  var _context$actions;
  var onClickCallback = _ref.onClick,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var modal = (0, _modal.useSmartLinkModal)();
  var context = (0, _flexibleUiContext.useFlexibleUiContext)();
  var actionData = context === null || context === void 0 || (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions.ViewRelatedLinksAction;
  var _useAnalyticsEvents = (0, _useAnalyticsEvents2.useAnalyticsEvents)(),
    fireEvent = _useAnalyticsEvents.fireEvent;
  var onClick = (0, _react.useCallback)(function () {
    var ari = actionData === null || actionData === void 0 ? void 0 : actionData.ari;
    if (ari) {
      modal.open( /*#__PURE__*/_react.default.createElement(RelatedLinksModal, {
        ari: ari,
        showModal: true,
        onClose: function onClose() {
          return modal.close();
        }
      }));
    }
    fireEvent('ui.button.clicked.relatedLinks', {});
    onClickCallback === null || onClickCallback === void 0 || onClickCallback();
  }, [actionData === null || actionData === void 0 ? void 0 : actionData.ari, fireEvent, modal, onClickCallback]);
  return actionData ? /*#__PURE__*/_react.default.createElement(_action.default, (0, _extends2.default)({
    content: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.related_links_view_related_links),
    icon: /*#__PURE__*/_react.default.createElement(_relatedLinksActionIcon.default, null),
    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;
};
var _default = exports.default = ViewRelatedLinksAction;