import * as pc from "picocolors";

/**
 * Consistent theme for Harmony MCP TUI
 * Uses picocolors for lightweight color output
 */

// Brand colors and symbols
export const symbols = {
  harmony: "\u25B2", // Triangle for Harmony logo
  check: "\u2713",
  cross: "\u2717",
  bullet: "\u2022",
  arrow: "\u2192",
  arrowRight: "\u25B8",
  dot: "\u25CF",
  dotEmpty: "\u25CB",
  info: "\u2139",
  warning: "\u26A0",
  pointer: "\u276F",
};

// Color functions
export const colors = {
  // Brand
  brand: (text: string) => pc.cyan(text),
  brandBold: (text: string) => pc.bold(pc.cyan(text)),

  // Status
  success: (text: string) => pc.green(text),
  error: (text: string) => pc.red(text),
  warning: (text: string) => pc.yellow(text),
  info: (text: string) => pc.blue(text),

  // Text
  dim: (text: string) => pc.dim(text),
  bold: (text: string) => pc.bold(text),
  muted: (text: string) => pc.gray(text),

  // Highlights
  highlight: (text: string) => pc.cyan(text),
  link: (text: string) => pc.underline(pc.cyan(text)),
};

// Styled messages
export const messages = {
  header: () => {
    return `
${colors.brandBold("  HARMONY")}
${colors.dim("  Project management for AI agents")}
`;
  },

  done: (message: string) => {
    return `${colors.success(symbols.check)} ${message}`;
  },

  fail: (message: string) => {
    return `${colors.error(symbols.cross)} ${message}`;
  },

  skip: (message: string) => {
    return `${colors.dim("-")} ${colors.dim(message)}`;
  },

  step: (number: number, total: number, message: string) => {
    return `${colors.dim(`[${number}/${total}]`)} ${message}`;
  },

  fileCreated: (path: string) => {
    return `  ${colors.success(symbols.check)} ${colors.dim(path)}`;
  },

  fileSkipped: (path: string) => {
    return `  ${colors.dim(symbols.bullet)} ${colors.dim(path)} ${colors.dim("(exists)")}`;
  },

  fileError: (path: string, error: string) => {
    return `  ${colors.error(symbols.cross)} ${path}: ${colors.error(error)}`;
  },
};

// Box drawing for sections
export function box(title: string, content: string): string {
  const lines = content.split("\n");
  const maxWidth = Math.max(title.length, ...lines.map((l) => l.length));
  const width = maxWidth + 4;

  const top = `\u250C${"─".repeat(width)}\u2510`;
  const bottom = `\u2514${"─".repeat(width)}\u2518`;
  const titleLine = `\u2502 ${colors.bold(title)}${" ".repeat(width - title.length - 1)}\u2502`;
  const contentLines = lines
    .map((line) => `\u2502 ${line}${" ".repeat(width - line.length - 1)}\u2502`)
    .join("\n");

  return `${top}\n${titleLine}\n${contentLines}\n${bottom}`;
}

// Format file paths for display (shorten home directory)
export function formatPath(path: string, homeDir: string): string {
  if (path.startsWith(homeDir)) {
    return `~${path.slice(homeDir.length)}`;
  }
  return path;
}

// Indent helper
export function indent(text: string, spaces = 2): string {
  const pad = " ".repeat(spaces);
  return text
    .split("\n")
    .map((line) => `${pad}${line}`)
    .join("\n");
}
