import { colors } from "../../utils/colors.js";
//#region src/cli/commands/doctor/format.ts
const STATUS_ICONS = {
	pass: "✓",
	warn: "⚠",
	fail: "✗",
	skip: "–"
};
function statusColor(status, text) {
	switch (status) {
		case "pass": return colors.green(text);
		case "warn": return colors.yellow(text);
		case "fail": return colors.red(text);
		default: return colors.gray(text);
	}
}
function formatCheckLine(result) {
	const icon = STATUS_ICONS[result.status];
	const fixed = result.fixed ? " " + colors.cyan("[fixed]") : "";
	return `  ${statusColor(result.status, icon)} ${result.label}: ${result.message}${fixed}`;
}
function formatHints(hints) {
	return hints.map((h) => `    ${colors.gray("→")} ${h}`);
}
function printSummary(results) {
	const passed = results.filter((r) => r.status === "pass").length;
	const warnings = results.filter((r) => r.status === "warn").length;
	const failed = results.filter((r) => r.status === "fail").length;
	const skipped = results.filter((r) => r.status === "skip").length;
	console.log("");
	console.log(colors.bold(`${passed} passed, ${warnings} warnings, ${failed} failed` + (skipped ? `, ${skipped} skipped` : "")));
}
function printResults(results, opts) {
	console.log("");
	console.log(colors.bold(opts?.security ? "xopc doctor --security" : "xopc doctor"));
	console.log("");
	for (const r of results) {
		console.log(formatCheckLine(r));
		if (opts?.security && r.findings?.length) for (const finding of r.findings) {
			const icon = finding.severity === "critical" ? "✗" : finding.severity === "warn" ? "⚠" : "·";
			const colored = statusColor(finding.severity === "critical" ? "fail" : finding.severity === "warn" ? "warn" : "pass", icon);
			console.log(`    ${colored} ${colors.bold(finding.checkId)} ${finding.title}`);
			console.log(`      ${colors.gray(finding.detail)}`);
			if (finding.remediation) console.log(`      ${colors.gray("→")} ${finding.remediation}`);
		}
		else for (const line of formatHints(r.hints)) console.log(line);
	}
	printSummary(results);
	console.log("");
}
function printJsonResults(results) {
	const payload = {
		ok: results.every((r) => r.status !== "fail"),
		checks: results.map((r) => ({
			id: r.id,
			label: r.label,
			status: r.status,
			message: r.message,
			hints: r.hints,
			fixed: r.fixed ?? false,
			...r.findings ? { findings: r.findings } : {}
		}))
	};
	console.log(JSON.stringify(payload, null, 2));
}
//#endregion
export { formatCheckLine, formatHints, printJsonResults, printResults, printSummary };

//# sourceMappingURL=format.js.map