import type { CustomTheme, ThemeColors } from "./customTheme";

const EMPTY_BG = {
  enabled: false,
  path: "",
  dataUrl: "",
  blur: 0,
  darken: 0,
  opacity: 1,
} as const;

/**
 * Generic ANSI 16 palette tuned for dark surfaces. Each preset spreads
 * this so it picks up the full set, then can override individual slots
 * where the canonical preset specifies different ANSI colors.
 */
const ANSI_DARK = {
  ansiBlack: "#18181b",
  ansiRed: "#ef4444",
  ansiGreen: "#22c55e",
  ansiYellow: "#eab308",
  ansiBlue: "#3b82f6",
  ansiMagenta: "#a855f7",
  ansiCyan: "#06b6d4",
  ansiWhite: "#e4e4e7",
  ansiBrightBlack: "#52525b",
  ansiBrightRed: "#f87171",
  ansiBrightGreen: "#4ade80",
  ansiBrightYellow: "#facc15",
  ansiBrightBlue: "#60a5fa",
  ansiBrightMagenta: "#c084fc",
  ansiBrightCyan: "#22d3ee",
  ansiBrightWhite: "#fafafa",
} satisfies Pick<
  ThemeColors,
  | "ansiBlack"
  | "ansiRed"
  | "ansiGreen"
  | "ansiYellow"
  | "ansiBlue"
  | "ansiMagenta"
  | "ansiCyan"
  | "ansiWhite"
  | "ansiBrightBlack"
  | "ansiBrightRed"
  | "ansiBrightGreen"
  | "ansiBrightYellow"
  | "ansiBrightBlue"
  | "ansiBrightMagenta"
  | "ansiBrightCyan"
  | "ansiBrightWhite"
>;

/** Generic ANSI 16 palette tuned for light surfaces (less neon, more contrast). */
const ANSI_LIGHT = {
  ansiBlack: "#3f3f46",
  ansiRed: "#dc2626",
  ansiGreen: "#16a34a",
  ansiYellow: "#ca8a04",
  ansiBlue: "#2563eb",
  ansiMagenta: "#9333ea",
  ansiCyan: "#0891b2",
  ansiWhite: "#e4e4e7",
  ansiBrightBlack: "#71717a",
  ansiBrightRed: "#ef4444",
  ansiBrightGreen: "#22c55e",
  ansiBrightYellow: "#eab308",
  ansiBrightBlue: "#3b82f6",
  ansiBrightMagenta: "#a855f7",
  ansiBrightCyan: "#06b6d4",
  ansiBrightWhite: "#fafafa",
} satisfies typeof ANSI_DARK;

const DARK_COLORS: ThemeColors = {
  background: "#1e1e1e",
  foreground: "#cccccc",
  card: "#1f1f1f",
  cardForeground: "#cccccc",
  popover: "#1f1f1f",
  popoverForeground: "#cccccc",
  button: "#0057fe",
  buttonForeground: "#ffffff",
  secondary: "#2a2d2e",
  secondaryForeground: "#cccccc",
  muted: "#252526",
  mutedForeground: "#9d9d9d",
  accent: "#0a2870",
  accentForeground: "#ffffff",
  destructive: "#f14c4c",
  border: "#2b2b2b",
  input: "#313131",
  buttonBorder: "#3a3a3a",
  ring: "#0057fe",
  sidebar: "#181818",
  sidebarForeground: "#cccccc",
  sidebarBorder: "#2b2b2b",
  sidebarAccent: "#37373d",
  sidebarAccentForeground: "#ffffff",
  iconWorking: "#facc15",
  iconIdle: "#34d399",
  iconBlocked: "#f87171",
  diffAdded: "#4ade80",
  diffRemoved: "#f87171",
  info: "#38bdf8",
  tabAccentTerminal: "#34d399",
  tabAccentSsh: "#38bdf8",
  tabAccentEditor: "#5b8bff",
  tabAccentPreview: "#22d3ee",
  tabAccentAiDiff: "#a78bfa",
  tabAccentGitDiff: "#fbbf24",
  resizeHandle: "#2b2b2b",
  ...ANSI_DARK,
};

