// src/actions/dead/reporters.ts
import chalk from "chalk";
function groupBy(items, keyFn) {
  const out = /* @__PURE__ */ new Map();
  for (const item of items) {
    const key = keyFn(item);
    let bucket = out.get(key);
    if (!bucket) {
      bucket = [];
      out.set(key, bucket);
    }
    bucket.push(item);
  }
  return out;
}
function kindLabel(kind) {
  return kind === "unused-local" ? "unused-local" : "unused-export";
}
function renderHuman(result) {
  if (result.findings.length === 0) {
    console.log(chalk.green(`Dead Code: no findings (${result.summary.scannedFiles} files in ${result.summary.scannedPackages} package${result.summary.scannedPackages === 1 ? "" : "s"})`));
    return;
  }
  const byPkg = groupBy(result.findings, (f) => f.pkg);
  for (const [pkg, findings] of byPkg) {
    console.log(chalk.green(`Dead Code [${pkg}]`));
    findings.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column);
    for (const f of findings) {
      const loc = `${f.file}:${f.line}:${f.column}`;
      const kind = chalk.yellow(kindLabel(f.kind).padEnd(13));
      const detail = f.detail ? chalk.gray(`  (${f.detail})`) : "";
      console.log(`  ${loc.padEnd(40)} ${kind} ${f.symbol}${detail}`);
    }
  }
  const localCount = result.findings.filter((f) => f.kind === "unused-local").length;
  const exportCount = result.findings.filter((f) => f.kind === "unused-export").length;
  console.log(chalk.gray(`
  scanned ${result.summary.scannedFiles} files in ${result.summary.scannedPackages} package${result.summary.scannedPackages === 1 ? "" : "s"}`));
  const parts = [];
  if (localCount > 0) parts.push(`${localCount} unused local${localCount === 1 ? "" : "s"}`);
  if (exportCount > 0) parts.push(`${exportCount} unused export${exportCount === 1 ? "" : "s"}`);
  if (parts.length > 0) console.log(chalk.yellow(`  ${parts.join(", ")}`));
}
function getDeadReporter(format) {
  if (format === "json") {
    return {
      render(result) {
        console.log(JSON.stringify(result, null, 2));
      }
    };
  }
  return { render: renderHuman };
}
export {
  getDeadReporter
};
//# sourceMappingURL=reporters.mjs.map
