// src/lib/updo/renderTable.ts
import chalk from "chalk";
var ORANGE = chalk.hex("#ff8800");
function classify(prefix, column, hasValue) {
  if (!hasValue) return chalk.gray;
  if (column === "next") return ORANGE;
  if (prefix === "^") {
    if (column === "major") return chalk.yellow;
    return chalk.green;
  }
  if (prefix === "~") {
    if (column === "patch") return chalk.green;
    if (column === "minor") return chalk.yellow;
    return chalk.red;
  }
  if (column === "patch") return chalk.yellow;
  return chalk.red;
}
function bucketValue(column, dep) {
  if (column === "patch") return dep.patch;
  if (column === "minor") return dep.minor;
  if (column === "major") return dep.major;
  return dep.next;
}
function bucketCell(column, dep) {
  const value = bucketValue(column, dep);
  const raw = value ?? "-";
  return classify(dep.preferredRangePrefix, column, value != null && value.length > 0)(raw);
}
var columns = [
  {
    color: (dep) => {
      if (dep.updateAvailable) return chalk.white(dep.name);
      return chalk.gray(dep.name);
    },
    header: "Package",
    value: (dep) => dep.name
  },
  {
    color: (dep) => chalk.gray(dep.current),
    header: "Current",
    value: (dep) => dep.current
  },
  {
    color: (dep) => bucketCell("patch", dep),
    header: "Patch",
    value: (dep) => dep.patch ?? "-"
  },
  {
    color: (dep) => bucketCell("minor", dep),
    header: "Minor",
    value: (dep) => dep.minor ?? "-"
  },
  {
    color: (dep) => bucketCell("major", dep),
    header: "Major",
    value: (dep) => dep.major ?? "-"
  },
  {
    color: (dep) => bucketCell("next", dep),
    header: "Next",
    value: (dep) => dep.next ?? "-"
  },
  {
    color: (dep) => chalk.gray(String(dep.workspaces.length)),
    header: "Packages",
    value: (dep) => String(dep.workspaces.length)
  }
];
function renderTable(deps) {
  const updatable = deps.filter((d) => d.updateAvailable);
  if (updatable.length === 0) {
    console.log(chalk.green("\nAll packages are up to date!"));
    return;
  }
  const widths = columns.map((col) => {
    let maxData = 0;
    for (const dep of updatable) {
      maxData = Math.max(maxData, col.value(dep).length);
    }
    return Math.max(col.header.length, maxData);
  });
  const header = columns.map((col, i) => chalk.bold(col.header.padEnd(widths[i]))).join("  ");
  console.log(`
${header}`);
  let totalWidth = -2;
  for (const w of widths) {
    totalWidth += w + 2;
  }
  console.log(chalk.gray("\u2500".repeat(totalWidth)));
  for (const dep of updatable) {
    const row = columns.map((col, i) => {
      const raw = col.value(dep);
      const colored = col.color(dep);
      const padding = widths[i] - raw.length;
      return colored + " ".repeat(Math.max(0, padding));
    }).join("  ");
    console.log(row);
  }
  console.log();
}
export {
  renderTable
};
//# sourceMappingURL=renderTable.mjs.map
