"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = MentionWithProfileCard;
var _react = _interopRequireWildcard(require("react"));
var _mention = require("@atlaskit/mention");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _anchor = _interopRequireDefault(require("@atlaskit/primitives/anchor"));
var _user = _interopRequireDefault(require("@atlaskit/profilecard/user"));
var _navigation = require("@atlaskit/teams-app-config/navigation");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
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); }
function MentionWithProfileCard(_ref) {
  var autoFocus = _ref.autoFocus,
    id = _ref.id,
    text = _ref.text,
    accessLevel = _ref.accessLevel,
    mentionProvider = _ref.mentionProvider,
    profilecardProvider = _ref.profilecardProvider,
    onClick = _ref.onClick,
    onMouseEnter = _ref.onMouseEnter,
    onMouseLeave = _ref.onMouseLeave,
    localId = _ref.localId,
    ssrPlaceholderId = _ref.ssrPlaceholderId;
  var cloudId = profilecardProvider.cloudId,
    renderUserMentionCard = profilecardProvider.renderUserMentionCard,
    resourceClient = profilecardProvider.resourceClient;
  var actions = (0, _react.useMemo)(function () {
    return profilecardProvider.getActions(id, text, accessLevel);
  }, [accessLevel, id, profilecardProvider, text]);
  if ((0, _platformFeatureFlags.fg)('people-teams_migrate-user-profile-card')) {
    var mention = /*#__PURE__*/_react.default.createElement(_mention.ResourcedMention, {
      id: id,
      text: text,
      accessLevel: accessLevel,
      localId: localId,
      mentionProvider: mentionProvider,
      onClick: onClick,
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave,
      ssrPlaceholderId: ssrPlaceholderId
    });
    if (renderUserMentionCard) {
      return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderUserMentionCard({
        userId: id,
        cloudId: cloudId,
        children: mention
      }));
    }
    var _navigateToTeamsApp = (0, _navigation.navigateToTeamsApp)({
        type: 'USER',
        payload: {
          userId: id
        },
        cloudId: cloudId
      }),
      href = _navigateToTeamsApp.href,
      target = _navigateToTeamsApp.target;
    return /*#__PURE__*/_react.default.createElement(_anchor.default, {
      href: href,
      target: target,
      rel: "noopener noreferrer",
      testId: "mention-with-profilecard-link-fallback"
    }, mention);
  }
  return /*#__PURE__*/_react.default.createElement(_user.default, {
    autoFocus: autoFocus,
    cloudId: cloudId,
    userId: id,
    resourceClient: resourceClient,
    actions: actions,
    trigger: "click",
    position: "bottom-end",
    testId: "mention-with-profilecard-trigger"
    // Ignored via go/ees005
    // eslint-disable-next-line require-unicode-regexp
    ,
    ariaLabel: text.replace(/^@/, ''),
    ssrPlaceholderId: ssrPlaceholderId,
    isRenderedInPortal: (0, _expValEquals.expValEquals)('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
  }, /*#__PURE__*/_react.default.createElement(_mention.ResourcedMention, {
    id: id,
    text: text,
    accessLevel: accessLevel,
    localId: localId,
    mentionProvider: mentionProvider,
    onClick: onClick,
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave,
    ssrPlaceholderId: ssrPlaceholderId
  }));
}