import a from './index5.mjs';
import { ensureI18nInitialized, i18n } from './index2.mjs';
import { a as getRuntimeHomepage, g as getRuntimeVersion } from '../shared/ccjk.gDEDGD_t.mjs';
import '../shared/ccjk.BAGoDD49.mjs';
import 'node:fs';
import 'node:process';
import 'node:url';
import '../shared/ccjk.bQ7Dh1g4.mjs';

const theme = {
  // === Core Colors ===
  /** Terminal green - main text color */
  primary: a.green,
  /** Bright white - emphasis and highlights */
  secondary: a.white,
  /** Dim green - subtle accents */
  accent: a.green,
  // === Semantic Colors ===
  /** Success - bright green checkmark */
  success: a.bold.green,
  /** Warning - amber/yellow for caution */
  warning: a.yellow,
  /** Error - red for failures */
  error: a.red,
  /** Info - cyan for informational messages */
  info: a.cyan,
  // === Text Styles ===
  /** Muted text - gray for less important info */
  muted: a.gray,
  /** Bold text */
  bold: a.bold,
  /** Dim text - for background info */
  dim: a.dim,
  // === MUD-specific Styles ===
  /** Command prompt style - bright green */
  prompt: a.bold.green,
  /** System message - white */
  system: a.white,
  /** NPC/hint text - dim green */
  hint: a.green,
  /** Quest/task highlight - bright */
  quest: a.bold.green,
  /** Item/feature name - white bold */
  item: a.bold.white
};
const status = {
  /** ✓ Success indicator */
  ok: (text) => `${a.green("\u2713")} ${text}`,
  /** ✗ Error indicator */
  fail: (text) => `${a.red("\u2717")} ${text}`,
  /** ⚠ Warning indicator */
  warn: (text) => `${a.yellow("\u26A0")} ${text}`,
  /** ℹ Info indicator */
  info: (text) => `${a.cyan("\u2139")} ${text}`,
  /** ○ Pending indicator */
  wait: (text) => `${a.gray("\u25CB")} ${text}`,
  /** ◐ In-progress indicator */
  work: (text) => `${a.green("\u25D0")} ${text}`};
const box = {
  single: { tl: "\u250C", tr: "\u2510", bl: "\u2514", br: "\u2518", h: "\u2500", v: "\u2502" },
  double: { tl: "\u2554", tr: "\u2557", bl: "\u255A", br: "\u255D", h: "\u2550", v: "\u2551" },
  rounded: { tl: "\u256D", tr: "\u256E", bl: "\u2570", br: "\u256F", h: "\u2500", v: "\u2502" },
  heavy: { tl: "\u250F", tr: "\u2513", bl: "\u2517", br: "\u251B", h: "\u2501", v: "\u2503" }
};
function boxify(content, style = "double", title) {
  const chars = box[style];
  const lines = content.split("\n");
  const getWidth = (s) => {
    let w = 0;
    for (const c of s) {
      w += c.match(/[\u4E00-\u9FFF\uFF01-\uFF60\u3000-\u303F]/) ? 2 : 1;
    }
    return w;
  };
  const maxWidth = Math.max(
    ...lines.map(getWidth),
    getWidth(title) + 4 
  );
  const paddedLines = lines.map((line) => {
    const padding = maxWidth - getWidth(line);
    return `${chars.v} ${line}${" ".repeat(padding)} ${chars.v}`;
  });
  let topBorder = `${chars.tl}${chars.h.repeat(maxWidth + 2)}${chars.tr}`;
  {
    const pad = Math.floor((maxWidth - getWidth(title)) / 2);
    topBorder = `${chars.tl}${chars.h.repeat(pad)} ${title} ${chars.h.repeat(maxWidth - pad - getWidth(title))}${chars.tr}`;
  }
  const bottomBorder = `${chars.bl}${chars.h.repeat(maxWidth + 2)}${chars.br}`;
  return theme.primary([topBorder, ...paddedLines, bottomBorder].join("\n"));
}

