import React, { useMemo } from 'react';
import { ResourcedEmoji } from '@atlaskit/emoji/element';
var EmojiNodeFunctional = function EmojiNodeFunctional(props) {
  var _resourceConfig$optim;
  var allowTextFallback = props.allowTextFallback,
    shortName = props.shortName,
    id = props.id,
    fallback = props.fallback,
    fitToHeight = props.fitToHeight,
    showTooltip = props.showTooltip,
    resourceConfig = props.resourceConfig,
    emojiProvider = props.emojiProvider;
  var emojiId = useMemo(function () {
    return {
      shortName: shortName,
      id: id,
      fallback: fallback
    };
  }, [shortName, id, fallback]);
  var emojiProviderResolver = useMemo(function () {
    return Promise.resolve(emojiProvider);
  }, [emojiProvider]);
  if (allowTextFallback && !emojiProvider) {
    return /*#__PURE__*/React.createElement("span", {
      "data-emoji-id": id,
      "data-emoji-short-name": shortName,
      "data-emoji-text": fallback || shortName
    }, fallback || shortName);
  }
  if (!emojiProvider) {
    return null;
  }
  return /*#__PURE__*/React.createElement(ResourcedEmoji, {
    emojiId: emojiId,
    emojiProvider: emojiProviderResolver,
    showTooltip: showTooltip,
    fitToHeight: fitToHeight,
    optimistic: true,
    optimisticImageURL: resourceConfig === null || resourceConfig === void 0 || (_resourceConfig$optim = resourceConfig.optimisticImageApi) === null || _resourceConfig$optim === void 0 ? void 0 : _resourceConfig$optim.getUrl({
      id: id,
      fallback: fallback,
      shortName: shortName
    }),
    editorEmoji: true
  });
};
var EmojiNode = function EmojiNode(_ref) {
  var allowTextFallback = _ref.allowTextFallback,
    shortName = _ref.shortName,
    id = _ref.id,
    fallback = _ref.fallback,
    fitToHeight = _ref.fitToHeight,
    showTooltip = _ref.showTooltip,
    resourceConfig = _ref.resourceConfig,
    emojiProvider = _ref.emojiProvider,
    providers = _ref.providers;
  return /*#__PURE__*/React.createElement(EmojiNodeFunctional, {
    allowTextFallback: allowTextFallback,
    shortName: shortName,
    id: id,
    fallback: fallback,
    fitToHeight: fitToHeight,
    showTooltip: showTooltip,
    resourceConfig: resourceConfig,
    emojiProvider: emojiProvider,
    providers: providers
  });
};
var _default_1 = /*#__PURE__*/React.memo(EmojiNode);
export default _default_1;