import lodash from "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 = lodash.isString(src) ? src : src.pathname;
  const thumbnail = lodash.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);
export {
  extractEntityData
};
//# sourceMappingURL=extract-entity-data.js.map
