"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var extract_entity_data_exports = {};
__export(extract_entity_data_exports, {
  extractEntityData: () => extractEntityData
});
module.exports = __toCommonJS(extract_entity_data_exports);
var import_lodash = __toESM(require("lodash"));
const defaultEntityConverter = () => [];
const imageConverter = (entity) => [
  {
    ...entity.data.src?.id && { id: entity.data.src?.id },
    width: entity.data.src?.width,
    height: entity.data.src?.height,
    url: entity.data.src?.file_name,
    type: "image",
    alt: entity.data.metadata?.alt || "",
    caption: entity.data.metadata?.caption || "",
    link: entity.data.config?.link
  }
];
const galleryConverter = (entity) => entity.data.items.filter(
  ({ metadata }) => !metadata?.type || metadata?.type === "image" || metadata?.type === "video"
).map(
  ({ metadata, url, itemId }) => metadata?.type === "video" ? {
    type: "video",
    url,
    thumbnail: metadata?.poster?.url || "",
    caption: metadata?.title || "",
    isGalleryItem: true
  } : {
    url,
    height: metadata?.height,
    width: metadata?.width,
    id: itemId,
    type: "image",
    alt: metadata?.altText || "",
    caption: metadata?.title || "",
    isGalleryItem: true
  }
);
const giphyConverter = (entity) => [
  {
    type: "giphy",
    url: entity.data.gif?.originalUrl,
    mp4: entity.data.gif?.downsizedSmallMp4,
    thumbnail: entity.data.gif?.stillUrl,
    width: entity.data.gif?.width,
    height: entity.data.gif?.height,
    source: "static",
    gifType: entity.data.gif?.gifType
  }
];
const videoConverter = ({ data: { src = {}, isCustomVideo, metadata = {} } }) => {
  const url = import_lodash.default.isString(src) ? src : src.pathname;
  const thumbnail = import_lodash.default.has(src, "thumbnail") ? src.thumbnail?.pathname : metadata.thumbnail_url || "";
  return [
    {
      type: "video",
      url,
      isCustom: isCustomVideo,
      thumbnail,
      caption: metadata.title || ""
    }
  ];
};
const fileConverter = (entity) => [
  {
    name: entity.data.name,
    type: "file",
    fileType: entity.data.type,
    url: entity.data.url
  }
];
const mapConverter = (entity) => [
  {
    type: "map",
    mapSettings: entity.data.mapSettings
  }
];
const linkConverter = (entity) => [
  {
    type: "link",
    url: entity.data.url
  }
];
const emojiConverter = (entity) => [
  {
    type: "emoji",
    emojiUnicode: entity.data.emojiUnicode
  }
];
const converters = {
  "wix-draft-plugin-image": imageConverter,
  "wix-draft-plugin-gallery": galleryConverter,
  "wix-draft-plugin-divider": defaultEntityConverter,
  "wix-draft-plugin-video": videoConverter,
  "wix-draft-plugin-sound-cloud": videoConverter,
  "wix-draft-plugin-giphy": giphyConverter,
  "wix-draft-plugin-file-upload": fileConverter,
  "wix-draft-plugin-map": mapConverter,
  mention: defaultEntityConverter,
  "wix-draft-plugin-headers-markdown": defaultEntityConverter,
  "wix-draft-plugin-link-button": defaultEntityConverter,
  "wix-draft-plugin-action-button": defaultEntityConverter,
  "wix-draft-plugin-poll": defaultEntityConverter,
  //TODO: make custom converter
  LINK: linkConverter,
  LINK_PREVIEW: linkConverter,
  EMOJI_TYPE: emojiConverter,
  "wix-draft-plugin-html": defaultEntityConverter
};
const extractEntityData = (entity) => converters[entity.type] ? converters[entity.type](entity) : defaultEntityConverter(entity);
//# sourceMappingURL=extract-entity-data.js.map
