"use strict";

const pc = require("picocolors");

const EVOLV_ORANGE_RGB = [209, 86, 53]; // #D15635

/**
 * Render text in evolv brand orange with truecolor → 256-color → yellow fallback.
 * Returns plain text when color is not supported (NO_COLOR, TERM=dumb, non-TTY).
 */
function evolvOrange(text) {
  if (!pc.isColorSupported) return text;
  if (
    process.env.COLORTERM === "truecolor" ||
    process.env.COLORTERM === "24bit"
  ) {
    return `\x1b[38;2;209;86;53m${text}\x1b[0m`;
  }
  if (process.env.TERM && process.env.TERM.includes("256color")) {
    return `\x1b[38;5;166m${text}\x1b[0m`;
  }
  return `\x1b[33m${text}\x1b[0m`;
}

module.exports = {
  // Brand
  brand: evolvOrange,

  // Semantic states
  success: pc.green,
  error: pc.red,
  warning: pc.yellow,
  info: pc.cyan,
  dim: pc.dim,
  bold: pc.bold,
  reset: pc.reset,

  // Status symbols (plain ASCII, color applied by caller)
  symbols: {
    active: "[*]",
    complete: "[x]",
    error: "[!]",
    skip: "[-]",
    progress: "[>]",
    pending: "[ ]",
  },

  // Box-drawing characters — installer UI only (bin/ui modules).
  // NOT for skill output. Skills use clean text headers per ADR-015.
  box: {
    tl: "\u250c",
    tr: "\u2510",
    bl: "\u2514",
    br: "\u2518",
    h: "\u2500",
    v: "\u2502",
  },

  // ANSI helpers
  /** Strip ANSI escape sequences from a string. */
  stripAnsi(str) {
    // eslint-disable-next-line no-control-regex
    return str.replace(/\x1b\[[0-9;]*m/g, "");
  },

  // Detection helpers
  isColorSupported: pc.isColorSupported,
  EVOLV_ORANGE_RGB,
};
