import _defineProperty from "@babel/runtime/helpers/defineProperty";
/* eslint-disable @repo/internal/react/no-class-components */
import React, { PureComponent } from 'react';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { ProviderFactory, WithProviders } from '../../provider-factory';
import { MentionWithProviders } from './mention-with-providers';
const MENTION_PROVIDERS = ['mentionProvider', 'profilecardProvider'];
export default class Mention extends PureComponent {
  constructor(props) {
    super(props);
    _defineProperty(this, "renderWithProvider", providers => {
      const {
        accessLevel,
        eventHandlers,
        id,
        text,
        localId,
        userType,
        isDisabled,
        disabledTooltip
      } = this.props;
      const {
        mentionProvider,
        profilecardProvider
      } = providers;
      return /*#__PURE__*/React.createElement(MentionWithProviders, {
        id: id,
        text: text,
        accessLevel: accessLevel,
        localId: localId,
        userType: userType,
        isDisabled: isDisabled,
        disabledTooltip: disabledTooltip,
        eventHandlers: eventHandlers,
        mentionProvider: mentionProvider,
        profilecardProvider: profilecardProvider
      });
    });
    this.providerFactory = props.providers || new ProviderFactory();
  }
  componentWillUnmount() {
    if (!this.props.providers) {
      // new ProviderFactory is created if no `providers` has been set
      // in this case when component is unmounted it's safe to destroy this providerFactory
      this.providerFactory.destroy();
    }
  }
  render() {
    const providers = expValEquals('platform_editor_perf_lint_cleanup', 'isEnabled', true) ? MENTION_PROVIDERS : ['mentionProvider', 'profilecardProvider'];
    return /*#__PURE__*/React.createElement(WithProviders, {
      providers: providers,
      providerFactory: this.providerFactory,
      renderNode: this.renderWithProvider
    });
  }
}