import { jsx as _jsx } from "react/jsx-runtime";
export const UploadJSXConverter = {
  upload: ({
    node
  }) => {
    const uploadDocument = node;
    const url = uploadDocument?.value?.url;
    /**
    * If the upload is not an image, return a link to the upload
    */
    if (!uploadDocument?.value?.mimeType?.startsWith('image')) {
      return /*#__PURE__*/_jsx("a", {
        href: url,
        rel: "noopener noreferrer",
        children: uploadDocument.value?.filename
      });
    }
    /**
    * If the upload is a simple image with no different sizes, return a simple img tag
    */
    if (!uploadDocument?.value?.sizes || !Object.keys(uploadDocument?.value?.sizes).length) {
      return /*#__PURE__*/_jsx("img", {
        alt: uploadDocument?.value?.filename,
        height: uploadDocument?.value?.height,
        src: url,
        width: uploadDocument?.value?.width
      });
    }
    /**
    * If the upload is an image with different sizes, return a picture element
    */
    const pictureJSX = [];
    // Iterate through each size in the data.sizes object
    for (const size in uploadDocument.value?.sizes) {
      const imageSize = uploadDocument.value?.sizes[size];
      // Skip if any property of the size object is null
      if (!imageSize.width || !imageSize.height || !imageSize.mimeType || !imageSize.filesize || !imageSize.filename || !imageSize.url) {
        continue;
      }
      const imageSizeURL = imageSize?.url;
      pictureJSX.push(/*#__PURE__*/_jsx("source", {
        media: "(max-width: ${imageSize.width}px)",
        srcSet: imageSizeURL,
        type: imageSize.mimeType
      }, size));
    }
    // Add the default img tag
    pictureJSX.push(/*#__PURE__*/_jsx("img", {
      alt: uploadDocument.value?.filename,
      height: uploadDocument.value?.height,
      src: url,
      width: uploadDocument.value?.width
    }, 'image'));
    return /*#__PURE__*/_jsx("picture", {
      children: pictureJSX
    });
  }
};
//# sourceMappingURL=upload.js.map