const LIGHT_COLORS: ThemeColors = {
  background: "#ffffff",
  foreground: "#1f2328",
  card: "#ffffff",
  cardForeground: "#1f2328",
  popover: "#ffffff",
  popoverForeground: "#1f2328",
  button: "#0057fe",
  buttonForeground: "#ffffff",
  secondary: "#f3f4f6",
  secondaryForeground: "#1f2328",
  muted: "#f3f4f6",
  mutedForeground: "#5d646e",
  accent: "#dbe5ff",
  accentForeground: "#1f2328",
  destructive: "#dc2626",
  border: "#e5e7eb",
  input: "#e5e7eb",
  buttonBorder: "#d1d5db",
  ring: "#0057fe",
  sidebar: "#fafafa",
  sidebarForeground: "#1f2328",
  sidebarBorder: "#e5e7eb",
  sidebarAccent: "#dbe5ff",
  sidebarAccentForeground: "#1f2328",
  iconWorking: "#ca8a04",
  iconIdle: "#059669",
  iconBlocked: "#dc2626",
  diffAdded: "#16a34a",
  diffRemoved: "#dc2626",
  info: "#0284c7",
  tabAccentTerminal: "#10b981",
  tabAccentSsh: "#0ea5e9",
  tabAccentEditor: "#0057fe",
  tabAccentPreview: "#06b6d4",
  tabAccentAiDiff: "#8b5cf6",
  tabAccentGitDiff: "#f59e0b",
  resizeHandle: "#e5e7eb",
  ...ANSI_LIGHT,
};

export const DEFAULT_CUSTOM_THEME: CustomTheme = {
  name: "Default",
  light: LIGHT_COLORS,
  dark: DARK_COLORS,
  background: { ...EMPTY_BG },
};

// Tokyo Night family.
const TOKYO_DARK: ThemeColors = {
  ...DARK_COLORS,
  background: "#1a1b26",
  foreground: "#c0caf5",
  card: "#1f2335",
  cardForeground: "#c0caf5",
  popover: "#1f2335",
  popoverForeground: "#c0caf5",
  button: "#7aa2f7",
  buttonForeground: "#1a1b26",
  secondary: "#24283b",
  secondaryForeground: "#c0caf5",
  muted: "#24283b",
  mutedForeground: "#9aa5ce",
  accent: "#3d59a1",
  accentForeground: "#ffffff",
  destructive: "#f7768e",
  border: "#2d3047",
  input: "#2d3047",
  buttonBorder: "#3d4263",
  ring: "#7aa2f7",
  sidebar: "#16161e",
  sidebarForeground: "#c0caf5",
  sidebarBorder: "#2d3047",
  sidebarAccent: "#3d59a1",
  sidebarAccentForeground: "#ffffff",
  iconWorking: "#e0af68",
  iconIdle: "#9ece6a",
  iconBlocked: "#f7768e",
  diffAdded: "#9ece6a",
  diffRemoved: "#f7768e",
  info: "#7dcfff",
  resizeHandle: "#2d3047",
  // Tokyo Night Storm ANSI 16.
  ansiBlack: "#15161e",
  ansiRed: "#f7768e",
  ansiGreen: "#9ece6a",
  ansiYellow: "#e0af68",
  ansiBlue: "#7aa2f7",
  ansiMagenta: "#bb9af7",
  ansiCyan: "#7dcfff",
  ansiWhite: "#a9b1d6",
  ansiBrightBlack: "#414868",
  ansiBrightRed: "#f7768e",
  ansiBrightGreen: "#9ece6a",
  ansiBrightYellow: "#e0af68",
  ansiBrightBlue: "#7aa2f7",
  ansiBrightMagenta: "#bb9af7",
  ansiBrightCyan: "#7dcfff",
  ansiBrightWhite: "#c0caf5",
};
// Tokyo Night Day (official light variant). Selection foregrounds darkened
// from the brand blue (#3760bf, ~3:1 vs lavender accent) to a near-navy
// (#1a2238, ~10:1) so file-tree selection text passes WCAG AA.
const TOKYO_LIGHT: ThemeColors = {
  ...LIGHT_COLORS,
  background: "#e1e2e7",
  foreground: "#1a2238",
  card: "#d5d6db",
  cardForeground: "#1a2238",
  popover: "#d5d6db",
  popoverForeground: "#1a2238",
  button: "#1f6fd6",
  buttonForeground: "#ffffff",
  secondary: "#c4c8da",
  secondaryForeground: "#1a2238",
  muted: "#c4c8da",
  mutedForeground: "#3a4566",
  accent: "#b6bfe2",
  accentForeground: "#1a2238",
  destructive: "#f52a65",
  border: "#a8aecb",
  input: "#a8aecb",
  buttonBorder: "#8990b3",
  ring: "#2e7de9",
  sidebar: "#d5d6db",
  sidebarForeground: "#1a2238",
  sidebarBorder: "#a8aecb",
  sidebarAccent: "#b6bfe2",
  sidebarAccentForeground: "#1a2238",
  iconWorking: "#8c6c3e",
  iconIdle: "#587539",
  iconBlocked: "#f52a65",
  diffAdded: "#587539",
  diffRemoved: "#f52a65",
  info: "#2e7de9",
  resizeHandle: "#a8aecb",
  // Tokyo Night Day ANSI 16 (official light terminal palette).
  ansiBlack: "#b4b5b9",
  ansiRed: "#f52a65",
  ansiGreen: "#587539",
  ansiYellow: "#8c6c3e",
  ansiBlue: "#2e7de9",
  ansiMagenta: "#9854f1",
  ansiCyan: "#007197",
  ansiWhite: "#6172b0",
  ansiBrightBlack: "#a1a6c5",
  ansiBrightRed: "#f52a65",
  ansiBrightGreen: "#587539",
  ansiBrightYellow: "#8c6c3e",
  ansiBrightBlue: "#2e7de9",
  ansiBrightMagenta: "#9854f1",
  ansiBrightCyan: "#007197",
  ansiBrightWhite: "#3760bf",
};

