import { extractEntity, extractImage, isEntityPresent } from '@atlaskit/link-extractors';
import { MediaType } from '../../constants';
var extractPreview = function extractPreview(data) {
  if (!data) {
    return undefined;
  }
  var url = extractImage(data);
  return url ? {
    type: MediaType.Image,
    url: url
  } : undefined;
};
export default extractPreview;

/**
 * Should be moved to link-extractors when jsonLd is deprecated
 */
export var extractSmartLinkPreviewImage = function extractSmartLinkPreviewImage(response) {
  if (!response || !(response !== null && response !== void 0 && response.data)) {
    return undefined;
  }
  if (isEntityPresent(response)) {
    var _entity$thumbnail;
    var entity = 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: MediaType.Image,
      url: url
    } : undefined;
  }
  return extractPreview(response.data);
};