"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 video_converter_exports = {};
__export(video_converter_exports, {
  videoConverter: () => videoConverter
});
module.exports = __toCommonJS(video_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 videoConverter = (0, import_types.definePmNodeConverter)({
  toPm: {
    types: [import_next_schema.Node_Type.VIDEO],
    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_consts.TIPTAP_VIDEO_TYPE,
            attrs: {
              ...node.videoData,
              id: node.id
            }
          },
          ...visit?.(
            (node.nodes?.length ?? 0) > 0 ? node : { ...node, nodes: [fallbackCaption] }
          ) ?? []
        ]
      };
    }
  },
  fromPm: {
    types: [import_consts.TIPTAP_FIGURE_TYPE, import_consts.TIPTAP_VIDEO_TYPE],
    convert: (node, visit) => {
      if (node.type === import_consts.TIPTAP_VIDEO_TYPE) {
        return void 0;
      }
      const videoNode = node.content?.find(({ type }) => type === import_consts.TIPTAP_VIDEO_TYPE);
      if (!videoNode) {
        return void 0;
      }
      const { id, loading, error, ...data } = videoNode?.attrs || {};
      if (loading || error) {
        return void 0;
      }
      const [captionNode] = visit?.(node) ?? [];
      const { spoiler, ...rest } = data.containerData || {};
      const containerData = {
        ...rest,
        ...spoiler?.enabled ? { spoiler: { ...spoiler } } : {}
      };
      return {
        type: import_next_schema.Node_Type.VIDEO,
        id: id ?? (0, import_ricos_content.generateId)(),
        nodes: captionNode?.nodes?.[0]?.textData?.text ? [captionNode] : [],
        videoData: {
          ...data,
          disableDownload: data.disableDownload || void 0,
          containerData: Object.keys(containerData).length ? containerData : void 0
        }
      };
    }
  }
});
//# sourceMappingURL=video-converter.js.map
