/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { yellow } from "./colors.js";
import { print } from "./print.js";

//#region ../cli/dist/lib/box.mjs
/*! © 2026 Yahoo, Inc. UDS CLI v0.0.0-development */
/**
* Strips ANSI escape codes from a string to get the visible character length.
*/
function stripAnsi(str) {
	return str.replace(/\x1b\[[0-9;]*m/g, "");
}
/**
* Prints lines inside a bordered box, similar to npm/turbo update notifications.
*
* Example output:
* ╭──────────────────────────────────────────────────────╮
* │                                                      │
* │   Updated UDS rules are available for Cursor and     │
* │   Claude Code. Run `uds editor-rules` to update.     │
* │                                                      │
* ╰──────────────────────────────────────────────────────╯
*/
function printBox(lines) {
	const padding = 3;
	const innerWidth = Math.max(...lines.map((l) => stripAnsi(l).length)) + padding * 2;
	const top = yellow(`╭${"─".repeat(innerWidth)}╮`);
	const bottom = yellow(`╰${"─".repeat(innerWidth)}╯`);
	const emptyLine = yellow("│") + " ".repeat(innerWidth) + yellow("│");
	print("");
	print(top);
	print(emptyLine);
	for (const line of lines) {
		const visibleLength = stripAnsi(line).length;
		const rightPad = innerWidth - padding - visibleLength;
		print(yellow("│") + " ".repeat(padding) + line + " ".repeat(rightPad) + yellow("│"));
	}
	print(emptyLine);
	print(bottom);
	print("");
}

//#endregion
export { printBox };