import { MAX_COLUMNS, MIN_COL_SPAN } from "./../../ricos-common-plugins/layout/shared-with-viewer.js";
const getNormalizedColSpans = (cellsColSpans) => {
  const totalColSpans = cellsColSpans.reduce((sum, colSpan) => sum + colSpan, 0);
  const allCellsValid = cellsColSpans.every((colSpan) => colSpan >= MIN_COL_SPAN);
  if (totalColSpans === MAX_COLUMNS && allCellsValid) {
    return cellsColSpans;
  }
  let remainingColumns = MAX_COLUMNS - totalColSpans;
  const cellsWithoutColSpan = cellsColSpans.filter((colSpan) => colSpan === 0);
  const canUseColSpan = totalColSpans <= MAX_COLUMNS && remainingColumns / cellsWithoutColSpan.length >= MIN_COL_SPAN;
  const defaultColSpan = Math.floor(MAX_COLUMNS / cellsColSpans.length);
  return cellsColSpans.map((oldColSpan, index) => {
    let colSpan = defaultColSpan;
    if (canUseColSpan) {
      if (oldColSpan) {
        colSpan = oldColSpan;
      } else if (index === cellsColSpans.length - 1) {
        colSpan = remainingColumns;
      } else {
        colSpan = defaultColSpan;
        remainingColumns -= defaultColSpan;
      }
    }
    return colSpan;
  });
};
export {
  getNormalizedColSpans
};
//# sourceMappingURL=get-normalized-col-spans.js.map
