/**
 * ASCII art and branding utilities for Nexus Prime
 */
const SCI_FI_LOADER_FRAMES = [
    '⠋ orbiting quantum nodes',
    '⠙ orbiting quantum nodes',
    '⠹ orbiting quantum nodes',
    '⠸ orbiting quantum nodes',
    '⠼ orbiting quantum nodes',
    '⠴ orbiting quantum nodes',
    '⠦ orbiting quantum nodes',
    '⠧ orbiting quantum nodes',
    '⠇ orbiting quantum nodes',
    '⠏ orbiting quantum nodes',
];
export const ASCII_ART = {
    nexusPrimeLogo: `
    ███╗   ██╗███████╗██╗  ██╗██╗   ██╗███████╗
    ████╗  ██║██╔════╝╚██╗██╔╝██║   ██║██╔════╝
    ██╔██╗ ██║█████╗   ╚███╔╝ ██║   ██║███████╗
    ██║╚██╗██║██╔══╝   ██╔██╗ ██║   ██║╚════██║
    ██║ ╚████║███████╗██╔╝ ██╗╚██████╔╝███████║
    ╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝

    ██████╗ ██████╗ ██╗███╗   ███╗███████╗
    ██╔══██╗██╔══██╗██║████╗ ████║██╔════╝
    ██████╔╝██████╔╝██║██╔████╔██║█████╗
    ██╔═══╝ ██╔══██╗██║██║╚██╔╝██║██╔══╝
    ██║     ██║  ██║██║██║ ╚═╝ ██║███████╗
    ╚═╝     ╚═╝  ╚═╝╚═╝╚═╝     ╚═╝╚══════╝`,
    nexusPrimeLogoCompact: `
    _   _ _____  __   __ _   _  ____   ____   ___  __  __ _____
   | \\ | | ____| \\ \\ / /| | | |/ ___| |  _ \\ |_ _||  \\/  | ____|
   |  \\| |  _|    \\ V / | | | |\\___ \\ | |_) | | | | |\\/| |  _|
   | |\\  | |___    | |  | |_| | ___) ||  _ <  | | | |  | | |___
   |_| \\_|_____|   |_|   \\___/ |____/ |_| \\_\\|___||_|  |_|_____|`,
    sciFiLoaderFrames: SCI_FI_LOADER_FRAMES,
    sciFiLoaderFrameRateMs: 90,
    sciFiLoader: (frame) => {
        const frames = SCI_FI_LOADER_FRAMES;
        return frames[Math.abs(frame) % frames.length];
    },
    bootSuccessMessage: (version, buildMeta = {}) => {
        const buildDate = buildMeta.buildDate || new Date().toISOString();
        const nodeVersion = buildMeta.nodeVersion || process.version;
        const platform = buildMeta.platform || `${process.platform}/${process.arch}`;
        return `
  ╔════════════════════════════════════════════════════════════╗
  ║  ⚡ Nexus Prime v${version} Ready                               ║
  ║                                                            ║
  ║  🧠 Memory fabric initialized                              ║
  ║  🔄 Orchestration engines live                             ║
  ║  📡 MCP control plane active                               ║
  ║  ⚙️  Worker swarm standing by                              ║
  ║  Dashboard: http://localhost:3377                          ║
  ║  Open later: nexus-prime start                              ║
  ║                                                            ║
  ║  Build: ${buildDate.slice(0, 19).padEnd(47, ' ')}║
  ║  Node : ${nodeVersion.padEnd(47, ' ')}║
  ║  Host : ${platform.padEnd(47, ' ')}║
  ╚════════════════════════════════════════════════════════════╝`;
    },
};
function selectLogoForTerminal() {
    const columns = Number(process.stdout.columns || 0);
    if (columns > 0 && columns < 90) {
        return ASCII_ART.nexusPrimeLogoCompact;
    }
    return ASCII_ART.nexusPrimeLogo;
}
export function installationProgressBar(step, total, label) {
    const safeTotal = Math.max(1, total);
    const safeStep = Math.max(0, Math.min(step, safeTotal));
    const width = 24;
    const ratio = safeStep / safeTotal;
    const filled = Math.round(width * ratio);
    const bar = `${'█'.repeat(filled)}${'░'.repeat(Math.max(0, width - filled))}`;
    const pct = Math.round(ratio * 100);
    return `\r\x1b[36m[${bar}]\x1b[0m ${String(pct).padStart(3, ' ')}% ${label}`;
}
export function sciFiPhaseHeader(phaseName, phaseNumber) {
    const title = `PHASE ${phaseNumber} :: ${phaseName.toUpperCase()}`;
    const pad = '═'.repeat(Math.max(0, 68 - title.length));
    return [
        `\x1b[35m╔═ ${title} ${pad}╗\x1b[0m`,
        `\x1b[35m╚${'═'.repeat(74)}╝\x1b[0m`,
    ].join('\n');
}
export function nexusPrimeSubBrand(subtitle) {
    const text = subtitle.trim() || 'Nexus Prime';
    const edge = '─'.repeat(Math.max(8, text.length + 8));
    return [
        `\x1b[90m┌${edge}┐\x1b[0m`,
        `\x1b[90m│\x1b[0m  \x1b[36m${text}\x1b[0m  \x1b[90m│\x1b[0m`,
        `\x1b[90m└${edge}┘\x1b[0m`,
    ].join('\n');
}
export function printASCIILogo(version) {
    console.log('\n');
    console.log(selectLogoForTerminal());
    console.log(`\n  Local-first MCP control plane v${version}`);
    console.log('  Bootstrap. Orchestrate. Verify. Learn.\n');
}
/** @deprecated Prefer category-aware MCP visuals inside src/agents/adapters/mcp.ts */
export function printSciFiMCPInvoke(toolName) {
    console.log(nexusPrimeSubBrand(`MCP invoke: ${toolName}`));
}
export function printBootSuccessMessage(version, buildMeta = {}) {
    console.log(ASCII_ART.bootSuccessMessage(version, buildMeta));
}
// ─── Install boot sequence ────────────────────────────────────────────────────
const ANSI = {
    cyan: '\x1b[36m',
    green: '\x1b[32m',
    yellow: '\x1b[33m',
    red: '\x1b[31m',
    dim: '\x1b[2m',
    bold: '\x1b[1m',
    reset: '\x1b[0m',
};
function color(s, c) {
    if (!process.stdout.isTTY || process.env.NO_COLOR)
        return s;
    return `${ANSI[c]}${s}${ANSI.reset}`;
}
const INSTALL_BOOT_STEPS = [
    { tag: 'BOOT ', label: 'Initializing quantum memory substrate' },
    { tag: 'LINK ', label: 'Establishing MCP neural bridge' },
    { tag: 'SYNC ', label: 'Loading knowledge fabric' },
    { tag: 'VERI ', label: 'Verifying control plane integrity' },
    { tag: 'READY', label: 'Control plane online' },
];
/** Animated install boot sequence. Non-TTY mode prints static lines. */
export async function runInstallBootSequence(version) {
    const isTTY = process.stdout.isTTY === true;
    const sleep = (ms) => new Promise(r => setTimeout(r, ms));
    // Print logo border + title
    const border = '═'.repeat(62);
    process.stdout.write(color(`╔${border}╗\n`, 'cyan'));
    const logo = selectLogoForTerminal().trimStart();
    for (const line of logo.split('\n')) {
        process.stdout.write(color(`  ${line}\n`, 'cyan'));
    }
    process.stdout.write(color(`\n  P R I M E  ·  C O N T R O L  P L A N E  v${version}\n`, 'bold'));
    process.stdout.write(color(`╚${border}╝\n\n`, 'cyan'));
    for (let i = 0; i < INSTALL_BOOT_STEPS.length; i++) {
        const step = INSTALL_BOOT_STEPS[i];
        const isLast = i === INSTALL_BOOT_STEPS.length - 1;
        const barWidth = 28;
        if (isTTY && !isLast) {
            // Animate progress bar
            for (let f = 0; f <= barWidth; f++) {
                const filled = '█'.repeat(f);
                const empty = '░'.repeat(barWidth - f);
                const tagColored = color(`[${step.tag}]`, 'yellow');
                const line = `  ${tagColored}  ${step.label.padEnd(42, ' ')}  ${color(filled + empty, 'cyan')}\r`;
                process.stdout.write(line);
                await sleep(18);
            }
        }
        // Final settled line for this step
        const bar = '█'.repeat(barWidth);
        const tagColor = isLast ? 'green' : 'cyan';
        const tagStr = isLast
            ? color(`[${step.tag}]`, 'green')
            : color(`[${step.tag}]`, 'cyan');
        const checkOrBar = isLast ? color('  ✓', 'green') : color(`  ${bar}`, 'cyan');
        process.stdout.write(`  ${tagStr}  ${step.label.padEnd(42, ' ')}${checkOrBar}\n`);
        if (!isLast && isTTY)
            await sleep(120);
    }
    process.stdout.write('\n');
}
