"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 gif_converter_exports = {};
__export(gif_converter_exports, {
  gifConverter: () => gifConverter
});
module.exports = __toCommonJS(gif_converter_exports);
var import_types = require("./../../pm-converters/types.js");
var import_consts = require("./../../ricos-content/consts.js");
var import_ricos_content = require("./../../ricos-content/index.js");
var import_next_schema = require("./../../ricos-schema/next-schema/index.js");
const gifConverter = (0, import_types.definePmNodeConverter)({
  toPm: {
    types: [import_next_schema.Node_Type.GIF],
    convert: (node, visit) => {
      const fallbackCaption = {
        id: (0, import_ricos_content.generateId)(),
        type: import_next_schema.Node_Type.CAPTION,
        nodes: []
      };
      return {
        type: import_consts.TIPTAP_FIGURE_TYPE,
        attrs: {
          id: (0, import_ricos_content.generateId)()
        },
        content: [
          {
            type: import_ricos_content.TIPTAP_GIF_TYPE,
            attrs: {
              ...node.gifData,
              id: node.id
            }
          },
          ...visit?.(
            (node.nodes?.length ?? 0) > 0 ? node : { ...node, nodes: [fallbackCaption] }
          ) ?? []
        ]
      };
    }
  },
  fromPm: {
    types: [import_consts.TIPTAP_FIGURE_TYPE, import_ricos_content.TIPTAP_GIF_TYPE],
    convert: (node, visit) => {
      if (node.type === import_ricos_content.TIPTAP_GIF_TYPE) {
        return void 0;
      }
      const gifNode = node.content?.find(({ type }) => type === import_ricos_content.TIPTAP_GIF_TYPE);
      if (!gifNode) {
        return void 0;
      }
      const { id, ...data } = gifNode?.attrs || {};
      const gifType = data.gifType === import_next_schema.GIFData_GIFType.STICKER ? data.gifType : void 0;
      const [captionNode] = visit?.(node) ?? [];
      return {
        type: import_next_schema.Node_Type.GIF,
        id: id ?? (0, import_ricos_content.generateId)(),
        nodes: captionNode?.nodes?.[0]?.textData?.text ? [captionNode] : [],
        gifData: {
          ...data,
          gifType
        }
      };
    }
  }
});
//# sourceMappingURL=gif-converter.js.map
