"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 button_converters_exports = {};
__export(button_converters_exports, {
  actionButtonConverter: () => actionButtonConverter,
  linkButtonConverter: () => linkButtonConverter
});
module.exports = __toCommonJS(button_converters_exports);
var import_types = require("./../pm-converters/types.js");
var import_ricos_content = require("./../ricos-content/index.js");
var import_next_schema = require("./../ricos-schema/next-schema/index.js");
var import_link_converters = require("./../_shared/link/link-converters.js");
const toTiptapButtonConvert = (node) => {
  const styles = node.buttonData.styles;
  const bgColor = styles?.backgroundColor ?? styles?.colors?.background;
  const bgColorHover = styles?.backgroundColorHover;
  return {
    type: node.buttonData.type === "LINK" ? import_ricos_content.TIPTAP_LINK_BUTTON_TYPE : import_ricos_content.TIPTAP_ACTION_BUTTON_TYPE,
    attrs: {
      ...node.buttonData,
      styles: {
        ...styles,
        // Clear deprecated fields
        border: void 0,
        colors: void 0,
        backgroundColor: void 0,
        backgroundColorHover: void 0,
        // Migrate deprecated backgroundColor to new background union
        background: styles?.background ?? (bgColor ? { type: "COLOR", color: bgColor } : void 0),
        backgroundHover: styles?.backgroundHover ?? (bgColorHover ? { type: "COLOR", color: bgColorHover } : void 0),
        textColor: styles?.textColor ?? styles?.colors?.text,
        borderColor: styles?.borderColor ?? styles?.colors?.border,
        borderWidth: styles?.borderWidth ?? styles?.border?.width,
        borderRadius: styles?.borderRadius ?? styles?.border?.radius
      },
      id: node.id
    }
  };
};
const fromTiptapButtonConvert = (node) => {
  const { id, ...data } = node.attrs || {};
  const linkData = data.link;
  const containerData = data.containerData;
  return {
    type: import_next_schema.Node_Type.BUTTON,
    id,
    nodes: [],
    buttonData: {
      ...data,
      link: (0, import_link_converters.fromTiptapLinkConverter)(linkData),
      containerData: {
        ...containerData,
        alignment: containerData?.alignment || import_next_schema.PluginContainerData_Alignment.CENTER,
        width: containerData?.width ? {
          ...containerData?.width,
          size: containerData?.width?.custom ? void 0 : containerData?.width?.size
        } : void 0
      },
      text: data.text || ""
    }
  };
};
const linkButtonConverter = (0, import_types.definePmNodeConverter)({
  toPm: {
    types: [import_next_schema.Node_Type.BUTTON],
    convert: toTiptapButtonConvert
  },
  fromPm: {
    types: [import_ricos_content.TIPTAP_LINK_BUTTON_TYPE],
    convert: fromTiptapButtonConvert
  }
});
const actionButtonConverter = (0, import_types.definePmNodeConverter)({
  toPm: {
    types: [import_next_schema.Node_Type.BUTTON],
    convert: toTiptapButtonConvert
  },
  fromPm: {
    types: [import_ricos_content.TIPTAP_ACTION_BUTTON_TYPE],
    convert: fromTiptapButtonConvert
  }
});
//# sourceMappingURL=button-converters.js.map
