import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';

export default tseslint.config(
  // 全局忽略
  {
    ignores: ['dist', 'node_modules', 'src-tauri', 'src/api/generated', 'src/_unused'],
  },

  // 基础规则
  js.configs.recommended,
  ...tseslint.configs.recommended,

  // React + TypeScript 文件
  {
    files: ['**/*.{ts,tsx}'],
    plugins: {
      react,
      'react-hooks': reactHooks,
      'react-refresh': reactRefresh,
    },
    settings: {
      react: {
        version: 'detect',
      },
    },
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
    },
    rules: {
      // React
      ...react.configs.recommended.rules,
      ...react.configs['jsx-runtime'].rules,
      ...reactHooks.configs.recommended.rules,
      'react/prop-types': 'off', // TypeScript 已有类型检查，无需 PropTypes
      'react-hooks/set-state-in-effect': 'warn',
      'react-hooks/incompatible-library': 'off', // TanStack Virtual 等常见库误报
      'react-refresh/only-export-components': 'warn',
      'react/no-unescaped-entities': 'warn',

      // TypeScript
      '@typescript-eslint/ban-ts-comment': 'warn',
      '@typescript-eslint/no-explicit-any': 'warn',
      '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],

      // 通用
      'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
      'no-constant-condition': 'warn',
      eqeqeq: ['warn', 'always'],
      curly: ['warn', 'all'],
      'no-var': 'error',
      'prefer-const': 'warn',
    },
  },
);
