/**
 * Editor Themes
 *
 * Built-in Monaco themes and custom CMDOP themes
 */

export type EditorTheme = 'vs' | 'vs-dark' | 'hc-black' | 'hc-light' | 'cmdop-dark' | 'cmdop-light';

export const EDITOR_THEMES = {
  // Built-in themes
  'vs': 'Light (VS Code)',
  'vs-dark': 'Dark (VS Code)',
  'hc-black': 'High Contrast Dark',
  'hc-light': 'High Contrast Light',
  // Custom themes (to be defined)
  'cmdop-dark': 'CMDOP Dark',
  'cmdop-light': 'CMDOP Light',
} as const;

/**
 * Get default theme based on system preference
 */
export function getDefaultTheme(): EditorTheme {
  if (typeof window === 'undefined') return 'vs-dark';

  const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
  return prefersDark ? 'vs-dark' : 'vs';
}

/**
 * CMDOP Dark Theme Definition
 * Can be registered with monaco.editor.defineTheme()
 */
export const cmdopDarkTheme = {
  base: 'vs-dark' as const,
  inherit: true,
  rules: [
    { token: 'comment', foreground: '6A9955', fontStyle: 'italic' },
    { token: 'keyword', foreground: 'C586C0' },
    { token: 'string', foreground: 'CE9178' },
    { token: 'number', foreground: 'B5CEA8' },
    { token: 'type', foreground: '4EC9B0' },
    { token: 'function', foreground: 'DCDCAA' },
    { token: 'variable', foreground: '9CDCFE' },
  ],
  colors: {
    'editor.background': '#1a1a1a',
    'editor.foreground': '#D4D4D4',
    'editor.lineHighlightBackground': '#2d2d2d',
    'editor.selectionBackground': '#264F78',
    'editorCursor.foreground': '#AEAFAD',
    'editorLineNumber.foreground': '#858585',
    'editorLineNumber.activeForeground': '#C6C6C6',
  },
};

/**
 * CMDOP Light Theme Definition
 */
export const cmdopLightTheme = {
  base: 'vs' as const,
  inherit: true,
  rules: [
    { token: 'comment', foreground: '008000', fontStyle: 'italic' },
    { token: 'keyword', foreground: 'AF00DB' },
    { token: 'string', foreground: 'A31515' },
    { token: 'number', foreground: '098658' },
    { token: 'type', foreground: '267F99' },
    { token: 'function', foreground: '795E26' },
    { token: 'variable', foreground: '001080' },
  ],
  colors: {
    'editor.background': '#FFFFFF',
    'editor.foreground': '#000000',
    'editor.lineHighlightBackground': '#F5F5F5',
    'editor.selectionBackground': '#ADD6FF',
  },
};