// Nord family.
const NORD_DARK: ThemeColors = {
  ...DARK_COLORS,
  background: "#2e3440",
  foreground: "#d8dee9",
  card: "#3b4252",
  cardForeground: "#eceff4",
  popover: "#3b4252",
  popoverForeground: "#eceff4",
  button: "#88c0d0",
  buttonForeground: "#2e3440",
  secondary: "#434c5e",
  secondaryForeground: "#eceff4",
  muted: "#434c5e",
  mutedForeground: "#bdc6d6",
  accent: "#3f577a",
  accentForeground: "#eceff4",
  destructive: "#bf616a",
  border: "#4c566a",
  input: "#4c566a",
  buttonBorder: "#5b6478",
  ring: "#88c0d0",
  sidebar: "#292e39",
  sidebarForeground: "#d8dee9",
  sidebarBorder: "#4c566a",
  sidebarAccent: "#3f577a",
  sidebarAccentForeground: "#eceff4",
  iconWorking: "#ebcb8b",
  iconIdle: "#a3be8c",
  iconBlocked: "#bf616a",
  diffAdded: "#a3be8c",
  diffRemoved: "#bf616a",
  info: "#81a1c1",
  resizeHandle: "#4c566a",
  // Nord ANSI 16.
  ansiBlack: "#3b4252",
  ansiRed: "#bf616a",
  ansiGreen: "#a3be8c",
  ansiYellow: "#ebcb8b",
  ansiBlue: "#81a1c1",
  ansiMagenta: "#b48ead",
  ansiCyan: "#88c0d0",
  ansiWhite: "#e5e9f0",
  ansiBrightBlack: "#4c566a",
  ansiBrightRed: "#bf616a",
  ansiBrightGreen: "#a3be8c",
  ansiBrightYellow: "#ebcb8b",
  ansiBrightBlue: "#81a1c1",
  ansiBrightMagenta: "#b48ead",
  ansiBrightCyan: "#8fbcbb",
  ansiBrightWhite: "#eceff4",
};
const NORD_LIGHT: ThemeColors = {
  ...LIGHT_COLORS,
  background: "#eceff4",
  foreground: "#2e3440",
  card: "#e5e9f0",
  cardForeground: "#2e3440",
  popover: "#e5e9f0",
  popoverForeground: "#2e3440",
  button: "#3f577a",
  buttonForeground: "#eceff4",
  secondary: "#d8dee9",
  secondaryForeground: "#2e3440",
  muted: "#d8dee9",
  mutedForeground: "#4c566a",
  accent: "#88c0d0",
  accentForeground: "#2e3440",
  destructive: "#bf616a",
  border: "#d8dee9",
  input: "#d8dee9",
  buttonBorder: "#c5cdd9",
  ring: "#5e81ac",
  sidebar: "#e5e9f0",
  sidebarForeground: "#2e3440",
  sidebarBorder: "#d8dee9",
  sidebarAccent: "#88c0d0",
  sidebarAccentForeground: "#2e3440",
  iconWorking: "#d08770",
  iconIdle: "#a3be8c",
  iconBlocked: "#bf616a",
  diffAdded: "#a3be8c",
  diffRemoved: "#bf616a",
  info: "#5e81ac",
  resizeHandle: "#d8dee9",
  // Nord has no official light terminal palette; the standard Nord ANSI is
  // tuned for dark surfaces (green/yellow/cyan wash out on #eceff4). These are
  // the same Nord hues deepened to read on the light background while keeping
  // the Frost/Aurora character. Brights restore the canonical Nord tones.
  ansiBlack: "#2e3440",
  ansiRed: "#99313b",
  ansiGreen: "#4f6a43",
  ansiYellow: "#9a7227",
  ansiBlue: "#5e81ac",
  ansiMagenta: "#8a5d80",
  ansiCyan: "#3b7e8e",
  ansiWhite: "#4c566a",
  ansiBrightBlack: "#434c5e",
  ansiBrightRed: "#bf616a",
  ansiBrightGreen: "#5e7a50",
  ansiBrightYellow: "#b58a3a",
  ansiBrightBlue: "#5e81ac",
  ansiBrightMagenta: "#a3789a",
  ansiBrightCyan: "#4f93a3",
  ansiBrightWhite: "#2e3440",
};

