import { TRANSPARENT_HEX_COLOR } from "./../../_shared/colors.js";
import { resolveSmartBlockCssColor } from "./resolve-smart-block-css-color.js";
import { getCellColorAttr } from "./variant-features.js";
const computeSmartBlockCellVars = (cellAttrs, themeSmartBlock, type, cellIndex, orientation = "HORIZONTAL") => {
  const colorAttr = getCellColorAttr(type);
  const backgroundColor = colorAttr === "backgroundColor" ? cellAttrs.backgroundColor ?? themeSmartBlock?.backgroundColor : cellAttrs.backgroundColor;
  const accentColor = colorAttr === "accentColor" ? cellAttrs.accentColor ?? themeSmartBlock?.accentColor : cellAttrs.accentColor;
  const borderColor = cellAttrs.borderColor ?? themeSmartBlock?.borderColor;
  const { borderWidth, borderRadius } = cellAttrs;
  const vars = {};
  if (backgroundColor && backgroundColor !== TRANSPARENT_HEX_COLOR) {
    const resolved = resolveSmartBlockCssColor(backgroundColor);
    if (resolved) {
      vars["--ricos-internal-sb-bg"] = resolved;
    }
  }
  if (accentColor) {
    if (accentColor === TRANSPARENT_HEX_COLOR) {
      vars["--ricos-internal-sb-accent"] = "transparent";
    } else {
      const resolved = resolveSmartBlockCssColor(accentColor);
      if (resolved) {
        vars["--ricos-internal-sb-accent"] = resolved;
        vars["--ricos-internal-sb-accent-opaque"] = resolved;
      }
    }
  }
  if (borderColor) {
    if (borderColor === TRANSPARENT_HEX_COLOR) {
      vars["--ricos-internal-sb-border-color"] = "transparent";
    } else {
      const resolved = resolveSmartBlockCssColor(borderColor);
      if (resolved) {
        vars["--ricos-internal-sb-border-color"] = resolved;
      }
    }
  }
  if (borderWidth && borderWidth > 0) {
    vars["--ricos-internal-sb-border-width"] = `${borderWidth}px`;
  }
  if (borderRadius && borderRadius > 0) {
    vars["--ricos-internal-sb-border-radius"] = `${borderRadius}px`;
  }
  const gridPlacement = type === "SOLID_BOXES_ALTERNATING" ? getCheckerboardGridStyle(cellIndex, orientation) : type === "TIMELINE" || type === "MINIMAL_TIMELINE" ? getTimelineGridStyle(cellIndex, orientation) : (
    // PYRAMID and VERTICAL_FUNNEL drive their clip-path and centroid
    // math from `--ricos-internal-sb-cell-index`; the formulas differ
    // per-variant in SCSS but both need the same per-cell index.
    type === "PYRAMID" || type === "VERTICAL_FUNNEL" ? { "--ricos-internal-sb-cell-index": `${cellIndex}` } : void 0
  );
  if (type === "STAIRCASE") {
    vars["--ricos-internal-sb-cell-index"] = `${cellIndex}`;
  }
  return { ...vars, ...gridPlacement };
};
const getCheckerboardGridStyle = (cellIndex, orientation = "HORIZONTAL") => {
  if (orientation === "VERTICAL") {
    const row = cellIndex + 1;
    const col = cellIndex % 2 === 0 ? 1 : 2;
    return {
      "--ricos-internal-sb-grid-col": `${col}`,
      "--ricos-internal-sb-grid-row": `${row}`
    };
  }
  return {
    "--ricos-internal-sb-grid-col": `${cellIndex + 1}`,
    "--ricos-internal-sb-grid-row": `${cellIndex % 2 === 0 ? 1 : 2}`
  };
};
const getTimelineGridStyle = (cellIndex, orientation = "HORIZONTAL") => {
  if (orientation === "VERTICAL") {
    return {
      "--ricos-internal-sb-grid-col": cellIndex % 2 === 0 ? "1" : "2",
      "--ricos-internal-sb-grid-row": `${cellIndex + 1}`
    };
  }
  return {
    "--ricos-internal-sb-grid-col": `${2 * cellIndex + 1}`,
    "--ricos-internal-sb-grid-row": `${cellIndex % 2 === 0 ? 1 : 2}`
  };
};
export {
  computeSmartBlockCellVars
};
//# sourceMappingURL=compute-cell-css-vars.js.map
