import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      js.configs.recommended,
      tseslint.configs.recommended,
      reactHooks.configs.flat.recommended,
      reactRefresh.configs.vite,
    ],
    languageOptions: {
      globals: globals.browser,
    },
  },
  // ── Design Token Enforcement ────────────────────────────────────────────────
  // New hardcoded hex colors in components/pages are blocked (error).
  // Existing violations are tracked by: npm run check:tokens
  //
  // Use instead:
  //   DS_TEXT.secondary, DS_SURFACE.success.bg   (src/lib/ds.ts)
  //   matchScoreHex(score), criterionScoreTextColor(score)  (src/lib/utils.ts)
  //   RESULT_TYPE_META[type].color               (src/lib/ds.ts)
  //   MUI theme tokens: "primary.main", "text.secondary"
  {
    files: ['src/components/**/*.{ts,tsx}', 'src/pages/**/*.{ts,tsx}'],
    rules: {
      'no-restricted-syntax': [
        'warn',
        {
          selector: [
            'Property[key.name=/^(bgcolor|color|borderColor|background|fill|stroke)$/]',
            ' > Literal[value=/^#[0-9A-Fa-f]{3,8}$/]',
          ].join(''),
          message:
            'No hardcoded hex colors in sx/style props. Use DS_TEXT, DS_SURFACE, DS_BORDER, DS_BG, BADGE_COLORS from src/lib/ds.ts, or helper functions from src/lib/utils.ts.',
        },
      ],
    },
  },
])
