import React, { useMemo } from 'react';
import { ResourcedEmoji } from '@atlaskit/emoji/element';
const EmojiNodeFunctional = props => {
  var _resourceConfig$optim;
  const {
    allowTextFallback,
    shortName,
    id,
    fallback,
    fitToHeight,
    showTooltip,
    resourceConfig,
    emojiProvider
  } = props;
  const emojiId = useMemo(() => ({
    shortName,
    id,
    fallback
  }), [shortName, id, fallback]);
  const emojiProviderResolver = useMemo(() => 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 ? void 0 : (_resourceConfig$optim = resourceConfig.optimisticImageApi) === null || _resourceConfig$optim === void 0 ? void 0 : _resourceConfig$optim.getUrl({
      id,
      fallback,
      shortName
    }),
    editorEmoji: true
  });
};
const EmojiNode = ({
  allowTextFallback,
  shortName,
  id,
  fallback,
  fitToHeight,
  showTooltip,
  resourceConfig,
  emojiProvider,
  providers
}) => {
  return /*#__PURE__*/React.createElement(EmojiNodeFunctional, {
    allowTextFallback: allowTextFallback,
    shortName: shortName,
    id: id,
    fallback: fallback,
    fitToHeight: fitToHeight,
    showTooltip: showTooltip,
    resourceConfig: resourceConfig,
    emojiProvider: emojiProvider,
    providers: providers
  });
};
export default /*#__PURE__*/React.memo(EmojiNode);