"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _element = require("@atlaskit/emoji/element");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 = (0, _react.useMemo)(function () {
    return {
      shortName: shortName,
      id: id,
      fallback: fallback
    };
  }, [shortName, id, fallback]);
  var emojiProviderResolver = (0, _react.useMemo)(function () {
    return Promise.resolve(emojiProvider);
  }, [emojiProvider]);
  if (allowTextFallback && !emojiProvider) {
    return /*#__PURE__*/_react.default.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.default.createElement(_element.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.default.createElement(EmojiNodeFunctional, {
    allowTextFallback: allowTextFallback,
    shortName: shortName,
    id: id,
    fallback: fallback,
    fitToHeight: fitToHeight,
    showTooltip: showTooltip,
    resourceConfig: resourceConfig,
    emojiProvider: emojiProvider,
    providers: providers
  });
};
var _default = exports.default = /*#__PURE__*/_react.default.memo(EmojiNode);