// Catppuccin family (Mocha + Latte).
const CATPPUCCIN_DARK: ThemeColors = {
  ...DARK_COLORS,
  background: "#1e1e2e",
  foreground: "#cdd6f4",
  card: "#181825",
  cardForeground: "#cdd6f4",
  popover: "#181825",
  popoverForeground: "#cdd6f4",
  button: "#cba6f7",
  buttonForeground: "#1e1e2e",
  secondary: "#313244",
  secondaryForeground: "#cdd6f4",
  muted: "#313244",
  mutedForeground: "#a6adc8",
  accent: "#45475a",
  accentForeground: "#cdd6f4",
  destructive: "#f38ba8",
  border: "#45475a",
  input: "#45475a",
  buttonBorder: "#585b70",
  ring: "#cba6f7",
  sidebar: "#11111b",
  sidebarForeground: "#cdd6f4",
  sidebarBorder: "#45475a",
  sidebarAccent: "#585b70",
  sidebarAccentForeground: "#cdd6f4",
  iconWorking: "#f9e2af",
  iconIdle: "#a6e3a1",
  iconBlocked: "#f38ba8",
  diffAdded: "#a6e3a1",
  diffRemoved: "#f38ba8",
  info: "#89dceb",
  resizeHandle: "#45475a",
  // Catppuccin Mocha ANSI 16.
  ansiBlack: "#45475a",
  ansiRed: "#f38ba8",
  ansiGreen: "#a6e3a1",
  ansiYellow: "#f9e2af",
  ansiBlue: "#89b4fa",
  ansiMagenta: "#f5c2e7",
  ansiCyan: "#94e2d5",
  ansiWhite: "#bac2de",
  ansiBrightBlack: "#585b70",
  ansiBrightRed: "#f38ba8",
  ansiBrightGreen: "#a6e3a1",
  ansiBrightYellow: "#f9e2af",
  ansiBrightBlue: "#89b4fa",
  ansiBrightMagenta: "#f5c2e7",
  ansiBrightCyan: "#94e2d5",
  ansiBrightWhite: "#a6adc8",
};
// Catppuccin Latte. Default Latte uses `Text #4c4f69` against `Surface1`/
// `Overlay0` highlights which lands ~3.5:1 - acceptable for body text on
// the page bg, but not for selection text on the highlight bg. Selection
// foregrounds switched to Mocha `Base #1e1e2e` (~9:1) so file-tree picks
// stay readable.
const CATPPUCCIN_LIGHT: ThemeColors = {
  ...LIGHT_COLORS,
  background: "#eff1f5",
  foreground: "#1e1e2e",
  card: "#e6e9ef",
  cardForeground: "#1e1e2e",
  popover: "#e6e9ef",
  popoverForeground: "#1e1e2e",
  button: "#8839ef",
  buttonForeground: "#eff1f5",
  secondary: "#ccd0da",
  secondaryForeground: "#1e1e2e",
  muted: "#ccd0da",
  mutedForeground: "#4c4f69",
  accent: "#bcc0cc",
  accentForeground: "#1e1e2e",
  destructive: "#d20f39",
  border: "#bcc0cc",
  input: "#bcc0cc",
  buttonBorder: "#acb0be",
  ring: "#8839ef",
  sidebar: "#e6e9ef",
  sidebarForeground: "#1e1e2e",
  sidebarBorder: "#bcc0cc",
  sidebarAccent: "#acb0be",
  sidebarAccentForeground: "#1e1e2e",
  iconWorking: "#df8e1d",
  iconIdle: "#40a02b",
  iconBlocked: "#d20f39",
  diffAdded: "#40a02b",
  diffRemoved: "#d20f39",
  info: "#04a5e5",
  resizeHandle: "#bcc0cc",
  // Catppuccin Latte ANSI 16 (official light terminal palette).
  ansiBlack: "#5c5f77",
  ansiRed: "#d20f39",
  ansiGreen: "#40a02b",
  ansiYellow: "#df8e1d",
  ansiBlue: "#1e66f5",
  ansiMagenta: "#ea76cb",
  ansiCyan: "#179299",
  ansiWhite: "#acb0be",
  ansiBrightBlack: "#6c6f85",
  ansiBrightRed: "#d20f39",
  ansiBrightGreen: "#40a02b",
  ansiBrightYellow: "#df8e1d",
  ansiBrightBlue: "#1e66f5",
  ansiBrightMagenta: "#ea76cb",
  ansiBrightCyan: "#179299",
  ansiBrightWhite: "#bcc0cc",
};

