import _defineProperty from "@babel/runtime/helpers/defineProperty";
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
      } = this.props;
      const {
        mentionProvider,
        profilecardProvider
      } = providers;
      return /*#__PURE__*/React.createElement(MentionWithProviders, {
        id: id,
        text: text,
        accessLevel: accessLevel,
        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, {
      providers: ['mentionProvider', 'profilecardProvider'],
      providerFactory: this.providerFactory,
      renderNode: this.renderWithProvider
    });
  }
}