export interface TableMinWidthOptions {
  columnKeys: string[];
  widths: Record<string, number | undefined>;
  fallbackWidth?: number;
  fixedWidths?: number[];
  ignoredKeys?: string[];
}

export function computeTableMinWidth({
  columnKeys,
  widths,
  fallbackWidth = 120,
  fixedWidths = [],
  ignoredKeys = [],
}: TableMinWidthOptions) {
  const ignoredKeySet = new Set(ignoredKeys);
  const fixedWidth = fixedWidths.reduce((sum, width) => sum + width, 0);
  const columnsWidth = columnKeys.reduce((sum, key) => {
    if (ignoredKeySet.has(key)) {
      return sum;
    }

    return sum + (widths[key] ?? fallbackWidth);
  }, 0);

  return fixedWidth + columnsWidth;
}