// Solarized family.
// Solarized Dark. Body text bumped from base0 (#839496, ~4:1 on base03)
// to base1 (#93a1a1, ~5:1) so non-selected sidebar rows pass AA. Selection
// fg already paired correctly with the gold accent (base03 #002b36).
// mutedForeground was still base0 (#839496) against muted base02 (#073642)
// at ~4.0:1, just under AA - lifted to base1 (#93a1a1) for ~5:1.
const SOLARIZED_DARK: ThemeColors = {
  ...DARK_COLORS,
  background: "#002b36",
  foreground: "#93a1a1",
  card: "#073642",
  cardForeground: "#93a1a1",
  popover: "#073642",
  popoverForeground: "#93a1a1",
  button: "#3a9bdc",
  buttonForeground: "#002b36",
  secondary: "#073642",
  secondaryForeground: "#93a1a1",
  muted: "#073642",
  mutedForeground: "#93a1a1",
  accent: "#b58900",
  accentForeground: "#002b36",
  destructive: "#dc322f",
  border: "#0e4150",
  input: "#0e4150",
  buttonBorder: "#1a5063",
  ring: "#268bd2",
  sidebar: "#073642",
  sidebarForeground: "#93a1a1",
  sidebarBorder: "#0e4150",
  sidebarAccent: "#b58900",
  sidebarAccentForeground: "#002b36",
  iconWorking: "#b58900",
  iconIdle: "#859900",
  iconBlocked: "#dc322f",
  diffAdded: "#859900",
  diffRemoved: "#dc322f",
  info: "#2aa198",
  resizeHandle: "#0e4150",
  // Solarized ANSI 16 (shared between Dark + Light per author's spec).
  ansiBlack: "#073642",
  ansiRed: "#dc322f",
  ansiGreen: "#859900",
  ansiYellow: "#b58900",
  ansiBlue: "#268bd2",
  ansiMagenta: "#d33682",
  ansiCyan: "#2aa198",
  ansiWhite: "#eee8d5",
  ansiBrightBlack: "#002b36",
  ansiBrightRed: "#cb4b16",
  ansiBrightGreen: "#586e75",
  ansiBrightYellow: "#657b83",
  ansiBrightBlue: "#839496",
  ansiBrightMagenta: "#6c71c4",
  ansiBrightCyan: "#93a1a1",
  ansiBrightWhite: "#fdf6e3",
};
// Solarized Light. Gold accent (#b58900) on cream foreground (#fdf6e3) lands
// at ~2:1 - failing AA even at large text. Foregrounds for accent/sidebar-
// accent swapped to base03 (#002b36) where the spec already calls them
// "the dark text on a light bg" pair. body text uses base02 (#073642) for
// stronger contrast on the cream sidebar/page surfaces.
const SOLARIZED_LIGHT: ThemeColors = {
  ...LIGHT_COLORS,
  background: "#fdf6e3",
  foreground: "#073642",
  card: "#eee8d5",
  cardForeground: "#073642",
  popover: "#eee8d5",
  popoverForeground: "#073642",
  button: "#1a69a6",
  buttonForeground: "#fdf6e3",
  secondary: "#eee8d5",
  secondaryForeground: "#073642",
  muted: "#eee8d5",
  mutedForeground: "#4a5c63",
  accent: "#b58900",
  accentForeground: "#002b36",
  destructive: "#dc322f",
  border: "#d6d0bd",
  input: "#d6d0bd",
  buttonBorder: "#c0b89e",
  ring: "#268bd2",
  sidebar: "#eee8d5",
  sidebarForeground: "#073642",
  sidebarBorder: "#d6d0bd",
  sidebarAccent: "#b58900",
  sidebarAccentForeground: "#002b36",
  iconWorking: "#b58900",
  iconIdle: "#859900",
  iconBlocked: "#dc322f",
  diffAdded: "#859900",
  diffRemoved: "#dc322f",
  info: "#2aa198",
  resizeHandle: "#d6d0bd",
  // Solarized ANSI (shared with Dark).
  ansiBlack: "#073642",
  ansiRed: "#dc322f",
  ansiGreen: "#859900",
  ansiYellow: "#b58900",
  ansiBlue: "#268bd2",
  ansiMagenta: "#d33682",
  ansiCyan: "#2aa198",
  ansiWhite: "#eee8d5",
  ansiBrightBlack: "#002b36",
  ansiBrightRed: "#cb4b16",
  ansiBrightGreen: "#586e75",
  ansiBrightYellow: "#657b83",
  ansiBrightBlue: "#839496",
  ansiBrightMagenta: "#6c71c4",
  ansiBrightCyan: "#93a1a1",
  ansiBrightWhite: "#fdf6e3",
};

