"use strict";
// src/cli/MatrixTheme.ts
// Visual theme for the OpenLife TUI suite — Matrix 2026 redesign.
// Lime green on black. Vanilla ANSI 256-color codes, no deps.
// Reference: Downloads/ChatGPT Image 15 de mai. de 2026, 13_58_20.png (OPENLIFE logo)
// Reference: Downloads/69e80715-...png                                (code rain)
Object.defineProperty(exports, "__esModule", { value: true });
exports.RAIN_CONFIG = exports.RAIN_GLYPHS = exports.MATRIX = exports.ANSI = void 0;
exports.moveTo = moveTo;
exports.colorize = colorize;
exports.center = center;
exports.supportsColor = supportsColor;
exports.stripAnsi = stripAnsi;
exports.paint = paint;
exports.ANSI = Object.freeze({
    reset: '\x1b[0m',
    bold: '\x1b[1m',
    dim: '\x1b[2m',
    italic: '\x1b[3m',
    hideCursor: '\x1b[?25l',
    showCursor: '\x1b[?25h',
    clearScreen: '\x1b[2J\x1b[H',
    clearLine: '\x1b[2K',
    save: '\x1b[s',
    restore: '\x1b[u',
});
// Matrix lime green palette — three brightness stops.
exports.MATRIX = Object.freeze({
    head: '\x1b[38;5;82m\x1b[1m', // bright lime — column head, banner, highlights
    body: '\x1b[38;5;46m', // canonical Matrix green — base text
    tail: '\x1b[38;5;22m\x1b[2m', // faded — rain tail, dividers, secondary text
    warn: '\x1b[38;5;226m', // yellow — caution
    err: '\x1b[38;5;196m', // red — errors
    white: '\x1b[38;5;231m', // pure white — accents only
});
// Glyph set for the Matrix rain — digits + half-width katakana + a few symbols.
// Half-width kana mimics the original Matrix film aesthetic while staying
// 1 column wide in any terminal font (full-width kana would break alignment).
exports.RAIN_GLYPHS = ('0123456789' +
    'ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜﾝ' +
    '*+-/:.<>=#$%@').split('');
// Rain timing — 80ms tick matches the reference (~12fps), low enough CPU.
exports.RAIN_CONFIG = Object.freeze({
    tickMs: 80,
    trailMin: 6,
    trailMax: 18,
    spawnChance: 0.15, // probability a new column starts each tick
    glyphMutate: 0.08, // probability a mid-trail glyph swaps for noise
});
// Cursor positioning helpers (1-indexed, ANSI convention).
function moveTo(row, col) {
    return `\x1b[${row};${col}H`;
}
function colorize(text, color) {
    return `${color}${text}${exports.ANSI.reset}`;
}
// Centered line padded to a given width with spaces.
function center(text, width) {
    if (text.length >= width)
        return text;
    const pad = Math.floor((width - text.length) / 2);
    return ' '.repeat(pad) + text;
}
// Detect whether stdout supports the 256-color theme.
// Conservative: requires TTY + non-dumb TERM. CI/pipes get plain output.
function supportsColor() {
    if (process.env.NO_COLOR)
        return false;
    if (process.env.FORCE_COLOR)
        return true;
    if (!process.stdout.isTTY)
        return false;
    const term = (process.env.TERM || '').toLowerCase();
    if (!term || term === 'dumb')
        return false;
    return true;
}
// Strip ANSI from a string — for tests and non-TTY rendering paths.
function stripAnsi(s) {
    // Covers SGR, cursor moves, save/restore, screen clears. Good enough for tests.
    return s.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '');
}
// Conditional wrapper — applies color only when terminal supports it.
function paint(text, color) {
    return supportsColor() ? `${color}${text}${exports.ANSI.reset}` : text;
}
