import type { AnsiColorName } from '@simon_he/vue-tui'
import type { UiTheme } from './ui-theme'

const palette256: Partial<Record<AnsiColorName, string>> = {
  black: '#1e1e1e', // Primary text
  blackBright: '#f3f3f3', // Chrome BG
  white: '#ffffff', // Window BG
  whiteBright: '#ffffff',
  blue: '#bdbdbd', // Border / separator
  blueBright: '#4a4a4a', // Muted text
  cyan: '#e6f2ff', // Accent blue (soft bg)
  cyanBright: '#007acc', // Accent blue
  magenta: '#f2e7ff', // Accent purple (soft bg)
  magentaBright: '#af00db', // Accent purple
  yellow: '#fff4cc', // Warning / prompt (soft bg)
  yellowBright: '#795e26', // Warning text
  green: '#e8f5e9', // Diff add bg (light)
  greenBright: '#107c10', // Success text
  red: '#fde7e9', // Diff del bg (light)
  redBright: '#a1260d', // Error text
}

export const MONOKAI_LIGHT_UI_THEME: UiTheme = Object.freeze({
  palette256,
  tokensByLevel: {
    256: {
      'bg.window': { bg: 'white' },
      'bg.chrome': { bg: 'blackBright' },
      'border.default': { fg: 'blue' },
      'text.primary': { fg: 'black' },
      'text.muted': { fg: 'blueBright' },
      'text.faint': { fg: 'blue' },

      'accent.cyan': { fg: 'cyanBright', bold: true },
      'accent.purple': { fg: 'magentaBright', bold: true },
      'status.success': { fg: 'greenBright', bold: true },
      'status.warning': { fg: 'yellowBright', bold: true },
      'status.danger': { fg: 'redBright', bold: true },

      'select.item': { fg: 'white', bg: 'cyanBright', bold: true },
      'select.text': { fg: 'white', bg: 'magentaBright' },
      'focus.ring': { fg: 'cyanBright' },

      'code.inline': { fg: 'magentaBright' },
      'code.block.header': { fg: 'blueBright', bg: 'blackBright' },
      'code.block.body': { fg: 'black', bg: 'blackBright' },
      'diff.add': { fg: 'greenBright' },
      'diff.del': { fg: 'redBright' },
      'diff.hunk': { fg: 'cyanBright' },
      'diff.add.line': { bg: 'green' },
      'diff.del.line': { bg: 'red' },

      'dialog.chrome': { fg: 'blueBright', bg: 'blackBright' },
      'dialog.body': { bg: 'white' },
      'input.field': { fg: 'black', bg: 'blackBright' },
      'chip.plan': { fg: 'white', bg: 'magentaBright', bold: true },
      'chip.agent': { fg: 'white', bg: 'greenBright', bold: true },
      'chip.meta': { fg: 'blueBright', bg: 'blackBright', bold: true },
    },
    16: {
      'bg.window': { bg: 'white' },
      'bg.chrome': { bg: 'blackBright' },
      'border.default': { fg: 'blue' },
      'text.primary': { fg: 'black' },
      'text.muted': { fg: 'blueBright' },
      'text.faint': { fg: 'blueBright', dim: true },

      'accent.cyan': { fg: 'cyanBright', bold: true },
      'accent.purple': { fg: 'magentaBright', bold: true },
      'status.success': { fg: 'greenBright', bold: true },
      'status.warning': { fg: 'yellowBright', bold: true },
      'status.danger': { fg: 'redBright', bold: true },

      'select.item': { inverse: true, bold: true },
      'select.text': { inverse: true },
      'focus.ring': { fg: 'cyanBright' },

      'code.inline': { fg: 'magentaBright' },
      'code.block.header': { fg: 'blueBright' },
      'code.block.body': { fg: 'black' },
      'diff.add': { fg: 'greenBright' },
      'diff.del': { fg: 'redBright' },
      'diff.hunk': { fg: 'cyanBright' },
      'diff.add.line': { bg: 'green' },
      'diff.del.line': { bg: 'red' },

      'dialog.chrome': { fg: 'blueBright', bg: 'blackBright' },
      'dialog.body': { bg: 'white' },
      'input.field': { fg: 'black', bg: 'blackBright' },
      'chip.plan': { inverse: true, bold: true },
      'chip.agent': { inverse: true, bold: true },
      'chip.meta': { dim: true },
    },
    8: {
      'bg.window': { bg: 'white' },
      'bg.chrome': { bg: 'blackBright' },
      'border.default': { dim: true },
      'text.primary': { fg: 'black' },
      'text.muted': { fg: 'black', dim: true },
      'text.faint': { fg: 'black', dim: true },

      'accent.cyan': { fg: 'cyan', bold: true },
      'accent.purple': { fg: 'magenta', bold: true },
      'status.success': { fg: 'green', bold: true },
      'status.warning': { fg: 'yellow', bold: true },
      'status.danger': { fg: 'red', bold: true },

      'select.item': { inverse: true, bold: true },
      'select.text': { inverse: true },
      'focus.ring': { fg: 'cyan' },

      'code.inline': { fg: 'magenta' },
      'code.block.header': { dim: true },
      'code.block.body': {},
      'diff.add': { fg: 'green' },
      'diff.del': { fg: 'red' },
      'diff.hunk': { fg: 'cyan' },
      'diff.add.line': { bg: 'green' },
      'diff.del.line': { bg: 'red' },

      'dialog.chrome': { fg: 'blue' },
      'dialog.body': {},
      'input.field': { inverse: true },
      'chip.plan': { inverse: true, bold: true },
      'chip.agent': { inverse: true, bold: true },
      'chip.meta': { dim: true },
    },
  },
})
