import { definePmNodeConverter } from "./../pm-converters/types.js";
import { HTMLData_Source, Node_Type } from "./../ricos-schema/next-schema/index.js";
const htmlConverter = definePmNodeConverter({
  toPm: {
    types: [Node_Type.HTML],
    convert: (node) => {
      return {
        type: Node_Type.HTML,
        attrs: {
          ...node.htmlData,
          id: node.id,
          autoHeight: node.htmlData.autoHeight ?? true,
          state: {
            status: "SUCCESS"
          }
        }
      };
    }
  },
  fromPm: {
    types: [Node_Type.HTML],
    convert: (node) => {
      const { id } = node.attrs || {};
      const attrs = node.attrs || {};
      const hasContent = attrs.html !== null || attrs.widgetId !== null;
      if (attrs.state === null || attrs.state?.status === "INITIAL" || attrs.state?.status === "LOADING" && !hasContent || attrs.state?.status === "ERROR" && !hasContent) {
        return void 0;
      }
      const htmlData = {
        containerData: attrs.containerData ?? void 0,
        source: attrs.source || HTMLData_Source.HTML,
        url: attrs.url || void 0,
        html: attrs.html || void 0,
        widgetId: attrs.widgetId || void 0,
        autoHeight: attrs.autoHeight === false ? false : void 0
      };
      return {
        type: Node_Type.HTML,
        id,
        nodes: [],
        htmlData
      };
    }
  }
});
export {
  htmlConverter
};
//# sourceMappingURL=html-converter.js.map
