import { definePmNodeConverter } from "./../pm-converters/types.js";
import { Node_Type } from "./../ricos-schema/next-schema/index.js";
import { hasOnlyDefaults } from "./utils.js";
const DEFAULT_FALSE_PROPERTIES = [
  "hideImage",
  "hidePrice",
  "hideButton",
  "hideDescription",
  "hideDateTime",
  "hideLocation",
  "hideDuration"
];
const DEFAULT_TRUE_PROPERTIES = ["hideRibbon"];
const STYLE_DEFAULTS = {
  imageStyles: { imagePosition: "START", aspectRatio: "SQUARE", resizing: "FILL" },
  ribbonStyles: { ribbonPlacement: "PRODUCT_INFO" },
  cardStyles: { type: "CONTAINED", alignment: "START", titlePriceLayout: "STACKED" },
  buttonStyles: { buttonSize: "MEDIUM" }
};
const filterDefaultData = (data) => {
  const filteredData = Object.fromEntries(
    Object.entries(data).filter(
      ([key, value]) => (!DEFAULT_FALSE_PROPERTIES.includes(key) || value === true) && (!DEFAULT_TRUE_PROPERTIES.includes(key) || value === false)
    )
  );
  Object.entries(STYLE_DEFAULTS).forEach(([styleKey, defaults]) => {
    if (filteredData[styleKey] && hasOnlyDefaults(filteredData[styleKey], defaults)) {
      filteredData[styleKey] = void 0;
    }
  });
  return filteredData;
};
const appEmbedConverter = definePmNodeConverter({
  toPm: {
    types: [Node_Type.APP_EMBED],
    convert: (node) => {
      const { containerData, ...appEmbedData } = node.appEmbedData;
      return {
        type: Node_Type.APP_EMBED,
        attrs: {
          ...appEmbedData,
          containerData,
          id: node.id
        }
      };
    }
  },
  fromPm: {
    types: [Node_Type.APP_EMBED],
    convert: (node) => {
      const { id, containerData, ...data } = node.attrs || {};
      const finalData = filterDefaultData(data);
      return {
        type: Node_Type.APP_EMBED,
        id,
        nodes: [],
        appEmbedData: {
          ...finalData,
          containerData
        }
      };
    }
  }
});
export {
  appEmbedConverter
};
//# sourceMappingURL=app-embed-converter.js.map
