"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var convert_to_gallery_item_exports = {};
__export(convert_to_gallery_item_exports, {
  convertToGalleryItem: () => convertToGalleryItem
});
module.exports = __toCommonJS(convert_to_gallery_item_exports);
var import_get_link_href_url = require("./../link/get-link-href-url.js");
var import_normalize_href = require("./../link/normalize-href.js");
var import_wix_rich_content_common = require("./../../wix-rich-content-common/index.js");
const convertToGalleryItem = ({
  item,
  index,
  relValue,
  anchorTarget,
  baseUrl
}) => {
  const { image, video, title, altText } = item;
  const media = image?.media || video?.media;
  const mediaUrl = media?.src?.url || media?.src?.id || "";
  const width = media?.width || 0;
  const height = media?.height || 0;
  const convertedData = {
    mediaUrl,
    url: mediaUrl,
    metaData: {
      type: image ? "image" : "video",
      height,
      width,
      title,
      alt: altText
    },
    // uuid is used to guarentee there are no 2 gallery items on the DOM with the same ID (on different galleries) due to a pro gallery issues with videos - breaks the video controls behavoiur.
    itemId: (0, import_wix_rich_content_common.uuid)() + "_" + index.toString(),
    hash: mediaUrl + "_" + index.toString()
  };
  if (video) {
    convertedData.metaData.link = {
      target: "_blank",
      rel: "noopener",
      url: (0, import_normalize_href.normalizeHref)(mediaUrl) ?? ""
    };
    const { src, width: thumbnailWidth, height: thumbnailHeight } = video.thumbnail || {};
    if (src?.url || src?.id) {
      convertedData.metaData.poster = {
        url: src.url || src.id || "",
        width: thumbnailWidth || width,
        height: thumbnailHeight || height
      };
    }
  }
  if (image?.link) {
    const { url: linkUrl = "", target: linkTarget, rel: linkRel, anchor } = image.link;
    const target = linkTarget && `_${linkTarget.toLowerCase()}` || anchorTarget || "_self";
    let rel = relValue || "noopener";
    if (linkRel) {
      rel = "noopener";
      linkRel.nofollow && (rel += " nofollow");
      linkRel.sponsored && (rel += " sponsored");
      linkRel.ugc && (rel += " ugc");
      (linkRel.noreferrer || linkRel.noreferrer === void 0) && (rel += " noreferrer");
    }
    const normalizedUrl = (0, import_normalize_href.normalizeHref)(linkUrl) ?? "";
    const url = normalizedUrl ? normalizedUrl : (0, import_get_link_href_url.getLinkHrefUrl)(anchor ? { anchor } : { url: linkUrl }, baseUrl) ?? "";
    convertedData.metaData.link = {
      type: "wix",
      target,
      data: {
        type: anchor ? "AnchorLink" : "ExternalLink",
        target,
        rel,
        url,
        anchorName: anchor
      }
    };
    convertedData.directLink = {
      url,
      target,
      rel
    };
  }
  return convertedData;
};
//# sourceMappingURL=convert-to-gallery-item.js.map
