import _defineProperty from "@babel/runtime/helpers/defineProperty";
/* eslint-disable @repo/internal/react/no-class-components */
import React, { PureComponent } from 'react';
import { ProviderFactory, WithProviders } from '../../provider-factory';
import { MentionWithProviders } from './mention-with-providers';
export default class Mention extends PureComponent {
  constructor(props) {
    super(props);
    _defineProperty(this, "renderWithProvider", providers => {
      const {
        accessLevel,
        eventHandlers,
        id,
        text,
        localId
      } = this.props;
      const {
        mentionProvider,
        profilecardProvider
      } = providers;
      return /*#__PURE__*/React.createElement(MentionWithProviders, {
        id: id,
        text: text,
        accessLevel: accessLevel,
        localId: localId,
        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() {
    return /*#__PURE__*/React.createElement(WithProviders
    // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
    , {
      providers: ['mentionProvider', 'profilecardProvider'],
      providerFactory: this.providerFactory,
      renderNode: this.renderWithProvider
    });
  }
}