"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var from_external_node_exports = {};
__export(from_external_node_exports, {
  fromExternalNode: () => fromExternalNode
});
module.exports = __toCommonJS(from_external_node_exports);
var import_react = __toESM(require("react"));
var import_struct_converters = require("./../../../../../ricos-content/lib/struct-converters.js");
var import_v1 = require("./../../../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_get_class_names = require("./get-class-names.js");
var import_node_view_container = require("./node-view-container.js");
const isDraftEntityConfig = (data) => (data.width || data.alignment || data.textWrap) && (["content", "original", "fullWidth", "small"].includes(data.size) || ["center", "left", "right"].includes(data.alignment));
const toContainerData = (data) => ({
  ...typeof data.size === "string" ? { width: { size: data.size.toUpperCase() } } : {},
  ...typeof data.alignment === "string" ? { alignment: data.alignment.toUpperCase() } : {},
  ...typeof data.textWrap !== "undefined" ? { textWrap: data.textWrap !== "nowrap" } : {}
});
const getContainerData = (externalData) => {
  if (isDraftEntityConfig(externalData.config || {})) {
    return toContainerData(externalData.config);
  }
  return externalData.containerData;
};
const Plugin = ({
  type,
  context,
  node,
  nodeIndex,
  children,
  pluginComponent: { component: Component }
}) => {
  const settings = context.config?.[type] || {};
  const componentData = node.externalData && (0, import_struct_converters.convertStructToJson)(node.externalData) || {};
  const containerData = getContainerData(componentData) || {};
  const componentProps = {
    type,
    componentData,
    settings,
    children,
    ...context,
    blockKey: node.id
  };
  const customClassNames = {
    alignment: (0, import_get_class_names.getAlignmentClassName)(containerData),
    size: (0, import_get_class_names.getSizeClassName)(containerData),
    textWrap: (0, import_get_class_names.getTextWrapClassName)(containerData)
  };
  return /* @__PURE__ */ import_react.default.createElement(import_node_view_container.nodeViewContainer, { node, nodeIndex, customClassNames }, /* @__PURE__ */ import_react.default.createElement(Component, { ...componentProps }));
};
const fromExternalNode = (args) => {
  return {
    [import_v1.Node_Type.EXTERNAL]: ({ node, nodeIndex }) => {
      return /* @__PURE__ */ import_react.default.createElement(Plugin, { key: node.id, node, nodeIndex, ...args });
    }
  };
};
//# sourceMappingURL=from-external-node.js.map