// Monokai family.
// Monokai Dark. The canonical "comment" gray #75715e is intentionally dim
// (designed for code comments, not UI body). Against `muted` #3e3d32 it
// only lands ~2.2:1 - well under AA - so muted body text in the sidebar
// and popovers becomes unreadable. Lifted to #bcb29a (~4.9:1) which keeps
// the warm Monokai cast while passing AA.
const MONOKAI_DARK: ThemeColors = {
  ...DARK_COLORS,
  background: "#272822",
  foreground: "#f8f8f2",
  card: "#1e1f1c",
  cardForeground: "#f8f8f2",
  popover: "#1e1f1c",
  popoverForeground: "#f8f8f2",
  button: "#a6e22e",
  buttonForeground: "#272822",
  secondary: "#3e3d32",
  secondaryForeground: "#f8f8f2",
  muted: "#3e3d32",
  mutedForeground: "#bcb29a",
  accent: "#66d9ef",
  accentForeground: "#272822",
  destructive: "#f92672",
  border: "#3e3d32",
  input: "#3e3d32",
  buttonBorder: "#49483e",
  ring: "#a6e22e",
  sidebar: "#1e1f1c",
  sidebarForeground: "#f8f8f2",
  sidebarBorder: "#3e3d32",
  sidebarAccent: "#75715e",
  sidebarAccentForeground: "#f8f8f2",
  iconWorking: "#e6db74",
  iconIdle: "#a6e22e",
  iconBlocked: "#f92672",
  diffAdded: "#a6e22e",
  diffRemoved: "#f92672",
  info: "#66d9ef",
  resizeHandle: "#3e3d32",
  // Monokai ANSI 16.
  ansiBlack: "#272822",
  ansiRed: "#f92672",
  ansiGreen: "#a6e22e",
  ansiYellow: "#f4bf75",
  ansiBlue: "#66d9ef",
  ansiMagenta: "#ae81ff",
  ansiCyan: "#a1efe4",
  ansiWhite: "#f8f8f2",
  ansiBrightBlack: "#75715e",
  ansiBrightRed: "#f92672",
  ansiBrightGreen: "#a6e22e",
  ansiBrightYellow: "#f4bf75",
  ansiBrightBlue: "#66d9ef",
  ansiBrightMagenta: "#ae81ff",
  ansiBrightCyan: "#a1efe4",
  ansiBrightWhite: "#f9f8f5",
};
// Monokai Light. The bright cyan accent (#0099a8) on white text fails AA
// (~3.5:1); deepened to #006d75 (~5.6:1) while keeping the Monokai cyan
// signature.
const MONOKAI_LIGHT: ThemeColors = {
  ...LIGHT_COLORS,
  background: "#fafafa",
  foreground: "#272822",
  card: "#f5f5f5",
  cardForeground: "#272822",
  popover: "#f5f5f5",
  popoverForeground: "#272822",
  button: "#75af00",
  buttonForeground: "#272822",
  secondary: "#eaeaea",
  secondaryForeground: "#272822",
  muted: "#eaeaea",
  mutedForeground: "#5a5848",
  accent: "#006d75",
  accentForeground: "#fafafa",
  destructive: "#f92672",
  border: "#d1d1d1",
  input: "#d1d1d1",
  buttonBorder: "#bcbcbc",
  ring: "#75af00",
  sidebar: "#f5f5f5",
  sidebarForeground: "#272822",
  sidebarBorder: "#d1d1d1",
  sidebarAccent: "#5e5b4a",
  sidebarAccentForeground: "#fafafa",
  iconWorking: "#b58900",
  iconIdle: "#75af00",
  iconBlocked: "#f92672",
  diffAdded: "#75af00",
  diffRemoved: "#f92672",
  info: "#006d75",
  resizeHandle: "#d1d1d1",
  // Monokai has no canonical light terminal palette; these keep the Monokai
  // hues but deepened so red/green/yellow/cyan read on the #fafafa background.
  // Brights restore the familiar neon Monokai tones.
  ansiBlack: "#272822",
  ansiRed: "#c2185b",
  ansiGreen: "#5a7d00",
  ansiYellow: "#a6770a",
  ansiBlue: "#1c7e8e",
  ansiMagenta: "#7c4dbd",
  ansiCyan: "#0a8a8a",
  ansiWhite: "#5a5848",
  ansiBrightBlack: "#75715e",
  ansiBrightRed: "#f92672",
  ansiBrightGreen: "#7aab00",
  ansiBrightYellow: "#c89a2a",
  ansiBrightBlue: "#0099a8",
  ansiBrightMagenta: "#9a6fe0",
  ansiBrightCyan: "#3aa9a0",
  ansiBrightWhite: "#272822",
};

