// packages/block-library/src/media-text/transforms.js
import { createBlock } from "@wordpress/blocks";
var transforms = {
  from: [
    {
      type: "block",
      blocks: ["core/image"],
      transform: ({ alt, url, id, anchor }) => createBlock("core/media-text", {
        mediaAlt: alt,
        mediaId: id,
        mediaUrl: url,
        mediaType: "image",
        anchor
      })
    },
    {
      type: "block",
      blocks: ["core/video"],
      transform: ({ src, id, anchor }) => createBlock("core/media-text", {
        mediaId: id,
        mediaUrl: src,
        mediaType: "video",
        anchor
      })
    },
    {
      type: "block",
      blocks: ["core/cover"],
      transform: ({
        align,
        alt,
        anchor,
        backgroundType,
        customGradient,
        customOverlayColor,
        gradient,
        id,
        overlayColor,
        style,
        textColor,
        url,
        useFeaturedImage
      }, innerBlocks) => {
        let additionalAttributes = {};
        if (customGradient) {
          additionalAttributes = {
            style: {
              color: {
                gradient: customGradient
              }
            }
          };
        } else if (customOverlayColor) {
          additionalAttributes = {
            style: {
              color: {
                background: customOverlayColor
              }
            }
          };
        }
        if (style?.color?.text) {
          additionalAttributes.style = {
            color: {
              ...additionalAttributes.style?.color,
              text: style.color.text
            }
          };
        }
        return createBlock(
          "core/media-text",
          {
            align,
            anchor,
            backgroundColor: overlayColor,
            gradient,
            mediaAlt: alt,
            mediaId: id,
            mediaType: backgroundType,
            mediaUrl: url,
            textColor,
            useFeaturedImage,
            ...additionalAttributes
          },
          innerBlocks
        );
      }
    }
  ],
  to: [
    {
      type: "block",
      blocks: ["core/image"],
      isMatch: ({ mediaType, mediaUrl }) => {
        return !mediaUrl || mediaType === "image";
      },
      transform: ({ mediaAlt, mediaId, mediaUrl, anchor }) => {
        return createBlock("core/image", {
          alt: mediaAlt,
          id: mediaId,
          url: mediaUrl,
          anchor
        });
      }
    },
    {
      type: "block",
      blocks: ["core/video"],
      isMatch: ({ mediaType, mediaUrl }) => {
        return !mediaUrl || mediaType === "video";
      },
      transform: ({ mediaId, mediaUrl, anchor }) => {
        return createBlock("core/video", {
          id: mediaId,
          src: mediaUrl,
          anchor
        });
      }
    },
    {
      type: "block",
      blocks: ["core/cover"],
      transform: ({
        align,
        anchor,
        backgroundColor,
        focalPoint,
        gradient,
        mediaAlt,
        mediaId,
        mediaType,
        mediaUrl,
        style,
        textColor,
        useFeaturedImage
      }, innerBlocks) => {
        const additionalAttributes = {};
        if (style?.color?.gradient) {
          additionalAttributes.customGradient = style.color.gradient;
        } else if (style?.color?.background) {
          additionalAttributes.customOverlayColor = style.color.background;
        }
        if (style?.color?.text) {
          additionalAttributes.style = {
            color: { text: style.color.text }
          };
        }
        const coverAttributes = {
          align,
          alt: mediaAlt,
          anchor,
          backgroundType: mediaType,
          dimRatio: !!mediaUrl || useFeaturedImage ? 50 : 100,
          focalPoint,
          gradient,
          id: mediaId,
          overlayColor: backgroundColor,
          textColor,
          url: mediaUrl,
          useFeaturedImage,
          ...additionalAttributes
        };
        return createBlock(
          "core/cover",
          coverAttributes,
          innerBlocks
        );
      }
    }
  ]
};
var transforms_default = transforms;
export {
  transforms_default as default
};
//# sourceMappingURL=transforms.js.map
