"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 block_view_model_exports = {};
__export(block_view_model_exports, {
  jtdBlockToViewModel: () => jtdBlockToViewModel,
  pmBlockToViewModel: () => pmBlockToViewModel
});
module.exports = __toCommonJS(block_view_model_exports);
var import_next_schema = require("./../../ricos-schema/next-schema/index.js");
var import_pm_node_types = require("./../../_shared/pm-node-types.js");
var import_consts = require("../consts.js");
const nullToUndef = (value) => value === null || value === void 0 ? void 0 : value;
const hasCellRenderData = (type) => type === "CIRCLE" || type === "STAIRCASE" || type === "PYRAMID" || type === "VERTICAL_FUNNEL";
const pmCells = (pmNode) => {
  const cells = [];
  pmNode.forEach((child) => {
    if (child.type.name === import_pm_node_types.PmNodeType.SMART_BLOCK_CELL) {
      const attrs = child.attrs;
      cells.push({
        cellId: nullToUndef(attrs.id),
        accentColor: nullToUndef(attrs.accentColor),
        shape: attrs.shape,
        shapeColor: nullToUndef(attrs.shapeColor)
      });
    }
  });
  return cells;
};
const jtdCells = (node) => (node.nodes ?? []).filter((n) => n.type === import_next_schema.Node_Type.SMART_BLOCK_CELL).map((cell) => {
  const data = cell.smartBlockCellData;
  return {
    cellId: cell.id,
    accentColor: data && "accentColor" in data ? data.accentColor : void 0,
    shape: data && "shape" in data ? data.shape : void 0,
    shapeColor: data && "shapeColor" in data ? data.shapeColor : void 0
  };
});
const pmBlockToViewModel = (pmNode) => {
  const attrs = pmNode.attrs;
  const type = attrs.type ?? import_consts.SMART_BLOCK_DEFAULTS.type;
  return {
    type,
    columnSize: attrs.columnSize ?? import_consts.SMART_BLOCK_DEFAULTS.columnSize,
    orientation: nullToUndef(attrs.orientation),
    totalCells: pmNode.childCount,
    blockBorder: {
      borderColor: nullToUndef(attrs.borderColor),
      borderWidth: nullToUndef(attrs.borderWidth),
      borderRadius: nullToUndef(attrs.borderRadius)
    },
    cells: hasCellRenderData(type) ? pmCells(pmNode) : void 0
  };
};
const jtdBlockToViewModel = (node) => {
  const data = node.smartBlockData;
  const type = data?.type ?? import_consts.SMART_BLOCK_DEFAULTS.type;
  return {
    type,
    columnSize: data && "columnSize" in data ? data.columnSize ?? import_consts.SMART_BLOCK_DEFAULTS.columnSize : import_consts.SMART_BLOCK_DEFAULTS.columnSize,
    orientation: data && "orientation" in data ? data.orientation : void 0,
    totalCells: node.nodes?.length ?? 0,
    blockBorder: {
      borderColor: data && "borderColor" in data ? data.borderColor : void 0,
      borderWidth: data && "borderWidth" in data ? data.borderWidth : void 0,
      borderRadius: data && "borderRadius" in data ? data.borderRadius : void 0
    },
    cells: hasCellRenderData(type) ? jtdCells(node) : void 0
  };
};
//# sourceMappingURL=block-view-model.js.map
