// src/lib/updo/renderTable.ts
import chalk from "chalk";
import semver from "semver";
function versionColor(version, current) {
  if (!version || !current) return chalk.gray(version ?? "-");
  if (version === current) return chalk.gray(version);
  const diff = semver.diff(current, version);
  if (diff === "major" || diff === "premajor") return chalk.red(version);
  if (diff === "minor" || diff === "preminor") return chalk.yellow(version);
  return chalk.green(version);
}
var columns = [
  {
    color: (_v, dep) => dep.updateAvailable ? chalk.white(dep.name) : chalk.gray(dep.name),
    header: "Package",
    value: (dep) => dep.name
  },
  {
    color: (_v, dep) => chalk.gray(dep.current ?? "-"),
    header: "Current",
    value: (dep) => dep.current ?? "-"
  },
  {
    color: (_v, dep) => versionColor(dep.wanted, dep.current),
    header: "Wanted",
    value: (dep) => dep.wanted ?? "-"
  },
  {
    color: (_v, dep) => versionColor(dep.latest, dep.current),
    header: "Latest",
    value: (dep) => dep.latest ?? "-"
  },
  {
    color: (_v, dep) => versionColor(dep.next, dep.current),
    header: "Next/RC",
    value: (dep) => dep.next ?? "-"
  },
  {
    color: (_v, dep) => chalk.gray(dep.depTypes.join(", ")),
    header: "Type",
    value: (dep) => dep.depTypes.join(", ")
  }
];
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(raw, 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