// Copyright (c) 2026 defconxt. All rights reserved.
// Licensed under AGPL-3.0 — see LICENSE file for details.

/**
 * NERF branding — ASCII art, status indicators, formatted output.
 */

// ANSI colors
const R = '\x1b[0m';     // reset
const B = '\x1b[1m';     // bold
const D = '\x1b[2m';     // dim
const RED = '\x1b[31m';
const GRN = '\x1b[32m';
const YLW = '\x1b[33m';
const BLU = '\x1b[34m';
const MAG = '\x1b[35m';
const CYN = '\x1b[36m';

const LOGO = `${CYN}${B}
   ██████╗██╗██████╗ ██╗  ██╗███████╗██████╗
  ██╔════╝██║██╔══██╗██║  ██║██╔════╝██╔══██╗
  ██║     ██║██████╔╝███████║█████╗  ██████╔╝
  ██║     ██║██╔═══╝ ██╔══██║██╔══╝  ██╔══██╗
  ╚██████╗██║██║     ██║  ██║███████╗██║  ██║
   ╚═════╝╚═╝╚═╝     ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝${R}`;

const LOGO_SMALL = `${CYN}${B}▸ NERF${R}`;

/** Status indicator dots */
export const dot = {
  ok:   `${GRN}●${R}`,
  warn: `${YLW}●${R}`,
  fail: `${RED}●${R}`,
  info: `${BLU}●${R}`,
  skip: `${D}○${R}`,
};

/** Print the full ASCII banner with version */
export function banner(version = '') {
  const ver = version ? `${D}v${version}${R}` : '';
  process.stderr.write(`${LOGO}\n  ${D}Claude Integrated Privacy & Hardening Expert Resource${R}  ${ver}\n\n`);
}

/** Print a compact one-line header */
export function header(text, version = '') {
  const ver = version ? ` ${D}v${version}${R}` : '';
  process.stderr.write(`${LOGO_SMALL}${ver} ${D}—${R} ${text}\n`);
}

/** Print a status line with colored dot */
export function status(name, state, detail = '') {
  const d = dot[state] || dot.info;
  const detailStr = detail ? ` ${D}${detail}${R}` : '';
  process.stderr.write(`  ${d} ${name}${detailStr}\n`);
}

/** Print a section divider */
export function divider() {
  process.stderr.write(`${D}${'─'.repeat(50)}${R}\n`);
}

/** Print a success message */
export function success(msg) {
  process.stderr.write(`  ${GRN}✔${R} ${msg}\n`);
}

/** Print a warning message */
export function warn(msg) {
  process.stderr.write(`  ${YLW}⚠${R} ${msg}\n`);
}

/** Print an error message */
export function error(msg) {
  process.stderr.write(`  ${RED}✖${R} ${msg}\n`);
}

/** Print an info message */
export function info(msg) {
  process.stderr.write(`  ${BLU}ℹ${R} ${msg}\n`);
}

/**
 * Format doctor checks with status dots.
 * @param {object[]} checks - Array of {name, status, detail}
 * @returns {string} Formatted output for terminal
 */
export function formatDoctorChecks(checks) {
  const lines = [];
  for (const c of checks) {
    const state = c.status === 'ok' ? 'ok' : c.status === 'optional' ? 'skip' : c.status === 'missing' ? 'fail' : 'warn';
    const d = dot[state];
    lines.push(`  ${d} ${B}${c.name}${R}  ${D}${c.detail}${R}`);
  }
  return lines.join('\n');
}

/**
 * Format version output.
 * @param {string} version
 */
export function formatVersion(version) {
  return `${LOGO_SMALL} ${B}${version}${R}`;
}

export { LOGO, LOGO_SMALL, R, B, D, RED, GRN, YLW, BLU, MAG, CYN };
