"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.extractSmartLinkPreviewImage = exports.default = void 0;
var _linkExtractors = require("@atlaskit/link-extractors");
var _constants = require("../../constants");
var extractPreview = function extractPreview(data) {
  if (!data) {
    return undefined;
  }
  var url = (0, _linkExtractors.extractImage)(data);
  return url ? {
    type: _constants.MediaType.Image,
    url: url
  } : undefined;
};
var _default = exports.default = extractPreview;
/**
 * Should be moved to link-extractors when jsonLd is deprecated
 */
var extractSmartLinkPreviewImage = exports.extractSmartLinkPreviewImage = function extractSmartLinkPreviewImage(response) {
  if (!response || !(response !== null && response !== void 0 && response.data)) {
    return undefined;
  }
  if ((0, _linkExtractors.isEntityPresent)(response)) {
    var _entity$thumbnail;
    var entity = (0, _linkExtractors.extractEntity)(response);
    var url = entity === null || entity === void 0 || (_entity$thumbnail = entity.thumbnail) === null || _entity$thumbnail === void 0 ? void 0 : _entity$thumbnail.externalUrl;
    return url ? {
      type: _constants.MediaType.Image,
      url: url
    } : undefined;
  }
  return extractPreview(response.data);
};