function getDisplayWidth(str) {
  let width = 0;
  for (const char of str) {
    if (char.match(/[\u4E00-\u9FFF\uFF01-\uFF60\u3000-\u303F]/)) {
      width += 2;
    } else {
      width += 1;
    }
  }
  return width;
}
function padToDisplayWidth(str, targetWidth) {
  const currentWidth = getDisplayWidth(str);
  const paddingNeeded = Math.max(0, targetWidth - currentWidth);
  return str + " ".repeat(paddingNeeded);
}
function displayBanner(subtitle) {
  ensureI18nInitialized();
  const version = getRuntimeVersion();
  const defaultSubtitle = i18n.t("cli:banner.subtitle");
  const subtitleText = subtitle || defaultSubtitle;
  const paddedSubtitle = padToDisplayWidth(subtitleText, 28);
  console.log(
    a.green.bold(`
\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
\u2551                                                               \u2551
\u2551   \u2588\u2588\u2588\u2588\u2588\u2588\u2557  \u2588\u2588\u2588\u2588\u2588\u2588\u2557      \u2588\u2588\u2557\u2588\u2588\u2557  \u2588\u2588\u2557                           \u2551
\u2551  \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D      \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u255D                           \u2551
\u2551  \u2588\u2588\u2551      \u2588\u2588\u2551           \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2554\u255D    ${a.white.bold("JinKu")}                 \u2551
\u2551  \u2588\u2588\u2551      \u2588\u2588\u2551      \u2588\u2588   \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2588\u2588\u2557    ${a.gray(`v${version}`)}${" ".repeat(Math.max(0, 17 - version.length))}\u2551
\u2551  \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551  \u2588\u2588\u2557                           \u2551
\u2551   \u255A\u2550\u2550\u2550\u2550\u2550\u255D  \u255A\u2550\u2550\u2550\u2550\u2550\u255D  \u255A\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D  \u255A\u2550\u255D   ${a.gray(paddedSubtitle)} \u2551
\u2551                                                               \u2551
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
`)
  );
}
function displayBannerWithInfo(subtitle) {
  const homepage = getRuntimeHomepage();
  displayBanner(subtitle);
  console.log(a.gray(`  ${a.green("ccjk")} - Advanced AI Development Assistant`));
  console.log(a.gray(`  ${a.green(homepage)}
`));
}
function displayCommandDiscovery() {
  ensureI18nInitialized();
  const isZhCN = i18n.language === "zh-CN";
  console.log(a.green.bold(`
${i18n.t("cli:commandDiscovery.title")}`));
  console.log(a.gray("\u2500".repeat(60)));
  const ccjkCommands = [
    { cmd: "/status", desc: i18n.t("cli:commandDiscovery.status"), descEn: "Brain Dashboard" },
    { cmd: "/health", desc: i18n.t("cli:commandDiscovery.health"), descEn: "Health Check" },
    { cmd: "/search", desc: i18n.t("cli:commandDiscovery.search"), descEn: "Search Contexts" },
    { cmd: "/compress", desc: i18n.t("cli:commandDiscovery.compress"), descEn: "Compression Stats" },
    { cmd: "/tasks", desc: i18n.t("cli:commandDiscovery.tasks"), descEn: "Task Manager" },
    { cmd: "/backup", desc: i18n.t("cli:commandDiscovery.backup"), descEn: "Create Backup" },
    { cmd: "/optimize", desc: i18n.t("cli:commandDiscovery.optimize"), descEn: "Optimize DB" }
  ];
  for (const { cmd, desc, descEn } of ccjkCommands) {
    const cmdPadded = cmd.padEnd(12);
    if (isZhCN) {
      console.log(`  ${a.cyan(cmdPadded)} - ${a.white(desc)} ${a.gray(`(${descEn})`)}`);
    } else {
      console.log(`  ${a.cyan(cmdPadded)} - ${a.white(desc)}`);
    }
  }
  console.log(a.gray(`
${"\u2500".repeat(60)}`));
  console.log(a.gray(`  ${i18n.t("cli:commandDiscovery.footer")}
`));
}
const STATUS = {
  success: status.ok,
  error: status.fail,
  warning: status.warn,
  info: status.info,
  pending: status.wait,
  inProgress: status.work
};

export { theme as COLORS, STATUS, box, boxify, displayBanner, displayBannerWithInfo, displayCommandDiscovery, getDisplayWidth, padToDisplayWidth, status, theme };