// Matrix family (dark green phosphor + a "light" inverted variant).
const MATRIX_DARK: ThemeColors = {
  ...DARK_COLORS,
  background: "#000000",
  foreground: "#00ff41",
  card: "#050a05",
  cardForeground: "#00ff41",
  popover: "#050a05",
  popoverForeground: "#00ff41",
  button: "#00ff41",
  buttonForeground: "#000000",
  secondary: "#0a1f0a",
  secondaryForeground: "#00ff41",
  muted: "#0a160a",
  mutedForeground: "#3f8f3f",
  accent: "#003b00",
  accentForeground: "#00ff41",
  destructive: "#ff003c",
  border: "#0d2f0d",
  input: "#0d2f0d",
  buttonBorder: "#00ff41",
  ring: "#00ff41",
  sidebar: "#020602",
  sidebarForeground: "#00ff41",
  sidebarBorder: "#0d2f0d",
  sidebarAccent: "#008f11",
  sidebarAccentForeground: "#000000",
  iconWorking: "#39ff14",
  iconIdle: "#3f8f3f",
  iconBlocked: "#ff003c",
  diffAdded: "#00ff41",
  diffRemoved: "#ff003c",
  info: "#00d4ff",
  tabAccentTerminal: "#00ff41",
  tabAccentSsh: "#00ffaa",
  tabAccentEditor: "#39ff14",
  tabAccentPreview: "#00d4ff",
  tabAccentAiDiff: "#aaff00",
  tabAccentGitDiff: "#ffd700",
  resizeHandle: "#0d2f0d",
  // Matrix ANSI 16 - green-dominant phosphor palette.
  ansiBlack: "#003b00",
  ansiRed: "#ff003c",
  ansiGreen: "#00ff41",
  ansiYellow: "#ffd700",
  ansiBlue: "#00d4ff",
  ansiMagenta: "#aaff00",
  ansiCyan: "#00ffaa",
  ansiWhite: "#00cc33",
  ansiBrightBlack: "#0d2f0d",
  ansiBrightRed: "#ff003c",
  ansiBrightGreen: "#39ff14",
  ansiBrightYellow: "#ffd700",
  ansiBrightBlue: "#00ffaa",
  ansiBrightMagenta: "#aaff00",
  ansiBrightCyan: "#00ffea",
  ansiBrightWhite: "#00ff41",
};
const MATRIX_LIGHT: ThemeColors = {
  ...LIGHT_COLORS,
  background: "#f4fff4",
  foreground: "#003b00",
  card: "#e6f5e6",
  cardForeground: "#003b00",
  popover: "#e6f5e6",
  popoverForeground: "#003b00",
  button: "#006400",
  buttonForeground: "#f4fff4",
  secondary: "#d4eed4",
  secondaryForeground: "#003b00",
  muted: "#d4eed4",
  mutedForeground: "#2c722c",
  accent: "#a6e3a1",
  accentForeground: "#003b00",
  destructive: "#c2185b",
  border: "#bfd9bf",
  input: "#bfd9bf",
  buttonBorder: "#9ec59e",
  ring: "#006400",
  sidebar: "#e6f5e6",
  sidebarForeground: "#003b00",
  sidebarBorder: "#bfd9bf",
  sidebarAccent: "#a6e3a1",
  sidebarAccentForeground: "#003b00",
  iconWorking: "#0a8a0a",
  iconIdle: "#006400",
  iconBlocked: "#c2185b",
  diffAdded: "#006400",
  diffRemoved: "#c2185b",
  info: "#1976d2",
  tabAccentTerminal: "#006400",
  tabAccentSsh: "#0a8a8a",
  tabAccentEditor: "#0a6a0a",
  tabAccentPreview: "#1976d2",
  tabAccentAiDiff: "#5a8f00",
  tabAccentGitDiff: "#b58900",
  resizeHandle: "#bfd9bf",
  // Matrix "light" inverts the phosphor look: dark greens on a pale-green page.
  // Generic blue ANSI would clash, so use a dark-green-dominant set that reads
  // on #f4fff4 and keeps the Matrix identity.
  ansiBlack: "#003b00",
  ansiRed: "#c2185b",
  ansiGreen: "#006400",
  ansiYellow: "#8a6d00",
  ansiBlue: "#1565c0",
  ansiMagenta: "#5a8f00",
  ansiCyan: "#0a7a6a",
  ansiWhite: "#2c722c",
  ansiBrightBlack: "#0a4d0a",
  ansiBrightRed: "#c2185b",
  ansiBrightGreen: "#008000",
  ansiBrightYellow: "#a07a00",
  ansiBrightBlue: "#1976d2",
  ansiBrightMagenta: "#6a9f00",
  ansiBrightCyan: "#0a8a76",
  ansiBrightWhite: "#003b00",
};

export const THEME_PRESETS: CustomTheme[] = [
  {
    name: "Default",
    light: LIGHT_COLORS,
    dark: DARK_COLORS,
    background: { ...EMPTY_BG },
  },
  {
    name: "Tokyo Night",
    light: TOKYO_LIGHT,
    dark: TOKYO_DARK,
    background: { ...EMPTY_BG },
  },
  {
    name: "Nord",
    light: NORD_LIGHT,
    dark: NORD_DARK,
    background: { ...EMPTY_BG },
  },
  {
    name: "Catppuccin",
    light: CATPPUCCIN_LIGHT,
    dark: CATPPUCCIN_DARK,
    background: { ...EMPTY_BG },
  },
  {
    name: "Solarized",
    light: SOLARIZED_LIGHT,
    dark: SOLARIZED_DARK,
    background: { ...EMPTY_BG },
  },
  {
    name: "Monokai",
    light: MONOKAI_LIGHT,
    dark: MONOKAI_DARK,
    background: { ...EMPTY_BG },
  },
  {
    name: "Matrix",
    light: MATRIX_LIGHT,
    dark: MATRIX_DARK,
    background: { ...EMPTY_BG },
  },
];
