// ESLint配置文件 - 需要通过 .dev-tools-config.json 启用
// 运行 `npm run scripts:enable` 来启用ESLint

const fs = require('fs');
const path = require('path');

// 检查开发工具配置
const configPath = path.join(__dirname, '.dev-tools-config.json');
let eslintEnabled = false;

try {
  const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
  eslintEnabled = config.tools?.eslint?.enabled === true;
} catch (error) {
  console.warn('⚠️  无法读取开发工具配置，ESLint将被禁用');
}

// 如果ESLint被禁用，返回空配置
if (!eslintEnabled) {
  console.log('ℹ️  ESLint已在配置中被禁用，如需启用请运行: npm run scripts:enable');
  module.exports = {};
  return;
}

// ESLint正常配置
module.exports = {
  root: true,
  env: { browser: true, es2020: true },
  extends: [
    'eslint:recommended',
    '@typescript-eslint/recommended',
    'plugin:react-hooks/recommended',
  ],
  ignorePatterns: ['dist', '.eslintrc.cjs', 'node_modules'],
  parser: '@typescript-eslint/parser',
  plugins: ['react-refresh'],
  rules: {
    'react-refresh/only-export-components': [
      'warn',
      { allowConstantExport: true },
    ],
    '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
    '@typescript-eslint/no-explicit-any': 'warn',
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn',
  },
};