import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";

const eslintConfig = defineConfig([
  ...nextVitals,
  ...nextTs,
  // Override default ignores of eslint-config-next.
  globalIgnores([
    // Default ignores of eslint-config-next:
    ".next/**",
    "out/**",
    "build/**",
    "next-env.d.ts",
    // Ignore legacy .js scripts that use CommonJS
    "scripts/**",
    "supabase/**",
    "fix-agents.js",
  ]),
  // Allow setState in useEffect for PWA prompts and client-side state initialization
  {
    files: ["**/pwa/**", "**/InstallPrompt.tsx"],
    rules: {
      "react-hooks/set-state-in-effect": "off",
    },
  },
  // Relax some rules for legacy code
  {
    files: ["db/**", "scripts/**", "supabase/**"],
    rules: {
      "@typescript-eslint/no-require-imports": "off",
      "@typescript-eslint/no-explicit-any": "warn",
    },
  },
]);

export default eslintConfig;
