import React, { useMemo } from 'react';
import { ResourcedMention } from '@atlaskit/mention';
import { fg } from '@atlaskit/platform-feature-flags';
import Anchor from '@atlaskit/primitives/anchor';
import ProfileCardTrigger from '@atlaskit/profilecard/user';
import { navigateToTeamsApp } from '@atlaskit/teams-app-config/navigation';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
export default 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 = useMemo(function () {
    return profilecardProvider.getActions(id, text, accessLevel);
  }, [accessLevel, id, profilecardProvider, text]);
  if (fg('people-teams_migrate-user-profile-card')) {
    var mention = /*#__PURE__*/React.createElement(ResourcedMention, {
      id: id,
      text: text,
      accessLevel: accessLevel,
      localId: localId,
      mentionProvider: mentionProvider,
      onClick: onClick,
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave,
      ssrPlaceholderId: ssrPlaceholderId
    });
    if (renderUserMentionCard) {
      return /*#__PURE__*/React.createElement(React.Fragment, null, renderUserMentionCard({
        userId: id,
        cloudId: cloudId,
        children: mention
      }));
    }
    var _navigateToTeamsApp = navigateToTeamsApp({
        type: 'USER',
        payload: {
          userId: id
        },
        cloudId: cloudId
      }),
      href = _navigateToTeamsApp.href,
      target = _navigateToTeamsApp.target;
    return /*#__PURE__*/React.createElement(Anchor, {
      href: href,
      target: target,
      rel: "noopener noreferrer",
      testId: "mention-with-profilecard-link-fallback"
    }, mention);
  }
  return /*#__PURE__*/React.createElement(ProfileCardTrigger, {
    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: expValEquals('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
  }, /*#__PURE__*/React.createElement(ResourcedMention, {
    id: id,
    text: text,
    accessLevel: accessLevel,
    localId: localId,
    mentionProvider: mentionProvider,
    onClick: onClick,
    onMouseEnter: onMouseEnter,
    onMouseLeave: onMouseLeave,
    ssrPlaceholderId: ssrPlaceholderId
  }));
}