import {
  Node_Type
} from "./../../ricos-schema/next-schema/index.js";
import { Decoration_Type } from "./../../ricos-types/index.js";
import { PmNodeType } from "./../../_shared/pm-node-types.js";
const nullToUndef = (value) => value === null || value === void 0 ? void 0 : value;
const pmCellToViewModel = (pmNode, parent) => {
  const attrs = pmNode.attrs;
  const { type } = parent;
  return {
    type,
    cellIndex: parent.cellIndex,
    totalCells: parent.totalCells,
    columnSize: parent.columnSize,
    orientation: parent.orientation,
    isShapesMode: parent.isShapesMode,
    cellId: attrs.id,
    cellColors: {
      accentColor: nullToUndef(attrs.accentColor),
      backgroundColor: nullToUndef(attrs.backgroundColor),
      borderColor: nullToUndef(attrs.borderColor),
      borderWidth: nullToUndef(attrs.borderWidth),
      borderRadius: nullToUndef(attrs.borderRadius)
    },
    shape: nullToUndef(attrs.shape),
    shapeColor: nullToUndef(attrs.shapeColor),
    label: attrs.label ?? null,
    contentStyle: getPmCellContentStyle(pmNode, type)
  };
};
const getPmCellContentStyle = (pmNode, type) => {
  if (type !== "SMALL_BULLETS") {
    return {};
  }
  const firstBlock = pmNode.firstChild;
  if (!firstBlock) {
    return {};
  }
  const headingLevel = firstBlock.type.name === PmNodeType.HEADING ? firstBlock.attrs.level : void 0;
  const fontSize = firstBlock.firstChild?.marks.find((m) => m.type.name === Decoration_Type.FONT_SIZE)?.attrs.value;
  return { fontSize, headingLevel };
};
const ricosCellToViewModel = (cellNode, parent) => {
  const cellData = cellNode.smartBlockCellData;
  const { type } = parent;
  const label = cellData && "label" in cellData ? cellData.label ?? null : null;
  return {
    type,
    cellIndex: parent.cellIndex,
    totalCells: parent.totalCells,
    columnSize: parent.columnSize,
    orientation: parent.orientation,
    isShapesMode: parent.isShapesMode,
    cellId: cellNode.id,
    cellColors: {
      accentColor: cellData && "accentColor" in cellData ? cellData.accentColor : void 0,
      backgroundColor: cellData && "backgroundColor" in cellData ? cellData.backgroundColor : void 0,
      borderColor: cellData && "borderColor" in cellData ? cellData.borderColor : void 0,
      borderWidth: cellData && "borderWidth" in cellData ? cellData.borderWidth : void 0,
      borderRadius: cellData && "borderRadius" in cellData ? cellData.borderRadius : void 0
    },
    shape: cellData && "shape" in cellData ? cellData.shape : void 0,
    shapeColor: cellData && "shapeColor" in cellData ? cellData.shapeColor : void 0,
    label,
    contentStyle: getRicosCellContentStyle(cellNode, type)
  };
};
const getRicosCellContentStyle = (cellNode, type) => {
  if (type !== "SMALL_BULLETS") {
    return {};
  }
  const firstChild = cellNode.nodes?.[0];
  if (!firstChild) {
    return {};
  }
  const headingLevel = firstChild.type === Node_Type.HEADING ? firstChild.headingData?.level ?? void 0 : void 0;
  const firstInline = firstChild.nodes?.[0];
  const fontSize = firstInline && "textData" in firstInline ? firstInline.textData?.decorations?.find((d) => d.type === Decoration_Type.FONT_SIZE)?.fontSizeData?.value : void 0;
  return { fontSize, headingLevel };
};
export {
  pmCellToViewModel,
  ricosCellToViewModel
};
//# sourceMappingURL=cell-view-model.js.map
