/**
 * util/banner.mjs — Aperant install masthead.
 *
 * Prints the APERANT wordmark in the brand's antique-gold palette
 * (#C5A94E and siblings from dove-banner.svg) above the clack
 * multiselect. We use the `ANSI Shadow` figlet shape — same style
 * GSD uses — because it's the most legible at 58 cols and degrades
 * cleanly when copy-pasted (all chars are in the Unicode Box Drawing
 * and Block Elements ranges, no emoji).
 *
 * Honors NO_COLOR (https://no-color.org) and falls back to plain
 * text when stdout is not a TTY so piped output stays parseable.
 */

/** ANSI 256 gold — closest preset to #C5A94E without needing truecolor. */
const GOLD = '\x1b[38;5;178m'
/** Dimmer gold for subtitle text. */
const GOLD_DIM = '\x1b[38;5;136m'
const RESET = '\x1b[0m'

/** Six-row ANSI-Shadow wordmark. Exactly one leading space per row. */
const APERANT_LINES = [
	' █████╗ ██████╗ ███████╗██████╗  █████╗ ███╗   ██╗████████╗',
	'██╔══██╗██╔══██╗██╔════╝██╔══██╗██╔══██╗████╗  ██║╚══██╔══╝',
	'███████║██████╔╝█████╗  ██████╔╝███████║██╔██╗ ██║   ██║   ',
	'██╔══██║██╔═══╝ ██╔══╝  ██╔══██╗██╔══██║██║╚██╗██║   ██║   ',
	'██║  ██║██║     ███████╗██║  ██║██║  ██║██║ ╚████║   ██║   ',
	'╚═╝  ╚═╝╚═╝     ╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝   ',
]

/**
 * Whether to emit ANSI color escape codes.
 * @returns {boolean}
 */
function colorsEnabled() {
	if (process.env.NO_COLOR) return false
	if (!process.stdout.isTTY) return false
	return true
}

/**
 * Render the install masthead as a single multi-line string suitable
 * for clack.intro(). Includes version + tagline.
 *
 * @param {string} version  Framework semver (e.g. "0.1.4").
 * @returns {string}
 */
export function aperantBanner(version) {
	const color = colorsEnabled()
	const gold = color ? GOLD : ''
	const dim = color ? GOLD_DIM : ''
	const reset = color ? RESET : ''

	const lines = APERANT_LINES.map((l) => `${gold}${l}${reset}`).join('\n')
	const tagline = `${dim}framework v${version} · AI coding for the full lifecycle${reset}`
	return `${lines}\n\n${tagline}`
}
