import nextConfig from "eslint-config-next"
import prettier from "eslint-config-prettier"

// Find the config object that includes the @typescript-eslint plugin
// and add our custom rule there
const eslintConfig = [
  ...nextConfig.map(config => {
    if (config.plugins?.["@typescript-eslint"]) {
      return {
        ...config,
        rules: {
          ...config.rules,
          "@typescript-eslint/no-explicit-any": "warn",
        },
      }
    }
    return config
  }),
  prettier,
  {
    rules: {
      "react/react-in-jsx-scope": "off",
      // Downgrade React Compiler rules to warnings: pre-existing patterns, fix incrementally
      "react-hooks/set-state-in-effect": "warn",
      "react-hooks/error-boundaries": "warn",
      "react-hooks/immutability": "warn",
      "react-hooks/preserve-manual-memoization": "warn",
      "react-hooks/purity": "warn",
      "react-hooks/refs": "warn",
      "react-hooks/static-components": "warn",
    },
  },
  {
    ignores: [
      "dist/**",
      "node_modules/**",
      "*.config.js",
      "*.config.mjs",
      ".next/**",
    ],
  },
]

export default eslintConfig
