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

const palette256: Partial<Record<AnsiColorName, string>> = {
  black: '#2d2a2e', // Window BG
  blackBright: '#221f22', // Chrome BG
  white: '#fcfcfa', // Primary text
  whiteBright: '#fcfcfa',
  blue: '#403e41', // Border / separator
  blueBright: '#727072', // Muted text
  cyan: '#78dce8', // Accent cyan
  cyanBright: '#78dce8',
  magenta: '#ab9df2', // Accent purple
  magentaBright: '#ab9df2',
  yellow: '#ffd866', // Warning / prompt
  yellowBright: '#ffd866',
  green: '#2f3f2a', // Diff add bg (subtle)
  greenBright: '#a9dc76',
  red: '#46232c', // Diff del bg (subtle)
  redBright: '#ff6188',
}

export const MONOKAI_UI_THEME: UiTheme = Object.freeze({
  palette256,
  tokensByLevel: {
    256: {
      'bg.window': { bg: 'black' },
      'bg.chrome': { bg: 'blackBright' },
      'border.default': { fg: 'blue', dim: true },
      'text.primary': { fg: 'white' },
      'text.muted': { fg: 'white', dim: true },
      'text.faint': { fg: 'white', 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': { fg: 'black', bg: 'cyanBright', bold: true },
      'select.text': { fg: 'black', bg: 'magentaBright' },
      'focus.ring': { fg: 'cyanBright' },

      'code.inline': { fg: 'yellowBright' },
      'code.block.header': { fg: 'blueBright', bg: 'blackBright' },
      'code.block.body': { fg: 'white', 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: 'black' },
      'input.field': { fg: 'white', bg: 'blackBright' },
      'chip.plan': { fg: 'black', bg: 'magentaBright', bold: true },
      'chip.agent': { fg: 'black', bg: 'greenBright', bold: true },
      'chip.meta': { fg: 'blueBright', bg: 'blackBright', bold: true },
    },
    16: {
      'bg.window': { bg: 'black' },
      'bg.chrome': { bg: 'blackBright' },
      'border.default': { fg: 'blue', dim: true },
      'text.primary': { fg: 'white' },
      'text.muted': { fg: 'white', dim: true },
      'text.faint': { fg: 'white', 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: 'yellowBright' },
      'code.block.header': { fg: 'white', dim: true },
      'code.block.body': { fg: 'white' },
      '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: 'black' },
      'input.field': { fg: 'white', bg: 'blackBright' },
      'chip.plan': { fg: 'black', bg: 'magentaBright', bold: true },
      'chip.agent': { fg: 'black', bg: 'greenBright', bold: true },
      'chip.meta': { fg: 'blueBright', bg: 'blackBright', bold: true },
    },
    8: {
      'bg.window': { bg: 'black' },
      'bg.chrome': { bg: 'blackBright' },
      'border.default': { dim: true },
      'text.primary': { fg: 'white' },
      'text.muted': { fg: 'white', dim: true },
      'text.faint': { fg: 'white', 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: 'yellow' },
      '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': {},
      'chip.plan': { inverse: true, bold: true },
      'chip.agent': { inverse: true, bold: true },
      'chip.meta': { dim: true },
    },
  },
})
