"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 from_pm_image_any_state_exports = {};
__export(from_pm_image_any_state_exports, {
  fromPmImageAnyState: () => fromPmImageAnyState
});
module.exports = __toCommonJS(from_pm_image_any_state_exports);
var import_ricos_content = require("./../../ricos-content/index.js");
var import_next_schema = require("./../../ricos-schema/next-schema/index.js");
var import_link_converters = require("./../../_shared/link/link-converters.js");
var import_caption_to_plain_text = require("./caption-to-plain-text.js");
const fromPmImageAnyState = (pmFigureNode, fromPmNode) => {
  const imageNode = pmFigureNode.content?.find(
    ({ type }) => type === import_ricos_content.TIPTAP_IMAGE_TYPE
  );
  if (!imageNode) {
    return void 0;
  }
  const { id, ...imageData } = imageNode?.attrs || {};
  const captionNode = fromPmNode(pmFigureNode)?.nodes?.[0] ?? [];
  const captionPlainText = (0, import_caption_to_plain_text.captionToPlainText)(pmFigureNode);
  const { spoiler, ...rest } = imageData.containerData || {};
  const containerData = {
    ...rest,
    ...spoiler?.enabled ? { spoiler: { ...spoiler } } : {}
  };
  const image = imageData.image ? imageData.image : imageData.tempData ? fallbackImage : fallbackImage;
  return {
    type: import_next_schema.Node_Type.IMAGE,
    id: id ?? (0, import_ricos_content.generateId)(),
    nodes: captionPlainText ? [captionNode] : [],
    imageData: {
      ...imageData,
      image,
      caption: captionPlainText,
      altText: imageData.altText || void 0,
      decorative: imageData.decorative || void 0,
      disableDownload: imageData.disableDownload || void 0,
      disableExpand: imageData.disableExpand || void 0,
      containerData: Object.keys(containerData).length ? containerData : void 0,
      styles: imageData.styles || void 0,
      link: imageData.link ? (0, import_link_converters.fromTiptapLinkConverter)(imageData.link) : void 0
    }
  };
};
const fallbackImage = {
  src: {
    url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNgYAAAAAMAASsJTYQAAAAASUVORK5CYII="
  }
};
//# sourceMappingURL=from-pm-image-any-state.js.map
