import { definePmNodeConverter } from "./../pm-converters/types.js";
import { Node_Type } from "./../ricos-schema/next-schema/index.js";
import { fromTiptapLinkConverter } from "./../_shared/link/link-converters.js";
const galleryConverter = definePmNodeConverter({
  toPm: {
    types: [Node_Type.GALLERY],
    convert: (node) => ({
      type: Node_Type.GALLERY,
      attrs: {
        ...node.galleryData,
        id: node.id
      }
    })
  },
  fromPm: {
    types: [Node_Type.GALLERY],
    convert: (node) => {
      const { id, ...data } = node.attrs || {};
      const { spoiler, ...rest } = data.containerData || {};
      const containerData = {
        ...rest,
        ...spoiler?.enabled ? { spoiler: { ...spoiler } } : {}
      };
      const galleryData = data;
      const items = galleryData.items.map(({ loading, error, ...item }) => {
        if (loading || error) {
          return void 0;
        }
        if ("image" in item && item.image) {
          return {
            ...item,
            image: {
              ...item.image,
              link: fromTiptapLinkConverter(item.image.link)
            }
          };
        }
        return item;
      }).filter(Boolean);
      if (items.length === 0) {
        return void 0;
      }
      return {
        type: Node_Type.GALLERY,
        id,
        nodes: [],
        galleryData: {
          ...galleryData,
          items,
          disableExpand: data.disableExpand || void 0,
          disableDownload: data.disableDownload || void 0,
          containerData: Object.keys(containerData).length ? containerData : void 0
        }
      };
    }
  }
});
export {
  galleryConverter
};
//# sourceMappingURL=gallery-converter.js.map
