"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 smart_block_cell_exports = {};
__export(smart_block_cell_exports, {
  default: () => smart_block_cell_default
});
module.exports = __toCommonJS(smart_block_cell_exports);
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_smart_block_cell_view = require("../components/smart-block-cell-view.js");
var import_consts = require("../consts.js");
var import_cell_position = require("../utils/cell-position.js");
var import_cell_view_model = require("../utils/cell-view-model.js");
var import_resolve_theme_smart_block = require("../utils/resolve-theme-smart-block.js");
const CIRCLE_SIDE_TO_ALIGNMENT = {
  left: "right",
  right: "left",
  bottom: "center"
};
const SmartBlockCellViewer = ({
  node,
  nodeIndex: cellIndex,
  RicosNodesRenderer
}) => {
  const cellNode = node;
  const { theme } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const themeSmartBlock = (0, import_react.useMemo)(() => (0, import_resolve_theme_smart_block.resolveThemeSmartBlock)(theme), [theme]);
  const nodeContext = (0, import_react.useContext)(import_ricos_context.RicosNodeContext) ?? {};
  const parentNode = nodeContext.parentNode;
  const smartBlockData = parentNode?.smartBlockData;
  const type = smartBlockData?.type ?? import_consts.SMART_BLOCK_DEFAULTS.type;
  const columnSize = smartBlockData && "columnSize" in smartBlockData ? smartBlockData?.columnSize ?? import_consts.SMART_BLOCK_DEFAULTS.columnSize : import_consts.SMART_BLOCK_DEFAULTS.columnSize;
  const orientation = smartBlockData && "orientation" in smartBlockData ? smartBlockData.orientation : "HORIZONTAL";
  const isShapesMode = !!parentNode?.nodes?.some(
    (n) => n.type === "SMART_BLOCK_CELL" && n.smartBlockCellData !== null && n.smartBlockCellData !== void 0 && "shape" in n.smartBlockCellData && n.smartBlockCellData.shape !== null && n.smartBlockCellData.shape !== void 0
  );
  const totalCells = parentNode?.nodes?.length ?? 1;
  const viewModel = (0, import_react.useMemo)(
    () => (0, import_cell_view_model.ricosCellToViewModel)(cellNode, {
      type,
      columnSize,
      orientation,
      totalCells,
      cellIndex,
      isShapesMode
    }),
    [cellNode, type, columnSize, orientation, totalCells, cellIndex, isShapesMode]
  );
  const circleAlignment = type === "CIRCLE" ? CIRCLE_SIDE_TO_ALIGNMENT[(0, import_cell_position.getCircleCellStyle)(cellIndex, totalCells).side] : void 0;
  return /* @__PURE__ */ import_react.default.createElement(
    import_smart_block_cell_view.SmartBlockCellView,
    {
      viewModel,
      themeSmartBlock,
      contentSlot: (contentProps) => {
        const renderer = /* @__PURE__ */ import_react.default.createElement(
          RicosNodesRenderer,
          {
            key: `children-${node.id}`,
            nodes: node.nodes ?? [],
            shouldParagraphApplyTextStyle: true
          }
        );
        return /* @__PURE__ */ import_react.default.createElement("div", { ...contentProps }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosNodeContextProvider, { parentNode: node, parentIndex: cellIndex }, circleAlignment ? /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosAlignmentContextProvider, { textAlignment: circleAlignment }, renderer) : renderer));
      }
    }
  );
};
const SmartBlockCellRenderer = ({ node, ...props }) => {
  return /* @__PURE__ */ import_react.default.createElement(SmartBlockCellViewer, { key: node.id, node, ...props });
};
var smart_block_cell_default = SmartBlockCellRenderer;
//# sourceMappingURL=smart-block-cell.js.map
