import type { ITheme } from '@xterm/xterm'
import type { ThemeId } from '@/context/ThemeContext'

/**
 * 终端配色：与面板主题同系，但保证终端可读性
 * - 使用固定色板，不读 CSS 变量（避免切换瞬间读到旧值）
 * - 暗色：高对比浅字；亮色：深字浅底
 */
export function getTerminalTheme(theme: ThemeId): ITheme {
  if (theme === 'light') {
    return {
      background: '#f8f9fa',
      foreground: '#212529',
      cursor: '#212529',
      cursorAccent: '#f8f9fa',
      selectionBackground: 'rgba(33, 37, 41, 0.18)',
      selectionForeground: '#212529',
      selectionInactiveBackground: 'rgba(33, 37, 41, 0.1)',
      black: '#212529',
      red: '#dc2626',
      green: '#059669',
      yellow: '#d97706',
      blue: '#2563eb',
      magenta: '#7c3aed',
      cyan: '#0e7490',
      white: '#495057',
      brightBlack: '#868e96',
      brightRed: '#e03131',
      brightGreen: '#2f9e44',
      brightYellow: '#e67700',
      brightBlue: '#1c7ed6',
      brightMagenta: '#9c36b5',
      brightCyan: '#0c8599',
      brightWhite: '#212529',
    }
  }

  return {
    background: '#1a1a1a',
    foreground: '#f0f0f0',
    cursor: '#c0c0c0',
    cursorAccent: '#1a1a1a',
    selectionBackground: 'rgba(192, 192, 192, 0.35)',
    selectionForeground: '#ffffff',
    selectionInactiveBackground: 'rgba(192, 192, 192, 0.2)',
    black: '#4a4a4a',
    red: '#ff8a80',
    green: '#69f0ae',
    yellow: '#ffd54f',
    blue: '#82b1ff',
    magenta: '#e1bee7',
    cyan: '#80deea',
    white: '#e8e8e8',
    brightBlack: '#b0b0b0',
    brightRed: '#ff5252',
    brightGreen: '#69f0ae',
    brightYellow: '#ffee58',
    brightBlue: '#448aff',
    brightMagenta: '#e040fb',
    brightCyan: '#18ffff',
    brightWhite: '#ffffff',
  }
}
